1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 83eab52..31f16c4 100644
7 @@ -248,6 +248,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 7bbaca9..a026491 100644
19 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index dd9820b..d0435d9 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -59,6 +59,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
36 aufs4.x-rcN base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 1b0a87f..76fd7cc 100644
42 @@ -2319,6 +2319,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 0ecb646..cf39138 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 95d71ed..8ca5f09 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 be8fbe2..f5f4f94 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 @@ -61,6 +61,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 @@ EXPORT_SYMBOL(generic_update_time);
131 * This does the actual work of updating an inodes time or version. Must have
132 * had called mnt_want_write() before calling this.
134 -static int update_time(struct inode *inode, struct timespec *time, int flags)
135 +int update_time(struct inode *inode, struct timespec *time, int flags)
137 int (*update_time)(struct inode *, struct timespec *, int);
139 diff --git a/fs/read_write.c b/fs/read_write.c
140 index c4f88af..ac71b96 100644
141 --- a/fs/read_write.c
142 +++ b/fs/read_write.c
143 @@ -513,6 +513,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 006ba50..46c87af 100644
176 @@ -859,8 +859,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
178 * Attempt to initiate a splice from pipe to file.
180 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
181 - loff_t *ppos, size_t len, unsigned int flags)
182 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
183 + loff_t *ppos, size_t len, unsigned int flags)
185 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
186 loff_t *, size_t, unsigned int);
187 @@ -876,9 +876,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/fs/sync.c b/fs/sync.c
201 index 11ba023..abf6a5d 100644
205 * wait == 1 case since in that case write_inode() functions do
206 * sync_dirty_buffer() and thus effectively write one block at a time.
208 -static int __sync_filesystem(struct super_block *sb, int wait)
209 +int __sync_filesystem(struct super_block *sb, int wait)
213 diff --git a/include/linux/file.h b/include/linux/file.h
214 index 61eb82c..e700888 100644
215 --- a/include/linux/file.h
216 +++ b/include/linux/file.h
217 @@ -19,6 +19,7 @@ struct dentry;
219 extern struct file *alloc_file(const struct path *, fmode_t mode,
220 const struct file_operations *fop);
221 +extern struct file *get_empty_filp(void);
223 static inline void fput_light(struct file *file, int fput_needed)
225 diff --git a/include/linux/fs.h b/include/linux/fs.h
226 index 7251f7b..3668627 100644
227 --- a/include/linux/fs.h
228 +++ b/include/linux/fs.h
229 @@ -1246,6 +1246,7 @@ extern void fasync_free(struct fasync_struct *);
230 /* can be called from interrupts */
231 extern void kill_fasync(struct fasync_struct **, int, int);
233 +extern int setfl(int fd, struct file * filp, unsigned long arg);
234 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
235 extern void f_setown(struct file *filp, unsigned long arg, int force);
236 extern void f_delown(struct file *filp);
237 @@ -1673,6 +1674,7 @@ struct file_operations {
238 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
239 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
240 int (*check_flags)(int);
241 + int (*setfl)(struct file *, unsigned long);
242 int (*flock) (struct file *, int, struct file_lock *);
243 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
244 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
245 @@ -1749,6 +1751,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
246 struct iovec *fast_pointer,
247 struct iovec **ret_pointer);
249 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
250 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
252 +vfs_readf_t vfs_readf(struct file *file);
253 +vfs_writef_t vfs_writef(struct file *file);
255 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
256 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
257 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
258 @@ -2127,6 +2135,7 @@ extern int current_umask(void);
259 extern void ihold(struct inode * inode);
260 extern void iput(struct inode *);
261 extern int generic_update_time(struct inode *, struct timespec *, int);
262 +extern int update_time(struct inode *, struct timespec *, int);
265 extern struct kobject *fs_kobj;
266 @@ -2407,6 +2416,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
270 +extern int __sync_filesystem(struct super_block *, int);
271 extern int sync_filesystem(struct super_block *);
272 extern const struct file_operations def_blk_fops;
273 extern const struct file_operations def_chr_fops;
274 diff --git a/include/linux/splice.h b/include/linux/splice.h
275 index 00a2116..1f0a4a2 100644
276 --- a/include/linux/splice.h
277 +++ b/include/linux/splice.h
278 @@ -86,4 +86,10 @@ extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
280 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
281 extern const struct pipe_buf_operations default_pipe_buf_ops;
283 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
284 + loff_t *ppos, size_t len, unsigned int flags);
285 +extern long do_splice_to(struct file *in, loff_t *ppos,
286 + struct pipe_inode_info *pipe, size_t len,
287 + unsigned int flags);
289 aufs4.x-rcN mmap patch
291 diff --git a/fs/proc/base.c b/fs/proc/base.c
292 index c87b6b9..6b71643 100644
295 @@ -1946,7 +1946,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
296 down_read(&mm->mmap_sem);
297 vma = find_exact_vma(mm, vm_start, vm_end);
298 if (vma && vma->vm_file) {
299 - *path = vma->vm_file->f_path;
300 + *path = vma_pr_or_file(vma)->f_path;
304 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
305 index 7563437..7c0dc0f 100644
306 --- a/fs/proc/nommu.c
307 +++ b/fs/proc/nommu.c
308 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
309 file = region->vm_file;
312 - struct inode *inode = file_inode(region->vm_file);
313 + struct inode *inode;
315 + file = vmr_pr_or_file(region);
316 + inode = file_inode(file);
317 dev = inode->i_sb->s_dev;
320 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
321 index f08bd31..e1b9a37 100644
322 --- a/fs/proc/task_mmu.c
323 +++ b/fs/proc/task_mmu.c
324 @@ -292,7 +292,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
325 const char *name = NULL;
328 - struct inode *inode = file_inode(vma->vm_file);
329 + struct inode *inode;
331 + file = vma_pr_or_file(vma);
332 + inode = file_inode(file);
333 dev = inode->i_sb->s_dev;
335 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
336 @@ -1629,7 +1632,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
337 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
338 struct vm_area_struct *vma = v;
339 struct numa_maps *md = &numa_priv->md;
340 - struct file *file = vma->vm_file;
341 + struct file *file = vma_pr_or_file(vma);
342 struct mm_struct *mm = vma->vm_mm;
343 struct mm_walk walk = {
344 .hugetlb_entry = gather_hugetlb_stats,
345 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
346 index 23266694..58e59b6 100644
347 --- a/fs/proc/task_nommu.c
348 +++ b/fs/proc/task_nommu.c
349 @@ -157,7 +157,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
353 - struct inode *inode = file_inode(vma->vm_file);
354 + struct inode *inode;
356 + file = vma_pr_or_file(vma);
357 + inode = file_inode(file);
358 dev = inode->i_sb->s_dev;
360 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
361 diff --git a/include/linux/mm.h b/include/linux/mm.h
362 index 00a8fa7..a90742b 100644
363 --- a/include/linux/mm.h
364 +++ b/include/linux/mm.h
365 @@ -1294,6 +1294,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
369 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
370 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
372 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
373 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
375 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
377 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
379 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
380 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
383 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
384 +extern void vmr_do_fput(struct vm_region *, const char[], int);
386 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
388 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
389 +#endif /* !CONFIG_MMU */
391 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
392 unsigned int gup_flags);
393 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
394 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
395 index f60f45f..38c5f76 100644
396 --- a/include/linux/mm_types.h
397 +++ b/include/linux/mm_types.h
398 @@ -259,6 +259,7 @@ struct vm_region {
399 unsigned long vm_top; /* region allocated to here */
400 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
401 struct file *vm_file; /* the backing file or NULL */
402 + struct file *vm_prfile; /* the virtual backing file or NULL */
404 int vm_usage; /* region usage count (access under nommu_region_sem) */
405 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
406 @@ -333,6 +334,7 @@ struct vm_area_struct {
407 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
409 struct file * vm_file; /* File we map to (can be NULL). */
410 + struct file *vm_prfile; /* shadow of vm_file */
411 void * vm_private_data; /* was vm_pte (shared mem) */
414 diff --git a/kernel/fork.c b/kernel/fork.c
415 index 6c463c80..24ae37c 100644
418 @@ -641,7 +641,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
419 struct inode *inode = file_inode(file);
420 struct address_space *mapping = file->f_mapping;
424 if (tmp->vm_flags & VM_DENYWRITE)
425 atomic_dec(&inode->i_writecount);
426 i_mmap_lock_write(mapping);
427 diff --git a/mm/Makefile b/mm/Makefile
428 index 026f6a8..723da17 100644
431 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
432 mm_init.o mmu_context.o percpu.o slab_common.o \
433 compaction.o vmacache.o swap_slots.o \
434 interval_tree.o list_lru.o workingset.o \
436 + prfile.o debug.o $(mmu-y)
440 diff --git a/mm/filemap.c b/mm/filemap.c
441 index 1694623..68cd758 100644
444 @@ -2406,7 +2406,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf)
445 int ret = VM_FAULT_LOCKED;
447 sb_start_pagefault(inode->i_sb);
448 - file_update_time(vmf->vma->vm_file);
449 + vma_file_update_time(vmf->vma);
451 if (page->mapping != inode->i_mapping) {
453 diff --git a/mm/mmap.c b/mm/mmap.c
454 index bfbe885..8bd32f9 100644
457 @@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
458 if (vma->vm_ops && vma->vm_ops->close)
459 vma->vm_ops->close(vma);
461 - fput(vma->vm_file);
463 mpol_put(vma_policy(vma));
464 kmem_cache_free(vm_area_cachep, vma);
466 @@ -881,7 +881,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
469 uprobe_munmap(next, next->vm_start, next->vm_end);
474 anon_vma_merge(vma, next);
475 @@ -1731,8 +1731,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
483 /* Undo any partial mapping done by a device driver. */
484 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
485 @@ -2537,7 +2537,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
489 - get_file(new->vm_file);
492 if (new->vm_ops && new->vm_ops->open)
493 new->vm_ops->open(new);
494 @@ -2556,7 +2556,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
495 if (new->vm_ops && new->vm_ops->close)
496 new->vm_ops->close(new);
498 - fput(new->vm_file);
500 unlink_anon_vmas(new);
502 mpol_put(vma_policy(new));
503 @@ -2710,7 +2710,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
504 struct vm_area_struct *vma;
505 unsigned long populate = 0;
506 unsigned long ret = -EINVAL;
508 + struct file *file, *prfile;
510 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
511 current->comm, current->pid);
512 @@ -2785,10 +2785,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
516 - file = get_file(vma->vm_file);
518 + file = vma->vm_file;
519 + prfile = vma->vm_prfile;
520 ret = do_mmap_pgoff(vma->vm_file, start, size,
521 prot, flags, pgoff, &populate, NULL);
522 + if (!IS_ERR_VALUE(ret) && file && prfile) {
523 + struct vm_area_struct *new_vma;
525 + new_vma = find_vma(mm, ret);
526 + if (!new_vma->vm_prfile)
527 + new_vma->vm_prfile = prfile;
528 + if (new_vma != vma)
532 + * two fput()s instead of vma_fput(vma),
533 + * coz vma may not be available anymore.
539 up_write(&mm->mmap_sem);
541 @@ -3079,7 +3096,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
542 if (anon_vma_clone(new_vma, vma))
543 goto out_free_mempol;
544 if (new_vma->vm_file)
545 - get_file(new_vma->vm_file);
546 + vma_get_file(new_vma);
547 if (new_vma->vm_ops && new_vma->vm_ops->open)
548 new_vma->vm_ops->open(new_vma);
549 vma_link(mm, new_vma, prev, rb_link, rb_parent);
550 diff --git a/mm/nommu.c b/mm/nommu.c
551 index 2d131b9..5dc9a19 100644
554 @@ -637,7 +637,7 @@ static void __put_nommu_region(struct vm_region *region)
555 up_write(&nommu_region_sem);
558 - fput(region->vm_file);
561 /* IO memory and memory shared directly out of the pagecache
562 * from ramfs/tmpfs mustn't be released here */
563 @@ -795,7 +795,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
564 if (vma->vm_ops && vma->vm_ops->close)
565 vma->vm_ops->close(vma);
567 - fput(vma->vm_file);
569 put_nommu_region(vma->vm_region);
570 kmem_cache_free(vm_area_cachep, vma);
572 @@ -1322,7 +1322,7 @@ unsigned long do_mmap(struct file *file,
573 goto error_just_free;
576 - fput(region->vm_file);
578 kmem_cache_free(vm_region_jar, region);
581 @@ -1397,10 +1397,10 @@ unsigned long do_mmap(struct file *file,
582 up_write(&nommu_region_sem);
585 - fput(region->vm_file);
587 kmem_cache_free(vm_region_jar, region);
589 - fput(vma->vm_file);
591 kmem_cache_free(vm_area_cachep, vma);
594 diff --git a/mm/prfile.c b/mm/prfile.c
596 index 0000000..b323b8a
601 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
602 + * in /proc/PID/maps.
603 + * Call these functions via macros defined in linux/mm.h.
605 + * See Documentation/filesystems/aufs/design/06mmap.txt
607 + * Copyright (c) 2014 Junjro R. Okajima
608 + * Copyright (c) 2014 Ian Campbell
611 +#include <linux/mm.h>
612 +#include <linux/file.h>
613 +#include <linux/fs.h>
615 +/* #define PRFILE_TRACE */
616 +static inline void prfile_trace(struct file *f, struct file *pr,
617 + const char func[], int line, const char func2[])
621 + pr_info("%s:%d: %s, %s\n", func, line, func2,
622 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
626 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
629 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
631 + prfile_trace(f, pr, func, line, __func__);
632 + file_update_time(f);
634 + file_update_time(pr);
637 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
643 + return (f && pr) ? pr : f;
646 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
648 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
650 + prfile_trace(f, pr, func, line, __func__);
656 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
658 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
660 + prfile_trace(f, pr, func, line, __func__);
667 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
670 + struct file *f = region->vm_file, *pr = region->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
673 + return (f && pr) ? pr : f;
676 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
678 + struct file *f = region->vm_file, *pr = region->vm_prfile;
680 + prfile_trace(f, pr, func, line, __func__);
685 +#endif /* !CONFIG_MMU */
686 aufs4.x-rcN standalone patch
688 diff --git a/fs/dcache.c b/fs/dcache.c
689 index 8ca5f09..b1ff5be 100644
692 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
696 +EXPORT_SYMBOL_GPL(d_walk);
699 struct vfsmount *mnt;
700 @@ -2864,6 +2865,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
702 write_sequnlock(&rename_lock);
704 +EXPORT_SYMBOL_GPL(d_exchange);
707 * d_ancestor - search for an ancestor
708 diff --git a/fs/exec.c b/fs/exec.c
709 index 65145a3..8d35776 100644
712 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
713 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
714 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
716 +EXPORT_SYMBOL_GPL(path_noexec);
720 diff --git a/fs/fcntl.c b/fs/fcntl.c
721 index f5f4f94..c671660 100644
724 @@ -83,6 +83,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
728 +EXPORT_SYMBOL_GPL(setfl);
730 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
732 diff --git a/fs/file_table.c b/fs/file_table.c
733 index 954d510..4fb5b10 100644
734 --- a/fs/file_table.c
735 +++ b/fs/file_table.c
736 @@ -148,6 +148,7 @@ struct file *get_empty_filp(void)
738 return ERR_PTR(-ENFILE);
740 +EXPORT_SYMBOL_GPL(get_empty_filp);
743 * alloc_file - allocate and initialize a 'struct file'
744 @@ -259,6 +260,7 @@ void flush_delayed_fput(void)
748 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
750 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
752 @@ -301,6 +303,7 @@ void __fput_sync(struct file *file)
756 +EXPORT_SYMBOL_GPL(__fput_sync);
758 void put_filp(struct file *file)
760 @@ -309,6 +312,7 @@ void put_filp(struct file *file)
764 +EXPORT_SYMBOL_GPL(put_filp);
766 void __init files_init(void)
768 diff --git a/fs/inode.c b/fs/inode.c
769 index 9a9ba3a..a3a18d8 100644
772 @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
774 return update_time(inode, time, flags);
776 +EXPORT_SYMBOL_GPL(update_time);
779 * touch_atime - update the access time
780 diff --git a/fs/namespace.c b/fs/namespace.c
781 index cc1375ef..9b4c67c 100644
784 @@ -465,6 +465,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
785 mnt_dec_writers(real_mount(mnt));
788 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
791 * mnt_drop_write - give up write access to a mount
792 @@ -1884,6 +1885,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
796 +EXPORT_SYMBOL_GPL(iterate_mounts);
798 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
800 diff --git a/fs/notify/group.c b/fs/notify/group.c
801 index fbe3cbe..bdfc61e 100644
802 --- a/fs/notify/group.c
803 +++ b/fs/notify/group.c
805 #include <linux/srcu.h>
806 #include <linux/rculist.h>
807 #include <linux/wait.h>
808 +#include <linux/module.h>
810 #include <linux/fsnotify_backend.h>
811 #include "fsnotify.h"
812 @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
814 atomic_inc(&group->refcnt);
816 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
819 * Drop a reference to a group. Free it if it's through.
820 @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
821 if (atomic_dec_and_test(&group->refcnt))
822 fsnotify_final_destroy_group(group);
824 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
827 * Create a new fsnotify_group and hold a reference for the group returned.
828 @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
832 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
834 int fsnotify_fasync(int fd, struct file *file, int on)
836 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
837 index 6043306..fdb50e4 100644
838 --- a/fs/notify/mark.c
839 +++ b/fs/notify/mark.c
840 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
841 mark->free_mark(mark);
844 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
846 /* Calculate mask of events for a list of marks */
847 u32 fsnotify_recalc_mask(struct hlist_head *head)
848 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
849 mutex_unlock(&group->mark_mutex);
850 fsnotify_free_mark(mark);
852 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
854 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
856 @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
860 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
862 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
863 struct inode *inode, struct vfsmount *mnt, int allow_dups)
864 @@ -521,6 +524,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
865 atomic_set(&mark->refcnt, 1);
866 mark->free_mark = free_mark;
868 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
871 * Destroy all marks in destroy_list, waits for SRCU period to finish before
872 diff --git a/fs/open.c b/fs/open.c
873 index 949cef2..9a892fb8 100644
876 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
877 inode_unlock(dentry->d_inode);
880 +EXPORT_SYMBOL_GPL(do_truncate);
882 long vfs_truncate(const struct path *path, loff_t length)
884 @@ -693,6 +694,7 @@ int open_check_o_direct(struct file *f)
888 +EXPORT_SYMBOL_GPL(open_check_o_direct);
890 static int do_dentry_open(struct file *f,
892 diff --git a/fs/read_write.c b/fs/read_write.c
893 index ac71b96..b69e687 100644
894 --- a/fs/read_write.c
895 +++ b/fs/read_write.c
896 @@ -523,6 +523,7 @@ vfs_readf_t vfs_readf(struct file *file)
897 return new_sync_read;
898 return ERR_PTR(-ENOSYS);
900 +EXPORT_SYMBOL_GPL(vfs_readf);
902 vfs_writef_t vfs_writef(struct file *file)
904 @@ -534,6 +535,7 @@ vfs_writef_t vfs_writef(struct file *file)
905 return new_sync_write;
906 return ERR_PTR(-ENOSYS);
908 +EXPORT_SYMBOL_GPL(vfs_writef);
910 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
912 diff --git a/fs/splice.c b/fs/splice.c
913 index 46c87af..0efa652 100644
916 @@ -872,6 +872,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
918 return splice_write(pipe, out, ppos, len, flags);
920 +EXPORT_SYMBOL_GPL(do_splice_from);
923 * Attempt to initiate a splice from a file to a pipe.
924 @@ -901,6 +902,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
926 return splice_read(in, ppos, pipe, len, flags);
928 +EXPORT_SYMBOL_GPL(do_splice_to);
931 * splice_direct_to_actor - splices data directly between two non-pipes
932 diff --git a/fs/sync.c b/fs/sync.c
933 index abf6a5d..c86fe9c 100644
936 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
937 sb->s_op->sync_fs(sb, wait);
938 return __sync_blockdev(sb->s_bdev, wait);
940 +EXPORT_SYMBOL_GPL(__sync_filesystem);
943 * Write out and wait upon all dirty data associated with this
944 diff --git a/fs/xattr.c b/fs/xattr.c
945 index 7e3317c..88910fe 100644
948 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
949 *xattr_value = value;
952 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
955 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
956 diff --git a/kernel/task_work.c b/kernel/task_work.c
957 index d513051..e056d54 100644
958 --- a/kernel/task_work.c
959 +++ b/kernel/task_work.c
960 @@ -119,3 +119,4 @@ void task_work_run(void)
964 +EXPORT_SYMBOL_GPL(task_work_run);
965 diff --git a/security/commoncap.c b/security/commoncap.c
966 index 78b3783..c8b3e88 100644
967 --- a/security/commoncap.c
968 +++ b/security/commoncap.c
969 @@ -1062,12 +1062,14 @@ int cap_mmap_addr(unsigned long addr)
973 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
975 int cap_mmap_file(struct file *file, unsigned long reqprot,
976 unsigned long prot, unsigned long flags)
980 +EXPORT_SYMBOL_GPL(cap_mmap_file);
982 #ifdef CONFIG_SECURITY
984 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
985 index 03c1652..f88c84b 100644
986 --- a/security/device_cgroup.c
987 +++ b/security/device_cgroup.c
989 #include <linux/device_cgroup.h>
990 #include <linux/cgroup.h>
991 #include <linux/ctype.h>
992 +#include <linux/export.h>
993 #include <linux/list.h>
994 #include <linux/uaccess.h>
995 #include <linux/seq_file.h>
996 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
997 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
1000 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
1002 int devcgroup_inode_mknod(int mode, dev_t dev)
1004 diff --git a/security/security.c b/security/security.c
1005 index d0e07f2..5e323b0 100644
1006 --- a/security/security.c
1007 +++ b/security/security.c
1008 @@ -481,6 +481,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1010 return call_int_hook(path_rmdir, 0, dir, dentry);
1012 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1014 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1016 @@ -497,6 +498,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1018 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1020 +EXPORT_SYMBOL_GPL(security_path_symlink);
1022 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1023 struct dentry *new_dentry)
1024 @@ -505,6 +507,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1026 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1028 +EXPORT_SYMBOL_GPL(security_path_link);
1030 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1031 const struct path *new_dir, struct dentry *new_dentry,
1032 @@ -532,6 +535,7 @@ int security_path_truncate(const struct path *path)
1034 return call_int_hook(path_truncate, 0, path);
1036 +EXPORT_SYMBOL_GPL(security_path_truncate);
1038 int security_path_chmod(const struct path *path, umode_t mode)
1040 @@ -539,6 +543,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1042 return call_int_hook(path_chmod, 0, path, mode);
1044 +EXPORT_SYMBOL_GPL(security_path_chmod);
1046 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1048 @@ -546,6 +551,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1050 return call_int_hook(path_chown, 0, path, uid, gid);
1052 +EXPORT_SYMBOL_GPL(security_path_chown);
1054 int security_path_chroot(const struct path *path)
1056 @@ -631,6 +637,7 @@ int security_inode_readlink(struct dentry *dentry)
1058 return call_int_hook(inode_readlink, 0, dentry);
1060 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1062 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1064 @@ -646,6 +653,7 @@ int security_inode_permission(struct inode *inode, int mask)
1066 return call_int_hook(inode_permission, 0, inode, mask);
1068 +EXPORT_SYMBOL_GPL(security_inode_permission);
1070 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1072 @@ -817,6 +825,7 @@ int security_file_permission(struct file *file, int mask)
1074 return fsnotify_perm(file, mask);
1076 +EXPORT_SYMBOL_GPL(security_file_permission);
1078 int security_file_alloc(struct file *file)
1080 @@ -876,6 +885,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1082 return ima_file_mmap(file, prot);
1084 +EXPORT_SYMBOL_GPL(security_mmap_file);
1086 int security_mmap_addr(unsigned long addr)
1088 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1089 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1090 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-05-06 22:16:52.774886674 +0200
1092 +What: /debug/aufs/si_<id>/
1094 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1096 + Under /debug/aufs, a directory named si_<id> is created
1097 + per aufs mount, where <id> is a unique id generated
1100 +What: /debug/aufs/si_<id>/plink
1102 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1104 + It has three lines and shows the information about the
1105 + pseudo-link. The first line is a single number
1106 + representing a number of buckets. The second line is a
1107 + number of pseudo-links per buckets (separated by a
1108 + blank). The last line is a single number representing a
1109 + total number of psedo-links.
1110 + When the aufs mount option 'noplink' is specified, it
1111 + will show "1\n0\n0\n".
1113 +What: /debug/aufs/si_<id>/xib
1115 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1117 + It shows the consumed blocks by xib (External Inode Number
1118 + Bitmap), its block size and file size.
1119 + When the aufs mount option 'noxino' is specified, it
1120 + will be empty. About XINO files, see the aufs manual.
1122 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1124 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1126 + It shows the consumed blocks by xino (External Inode Number
1127 + Translation Table), its link count, block size and file
1129 + When the aufs mount option 'noxino' is specified, it
1130 + will be empty. About XINO files, see the aufs manual.
1132 +What: /debug/aufs/si_<id>/xigen
1134 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1136 + It shows the consumed blocks by xigen (External Inode
1137 + Generation Table), its block size and file size.
1138 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1140 + When the aufs mount option 'noxino' is specified, it
1141 + will be empty. About XINO files, see the aufs manual.
1142 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1143 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1144 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-05-06 22:16:52.774886674 +0200
1146 +What: /sys/fs/aufs/si_<id>/
1148 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1150 + Under /sys/fs/aufs, a directory named si_<id> is created
1151 + per aufs mount, where <id> is a unique id generated
1154 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1156 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1158 + It shows the abolute path of a member directory (which
1159 + is called branch) in aufs, and its permission.
1161 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1163 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1165 + It shows the id of a member directory (which is called
1168 +What: /sys/fs/aufs/si_<id>/xi_path
1170 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1172 + It shows the abolute path of XINO (External Inode Number
1173 + Bitmap, Translation Table and Generation Table) file
1174 + even if it is the default path.
1175 + When the aufs mount option 'noxino' is specified, it
1176 + will be empty. About XINO files, see the aufs manual.
1177 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1178 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1179 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-05-06 22:16:52.774886674 +0200
1182 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1184 +# This program is free software; you can redistribute it and/or modify
1185 +# it under the terms of the GNU General Public License as published by
1186 +# the Free Software Foundation; either version 2 of the License, or
1187 +# (at your option) any later version.
1189 +# This program is distributed in the hope that it will be useful,
1190 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1191 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1192 +# GNU General Public License for more details.
1194 +# You should have received a copy of the GNU General Public License
1195 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1198 +----------------------------------------
1200 +aufs [ei ju: ef es] | [a u f s]
1201 +1. abbrev. for "advanced multi-layered unification filesystem".
1202 +2. abbrev. for "another unionfs".
1203 +3. abbrev. for "auf das" in German which means "on the" in English.
1204 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1205 + But "Filesystem aufs Filesystem" is hard to understand.
1207 +AUFS is a filesystem with features:
1208 +- multi layered stackable unification filesystem, the member directory
1209 + is called as a branch.
1210 +- branch permission and attribute, 'readonly', 'real-readonly',
1211 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1213 +- internal "file copy-on-write".
1214 +- logical deletion, whiteout.
1215 +- dynamic branch manipulation, adding, deleting and changing permission.
1216 +- allow bypassing aufs, user's direct branch access.
1217 +- external inode number translation table and bitmap which maintains the
1218 + persistent aufs inode number.
1219 +- seekable directory, including NFS readdir.
1220 +- file mapping, mmap and sharing pages.
1221 +- pseudo-link, hardlink over branches.
1222 +- loopback mounted filesystem as a branch.
1223 +- several policies to select one among multiple writable branches.
1224 +- revert a single systemcall when an error occurs in aufs.
1228 +Multi Layered Stackable Unification Filesystem
1229 +----------------------------------------------------------------------
1230 +Most people already knows what it is.
1231 +It is a filesystem which unifies several directories and provides a
1232 +merged single directory. When users access a file, the access will be
1233 +passed/re-directed/converted (sorry, I am not sure which English word is
1234 +correct) to the real file on the member filesystem. The member
1235 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1236 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1237 +readonly branch is handled by creating 'whiteout' on the upper writable
1240 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1241 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1242 +different approaches to implement the merged-view.
1243 +The former tries putting it into VFS, and the latter implements as a
1244 +separate filesystem.
1245 +(If I misunderstand about these implementations, please let me know and
1246 +I shall correct it. Because it is a long time ago when I read their
1247 +source files last time).
1249 +UnionMount's approach will be able to small, but may be hard to share
1250 +branches between several UnionMount since the whiteout in it is
1251 +implemented in the inode on branch filesystem and always
1252 +shared. According to Bharata's post, readdir does not seems to be
1254 +There are several missing features known in this implementations such as
1255 +- for users, the inode number may change silently. eg. copy-up.
1256 +- link(2) may break by copy-up.
1257 +- read(2) may get an obsoleted filedata (fstat(2) too).
1258 +- fcntl(F_SETLK) may be broken by copy-up.
1259 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1262 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1263 +merged into mainline. This is another implementation of UnionMount as a
1264 +separated filesystem. All the limitations and known problems which
1265 +UnionMount are equally inherited to "overlay" filesystem.
1267 +Unionfs has a longer history. When I started implementing a stackable
1268 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1269 +inode, dentry and file objects and they have an array pointing lower
1270 +same kind objects. After contributing many patches for Unionfs, I
1271 +re-started my project AUFS (Jun 2006).
1273 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1274 +implemented my own ideas, approaches and enhancements and it became
1275 +totally different one.
1277 +Comparing DM snapshot and fs based implementation
1278 +- the number of bytes to be copied between devices is much smaller.
1279 +- the type of filesystem must be one and only.
1280 +- the fs must be writable, no readonly fs, even for the lower original
1281 + device. so the compression fs will not be usable. but if we use
1282 + loopback mount, we may address this issue.
1284 + mount /cdrom/squashfs.img /sq
1285 + losetup /sq/ext2.img
1286 + losetup /somewhere/cow
1287 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1288 +- it will be difficult (or needs more operations) to extract the
1289 + difference between the original device and COW.
1290 +- DM snapshot-merge may help a lot when users try merging. in the
1291 + fs-layer union, users will use rsync(1).
1293 +You may want to read my old paper "Filesystems in LiveCD"
1294 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1297 +Several characters/aspects/persona of aufs
1298 +----------------------------------------------------------------------
1300 +Aufs has several characters, aspects or persona.
1301 +1. a filesystem, callee of VFS helper
1302 +2. sub-VFS, caller of VFS helper for branches
1303 +3. a virtual filesystem which maintains persistent inode number
1304 +4. reader/writer of files on branches such like an application
1306 +1. Callee of VFS Helper
1307 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1308 +unlink(2) from an application reaches sys_unlink() kernel function and
1309 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1310 +calls filesystem specific unlink operation. Actually aufs implements the
1311 +unlink operation but it behaves like a redirector.
1313 +2. Caller of VFS Helper for Branches
1314 +aufs_unlink() passes the unlink request to the branch filesystem as if
1315 +it were called from VFS. So the called unlink operation of the branch
1316 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1317 +every necessary pre/post operation for the branch filesystem.
1318 +- acquire the lock for the parent dir on a branch
1319 +- lookup in a branch
1320 +- revalidate dentry on a branch
1321 +- mnt_want_write() for a branch
1322 +- vfs_unlink() for a branch
1323 +- mnt_drop_write() for a branch
1324 +- release the lock on a branch
1326 +3. Persistent Inode Number
1327 +One of the most important issue for a filesystem is to maintain inode
1328 +numbers. This is particularly important to support exporting a
1329 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1330 +backend block device for its own. But some storage is necessary to
1331 +keep and maintain the inode numbers. It may be a large space and may not
1332 +suit to keep in memory. Aufs rents some space from its first writable
1333 +branch filesystem (by default) and creates file(s) on it. These files
1334 +are created by aufs internally and removed soon (currently) keeping
1336 +Note: Because these files are removed, they are totally gone after
1337 + unmounting aufs. It means the inode numbers are not persistent
1338 + across unmount or reboot. I have a plan to make them really
1339 + persistent which will be important for aufs on NFS server.
1341 +4. Read/Write Files Internally (copy-on-write)
1342 +Because a branch can be readonly, when you write a file on it, aufs will
1343 +"copy-up" it to the upper writable branch internally. And then write the
1344 +originally requested thing to the file. Generally kernel doesn't
1345 +open/read/write file actively. In aufs, even a single write may cause a
1346 +internal "file copy". This behaviour is very similar to cp(1) command.
1348 +Some people may think it is better to pass such work to user space
1349 +helper, instead of doing in kernel space. Actually I am still thinking
1350 +about it. But currently I have implemented it in kernel space.
1351 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1352 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1353 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2017-05-06 22:16:52.774886674 +0200
1356 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1358 +# This program is free software; you can redistribute it and/or modify
1359 +# it under the terms of the GNU General Public License as published by
1360 +# the Free Software Foundation; either version 2 of the License, or
1361 +# (at your option) any later version.
1363 +# This program is distributed in the hope that it will be useful,
1364 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1365 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1366 +# GNU General Public License for more details.
1368 +# You should have received a copy of the GNU General Public License
1369 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1371 +Basic Aufs Internal Structure
1373 +Superblock/Inode/Dentry/File Objects
1374 +----------------------------------------------------------------------
1375 +As like an ordinary filesystem, aufs has its own
1376 +superblock/inode/dentry/file objects. All these objects have a
1377 +dynamically allocated array and store the same kind of pointers to the
1378 +lower filesystem, branch.
1379 +For example, when you build a union with one readwrite branch and one
1380 +readonly, mounted /au, /rw and /ro respectively.
1382 +- /ro/fileA exists but /rw/fileA
1384 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1385 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1386 +- [0] = NULL (because /rw/fileA doesn't exist)
1389 +This style of an array is essentially same to the aufs
1390 +superblock/inode/dentry/file objects.
1392 +Because aufs supports manipulating branches, ie. add/delete/change
1393 +branches dynamically, these objects has its own generation. When
1394 +branches are changed, the generation in aufs superblock is
1395 +incremented. And a generation in other object are compared when it is
1396 +accessed. When a generation in other objects are obsoleted, aufs
1397 +refreshes the internal array.
1401 +----------------------------------------------------------------------
1402 +Additionally aufs superblock has some data for policies to select one
1403 +among multiple writable branches, XIB files, pseudo-links and kobject.
1404 +See below in detail.
1405 +About the policies which supports copy-down a directory, see
1406 +wbr_policy.txt too.
1409 +Branch and XINO(External Inode Number Translation Table)
1410 +----------------------------------------------------------------------
1411 +Every branch has its own xino (external inode number translation table)
1412 +file. The xino file is created and unlinked by aufs internally. When two
1413 +members of a union exist on the same filesystem, they share the single
1415 +The struct of a xino file is simple, just a sequence of aufs inode
1416 +numbers which is indexed by the lower inode number.
1417 +In the above sample, assume the inode number of /ro/fileA is i111 and
1418 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1419 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1421 +When the inode numbers are not contiguous, the xino file will be sparse
1422 +which has a hole in it and doesn't consume as much disk space as it
1423 +might appear. If your branch filesystem consumes disk space for such
1424 +holes, then you should specify 'xino=' option at mounting aufs.
1426 +Aufs has a mount option to free the disk blocks for such holes in XINO
1427 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1428 +meet a problem of disk shortage due to XINO files, then you should try
1429 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1430 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1431 +the holes in XINO files.
1433 +Also a writable branch has three kinds of "whiteout bases". All these
1434 +are existed when the branch is joined to aufs, and their names are
1435 +whiteout-ed doubly, so that users will never see their names in aufs
1437 +1. a regular file which will be hardlinked to all whiteouts.
1438 +2. a directory to store a pseudo-link.
1439 +3. a directory to store an "orphan"-ed file temporary.
1442 + When you remove a file on a readonly branch, aufs handles it as a
1443 + logical deletion and creates a whiteout on the upper writable branch
1444 + as a hardlink of this file in order not to consume inode on the
1447 + See below, Pseudo-link.
1449 + When "fileC" exists on the lower readonly branch only and it is
1450 + opened and removed with its parent dir, and then user writes
1451 + something into it, then aufs copies-up fileC to this
1452 + directory. Because there is no other dir to store fileC. After
1453 + creating a file under this dir, the file is unlinked.
1455 +Because aufs supports manipulating branches, ie. add/delete/change
1456 +dynamically, a branch has its own id. When the branch order changes,
1457 +aufs finds the new index by searching the branch id.
1461 +----------------------------------------------------------------------
1462 +Assume "fileA" exists on the lower readonly branch only and it is
1463 +hardlinked to "fileB" on the branch. When you write something to fileA,
1464 +aufs copies-up it to the upper writable branch. Additionally aufs
1465 +creates a hardlink under the Pseudo-link Directory of the writable
1466 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1467 +simple list. If fileB is read after unlinking fileA, aufs returns
1468 +filedata from the pseudo-link instead of the lower readonly
1469 +branch. Because the pseudo-link is based upon the inode, to keep the
1470 +inode number by xino (see above) is essentially necessary.
1472 +All the hardlinks under the Pseudo-link Directory of the writable branch
1473 +should be restored in a proper location later. Aufs provides a utility
1474 +to do this. The userspace helpers executed at remounting and unmounting
1476 +During this utility is running, it puts aufs into the pseudo-link
1477 +maintenance mode. In this mode, only the process which began the
1478 +maintenance mode (and its child processes) is allowed to operate in
1479 +aufs. Some other processes which are not related to the pseudo-link will
1480 +be allowed to run too, but the rest have to return an error or wait
1481 +until the maintenance mode ends. If a process already acquires an inode
1482 +mutex (in VFS), it has to return an error.
1485 +XIB(external inode number bitmap)
1486 +----------------------------------------------------------------------
1487 +Addition to the xino file per a branch, aufs has an external inode number
1488 +bitmap in a superblock object. It is also an internal file such like a
1490 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1492 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1494 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1495 +reduce the number of consumed disk blocks for these files.
1498 +Virtual or Vertical Dir, and Readdir in Userspace
1499 +----------------------------------------------------------------------
1500 +In order to support multiple layers (branches), aufs readdir operation
1501 +constructs a virtual dir block on memory. For readdir, aufs calls
1502 +vfs_readdir() internally for each dir on branches, merges their entries
1503 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1504 +object. So the file object has its entry list until it is closed. The
1505 +entry list will be updated when the file position is zero and becomes
1506 +obsoleted. This decision is made in aufs automatically.
1508 +The dynamically allocated memory block for the name of entries has a
1509 +unit of 512 bytes (by default) and stores the names contiguously (no
1510 +padding). Another block for each entry is handled by kmem_cache too.
1511 +During building dir blocks, aufs creates hash list and judging whether
1512 +the entry is whiteouted by its upper branch or already listed.
1513 +The merged result is cached in the corresponding inode object and
1514 +maintained by a customizable life-time option.
1516 +Some people may call it can be a security hole or invite DoS attack
1517 +since the opened and once readdir-ed dir (file object) holds its entry
1518 +list and becomes a pressure for system memory. But I'd say it is similar
1519 +to files under /proc or /sys. The virtual files in them also holds a
1520 +memory page (generally) while they are opened. When an idea to reduce
1521 +memory for them is introduced, it will be applied to aufs too.
1522 +For those who really hate this situation, I've developed readdir(3)
1523 +library which operates this merging in userspace. You just need to set
1524 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1525 +kernel space for readdir(3).
1529 +----------------------------------------------------------------------
1530 +Aufs sometimes requires privilege access to a branch. For instance,
1531 +in copy-up/down operation. When a user process is going to make changes
1532 +to a file which exists in the lower readonly branch only, and the mode
1533 +of one of ancestor directories may not be writable by a user
1534 +process. Here aufs copy-up the file with its ancestors and they may
1535 +require privilege to set its owner/group/mode/etc.
1536 +This is a typical case of a application character of aufs (see
1539 +Aufs uses workqueue synchronously for this case. It creates its own
1540 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1541 +passes the request to call mkdir or write (for example), and wait for
1542 +its completion. This approach solves a problem of a signal handler
1544 +If aufs didn't adopt the workqueue and changed the privilege of the
1545 +process, then the process may receive the unexpected SIGXFSZ or other
1548 +Also aufs uses the system global workqueue ("events" kernel thread) too
1549 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1550 +whiteout base and etc. This is unrelated to a privilege.
1551 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1552 +superblock at the beginning, at the same time waits for the completion
1553 +of all queued asynchronous tasks.
1557 +----------------------------------------------------------------------
1558 +The whiteout in aufs is very similar to Unionfs's. That is represented
1559 +by its filename. UnionMount takes an approach of a file mode, but I am
1560 +afraid several utilities (find(1) or something) will have to support it.
1562 +Basically the whiteout represents "logical deletion" which stops aufs to
1563 +lookup further, but also it represents "dir is opaque" which also stop
1566 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1567 +In order to make several functions in a single systemcall to be
1568 +revertible, aufs adopts an approach to rename a directory to a temporary
1569 +unique whiteouted name.
1570 +For example, in rename(2) dir where the target dir already existed, aufs
1571 +renames the target dir to a temporary unique whiteouted name before the
1572 +actual rename on a branch, and then handles other actions (make it opaque,
1573 +update the attributes, etc). If an error happens in these actions, aufs
1574 +simply renames the whiteouted name back and returns an error. If all are
1575 +succeeded, aufs registers a function to remove the whiteouted unique
1576 +temporary name completely and asynchronously to the system global
1581 +----------------------------------------------------------------------
1582 +It is a well-known feature or concept.
1583 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1584 +internally and makes change to the new file on the upper writable branch.
1585 +When the trigger systemcall does not update the timestamps of the parent
1586 +dir, aufs reverts it after copy-up.
1589 +Move-down (aufs3.9 and later)
1590 +----------------------------------------------------------------------
1591 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1592 +the lower readonly branch to the upper writable branch when a user
1593 +changes something about the file.
1594 +"Move-down" is an opposite action of copy-up. Basically this action is
1595 +ran manually instead of automatically and internally.
1596 +For desgin and implementation, aufs has to consider these issues.
1597 +- whiteout for the file may exist on the lower branch.
1598 +- ancestor directories may not exist on the lower branch.
1599 +- diropq for the ancestor directories may exist on the upper branch.
1600 +- free space on the lower branch will reduce.
1601 +- another access to the file may happen during moving-down, including
1602 + UDBA (see "Revalidate Dentry and UDBA").
1603 +- the file should not be hard-linked nor pseudo-linked. they should be
1604 + handled by auplink utility later.
1606 +Sometimes users want to move-down a file from the upper writable branch
1607 +to the lower readonly or writable branch. For instance,
1608 +- the free space of the upper writable branch is going to run out.
1609 +- create a new intermediate branch between the upper and lower branch.
1612 +For this purpose, use "aumvdown" command in aufs-util.git.
1613 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1614 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1615 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2017-05-06 22:16:52.774886674 +0200
1618 +# Copyright (C) 2015-2017 Junjiro R. Okajima
1620 +# This program is free software; you can redistribute it and/or modify
1621 +# it under the terms of the GNU General Public License as published by
1622 +# the Free Software Foundation; either version 2 of the License, or
1623 +# (at your option) any later version.
1625 +# This program is distributed in the hope that it will be useful,
1626 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1627 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1628 +# GNU General Public License for more details.
1630 +# You should have received a copy of the GNU General Public License
1631 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1633 +Support for a branch who has its ->atomic_open()
1634 +----------------------------------------------------------------------
1635 +The filesystems who implement its ->atomic_open() are not majority. For
1636 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1637 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1638 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1639 +sure whether all filesystems who have ->atomic_open() behave like this,
1640 +but NFSv4 surely returns the error.
1642 +In order to support ->atomic_open() for aufs, there are a few
1645 +A. Introduce aufs_atomic_open()
1646 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1648 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1649 + an aufs user Pip Cet's approach
1650 + - calls aufs_create(), VFS finish_open() and notify_change().
1651 + - pass fake-mode to finish_open(), and then correct the mode by
1653 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1654 + - no aufs_atomic_open().
1655 + - aufs_lookup() registers the TID to an aufs internal object.
1656 + - aufs_create() does nothing when the matching TID is registered, but
1657 + registers the mode.
1658 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1659 + TID is registered.
1660 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1662 + - no aufs_atomic_open().
1663 + - aufs_create() registers the TID to an internal object. this info
1664 + represents "this process created this file just now."
1665 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1666 + registered TID and re-try open() with superuser's credential.
1668 +Pros and cons for each approach.
1671 + - straightforward but highly depends upon VFS internal.
1672 + - the atomic behavaiour is kept.
1673 + - some of parameters such as nameidata are hard to reproduce for
1677 + - easy to implement.
1678 + - the atomic behavaiour is lost.
1680 + - the atomic behavaiour is kept.
1681 + - dirty and tricky.
1682 + - VFS checks whether the file is created correctly after calling
1683 + ->create(), which means this approach doesn't work.
1685 + - easy to implement.
1686 + - the atomic behavaiour is lost.
1687 + - to open a file with superuser's credential and give it to a user
1688 + process is a bad idea, since the file object keeps the credential
1689 + in it. It may affect LSM or something. This approach doesn't work
1692 +The approach A is ideal, but it hard to implement. So here is a
1693 +variation of A, which is to be implemented.
1695 +A-1. Introduce aufs_atomic_open()
1696 + - calls branch fs ->atomic_open() if exists. otherwise calls
1697 + vfs_create() and finish_open().
1698 + - the demerit is that the several checks after branch fs
1699 + ->atomic_open() are lost. in the ordinary case, the checks are
1700 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1701 + be implemented in aufs, but not all I am afraid.
1702 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1703 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1704 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2017-05-06 22:16:52.774886674 +0200
1707 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1709 +# This program is free software; you can redistribute it and/or modify
1710 +# it under the terms of the GNU General Public License as published by
1711 +# the Free Software Foundation; either version 2 of the License, or
1712 +# (at your option) any later version.
1714 +# This program is distributed in the hope that it will be useful,
1715 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1716 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717 +# GNU General Public License for more details.
1719 +# You should have received a copy of the GNU General Public License
1720 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1723 +----------------------------------------------------------------------
1724 +Since aufs has a character of sub-VFS (see Introduction), it operates
1725 +lookup for branches as VFS does. It may be a heavy work. But almost all
1726 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1727 +directly connected to its parent. Digging down the directory hierarchy
1728 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1731 +When a branch is a remote filesystem, aufs basically relies upon its
1732 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1734 +For d_revalidate, aufs implements three levels of revalidate tests. See
1735 +"Revalidate Dentry and UDBA" in detail.
1738 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1739 +----------------------------------------------------------------------
1740 +Let's try case study.
1741 +- aufs has two branches, upper readwrite and lower readonly.
1743 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1744 +- user invoked "chmod a+rx /au/dirA"
1745 +- the internal copy-up is activated and "/rw/dirA" is created and its
1746 + permission bits are set to world readable.
1747 +- then "/au/dirA" becomes world readable?
1749 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1750 +or it may be a natively readonly filesystem. If aufs respects the lower
1751 +branch, it should not respond readdir request from other users. But user
1752 +allowed it by chmod. Should really aufs rejects showing the entries
1755 +To be honest, I don't have a good solution for this case. So aufs
1756 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1758 +When dirperm1 is specified, aufs checks only the highest one for the
1759 +directory permission, and shows the entries. Otherwise, as usual, checks
1760 +every dir existing on all branches and rejects the request.
1762 +As a side effect, dirperm1 option improves the performance of aufs
1763 +because the number of permission check is reduced when the number of
1767 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1768 +----------------------------------------------------------------------
1769 +Generally VFS helpers re-validate a dentry as a part of lookup.
1770 +0. digging down the directory hierarchy.
1771 +1. lock the parent dir by its i_mutex.
1772 +2. lookup the final (child) entry.
1774 +4. call the actual operation (create, unlink, etc.)
1775 +5. unlock the parent dir
1777 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1778 +called. Actually aufs implements it and checks the dentry on a branch is
1780 +But it is not enough. Because aufs has to release the lock for the
1781 +parent dir on a branch at the end of ->lookup() (step 2) and
1782 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1784 +If the file on a branch is changed directly, eg. bypassing aufs, after
1785 +aufs released the lock, then the subsequent operation may cause
1786 +something unpleasant result.
1788 +This situation is a result of VFS architecture, ->lookup() and
1789 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1790 +design from VFS's point of view. It is just not suitable for sub-VFS
1793 +Aufs supports such case by three level of revalidation which is
1794 +selectable by user.
1795 +1. Simple Revalidate
1796 + Addition to the native flow in VFS's, confirm the child-parent
1797 + relationship on the branch just after locking the parent dir on the
1798 + branch in the "actual operation" (step 4). When this validation
1799 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1800 + checks the validation of the dentry on branches.
1801 +2. Monitor Changes Internally by Inotify/Fsnotify
1802 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1803 + the dentry on the branch, and returns EBUSY if it finds different
1805 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1806 + during it is in cache. When the event is notified, aufs registers a
1807 + function to kernel 'events' thread by schedule_work(). And the
1808 + function sets some special status to the cached aufs dentry and inode
1809 + private data. If they are not cached, then aufs has nothing to
1810 + do. When the same file is accessed through aufs (step 0-3) later,
1811 + aufs will detect the status and refresh all necessary data.
1812 + In this mode, aufs has to ignore the event which is fired by aufs
1814 +3. No Extra Validation
1815 + This is the simplest test and doesn't add any additional revalidation
1816 + test, and skip the revalidation in step 4. It is useful and improves
1817 + aufs performance when system surely hide the aufs branches from user,
1818 + by over-mounting something (or another method).
1819 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1820 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1821 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2017-05-06 22:16:52.774886674 +0200
1824 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1826 +# This program is free software; you can redistribute it and/or modify
1827 +# it under the terms of the GNU General Public License as published by
1828 +# the Free Software Foundation; either version 2 of the License, or
1829 +# (at your option) any later version.
1831 +# This program is distributed in the hope that it will be useful,
1832 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1833 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1834 +# GNU General Public License for more details.
1836 +# You should have received a copy of the GNU General Public License
1837 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1839 +Branch Manipulation
1841 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1842 +and changing its permission/attribute, there are a lot of works to do.
1846 +----------------------------------------------------------------------
1847 +o Confirm the adding dir exists outside of aufs, including loopback
1848 + mount, and its various attributes.
1849 +o Initialize the xino file and whiteout bases if necessary.
1852 +o Check the owner/group/mode of the directory
1853 + When the owner/group/mode of the adding directory differs from the
1854 + existing branch, aufs issues a warning because it may impose a
1856 + For example, when a upper writable branch has a world writable empty
1857 + top directory, a malicious user can create any files on the writable
1858 + branch directly, like copy-up and modify manually. If something like
1859 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1860 + writable branch, and the writable branch is world-writable, then a
1861 + malicious guy may create /etc/passwd on the writable branch directly
1862 + and the infected file will be valid in aufs.
1863 + I am afraid it can be a security issue, but aufs can do nothing except
1864 + producing a warning.
1868 +----------------------------------------------------------------------
1869 +o Confirm the deleting branch is not busy
1870 + To be general, there is one merit to adopt "remount" interface to
1871 + manipulate branches. It is to discard caches. At deleting a branch,
1872 + aufs checks the still cached (and connected) dentries and inodes. If
1873 + there are any, then they are all in-use. An inode without its
1874 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1876 + For the cached one, aufs checks whether the same named entry exists on
1878 + If the cached one is a directory, because aufs provides a merged view
1879 + to users, as long as one dir is left on any branch aufs can show the
1880 + dir to users. In this case, the branch can be removed from aufs.
1881 + Otherwise aufs rejects deleting the branch.
1883 + If any file on the deleting branch is opened by aufs, then aufs
1887 +Modify the Permission of a Branch
1888 +----------------------------------------------------------------------
1889 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1892 +o rw --> ro: Confirm the modifying branch is not busy
1893 + Aufs rejects the request if any of these conditions are true.
1894 + - a file on the branch is mmap-ed.
1895 + - a regular file on the branch is opened for write and there is no
1896 + same named entry on the upper branch.
1897 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1898 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1899 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2017-05-06 22:16:52.774886674 +0200
1902 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1904 +# This program is free software; you can redistribute it and/or modify
1905 +# it under the terms of the GNU General Public License as published by
1906 +# the Free Software Foundation; either version 2 of the License, or
1907 +# (at your option) any later version.
1909 +# This program is distributed in the hope that it will be useful,
1910 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1911 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1912 +# GNU General Public License for more details.
1914 +# You should have received a copy of the GNU General Public License
1915 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1917 +Policies to Select One among Multiple Writable Branches
1918 +----------------------------------------------------------------------
1919 +When the number of writable branch is more than one, aufs has to decide
1920 +the target branch for file creation or copy-up. By default, the highest
1921 +writable branch which has the parent (or ancestor) dir of the target
1922 +file is chosen (top-down-parent policy).
1923 +By user's request, aufs implements some other policies to select the
1924 +writable branch, for file creation several policies, round-robin,
1925 +most-free-space, and other policies. For copy-up, top-down-parent,
1926 +bottom-up-parent, bottom-up and others.
1928 +As expected, the round-robin policy selects the branch in circular. When
1929 +you have two writable branches and creates 10 new files, 5 files will be
1930 +created for each branch. mkdir(2) systemcall is an exception. When you
1931 +create 10 new directories, all will be created on the same branch.
1932 +And the most-free-space policy selects the one which has most free
1933 +space among the writable branches. The amount of free space will be
1934 +checked by aufs internally, and users can specify its time interval.
1936 +The policies for copy-up is more simple,
1937 +top-down-parent is equivalent to the same named on in create policy,
1938 +bottom-up-parent selects the writable branch where the parent dir
1939 +exists and the nearest upper one from the copyup-source,
1940 +bottom-up selects the nearest upper writable branch from the
1941 +copyup-source, regardless the existence of the parent dir.
1943 +There are some rules or exceptions to apply these policies.
1944 +- If there is a readonly branch above the policy-selected branch and
1945 + the parent dir is marked as opaque (a variation of whiteout), or the
1946 + target (creating) file is whiteout-ed on the upper readonly branch,
1947 + then the result of the policy is ignored and the target file will be
1948 + created on the nearest upper writable branch than the readonly branch.
1949 +- If there is a writable branch above the policy-selected branch and
1950 + the parent dir is marked as opaque or the target file is whiteouted
1951 + on the branch, then the result of the policy is ignored and the target
1952 + file will be created on the highest one among the upper writable
1953 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1955 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1956 + They try selecting the branch where the source exists as possible
1957 + since copyup a large file will take long time. If it can't be,
1958 + ie. the branch where the source exists is readonly, then they will
1959 + follow the copyup policy.
1960 +- There is an exception for rename(2) when the target exists.
1961 + If the rename target exists, aufs compares the index of the branches
1962 + where the source and the target exists and selects the higher
1963 + one. If the selected branch is readonly, then aufs follows the
1965 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1966 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1967 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2017-05-06 22:16:52.774886674 +0200
1970 +# Copyright (C) 2011-2017 Junjiro R. Okajima
1972 +# This program is free software; you can redistribute it and/or modify
1973 +# it under the terms of the GNU General Public License as published by
1974 +# the Free Software Foundation; either version 2 of the License, or
1975 +# (at your option) any later version.
1977 +# This program is distributed in the hope that it will be useful,
1978 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1979 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1980 +# GNU General Public License for more details.
1982 +# You should have received a copy of the GNU General Public License
1983 +# along with this program; if not, write to the Free Software
1984 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1987 +File-based Hierarchical Storage Management (FHSM)
1988 +----------------------------------------------------------------------
1989 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1990 +storage world. Aufs provides this feature as file-based with multiple
1991 +writable branches, based upon the principle of "Colder, the Lower".
1992 +Here the word "colder" means that the less used files, and "lower" means
1993 +that the position in the order of the stacked branches vertically.
1994 +These multiple writable branches are prioritized, ie. the topmost one
1995 +should be the fastest drive and be used heavily.
1997 +o Characters in aufs FHSM story
1998 +- aufs itself and a new branch attribute.
1999 +- a new ioctl interface to move-down and to establish a connection with
2000 + the daemon ("move-down" is a converse of "copy-up").
2001 +- userspace tool and daemon.
2003 +The userspace daemon establishes a connection with aufs and waits for
2004 +the notification. The notified information is very similar to struct
2005 +statfs containing the number of consumed blocks and inodes.
2006 +When the consumed blocks/inodes of a branch exceeds the user-specified
2007 +upper watermark, the daemon activates its move-down process until the
2008 +consumed blocks/inodes reaches the user-specified lower watermark.
2010 +The actual move-down is done by aufs based upon the request from
2011 +user-space since we need to maintain the inode number and the internal
2012 +pointer arrays in aufs.
2014 +Currently aufs FHSM handles the regular files only. Additionally they
2015 +must not be hard-linked nor pseudo-linked.
2018 +o Cowork of aufs and the user-space daemon
2019 + During the userspace daemon established the connection, aufs sends a
2020 + small notification to it whenever aufs writes something into the
2021 + writable branch. But it may cost high since aufs issues statfs(2)
2022 + internally. So user can specify a new option to cache the
2023 + info. Actually the notification is controlled by these factors.
2024 + + the specified cache time.
2025 + + classified as "force" by aufs internally.
2026 + Until the specified time expires, aufs doesn't send the info
2027 + except the forced cases. When aufs decide forcing, the info is always
2028 + notified to userspace.
2029 + For example, the number of free inodes is generally large enough and
2030 + the shortage of it happens rarely. So aufs doesn't force the
2031 + notification when creating a new file, directory and others. This is
2032 + the typical case which aufs doesn't force.
2033 + When aufs writes the actual filedata and the files consumes any of new
2034 + blocks, the aufs forces notifying.
2037 +o Interfaces in aufs
2038 +- New branch attribute.
2040 + Specifies that the branch is managed by FHSM feature. In other word,
2041 + participant in the FHSM.
2042 + When nofhsm is set to the branch, it will not be the source/target
2043 + branch of the move-down operation. This attribute is set
2044 + independently from coo and moo attributes, and if you want full
2045 + FHSM, you should specify them as well.
2046 +- New mount option.
2048 + Specifies a second to suppress many less important info to be
2051 + + AUFS_CTL_FHSM_FD
2052 + create a new file descriptor which userspace can read the notification
2053 + (a subset of struct statfs) from aufs.
2054 +- Module parameter 'brs'
2055 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2057 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2058 + When there are two or more branches with fhsm attributes,
2059 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2060 + terminates it. As a result of remounting and branch-manipulation, the
2061 + number of branches with fhsm attribute can be one. In this case,
2062 + /sbin/mount.aufs will terminate the user-space daemon.
2065 +Finally the operation is done as these steps in kernel-space.
2067 + + no one else is using the file.
2068 + + the file is not hard-linked.
2069 + + the file is not pseudo-linked.
2070 + + the file is a regular file.
2071 + + the parent dir is not opaqued.
2072 +- find the target writable branch.
2073 +- make sure the file is not whiteout-ed by the upper (than the target)
2075 +- make the parent dir on the target branch.
2076 +- mutex lock the inode on the branch.
2077 +- unlink the whiteout on the target branch (if exists).
2078 +- lookup and create the whiteout-ed temporary name on the target branch.
2079 +- copy the file as the whiteout-ed temporary name on the target branch.
2080 +- rename the whiteout-ed temporary name to the original name.
2081 +- unlink the file on the source branch.
2082 +- maintain the internal pointer array and the external inode number
2084 +- maintain the timestamps and other attributes of the parent dir and the
2087 +And of course, in every step, an error may happen. So the operation
2088 +should restore the original file state after an error happens.
2089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2090 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2091 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2017-05-06 22:16:52.774886674 +0200
2094 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2096 +# This program is free software; you can redistribute it and/or modify
2097 +# it under the terms of the GNU General Public License as published by
2098 +# the Free Software Foundation; either version 2 of the License, or
2099 +# (at your option) any later version.
2101 +# This program is distributed in the hope that it will be useful,
2102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2104 +# GNU General Public License for more details.
2106 +# You should have received a copy of the GNU General Public License
2107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2109 +mmap(2) -- File Memory Mapping
2110 +----------------------------------------------------------------------
2111 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2112 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2114 +This approach is simple and good, but there is one problem.
2115 +Under /proc, several entries show the mmapped files by its path (with
2116 +device and inode number), and the printed path will be the path on the
2117 +branch fs's instead of virtual aufs's.
2118 +This is not a problem in most cases, but some utilities lsof(1) (and its
2119 +user) may expect the path on aufs.
2121 +To address this issue, aufs adds a new member called vm_prfile in struct
2122 +vm_area_struct (and struct vm_region). The original vm_file points to
2123 +the file on the branch fs in order to handle everything correctly as
2124 +usual. The new vm_prfile points to a virtual file in aufs, and the
2125 +show-functions in procfs refers to vm_prfile if it is set.
2126 +Also we need to maintain several other places where touching vm_file
2128 +- fork()/clone() copies vma and the reference count of vm_file is
2130 +- merging vma maintains the ref count too.
2132 +This is not a good approach. It just fakes the printed path. But it
2133 +leaves all behaviour around f_mapping unchanged. This is surely an
2135 +Actually aufs had adopted another complicated approach which calls
2136 +generic_file_mmap() and handles struct vm_operations_struct. In this
2137 +approach, aufs met a hard problem and I could not solve it without
2138 +switching the approach.
2140 +There may be one more another approach which is
2141 +- bind-mount the branch-root onto the aufs-root internally
2142 +- grab the new vfsmount (ie. struct mount)
2143 +- lazy-umount the branch-root internally
2144 +- in open(2) the aufs-file, open the branch-file with the hidden
2145 + vfsmount (instead of the original branch's vfsmount)
2146 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2147 + but it may be possible from userspace by the mount helper.
2149 +Adding the internal hidden vfsmount and using it in opening a file, the
2150 +file path under /proc will be printed correctly. This approach looks
2151 +smarter, but is not possible I am afraid.
2152 +- aufs-root may be bind-mount later. when it happens, another hidden
2153 + vfsmount will be required.
2154 +- it is hard to get the chance to bind-mount and lazy-umount
2155 + + in kernel-space, FS can have vfsmount in open(2) via
2156 + file->f_path, and aufs can know its vfsmount. But several locks are
2157 + already acquired, and if aufs tries to bind-mount and lazy-umount
2158 + here, then it may cause a deadlock.
2159 + + in user-space, bind-mount doesn't invoke the mount helper.
2160 +- since /proc shows dev and ino, aufs has to give vma these info. it
2161 + means a new member vm_prinode will be necessary. this is essentially
2162 + equivalent to vm_prfile described above.
2164 +I have to give up this "looks-smater" approach.
2165 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2166 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2167 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2017-05-06 22:16:52.774886674 +0200
2170 +# Copyright (C) 2014-2017 Junjiro R. Okajima
2172 +# This program is free software; you can redistribute it and/or modify
2173 +# it under the terms of the GNU General Public License as published by
2174 +# the Free Software Foundation; either version 2 of the License, or
2175 +# (at your option) any later version.
2177 +# This program is distributed in the hope that it will be useful,
2178 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2179 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180 +# GNU General Public License for more details.
2182 +# You should have received a copy of the GNU General Public License
2183 +# along with this program; if not, write to the Free Software
2184 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2187 +Listing XATTR/EA and getting the value
2188 +----------------------------------------------------------------------
2189 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2190 +shows the values from the topmost existing file. This behaviour is good
2191 +for the non-dir entries since the bahaviour exactly matches the shown
2192 +information. But for the directories, aufs considers all the same named
2193 +entries on the lower branches. Which means, if one of the lower entry
2194 +rejects readdir call, then aufs returns an error even if the topmost
2195 +entry allows it. This behaviour is necessary to respect the branch fs's
2196 +security, but can make users confused since the user-visible standard
2197 +attributes don't match the behaviour.
2198 +To address this issue, aufs has a mount option called dirperm1 which
2199 +checks the permission for the topmost entry only, and ignores the lower
2200 +entry's permission.
2202 +A similar issue can happen around XATTR.
2203 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2204 +always set. Otherwise these very unpleasant situation would happen.
2205 +- listxattr(2) may return the duplicated entries.
2206 +- users may not be able to remove or reset the XATTR forever,
2209 +XATTR/EA support in the internal (copy,move)-(up,down)
2210 +----------------------------------------------------------------------
2211 +Generally the extended attributes of inode are categorized as these.
2212 +- "security" for LSM and capability.
2213 +- "system" for posix ACL, 'acl' mount option is required for the branch
2215 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2216 +- "user" for userspace, 'user_xattr' mount option is required for the
2217 + branch fs generally.
2219 +Moreover there are some other categories. Aufs handles these rather
2220 +unpopular categories as the ordinary ones, ie. there is no special
2221 +condition nor exception.
2223 +In copy-up, the support for XATTR on the dst branch may differ from the
2224 +src branch. In this case, the copy-up operation will get an error and
2225 +the original user operation which triggered the copy-up will fail. It
2226 +can happen that even all copy-up will fail.
2227 +When both of src and dst branches support XATTR and if an error occurs
2228 +during copying XATTR, then the copy-up should fail obviously. That is a
2229 +good reason and aufs should return an error to userspace. But when only
2230 +the src branch support that XATTR, aufs should not return an error.
2231 +For example, the src branch supports ACL but the dst branch doesn't
2232 +because the dst branch may natively un-support it or temporary
2233 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2234 +may NOT return an error even if the XATTR is not supported. It is
2235 +totally up to the branch fs.
2237 +Anyway when the aufs internal copy-up gets an error from the dst branch
2238 +fs, then aufs tries removing the just copied entry and returns the error
2239 +to the userspace. The worst case of this situation will be all copy-up
2242 +For the copy-up operation, there two basic approaches.
2243 +- copy the specified XATTR only (by category above), and return the
2244 + error unconditionally if it happens.
2245 +- copy all XATTR, and ignore the error on the specified category only.
2247 +In order to support XATTR and to implement the correct behaviour, aufs
2248 +chooses the latter approach and introduces some new branch attributes,
2249 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2250 +They correspond to the XATTR namespaces (see above). Additionally, to be
2251 +convenient, "icex" is also provided which means all "icex*" attributes
2252 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2254 +The meaning of these attributes is to ignore the error from setting
2255 +XATTR on that branch.
2256 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2257 +error from the dst branch according to the specified attributes.
2259 +Some XATTR may have its default value. The default value may come from
2260 +the parent dir or the environment. If the default value is set at the
2261 +file creating-time, it will be overwritten by copy-up.
2262 +Some contradiction may happen I am afraid.
2263 +Do we need another attribute to stop copying XATTR? I am unsure. For
2264 +now, aufs implements the branch attributes to ignore the error.
2265 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2266 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2267 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2017-05-06 22:16:52.774886674 +0200
2270 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2272 +# This program is free software; you can redistribute it and/or modify
2273 +# it under the terms of the GNU General Public License as published by
2274 +# the Free Software Foundation; either version 2 of the License, or
2275 +# (at your option) any later version.
2277 +# This program is distributed in the hope that it will be useful,
2278 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2279 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2280 +# GNU General Public License for more details.
2282 +# You should have received a copy of the GNU General Public License
2283 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2285 +Export Aufs via NFS
2286 +----------------------------------------------------------------------
2287 +Here is an approach.
2288 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2290 +- iget_locked(): initialize aufs inode generation for a new inode, and
2291 + store it in xigen file.
2292 +- destroy_inode(): increment aufs inode generation and store it in xigen
2293 + file. it is necessary even if it is not unlinked, because any data of
2294 + inode may be changed by UDBA.
2295 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2296 + build file handle by
2297 + + branch id (4 bytes)
2298 + + superblock generation (4 bytes)
2299 + + inode number (4 or 8 bytes)
2300 + + parent dir inode number (4 or 8 bytes)
2301 + + inode generation (4 bytes))
2302 + + return value of exportfs_encode_fh() for the parent on a branch (4
2304 + + file handle for a branch (by exportfs_encode_fh())
2306 + + find the index of a branch from its id in handle, and check it is
2307 + still exist in aufs.
2308 + + 1st level: get the inode number from handle and search it in cache.
2309 + + 2nd level: if not found in cache, get the parent inode number from
2310 + the handle and search it in cache. and then open the found parent
2311 + dir, find the matching inode number by vfs_readdir() and get its
2312 + name, and call lookup_one_len() for the target dentry.
2313 + + 3rd level: if the parent dir is not cached, call
2314 + exportfs_decode_fh() for a branch and get the parent on a branch,
2315 + build a pathname of it, convert it a pathname in aufs, call
2316 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2318 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2319 + for every branch, but not itself. to get this, (currently) aufs
2320 + searches in current->nsproxy->mnt_ns list. it may not be a good
2321 + idea, but I didn't get other approach.
2322 + + test the generation of the gotten inode.
2323 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2324 + convert it into ESTALE for NFSD.
2325 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2326 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2327 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2328 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2329 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2017-05-06 22:16:52.774886674 +0200
2332 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2334 +# This program is free software; you can redistribute it and/or modify
2335 +# it under the terms of the GNU General Public License as published by
2336 +# the Free Software Foundation; either version 2 of the License, or
2337 +# (at your option) any later version.
2339 +# This program is distributed in the hope that it will be useful,
2340 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2341 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2342 +# GNU General Public License for more details.
2344 +# You should have received a copy of the GNU General Public License
2345 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2347 +Show Whiteout Mode (shwh)
2348 +----------------------------------------------------------------------
2349 +Generally aufs hides the name of whiteouts. But in some cases, to show
2350 +them is very useful for users. For instance, creating a new middle layer
2351 +(branch) by merging existing layers.
2353 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2354 +When you have three branches,
2355 +- Bottom: 'system', squashfs (underlying base system), read-only
2356 +- Middle: 'mods', squashfs, read-only
2357 +- Top: 'overlay', ram (tmpfs), read-write
2359 +The top layer is loaded at boot time and saved at shutdown, to preserve
2360 +the changes made to the system during the session.
2361 +When larger changes have been made, or smaller changes have accumulated,
2362 +the size of the saved top layer data grows. At this point, it would be
2363 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2364 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2365 +restoring save and load speed.
2367 +This merging is simplified by the use of another aufs mount, of just the
2368 +two overlay branches using the 'shwh' option.
2369 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2370 + aufs /livesys/merge_union
2372 +A merged view of these two branches is then available at
2373 +/livesys/merge_union, and the new feature is that the whiteouts are
2375 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2376 +writing to all branches. Also the default mode for all branches is 'ro'.
2377 +It is now possible to save the combined contents of the two overlay
2378 +branches to a new squashfs, e.g.:
2379 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2381 +This new squashfs archive can be stored on the boot device and the
2382 +initramfs will use it to replace the old one at the next boot.
2383 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2384 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2385 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2017-05-06 22:16:52.774886674 +0200
2388 +# Copyright (C) 2010-2017 Junjiro R. Okajima
2390 +# This program is free software; you can redistribute it and/or modify
2391 +# it under the terms of the GNU General Public License as published by
2392 +# the Free Software Foundation; either version 2 of the License, or
2393 +# (at your option) any later version.
2395 +# This program is distributed in the hope that it will be useful,
2396 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2397 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2398 +# GNU General Public License for more details.
2400 +# You should have received a copy of the GNU General Public License
2401 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2403 +Dynamically customizable FS operations
2404 +----------------------------------------------------------------------
2405 +Generally FS operations (struct inode_operations, struct
2406 +address_space_operations, struct file_operations, etc.) are defined as
2407 +"static const", but it never means that FS have only one set of
2408 +operation. Some FS have multiple sets of them. For instance, ext2 has
2409 +three sets, one for XIP, for NOBH, and for normal.
2410 +Since aufs overrides and redirects these operations, sometimes aufs has
2411 +to change its behaviour according to the branch FS type. More importantly
2412 +VFS acts differently if a function (member in the struct) is set or
2413 +not. It means aufs should have several sets of operations and select one
2414 +among them according to the branch FS definition.
2416 +In order to solve this problem and not to affect the behaviour of VFS,
2417 +aufs defines these operations dynamically. For instance, aufs defines
2418 +dummy direct_IO function for struct address_space_operations, but it may
2419 +not be set to the address_space_operations actually. When the branch FS
2420 +doesn't have it, aufs doesn't set it to its address_space_operations
2421 +while the function definition itself is still alive. So the behaviour
2422 +itself will not change, and it will return an error when direct_IO is
2425 +The lifetime of these dynamically generated operation object is
2426 +maintained by aufs branch object. When the branch is removed from aufs,
2427 +the reference counter of the object is decremented. When it reaches
2428 +zero, the dynamically generated operation object will be freed.
2430 +This approach is designed to support AIO (io_submit), Direct I/O and
2432 +Currently this approach is applied to address_space_operations for
2433 +regular files only.
2434 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2435 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2436 +++ linux/Documentation/filesystems/aufs/README 2017-05-06 22:16:52.774886674 +0200
2439 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2445 +----------------------------------------
2446 +In the early days, aufs was entirely re-designed and re-implemented
2447 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2448 +improvements and implementations, it becomes totally different from
2449 +Unionfs while keeping the basic features.
2450 +Recently, Unionfs Version 2.x series begin taking some of the same
2451 +approaches to aufs1's.
2452 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2453 +University and his team.
2455 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2456 +If you want older kernel version support, try aufs2-2.6.git or
2457 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2459 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2460 + According to Christoph Hellwig, linux rejects all union-type
2461 + filesystems but UnionMount.
2462 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2464 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2465 + UnionMount, and he pointed out an issue around a directory mutex
2466 + lock and aufs addressed it. But it is still unsure whether aufs will
2467 + be merged (or any other union solution).
2468 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2472 +----------------------------------------
2473 +- unite several directories into a single virtual filesystem. The member
2474 + directory is called as a branch.
2475 +- you can specify the permission flags to the branch, which are 'readonly',
2476 + 'readwrite' and 'whiteout-able.'
2477 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2478 + readonly branch are modifiable logically.
2479 +- dynamic branch manipulation, add, del.
2482 +Also there are many enhancements in aufs, such as:
2483 +- test only the highest one for the directory permission (dirperm1)
2484 +- copyup on open (coo=)
2485 +- 'move' policy for copy-up between two writable branches, after
2486 + checking free space.
2488 +- readdir(3) in userspace.
2489 +- keep inode number by external inode number table
2490 +- keep the timestamps of file/dir in internal copyup operation
2491 +- seekable directory, supporting NFS readdir.
2492 +- whiteout is hardlinked in order to reduce the consumption of inodes
2494 +- do not copyup, nor create a whiteout when it is unnecessary
2495 +- revert a single systemcall when an error occurs in aufs
2496 +- remount interface instead of ioctl
2497 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2498 +- loopback mounted filesystem as a branch
2499 +- kernel thread for removing the dir who has a plenty of whiteouts
2500 +- support copyup sparse file (a file which has a 'hole' in it)
2501 +- default permission flags for branches
2502 +- selectable permission flags for ro branch, whether whiteout can
2505 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2506 +- support multiple writable branches, some policies to select one
2507 + among multiple writable branches.
2508 +- a new semantics for link(2) and rename(2) to support multiple
2509 + writable branches.
2510 +- no glibc changes are required.
2511 +- pseudo hardlink (hardlink over branches)
2512 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2513 + including NFS or remote filesystem branch.
2514 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2517 +Currently these features are dropped temporary from aufs4.
2518 +See design/08plan.txt in detail.
2519 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2521 +- statistics of aufs thread (/sys/fs/aufs/stat)
2523 +Features or just an idea in the future (see also design/*.txt),
2524 +- reorder the branch index without del/re-add.
2525 +- permanent xino files for NFSD
2526 +- an option for refreshing the opened files after add/del branches
2527 +- light version, without branch manipulation. (unnecessary?)
2528 +- copyup in userspace
2529 +- inotify in userspace
2534 +----------------------------------------
2535 +There are three GIT trees for aufs4, aufs4-linux.git,
2536 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2538 +While the aufs-util is always necessary, you need either of aufs4-linux
2539 +or aufs4-standalone.
2541 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2542 +git://git.kernel.org/.../torvalds/linux.git.
2543 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2544 +build aufs4 as an external kernel module.
2545 +Several extra patches are not included in this tree. Only
2546 +aufs4-standalone tree contains them. They are described in the later
2547 +section "Configuration and Compilation."
2549 +On the other hand, the aufs4-standalone tree has only aufs source files
2550 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2551 +But you need to apply all aufs patches manually.
2553 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2554 +represents the linux kernel version, "linux-4.x". For instance,
2555 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2556 +"aufs4.x-rcN" branch.
2559 +$ git clone --reference /your/linux/git/tree \
2560 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2561 +- if you don't have linux GIT tree, then remove "--reference ..."
2562 +$ cd aufs4-linux.git
2563 +$ git checkout origin/aufs4.0
2565 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2566 +leave the patch-work to GIT.
2567 +$ cd /your/linux/git/tree
2568 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2570 +$ git checkout -b my4.0 v4.0
2571 +$ (add your local change...)
2572 +$ git pull aufs4 aufs4.0
2573 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2574 +- you may need to solve some conflicts between your_changes and
2575 + aufs4.0. in this case, git-rerere is recommended so that you can
2576 + solve the similar conflicts automatically when you upgrade to 4.1 or
2577 + later in the future.
2579 +o aufs4-standalone tree
2580 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2581 +$ cd aufs4-standalone.git
2582 +$ git checkout origin/aufs4.0
2585 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2586 +- note that the public aufs-util.git is on SourceForge instead of
2589 +$ git checkout origin/aufs4.0
2591 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2592 +The minor version number, 'x' in '4.x', of aufs may not always
2593 +follow the minor version number of the kernel.
2594 +Because changes in the kernel that cause the use of a new
2595 +minor version number do not always require changes to aufs-util.
2597 +Since aufs-util has its own minor version number, you may not be
2598 +able to find a GIT branch in aufs-util for your kernel's
2599 +exact minor version number.
2600 +In this case, you should git-checkout the branch for the
2601 +nearest lower number.
2603 +For (an unreleased) example:
2604 +If you are using "linux-4.10" and the "aufs4.10" branch
2605 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2606 +or something numerically smaller is the branch for your kernel.
2608 +Also you can view all branches by
2612 +3. Configuration and Compilation
2613 +----------------------------------------
2614 +Make sure you have git-checkout'ed the correct branch.
2616 +For aufs4-linux tree,
2617 +- enable CONFIG_AUFS_FS.
2618 +- set other aufs configurations if necessary.
2620 +For aufs4-standalone tree,
2621 +There are several ways to build.
2624 +- apply ./aufs4-kbuild.patch to your kernel source files.
2625 +- apply ./aufs4-base.patch too.
2626 +- apply ./aufs4-mmap.patch too.
2627 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2628 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2629 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2630 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2631 +- enable CONFIG_AUFS_FS, you can select either
2633 +- and build your kernel as usual.
2634 +- install the built kernel.
2635 + Note: Since linux-3.9, every filesystem module requires an alias
2636 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2637 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2638 +- install the header files too by "make headers_install" to the
2639 + directory where you specify. By default, it is $PWD/usr.
2640 + "make help" shows a brief note for headers_install.
2641 +- and reboot your system.
2644 +- module only (CONFIG_AUFS_FS=m).
2645 +- apply ./aufs4-base.patch to your kernel source files.
2646 +- apply ./aufs4-mmap.patch too.
2647 +- apply ./aufs4-standalone.patch too.
2648 +- build your kernel, don't forget "make headers_install", and reboot.
2649 +- edit ./config.mk and set other aufs configurations if necessary.
2650 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2651 + every aufs configurations.
2652 +- build the module by simple "make".
2653 + Note: Since linux-3.9, every filesystem module requires an alias
2654 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2655 + modules.aliases file.
2656 +- you can specify ${KDIR} make variable which points to your kernel
2658 +- install the files
2659 + + run "make install" to install the aufs module, or copy the built
2660 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2661 + + run "make install_headers" (instead of headers_install) to install
2662 + the modified aufs header file (you can specify DESTDIR which is
2663 + available in aufs standalone version's Makefile only), or copy
2664 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2665 + you like manually. By default, the target directory is $PWD/usr.
2666 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2667 + kernel source tree.
2669 +Note: The header file aufs_type.h is necessary to build aufs-util
2670 + as well as "make headers_install" in the kernel source tree.
2671 + headers_install is subject to be forgotten, but it is essentially
2672 + necessary, not only for building aufs-util.
2673 + You may not meet problems without headers_install in some older
2677 +- read README in aufs-util, build and install it
2678 +- note that your distribution may contain an obsoleted version of
2679 + aufs_type.h in /usr/include/linux or something. When you build aufs
2680 + utilities, make sure that your compiler refers the correct aufs header
2681 + file which is built by "make headers_install."
2682 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2683 + then run "make install_ulib" too. And refer to the aufs manual in
2686 +There several other patches in aufs4-standalone.git. They are all
2687 +optional. When you meet some problems, they will help you.
2688 +- aufs4-loopback.patch
2689 + Supports a nested loopback mount in a branch-fs. This patch is
2690 + unnecessary until aufs produces a message like "you may want to try
2691 + another patch for loopback file".
2693 + Modifies a system global kernel internal function get_next_ino() in
2694 + order to stop assigning 0 for an inode-number. Not directly related to
2695 + aufs, but recommended generally.
2697 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2698 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2699 + duplication of inode number, which is important for backup tools and
2700 + other utilities. When you find aufs XINO files for tmpfs branch
2701 + growing too much, try this patch.
2702 +- lockdep-debug.patch
2703 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2704 + also a caller of VFS functions for branch filesystems, subclassing of
2705 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2706 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2707 + need to apply this debug patch to expand several constant values.
2708 + If don't know what LOCKDEP, then you don't have apply this patch.
2712 +----------------------------------------
2713 +At first, make sure aufs-util are installed, and please read the aufs
2714 +manual, aufs.5 in aufs-util.git tree.
2718 +$ mkdir /tmp/rw /tmp/aufs
2719 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2721 +Here is another example. The result is equivalent.
2722 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2724 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2725 +# mount -o remount,append:${HOME} /tmp/aufs
2727 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2728 +you modify a file under /tmp/aufs, the one on your home directory is
2729 +not affected, instead the same named file will be newly created under
2730 +/tmp/rw. And all of your modification to a file will be applied to
2731 +the one under /tmp/rw. This is called the file based Copy on Write
2733 +Aufs mount options are described in aufs.5.
2734 +If you run chroot or something and make your aufs as a root directory,
2735 +then you need to customize the shutdown script. See the aufs manual in
2738 +Additionally, there are some sample usages of aufs which are a
2739 +diskless system with network booting, and LiveCD over NFS.
2740 +See sample dir in CVS tree on SourceForge.
2744 +----------------------------------------
2745 +When you have any problems or strange behaviour in aufs, please let me
2747 +- /proc/mounts (instead of the output of mount(8))
2748 +- /sys/module/aufs/*
2749 +- /sys/fs/aufs/* (if you have them)
2750 +- /debug/aufs/* (if you have them)
2751 +- linux kernel version
2752 + if your kernel is not plain, for example modified by distributor,
2753 + the url where i can download its source is necessary too.
2754 +- aufs version which was printed at loading the module or booting the
2755 + system, instead of the date you downloaded.
2756 +- configuration (define/undefine CONFIG_AUFS_xxx)
2757 +- kernel configuration or /proc/config.gz (if you have it)
2758 +- behaviour which you think to be incorrect
2759 +- actual operation, reproducible one is better
2760 +- mailto: aufs-users at lists.sourceforge.net
2762 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2763 +and Feature Requests) on SourceForge. Please join and write to
2767 +6. Acknowledgements
2768 +----------------------------------------
2769 +Thanks to everyone who have tried and are using aufs, whoever
2770 +have reported a bug or any feedback.
2772 +Especially donators:
2773 +Tomas Matejicek(slax.org) made a donation (much more than once).
2774 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2775 + scripts) is making "doubling" donations.
2776 + Unfortunately I cannot list all of the donators, but I really
2778 + It ends Aug 2010, but the ordinary donation URL is still available.
2779 + <http://sourceforge.net/donate/index.php?group_id=167503>
2780 +Dai Itasaka made a donation (2007/8).
2781 +Chuck Smith made a donation (2008/4, 10 and 12).
2782 +Henk Schoneveld made a donation (2008/9).
2783 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2784 +Francois Dupoux made a donation (2008/11).
2785 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2786 + aufs2 GIT tree (2009/2).
2787 +William Grant made a donation (2009/3).
2788 +Patrick Lane made a donation (2009/4).
2789 +The Mail Archive (mail-archive.com) made donations (2009/5).
2790 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2791 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2792 +Pavel Pronskiy made a donation (2011/2).
2793 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2794 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2795 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2797 +Sam Liddicott made a donation (2011/9).
2798 +Era Scarecrow made a donation (2013/4).
2799 +Bor Ratajc made a donation (2013/4).
2800 +Alessandro Gorreta made a donation (2013/4).
2801 +POIRETTE Marc made a donation (2013/4).
2802 +Alessandro Gorreta made a donation (2013/4).
2803 +lauri kasvandik made a donation (2013/5).
2804 +"pemasu from Finland" made a donation (2013/7).
2805 +The Parted Magic Project made a donation (2013/9 and 11).
2806 +Pavel Barta made a donation (2013/10).
2807 +Nikolay Pertsev made a donation (2014/5).
2808 +James B made a donation (2014/7 and 2015/7).
2809 +Stefano Di Biase made a donation (2014/8).
2810 +Daniel Epellei made a donation (2015/1).
2811 +OmegaPhil made a donation (2016/1).
2812 +Tomasz Szewczyk made a donation (2016/4).
2813 +James Burry made a donation (2016/12).
2815 +Thank you very much.
2816 +Donations are always, including future donations, very important and
2817 +helpful for me to keep on developing aufs.
2821 +----------------------------------------
2822 +If you are an experienced user, no explanation is needed. Aufs is
2823 +just a linux filesystem.
2828 +# Local variables: ;
2831 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2832 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2833 +++ linux/fs/aufs/aufs.h 2017-05-06 22:16:52.774886674 +0200
2836 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2838 + * This program, aufs is free software; you can redistribute it and/or modify
2839 + * it under the terms of the GNU General Public License as published by
2840 + * the Free Software Foundation; either version 2 of the License, or
2841 + * (at your option) any later version.
2843 + * This program is distributed in the hope that it will be useful,
2844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846 + * GNU General Public License for more details.
2848 + * You should have received a copy of the GNU General Public License
2849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2853 + * all header files
2861 +#define AuStub(type, name, body, ...) \
2862 + static inline type name(__VA_ARGS__) { body; }
2864 +#define AuStubVoid(name, ...) \
2865 + AuStub(void, name, , __VA_ARGS__)
2866 +#define AuStubInt0(name, ...) \
2867 + AuStub(int, name, return 0, __VA_ARGS__)
2871 +#include "branch.h"
2874 +#include "dbgaufs.h"
2875 +#include "dentry.h"
2879 +#include "fstype.h"
2882 +#include "module.h"
2887 +#include "sysaufs.h"
2892 +#endif /* __KERNEL__ */
2893 +#endif /* __AUFS_H__ */
2894 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2895 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2896 +++ linux/fs/aufs/branch.c 2017-05-06 22:16:52.774886674 +0200
2899 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2901 + * This program, aufs is free software; you can redistribute it and/or modify
2902 + * it under the terms of the GNU General Public License as published by
2903 + * the Free Software Foundation; either version 2 of the License, or
2904 + * (at your option) any later version.
2906 + * This program is distributed in the hope that it will be useful,
2907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2909 + * GNU General Public License for more details.
2911 + * You should have received a copy of the GNU General Public License
2912 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2916 + * branch management
2919 +#include <linux/compat.h>
2920 +#include <linux/statfs.h>
2924 + * free a single branch
2926 +static void au_br_do_free(struct au_branch *br)
2929 + struct au_wbr *wbr;
2930 + struct au_dykey **key;
2932 + au_hnotify_fin_br(br);
2934 + if (br->br_xino.xi_file)
2935 + fput(br->br_xino.xi_file);
2936 + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--)
2937 + AuDebugOn(br->br_xino.xi_nondir.array[i]);
2938 + au_delayed_kfree(br->br_xino.xi_nondir.array);
2940 + AuDebugOn(au_br_count(br));
2941 + au_br_count_fin(br);
2945 + for (i = 0; i < AuBrWh_Last; i++)
2946 + dput(wbr->wbr_wh[i]);
2947 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2948 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2951 + if (br->br_fhsm) {
2952 + au_br_fhsm_fin(br->br_fhsm);
2953 + au_delayed_kfree(br->br_fhsm);
2956 + key = br->br_dykey;
2957 + for (i = 0; i < AuBrDynOp; i++, key++)
2963 + /* recursive lock, s_umount of branch's */
2965 + path_put(&br->br_path);
2968 + au_delayed_kfree(wbr);
2969 + au_delayed_kfree(br);
2973 + * frees all branches
2975 +void au_br_free(struct au_sbinfo *sbinfo)
2977 + aufs_bindex_t bmax;
2978 + struct au_branch **br;
2980 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2982 + bmax = sbinfo->si_bbot + 1;
2983 + br = sbinfo->si_branch;
2985 + au_br_do_free(*br++);
2989 + * find the index of a branch which is specified by @br_id.
2991 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2993 + aufs_bindex_t bindex, bbot;
2995 + bbot = au_sbbot(sb);
2996 + for (bindex = 0; bindex <= bbot; bindex++)
2997 + if (au_sbr_id(sb, bindex) == br_id)
3002 +/* ---------------------------------------------------------------------- */
3008 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3009 + struct dentry *h_root)
3011 + if (unlikely(h_adding == h_root
3012 + || au_test_loopback_overlap(sb, h_adding)))
3014 + if (h_adding->d_sb != h_root->d_sb)
3016 + return au_test_subdir(h_adding, h_root)
3017 + || au_test_subdir(h_root, h_adding);
3021 + * returns a newly allocated branch. @new_nbranch is a number of branches
3022 + * after adding a branch.
3024 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3027 + struct au_branch *add_branch;
3028 + struct dentry *root;
3029 + struct inode *inode;
3033 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3034 + if (unlikely(!add_branch))
3036 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3037 + add_branch->br_xino.xi_nondir.array
3038 + = kzalloc(sizeof(ino_t) * add_branch->br_xino.xi_nondir.total,
3040 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3043 + err = au_hnotify_init_br(add_branch, perm);
3044 + if (unlikely(err))
3045 + goto out_xinondir;
3047 + if (au_br_writable(perm)) {
3048 + /* may be freed separately at changing the branch permission */
3049 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3051 + if (unlikely(!add_branch->br_wbr))
3055 + if (au_br_fhsm(perm)) {
3056 + err = au_fhsm_br_alloc(add_branch);
3057 + if (unlikely(err))
3061 + root = sb->s_root;
3062 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3064 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3066 + inode = d_inode(root);
3067 + err = au_hinode_realloc(au_ii(inode), new_nbranch, /*may_shrink*/0);
3070 + return add_branch; /* success */
3073 + if (add_branch->br_wbr)
3074 + au_delayed_kfree(add_branch->br_wbr);
3076 + au_hnotify_fin_br(add_branch);
3078 + au_delayed_kfree(add_branch->br_xino.xi_nondir.array);
3080 + au_delayed_kfree(add_branch);
3082 + return ERR_PTR(err);
3086 + * test if the branch permission is legal or not.
3088 +static int test_br(struct inode *inode, int brperm, char *path)
3092 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3097 + pr_err("write permission for readonly mount or inode, %s\n", path);
3105 + * 0: success, the caller will add it
3106 + * plus: success, it is already unified, the caller should ignore it
3109 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3112 + aufs_bindex_t bbot, bindex;
3113 + struct dentry *root, *h_dentry;
3114 + struct inode *inode, *h_inode;
3116 + root = sb->s_root;
3117 + bbot = au_sbbot(sb);
3118 + if (unlikely(bbot >= 0
3119 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3123 + pr_err("%s duplicated\n", add->pathname);
3128 + err = -ENOSPC; /* -E2BIG; */
3129 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3130 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3131 + pr_err("number of branches exceeded %s\n", add->pathname);
3136 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3137 + pr_err("bad index %d\n", add->bindex);
3141 + inode = d_inode(add->path.dentry);
3143 + if (unlikely(!inode->i_nlink)) {
3144 + pr_err("no existence %s\n", add->pathname);
3149 + if (unlikely(inode->i_sb == sb)) {
3150 + pr_err("%s must be outside\n", add->pathname);
3154 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3155 + pr_err("unsupported filesystem, %s (%s)\n",
3156 + add->pathname, au_sbtype(inode->i_sb));
3160 + if (unlikely(inode->i_sb->s_stack_depth)) {
3161 + pr_err("already stacked, %s (%s)\n",
3162 + add->pathname, au_sbtype(inode->i_sb));
3166 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3167 + if (unlikely(err))
3171 + return 0; /* success */
3174 + for (bindex = 0; bindex <= bbot; bindex++)
3175 + if (unlikely(test_overlap(sb, add->path.dentry,
3176 + au_h_dptr(root, bindex)))) {
3177 + pr_err("%s is overlapped\n", add->pathname);
3182 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3183 + h_dentry = au_h_dptr(root, 0);
3184 + h_inode = d_inode(h_dentry);
3185 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3186 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3187 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3188 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3190 + i_uid_read(inode), i_gid_read(inode),
3191 + (inode->i_mode & S_IALLUGO),
3192 + i_uid_read(h_inode), i_gid_read(h_inode),
3193 + (h_inode->i_mode & S_IALLUGO));
3201 + * initialize or clean the whiteouts for an adding branch
3203 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3206 + int err, old_perm;
3207 + aufs_bindex_t bindex;
3208 + struct inode *h_inode;
3209 + struct au_wbr *wbr;
3210 + struct au_hinode *hdir;
3211 + struct dentry *h_dentry;
3213 + err = vfsub_mnt_want_write(au_br_mnt(br));
3214 + if (unlikely(err))
3218 + old_perm = br->br_perm;
3219 + br->br_perm = new_perm;
3222 + bindex = au_br_index(sb, br->br_id);
3223 + if (0 <= bindex) {
3224 + hdir = au_hi(d_inode(sb->s_root), bindex);
3225 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3227 + h_dentry = au_br_dentry(br);
3228 + h_inode = d_inode(h_dentry);
3229 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3232 + err = au_wh_init(br, sb);
3234 + wbr_wh_write_lock(wbr);
3235 + err = au_wh_init(br, sb);
3236 + wbr_wh_write_unlock(wbr);
3239 + au_hn_inode_unlock(hdir);
3241 + inode_unlock(h_inode);
3242 + vfsub_mnt_drop_write(au_br_mnt(br));
3243 + br->br_perm = old_perm;
3245 + if (!err && wbr && !au_br_writable(new_perm)) {
3246 + au_delayed_kfree(wbr);
3247 + br->br_wbr = NULL;
3254 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3258 + struct kstatfs kst;
3259 + struct au_wbr *wbr;
3262 + au_rw_init(&wbr->wbr_wh_rwsem);
3263 + atomic_set(&wbr->wbr_wh_running, 0);
3266 + * a limit for rmdir/rename a dir
3267 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3269 + err = vfs_statfs(&br->br_path, &kst);
3270 + if (unlikely(err))
3273 + if (kst.f_namelen >= NAME_MAX)
3274 + err = au_br_init_wh(sb, br, perm);
3276 + pr_err("%pd(%s), unsupported namelen %ld\n",
3278 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3284 +/* initialize a new branch */
3285 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3286 + struct au_opt_add *add)
3289 + struct inode *h_inode;
3292 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3293 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3294 + br->br_perm = add->perm;
3295 + br->br_path = add->path; /* set first, path_get() later */
3296 + spin_lock_init(&br->br_dykey_lock);
3297 + au_br_count_init(br);
3298 + atomic_set(&br->br_xino_running, 0);
3299 + br->br_id = au_new_br_id(sb);
3300 + AuDebugOn(br->br_id < 0);
3302 + if (au_br_writable(add->perm)) {
3303 + err = au_wbr_init(br, sb, add->perm);
3304 + if (unlikely(err))
3308 + if (au_opt_test(au_mntflags(sb), XINO)) {
3309 + h_inode = d_inode(add->path.dentry);
3310 + err = au_xino_br(sb, br, h_inode->i_ino,
3311 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3312 + if (unlikely(err)) {
3313 + AuDebugOn(br->br_xino.xi_file);
3318 + sysaufs_br_init(br);
3319 + path_get(&br->br_path);
3320 + goto out; /* success */
3323 + memset(&br->br_path, 0, sizeof(br->br_path));
3328 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3329 + struct au_branch *br, aufs_bindex_t bbot,
3330 + aufs_bindex_t amount)
3332 + struct au_branch **brp;
3334 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3336 + brp = sbinfo->si_branch + bindex;
3337 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3339 + sbinfo->si_bbot++;
3340 + if (unlikely(bbot < 0))
3341 + sbinfo->si_bbot = 0;
3344 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3345 + aufs_bindex_t bbot, aufs_bindex_t amount)
3347 + struct au_hdentry *hdp;
3349 + AuRwMustWriteLock(&dinfo->di_rwsem);
3351 + hdp = au_hdentry(dinfo, bindex);
3352 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3353 + au_h_dentry_init(hdp);
3355 + if (unlikely(bbot < 0))
3356 + dinfo->di_btop = 0;
3359 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3360 + aufs_bindex_t bbot, aufs_bindex_t amount)
3362 + struct au_hinode *hip;
3364 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3366 + hip = au_hinode(iinfo, bindex);
3367 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3368 + au_hinode_init(hip);
3370 + if (unlikely(bbot < 0))
3371 + iinfo->ii_btop = 0;
3374 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3375 + aufs_bindex_t bindex)
3377 + struct dentry *root, *h_dentry;
3378 + struct inode *root_inode, *h_inode;
3379 + aufs_bindex_t bbot, amount;
3381 + root = sb->s_root;
3382 + root_inode = d_inode(root);
3383 + bbot = au_sbbot(sb);
3384 + amount = bbot + 1 - bindex;
3385 + h_dentry = au_br_dentry(br);
3386 + au_sbilist_lock();
3387 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3388 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3389 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3390 + au_set_h_dptr(root, bindex, dget(h_dentry));
3391 + h_inode = d_inode(h_dentry);
3392 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3393 + au_sbilist_unlock();
3396 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3399 + aufs_bindex_t bbot, add_bindex;
3400 + struct dentry *root, *h_dentry;
3401 + struct inode *root_inode;
3402 + struct au_branch *add_branch;
3404 + root = sb->s_root;
3405 + root_inode = d_inode(root);
3406 + IMustLock(root_inode);
3407 + IiMustWriteLock(root_inode);
3408 + err = test_add(sb, add, remount);
3409 + if (unlikely(err < 0))
3413 + goto out; /* success */
3416 + bbot = au_sbbot(sb);
3417 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3418 + err = PTR_ERR(add_branch);
3419 + if (IS_ERR(add_branch))
3422 + err = au_br_init(add_branch, sb, add);
3423 + if (unlikely(err)) {
3424 + au_br_do_free(add_branch);
3428 + add_bindex = add->bindex;
3430 + au_br_do_add(sb, add_branch, add_bindex);
3432 + sysaufs_brs_del(sb, add_bindex);
3433 + au_br_do_add(sb, add_branch, add_bindex);
3434 + sysaufs_brs_add(sb, add_bindex);
3437 + h_dentry = add->path.dentry;
3438 + if (!add_bindex) {
3439 + au_cpup_attr_all(root_inode, /*force*/1);
3440 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3442 + au_add_nlink(root_inode, d_inode(h_dentry));
3445 + * this test/set prevents aufs from handling unnecesary notify events
3446 + * of xino files, in case of re-adding a writable branch which was
3447 + * once detached from aufs.
3449 + if (au_xino_brid(sb) < 0
3450 + && au_br_writable(add_branch->br_perm)
3451 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3452 + && add_branch->br_xino.xi_file
3453 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3454 + au_xino_brid_set(sb, add_branch->br_id);
3460 +/* ---------------------------------------------------------------------- */
3462 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3463 + unsigned long long max __maybe_unused,
3466 + unsigned long long n;
3467 + struct file **p, *f;
3468 + struct au_sphlhead *files;
3469 + struct au_finfo *finfo;
3473 + files = &au_sbi(sb)->si_files;
3474 + spin_lock(&files->spin);
3475 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3476 + f = finfo->fi_file;
3478 + && !special_file(file_inode(f)->i_mode)) {
3482 + AuDebugOn(n > max);
3485 + spin_unlock(&files->spin);
3490 +static struct file **au_farray_alloc(struct super_block *sb,
3491 + unsigned long long *max)
3493 + *max = au_nfiles(sb);
3494 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3497 +static void au_farray_free(struct file **a, unsigned long long max)
3499 + unsigned long long ull;
3501 + for (ull = 0; ull < max; ull++)
3507 +/* ---------------------------------------------------------------------- */
3513 +/* to show the line number, do not make it inlined function */
3514 +#define AuVerbose(do_info, fmt, ...) do { \
3516 + pr_info(fmt, ##__VA_ARGS__); \
3519 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3520 + aufs_bindex_t bbot)
3522 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3525 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3526 + aufs_bindex_t bbot)
3528 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3532 + * test if the branch is deletable or not.
3534 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3535 + unsigned int sigen, const unsigned int verbose)
3537 + int err, i, j, ndentry;
3538 + aufs_bindex_t btop, bbot;
3539 + struct au_dcsub_pages dpages;
3540 + struct au_dpage *dpage;
3543 + err = au_dpages_init(&dpages, GFP_NOFS);
3544 + if (unlikely(err))
3546 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3547 + if (unlikely(err))
3550 + for (i = 0; !err && i < dpages.ndpage; i++) {
3551 + dpage = dpages.dpages + i;
3552 + ndentry = dpage->ndentry;
3553 + for (j = 0; !err && j < ndentry; j++) {
3554 + d = dpage->dentries[j];
3555 + AuDebugOn(au_dcount(d) <= 0);
3556 + if (!au_digen_test(d, sigen)) {
3557 + di_read_lock_child(d, AuLock_IR);
3558 + if (unlikely(au_dbrange_test(d))) {
3559 + di_read_unlock(d, AuLock_IR);
3563 + di_write_lock_child(d);
3564 + if (unlikely(au_dbrange_test(d))) {
3565 + di_write_unlock(d);
3568 + err = au_reval_dpath(d, sigen);
3570 + di_downgrade_lock(d, AuLock_IR);
3572 + di_write_unlock(d);
3577 + /* AuDbgDentry(d); */
3578 + btop = au_dbtop(d);
3579 + bbot = au_dbbot(d);
3580 + if (btop <= bindex
3582 + && au_h_dptr(d, bindex)
3583 + && au_test_dbusy(d, btop, bbot)) {
3585 + AuVerbose(verbose, "busy %pd\n", d);
3588 + di_read_unlock(d, AuLock_IR);
3593 + au_dpages_free(&dpages);
3598 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3599 + unsigned int sigen, const unsigned int verbose)
3602 + unsigned long long max, ull;
3603 + struct inode *i, **array;
3604 + aufs_bindex_t btop, bbot;
3606 + array = au_iarray_alloc(sb, &max);
3607 + err = PTR_ERR(array);
3608 + if (IS_ERR(array))
3612 + AuDbg("b%d\n", bindex);
3613 + for (ull = 0; !err && ull < max; ull++) {
3617 + if (i->i_ino == AUFS_ROOT_INO)
3620 + /* AuDbgInode(i); */
3621 + if (au_iigen(i, NULL) == sigen)
3622 + ii_read_lock_child(i);
3624 + ii_write_lock_child(i);
3625 + err = au_refresh_hinode_self(i);
3628 + ii_downgrade_lock(i);
3630 + ii_write_unlock(i);
3635 + btop = au_ibtop(i);
3636 + bbot = au_ibbot(i);
3637 + if (btop <= bindex
3639 + && au_h_iptr(i, bindex)
3640 + && au_test_ibusy(i, btop, bbot)) {
3642 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3645 + ii_read_unlock(i);
3647 + au_iarray_free(array, max);
3653 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3654 + const unsigned int verbose)
3657 + unsigned int sigen;
3659 + sigen = au_sigen(root->d_sb);
3660 + DiMustNoWaiters(root);
3661 + IiMustNoWaiters(d_inode(root));
3662 + di_write_unlock(root);
3663 + err = test_dentry_busy(root, bindex, sigen, verbose);
3665 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3666 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3671 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3672 + struct file **to_free, int *idx)
3675 + unsigned char matched, root;
3676 + aufs_bindex_t bindex, bbot;
3677 + struct au_fidir *fidir;
3678 + struct au_hfile *hfile;
3681 + root = IS_ROOT(file->f_path.dentry);
3684 + to_free[*idx] = file;
3690 + fidir = au_fi(file)->fi_hdir;
3691 + AuDebugOn(!fidir);
3692 + bbot = au_fbbot_dir(file);
3693 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3694 + hfile = fidir->fd_hfile + bindex;
3695 + if (!hfile->hf_file)
3698 + if (hfile->hf_br->br_id == br_id) {
3710 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3711 + struct file **to_free, int opened)
3714 + unsigned long long ull, max;
3715 + aufs_bindex_t btop;
3716 + struct file *file, **array;
3717 + struct dentry *root;
3718 + struct au_hfile *hfile;
3720 + array = au_farray_alloc(sb, &max);
3721 + err = PTR_ERR(array);
3722 + if (IS_ERR(array))
3727 + root = sb->s_root;
3728 + di_write_unlock(root);
3729 + for (ull = 0; ull < max; ull++) {
3730 + file = array[ull];
3731 + if (unlikely(!file))
3734 + /* AuDbg("%pD\n", file); */
3735 + fi_read_lock(file);
3736 + btop = au_fbtop(file);
3737 + if (!d_is_dir(file->f_path.dentry)) {
3738 + hfile = &au_fi(file)->fi_htop;
3739 + if (hfile->hf_br->br_id == br_id)
3742 + err = test_dir_busy(file, br_id, to_free, &idx);
3743 + fi_read_unlock(file);
3744 + if (unlikely(err))
3747 + di_write_lock_child(root);
3748 + au_farray_free(array, max);
3749 + AuDebugOn(idx > opened);
3755 +static void br_del_file(struct file **to_free, unsigned long long opened,
3756 + aufs_bindex_t br_id)
3758 + unsigned long long ull;
3759 + aufs_bindex_t bindex, btop, bbot, bfound;
3760 + struct file *file;
3761 + struct au_fidir *fidir;
3762 + struct au_hfile *hfile;
3764 + for (ull = 0; ull < opened; ull++) {
3765 + file = to_free[ull];
3766 + if (unlikely(!file))
3769 + /* AuDbg("%pD\n", file); */
3770 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3772 + fidir = au_fi(file)->fi_hdir;
3773 + AuDebugOn(!fidir);
3774 + fi_write_lock(file);
3775 + btop = au_fbtop(file);
3776 + bbot = au_fbbot_dir(file);
3777 + for (bindex = btop; bindex <= bbot; bindex++) {
3778 + hfile = fidir->fd_hfile + bindex;
3779 + if (!hfile->hf_file)
3782 + if (hfile->hf_br->br_id == br_id) {
3787 + AuDebugOn(bfound < 0);
3788 + au_set_h_fptr(file, bfound, NULL);
3789 + if (bfound == btop) {
3790 + for (btop++; btop <= bbot; btop++)
3791 + if (au_hf_dir(file, btop)) {
3792 + au_set_fbtop(file, btop);
3796 + fi_write_unlock(file);
3800 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3801 + const aufs_bindex_t bindex,
3802 + const aufs_bindex_t bbot)
3804 + struct au_branch **brp, **p;
3806 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3808 + brp = sbinfo->si_branch + bindex;
3809 + if (bindex < bbot)
3810 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3811 + sbinfo->si_branch[0 + bbot] = NULL;
3812 + sbinfo->si_bbot--;
3814 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3817 + sbinfo->si_branch = p;
3818 + /* harmless error */
3821 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3822 + const aufs_bindex_t bbot)
3824 + struct au_hdentry *hdp, *p;
3826 + AuRwMustWriteLock(&dinfo->di_rwsem);
3828 + hdp = au_hdentry(dinfo, bindex);
3829 + if (bindex < bbot)
3830 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3831 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3834 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3837 + dinfo->di_hdentry = p;
3838 + /* harmless error */
3841 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3842 + const aufs_bindex_t bbot)
3844 + struct au_hinode *hip, *p;
3846 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3848 + hip = au_hinode(iinfo, bindex);
3849 + if (bindex < bbot)
3850 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3851 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3854 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3857 + iinfo->ii_hinode = p;
3858 + /* harmless error */
3861 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3862 + struct au_branch *br)
3864 + aufs_bindex_t bbot;
3865 + struct au_sbinfo *sbinfo;
3866 + struct dentry *root, *h_root;
3867 + struct inode *inode, *h_inode;
3868 + struct au_hinode *hinode;
3870 + SiMustWriteLock(sb);
3872 + root = sb->s_root;
3873 + inode = d_inode(root);
3874 + sbinfo = au_sbi(sb);
3875 + bbot = sbinfo->si_bbot;
3877 + h_root = au_h_dptr(root, bindex);
3878 + hinode = au_hi(inode, bindex);
3879 + h_inode = au_igrab(hinode->hi_inode);
3882 + au_sbilist_lock();
3883 + au_br_do_del_brp(sbinfo, bindex, bbot);
3884 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3885 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3886 + au_sbilist_unlock();
3890 + au_br_do_free(br);
3893 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3894 + unsigned long long max, void *arg)
3899 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3902 + unsigned long long opened;
3903 + unsigned int mnt_flags;
3904 + aufs_bindex_t bindex, bbot, br_id;
3905 + unsigned char do_wh, verbose;
3906 + struct au_branch *br;
3907 + struct au_wbr *wbr;
3908 + struct dentry *root;
3909 + struct file **to_free;
3914 + root = sb->s_root;
3915 + bindex = au_find_dbindex(root, del->h_path.dentry);
3918 + goto out; /* success */
3920 + pr_err("%s no such branch\n", del->pathname);
3923 + AuDbg("bindex b%d\n", bindex);
3926 + mnt_flags = au_mntflags(sb);
3927 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3928 + bbot = au_sbbot(sb);
3929 + if (unlikely(!bbot)) {
3930 + AuVerbose(verbose, "no more branches left\n");
3933 + br = au_sbr(sb, bindex);
3934 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3936 + br_id = br->br_id;
3937 + opened = au_br_count(br);
3938 + if (unlikely(opened)) {
3939 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3940 + err = PTR_ERR(to_free);
3941 + if (IS_ERR(to_free))
3944 + err = test_file_busy(sb, br_id, to_free, opened);
3945 + if (unlikely(err)) {
3946 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3952 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3954 + /* instead of WbrWhMustWriteLock(wbr) */
3955 + SiMustWriteLock(sb);
3956 + for (i = 0; i < AuBrWh_Last; i++) {
3957 + dput(wbr->wbr_wh[i]);
3958 + wbr->wbr_wh[i] = NULL;
3962 + err = test_children_busy(root, bindex, verbose);
3963 + if (unlikely(err)) {
3972 + * now we confirmed the branch is deletable.
3973 + * let's free the remaining opened dirs on the branch.
3975 + di_write_unlock(root);
3976 + br_del_file(to_free, opened, br_id);
3977 + di_write_lock_child(root);
3981 + au_br_do_del(sb, bindex, br);
3983 + sysaufs_brs_del(sb, bindex);
3984 + au_br_do_del(sb, bindex, br);
3985 + sysaufs_brs_add(sb, bindex);
3989 + au_cpup_attr_all(d_inode(root), /*force*/1);
3990 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3992 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3993 + if (au_opt_test(mnt_flags, PLINK))
3994 + au_plink_half_refresh(sb, br_id);
3996 + if (au_xino_brid(sb) == br_id)
3997 + au_xino_brid_set(sb, -1);
3998 + goto out; /* success */
4002 + rerr = au_br_init_wh(sb, br, br->br_perm);
4004 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4005 + del->pathname, rerr);
4008 + au_farray_free(to_free, opened);
4012 +/* ---------------------------------------------------------------------- */
4014 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4017 + aufs_bindex_t btop, bbot;
4018 + struct aufs_ibusy ibusy;
4019 + struct inode *inode, *h_inode;
4022 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4025 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4027 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4028 + if (unlikely(err)) {
4035 + si_read_lock(sb, AuLock_FLUSH);
4036 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4040 + ibusy.h_ino = 0; /* invalid */
4041 + inode = ilookup(sb, ibusy.ino);
4043 + || inode->i_ino == AUFS_ROOT_INO
4044 + || au_is_bad_inode(inode))
4047 + ii_read_lock_child(inode);
4048 + btop = au_ibtop(inode);
4049 + bbot = au_ibbot(inode);
4050 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4051 + h_inode = au_h_iptr(inode, ibusy.bindex);
4052 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4053 + ibusy.h_ino = h_inode->i_ino;
4055 + ii_read_unlock(inode);
4059 + si_read_unlock(sb);
4061 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4062 + if (unlikely(err)) {
4071 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4073 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4076 +#ifdef CONFIG_COMPAT
4077 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4079 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4083 +/* ---------------------------------------------------------------------- */
4086 + * change a branch permission
4089 +static void au_warn_ima(void)
4092 + /* since it doesn't support mark_files_ro() */
4093 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4097 +static int do_need_sigen_inc(int a, int b)
4099 + return au_br_whable(a) && !au_br_whable(b);
4102 +static int need_sigen_inc(int old, int new)
4104 + return do_need_sigen_inc(old, new)
4105 + || do_need_sigen_inc(new, old);
4108 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4111 + unsigned int mnt_flags;
4112 + unsigned long long ull, max;
4113 + aufs_bindex_t br_id;
4114 + unsigned char verbose, writer;
4115 + struct file *file, *hf, **array;
4116 + struct au_hfile *hfile;
4118 + mnt_flags = au_mntflags(sb);
4119 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4121 + array = au_farray_alloc(sb, &max);
4122 + err = PTR_ERR(array);
4123 + if (IS_ERR(array))
4127 + br_id = au_sbr_id(sb, bindex);
4128 + for (ull = 0; ull < max; ull++) {
4129 + file = array[ull];
4130 + if (unlikely(!file))
4133 + /* AuDbg("%pD\n", file); */
4134 + fi_read_lock(file);
4135 + if (unlikely(au_test_mmapped(file))) {
4137 + AuVerbose(verbose, "mmapped %pD\n", file);
4139 + FiMustNoWaiters(file);
4140 + fi_read_unlock(file);
4144 + hfile = &au_fi(file)->fi_htop;
4145 + hf = hfile->hf_file;
4146 + if (!d_is_reg(file->f_path.dentry)
4147 + || !(file->f_mode & FMODE_WRITE)
4148 + || hfile->hf_br->br_id != br_id
4149 + || !(hf->f_mode & FMODE_WRITE))
4150 + array[ull] = NULL;
4156 + FiMustNoWaiters(file);
4157 + fi_read_unlock(file);
4165 + for (ull = 0; ull < max; ull++) {
4166 + file = array[ull];
4170 + /* todo: already flushed? */
4172 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4173 + * approach which resets f_mode and calls mnt_drop_write() and
4174 + * file_release_write() for each file, because the branch
4175 + * attribute in aufs world is totally different from the native
4178 + /* fi_read_lock(file); */
4179 + hfile = &au_fi(file)->fi_htop;
4180 + hf = hfile->hf_file;
4181 + /* fi_read_unlock(file); */
4182 + spin_lock(&hf->f_lock);
4183 + writer = !!(hf->f_mode & FMODE_WRITER);
4184 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4185 + spin_unlock(&hf->f_lock);
4187 + put_write_access(file_inode(hf));
4188 + __mnt_drop_write(hf->f_path.mnt);
4193 + au_farray_free(array, max);
4199 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4203 + aufs_bindex_t bindex;
4204 + struct dentry *root;
4205 + struct au_branch *br;
4206 + struct au_br_fhsm *bf;
4208 + root = sb->s_root;
4209 + bindex = au_find_dbindex(root, mod->h_root);
4212 + return 0; /* success */
4214 + pr_err("%s no such branch\n", mod->path);
4217 + AuDbg("bindex b%d\n", bindex);
4219 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4220 + if (unlikely(err))
4223 + br = au_sbr(sb, bindex);
4224 + AuDebugOn(mod->h_root != au_br_dentry(br));
4225 + if (br->br_perm == mod->perm)
4226 + return 0; /* success */
4228 + /* pre-allocate for non-fhsm --> fhsm */
4230 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4231 + err = au_fhsm_br_alloc(br);
4232 + if (unlikely(err))
4235 + br->br_fhsm = NULL;
4238 + if (au_br_writable(br->br_perm)) {
4239 + /* remove whiteout base */
4240 + err = au_br_init_wh(sb, br, mod->perm);
4241 + if (unlikely(err))
4244 + if (!au_br_writable(mod->perm)) {
4245 + /* rw --> ro, file might be mmapped */
4246 + DiMustNoWaiters(root);
4247 + IiMustNoWaiters(d_inode(root));
4248 + di_write_unlock(root);
4249 + err = au_br_mod_files_ro(sb, bindex);
4250 + /* aufs_write_lock() calls ..._child() */
4251 + di_write_lock_child(root);
4253 + if (unlikely(err)) {
4255 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4258 + rerr = au_wbr_init(br, sb, br->br_perm);
4259 + if (unlikely(rerr)) {
4260 + AuIOErr("nested error %d (%d)\n",
4262 + br->br_perm = mod->perm;
4266 + } else if (au_br_writable(mod->perm)) {
4269 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4271 + err = au_wbr_init(br, sb, mod->perm);
4272 + if (unlikely(err)) {
4273 + au_delayed_kfree(br->br_wbr);
4274 + br->br_wbr = NULL;
4278 + if (unlikely(err))
4281 + if (au_br_fhsm(br->br_perm)) {
4282 + if (!au_br_fhsm(mod->perm)) {
4283 + /* fhsm --> non-fhsm */
4284 + au_br_fhsm_fin(br->br_fhsm);
4285 + au_delayed_kfree(br->br_fhsm);
4286 + br->br_fhsm = NULL;
4288 + } else if (au_br_fhsm(mod->perm))
4289 + /* non-fhsm --> fhsm */
4292 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4293 + br->br_perm = mod->perm;
4294 + goto out; /* success */
4298 + au_delayed_kfree(bf);
4304 +/* ---------------------------------------------------------------------- */
4306 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4309 + struct kstatfs kstfs;
4311 + err = vfs_statfs(&br->br_path, &kstfs);
4313 + stfs->f_blocks = kstfs.f_blocks;
4314 + stfs->f_bavail = kstfs.f_bavail;
4315 + stfs->f_files = kstfs.f_files;
4316 + stfs->f_ffree = kstfs.f_ffree;
4321 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4322 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4323 +++ linux/fs/aufs/branch.h 2017-05-06 22:16:52.774886674 +0200
4326 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4328 + * This program, aufs is free software; you can redistribute it and/or modify
4329 + * it under the terms of the GNU General Public License as published by
4330 + * the Free Software Foundation; either version 2 of the License, or
4331 + * (at your option) any later version.
4333 + * This program is distributed in the hope that it will be useful,
4334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4336 + * GNU General Public License for more details.
4338 + * You should have received a copy of the GNU General Public License
4339 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4343 + * branch filesystems and xino for them
4346 +#ifndef __AUFS_BRANCH_H__
4347 +#define __AUFS_BRANCH_H__
4351 +#include <linux/mount.h>
4356 +/* ---------------------------------------------------------------------- */
4359 +struct au_xino_file {
4360 + struct file *xi_file;
4365 + /* reserved for future use */
4366 + /* unsigned long *bitmap; */
4367 + wait_queue_head_t wqh;
4370 + /* todo: make xino files an array to support huge inode number */
4372 +#ifdef CONFIG_DEBUG_FS
4373 + struct dentry *xi_dbgaufs;
4377 +/* File-based Hierarchical Storage Management */
4378 +struct au_br_fhsm {
4379 +#ifdef CONFIG_AUFS_FHSM
4380 + struct mutex bf_lock;
4381 + unsigned long bf_jiffy;
4382 + struct aufs_stfs bf_stfs;
4387 +/* members for writable branch only */
4388 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4390 + struct au_rwsem wbr_wh_rwsem;
4391 + struct dentry *wbr_wh[AuBrWh_Last];
4392 + atomic_t wbr_wh_running;
4393 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4394 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4395 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4398 + unsigned long long wbr_bytes;
4401 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4402 +#define AuBrDynOp (AuDyLast * 4)
4404 +#ifdef CONFIG_AUFS_HFSNOTIFY
4405 +/* support for asynchronous destruction */
4406 +struct au_br_hfsnotify {
4407 + struct fsnotify_group *hfsn_group;
4411 +/* sysfs entries */
4412 +struct au_brsysfs {
4414 + struct attribute attr;
4423 +/* protected by superblock rwsem */
4425 + struct au_xino_file br_xino;
4427 + aufs_bindex_t br_id;
4430 + struct path br_path;
4431 + spinlock_t br_dykey_lock;
4432 + struct au_dykey *br_dykey[AuBrDynOp];
4433 + struct percpu_counter br_count;
4435 + struct au_wbr *br_wbr;
4436 + struct au_br_fhsm *br_fhsm;
4438 + /* xino truncation */
4439 + atomic_t br_xino_running;
4441 +#ifdef CONFIG_AUFS_HFSNOTIFY
4442 + struct au_br_hfsnotify *br_hfsn;
4445 +#ifdef CONFIG_SYSFS
4446 + /* entries under sysfs per mount-point */
4447 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4451 +/* ---------------------------------------------------------------------- */
4453 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4455 + return br->br_path.mnt;
4458 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4460 + return br->br_path.dentry;
4463 +static inline struct super_block *au_br_sb(struct au_branch *br)
4465 + return au_br_mnt(br)->mnt_sb;
4468 +static inline void au_br_get(struct au_branch *br)
4470 + percpu_counter_inc(&br->br_count);
4473 +static inline void au_br_put(struct au_branch *br)
4475 + percpu_counter_dec(&br->br_count);
4478 +static inline s64 au_br_count(struct au_branch *br)
4480 + return percpu_counter_sum(&br->br_count);
4483 +static inline void au_br_count_init(struct au_branch *br)
4485 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4488 +static inline void au_br_count_fin(struct au_branch *br)
4490 + percpu_counter_destroy(&br->br_count);
4493 +static inline int au_br_rdonly(struct au_branch *br)
4495 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4496 + || !au_br_writable(br->br_perm))
4500 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4502 +#ifdef CONFIG_AUFS_HNOTIFY
4503 + return !(brperm & AuBrPerm_RR);
4509 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4511 + int err, exec_flag;
4514 + exec_flag = oflag & __FMODE_EXEC;
4515 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4521 +/* ---------------------------------------------------------------------- */
4525 +void au_br_free(struct au_sbinfo *sinfo);
4526 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4528 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4530 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4531 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4532 +#ifdef CONFIG_COMPAT
4533 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4536 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4539 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4542 +static const loff_t au_loff_max = LLONG_MAX;
4544 +int au_xib_trunc(struct super_block *sb);
4545 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4547 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4548 + size_t size, loff_t *pos);
4549 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4550 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4551 +ino_t au_xino_new_ino(struct super_block *sb);
4552 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4553 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4555 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4557 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4558 + struct file *base_file, int do_test);
4559 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4561 +struct au_opt_xino;
4562 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4563 +void au_xino_clr(struct super_block *sb);
4564 +struct file *au_xino_def(struct super_block *sb);
4565 +int au_xino_path(struct seq_file *seq, struct file *file);
4567 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4568 + ino_t h_ino, int idx);
4569 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4572 +/* ---------------------------------------------------------------------- */
4574 +/* Superblock to branch */
4576 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4578 + return au_sbr(sb, bindex)->br_id;
4582 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4584 + return au_br_mnt(au_sbr(sb, bindex));
4588 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4590 + return au_br_sb(au_sbr(sb, bindex));
4593 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4595 + au_br_get(au_sbr(sb, bindex));
4598 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4600 + au_br_put(au_sbr(sb, bindex));
4603 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4605 + return au_sbr(sb, bindex)->br_perm;
4608 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4610 + return au_br_whable(au_sbr_perm(sb, bindex));
4613 +/* ---------------------------------------------------------------------- */
4616 + * wbr_wh_read_lock, wbr_wh_write_lock
4617 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4619 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4621 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4622 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4623 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4625 +/* ---------------------------------------------------------------------- */
4627 +#ifdef CONFIG_AUFS_FHSM
4628 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4630 + mutex_init(&brfhsm->bf_lock);
4631 + brfhsm->bf_jiffy = 0;
4632 + brfhsm->bf_readable = 0;
4635 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4637 + mutex_destroy(&brfhsm->bf_lock);
4640 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4641 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4644 +#endif /* __KERNEL__ */
4645 +#endif /* __AUFS_BRANCH_H__ */
4646 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4647 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4648 +++ linux/fs/aufs/conf.mk 2017-05-06 22:16:52.774886674 +0200
4651 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4655 +AuConfStr += ${1}=${${1}}
4659 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4661 + HNOTIFY HFSNOTIFY \
4672 +$(foreach i, ${AuConfAll}, \
4673 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4675 +AuConfName = ${obj}/conf.str
4676 +${AuConfName}.tmp: FORCE
4677 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4678 +${AuConfName}: ${AuConfName}.tmp
4679 + @diff -q $< $@ > /dev/null 2>&1 || { \
4680 + echo ' GEN ' $@; \
4684 +clean-files += ${AuConfName} ${AuConfName}.tmp
4685 +${obj}/sysfs.o: ${AuConfName}
4687 +-include ${srctree}/${src}/conf_priv.mk
4688 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4689 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4690 +++ linux/fs/aufs/cpup.c 2017-05-06 22:16:52.774886674 +0200
4693 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4695 + * This program, aufs is free software; you can redistribute it and/or modify
4696 + * it under the terms of the GNU General Public License as published by
4697 + * the Free Software Foundation; either version 2 of the License, or
4698 + * (at your option) any later version.
4700 + * This program is distributed in the hope that it will be useful,
4701 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4702 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4703 + * GNU General Public License for more details.
4705 + * You should have received a copy of the GNU General Public License
4706 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4710 + * copy-up functions, see wbr_policy.c for copy-down
4713 +#include <linux/fs_stack.h>
4714 +#include <linux/mm.h>
4715 +#include <linux/task_work.h>
4718 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4720 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4721 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4723 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4725 + dst->i_flags |= iflags & ~mask;
4726 + if (au_test_fs_notime(dst->i_sb))
4727 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4730 +void au_cpup_attr_timesizes(struct inode *inode)
4732 + struct inode *h_inode;
4734 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4735 + fsstack_copy_attr_times(inode, h_inode);
4736 + fsstack_copy_inode_size(inode, h_inode);
4739 +void au_cpup_attr_nlink(struct inode *inode, int force)
4741 + struct inode *h_inode;
4742 + struct super_block *sb;
4743 + aufs_bindex_t bindex, bbot;
4746 + bindex = au_ibtop(inode);
4747 + h_inode = au_h_iptr(inode, bindex);
4749 + && !S_ISDIR(h_inode->i_mode)
4750 + && au_opt_test(au_mntflags(sb), PLINK)
4751 + && au_plink_test(inode))
4755 + * 0 can happen in revalidating.
4756 + * h_inode->i_mutex may not be held here, but it is harmless since once
4757 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4759 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4760 + * the incorrect link count.
4762 + set_nlink(inode, h_inode->i_nlink);
4765 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4766 + * it may includes whplink directory.
4768 + if (S_ISDIR(h_inode->i_mode)) {
4769 + bbot = au_ibbot(inode);
4770 + for (bindex++; bindex <= bbot; bindex++) {
4771 + h_inode = au_h_iptr(inode, bindex);
4773 + au_add_nlink(inode, h_inode);
4778 +void au_cpup_attr_changeable(struct inode *inode)
4780 + struct inode *h_inode;
4782 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4783 + inode->i_mode = h_inode->i_mode;
4784 + inode->i_uid = h_inode->i_uid;
4785 + inode->i_gid = h_inode->i_gid;
4786 + au_cpup_attr_timesizes(inode);
4787 + au_cpup_attr_flags(inode, h_inode->i_flags);
4790 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4792 + struct au_iinfo *iinfo = au_ii(inode);
4794 + IiMustWriteLock(inode);
4796 + iinfo->ii_higen = h_inode->i_generation;
4797 + iinfo->ii_hsb1 = h_inode->i_sb;
4800 +void au_cpup_attr_all(struct inode *inode, int force)
4802 + struct inode *h_inode;
4804 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4805 + au_cpup_attr_changeable(inode);
4806 + if (inode->i_nlink > 0)
4807 + au_cpup_attr_nlink(inode, force);
4808 + inode->i_rdev = h_inode->i_rdev;
4809 + inode->i_blkbits = h_inode->i_blkbits;
4810 + au_cpup_igen(inode, h_inode);
4813 +/* ---------------------------------------------------------------------- */
4815 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4817 +/* keep the timestamps of the parent dir when cpup */
4818 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4819 + struct path *h_path)
4821 + struct inode *h_inode;
4823 + dt->dt_dentry = dentry;
4824 + dt->dt_h_path = *h_path;
4825 + h_inode = d_inode(h_path->dentry);
4826 + dt->dt_atime = h_inode->i_atime;
4827 + dt->dt_mtime = h_inode->i_mtime;
4831 +void au_dtime_revert(struct au_dtime *dt)
4833 + struct iattr attr;
4836 + attr.ia_atime = dt->dt_atime;
4837 + attr.ia_mtime = dt->dt_mtime;
4838 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4839 + | ATTR_ATIME | ATTR_ATIME_SET;
4841 + /* no delegation since this is a directory */
4842 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4843 + if (unlikely(err))
4844 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4847 +/* ---------------------------------------------------------------------- */
4849 +/* internal use only */
4850 +struct au_cpup_reg_attr {
4853 + unsigned int iflags; /* inode->i_flags */
4856 +static noinline_for_stack
4857 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4858 + struct au_cpup_reg_attr *h_src_attr)
4860 + int err, sbits, icex;
4861 + unsigned int mnt_flags;
4862 + unsigned char verbose;
4864 + struct path h_path;
4865 + struct inode *h_isrc, *h_idst;
4866 + struct kstat *h_st;
4867 + struct au_branch *br;
4869 + h_path.dentry = au_h_dptr(dst, bindex);
4870 + h_idst = d_inode(h_path.dentry);
4871 + br = au_sbr(dst->d_sb, bindex);
4872 + h_path.mnt = au_br_mnt(br);
4873 + h_isrc = d_inode(h_src);
4874 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4875 + | ATTR_ATIME | ATTR_MTIME
4876 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4877 + if (h_src_attr && h_src_attr->valid) {
4878 + h_st = &h_src_attr->st;
4879 + ia.ia_uid = h_st->uid;
4880 + ia.ia_gid = h_st->gid;
4881 + ia.ia_atime = h_st->atime;
4882 + ia.ia_mtime = h_st->mtime;
4883 + if (h_idst->i_mode != h_st->mode
4884 + && !S_ISLNK(h_idst->i_mode)) {
4885 + ia.ia_valid |= ATTR_MODE;
4886 + ia.ia_mode = h_st->mode;
4888 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4889 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4891 + ia.ia_uid = h_isrc->i_uid;
4892 + ia.ia_gid = h_isrc->i_gid;
4893 + ia.ia_atime = h_isrc->i_atime;
4894 + ia.ia_mtime = h_isrc->i_mtime;
4895 + if (h_idst->i_mode != h_isrc->i_mode
4896 + && !S_ISLNK(h_idst->i_mode)) {
4897 + ia.ia_valid |= ATTR_MODE;
4898 + ia.ia_mode = h_isrc->i_mode;
4900 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4901 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4903 + /* no delegation since it is just created */
4904 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4906 + /* is this nfs only? */
4907 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4908 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4909 + ia.ia_mode = h_isrc->i_mode;
4910 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4913 + icex = br->br_perm & AuBrAttr_ICEX;
4915 + mnt_flags = au_mntflags(dst->d_sb);
4916 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4917 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4923 +/* ---------------------------------------------------------------------- */
4925 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4926 + char *buf, unsigned long blksize)
4929 + size_t sz, rbytes, wbytes;
4930 + unsigned char all_zero;
4932 + struct inode *h_inode;
4933 + /* reduce stack usage */
4936 + zp = page_address(ZERO_PAGE(0));
4937 + if (unlikely(!zp))
4938 + return -ENOMEM; /* possible? */
4943 + AuDbg("len %lld\n", len);
4945 + if (len < blksize)
4949 + /* todo: signal_pending? */
4950 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4951 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4954 + if (unlikely(err < 0))
4958 + if (len >= rbytes && rbytes == blksize)
4959 + all_zero = !memcmp(buf, zp, rbytes);
4966 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4968 + /* todo: signal_pending? */
4969 + if (unlikely(err == -EAGAIN || err == -EINTR))
4971 + if (unlikely(err < 0))
4976 + if (unlikely(err < 0))
4982 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4984 + if (unlikely(res < 0))
4991 + /* the last block may be a hole */
4992 + if (!err && all_zero) {
4993 + AuLabel(last hole);
4996 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4997 + /* nfs requires this step to make last hole */
4998 + /* is this only nfs? */
5000 + /* todo: signal_pending? */
5001 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5002 + } while (err == -EAGAIN || err == -EINTR);
5009 + ia->ia_size = dst->f_pos;
5010 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5011 + ia->ia_file = dst;
5012 + h_inode = file_inode(dst);
5013 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5014 + /* no delegation since it is just created */
5015 + err = vfsub_notify_change(&dst->f_path, ia,
5016 + /*delegated*/NULL);
5017 + inode_unlock(h_inode);
5024 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5027 + unsigned long blksize;
5028 + unsigned char do_kfree;
5032 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5033 + if (!blksize || PAGE_SIZE < blksize)
5034 + blksize = PAGE_SIZE;
5035 + AuDbg("blksize %lu\n", blksize);
5036 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5038 + buf = kmalloc(blksize, GFP_NOFS);
5040 + buf = (void *)__get_free_page(GFP_NOFS);
5041 + if (unlikely(!buf))
5044 + if (len > (1 << 22))
5045 + AuDbg("copying a large file %lld\n", (long long)len);
5049 + err = au_do_copy_file(dst, src, len, buf, blksize);
5051 + au_delayed_kfree(buf);
5053 + au_delayed_free_page((unsigned long)buf);
5060 + * to support a sparse file which is opened with O_APPEND,
5061 + * we need to close the file.
5063 +static int au_cp_regular(struct au_cp_generic *cpg)
5066 + enum { SRC, DST };
5068 + aufs_bindex_t bindex;
5069 + unsigned int flags;
5070 + struct dentry *dentry;
5072 + struct file *file;
5076 + .bindex = cpg->bsrc,
5077 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5081 + .bindex = cpg->bdst,
5082 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5083 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5084 + .label = &&out_src
5087 + struct super_block *sb, *h_src_sb;
5088 + struct inode *h_src_inode;
5089 + struct task_struct *tsk = current;
5091 + /* bsrc branch can be ro/rw. */
5092 + sb = cpg->dentry->d_sb;
5094 + for (i = 0; i < 2; i++, f++) {
5095 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5096 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5097 + /*file*/NULL, f->force_wr);
5098 + err = PTR_ERR(f->file);
5099 + if (IS_ERR(f->file))
5103 + /* try stopping to update while we copyup */
5104 + h_src_inode = d_inode(file[SRC].dentry);
5105 + h_src_sb = h_src_inode->i_sb;
5106 + if (!au_test_nfs(h_src_sb))
5107 + IMustLock(h_src_inode);
5109 + if (h_src_sb != file_inode(file[DST].file)->i_sb
5110 + || !file[DST].file->f_op->clone_file_range)
5111 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5113 + if (!au_test_nfs(h_src_sb)) {
5114 + inode_unlock(h_src_inode);
5115 + err = vfsub_clone_file_range(file[SRC].file,
5116 + file[DST].file, cpg->len);
5117 + inode_lock(h_src_inode);
5119 + err = vfsub_clone_file_range(file[SRC].file,
5120 + file[DST].file, cpg->len);
5121 + if (unlikely(err == -EOPNOTSUPP && au_test_nfs(h_src_sb)))
5122 + /* the backend fs on NFS may not support cloning */
5123 + err = au_copy_file(file[DST].file, file[SRC].file,
5128 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5129 + if (tsk->flags & PF_KTHREAD)
5130 + __fput_sync(file[DST].file);
5132 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5134 + fput(file[DST].file);
5137 + * we have to call both since we don't know which place the file
5141 + flush_delayed_fput();
5143 + au_sbr_put(sb, file[DST].bindex);
5146 + fput(file[SRC].file);
5147 + au_sbr_put(sb, file[SRC].bindex);
5152 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5153 + struct au_cpup_reg_attr *h_src_attr)
5157 + struct path h_path;
5158 + struct inode *h_src_inode, *h_dst_inode;
5161 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5162 + l = i_size_read(h_src_inode);
5163 + if (cpg->len == -1 || l < cpg->len)
5166 + /* try stopping to update while we are referencing */
5167 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5168 + au_pin_hdir_unlock(cpg->pin);
5170 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5171 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5172 + h_src_attr->iflags = h_src_inode->i_flags;
5173 + if (!au_test_nfs(h_src_inode->i_sb))
5174 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5176 + inode_unlock(h_src_inode);
5177 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5178 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5180 + if (unlikely(err)) {
5181 + inode_unlock(h_src_inode);
5184 + h_src_attr->valid = 1;
5185 + if (!au_test_nfs(h_src_inode->i_sb)) {
5186 + err = au_cp_regular(cpg);
5187 + inode_unlock(h_src_inode);
5189 + inode_unlock(h_src_inode);
5190 + err = au_cp_regular(cpg);
5192 + rerr = au_pin_hdir_relock(cpg->pin);
5196 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5197 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5198 + h_dst_inode = d_inode(h_path.dentry);
5199 + spin_lock(&h_dst_inode->i_lock);
5200 + h_dst_inode->i_state |= I_LINKABLE;
5201 + spin_unlock(&h_dst_inode->i_lock);
5208 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5209 + struct inode *h_dir)
5212 + mm_segment_t old_fs;
5219 + sym.k = (void *)__get_free_page(GFP_NOFS);
5220 + if (unlikely(!sym.k))
5223 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5224 + old_fs = get_fs();
5225 + set_fs(KERNEL_DS);
5226 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5231 + sym.k[symlen] = 0;
5232 + err = vfsub_symlink(h_dir, h_path, sym.k);
5234 + au_delayed_free_page((unsigned long)sym.k);
5241 + * regardless 'acl' option, reset all ACL.
5242 + * All ACL will be copied up later from the original entry on the lower branch.
5244 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5247 + struct dentry *h_dentry;
5248 + struct inode *h_inode;
5250 + h_dentry = h_path->dentry;
5251 + h_inode = d_inode(h_dentry);
5252 + /* forget_all_cached_acls(h_inode)); */
5253 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5255 + if (err == -EOPNOTSUPP)
5258 + err = vfsub_acl_chmod(h_inode, mode);
5264 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5265 + struct inode *h_dir, struct path *h_path)
5268 + struct inode *dir, *inode;
5270 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5272 + if (err == -EOPNOTSUPP)
5274 + if (unlikely(err))
5278 + * strange behaviour from the users view,
5279 + * particularry setattr case
5281 + dir = d_inode(dst_parent);
5282 + if (au_ibtop(dir) == cpg->bdst)
5283 + au_cpup_attr_nlink(dir, /*force*/1);
5284 + inode = d_inode(cpg->dentry);
5285 + au_cpup_attr_nlink(inode, /*force*/1);
5291 +static noinline_for_stack
5292 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5293 + struct au_cpup_reg_attr *h_src_attr)
5297 + unsigned int mnt_flags;
5298 + unsigned char isdir, isreg, force;
5299 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5300 + struct au_dtime dt;
5301 + struct path h_path;
5302 + struct dentry *h_src, *h_dst, *h_parent;
5303 + struct inode *h_inode, *h_dir;
5304 + struct super_block *sb;
5306 + /* bsrc branch can be ro/rw. */
5307 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5308 + h_inode = d_inode(h_src);
5309 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5311 + /* try stopping to be referenced while we are creating */
5312 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5313 + if (au_ftest_cpup(cpg->flags, RENAME))
5314 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5315 + AUFS_WH_PFX_LEN));
5316 + h_parent = h_dst->d_parent; /* dir inode is locked */
5317 + h_dir = d_inode(h_parent);
5319 + AuDebugOn(h_parent != h_dst->d_parent);
5321 + sb = cpg->dentry->d_sb;
5322 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5324 + h_path.dentry = h_parent;
5325 + au_dtime_store(&dt, dst_parent, &h_path);
5327 + h_path.dentry = h_dst;
5331 + mode = h_inode->i_mode;
5332 + switch (mode & S_IFMT) {
5335 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5336 + /*want_excl*/true);
5338 + err = au_do_cpup_regular(cpg, h_src_attr);
5342 + err = vfsub_mkdir(h_dir, &h_path, mode);
5344 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5347 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5351 + AuDebugOn(!capable(CAP_MKNOD));
5355 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5358 + AuIOErr("Unknown inode type 0%o\n", mode);
5362 + err = au_reset_acl(h_dir, &h_path, mode);
5364 + mnt_flags = au_mntflags(sb);
5365 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5367 + && au_opt_test(mnt_flags, XINO)
5368 + && (h_inode->i_nlink == 1
5369 + || (h_inode->i_state & I_LINKABLE))
5370 + /* todo: unnecessary? */
5371 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5372 + && cpg->bdst < cpg->bsrc
5373 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5374 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5375 + /* ignore this error */
5380 + force = !!cpg->len;
5381 + if (cpg->len == -1)
5382 + force = !!i_size_read(h_inode);
5384 + au_fhsm_wrote(sb, cpg->bdst, force);
5388 + au_dtime_revert(&dt);
5392 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5395 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5396 + struct inode *h_dir;
5397 + aufs_bindex_t bdst;
5399 + dentry = cpg->dentry;
5401 + h_dentry = au_h_dptr(dentry, bdst);
5402 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5404 + au_set_h_dptr(dentry, bdst, NULL);
5405 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5407 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5408 + au_set_h_dptr(dentry, bdst, h_dentry);
5411 + parent = dget_parent(dentry);
5412 + h_parent = au_h_dptr(parent, bdst);
5414 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5415 + if (IS_ERR(h_path->dentry))
5416 + err = PTR_ERR(h_path->dentry);
5418 + if (unlikely(err))
5421 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5422 + h_dir = d_inode(h_parent);
5424 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5425 + /* no delegation since it is just created */
5426 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5428 + dput(h_path->dentry);
5435 + * copyup the @dentry from @bsrc to @bdst.
5436 + * the caller must set the both of lower dentries.
5437 + * @len is for truncating when it is -1 copyup the entire file.
5438 + * in link/rename cases, @dst_parent may be different from the real one.
5439 + * basic->bsrc can be larger than basic->bdst.
5440 + * aufs doesn't touch the credential so
5441 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5443 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5446 + aufs_bindex_t old_ibtop;
5447 + unsigned char isdir, plink;
5448 + struct dentry *h_src, *h_dst, *h_parent;
5449 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5450 + struct super_block *sb;
5451 + struct au_branch *br;
5452 + /* to reuduce stack size */
5454 + struct au_dtime dt;
5455 + struct path h_path;
5456 + struct au_cpup_reg_attr h_src_attr;
5460 + a = kmalloc(sizeof(*a), GFP_NOFS);
5463 + a->h_src_attr.valid = 0;
5465 + sb = cpg->dentry->d_sb;
5466 + br = au_sbr(sb, cpg->bdst);
5467 + a->h_path.mnt = au_br_mnt(br);
5468 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5469 + h_parent = h_dst->d_parent; /* dir inode is locked */
5470 + h_dir = d_inode(h_parent);
5473 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5474 + inode = d_inode(cpg->dentry);
5477 + dst_parent = dget_parent(cpg->dentry);
5481 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5482 + dst_inode = au_h_iptr(inode, cpg->bdst);
5484 + if (unlikely(!plink)) {
5486 + AuIOErr("hi%lu(i%lu) exists on b%d "
5487 + "but plink is disabled\n",
5488 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5492 + if (dst_inode->i_nlink) {
5493 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5495 + h_src = au_plink_lkup(inode, cpg->bdst);
5496 + err = PTR_ERR(h_src);
5497 + if (IS_ERR(h_src))
5499 + if (unlikely(d_is_negative(h_src))) {
5501 + AuIOErr("i%lu exists on b%d "
5502 + "but not pseudo-linked\n",
5503 + inode->i_ino, cpg->bdst);
5509 + a->h_path.dentry = h_parent;
5510 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5513 + a->h_path.dentry = h_dst;
5515 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5516 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5517 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5519 + au_dtime_revert(&a->dt);
5520 + if (unlikely(err == -EWOULDBLOCK)) {
5521 + pr_warn("cannot retry for NFSv4 delegation"
5522 + " for an internal link\n");
5528 + /* todo: cpup_wh_file? */
5530 + au_update_ibrange(inode, /*do_put_zero*/1);
5533 + isdir = S_ISDIR(inode->i_mode);
5534 + old_ibtop = au_ibtop(inode);
5535 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5536 + if (unlikely(err))
5538 + dst_inode = d_inode(h_dst);
5539 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5540 + /* todo: necessary? */
5541 + /* au_pin_hdir_unlock(cpg->pin); */
5543 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5544 + if (unlikely(err)) {
5545 + /* todo: necessary? */
5546 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5547 + inode_unlock(dst_inode);
5551 + if (cpg->bdst < old_ibtop) {
5552 + if (S_ISREG(inode->i_mode)) {
5553 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5554 + if (unlikely(err)) {
5555 + /* ignore an error */
5556 + /* au_pin_hdir_relock(cpg->pin); */
5557 + inode_unlock(dst_inode);
5561 + au_set_ibtop(inode, cpg->bdst);
5563 + au_set_ibbot(inode, cpg->bdst);
5564 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5565 + au_hi_flags(inode, isdir));
5567 + /* todo: necessary? */
5568 + /* err = au_pin_hdir_relock(cpg->pin); */
5569 + inode_unlock(dst_inode);
5570 + if (unlikely(err))
5573 + src_inode = d_inode(h_src);
5575 + && (src_inode->i_nlink > 1
5576 + || src_inode->i_state & I_LINKABLE)
5578 + au_plink_append(inode, cpg->bdst, h_dst);
5580 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5581 + a->h_path.dentry = h_dst;
5582 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5585 + goto out_parent; /* success */
5589 + a->h_path.dentry = h_parent;
5590 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5591 + a->h_path.dentry = h_dst;
5593 + if (d_is_positive(h_dst)) {
5595 + /* no delegation since it is just created */
5596 + rerr = vfsub_unlink(h_dir, &a->h_path,
5597 + /*delegated*/NULL, /*force*/0);
5599 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5601 + au_dtime_revert(&a->dt);
5603 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5608 + au_delayed_kfree(a);
5613 +#if 0 /* reserved */
5614 +struct au_cpup_single_args {
5616 + struct au_cp_generic *cpg;
5617 + struct dentry *dst_parent;
5620 +static void au_call_cpup_single(void *args)
5622 + struct au_cpup_single_args *a = args;
5624 + au_pin_hdir_acquire_nest(a->cpg->pin);
5625 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5626 + au_pin_hdir_release(a->cpg->pin);
5631 + * prevent SIGXFSZ in copy-up.
5632 + * testing CAP_MKNOD is for generic fs,
5633 + * but CAP_FSETID is for xfs only, currently.
5635 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5638 + struct super_block *sb;
5639 + struct inode *h_dir;
5642 + sb = au_pinned_parent(pin)->d_sb;
5643 + if (!au_wkq_test()
5644 + && (!au_sbi(sb)->si_plink_maint_pid
5645 + || au_plink_maint(sb, AuLock_NOPLM))) {
5646 + switch (mode & S_IFMT) {
5648 + /* no condition about RLIMIT_FSIZE and the file size */
5653 + do_sio = !capable(CAP_MKNOD);
5657 + do_sio = ((mode & (S_ISUID | S_ISGID))
5658 + && !capable(CAP_FSETID));
5659 + /* this workaround may be removed in the future */
5661 + h_dir = au_pinned_h_dir(pin);
5662 + do_sio = h_dir->i_mode & S_ISVTX;
5669 +#if 0 /* reserved */
5670 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5673 + struct dentry *h_dentry;
5675 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5676 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5677 + err = au_cpup_single(cpg, dst_parent);
5679 + struct au_cpup_single_args args = {
5682 + .dst_parent = dst_parent
5684 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5685 + if (unlikely(wkq_err))
5694 + * copyup the @dentry from the first active lower branch to @bdst,
5695 + * using au_cpup_single().
5697 +static int au_cpup_simple(struct au_cp_generic *cpg)
5700 + unsigned int flags_orig;
5701 + struct dentry *dentry;
5703 + AuDebugOn(cpg->bsrc < 0);
5705 + dentry = cpg->dentry;
5706 + DiMustWriteLock(dentry);
5708 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5710 + flags_orig = cpg->flags;
5711 + au_fset_cpup(cpg->flags, RENAME);
5712 + err = au_cpup_single(cpg, NULL);
5713 + cpg->flags = flags_orig;
5715 + return 0; /* success */
5718 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5719 + au_set_dbtop(dentry, cpg->bsrc);
5725 +struct au_cpup_simple_args {
5727 + struct au_cp_generic *cpg;
5730 +static void au_call_cpup_simple(void *args)
5732 + struct au_cpup_simple_args *a = args;
5734 + au_pin_hdir_acquire_nest(a->cpg->pin);
5735 + *a->errp = au_cpup_simple(a->cpg);
5736 + au_pin_hdir_release(a->cpg->pin);
5739 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5742 + struct dentry *dentry, *parent;
5743 + struct file *h_file;
5744 + struct inode *h_dir;
5746 + dentry = cpg->dentry;
5748 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5749 + AuDebugOn(cpg->bsrc < 0);
5750 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5751 + err = PTR_ERR(h_file);
5752 + if (IS_ERR(h_file))
5756 + parent = dget_parent(dentry);
5757 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5758 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5759 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5760 + err = au_cpup_simple(cpg);
5762 + struct au_cpup_simple_args args = {
5766 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5767 + if (unlikely(wkq_err))
5773 + au_h_open_post(dentry, cpg->bsrc, h_file);
5779 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5781 + aufs_bindex_t bsrc, bbot;
5782 + struct dentry *dentry, *h_dentry;
5784 + if (cpg->bsrc < 0) {
5785 + dentry = cpg->dentry;
5786 + bbot = au_dbbot(dentry);
5787 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5788 + h_dentry = au_h_dptr(dentry, bsrc);
5790 + AuDebugOn(d_is_negative(h_dentry));
5794 + AuDebugOn(bsrc > bbot);
5797 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5798 + return au_do_sio_cpup_simple(cpg);
5801 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5803 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5804 + return au_do_sio_cpup_simple(cpg);
5807 +/* ---------------------------------------------------------------------- */
5810 + * copyup the deleted file for writing.
5812 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5813 + struct file *file)
5816 + unsigned int flags_orig;
5817 + aufs_bindex_t bsrc_orig;
5818 + struct au_dinfo *dinfo;
5820 + struct au_hdentry *hd;
5821 + struct dentry *h_dentry;
5824 + dinfo = au_di(cpg->dentry);
5825 + AuRwMustWriteLock(&dinfo->di_rwsem);
5827 + bsrc_orig = cpg->bsrc;
5828 + cpg->bsrc = dinfo->di_btop;
5829 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5830 + hdst.h_dentry = hdst.hd->hd_dentry;
5831 + hdst.hd->hd_dentry = wh_dentry;
5832 + dinfo->di_btop = cpg->bdst;
5834 + hsrc.h_dentry = NULL;
5836 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5837 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5838 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5840 + flags_orig = cpg->flags;
5841 + cpg->flags = !AuCpup_DTIME;
5842 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5843 + cpg->flags = flags_orig;
5846 + err = au_reopen_nondir(file);
5847 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5849 + hdst.hd->hd_dentry = hdst.h_dentry;
5850 + dinfo->di_btop = cpg->bsrc;
5851 + cpg->bsrc = bsrc_orig;
5856 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5859 + aufs_bindex_t bdst;
5860 + struct au_dtime dt;
5861 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5862 + struct au_branch *br;
5863 + struct path h_path;
5865 + dentry = cpg->dentry;
5867 + br = au_sbr(dentry->d_sb, bdst);
5868 + parent = dget_parent(dentry);
5869 + h_parent = au_h_dptr(parent, bdst);
5870 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5871 + err = PTR_ERR(wh_dentry);
5872 + if (IS_ERR(wh_dentry))
5875 + h_path.dentry = h_parent;
5876 + h_path.mnt = au_br_mnt(br);
5877 + au_dtime_store(&dt, parent, &h_path);
5878 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5879 + if (unlikely(err))
5883 + h_path.dentry = wh_dentry;
5884 + if (!d_is_dir(wh_dentry)) {
5885 + /* no delegation since it is just created */
5886 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5887 + /*delegated*/NULL, /*force*/0);
5889 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5890 + if (unlikely(err)) {
5891 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5895 + au_dtime_revert(&dt);
5896 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5905 +struct au_cpup_wh_args {
5907 + struct au_cp_generic *cpg;
5908 + struct file *file;
5911 +static void au_call_cpup_wh(void *args)
5913 + struct au_cpup_wh_args *a = args;
5915 + au_pin_hdir_acquire_nest(a->cpg->pin);
5916 + *a->errp = au_cpup_wh(a->cpg, a->file);
5917 + au_pin_hdir_release(a->cpg->pin);
5920 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5923 + aufs_bindex_t bdst;
5924 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5925 + struct inode *dir, *h_dir, *h_tmpdir;
5926 + struct au_wbr *wbr;
5927 + struct au_pin wh_pin, *pin_orig;
5929 + dentry = cpg->dentry;
5931 + parent = dget_parent(dentry);
5932 + dir = d_inode(parent);
5935 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5938 + if (!h_dir->i_nlink) {
5939 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5940 + h_orph = wbr->wbr_orph;
5942 + h_parent = dget(au_h_dptr(parent, bdst));
5943 + au_set_h_dptr(parent, bdst, dget(h_orph));
5944 + h_tmpdir = d_inode(h_orph);
5945 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5947 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5948 + /* todo: au_h_open_pre()? */
5950 + pin_orig = cpg->pin;
5951 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5952 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5953 + cpg->pin = &wh_pin;
5956 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5957 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5958 + err = au_cpup_wh(cpg, file);
5960 + struct au_cpup_wh_args args = {
5965 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5966 + if (unlikely(wkq_err))
5971 + inode_unlock(h_tmpdir);
5972 + /* todo: au_h_open_post()? */
5973 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5974 + au_set_h_dptr(parent, bdst, h_parent);
5975 + AuDebugOn(!pin_orig);
5976 + cpg->pin = pin_orig;
5984 +/* ---------------------------------------------------------------------- */
5987 + * generic routine for both of copy-up and copy-down.
5989 +/* cf. revalidate function in file.c */
5990 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5991 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5992 + struct au_pin *pin,
5993 + struct dentry *h_parent, void *arg),
5997 + struct au_pin pin;
5998 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6001 + parent = dget_parent(dentry);
6002 + if (IS_ROOT(parent))
6005 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6006 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6008 + /* do not use au_dpage */
6009 + real_parent = parent;
6012 + parent = dget_parent(dentry);
6013 + h_parent = au_h_dptr(parent, bdst);
6015 + goto out; /* success */
6017 + /* find top dir which is necessary to cpup */
6021 + parent = dget_parent(d);
6022 + di_read_lock_parent3(parent, !AuLock_IR);
6023 + h_parent = au_h_dptr(parent, bdst);
6024 + di_read_unlock(parent, !AuLock_IR);
6025 + } while (!h_parent);
6027 + if (d != real_parent)
6028 + di_write_lock_child3(d);
6030 + /* somebody else might create while we were sleeping */
6031 + h_dentry = au_h_dptr(d, bdst);
6032 + if (!h_dentry || d_is_negative(h_dentry)) {
6034 + au_update_dbtop(d);
6036 + au_pin_set_dentry(&pin, d);
6037 + err = au_do_pin(&pin);
6039 + err = cp(d, bdst, &pin, h_parent, arg);
6044 + if (d != real_parent)
6045 + di_write_unlock(d);
6046 + if (unlikely(err))
6055 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6056 + struct au_pin *pin,
6057 + struct dentry *h_parent __maybe_unused,
6058 + void *arg __maybe_unused)
6060 + struct au_cp_generic cpg = {
6066 + .flags = AuCpup_DTIME
6068 + return au_sio_cpup_simple(&cpg);
6071 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6073 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6076 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6079 + struct dentry *parent;
6080 + struct inode *dir;
6082 + parent = dget_parent(dentry);
6083 + dir = d_inode(parent);
6085 + if (au_h_iptr(dir, bdst))
6088 + di_read_unlock(parent, AuLock_IR);
6089 + di_write_lock_parent(parent);
6090 + /* someone else might change our inode while we were sleeping */
6091 + if (!au_h_iptr(dir, bdst))
6092 + err = au_cpup_dirs(dentry, bdst);
6093 + di_downgrade_lock(parent, AuLock_IR);
6099 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6100 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6101 +++ linux/fs/aufs/cpup.h 2017-05-06 22:16:52.774886674 +0200
6104 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6106 + * This program, aufs is free software; you can redistribute it and/or modify
6107 + * it under the terms of the GNU General Public License as published by
6108 + * the Free Software Foundation; either version 2 of the License, or
6109 + * (at your option) any later version.
6111 + * This program is distributed in the hope that it will be useful,
6112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6114 + * GNU General Public License for more details.
6116 + * You should have received a copy of the GNU General Public License
6117 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6121 + * copy-up/down functions
6124 +#ifndef __AUFS_CPUP_H__
6125 +#define __AUFS_CPUP_H__
6129 +#include <linux/path.h>
6135 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6136 +void au_cpup_attr_timesizes(struct inode *inode);
6137 +void au_cpup_attr_nlink(struct inode *inode, int force);
6138 +void au_cpup_attr_changeable(struct inode *inode);
6139 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6140 +void au_cpup_attr_all(struct inode *inode, int force);
6142 +/* ---------------------------------------------------------------------- */
6144 +struct au_cp_generic {
6145 + struct dentry *dentry;
6146 + aufs_bindex_t bdst, bsrc;
6148 + struct au_pin *pin;
6149 + unsigned int flags;
6153 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6154 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6156 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6157 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6159 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6161 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6162 + the branch is marked as RO */
6164 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6165 +#define au_fset_cpup(flags, name) \
6166 + do { (flags) |= AuCpup_##name; } while (0)
6167 +#define au_fclr_cpup(flags, name) \
6168 + do { (flags) &= ~AuCpup_##name; } while (0)
6170 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6171 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6172 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6173 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6175 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6176 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6177 + struct au_pin *pin,
6178 + struct dentry *h_parent, void *arg),
6180 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6181 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6183 +/* ---------------------------------------------------------------------- */
6185 +/* keep timestamps when copyup */
6187 + struct dentry *dt_dentry;
6188 + struct path dt_h_path;
6189 + struct timespec dt_atime, dt_mtime;
6191 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6192 + struct path *h_path);
6193 +void au_dtime_revert(struct au_dtime *dt);
6195 +#endif /* __KERNEL__ */
6196 +#endif /* __AUFS_CPUP_H__ */
6197 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6198 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6199 +++ linux/fs/aufs/dbgaufs.c 2017-05-06 22:16:52.774886674 +0200
6202 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6204 + * This program, aufs is free software; you can redistribute it and/or modify
6205 + * it under the terms of the GNU General Public License as published by
6206 + * the Free Software Foundation; either version 2 of the License, or
6207 + * (at your option) any later version.
6209 + * This program is distributed in the hope that it will be useful,
6210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6212 + * GNU General Public License for more details.
6214 + * You should have received a copy of the GNU General Public License
6215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6219 + * debugfs interface
6222 +#include <linux/debugfs.h>
6225 +#ifndef CONFIG_SYSFS
6226 +#error DEBUG_FS depends upon SYSFS
6229 +static struct dentry *dbgaufs;
6230 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6232 +/* 20 is max digits length of ulong 64 */
6233 +struct dbgaufs_arg {
6239 + * common function for all XINO files
6241 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6242 + struct file *file)
6244 + au_delayed_kfree(file->private_data);
6248 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6252 + struct dbgaufs_arg *p;
6255 + p = kmalloc(sizeof(*p), GFP_NOFS);
6261 + file->private_data = p;
6265 + err = vfsub_getattr(&xf->f_path, &st);
6269 + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n",
6270 + (long)file_count(xf), st.blocks, st.blksize,
6271 + (long long)st.size);
6273 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6274 + st.blocks, st.blksize,
6275 + (long long)st.size);
6276 + AuDebugOn(p->n >= sizeof(p->a));
6278 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6287 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6288 + size_t count, loff_t *ppos)
6290 + struct dbgaufs_arg *p;
6292 + p = file->private_data;
6293 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6296 +/* ---------------------------------------------------------------------- */
6298 +struct dbgaufs_plink_arg {
6303 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6304 + struct file *file)
6306 + au_delayed_free_page((unsigned long)file->private_data);
6310 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6312 + int err, i, limit;
6313 + unsigned long n, sum;
6314 + struct dbgaufs_plink_arg *p;
6315 + struct au_sbinfo *sbinfo;
6316 + struct super_block *sb;
6317 + struct au_sphlhead *sphl;
6320 + p = (void *)get_zeroed_page(GFP_NOFS);
6325 + sbinfo = inode->i_private;
6326 + sb = sbinfo->si_sb;
6327 + si_noflush_read_lock(sb);
6328 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6329 + limit = PAGE_SIZE - sizeof(p->n);
6331 + /* the number of buckets */
6332 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6337 + for (i = 0, sphl = sbinfo->si_plink;
6338 + i < AuPlink_NHASH;
6340 + n = au_sphl_count(sphl);
6343 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6346 + if (unlikely(limit <= 0))
6349 + p->a[p->n - 1] = '\n';
6351 + /* the sum of plinks */
6352 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6355 + if (unlikely(limit <= 0))
6358 +#define str "1\n0\n0\n"
6359 + p->n = sizeof(str) - 1;
6360 + strcpy(p->a, str);
6363 + si_read_unlock(sb);
6366 + file->private_data = p;
6367 + goto out; /* success */
6370 + au_delayed_free_page((unsigned long)p);
6375 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6376 + size_t count, loff_t *ppos)
6378 + struct dbgaufs_plink_arg *p;
6380 + p = file->private_data;
6381 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6384 +static const struct file_operations dbgaufs_plink_fop = {
6385 + .owner = THIS_MODULE,
6386 + .open = dbgaufs_plink_open,
6387 + .release = dbgaufs_plink_release,
6388 + .read = dbgaufs_plink_read
6391 +/* ---------------------------------------------------------------------- */
6393 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6396 + struct au_sbinfo *sbinfo;
6397 + struct super_block *sb;
6399 + sbinfo = inode->i_private;
6400 + sb = sbinfo->si_sb;
6401 + si_noflush_read_lock(sb);
6402 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6403 + si_read_unlock(sb);
6407 +static const struct file_operations dbgaufs_xib_fop = {
6408 + .owner = THIS_MODULE,
6409 + .open = dbgaufs_xib_open,
6410 + .release = dbgaufs_xi_release,
6411 + .read = dbgaufs_xi_read
6414 +/* ---------------------------------------------------------------------- */
6416 +#define DbgaufsXi_PREFIX "xi"
6418 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6422 + struct au_sbinfo *sbinfo;
6423 + struct super_block *sb;
6425 + struct qstr *name;
6429 + name = &file->f_path.dentry->d_name;
6430 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6431 + || memcmp(name->name, DbgaufsXi_PREFIX,
6432 + sizeof(DbgaufsXi_PREFIX) - 1)))
6434 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6435 + if (unlikely(err))
6438 + sbinfo = inode->i_private;
6439 + sb = sbinfo->si_sb;
6440 + si_noflush_read_lock(sb);
6441 + if (l <= au_sbbot(sb)) {
6442 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6443 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6446 + si_read_unlock(sb);
6452 +static const struct file_operations dbgaufs_xino_fop = {
6453 + .owner = THIS_MODULE,
6454 + .open = dbgaufs_xino_open,
6455 + .release = dbgaufs_xi_release,
6456 + .read = dbgaufs_xi_read
6459 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6461 + aufs_bindex_t bbot;
6462 + struct au_branch *br;
6463 + struct au_xino_file *xi;
6465 + if (!au_sbi(sb)->si_dbgaufs)
6468 + bbot = au_sbbot(sb);
6469 + for (; bindex <= bbot; bindex++) {
6470 + br = au_sbr(sb, bindex);
6471 + xi = &br->br_xino;
6472 + /* debugfs acquires the parent i_mutex */
6474 + debugfs_remove(xi->xi_dbgaufs);
6476 + xi->xi_dbgaufs = NULL;
6480 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6482 + struct au_sbinfo *sbinfo;
6483 + struct dentry *parent;
6484 + struct au_branch *br;
6485 + struct au_xino_file *xi;
6486 + aufs_bindex_t bbot;
6487 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6489 + sbinfo = au_sbi(sb);
6490 + parent = sbinfo->si_dbgaufs;
6494 + bbot = au_sbbot(sb);
6495 + for (; bindex <= bbot; bindex++) {
6496 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6497 + br = au_sbr(sb, bindex);
6498 + xi = &br->br_xino;
6499 + AuDebugOn(xi->xi_dbgaufs);
6500 + /* debugfs acquires the parent i_mutex */
6502 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6503 + sbinfo, &dbgaufs_xino_fop);
6505 + /* ignore an error */
6506 + if (unlikely(!xi->xi_dbgaufs))
6507 + AuWarn1("failed %s under debugfs\n", name);
6511 +/* ---------------------------------------------------------------------- */
6513 +#ifdef CONFIG_AUFS_EXPORT
6514 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6517 + struct au_sbinfo *sbinfo;
6518 + struct super_block *sb;
6520 + sbinfo = inode->i_private;
6521 + sb = sbinfo->si_sb;
6522 + si_noflush_read_lock(sb);
6523 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6524 + si_read_unlock(sb);
6528 +static const struct file_operations dbgaufs_xigen_fop = {
6529 + .owner = THIS_MODULE,
6530 + .open = dbgaufs_xigen_open,
6531 + .release = dbgaufs_xi_release,
6532 + .read = dbgaufs_xi_read
6535 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6540 + * This function is a dynamic '__init' function actually,
6541 + * so the tiny check for si_rwsem is unnecessary.
6543 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6546 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6547 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6548 + &dbgaufs_xigen_fop);
6549 + if (sbinfo->si_dbgaufs_xigen)
6555 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6559 +#endif /* CONFIG_AUFS_EXPORT */
6561 +/* ---------------------------------------------------------------------- */
6563 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6566 + * This function is a dynamic '__fin' function actually,
6567 + * so the tiny check for si_rwsem is unnecessary.
6569 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6571 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6572 + sbinfo->si_dbgaufs = NULL;
6573 + kobject_put(&sbinfo->si_kobj);
6576 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6579 + char name[SysaufsSiNameLen];
6582 + * This function is a dynamic '__init' function actually,
6583 + * so the tiny check for si_rwsem is unnecessary.
6585 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6589 + AuErr1("/debug/aufs is uninitialized\n");
6594 + sysaufs_name(sbinfo, name);
6595 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6596 + if (unlikely(!sbinfo->si_dbgaufs))
6598 + kobject_get(&sbinfo->si_kobj);
6600 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6601 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6602 + &dbgaufs_xib_fop);
6603 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6606 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6607 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6608 + &dbgaufs_plink_fop);
6609 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6612 + err = dbgaufs_xigen_init(sbinfo);
6614 + goto out; /* success */
6617 + dbgaufs_si_fin(sbinfo);
6622 +/* ---------------------------------------------------------------------- */
6624 +void dbgaufs_fin(void)
6626 + debugfs_remove(dbgaufs);
6629 +int __init dbgaufs_init(void)
6634 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6639 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6640 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6641 +++ linux/fs/aufs/dbgaufs.h 2017-05-06 22:16:52.774886674 +0200
6644 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6646 + * This program, aufs is free software; you can redistribute it and/or modify
6647 + * it under the terms of the GNU General Public License as published by
6648 + * the Free Software Foundation; either version 2 of the License, or
6649 + * (at your option) any later version.
6651 + * This program is distributed in the hope that it will be useful,
6652 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6653 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6654 + * GNU General Public License for more details.
6656 + * You should have received a copy of the GNU General Public License
6657 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6661 + * debugfs interface
6664 +#ifndef __DBGAUFS_H__
6665 +#define __DBGAUFS_H__
6669 +struct super_block;
6672 +#ifdef CONFIG_DEBUG_FS
6674 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6675 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6676 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6677 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6678 +void dbgaufs_fin(void);
6679 +int __init dbgaufs_init(void);
6681 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6682 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6683 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6684 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6685 +AuStubVoid(dbgaufs_fin, void)
6686 +AuStubInt0(__init dbgaufs_init, void)
6687 +#endif /* CONFIG_DEBUG_FS */
6689 +#endif /* __KERNEL__ */
6690 +#endif /* __DBGAUFS_H__ */
6691 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6692 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6693 +++ linux/fs/aufs/dcsub.c 2017-05-06 22:16:52.774886674 +0200
6696 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6698 + * This program, aufs is free software; you can redistribute it and/or modify
6699 + * it under the terms of the GNU General Public License as published by
6700 + * the Free Software Foundation; either version 2 of the License, or
6701 + * (at your option) any later version.
6703 + * This program is distributed in the hope that it will be useful,
6704 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6705 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6706 + * GNU General Public License for more details.
6708 + * You should have received a copy of the GNU General Public License
6709 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6713 + * sub-routines for dentry cache
6718 +static void au_dpage_free(struct au_dpage *dpage)
6721 + struct dentry **p;
6723 + p = dpage->dentries;
6724 + for (i = 0; i < dpage->ndentry; i++)
6726 + au_delayed_free_page((unsigned long)dpage->dentries);
6729 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6735 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6736 + if (unlikely(!dpages->dpages))
6739 + p = (void *)__get_free_page(gfp);
6743 + dpages->dpages[0].ndentry = 0;
6744 + dpages->dpages[0].dentries = p;
6745 + dpages->ndpage = 1;
6746 + return 0; /* success */
6749 + au_delayed_kfree(dpages->dpages);
6754 +void au_dpages_free(struct au_dcsub_pages *dpages)
6757 + struct au_dpage *p;
6759 + p = dpages->dpages;
6760 + for (i = 0; i < dpages->ndpage; i++)
6761 + au_dpage_free(p++);
6762 + au_delayed_kfree(dpages->dpages);
6765 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6766 + struct dentry *dentry, gfp_t gfp)
6769 + struct au_dpage *dpage;
6772 + dpage = dpages->dpages + dpages->ndpage - 1;
6773 + sz = PAGE_SIZE / sizeof(dentry);
6774 + if (unlikely(dpage->ndentry >= sz)) {
6775 + AuLabel(new dpage);
6777 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6778 + p = au_kzrealloc(dpages->dpages, sz,
6779 + sz + sizeof(*dpages->dpages), gfp,
6784 + dpages->dpages = p;
6785 + dpage = dpages->dpages + dpages->ndpage;
6786 + p = (void *)__get_free_page(gfp);
6790 + dpage->ndentry = 0;
6791 + dpage->dentries = p;
6795 + AuDebugOn(au_dcount(dentry) <= 0);
6796 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6797 + return 0; /* success */
6803 +/* todo: BAD approach */
6804 +/* copied from linux/fs/dcache.c */
6812 +extern void d_walk(struct dentry *parent, void *data,
6813 + enum d_walk_ret (*enter)(void *, struct dentry *),
6814 + void (*finish)(void *));
6816 +struct ac_dpages_arg {
6818 + struct au_dcsub_pages *dpages;
6819 + struct super_block *sb;
6820 + au_dpages_test test;
6824 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6826 + enum d_walk_ret ret;
6827 + struct ac_dpages_arg *arg = _arg;
6829 + ret = D_WALK_CONTINUE;
6830 + if (dentry->d_sb == arg->sb
6831 + && !IS_ROOT(dentry)
6832 + && au_dcount(dentry) > 0
6834 + && (!arg->test || arg->test(dentry, arg->arg))) {
6835 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6836 + if (unlikely(arg->err))
6837 + ret = D_WALK_QUIT;
6843 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6844 + au_dpages_test test, void *arg)
6846 + struct ac_dpages_arg args = {
6854 + d_walk(root, &args, au_call_dpages_append, NULL);
6859 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6860 + int do_include, au_dpages_test test, void *arg)
6865 + write_seqlock(&rename_lock);
6866 + spin_lock(&dentry->d_lock);
6868 + && au_dcount(dentry) > 0
6869 + && (!test || test(dentry, arg)))
6870 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6871 + spin_unlock(&dentry->d_lock);
6872 + if (unlikely(err))
6876 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6879 + while (!IS_ROOT(dentry)) {
6880 + dentry = dentry->d_parent; /* rename_lock is locked */
6881 + spin_lock(&dentry->d_lock);
6882 + if (au_dcount(dentry) > 0
6883 + && (!test || test(dentry, arg)))
6884 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6885 + spin_unlock(&dentry->d_lock);
6886 + if (unlikely(err))
6891 + write_sequnlock(&rename_lock);
6895 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6897 + return au_di(dentry) && dentry->d_sb == arg;
6900 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6901 + struct dentry *dentry, int do_include)
6903 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6904 + au_dcsub_dpages_aufs, dentry->d_sb);
6907 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6909 + struct path path[2] = {
6918 + return path_is_under(path + 0, path + 1);
6920 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6921 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6922 +++ linux/fs/aufs/dcsub.h 2017-05-06 22:16:52.778220093 +0200
6925 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6927 + * This program, aufs is free software; you can redistribute it and/or modify
6928 + * it under the terms of the GNU General Public License as published by
6929 + * the Free Software Foundation; either version 2 of the License, or
6930 + * (at your option) any later version.
6932 + * This program is distributed in the hope that it will be useful,
6933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6935 + * GNU General Public License for more details.
6937 + * You should have received a copy of the GNU General Public License
6938 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6942 + * sub-routines for dentry cache
6945 +#ifndef __AUFS_DCSUB_H__
6946 +#define __AUFS_DCSUB_H__
6950 +#include <linux/dcache.h>
6951 +#include <linux/fs.h>
6955 + struct dentry **dentries;
6958 +struct au_dcsub_pages {
6960 + struct au_dpage *dpages;
6963 +/* ---------------------------------------------------------------------- */
6966 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6967 +void au_dpages_free(struct au_dcsub_pages *dpages);
6968 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6969 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6970 + au_dpages_test test, void *arg);
6971 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6972 + int do_include, au_dpages_test test, void *arg);
6973 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6974 + struct dentry *dentry, int do_include);
6975 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6977 +/* ---------------------------------------------------------------------- */
6980 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6981 + * include/linux/dcache.h. Try them (in the future).
6984 +static inline int au_d_hashed_positive(struct dentry *d)
6987 + struct inode *inode = d_inode(d);
6990 + if (unlikely(d_unhashed(d)
6991 + || d_is_negative(d)
6992 + || !inode->i_nlink))
6997 +static inline int au_d_linkable(struct dentry *d)
7000 + struct inode *inode = d_inode(d);
7002 + err = au_d_hashed_positive(d);
7004 + && d_is_positive(d)
7005 + && (inode->i_state & I_LINKABLE))
7010 +static inline int au_d_alive(struct dentry *d)
7013 + struct inode *inode;
7017 + err = au_d_hashed_positive(d);
7019 + inode = d_inode(d);
7020 + if (unlikely(d_unlinked(d)
7021 + || d_is_negative(d)
7022 + || !inode->i_nlink))
7028 +static inline int au_alive_dir(struct dentry *d)
7032 + err = au_d_alive(d);
7033 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7038 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7040 + return a->len == b->len
7041 + && !memcmp(a->name, b->name, a->len);
7046 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7048 + * the type of d_lockref.count became int, but the inlined function d_count()
7049 + * still returns unsigned int.
7050 + * I don't know why. Maybe it is for every d_count() users?
7051 + * Anyway au_dcount() lives on.
7053 +static inline int au_dcount(struct dentry *d)
7055 + return (int)d_count(d);
7058 +#endif /* __KERNEL__ */
7059 +#endif /* __AUFS_DCSUB_H__ */
7060 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7061 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7062 +++ linux/fs/aufs/debug.c 2017-05-06 22:16:52.778220093 +0200
7065 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7067 + * This program, aufs is free software; you can redistribute it and/or modify
7068 + * it under the terms of the GNU General Public License as published by
7069 + * the Free Software Foundation; either version 2 of the License, or
7070 + * (at your option) any later version.
7072 + * This program is distributed in the hope that it will be useful,
7073 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7075 + * GNU General Public License for more details.
7077 + * You should have received a copy of the GNU General Public License
7078 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7082 + * debug print functions
7087 +/* Returns 0, or -errno. arg is in kp->arg. */
7088 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7092 + err = kstrtoint(val, 0, &n);
7102 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7103 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7108 + return sprintf(buffer, "%d", atomic_read(a));
7111 +static struct kernel_param_ops param_ops_atomic_t = {
7112 + .set = param_atomic_t_set,
7113 + .get = param_atomic_t_get
7114 + /* void (*free)(void *arg) */
7117 +atomic_t aufs_debug = ATOMIC_INIT(0);
7118 +MODULE_PARM_DESC(debug, "debug print");
7119 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7121 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7122 +char *au_plevel = KERN_DEBUG;
7123 +#define dpri(fmt, ...) do { \
7125 + && strcmp(au_plevel, KERN_DEBUG)) \
7126 + || au_debug_test()) \
7127 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7130 +/* ---------------------------------------------------------------------- */
7132 +void au_dpri_whlist(struct au_nhash *whlist)
7134 + unsigned long ul, n;
7135 + struct hlist_head *head;
7136 + struct au_vdir_wh *pos;
7138 + n = whlist->nh_num;
7139 + head = whlist->nh_head;
7140 + for (ul = 0; ul < n; ul++) {
7141 + hlist_for_each_entry(pos, head, wh_hash)
7142 + dpri("b%d, %.*s, %d\n",
7144 + pos->wh_str.len, pos->wh_str.name,
7150 +void au_dpri_vdir(struct au_vdir *vdir)
7153 + union au_vdir_deblk_p p;
7156 + if (!vdir || IS_ERR(vdir)) {
7157 + dpri("err %ld\n", PTR_ERR(vdir));
7161 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7162 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7163 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7164 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7165 + p.deblk = vdir->vd_deblk[ul];
7167 + dpri("[%lu]: %p\n", ul, o);
7171 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7172 + struct dentry *wh)
7177 + if (!inode || IS_ERR(inode)) {
7178 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7182 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7183 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7184 + && sizeof(inode->i_blocks) != sizeof(u64));
7186 + n = (void *)wh->d_name.name;
7187 + l = wh->d_name.len;
7190 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7191 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7193 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7194 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7195 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7196 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7197 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7198 + inode->i_state, inode->i_flags, inode->i_version,
7199 + inode->i_generation,
7200 + l ? ", wh " : "", l, n);
7204 +void au_dpri_inode(struct inode *inode)
7206 + struct au_iinfo *iinfo;
7207 + struct au_hinode *hi;
7208 + aufs_bindex_t bindex;
7211 + err = do_pri_inode(-1, inode, -1, NULL);
7212 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7215 + iinfo = au_ii(inode);
7216 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7217 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7218 + if (iinfo->ii_btop < 0)
7221 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7222 + hi = au_hinode(iinfo, bindex);
7224 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7228 +void au_dpri_dalias(struct inode *inode)
7232 + spin_lock(&inode->i_lock);
7233 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7234 + au_dpri_dentry(d);
7235 + spin_unlock(&inode->i_lock);
7238 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7240 + struct dentry *wh = NULL;
7242 + struct inode *inode;
7243 + struct au_iinfo *iinfo;
7244 + struct au_hinode *hi;
7246 + if (!dentry || IS_ERR(dentry)) {
7247 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7250 + /* do not call dget_parent() here */
7251 + /* note: access d_xxx without d_lock */
7252 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7253 + bindex, dentry, dentry,
7254 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7255 + au_dcount(dentry), dentry->d_flags,
7256 + d_unhashed(dentry) ? "un" : "");
7259 + if (d_is_positive(dentry))
7260 + inode = d_inode(dentry);
7262 + && au_test_aufs(dentry->d_sb)
7264 + && !au_is_bad_inode(inode)) {
7265 + iinfo = au_ii(inode);
7266 + hi = au_hinode(iinfo, bindex);
7268 + wh = hi->hi_whdentry;
7270 + do_pri_inode(bindex, inode, hn, wh);
7274 +void au_dpri_dentry(struct dentry *dentry)
7276 + struct au_dinfo *dinfo;
7277 + aufs_bindex_t bindex;
7280 + err = do_pri_dentry(-1, dentry);
7281 + if (err || !au_test_aufs(dentry->d_sb))
7284 + dinfo = au_di(dentry);
7287 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7288 + dinfo->di_btop, dinfo->di_bbot,
7289 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7290 + dinfo->di_tmpfile);
7291 + if (dinfo->di_btop < 0)
7293 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7294 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7297 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7301 + if (!file || IS_ERR(file)) {
7302 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7307 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7308 + && au_test_aufs(file->f_path.dentry->d_sb)
7310 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7311 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7312 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7313 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7314 + file->f_version, file->f_pos, a);
7315 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7316 + do_pri_dentry(bindex, file->f_path.dentry);
7320 +void au_dpri_file(struct file *file)
7322 + struct au_finfo *finfo;
7323 + struct au_fidir *fidir;
7324 + struct au_hfile *hfile;
7325 + aufs_bindex_t bindex;
7328 + err = do_pri_file(-1, file);
7330 + || IS_ERR_OR_NULL(file->f_path.dentry)
7331 + || !au_test_aufs(file->f_path.dentry->d_sb))
7334 + finfo = au_fi(file);
7337 + if (finfo->fi_btop < 0)
7339 + fidir = finfo->fi_hdir;
7341 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7343 + for (bindex = finfo->fi_btop;
7344 + bindex >= 0 && bindex <= fidir->fd_bbot;
7346 + hfile = fidir->fd_hfile + bindex;
7347 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7351 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7353 + struct vfsmount *mnt;
7354 + struct super_block *sb;
7356 + if (!br || IS_ERR(br))
7358 + mnt = au_br_mnt(br);
7359 + if (!mnt || IS_ERR(mnt))
7362 + if (!sb || IS_ERR(sb))
7365 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7366 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7368 + bindex, br->br_perm, br->br_id, au_br_count(br),
7369 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7370 + sb->s_flags, sb->s_count,
7371 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7375 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7379 +void au_dpri_sb(struct super_block *sb)
7381 + struct au_sbinfo *sbinfo;
7382 + aufs_bindex_t bindex;
7384 + /* to reuduce stack size */
7386 + struct vfsmount mnt;
7387 + struct au_branch fake;
7390 + /* this function can be called from magic sysrq */
7391 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7392 + if (unlikely(!a)) {
7393 + dpri("no memory\n");
7397 + a->mnt.mnt_sb = sb;
7398 + a->fake.br_path.mnt = &a->mnt;
7399 + au_br_count_init(&a->fake);
7400 + err = do_pri_br(-1, &a->fake);
7401 + au_br_count_fin(&a->fake);
7402 + au_delayed_kfree(a);
7403 + dpri("dev 0x%x\n", sb->s_dev);
7404 + if (err || !au_test_aufs(sb))
7407 + sbinfo = au_sbi(sb);
7410 + dpri("nw %d, gen %u, kobj %d\n",
7411 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7412 + kref_read(&sbinfo->si_kobj.kref));
7413 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7414 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7417 +/* ---------------------------------------------------------------------- */
7419 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7421 + struct inode *h_inode, *inode = d_inode(dentry);
7422 + struct dentry *h_dentry;
7423 + aufs_bindex_t bindex, bbot, bi;
7425 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7428 + bbot = au_dbbot(dentry);
7429 + bi = au_ibbot(inode);
7432 + bindex = au_dbtop(dentry);
7433 + bi = au_ibtop(inode);
7437 + for (; bindex <= bbot; bindex++) {
7438 + h_dentry = au_h_dptr(dentry, bindex);
7441 + h_inode = au_h_iptr(inode, bindex);
7442 + if (unlikely(h_inode != d_inode(h_dentry))) {
7444 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7445 + AuDbgDentry(dentry);
7446 + AuDbgInode(inode);
7453 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7456 + struct au_dcsub_pages dpages;
7457 + struct au_dpage *dpage;
7458 + struct dentry **dentries;
7460 + err = au_dpages_init(&dpages, GFP_NOFS);
7462 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7464 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7465 + dpage = dpages.dpages + i;
7466 + dentries = dpage->dentries;
7467 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7468 + AuDebugOn(au_digen_test(dentries[j], sigen));
7470 + au_dpages_free(&dpages);
7473 +void au_dbg_verify_kthread(void)
7475 + if (au_wkq_test()) {
7478 + * It may be recursive, but udba=notify between two aufs mounts,
7479 + * where a single ro branch is shared, is not a problem.
7485 +/* ---------------------------------------------------------------------- */
7487 +int __init au_debug_init(void)
7489 + aufs_bindex_t bindex;
7490 + struct au_vdir_destr destr;
7493 + AuDebugOn(bindex >= 0);
7496 + AuDebugOn(destr.len < NAME_MAX);
7498 +#ifdef CONFIG_4KSTACKS
7499 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7504 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7505 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7506 +++ linux/fs/aufs/debug.h 2017-05-06 22:16:52.778220093 +0200
7509 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7511 + * This program, aufs is free software; you can redistribute it and/or modify
7512 + * it under the terms of the GNU General Public License as published by
7513 + * the Free Software Foundation; either version 2 of the License, or
7514 + * (at your option) any later version.
7516 + * This program is distributed in the hope that it will be useful,
7517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7519 + * GNU General Public License for more details.
7521 + * You should have received a copy of the GNU General Public License
7522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7526 + * debug print functions
7529 +#ifndef __AUFS_DEBUG_H__
7530 +#define __AUFS_DEBUG_H__
7534 +#include <linux/atomic.h>
7535 +#include <linux/module.h>
7536 +#include <linux/kallsyms.h>
7537 +#include <linux/sysrq.h>
7539 +#ifdef CONFIG_AUFS_DEBUG
7540 +#define AuDebugOn(a) BUG_ON(a)
7542 +/* module parameter */
7543 +extern atomic_t aufs_debug;
7544 +static inline void au_debug_on(void)
7546 + atomic_inc(&aufs_debug);
7548 +static inline void au_debug_off(void)
7550 + atomic_dec_if_positive(&aufs_debug);
7553 +static inline int au_debug_test(void)
7555 + return atomic_read(&aufs_debug) > 0;
7558 +#define AuDebugOn(a) do {} while (0)
7559 +AuStubVoid(au_debug_on, void)
7560 +AuStubVoid(au_debug_off, void)
7561 +AuStubInt0(au_debug_test, void)
7562 +#endif /* CONFIG_AUFS_DEBUG */
7564 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7566 +/* ---------------------------------------------------------------------- */
7570 +#define AuDbg(fmt, ...) do { \
7571 + if (au_debug_test()) \
7572 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7574 +#define AuLabel(l) AuDbg(#l "\n")
7575 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7576 +#define AuWarn1(fmt, ...) do { \
7577 + static unsigned char _c; \
7579 + pr_warn(fmt, ##__VA_ARGS__); \
7582 +#define AuErr1(fmt, ...) do { \
7583 + static unsigned char _c; \
7585 + pr_err(fmt, ##__VA_ARGS__); \
7588 +#define AuIOErr1(fmt, ...) do { \
7589 + static unsigned char _c; \
7591 + AuIOErr(fmt, ##__VA_ARGS__); \
7594 +#define AuUnsupportMsg "This operation is not supported." \
7595 + " Please report this application to aufs-users ML."
7596 +#define AuUnsupport(fmt, ...) do { \
7597 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7601 +#define AuTraceErr(e) do { \
7602 + if (unlikely((e) < 0)) \
7603 + AuDbg("err %d\n", (int)(e)); \
7606 +#define AuTraceErrPtr(p) do { \
7608 + AuDbg("err %ld\n", PTR_ERR(p)); \
7611 +/* dirty macros for debug print, use with "%.*s" and caution */
7612 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7614 +/* ---------------------------------------------------------------------- */
7617 +#ifdef CONFIG_AUFS_DEBUG
7618 +extern struct mutex au_dbg_mtx;
7619 +extern char *au_plevel;
7621 +void au_dpri_whlist(struct au_nhash *whlist);
7623 +void au_dpri_vdir(struct au_vdir *vdir);
7625 +void au_dpri_inode(struct inode *inode);
7626 +void au_dpri_dalias(struct inode *inode);
7627 +void au_dpri_dentry(struct dentry *dentry);
7629 +void au_dpri_file(struct file *filp);
7630 +struct super_block;
7631 +void au_dpri_sb(struct super_block *sb);
7633 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7634 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7635 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7636 +void au_dbg_verify_kthread(void);
7638 +int __init au_debug_init(void);
7640 +#define AuDbgWhlist(w) do { \
7641 + mutex_lock(&au_dbg_mtx); \
7643 + au_dpri_whlist(w); \
7644 + mutex_unlock(&au_dbg_mtx); \
7647 +#define AuDbgVdir(v) do { \
7648 + mutex_lock(&au_dbg_mtx); \
7650 + au_dpri_vdir(v); \
7651 + mutex_unlock(&au_dbg_mtx); \
7654 +#define AuDbgInode(i) do { \
7655 + mutex_lock(&au_dbg_mtx); \
7657 + au_dpri_inode(i); \
7658 + mutex_unlock(&au_dbg_mtx); \
7661 +#define AuDbgDAlias(i) do { \
7662 + mutex_lock(&au_dbg_mtx); \
7664 + au_dpri_dalias(i); \
7665 + mutex_unlock(&au_dbg_mtx); \
7668 +#define AuDbgDentry(d) do { \
7669 + mutex_lock(&au_dbg_mtx); \
7671 + au_dpri_dentry(d); \
7672 + mutex_unlock(&au_dbg_mtx); \
7675 +#define AuDbgFile(f) do { \
7676 + mutex_lock(&au_dbg_mtx); \
7678 + au_dpri_file(f); \
7679 + mutex_unlock(&au_dbg_mtx); \
7682 +#define AuDbgSb(sb) do { \
7683 + mutex_lock(&au_dbg_mtx); \
7684 + AuDbg(#sb "\n"); \
7686 + mutex_unlock(&au_dbg_mtx); \
7689 +#define AuDbgSym(addr) do { \
7690 + char sym[KSYM_SYMBOL_LEN]; \
7691 + sprint_symbol(sym, (unsigned long)addr); \
7692 + AuDbg("%s\n", sym); \
7695 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7696 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7697 +AuStubVoid(au_dbg_verify_kthread, void)
7698 +AuStubInt0(__init au_debug_init, void)
7700 +#define AuDbgWhlist(w) do {} while (0)
7701 +#define AuDbgVdir(v) do {} while (0)
7702 +#define AuDbgInode(i) do {} while (0)
7703 +#define AuDbgDAlias(i) do {} while (0)
7704 +#define AuDbgDentry(d) do {} while (0)
7705 +#define AuDbgFile(f) do {} while (0)
7706 +#define AuDbgSb(sb) do {} while (0)
7707 +#define AuDbgSym(addr) do {} while (0)
7708 +#endif /* CONFIG_AUFS_DEBUG */
7710 +/* ---------------------------------------------------------------------- */
7712 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7713 +int __init au_sysrq_init(void);
7714 +void au_sysrq_fin(void);
7716 +#ifdef CONFIG_HW_CONSOLE
7717 +#define au_dbg_blocked() do { \
7719 + handle_sysrq('w'); \
7722 +AuStubVoid(au_dbg_blocked, void)
7726 +AuStubInt0(__init au_sysrq_init, void)
7727 +AuStubVoid(au_sysrq_fin, void)
7728 +AuStubVoid(au_dbg_blocked, void)
7729 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7731 +#endif /* __KERNEL__ */
7732 +#endif /* __AUFS_DEBUG_H__ */
7733 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7734 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7735 +++ linux/fs/aufs/dentry.c 2017-05-06 22:16:52.778220093 +0200
7738 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7740 + * This program, aufs is free software; you can redistribute it and/or modify
7741 + * it under the terms of the GNU General Public License as published by
7742 + * the Free Software Foundation; either version 2 of the License, or
7743 + * (at your option) any later version.
7745 + * This program is distributed in the hope that it will be useful,
7746 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7747 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7748 + * GNU General Public License for more details.
7750 + * You should have received a copy of the GNU General Public License
7751 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7755 + * lookup and dentry operations
7758 +#include <linux/namei.h>
7761 +struct au_do_lookup_args {
7762 + unsigned int flags;
7767 + * returns positive/negative dentry, NULL or an error.
7768 + * NULL means whiteout-ed or not-found.
7770 +static struct dentry*
7771 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7772 + aufs_bindex_t bindex, struct qstr *wh_name,
7773 + struct au_do_lookup_args *args)
7775 + struct dentry *h_dentry;
7776 + struct inode *h_inode;
7777 + struct au_branch *br;
7778 + int wh_found, opq;
7779 + unsigned char wh_able;
7780 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7781 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7785 + br = au_sbr(dentry->d_sb, bindex);
7786 + wh_able = !!au_br_whable(br->br_perm);
7788 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7789 + h_dentry = ERR_PTR(wh_found);
7792 + if (unlikely(wh_found < 0))
7795 + /* We found a whiteout */
7796 + /* au_set_dbbot(dentry, bindex); */
7797 + au_set_dbwh(dentry, bindex);
7799 + return NULL; /* success */
7803 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7805 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7806 + if (IS_ERR(h_dentry)) {
7807 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7813 + h_inode = d_inode(h_dentry);
7814 + if (d_is_negative(h_dentry)) {
7817 + } else if (wh_found
7818 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7821 + if (au_dbbot(dentry) <= bindex)
7822 + au_set_dbbot(dentry, bindex);
7823 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7824 + au_set_dbtop(dentry, bindex);
7825 + au_set_h_dptr(dentry, bindex, h_dentry);
7827 + if (!d_is_dir(h_dentry)
7829 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7830 + goto out; /* success */
7832 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7833 + opq = au_diropq_test(h_dentry);
7834 + inode_unlock(h_inode);
7836 + au_set_dbdiropq(dentry, bindex);
7837 + else if (unlikely(opq < 0)) {
7838 + au_set_h_dptr(dentry, bindex, NULL);
7839 + h_dentry = ERR_PTR(opq);
7850 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7852 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7853 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7859 + * returns the number of lower positive dentries,
7860 + * otherwise an error.
7861 + * can be called at unlinking with @type is zero.
7863 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7864 + unsigned int flags)
7866 + int npositive, err;
7867 + aufs_bindex_t bindex, btail, bdiropq;
7868 + unsigned char isdir, dirperm1;
7869 + struct qstr whname;
7870 + struct au_do_lookup_args args = {
7873 + const struct qstr *name = &dentry->d_name;
7874 + struct dentry *parent;
7875 + struct super_block *sb;
7877 + sb = dentry->d_sb;
7878 + err = au_test_shwh(sb, name);
7879 + if (unlikely(err))
7882 + err = au_wh_name_alloc(&whname, name);
7883 + if (unlikely(err))
7886 + isdir = !!d_is_dir(dentry);
7887 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7890 + parent = dget_parent(dentry);
7891 + btail = au_dbtaildir(parent);
7892 + for (bindex = btop; bindex <= btail; bindex++) {
7893 + struct dentry *h_parent, *h_dentry;
7894 + struct inode *h_inode, *h_dir;
7896 + h_dentry = au_h_dptr(dentry, bindex);
7898 + if (d_is_positive(h_dentry))
7902 + h_parent = au_h_dptr(parent, bindex);
7903 + if (!h_parent || !d_is_dir(h_parent))
7906 + h_dir = d_inode(h_parent);
7907 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7908 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7910 + inode_unlock(h_dir);
7911 + err = PTR_ERR(h_dentry);
7912 + if (IS_ERR(h_dentry))
7915 + au_fclr_lkup(args.flags, ALLOW_NEG);
7917 + au_fset_lkup(args.flags, IGNORE_PERM);
7919 + if (au_dbwh(dentry) == bindex)
7923 + if (d_is_negative(h_dentry))
7925 + h_inode = d_inode(h_dentry);
7928 + args.type = h_inode->i_mode & S_IFMT;
7929 + if (args.type != S_IFDIR)
7932 + /* the type of lower may be different */
7933 + bdiropq = au_dbdiropq(dentry);
7934 + if (bdiropq >= 0 && bdiropq <= bindex)
7940 + AuLabel(positive);
7941 + au_update_dbtop(dentry);
7944 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7945 + && au_dbtop(dentry) < 0)) {
7947 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7953 + au_delayed_kfree(whname.name);
7958 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7960 + struct dentry *dentry;
7963 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7964 + dentry = vfsub_lkup_one(name, parent);
7966 + struct vfsub_lkup_one_args args = {
7972 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7973 + if (unlikely(wkq_err))
7974 + dentry = ERR_PTR(wkq_err);
7981 + * lookup @dentry on @bindex which should be negative.
7983 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7986 + struct dentry *parent, *h_parent, *h_dentry;
7987 + struct au_branch *br;
7989 + parent = dget_parent(dentry);
7990 + h_parent = au_h_dptr(parent, bindex);
7991 + br = au_sbr(dentry->d_sb, bindex);
7993 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7995 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7996 + err = PTR_ERR(h_dentry);
7997 + if (IS_ERR(h_dentry))
7999 + if (unlikely(d_is_positive(h_dentry))) {
8001 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8007 + if (bindex < au_dbtop(dentry))
8008 + au_set_dbtop(dentry, bindex);
8009 + if (au_dbbot(dentry) < bindex)
8010 + au_set_dbbot(dentry, bindex);
8011 + au_set_h_dptr(dentry, bindex, h_dentry);
8018 +/* ---------------------------------------------------------------------- */
8020 +/* subset of struct inode */
8022 + unsigned long i_ino;
8023 + /* unsigned int i_nlink; */
8029 + blkcnt_t i_blocks;
8034 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8036 + ia->i_ino = h_inode->i_ino;
8037 + /* ia->i_nlink = h_inode->i_nlink; */
8038 + ia->i_uid = h_inode->i_uid;
8039 + ia->i_gid = h_inode->i_gid;
8040 + ia->i_version = h_inode->i_version;
8042 + ia->i_size = h_inode->i_size;
8043 + ia->i_blocks = h_inode->i_blocks;
8045 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8048 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8050 + return ia->i_ino != h_inode->i_ino
8051 + /* || ia->i_nlink != h_inode->i_nlink */
8052 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8053 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8054 + || ia->i_version != h_inode->i_version
8056 + || ia->i_size != h_inode->i_size
8057 + || ia->i_blocks != h_inode->i_blocks
8059 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8062 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8063 + struct au_branch *br)
8066 + struct au_iattr ia;
8067 + struct inode *h_inode;
8068 + struct dentry *h_d;
8069 + struct super_block *h_sb;
8072 + memset(&ia, -1, sizeof(ia));
8073 + h_sb = h_dentry->d_sb;
8075 + if (d_is_positive(h_dentry)) {
8076 + h_inode = d_inode(h_dentry);
8077 + au_iattr_save(&ia, h_inode);
8078 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8079 + /* nfs d_revalidate may return 0 for negative dentry */
8080 + /* fuse d_revalidate always return 0 for negative dentry */
8083 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8084 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8085 + err = PTR_ERR(h_d);
8090 + if (unlikely(h_d != h_dentry
8091 + || d_inode(h_d) != h_inode
8092 + || (h_inode && au_iattr_test(&ia, h_inode))))
8093 + err = au_busy_or_stale();
8101 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8102 + struct dentry *h_parent, struct au_branch *br)
8107 + if (udba == AuOpt_UDBA_REVAL
8108 + && !au_test_fs_remote(h_dentry->d_sb)) {
8110 + err = (d_inode(h_dentry->d_parent) != h_dir);
8111 + } else if (udba != AuOpt_UDBA_NONE)
8112 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8117 +/* ---------------------------------------------------------------------- */
8119 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8122 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8123 + struct au_hdentry tmp, *p, *q;
8124 + struct au_dinfo *dinfo;
8125 + struct super_block *sb;
8127 + DiMustWriteLock(dentry);
8129 + sb = dentry->d_sb;
8130 + dinfo = au_di(dentry);
8131 + bbot = dinfo->di_bbot;
8132 + bwh = dinfo->di_bwh;
8133 + bdiropq = dinfo->di_bdiropq;
8134 + bindex = dinfo->di_btop;
8135 + p = au_hdentry(dinfo, bindex);
8136 + for (; bindex <= bbot; bindex++, p++) {
8137 + if (!p->hd_dentry)
8140 + new_bindex = au_br_index(sb, p->hd_id);
8141 + if (new_bindex == bindex)
8144 + if (dinfo->di_bwh == bindex)
8146 + if (dinfo->di_bdiropq == bindex)
8147 + bdiropq = new_bindex;
8148 + if (new_bindex < 0) {
8150 + p->hd_dentry = NULL;
8154 + /* swap two lower dentries, and loop again */
8155 + q = au_hdentry(dinfo, new_bindex);
8159 + if (tmp.hd_dentry) {
8165 + dinfo->di_bwh = -1;
8166 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8167 + dinfo->di_bwh = bwh;
8169 + dinfo->di_bdiropq = -1;
8171 + && bdiropq <= au_sbbot(sb)
8172 + && au_sbr_whable(sb, bdiropq))
8173 + dinfo->di_bdiropq = bdiropq;
8176 + dinfo->di_btop = -1;
8177 + dinfo->di_bbot = -1;
8178 + bbot = au_dbbot(parent);
8180 + p = au_hdentry(dinfo, bindex);
8181 + for (; bindex <= bbot; bindex++, p++)
8182 + if (p->hd_dentry) {
8183 + dinfo->di_btop = bindex;
8187 + if (dinfo->di_btop >= 0) {
8189 + p = au_hdentry(dinfo, bindex);
8190 + for (; bindex >= 0; bindex--, p--)
8191 + if (p->hd_dentry) {
8192 + dinfo->di_bbot = bindex;
8201 +static void au_do_hide(struct dentry *dentry)
8203 + struct inode *inode;
8205 + if (d_really_is_positive(dentry)) {
8206 + inode = d_inode(dentry);
8207 + if (!d_is_dir(dentry)) {
8208 + if (inode->i_nlink && !d_unhashed(dentry))
8209 + drop_nlink(inode);
8211 + clear_nlink(inode);
8212 + /* stop next lookup */
8213 + inode->i_flags |= S_DEAD;
8215 + smp_mb(); /* necessary? */
8220 +static int au_hide_children(struct dentry *parent)
8222 + int err, i, j, ndentry;
8223 + struct au_dcsub_pages dpages;
8224 + struct au_dpage *dpage;
8225 + struct dentry *dentry;
8227 + err = au_dpages_init(&dpages, GFP_NOFS);
8228 + if (unlikely(err))
8230 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8231 + if (unlikely(err))
8234 + /* in reverse order */
8235 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8236 + dpage = dpages.dpages + i;
8237 + ndentry = dpage->ndentry;
8238 + for (j = ndentry - 1; j >= 0; j--) {
8239 + dentry = dpage->dentries[j];
8240 + if (dentry != parent)
8241 + au_do_hide(dentry);
8246 + au_dpages_free(&dpages);
8251 +static void au_hide(struct dentry *dentry)
8255 + AuDbgDentry(dentry);
8256 + if (d_is_dir(dentry)) {
8257 + /* shrink_dcache_parent(dentry); */
8258 + err = au_hide_children(dentry);
8259 + if (unlikely(err))
8260 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8263 + au_do_hide(dentry);
8267 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8269 + * a dirty branch is added
8270 + * - on the top of layers
8271 + * - in the middle of layers
8272 + * - to the bottom of layers
8274 + * on the added branch there exists
8277 + * - a same named entry
8279 + * * negative --> positive
8280 + * * positive --> positive
8281 + * - type is unchanged
8282 + * - type is changed
8284 + * * negative --> negative
8285 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8288 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8289 + struct au_dinfo *tmp)
8292 + aufs_bindex_t bindex, bbot;
8294 + struct dentry *dentry;
8295 + struct inode *inode;
8297 + } orig_h, tmp_h = {
8300 + struct au_hdentry *hd;
8301 + struct inode *inode, *h_inode;
8302 + struct dentry *h_dentry;
8305 + AuDebugOn(dinfo->di_btop < 0);
8307 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8308 + orig_h.inode = NULL;
8309 + if (d_is_positive(orig_h.dentry)) {
8310 + orig_h.inode = d_inode(orig_h.dentry);
8311 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8313 + if (tmp->di_btop >= 0) {
8314 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8315 + if (d_is_positive(tmp_h.dentry)) {
8316 + tmp_h.inode = d_inode(tmp_h.dentry);
8317 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8322 + if (d_really_is_positive(dentry))
8323 + inode = d_inode(dentry);
8324 + if (!orig_h.inode) {
8325 + AuDbg("nagative originally\n");
8331 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8332 + AuDebugOn(dinfo->di_bdiropq != -1);
8334 + if (!tmp_h.inode) {
8335 + AuDbg("negative --> negative\n");
8336 + /* should have only one negative lower */
8337 + if (tmp->di_btop >= 0
8338 + && tmp->di_btop < dinfo->di_btop) {
8339 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8340 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8341 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8342 + au_di_cp(dinfo, tmp);
8343 + hd = au_hdentry(tmp, tmp->di_btop);
8344 + au_set_h_dptr(dentry, tmp->di_btop,
8345 + dget(hd->hd_dentry));
8347 + au_dbg_verify_dinode(dentry);
8349 + AuDbg("negative --> positive\n");
8351 + * similar to the behaviour of creating with bypassing
8353 + * unhash it in order to force an error in the
8354 + * succeeding create operation.
8355 + * we should not set S_DEAD here.
8358 + /* au_di_swap(tmp, dinfo); */
8359 + au_dbg_verify_dinode(dentry);
8362 + AuDbg("positive originally\n");
8363 + /* inode may be NULL */
8364 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8365 + if (!tmp_h.inode) {
8366 + AuDbg("positive --> negative\n");
8367 + /* or bypassing aufs */
8369 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8370 + dinfo->di_bwh = tmp->di_bwh;
8372 + err = au_refresh_hinode_self(inode);
8373 + au_dbg_verify_dinode(dentry);
8374 + } else if (orig_h.mode == tmp_h.mode) {
8375 + AuDbg("positive --> positive, same type\n");
8376 + if (!S_ISDIR(orig_h.mode)
8377 + && dinfo->di_btop > tmp->di_btop) {
8379 + * similar to the behaviour of removing and
8384 + err = au_refresh_hinode_self(inode);
8385 + au_dbg_verify_dinode(dentry);
8387 + /* fill empty slots */
8388 + if (dinfo->di_btop > tmp->di_btop)
8389 + dinfo->di_btop = tmp->di_btop;
8390 + if (dinfo->di_bbot < tmp->di_bbot)
8391 + dinfo->di_bbot = tmp->di_bbot;
8392 + dinfo->di_bwh = tmp->di_bwh;
8393 + dinfo->di_bdiropq = tmp->di_bdiropq;
8394 + bbot = dinfo->di_bbot;
8395 + bindex = tmp->di_btop;
8396 + hd = au_hdentry(tmp, bindex);
8397 + for (; bindex <= bbot; bindex++, hd++) {
8398 + if (au_h_dptr(dentry, bindex))
8400 + h_dentry = hd->hd_dentry;
8403 + AuDebugOn(d_is_negative(h_dentry));
8404 + h_inode = d_inode(h_dentry);
8405 + AuDebugOn(orig_h.mode
8406 + != (h_inode->i_mode
8408 + au_set_h_dptr(dentry, bindex,
8412 + err = au_refresh_hinode(inode, dentry);
8413 + au_dbg_verify_dinode(dentry);
8416 + AuDbg("positive --> positive, different type\n");
8417 + /* similar to the behaviour of removing and creating */
8420 + err = au_refresh_hinode_self(inode);
8421 + au_dbg_verify_dinode(dentry);
8429 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8431 + const struct dentry_operations *dop
8432 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8433 + static const unsigned int mask
8434 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8436 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8438 + if (dentry->d_op == dop)
8441 + AuDbg("%pd\n", dentry);
8442 + spin_lock(&dentry->d_lock);
8443 + if (dop == &aufs_dop)
8444 + dentry->d_flags |= mask;
8446 + dentry->d_flags &= ~mask;
8447 + dentry->d_op = dop;
8448 + spin_unlock(&dentry->d_lock);
8451 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8453 + int err, ebrange, nbr;
8454 + unsigned int sigen;
8455 + struct au_dinfo *dinfo, *tmp;
8456 + struct super_block *sb;
8457 + struct inode *inode;
8459 + DiMustWriteLock(dentry);
8460 + AuDebugOn(IS_ROOT(dentry));
8461 + AuDebugOn(d_really_is_negative(parent));
8463 + sb = dentry->d_sb;
8464 + sigen = au_sigen(sb);
8465 + err = au_digen_test(parent, sigen);
8466 + if (unlikely(err))
8469 + nbr = au_sbbot(sb) + 1;
8470 + dinfo = au_di(dentry);
8471 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8472 + if (unlikely(err))
8474 + ebrange = au_dbrange_test(dentry);
8476 + ebrange = au_do_refresh_hdentry(dentry, parent);
8478 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8479 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8480 + if (d_really_is_positive(dentry)) {
8481 + inode = d_inode(dentry);
8482 + err = au_refresh_hinode_self(inode);
8484 + au_dbg_verify_dinode(dentry);
8486 + goto out_dgen; /* success */
8490 + /* temporary dinfo */
8491 + AuDbgDentry(dentry);
8493 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8494 + if (unlikely(!tmp))
8496 + au_di_swap(tmp, dinfo);
8497 + /* returns the number of positive dentries */
8499 + * if current working dir is removed, it returns an error.
8500 + * but the dentry is legal.
8502 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8503 + AuDbgDentry(dentry);
8504 + au_di_swap(tmp, dinfo);
8505 + if (err == -ENOENT)
8508 + /* compare/refresh by dinfo */
8509 + AuDbgDentry(dentry);
8510 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8511 + au_dbg_verify_dinode(dentry);
8514 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8515 + au_rw_write_unlock(&tmp->di_rwsem);
8517 + if (unlikely(err))
8521 + au_update_digen(dentry);
8523 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8524 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8525 + AuDbgDentry(dentry);
8531 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8532 + struct dentry *dentry, aufs_bindex_t bindex)
8537 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8540 + AuDbg("b%d\n", bindex);
8542 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8543 + * due to whiteout and branch permission.
8545 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8546 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8547 + /* it may return tri-state */
8548 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8550 + if (unlikely(valid < 0))
8560 +/* todo: remove this */
8561 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8562 + unsigned int flags, int do_udba)
8565 + umode_t mode, h_mode;
8566 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8567 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8568 + struct inode *h_inode, *h_cached_inode;
8569 + struct dentry *h_dentry;
8570 + struct qstr *name, *h_name;
8577 + unhashed = !!d_unhashed(dentry);
8578 + is_root = !!IS_ROOT(dentry);
8579 + name = &dentry->d_name;
8580 + tmpfile = au_di(dentry)->di_tmpfile;
8583 + * Theoretically, REVAL test should be unnecessary in case of
8585 + * But {fs,i}notify doesn't fire some necessary events,
8586 + * IN_ATTRIB for atime/nlink/pageio
8587 + * Let's do REVAL test too.
8589 + if (do_udba && inode) {
8590 + mode = (inode->i_mode & S_IFMT);
8591 + plus = (inode->i_nlink > 0);
8592 + ibs = au_ibtop(inode);
8593 + ibe = au_ibbot(inode);
8596 + btop = au_dbtop(dentry);
8598 + if (inode && S_ISDIR(inode->i_mode))
8599 + btail = au_dbtaildir(dentry);
8600 + for (bindex = btop; bindex <= btail; bindex++) {
8601 + h_dentry = au_h_dptr(dentry, bindex);
8605 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8606 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8607 + spin_lock(&h_dentry->d_lock);
8608 + h_name = &h_dentry->d_name;
8609 + if (unlikely(do_udba
8612 + && (unhashed != !!d_unhashed(h_dentry)
8614 + && !au_qstreq(name, h_name))
8617 + && !(flags & LOOKUP_OPEN)
8618 + && (h_dentry->d_flags
8619 + & DCACHE_NFSFS_RENAMED)))
8623 + h_unhashed = d_unhashed(h_dentry);
8624 + spin_unlock(&h_dentry->d_lock);
8625 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8626 + unhashed, h_unhashed, dentry, h_dentry);
8629 + spin_unlock(&h_dentry->d_lock);
8631 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8632 + if (unlikely(err))
8633 + /* do not goto err, to keep the errno */
8636 + /* todo: plink too? */
8641 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8645 + if (d_is_positive(h_dentry))
8646 + h_inode = d_inode(h_dentry);
8649 + h_cached_inode = h_inode;
8651 + h_mode = (h_inode->i_mode & S_IFMT);
8652 + h_plus = (h_inode->i_nlink > 0);
8654 + if (inode && ibs <= bindex && bindex <= ibe)
8655 + h_cached_inode = au_h_iptr(inode, bindex);
8658 + if (unlikely(plus != h_plus && !tmpfile))
8661 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8663 + && !IS_ROOT(h_dentry)
8664 + && unhashed != d_unhashed(h_dentry)))
8667 + if (unlikely(mode != h_mode
8668 + || h_cached_inode != h_inode))
8681 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8682 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8685 + struct dentry *parent;
8687 + if (!au_digen_test(dentry, sigen))
8690 + parent = dget_parent(dentry);
8691 + di_read_lock_parent(parent, AuLock_IR);
8692 + AuDebugOn(au_digen_test(parent, sigen));
8693 + au_dbg_verify_gen(parent, sigen);
8694 + err = au_refresh_dentry(dentry, parent);
8695 + di_read_unlock(parent, AuLock_IR);
8701 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8704 + struct dentry *d, *parent;
8706 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8707 + return simple_reval_dpath(dentry, sigen);
8709 + /* slow loop, keep it simple and stupid */
8710 + /* cf: au_cpup_dirs() */
8713 + while (au_digen_test(dentry, sigen)) {
8717 + parent = dget_parent(d);
8718 + if (!au_digen_test(parent, sigen))
8724 + di_write_lock_child2(d);
8726 + /* someone might update our dentry while we were sleeping */
8727 + if (au_digen_test(d, sigen)) {
8729 + * todo: consolidate with simple_reval_dpath(),
8730 + * do_refresh() and au_reval_for_attr().
8732 + di_read_lock_parent(parent, AuLock_IR);
8733 + err = au_refresh_dentry(d, parent);
8734 + di_read_unlock(parent, AuLock_IR);
8738 + di_write_unlock(d);
8740 + if (unlikely(err))
8748 + * if valid returns 1, otherwise 0.
8750 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8753 + unsigned int sigen;
8754 + unsigned char do_udba;
8755 + struct super_block *sb;
8756 + struct inode *inode;
8758 + /* todo: support rcu-walk? */
8759 + if (flags & LOOKUP_RCU)
8763 + if (unlikely(!au_di(dentry)))
8767 + sb = dentry->d_sb;
8770 + * i_mutex of parent dir may be held,
8771 + * but we should not return 'invalid' due to busy.
8773 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8774 + if (unlikely(err)) {
8780 + if (d_really_is_positive(dentry))
8781 + inode = d_inode(dentry);
8782 + if (unlikely(inode && au_is_bad_inode(inode))) {
8787 + if (unlikely(au_dbrange_test(dentry))) {
8793 + sigen = au_sigen(sb);
8794 + if (au_digen_test(dentry, sigen)) {
8795 + AuDebugOn(IS_ROOT(dentry));
8796 + err = au_reval_dpath(dentry, sigen);
8797 + if (unlikely(err)) {
8802 + di_downgrade_lock(dentry, AuLock_IR);
8805 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8807 + && !(inode->i_state && I_LINKABLE)
8808 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8813 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8814 + if (do_udba && inode) {
8815 + aufs_bindex_t btop = au_ibtop(inode);
8816 + struct inode *h_inode;
8819 + h_inode = au_h_iptr(inode, btop);
8820 + if (h_inode && au_test_higen(inode, h_inode)) {
8827 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8828 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8830 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8836 + di_downgrade_lock(dentry, AuLock_IR);
8838 + aufs_read_unlock(dentry, AuLock_IR);
8843 + AuDbg("%pd invalid, %d\n", dentry, valid);
8849 +static void aufs_d_release(struct dentry *dentry)
8851 + if (au_di(dentry)) {
8852 + au_di_fin(dentry);
8853 + au_hn_di_reinit(dentry);
8857 +const struct dentry_operations aufs_dop = {
8858 + .d_revalidate = aufs_d_revalidate,
8859 + .d_weak_revalidate = aufs_d_revalidate,
8860 + .d_release = aufs_d_release
8863 +/* aufs_dop without d_revalidate */
8864 +const struct dentry_operations aufs_dop_noreval = {
8865 + .d_release = aufs_d_release
8867 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8868 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8869 +++ linux/fs/aufs/dentry.h 2017-05-06 22:16:52.778220093 +0200
8872 + * Copyright (C) 2005-2017 Junjiro R. Okajima
8874 + * This program, aufs is free software; you can redistribute it and/or modify
8875 + * it under the terms of the GNU General Public License as published by
8876 + * the Free Software Foundation; either version 2 of the License, or
8877 + * (at your option) any later version.
8879 + * This program is distributed in the hope that it will be useful,
8880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8882 + * GNU General Public License for more details.
8884 + * You should have received a copy of the GNU General Public License
8885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8889 + * lookup and dentry operations
8892 +#ifndef __AUFS_DENTRY_H__
8893 +#define __AUFS_DENTRY_H__
8897 +#include <linux/dcache.h>
8900 +struct au_hdentry {
8901 + struct dentry *hd_dentry;
8902 + aufs_bindex_t hd_id;
8906 + atomic_t di_generation;
8908 + struct au_rwsem di_rwsem;
8909 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8910 + unsigned char di_tmpfile; /* to allow the different name */
8912 + struct au_hdentry *di_hdentry;
8913 + struct llist_node di_lnode; /* delayed free */
8915 +} ____cacheline_aligned_in_smp;
8917 +/* ---------------------------------------------------------------------- */
8919 +/* flags for au_lkup_dentry() */
8920 +#define AuLkup_ALLOW_NEG 1
8921 +#define AuLkup_IGNORE_PERM (1 << 1)
8922 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8923 +#define au_fset_lkup(flags, name) \
8924 + do { (flags) |= AuLkup_##name; } while (0)
8925 +#define au_fclr_lkup(flags, name) \
8926 + do { (flags) &= ~AuLkup_##name; } while (0)
8928 +/* ---------------------------------------------------------------------- */
8931 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8933 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8934 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8935 + struct dentry *h_parent, struct au_branch *br);
8937 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8938 + unsigned int flags);
8939 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8940 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8941 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8942 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8945 +void au_di_init_once(void *_di);
8946 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8947 +void au_di_free(struct au_dinfo *dinfo);
8948 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8949 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8950 +int au_di_init(struct dentry *dentry);
8951 +void au_di_fin(struct dentry *dentry);
8952 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8954 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8955 +void di_read_unlock(struct dentry *d, int flags);
8956 +void di_downgrade_lock(struct dentry *d, int flags);
8957 +void di_write_lock(struct dentry *d, unsigned int lsc);
8958 +void di_write_unlock(struct dentry *d);
8959 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8960 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8961 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8963 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8964 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8965 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8966 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8968 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8969 + struct dentry *h_dentry);
8970 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8971 +int au_dbrange_test(struct dentry *dentry);
8972 +void au_update_digen(struct dentry *dentry);
8973 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8974 +void au_update_dbtop(struct dentry *dentry);
8975 +void au_update_dbbot(struct dentry *dentry);
8976 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8978 +/* ---------------------------------------------------------------------- */
8980 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8982 + return dentry->d_fsdata;
8985 +/* ---------------------------------------------------------------------- */
8987 +/* lock subclass for dinfo */
8989 + AuLsc_DI_CHILD, /* child first */
8990 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8991 + AuLsc_DI_CHILD3, /* copyup dirs */
8995 + AuLsc_DI_TMP /* temp for replacing dinfo */
8999 + * di_read_lock_child, di_write_lock_child,
9000 + * di_read_lock_child2, di_write_lock_child2,
9001 + * di_read_lock_child3, di_write_lock_child3,
9002 + * di_read_lock_parent, di_write_lock_parent,
9003 + * di_read_lock_parent2, di_write_lock_parent2,
9004 + * di_read_lock_parent3, di_write_lock_parent3,
9006 +#define AuReadLockFunc(name, lsc) \
9007 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9008 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9010 +#define AuWriteLockFunc(name, lsc) \
9011 +static inline void di_write_lock_##name(struct dentry *d) \
9012 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9014 +#define AuRWLockFuncs(name, lsc) \
9015 + AuReadLockFunc(name, lsc) \
9016 + AuWriteLockFunc(name, lsc)
9018 +AuRWLockFuncs(child, CHILD);
9019 +AuRWLockFuncs(child2, CHILD2);
9020 +AuRWLockFuncs(child3, CHILD3);
9021 +AuRWLockFuncs(parent, PARENT);
9022 +AuRWLockFuncs(parent2, PARENT2);
9023 +AuRWLockFuncs(parent3, PARENT3);
9025 +#undef AuReadLockFunc
9026 +#undef AuWriteLockFunc
9027 +#undef AuRWLockFuncs
9029 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9030 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9031 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9033 +/* ---------------------------------------------------------------------- */
9035 +/* todo: memory barrier? */
9036 +static inline unsigned int au_digen(struct dentry *d)
9038 + return atomic_read(&au_di(d)->di_generation);
9041 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9043 + hdentry->hd_dentry = NULL;
9046 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9047 + aufs_bindex_t bindex)
9049 + return di->di_hdentry + bindex;
9052 +static inline void au_hdput(struct au_hdentry *hd)
9055 + dput(hd->hd_dentry);
9058 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9060 + DiMustAnyLock(dentry);
9061 + return au_di(dentry)->di_btop;
9064 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9066 + DiMustAnyLock(dentry);
9067 + return au_di(dentry)->di_bbot;
9070 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9072 + DiMustAnyLock(dentry);
9073 + return au_di(dentry)->di_bwh;
9076 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9078 + DiMustAnyLock(dentry);
9079 + return au_di(dentry)->di_bdiropq;
9082 +/* todo: hard/soft set? */
9083 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9085 + DiMustWriteLock(dentry);
9086 + au_di(dentry)->di_btop = bindex;
9089 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9091 + DiMustWriteLock(dentry);
9092 + au_di(dentry)->di_bbot = bindex;
9095 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9097 + DiMustWriteLock(dentry);
9098 + /* dbwh can be outside of btop - bbot range */
9099 + au_di(dentry)->di_bwh = bindex;
9102 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9104 + DiMustWriteLock(dentry);
9105 + au_di(dentry)->di_bdiropq = bindex;
9108 +/* ---------------------------------------------------------------------- */
9110 +#ifdef CONFIG_AUFS_HNOTIFY
9111 +static inline void au_digen_dec(struct dentry *d)
9113 + atomic_dec(&au_di(d)->di_generation);
9116 +static inline void au_hn_di_reinit(struct dentry *dentry)
9118 + dentry->d_fsdata = NULL;
9121 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9122 +#endif /* CONFIG_AUFS_HNOTIFY */
9124 +#endif /* __KERNEL__ */
9125 +#endif /* __AUFS_DENTRY_H__ */
9126 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9127 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9128 +++ linux/fs/aufs/dinfo.c 2017-05-06 22:16:52.778220093 +0200
9131 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9133 + * This program, aufs is free software; you can redistribute it and/or modify
9134 + * it under the terms of the GNU General Public License as published by
9135 + * the Free Software Foundation; either version 2 of the License, or
9136 + * (at your option) any later version.
9138 + * This program is distributed in the hope that it will be useful,
9139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9141 + * GNU General Public License for more details.
9143 + * You should have received a copy of the GNU General Public License
9144 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9148 + * dentry private data
9153 +void au_di_init_once(void *_dinfo)
9155 + struct au_dinfo *dinfo = _dinfo;
9157 + au_rw_init(&dinfo->di_rwsem);
9160 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9162 + struct au_dinfo *dinfo;
9165 + dinfo = au_cache_alloc_dinfo();
9166 + if (unlikely(!dinfo))
9169 + nbr = au_sbbot(sb) + 1;
9172 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9173 + if (dinfo->di_hdentry) {
9174 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9175 + dinfo->di_btop = -1;
9176 + dinfo->di_bbot = -1;
9177 + dinfo->di_bwh = -1;
9178 + dinfo->di_bdiropq = -1;
9179 + dinfo->di_tmpfile = 0;
9180 + for (i = 0; i < nbr; i++)
9181 + dinfo->di_hdentry[i].hd_id = -1;
9185 + au_cache_dfree_dinfo(dinfo);
9192 +void au_di_free(struct au_dinfo *dinfo)
9194 + struct au_hdentry *p;
9195 + aufs_bindex_t bbot, bindex;
9197 + /* dentry may not be revalidated */
9198 + bindex = dinfo->di_btop;
9199 + if (bindex >= 0) {
9200 + bbot = dinfo->di_bbot;
9201 + p = au_hdentry(dinfo, bindex);
9202 + while (bindex++ <= bbot)
9205 + au_delayed_kfree(dinfo->di_hdentry);
9206 + au_cache_dfree_dinfo(dinfo);
9209 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9211 + struct au_hdentry *p;
9214 + AuRwMustWriteLock(&a->di_rwsem);
9215 + AuRwMustWriteLock(&b->di_rwsem);
9217 +#define DiSwap(v, name) \
9219 + v = a->di_##name; \
9220 + a->di_##name = b->di_##name; \
9221 + b->di_##name = v; \
9224 + DiSwap(p, hdentry);
9228 + DiSwap(bi, bdiropq);
9234 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9236 + AuRwMustWriteLock(&dst->di_rwsem);
9237 + AuRwMustWriteLock(&src->di_rwsem);
9239 + dst->di_btop = src->di_btop;
9240 + dst->di_bbot = src->di_bbot;
9241 + dst->di_bwh = src->di_bwh;
9242 + dst->di_bdiropq = src->di_bdiropq;
9246 +int au_di_init(struct dentry *dentry)
9249 + struct super_block *sb;
9250 + struct au_dinfo *dinfo;
9253 + sb = dentry->d_sb;
9254 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9256 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9257 + /* smp_mb(); */ /* atomic_set */
9258 + dentry->d_fsdata = dinfo;
9265 +void au_di_fin(struct dentry *dentry)
9267 + struct au_dinfo *dinfo;
9269 + dinfo = au_di(dentry);
9270 + AuRwDestroy(&dinfo->di_rwsem);
9271 + au_di_free(dinfo);
9274 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9277 + struct au_hdentry *hdp;
9279 + AuRwMustWriteLock(&dinfo->di_rwsem);
9282 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9284 + sz = sizeof(*hdp);
9285 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9288 + dinfo->di_hdentry = hdp;
9295 +/* ---------------------------------------------------------------------- */
9297 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9300 + case AuLsc_DI_CHILD:
9301 + ii_write_lock_child(inode);
9303 + case AuLsc_DI_CHILD2:
9304 + ii_write_lock_child2(inode);
9306 + case AuLsc_DI_CHILD3:
9307 + ii_write_lock_child3(inode);
9309 + case AuLsc_DI_PARENT:
9310 + ii_write_lock_parent(inode);
9312 + case AuLsc_DI_PARENT2:
9313 + ii_write_lock_parent2(inode);
9315 + case AuLsc_DI_PARENT3:
9316 + ii_write_lock_parent3(inode);
9323 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9326 + case AuLsc_DI_CHILD:
9327 + ii_read_lock_child(inode);
9329 + case AuLsc_DI_CHILD2:
9330 + ii_read_lock_child2(inode);
9332 + case AuLsc_DI_CHILD3:
9333 + ii_read_lock_child3(inode);
9335 + case AuLsc_DI_PARENT:
9336 + ii_read_lock_parent(inode);
9338 + case AuLsc_DI_PARENT2:
9339 + ii_read_lock_parent2(inode);
9341 + case AuLsc_DI_PARENT3:
9342 + ii_read_lock_parent3(inode);
9349 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9351 + struct inode *inode;
9353 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9354 + if (d_really_is_positive(d)) {
9355 + inode = d_inode(d);
9356 + if (au_ftest_lock(flags, IW))
9357 + do_ii_write_lock(inode, lsc);
9358 + else if (au_ftest_lock(flags, IR))
9359 + do_ii_read_lock(inode, lsc);
9363 +void di_read_unlock(struct dentry *d, int flags)
9365 + struct inode *inode;
9367 + if (d_really_is_positive(d)) {
9368 + inode = d_inode(d);
9369 + if (au_ftest_lock(flags, IW)) {
9370 + au_dbg_verify_dinode(d);
9371 + ii_write_unlock(inode);
9372 + } else if (au_ftest_lock(flags, IR)) {
9373 + au_dbg_verify_dinode(d);
9374 + ii_read_unlock(inode);
9377 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9380 +void di_downgrade_lock(struct dentry *d, int flags)
9382 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9383 + ii_downgrade_lock(d_inode(d));
9384 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9387 +void di_write_lock(struct dentry *d, unsigned int lsc)
9389 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9390 + if (d_really_is_positive(d))
9391 + do_ii_write_lock(d_inode(d), lsc);
9394 +void di_write_unlock(struct dentry *d)
9396 + au_dbg_verify_dinode(d);
9397 + if (d_really_is_positive(d))
9398 + ii_write_unlock(d_inode(d));
9399 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9402 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9404 + AuDebugOn(d1 == d2
9405 + || d_inode(d1) == d_inode(d2)
9406 + || d1->d_sb != d2->d_sb);
9408 + if ((isdir && au_test_subdir(d1, d2))
9410 + di_write_lock_child(d1);
9411 + di_write_lock_child2(d2);
9413 + di_write_lock_child(d2);
9414 + di_write_lock_child2(d1);
9418 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9420 + AuDebugOn(d1 == d2
9421 + || d_inode(d1) == d_inode(d2)
9422 + || d1->d_sb != d2->d_sb);
9424 + if ((isdir && au_test_subdir(d1, d2))
9426 + di_write_lock_parent(d1);
9427 + di_write_lock_parent2(d2);
9429 + di_write_lock_parent(d2);
9430 + di_write_lock_parent2(d1);
9434 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9436 + di_write_unlock(d1);
9437 + if (d_inode(d1) == d_inode(d2))
9438 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9440 + di_write_unlock(d2);
9443 +/* ---------------------------------------------------------------------- */
9445 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9449 + DiMustAnyLock(dentry);
9451 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9453 + AuDebugOn(bindex < 0);
9454 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9455 + AuDebugOn(d && au_dcount(d) <= 0);
9460 + * extended version of au_h_dptr().
9461 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9464 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9466 + struct dentry *h_dentry;
9467 + struct inode *inode, *h_inode;
9469 + AuDebugOn(d_really_is_negative(dentry));
9472 + if (au_dbtop(dentry) <= bindex
9473 + && bindex <= au_dbbot(dentry))
9474 + h_dentry = au_h_dptr(dentry, bindex);
9475 + if (h_dentry && !au_d_linkable(h_dentry)) {
9477 + goto out; /* success */
9480 + inode = d_inode(dentry);
9481 + AuDebugOn(bindex < au_ibtop(inode));
9482 + AuDebugOn(au_ibbot(inode) < bindex);
9483 + h_inode = au_h_iptr(inode, bindex);
9484 + h_dentry = d_find_alias(h_inode);
9486 + if (!IS_ERR(h_dentry)) {
9487 + if (!au_d_linkable(h_dentry))
9488 + goto out; /* success */
9494 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9495 + h_dentry = au_plink_lkup(inode, bindex);
9496 + AuDebugOn(!h_dentry);
9497 + if (!IS_ERR(h_dentry)) {
9498 + if (!au_d_hashed_positive(h_dentry))
9499 + goto out; /* success */
9506 + AuDbgDentry(h_dentry);
9510 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9512 + aufs_bindex_t bbot, bwh;
9514 + bbot = au_dbbot(dentry);
9516 + bwh = au_dbwh(dentry);
9519 + if (0 < bwh && bwh < bbot)
9525 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9527 + aufs_bindex_t bbot, bopq;
9529 + bbot = au_dbtail(dentry);
9531 + bopq = au_dbdiropq(dentry);
9532 + if (0 <= bopq && bopq < bbot)
9538 +/* ---------------------------------------------------------------------- */
9540 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9541 + struct dentry *h_dentry)
9543 + struct au_dinfo *dinfo;
9544 + struct au_hdentry *hd;
9545 + struct au_branch *br;
9547 + DiMustWriteLock(dentry);
9549 + dinfo = au_di(dentry);
9550 + hd = au_hdentry(dinfo, bindex);
9552 + hd->hd_dentry = h_dentry;
9554 + br = au_sbr(dentry->d_sb, bindex);
9555 + hd->hd_id = br->br_id;
9559 +int au_dbrange_test(struct dentry *dentry)
9562 + aufs_bindex_t btop, bbot;
9565 + btop = au_dbtop(dentry);
9566 + bbot = au_dbbot(dentry);
9568 + AuDebugOn(bbot < 0 && btop > bbot);
9571 + AuDebugOn(bbot >= 0);
9577 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9582 + if (unlikely(au_digen(dentry) != sigen
9583 + || au_iigen_test(d_inode(dentry), sigen)))
9589 +void au_update_digen(struct dentry *dentry)
9591 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9592 + /* smp_mb(); */ /* atomic_set */
9595 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9597 + struct au_dinfo *dinfo;
9598 + struct dentry *h_d;
9599 + struct au_hdentry *hdp;
9600 + aufs_bindex_t bindex, bbot;
9602 + DiMustWriteLock(dentry);
9604 + dinfo = au_di(dentry);
9605 + if (!dinfo || dinfo->di_btop < 0)
9608 + if (do_put_zero) {
9609 + bbot = dinfo->di_bbot;
9610 + bindex = dinfo->di_btop;
9611 + hdp = au_hdentry(dinfo, bindex);
9612 + for (; bindex <= bbot; bindex++, hdp++) {
9613 + h_d = hdp->hd_dentry;
9614 + if (h_d && d_is_negative(h_d))
9615 + au_set_h_dptr(dentry, bindex, NULL);
9619 + dinfo->di_btop = 0;
9620 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9621 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9622 + if (hdp->hd_dentry)
9624 + if (dinfo->di_btop > dinfo->di_bbot) {
9625 + dinfo->di_btop = -1;
9626 + dinfo->di_bbot = -1;
9630 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9631 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9632 + if (hdp->hd_dentry)
9634 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9637 +void au_update_dbtop(struct dentry *dentry)
9639 + aufs_bindex_t bindex, bbot;
9640 + struct dentry *h_dentry;
9642 + bbot = au_dbbot(dentry);
9643 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9644 + h_dentry = au_h_dptr(dentry, bindex);
9647 + if (d_is_positive(h_dentry)) {
9648 + au_set_dbtop(dentry, bindex);
9651 + au_set_h_dptr(dentry, bindex, NULL);
9655 +void au_update_dbbot(struct dentry *dentry)
9657 + aufs_bindex_t bindex, btop;
9658 + struct dentry *h_dentry;
9660 + btop = au_dbtop(dentry);
9661 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9662 + h_dentry = au_h_dptr(dentry, bindex);
9665 + if (d_is_positive(h_dentry)) {
9666 + au_set_dbbot(dentry, bindex);
9669 + au_set_h_dptr(dentry, bindex, NULL);
9673 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9675 + aufs_bindex_t bindex, bbot;
9677 + bbot = au_dbbot(dentry);
9678 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9679 + if (au_h_dptr(dentry, bindex) == h_dentry)
9683 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9684 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9685 +++ linux/fs/aufs/dir.c 2017-05-06 22:16:52.778220093 +0200
9688 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9690 + * This program, aufs is free software; you can redistribute it and/or modify
9691 + * it under the terms of the GNU General Public License as published by
9692 + * the Free Software Foundation; either version 2 of the License, or
9693 + * (at your option) any later version.
9695 + * This program is distributed in the hope that it will be useful,
9696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9698 + * GNU General Public License for more details.
9700 + * You should have received a copy of the GNU General Public License
9701 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9705 + * directory operations
9708 +#include <linux/fs_stack.h>
9711 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9713 + unsigned int nlink;
9715 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9717 + nlink = dir->i_nlink;
9718 + nlink += h_dir->i_nlink - 2;
9719 + if (h_dir->i_nlink < 2)
9721 + smp_mb(); /* for i_nlink */
9722 + /* 0 can happen in revaliding */
9723 + set_nlink(dir, nlink);
9726 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9728 + unsigned int nlink;
9730 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9732 + nlink = dir->i_nlink;
9733 + nlink -= h_dir->i_nlink - 2;
9734 + if (h_dir->i_nlink < 2)
9736 + smp_mb(); /* for i_nlink */
9737 + /* nlink == 0 means the branch-fs is broken */
9738 + set_nlink(dir, nlink);
9741 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9744 + aufs_bindex_t bindex, bbot;
9745 + struct file *h_file;
9746 + struct dentry *h_dentry;
9750 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9752 + bbot = au_fbbot_dir(file);
9753 + for (bindex = au_fbtop(file);
9754 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9756 + h_file = au_hf_dir(file, bindex);
9757 + if (h_file && file_inode(h_file))
9758 + sz += vfsub_f_size_read(h_file);
9761 + AuDebugOn(!dentry);
9762 + AuDebugOn(!d_is_dir(dentry));
9764 + bbot = au_dbtaildir(dentry);
9765 + for (bindex = au_dbtop(dentry);
9766 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9768 + h_dentry = au_h_dptr(dentry, bindex);
9769 + if (h_dentry && d_is_positive(h_dentry))
9770 + sz += i_size_read(d_inode(h_dentry));
9773 + if (sz < KMALLOC_MAX_SIZE)
9774 + sz = roundup_pow_of_two(sz);
9775 + if (sz > KMALLOC_MAX_SIZE)
9776 + sz = KMALLOC_MAX_SIZE;
9777 + else if (sz < NAME_MAX) {
9778 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9779 + sz = AUFS_RDBLK_DEF;
9784 +struct au_dir_ts_arg {
9785 + struct dentry *dentry;
9786 + aufs_bindex_t brid;
9789 +static void au_do_dir_ts(void *arg)
9791 + struct au_dir_ts_arg *a = arg;
9792 + struct au_dtime dt;
9793 + struct path h_path;
9794 + struct inode *dir, *h_dir;
9795 + struct super_block *sb;
9796 + struct au_branch *br;
9797 + struct au_hinode *hdir;
9799 + aufs_bindex_t btop, bindex;
9801 + sb = a->dentry->d_sb;
9802 + if (d_really_is_negative(a->dentry))
9804 + /* no dir->i_mutex lock */
9805 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9807 + dir = d_inode(a->dentry);
9808 + btop = au_ibtop(dir);
9809 + bindex = au_br_index(sb, a->brid);
9810 + if (bindex < btop)
9813 + br = au_sbr(sb, bindex);
9814 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9815 + if (!h_path.dentry)
9817 + h_path.mnt = au_br_mnt(br);
9818 + au_dtime_store(&dt, a->dentry, &h_path);
9820 + br = au_sbr(sb, btop);
9821 + if (!au_br_writable(br->br_perm))
9823 + h_path.dentry = au_h_dptr(a->dentry, btop);
9824 + h_path.mnt = au_br_mnt(br);
9825 + err = vfsub_mnt_want_write(h_path.mnt);
9828 + hdir = au_hi(dir, btop);
9829 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9830 + h_dir = au_h_iptr(dir, btop);
9831 + if (h_dir->i_nlink
9832 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9833 + dt.dt_h_path = h_path;
9834 + au_dtime_revert(&dt);
9836 + au_hn_inode_unlock(hdir);
9837 + vfsub_mnt_drop_write(h_path.mnt);
9838 + au_cpup_attr_timesizes(dir);
9841 + aufs_read_unlock(a->dentry, AuLock_DW);
9844 + au_nwt_done(&au_sbi(sb)->si_nowait);
9845 + au_delayed_kfree(arg);
9848 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9850 + int perm, wkq_err;
9851 + aufs_bindex_t btop;
9852 + struct au_dir_ts_arg *arg;
9853 + struct dentry *dentry;
9854 + struct super_block *sb;
9858 + dentry = d_find_any_alias(dir);
9859 + AuDebugOn(!dentry);
9860 + sb = dentry->d_sb;
9861 + btop = au_ibtop(dir);
9862 + if (btop == bindex) {
9863 + au_cpup_attr_timesizes(dir);
9867 + perm = au_sbr_perm(sb, btop);
9868 + if (!au_br_writable(perm))
9871 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9875 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9876 + arg->brid = au_sbr_id(sb, bindex);
9877 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9878 + if (unlikely(wkq_err)) {
9879 + pr_err("wkq %d\n", wkq_err);
9881 + au_delayed_kfree(arg);
9888 +/* ---------------------------------------------------------------------- */
9890 +static int reopen_dir(struct file *file)
9893 + unsigned int flags;
9894 + aufs_bindex_t bindex, btail, btop;
9895 + struct dentry *dentry, *h_dentry;
9896 + struct file *h_file;
9898 + /* open all lower dirs */
9899 + dentry = file->f_path.dentry;
9900 + btop = au_dbtop(dentry);
9901 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9902 + au_set_h_fptr(file, bindex, NULL);
9903 + au_set_fbtop(file, btop);
9905 + btail = au_dbtaildir(dentry);
9906 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9907 + au_set_h_fptr(file, bindex, NULL);
9908 + au_set_fbbot_dir(file, btail);
9910 + flags = vfsub_file_flags(file);
9911 + for (bindex = btop; bindex <= btail; bindex++) {
9912 + h_dentry = au_h_dptr(dentry, bindex);
9915 + h_file = au_hf_dir(file, bindex);
9919 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9920 + err = PTR_ERR(h_file);
9921 + if (IS_ERR(h_file))
9922 + goto out; /* close all? */
9923 + au_set_h_fptr(file, bindex, h_file);
9925 + au_update_figen(file);
9926 + /* todo: necessary? */
9927 + /* file->f_ra = h_file->f_ra; */
9934 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9937 + aufs_bindex_t bindex, btail;
9938 + struct dentry *dentry, *h_dentry;
9939 + struct vfsmount *mnt;
9941 + FiMustWriteLock(file);
9942 + AuDebugOn(h_file);
9945 + mnt = file->f_path.mnt;
9946 + dentry = file->f_path.dentry;
9947 + file->f_version = d_inode(dentry)->i_version;
9948 + bindex = au_dbtop(dentry);
9949 + au_set_fbtop(file, bindex);
9950 + btail = au_dbtaildir(dentry);
9951 + au_set_fbbot_dir(file, btail);
9952 + for (; !err && bindex <= btail; bindex++) {
9953 + h_dentry = au_h_dptr(dentry, bindex);
9957 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9958 + if (unlikely(err))
9960 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9961 + if (IS_ERR(h_file)) {
9962 + err = PTR_ERR(h_file);
9965 + au_set_h_fptr(file, bindex, h_file);
9967 + au_update_figen(file);
9968 + /* todo: necessary? */
9969 + /* file->f_ra = h_file->f_ra; */
9971 + return 0; /* success */
9974 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9975 + au_set_h_fptr(file, bindex, NULL);
9976 + au_set_fbtop(file, -1);
9977 + au_set_fbbot_dir(file, -1);
9982 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9983 + struct file *file)
9986 + struct super_block *sb;
9987 + struct au_fidir *fidir;
9990 + sb = file->f_path.dentry->d_sb;
9991 + si_read_lock(sb, AuLock_FLUSH);
9992 + fidir = au_fidir_alloc(sb);
9994 + struct au_do_open_args args = {
9995 + .open = do_open_dir,
9998 + err = au_do_open(file, &args);
9999 + if (unlikely(err))
10000 + au_delayed_kfree(fidir);
10002 + si_read_unlock(sb);
10006 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10007 + struct file *file)
10009 + struct au_vdir *vdir_cache;
10010 + struct au_finfo *finfo;
10011 + struct au_fidir *fidir;
10012 + struct au_hfile *hf;
10013 + aufs_bindex_t bindex, bbot;
10014 + int execed, delayed;
10016 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
10017 + finfo = au_fi(file);
10018 + fidir = finfo->fi_hdir;
10020 + au_sphl_del(&finfo->fi_hlist,
10021 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10022 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10024 + au_vdir_free(vdir_cache, delayed);
10026 + bindex = finfo->fi_btop;
10027 + if (bindex >= 0) {
10028 + execed = vfsub_file_execed(file);
10029 + hf = fidir->fd_hfile + bindex;
10031 + * calls fput() instead of filp_close(),
10032 + * since no dnotify or lock for the lower file.
10034 + bbot = fidir->fd_bbot;
10035 + for (; bindex <= bbot; bindex++, hf++)
10037 + au_hfput(hf, execed);
10039 + au_delayed_kfree(fidir);
10040 + finfo->fi_hdir = NULL;
10042 + au_finfo_fin(file, delayed);
10046 +/* ---------------------------------------------------------------------- */
10048 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10051 + aufs_bindex_t bindex, bbot;
10052 + struct file *h_file;
10055 + bbot = au_fbbot_dir(file);
10056 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10057 + h_file = au_hf_dir(file, bindex);
10059 + err = vfsub_flush(h_file, id);
10064 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10066 + return au_do_flush(file, id, au_do_flush_dir);
10069 +/* ---------------------------------------------------------------------- */
10071 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10074 + aufs_bindex_t bbot, bindex;
10075 + struct inode *inode;
10076 + struct super_block *sb;
10079 + sb = dentry->d_sb;
10080 + inode = d_inode(dentry);
10081 + IMustLock(inode);
10082 + bbot = au_dbbot(dentry);
10083 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10084 + struct path h_path;
10086 + if (au_test_ro(sb, bindex, inode))
10088 + h_path.dentry = au_h_dptr(dentry, bindex);
10089 + if (!h_path.dentry)
10092 + h_path.mnt = au_sbr_mnt(sb, bindex);
10093 + err = vfsub_fsync(NULL, &h_path, datasync);
10099 +static int au_do_fsync_dir(struct file *file, int datasync)
10102 + aufs_bindex_t bbot, bindex;
10103 + struct file *h_file;
10104 + struct super_block *sb;
10105 + struct inode *inode;
10107 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10108 + if (unlikely(err))
10111 + inode = file_inode(file);
10112 + sb = inode->i_sb;
10113 + bbot = au_fbbot_dir(file);
10114 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10115 + h_file = au_hf_dir(file, bindex);
10116 + if (!h_file || au_test_ro(sb, bindex, inode))
10119 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10127 + * @file may be NULL
10129 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10133 + struct dentry *dentry;
10134 + struct inode *inode;
10135 + struct super_block *sb;
10138 + dentry = file->f_path.dentry;
10139 + inode = d_inode(dentry);
10140 + inode_lock(inode);
10141 + sb = dentry->d_sb;
10142 + si_noflush_read_lock(sb);
10144 + err = au_do_fsync_dir(file, datasync);
10146 + di_write_lock_child(dentry);
10147 + err = au_do_fsync_dir_no_file(dentry, datasync);
10149 + au_cpup_attr_timesizes(inode);
10150 + di_write_unlock(dentry);
10152 + fi_write_unlock(file);
10154 + si_read_unlock(sb);
10155 + inode_unlock(inode);
10159 +/* ---------------------------------------------------------------------- */
10161 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10164 + struct dentry *dentry;
10165 + struct inode *inode, *h_inode;
10166 + struct super_block *sb;
10168 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10170 + dentry = file->f_path.dentry;
10171 + inode = d_inode(dentry);
10172 + IMustLock(inode);
10174 + sb = dentry->d_sb;
10175 + si_read_lock(sb, AuLock_FLUSH);
10176 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10177 + if (unlikely(err))
10179 + err = au_alive_dir(dentry);
10181 + err = au_vdir_init(file);
10182 + di_downgrade_lock(dentry, AuLock_IR);
10183 + if (unlikely(err))
10186 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10187 + if (!au_test_nfsd()) {
10188 + err = au_vdir_fill_de(file, ctx);
10189 + fsstack_copy_attr_atime(inode, h_inode);
10192 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10193 + * encode_fh() and others.
10195 + atomic_inc(&h_inode->i_count);
10196 + di_read_unlock(dentry, AuLock_IR);
10197 + si_read_unlock(sb);
10198 + err = au_vdir_fill_de(file, ctx);
10199 + fsstack_copy_attr_atime(inode, h_inode);
10200 + fi_write_unlock(file);
10208 + di_read_unlock(dentry, AuLock_IR);
10209 + fi_write_unlock(file);
10211 + si_read_unlock(sb);
10215 +/* ---------------------------------------------------------------------- */
10217 +#define AuTestEmpty_WHONLY 1
10218 +#define AuTestEmpty_CALLED (1 << 1)
10219 +#define AuTestEmpty_SHWH (1 << 2)
10220 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10221 +#define au_fset_testempty(flags, name) \
10222 + do { (flags) |= AuTestEmpty_##name; } while (0)
10223 +#define au_fclr_testempty(flags, name) \
10224 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10226 +#ifndef CONFIG_AUFS_SHWH
10227 +#undef AuTestEmpty_SHWH
10228 +#define AuTestEmpty_SHWH 0
10231 +struct test_empty_arg {
10232 + struct dir_context ctx;
10233 + struct au_nhash *whlist;
10234 + unsigned int flags;
10236 + aufs_bindex_t bindex;
10239 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10240 + int namelen, loff_t offset __maybe_unused, u64 ino,
10241 + unsigned int d_type)
10243 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10245 + char *name = (void *)__name;
10248 + au_fset_testempty(arg->flags, CALLED);
10250 + if (name[0] == '.'
10251 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10252 + goto out; /* success */
10254 + if (namelen <= AUFS_WH_PFX_LEN
10255 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10256 + if (au_ftest_testempty(arg->flags, WHONLY)
10257 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10258 + arg->err = -ENOTEMPTY;
10262 + name += AUFS_WH_PFX_LEN;
10263 + namelen -= AUFS_WH_PFX_LEN;
10264 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10265 + arg->err = au_nhash_append_wh
10266 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10267 + au_ftest_testempty(arg->flags, SHWH));
10271 + AuTraceErr(arg->err);
10275 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10278 + struct file *h_file;
10280 + h_file = au_h_open(dentry, arg->bindex,
10281 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10282 + /*file*/NULL, /*force_wr*/0);
10283 + err = PTR_ERR(h_file);
10284 + if (IS_ERR(h_file))
10288 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10289 + && !file_inode(h_file)->i_nlink)
10294 + au_fclr_testempty(arg->flags, CALLED);
10296 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10299 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10303 + au_sbr_put(dentry->d_sb, arg->bindex);
10308 +struct do_test_empty_args {
10310 + struct dentry *dentry;
10311 + struct test_empty_arg *arg;
10314 +static void call_do_test_empty(void *args)
10316 + struct do_test_empty_args *a = args;
10317 + *a->errp = do_test_empty(a->dentry, a->arg);
10320 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10322 + int err, wkq_err;
10323 + struct dentry *h_dentry;
10324 + struct inode *h_inode;
10326 + h_dentry = au_h_dptr(dentry, arg->bindex);
10327 + h_inode = d_inode(h_dentry);
10328 + /* todo: i_mode changes anytime? */
10329 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10330 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10331 + inode_unlock(h_inode);
10333 + err = do_test_empty(dentry, arg);
10335 + struct do_test_empty_args args = {
10337 + .dentry = dentry,
10340 + unsigned int flags = arg->flags;
10342 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10343 + if (unlikely(wkq_err))
10345 + arg->flags = flags;
10351 +int au_test_empty_lower(struct dentry *dentry)
10354 + unsigned int rdhash;
10355 + aufs_bindex_t bindex, btop, btail;
10356 + struct au_nhash whlist;
10357 + struct test_empty_arg arg = {
10359 + .actor = test_empty_cb
10362 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10364 + SiMustAnyLock(dentry->d_sb);
10366 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10368 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10369 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10370 + if (unlikely(err))
10374 + arg.whlist = &whlist;
10375 + btop = au_dbtop(dentry);
10376 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10377 + au_fset_testempty(arg.flags, SHWH);
10378 + test_empty = do_test_empty;
10379 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10380 + test_empty = sio_test_empty;
10381 + arg.bindex = btop;
10382 + err = test_empty(dentry, &arg);
10383 + if (unlikely(err))
10386 + au_fset_testempty(arg.flags, WHONLY);
10387 + btail = au_dbtaildir(dentry);
10388 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10389 + struct dentry *h_dentry;
10391 + h_dentry = au_h_dptr(dentry, bindex);
10392 + if (h_dentry && d_is_positive(h_dentry)) {
10393 + arg.bindex = bindex;
10394 + err = test_empty(dentry, &arg);
10399 + au_nhash_wh_free(&whlist);
10404 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10407 + struct test_empty_arg arg = {
10409 + .actor = test_empty_cb
10412 + aufs_bindex_t bindex, btail;
10415 + arg.whlist = whlist;
10416 + arg.flags = AuTestEmpty_WHONLY;
10417 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10418 + au_fset_testempty(arg.flags, SHWH);
10419 + btail = au_dbtaildir(dentry);
10420 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10421 + struct dentry *h_dentry;
10423 + h_dentry = au_h_dptr(dentry, bindex);
10424 + if (h_dentry && d_is_positive(h_dentry)) {
10425 + arg.bindex = bindex;
10426 + err = sio_test_empty(dentry, &arg);
10433 +/* ---------------------------------------------------------------------- */
10435 +const struct file_operations aufs_dir_fop = {
10436 + .owner = THIS_MODULE,
10437 + .llseek = default_llseek,
10438 + .read = generic_read_dir,
10439 + .iterate_shared = aufs_iterate_shared,
10440 + .unlocked_ioctl = aufs_ioctl_dir,
10441 +#ifdef CONFIG_COMPAT
10442 + .compat_ioctl = aufs_compat_ioctl_dir,
10444 + .open = aufs_open_dir,
10445 + .release = aufs_release_dir,
10446 + .flush = aufs_flush_dir,
10447 + .fsync = aufs_fsync_dir
10449 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10450 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10451 +++ linux/fs/aufs/dir.h 2017-05-06 22:16:52.778220093 +0200
10454 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10456 + * This program, aufs is free software; you can redistribute it and/or modify
10457 + * it under the terms of the GNU General Public License as published by
10458 + * the Free Software Foundation; either version 2 of the License, or
10459 + * (at your option) any later version.
10461 + * This program is distributed in the hope that it will be useful,
10462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10464 + * GNU General Public License for more details.
10466 + * You should have received a copy of the GNU General Public License
10467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10471 + * directory operations
10474 +#ifndef __AUFS_DIR_H__
10475 +#define __AUFS_DIR_H__
10479 +#include <linux/fs.h>
10481 +/* ---------------------------------------------------------------------- */
10483 +/* need to be faster and smaller */
10486 + unsigned int nh_num;
10487 + struct hlist_head *nh_head;
10490 +struct au_vdir_destr {
10491 + unsigned char len;
10492 + unsigned char name[0];
10495 +struct au_vdir_dehstr {
10496 + struct hlist_node hash;
10498 + struct au_vdir_destr *str;
10499 + struct llist_node lnode; /* delayed free */
10501 +} ____cacheline_aligned_in_smp;
10503 +struct au_vdir_de {
10505 + unsigned char de_type;
10506 + /* caution: packed */
10507 + struct au_vdir_destr de_str;
10510 +struct au_vdir_wh {
10511 + struct hlist_node wh_hash;
10512 +#ifdef CONFIG_AUFS_SHWH
10514 + aufs_bindex_t wh_bindex;
10515 + unsigned char wh_type;
10517 + aufs_bindex_t wh_bindex;
10519 + /* caution: packed */
10520 + struct au_vdir_destr wh_str;
10523 +union au_vdir_deblk_p {
10524 + unsigned char *deblk;
10525 + struct au_vdir_de *de;
10529 + unsigned char **vd_deblk;
10530 + unsigned long vd_nblk;
10532 + unsigned long ul;
10533 + union au_vdir_deblk_p p;
10536 + unsigned long vd_version;
10537 + unsigned int vd_deblk_sz;
10539 + unsigned long vd_jiffy;
10540 + struct llist_node vd_lnode; /* delayed free */
10542 +} ____cacheline_aligned_in_smp;
10544 +/* ---------------------------------------------------------------------- */
10547 +extern const struct file_operations aufs_dir_fop;
10548 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10549 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10550 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10551 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10552 +int au_test_empty_lower(struct dentry *dentry);
10553 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10556 +unsigned int au_rdhash_est(loff_t sz);
10557 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10558 +void au_nhash_wh_free(struct au_nhash *whlist);
10559 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10561 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10562 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10563 + unsigned int d_type, aufs_bindex_t bindex,
10564 + unsigned char shwh);
10565 +void au_vdir_free(struct au_vdir *vdir, int atonce);
10566 +int au_vdir_init(struct file *file);
10567 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10570 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10572 +#ifdef CONFIG_AUFS_RDU
10574 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10575 +#ifdef CONFIG_COMPAT
10576 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10577 + unsigned long arg);
10580 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10581 + unsigned int cmd, unsigned long arg)
10582 +#ifdef CONFIG_COMPAT
10583 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10584 + unsigned int cmd, unsigned long arg)
10588 +#endif /* __KERNEL__ */
10589 +#endif /* __AUFS_DIR_H__ */
10590 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10591 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10592 +++ linux/fs/aufs/dynop.c 2017-05-06 22:16:52.778220093 +0200
10595 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10597 + * This program, aufs is free software; you can redistribute it and/or modify
10598 + * it under the terms of the GNU General Public License as published by
10599 + * the Free Software Foundation; either version 2 of the License, or
10600 + * (at your option) any later version.
10602 + * This program is distributed in the hope that it will be useful,
10603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10605 + * GNU General Public License for more details.
10607 + * You should have received a copy of the GNU General Public License
10608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10612 + * dynamically customizable operations for regular files
10617 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10620 + * How large will these lists be?
10621 + * Usually just a few elements, 20-30 at most for each, I guess.
10623 +static struct au_sphlhead dynop[AuDyLast];
10625 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10627 + struct au_dykey *key, *tmp;
10628 + struct hlist_head *head;
10631 + head = &sphl->head;
10633 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10634 + if (tmp->dk_op.dy_hop == h_op) {
10636 + kref_get(&key->dk_kref);
10639 + rcu_read_unlock();
10644 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10646 + struct au_dykey **k, *found;
10647 + const void *h_op = key->dk_op.dy_hop;
10651 + k = br->br_dykey;
10652 + for (i = 0; i < AuBrDynOp; i++)
10654 + if (k[i]->dk_op.dy_hop == h_op) {
10661 + spin_lock(&br->br_dykey_lock);
10662 + for (; i < AuBrDynOp; i++)
10664 + if (k[i]->dk_op.dy_hop == h_op) {
10672 + spin_unlock(&br->br_dykey_lock);
10673 + BUG_ON(i == AuBrDynOp); /* expand the array */
10679 +/* kref_get() if @key is already added */
10680 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10682 + struct au_dykey *tmp, *found;
10683 + struct hlist_head *head;
10684 + const void *h_op = key->dk_op.dy_hop;
10687 + head = &sphl->head;
10688 + spin_lock(&sphl->spin);
10689 + hlist_for_each_entry(tmp, head, dk_hnode)
10690 + if (tmp->dk_op.dy_hop == h_op) {
10691 + kref_get(&tmp->dk_kref);
10696 + hlist_add_head_rcu(&key->dk_hnode, head);
10697 + spin_unlock(&sphl->spin);
10704 +static void dy_free_rcu(struct rcu_head *rcu)
10706 + struct au_dykey *key;
10708 + key = container_of(rcu, struct au_dykey, dk_rcu);
10710 + kfree(key); /* not delayed */
10713 +static void dy_free(struct kref *kref)
10715 + struct au_dykey *key;
10716 + struct au_sphlhead *sphl;
10718 + key = container_of(kref, struct au_dykey, dk_kref);
10719 + sphl = dynop + key->dk_op.dy_type;
10720 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10721 + call_rcu(&key->dk_rcu, dy_free_rcu);
10724 +void au_dy_put(struct au_dykey *key)
10726 + kref_put(&key->dk_kref, dy_free);
10729 +/* ---------------------------------------------------------------------- */
10731 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10733 +#ifdef CONFIG_AUFS_DEBUG
10734 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10735 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10737 +#define DyDbgDeclare(cnt) do {} while (0)
10738 +#define DyDbgInc(cnt) do {} while (0)
10741 +#define DySet(func, dst, src, h_op, h_sb) do { \
10743 + if (h_op->func) { \
10745 + dst.func = src.func; \
10747 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10751 +#define DySetForce(func, dst, src) do { \
10752 + AuDebugOn(!src.func); \
10754 + dst.func = src.func; \
10757 +#define DySetAop(func) \
10758 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10759 +#define DySetAopForce(func) \
10760 + DySetForce(func, dyaop->da_op, aufs_aop)
10762 +static void dy_aop(struct au_dykey *key, const void *h_op,
10763 + struct super_block *h_sb __maybe_unused)
10765 + struct au_dyaop *dyaop = (void *)key;
10766 + const struct address_space_operations *h_aop = h_op;
10767 + DyDbgDeclare(cnt);
10769 + AuDbg("%s\n", au_sbtype(h_sb));
10771 + DySetAop(writepage);
10772 + DySetAopForce(readpage); /* force */
10773 + DySetAop(writepages);
10774 + DySetAop(set_page_dirty);
10775 + DySetAop(readpages);
10776 + DySetAop(write_begin);
10777 + DySetAop(write_end);
10779 + DySetAop(invalidatepage);
10780 + DySetAop(releasepage);
10781 + DySetAop(freepage);
10782 + /* this one will be changed according to an aufs mount option */
10783 + DySetAop(direct_IO);
10784 + DySetAop(migratepage);
10785 + DySetAop(isolate_page);
10786 + DySetAop(putback_page);
10787 + DySetAop(launder_page);
10788 + DySetAop(is_partially_uptodate);
10789 + DySetAop(is_dirty_writeback);
10790 + DySetAop(error_remove_page);
10791 + DySetAop(swap_activate);
10792 + DySetAop(swap_deactivate);
10794 + DyDbgSize(cnt, *h_aop);
10797 +/* ---------------------------------------------------------------------- */
10799 +static void dy_bug(struct kref *kref)
10804 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10806 + struct au_dykey *key, *old;
10807 + struct au_sphlhead *sphl;
10810 + void (*set)(struct au_dykey *key, const void *h_op,
10811 + struct super_block *h_sb __maybe_unused);
10813 + static const struct op a[] = {
10815 + .sz = sizeof(struct au_dyaop),
10819 + const struct op *p;
10821 + sphl = dynop + op->dy_type;
10822 + key = dy_gfind_get(sphl, op->dy_hop);
10824 + goto out_add; /* success */
10826 + p = a + op->dy_type;
10827 + key = kzalloc(p->sz, GFP_NOFS);
10828 + if (unlikely(!key)) {
10829 + key = ERR_PTR(-ENOMEM);
10833 + key->dk_op.dy_hop = op->dy_hop;
10834 + kref_init(&key->dk_kref);
10835 + p->set(key, op->dy_hop, au_br_sb(br));
10836 + old = dy_gadd(sphl, key);
10838 + au_delayed_kfree(key);
10843 + old = dy_bradd(br, key);
10845 + /* its ref-count should never be zero here */
10846 + kref_put(&key->dk_kref, dy_bug);
10851 +/* ---------------------------------------------------------------------- */
10853 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10854 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10855 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10856 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10857 + * See the aufs manual in detail.
10859 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10862 + dyaop->da_op.direct_IO = NULL;
10864 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10867 +static struct au_dyaop *dy_aget(struct au_branch *br,
10868 + const struct address_space_operations *h_aop,
10871 + struct au_dyaop *dyaop;
10872 + struct au_dynop op;
10874 + op.dy_type = AuDy_AOP;
10875 + op.dy_haop = h_aop;
10876 + dyaop = (void *)dy_get(&op, br);
10877 + if (IS_ERR(dyaop))
10879 + dy_adx(dyaop, do_dx);
10885 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10886 + struct inode *h_inode)
10889 + struct super_block *sb;
10890 + struct au_branch *br;
10891 + struct au_dyaop *dyaop;
10893 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10894 + IiMustWriteLock(inode);
10896 + sb = inode->i_sb;
10897 + br = au_sbr(sb, bindex);
10898 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10899 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10900 + err = PTR_ERR(dyaop);
10901 + if (IS_ERR(dyaop))
10902 + /* unnecessary to call dy_fput() */
10906 + inode->i_mapping->a_ops = &dyaop->da_op;
10913 + * Is it safe to replace a_ops during the inode/file is in operation?
10914 + * Yes, I hope so.
10916 +int au_dy_irefresh(struct inode *inode)
10919 + aufs_bindex_t btop;
10920 + struct inode *h_inode;
10923 + if (S_ISREG(inode->i_mode)) {
10924 + btop = au_ibtop(inode);
10925 + h_inode = au_h_iptr(inode, btop);
10926 + err = au_dy_iaop(inode, btop, h_inode);
10931 +void au_dy_arefresh(int do_dx)
10933 + struct au_sphlhead *sphl;
10934 + struct hlist_head *head;
10935 + struct au_dykey *key;
10937 + sphl = dynop + AuDy_AOP;
10938 + head = &sphl->head;
10939 + spin_lock(&sphl->spin);
10940 + hlist_for_each_entry(key, head, dk_hnode)
10941 + dy_adx((void *)key, do_dx);
10942 + spin_unlock(&sphl->spin);
10945 +/* ---------------------------------------------------------------------- */
10947 +void __init au_dy_init(void)
10951 + /* make sure that 'struct au_dykey *' can be any type */
10952 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10954 + for (i = 0; i < AuDyLast; i++)
10955 + au_sphl_init(dynop + i);
10958 +void au_dy_fin(void)
10962 + for (i = 0; i < AuDyLast; i++)
10963 + WARN_ON(!hlist_empty(&dynop[i].head));
10965 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10966 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10967 +++ linux/fs/aufs/dynop.h 2017-05-06 22:16:52.778220093 +0200
10970 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10972 + * This program, aufs is free software; you can redistribute it and/or modify
10973 + * it under the terms of the GNU General Public License as published by
10974 + * the Free Software Foundation; either version 2 of the License, or
10975 + * (at your option) any later version.
10977 + * This program is distributed in the hope that it will be useful,
10978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10980 + * GNU General Public License for more details.
10982 + * You should have received a copy of the GNU General Public License
10983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10987 + * dynamically customizable operations (for regular files only)
10990 +#ifndef __AUFS_DYNOP_H__
10991 +#define __AUFS_DYNOP_H__
10995 +#include <linux/fs.h>
10996 +#include <linux/kref.h>
10998 +enum {AuDy_AOP, AuDyLast};
11003 + const void *dy_hop;
11004 + const struct address_space_operations *dy_haop;
11010 + struct hlist_node dk_hnode;
11011 + struct rcu_head dk_rcu;
11013 + struct au_dynop dk_op;
11016 + * during I am in the branch local array, kref is gotten. when the
11017 + * branch is removed, kref is put.
11019 + struct kref dk_kref;
11022 +/* stop unioning since their sizes are very different from each other */
11024 + struct au_dykey da_key;
11025 + struct address_space_operations da_op; /* not const */
11028 +/* ---------------------------------------------------------------------- */
11032 +void au_dy_put(struct au_dykey *key);
11033 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
11034 + struct inode *h_inode);
11035 +int au_dy_irefresh(struct inode *inode);
11036 +void au_dy_arefresh(int do_dio);
11038 +void __init au_dy_init(void);
11039 +void au_dy_fin(void);
11041 +#endif /* __KERNEL__ */
11042 +#endif /* __AUFS_DYNOP_H__ */
11043 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
11044 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
11045 +++ linux/fs/aufs/export.c 2017-05-06 22:16:52.778220093 +0200
11048 + * Copyright (C) 2005-2017 Junjiro R. Okajima
11050 + * This program, aufs is free software; you can redistribute it and/or modify
11051 + * it under the terms of the GNU General Public License as published by
11052 + * the Free Software Foundation; either version 2 of the License, or
11053 + * (at your option) any later version.
11055 + * This program is distributed in the hope that it will be useful,
11056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11058 + * GNU General Public License for more details.
11060 + * You should have received a copy of the GNU General Public License
11061 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11068 +#include <linux/exportfs.h>
11069 +#include <linux/fs_struct.h>
11070 +#include <linux/namei.h>
11071 +#include <linux/nsproxy.h>
11072 +#include <linux/random.h>
11073 +#include <linux/writeback.h>
11077 +#ifdef CONFIG_AUFS_INO_T_64
11085 +static ino_t decode_ino(__u32 *a)
11089 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11091 +#ifdef CONFIG_AUFS_INO_T_64
11097 +static void encode_ino(__u32 *a, ino_t ino)
11103 +#ifdef CONFIG_AUFS_INO_T_64
11108 +/* NFS file handle */
11112 +#ifdef CONFIG_AUFS_INO_T_64
11113 + /* support 64bit inode number */
11126 + Fh_ino = Fh_ino1,
11127 + Fh_dir_ino = Fh_dir_ino1
11130 +static int au_test_anon(struct dentry *dentry)
11132 + /* note: read d_flags without d_lock */
11133 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11136 +int au_test_nfsd(void)
11139 + struct task_struct *tsk = current;
11140 + char comm[sizeof(tsk->comm)];
11143 + if (tsk->flags & PF_KTHREAD) {
11144 + get_task_comm(comm, tsk);
11145 + ret = !strcmp(comm, "nfsd");
11151 +/* ---------------------------------------------------------------------- */
11152 +/* inode generation external table */
11154 +void au_xigen_inc(struct inode *inode)
11159 + struct super_block *sb;
11160 + struct au_sbinfo *sbinfo;
11162 + sb = inode->i_sb;
11163 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11165 + sbinfo = au_sbi(sb);
11166 + pos = inode->i_ino;
11167 + pos *= sizeof(igen);
11168 + igen = inode->i_generation + 1;
11169 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11170 + sizeof(igen), &pos);
11171 + if (sz == sizeof(igen))
11172 + return; /* success */
11174 + if (unlikely(sz >= 0))
11175 + AuIOErr("xigen error (%zd)\n", sz);
11178 +int au_xigen_new(struct inode *inode)
11183 + struct super_block *sb;
11184 + struct au_sbinfo *sbinfo;
11185 + struct file *file;
11188 + /* todo: dirty, at mount time */
11189 + if (inode->i_ino == AUFS_ROOT_INO)
11191 + sb = inode->i_sb;
11192 + SiMustAnyLock(sb);
11193 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11197 + pos = inode->i_ino;
11198 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11199 + AuIOErr1("too large i%lld\n", pos);
11202 + pos *= sizeof(inode->i_generation);
11205 + sbinfo = au_sbi(sb);
11206 + file = sbinfo->si_xigen;
11209 + if (vfsub_f_size_read(file)
11210 + < pos + sizeof(inode->i_generation)) {
11211 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11212 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11213 + sizeof(inode->i_generation), &pos);
11215 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11216 + sizeof(inode->i_generation), &pos);
11217 + if (sz == sizeof(inode->i_generation))
11218 + goto out; /* success */
11221 + if (unlikely(sz >= 0)) {
11223 + AuIOErr("xigen error (%zd)\n", sz);
11230 +int au_xigen_set(struct super_block *sb, struct file *base)
11233 + struct au_sbinfo *sbinfo;
11234 + struct file *file;
11236 + SiMustWriteLock(sb);
11238 + sbinfo = au_sbi(sb);
11239 + file = au_xino_create2(base, sbinfo->si_xigen);
11240 + err = PTR_ERR(file);
11241 + if (IS_ERR(file))
11244 + if (sbinfo->si_xigen)
11245 + fput(sbinfo->si_xigen);
11246 + sbinfo->si_xigen = file;
11252 +void au_xigen_clr(struct super_block *sb)
11254 + struct au_sbinfo *sbinfo;
11256 + SiMustWriteLock(sb);
11258 + sbinfo = au_sbi(sb);
11259 + if (sbinfo->si_xigen) {
11260 + fput(sbinfo->si_xigen);
11261 + sbinfo->si_xigen = NULL;
11265 +/* ---------------------------------------------------------------------- */
11267 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11270 + struct dentry *dentry, *d;
11271 + struct inode *inode;
11272 + unsigned int sigen;
11275 + inode = ilookup(sb, ino);
11279 + dentry = ERR_PTR(-ESTALE);
11280 + sigen = au_sigen(sb);
11281 + if (unlikely(au_is_bad_inode(inode)
11282 + || IS_DEADDIR(inode)
11283 + || sigen != au_iigen(inode, NULL)))
11287 + if (!dir_ino || S_ISDIR(inode->i_mode))
11288 + dentry = d_find_alias(inode);
11290 + spin_lock(&inode->i_lock);
11291 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11292 + spin_lock(&d->d_lock);
11293 + if (!au_test_anon(d)
11294 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11295 + dentry = dget_dlock(d);
11296 + spin_unlock(&d->d_lock);
11299 + spin_unlock(&d->d_lock);
11301 + spin_unlock(&inode->i_lock);
11303 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11304 + /* need to refresh */
11312 + AuTraceErrPtr(dentry);
11316 +/* ---------------------------------------------------------------------- */
11318 +/* todo: dirty? */
11319 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11321 +struct au_compare_mnt_args {
11323 + struct super_block *sb;
11326 + struct vfsmount *mnt;
11329 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11331 + struct au_compare_mnt_args *a = arg;
11333 + if (mnt->mnt_sb != a->sb)
11335 + a->mnt = mntget(mnt);
11339 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11342 + struct path root;
11343 + struct au_compare_mnt_args args = {
11347 + get_fs_root(current->fs, &root);
11349 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11350 + rcu_read_unlock();
11353 + AuDebugOn(!args.mnt);
11357 +struct au_nfsd_si_lock {
11358 + unsigned int sigen;
11359 + aufs_bindex_t bindex, br_id;
11360 + unsigned char force_lock;
11363 +static int si_nfsd_read_lock(struct super_block *sb,
11364 + struct au_nfsd_si_lock *nsi_lock)
11367 + aufs_bindex_t bindex;
11369 + si_read_lock(sb, AuLock_FLUSH);
11371 + /* branch id may be wrapped around */
11373 + bindex = au_br_index(sb, nsi_lock->br_id);
11374 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11375 + goto out; /* success */
11379 + if (!nsi_lock->force_lock)
11380 + si_read_unlock(sb);
11383 + nsi_lock->bindex = bindex;
11387 +struct find_name_by_ino {
11388 + struct dir_context ctx;
11389 + int called, found;
11396 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11397 + loff_t offset, u64 ino, unsigned int d_type)
11399 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11403 + if (a->ino != ino)
11406 + memcpy(a->name, name, namelen);
11407 + a->namelen = namelen;
11412 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11413 + struct au_nfsd_si_lock *nsi_lock)
11415 + struct dentry *dentry, *parent;
11416 + struct file *file;
11417 + struct inode *dir;
11418 + struct find_name_by_ino arg = {
11420 + .actor = find_name_by_ino
11425 + parent = path->dentry;
11427 + si_read_unlock(parent->d_sb);
11428 + file = vfsub_dentry_open(path, au_dir_roflags);
11429 + dentry = (void *)file;
11430 + if (IS_ERR(file))
11433 + dentry = ERR_PTR(-ENOMEM);
11434 + arg.name = (void *)__get_free_page(GFP_NOFS);
11435 + if (unlikely(!arg.name))
11442 + err = vfsub_iterate_dir(file, &arg.ctx);
11443 + } while (!err && !arg.found && arg.called);
11444 + dentry = ERR_PTR(err);
11445 + if (unlikely(err))
11447 + /* instead of ENOENT */
11448 + dentry = ERR_PTR(-ESTALE);
11452 + /* do not call vfsub_lkup_one() */
11453 + dir = d_inode(parent);
11454 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11455 + AuTraceErrPtr(dentry);
11456 + if (IS_ERR(dentry))
11458 + AuDebugOn(au_test_anon(dentry));
11459 + if (unlikely(d_really_is_negative(dentry))) {
11461 + dentry = ERR_PTR(-ENOENT);
11465 + au_delayed_free_page((unsigned long)arg.name);
11469 + if (unlikely(nsi_lock
11470 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11471 + if (!IS_ERR(dentry)) {
11473 + dentry = ERR_PTR(-ESTALE);
11475 + AuTraceErrPtr(dentry);
11479 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11481 + struct au_nfsd_si_lock *nsi_lock)
11483 + struct dentry *dentry;
11484 + struct path path;
11486 + if (dir_ino != AUFS_ROOT_INO) {
11487 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11488 + dentry = path.dentry;
11489 + if (!path.dentry || IS_ERR(path.dentry))
11491 + AuDebugOn(au_test_anon(path.dentry));
11493 + path.dentry = dget(sb->s_root);
11495 + path.mnt = au_mnt_get(sb);
11496 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11500 + AuTraceErrPtr(dentry);
11504 +/* ---------------------------------------------------------------------- */
11506 +static int h_acceptable(void *expv, struct dentry *dentry)
11511 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11512 + char *buf, int len, struct super_block *sb)
11516 + struct path path;
11518 + p = d_path(h_rootpath, buf, len);
11523 + path.mnt = h_rootpath->mnt;
11524 + path.dentry = h_parent;
11525 + p = d_path(&path, buf, len);
11531 + path.mnt = au_mnt_get(sb);
11532 + path.dentry = sb->s_root;
11533 + p = d_path(&path, buf, len - strlen(p));
11534 + mntput(path.mnt);
11538 + p[strlen(p)] = '/';
11541 + AuTraceErrPtr(p);
11546 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11547 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11549 + struct dentry *dentry, *h_parent, *root;
11550 + struct super_block *h_sb;
11551 + char *pathname, *p;
11552 + struct vfsmount *h_mnt;
11553 + struct au_branch *br;
11555 + struct path path;
11557 + br = au_sbr(sb, nsi_lock->bindex);
11558 + h_mnt = au_br_mnt(br);
11559 + h_sb = h_mnt->mnt_sb;
11560 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11562 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11563 + fh_len - Fh_tail, fh[Fh_h_type],
11564 + h_acceptable, /*context*/NULL);
11566 + dentry = h_parent;
11567 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11568 + AuWarn1("%s decode_fh failed, %ld\n",
11569 + au_sbtype(h_sb), PTR_ERR(h_parent));
11573 + if (unlikely(au_test_anon(h_parent))) {
11574 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11575 + au_sbtype(h_sb));
11576 + goto out_h_parent;
11579 + dentry = ERR_PTR(-ENOMEM);
11580 + pathname = (void *)__get_free_page(GFP_NOFS);
11581 + if (unlikely(!pathname))
11582 + goto out_h_parent;
11584 + root = sb->s_root;
11585 + path.mnt = h_mnt;
11586 + di_read_lock_parent(root, !AuLock_IR);
11587 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11588 + di_read_unlock(root, !AuLock_IR);
11589 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11590 + dentry = (void *)p;
11592 + goto out_pathname;
11594 + si_read_unlock(sb);
11595 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11596 + dentry = ERR_PTR(err);
11597 + if (unlikely(err))
11600 + dentry = ERR_PTR(-ENOENT);
11601 + AuDebugOn(au_test_anon(path.dentry));
11602 + if (unlikely(d_really_is_negative(path.dentry)))
11605 + if (ino != d_inode(path.dentry)->i_ino)
11606 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11608 + dentry = dget(path.dentry);
11613 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11614 + if (!IS_ERR(dentry)) {
11616 + dentry = ERR_PTR(-ESTALE);
11619 + au_delayed_free_page((unsigned long)pathname);
11623 + AuTraceErrPtr(dentry);
11627 +/* ---------------------------------------------------------------------- */
11629 +static struct dentry *
11630 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11633 + struct dentry *dentry;
11634 + __u32 *fh = fid->raw;
11635 + struct au_branch *br;
11636 + ino_t ino, dir_ino;
11637 + struct au_nfsd_si_lock nsi_lock = {
11641 + dentry = ERR_PTR(-ESTALE);
11642 + /* it should never happen, but the file handle is unreliable */
11643 + if (unlikely(fh_len < Fh_tail))
11645 + nsi_lock.sigen = fh[Fh_sigen];
11646 + nsi_lock.br_id = fh[Fh_br_id];
11648 + /* branch id may be wrapped around */
11650 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11652 + nsi_lock.force_lock = 1;
11654 + /* is this inode still cached? */
11655 + ino = decode_ino(fh + Fh_ino);
11656 + /* it should never happen */
11657 + if (unlikely(ino == AUFS_ROOT_INO))
11660 + dir_ino = decode_ino(fh + Fh_dir_ino);
11661 + dentry = decode_by_ino(sb, ino, dir_ino);
11662 + if (IS_ERR(dentry))
11667 + /* is the parent dir cached? */
11668 + br = au_sbr(sb, nsi_lock.bindex);
11670 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11671 + if (IS_ERR(dentry))
11676 + /* lookup path */
11677 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11678 + if (IS_ERR(dentry))
11680 + if (unlikely(!dentry))
11681 + /* todo?: make it ESTALE */
11685 + if (!au_digen_test(dentry, au_sigen(sb))
11686 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11687 + goto out_unlock; /* success */
11690 + dentry = ERR_PTR(-ESTALE);
11694 + si_read_unlock(sb);
11696 + AuTraceErrPtr(dentry);
11700 +#if 0 /* reserved for future use */
11701 +/* support subtreecheck option */
11702 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11703 + int fh_len, int fh_type)
11705 + struct dentry *parent;
11706 + __u32 *fh = fid->raw;
11709 + dir_ino = decode_ino(fh + Fh_dir_ino);
11710 + parent = decode_by_ino(sb, dir_ino, 0);
11711 + if (IS_ERR(parent))
11714 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11715 + dir_ino, fh, fh_len);
11718 + AuTraceErrPtr(parent);
11723 +/* ---------------------------------------------------------------------- */
11725 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11726 + struct inode *dir)
11729 + aufs_bindex_t bindex;
11730 + struct super_block *sb, *h_sb;
11731 + struct dentry *dentry, *parent, *h_parent;
11732 + struct inode *h_dir;
11733 + struct au_branch *br;
11736 + if (unlikely(*max_len <= Fh_tail)) {
11737 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11741 + err = FILEID_ROOT;
11742 + if (inode->i_ino == AUFS_ROOT_INO) {
11743 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11748 + sb = inode->i_sb;
11749 + err = si_read_lock(sb, AuLock_FLUSH);
11750 + if (unlikely(err))
11753 +#ifdef CONFIG_AUFS_DEBUG
11754 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11755 + AuWarn1("NFS-exporting requires xino\n");
11759 + ii_read_lock_child(inode);
11760 + bindex = au_ibtop(inode);
11762 + dentry = d_find_any_alias(inode);
11763 + if (unlikely(!dentry))
11765 + AuDebugOn(au_test_anon(dentry));
11766 + parent = dget_parent(dentry);
11768 + if (unlikely(!parent))
11770 + if (d_really_is_positive(parent))
11771 + dir = d_inode(parent);
11774 + ii_read_lock_parent(dir);
11775 + h_dir = au_h_iptr(dir, bindex);
11776 + ii_read_unlock(dir);
11777 + if (unlikely(!h_dir))
11779 + h_parent = d_find_any_alias(h_dir);
11780 + if (unlikely(!h_parent))
11781 + goto out_hparent;
11784 + br = au_sbr(sb, bindex);
11785 + h_sb = au_br_sb(br);
11786 + if (unlikely(!h_sb->s_export_op)) {
11787 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11788 + goto out_hparent;
11791 + fh[Fh_br_id] = br->br_id;
11792 + fh[Fh_sigen] = au_sigen(sb);
11793 + encode_ino(fh + Fh_ino, inode->i_ino);
11794 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11795 + fh[Fh_igen] = inode->i_generation;
11797 + *max_len -= Fh_tail;
11798 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11800 + /*connectable or subtreecheck*/0);
11801 + err = fh[Fh_h_type];
11802 + *max_len += Fh_tail;
11803 + /* todo: macros? */
11804 + if (err != FILEID_INVALID)
11807 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11814 + ii_read_unlock(inode);
11815 + si_read_unlock(sb);
11817 + if (unlikely(err < 0))
11818 + err = FILEID_INVALID;
11822 +/* ---------------------------------------------------------------------- */
11824 +static int aufs_commit_metadata(struct inode *inode)
11827 + aufs_bindex_t bindex;
11828 + struct super_block *sb;
11829 + struct inode *h_inode;
11830 + int (*f)(struct inode *inode);
11832 + sb = inode->i_sb;
11833 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11834 + ii_write_lock_child(inode);
11835 + bindex = au_ibtop(inode);
11836 + AuDebugOn(bindex < 0);
11837 + h_inode = au_h_iptr(inode, bindex);
11839 + f = h_inode->i_sb->s_export_op->commit_metadata;
11841 + err = f(h_inode);
11843 + struct writeback_control wbc = {
11844 + .sync_mode = WB_SYNC_ALL,
11845 + .nr_to_write = 0 /* metadata only */
11848 + err = sync_inode(h_inode, &wbc);
11851 + au_cpup_attr_timesizes(inode);
11852 + ii_write_unlock(inode);
11853 + si_read_unlock(sb);
11857 +/* ---------------------------------------------------------------------- */
11859 +static struct export_operations aufs_export_op = {
11860 + .fh_to_dentry = aufs_fh_to_dentry,
11861 + /* .fh_to_parent = aufs_fh_to_parent, */
11862 + .encode_fh = aufs_encode_fh,
11863 + .commit_metadata = aufs_commit_metadata
11866 +void au_export_init(struct super_block *sb)
11868 + struct au_sbinfo *sbinfo;
11871 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11872 + && IS_MODULE(CONFIG_EXPORTFS),
11873 + AUFS_NAME ": unsupported configuration "
11874 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11876 + sb->s_export_op = &aufs_export_op;
11877 + sbinfo = au_sbi(sb);
11878 + sbinfo->si_xigen = NULL;
11879 + get_random_bytes(&u, sizeof(u));
11880 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11881 + atomic_set(&sbinfo->si_xigen_next, u);
11883 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11884 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11885 +++ linux/fs/aufs/fhsm.c 2017-05-06 22:16:52.778220093 +0200
11888 + * Copyright (C) 2011-2017 Junjiro R. Okajima
11890 + * This program, aufs is free software; you can redistribute it and/or modify
11891 + * it under the terms of the GNU General Public License as published by
11892 + * the Free Software Foundation; either version 2 of the License, or
11893 + * (at your option) any later version.
11895 + * This program is distributed in the hope that it will be useful,
11896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11898 + * GNU General Public License for more details.
11900 + * You should have received a copy of the GNU General Public License
11901 + * along with this program; if not, write to the Free Software
11902 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11906 + * File-based Hierarchy Storage Management
11909 +#include <linux/anon_inodes.h>
11910 +#include <linux/poll.h>
11911 +#include <linux/seq_file.h>
11912 +#include <linux/statfs.h>
11915 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11917 + struct au_sbinfo *sbinfo;
11918 + struct au_fhsm *fhsm;
11920 + SiMustAnyLock(sb);
11922 + sbinfo = au_sbi(sb);
11923 + fhsm = &sbinfo->si_fhsm;
11924 + AuDebugOn(!fhsm);
11925 + return fhsm->fhsm_bottom;
11928 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11930 + struct au_sbinfo *sbinfo;
11931 + struct au_fhsm *fhsm;
11933 + SiMustWriteLock(sb);
11935 + sbinfo = au_sbi(sb);
11936 + fhsm = &sbinfo->si_fhsm;
11937 + AuDebugOn(!fhsm);
11938 + fhsm->fhsm_bottom = bindex;
11941 +/* ---------------------------------------------------------------------- */
11943 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11945 + struct au_br_fhsm *bf;
11947 + bf = br->br_fhsm;
11948 + MtxMustLock(&bf->bf_lock);
11950 + return !bf->bf_readable
11951 + || time_after(jiffies,
11952 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11955 +/* ---------------------------------------------------------------------- */
11957 +static void au_fhsm_notify(struct super_block *sb, int val)
11959 + struct au_sbinfo *sbinfo;
11960 + struct au_fhsm *fhsm;
11962 + SiMustAnyLock(sb);
11964 + sbinfo = au_sbi(sb);
11965 + fhsm = &sbinfo->si_fhsm;
11966 + if (au_fhsm_pid(fhsm)
11967 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11968 + atomic_set(&fhsm->fhsm_readable, val);
11970 + wake_up(&fhsm->fhsm_wqh);
11974 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11975 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11978 + struct au_branch *br;
11979 + struct au_br_fhsm *bf;
11981 + br = au_sbr(sb, bindex);
11982 + AuDebugOn(au_br_rdonly(br));
11983 + bf = br->br_fhsm;
11987 + mutex_lock(&bf->bf_lock);
11989 + MtxMustLock(&bf->bf_lock);
11991 + /* sb->s_root for NFS is unreliable */
11992 + err = au_br_stfs(br, &bf->bf_stfs);
11993 + if (unlikely(err)) {
11994 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11998 + bf->bf_jiffy = jiffies;
11999 + bf->bf_readable = 1;
12001 + au_fhsm_notify(sb, /*val*/1);
12003 + *rstfs = bf->bf_stfs;
12007 + mutex_unlock(&bf->bf_lock);
12008 + au_fhsm_notify(sb, /*val*/1);
12013 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
12016 + struct au_sbinfo *sbinfo;
12017 + struct au_fhsm *fhsm;
12018 + struct au_branch *br;
12019 + struct au_br_fhsm *bf;
12021 + AuDbg("b%d, force %d\n", bindex, force);
12022 + SiMustAnyLock(sb);
12024 + sbinfo = au_sbi(sb);
12025 + fhsm = &sbinfo->si_fhsm;
12026 + if (!au_ftest_si(sbinfo, FHSM)
12027 + || fhsm->fhsm_bottom == bindex)
12030 + br = au_sbr(sb, bindex);
12031 + bf = br->br_fhsm;
12033 + mutex_lock(&bf->bf_lock);
12035 + || au_fhsm_pid(fhsm)
12036 + || au_fhsm_test_jiffy(sbinfo, br))
12037 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
12039 + mutex_unlock(&bf->bf_lock);
12042 +void au_fhsm_wrote_all(struct super_block *sb, int force)
12044 + aufs_bindex_t bindex, bbot;
12045 + struct au_branch *br;
12047 + /* exclude the bottom */
12048 + bbot = au_fhsm_bottom(sb);
12049 + for (bindex = 0; bindex < bbot; bindex++) {
12050 + br = au_sbr(sb, bindex);
12051 + if (au_br_fhsm(br->br_perm))
12052 + au_fhsm_wrote(sb, bindex, force);
12056 +/* ---------------------------------------------------------------------- */
12058 +static unsigned int au_fhsm_poll(struct file *file,
12059 + struct poll_table_struct *wait)
12061 + unsigned int mask;
12062 + struct au_sbinfo *sbinfo;
12063 + struct au_fhsm *fhsm;
12066 + sbinfo = file->private_data;
12067 + fhsm = &sbinfo->si_fhsm;
12068 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12069 + if (atomic_read(&fhsm->fhsm_readable))
12070 + mask = POLLIN /* | POLLRDNORM */;
12072 + AuTraceErr((int)mask);
12076 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12077 + struct aufs_stfs *stfs, __s16 brid)
12081 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12083 + err = __put_user(brid, &stbr->brid);
12084 + if (unlikely(err))
12090 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12091 + struct aufs_stbr __user *stbr, size_t count)
12095 + aufs_bindex_t bindex, bbot;
12096 + struct au_branch *br;
12097 + struct au_br_fhsm *bf;
12099 + /* except the bottom branch */
12102 + bbot = au_fhsm_bottom(sb);
12103 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12104 + br = au_sbr(sb, bindex);
12105 + if (!au_br_fhsm(br->br_perm))
12108 + bf = br->br_fhsm;
12109 + mutex_lock(&bf->bf_lock);
12110 + if (bf->bf_readable) {
12112 + if (count >= sizeof(*stbr))
12113 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12116 + bf->bf_readable = 0;
12117 + count -= sizeof(*stbr);
12121 + mutex_unlock(&bf->bf_lock);
12124 + err = sizeof(*stbr) * nstbr;
12129 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12134 + aufs_bindex_t nfhsm, bindex, bbot;
12135 + struct au_sbinfo *sbinfo;
12136 + struct au_fhsm *fhsm;
12137 + struct au_branch *br;
12138 + struct super_block *sb;
12141 + sbinfo = file->private_data;
12142 + fhsm = &sbinfo->si_fhsm;
12144 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12145 + if (!atomic_read(&fhsm->fhsm_readable)) {
12146 + if (vfsub_file_flags(file) & O_NONBLOCK)
12149 + err = wait_event_interruptible_locked_irq
12151 + atomic_read(&fhsm->fhsm_readable));
12153 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12154 + if (unlikely(err))
12157 + /* sb may already be dead */
12158 + au_rw_read_lock(&sbinfo->si_rwsem);
12159 + readable = atomic_read(&fhsm->fhsm_readable);
12160 + if (readable > 0) {
12161 + sb = sbinfo->si_sb;
12163 + /* exclude the bottom branch */
12165 + bbot = au_fhsm_bottom(sb);
12166 + for (bindex = 0; bindex < bbot; bindex++) {
12167 + br = au_sbr(sb, bindex);
12168 + if (au_br_fhsm(br->br_perm))
12172 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12173 + atomic_set(&fhsm->fhsm_readable, 0);
12174 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12178 + au_rw_read_unlock(&sbinfo->si_rwsem);
12186 +static int au_fhsm_release(struct inode *inode, struct file *file)
12188 + struct au_sbinfo *sbinfo;
12189 + struct au_fhsm *fhsm;
12191 + /* sb may already be dead */
12192 + sbinfo = file->private_data;
12193 + fhsm = &sbinfo->si_fhsm;
12194 + spin_lock(&fhsm->fhsm_spin);
12195 + fhsm->fhsm_pid = 0;
12196 + spin_unlock(&fhsm->fhsm_spin);
12197 + kobject_put(&sbinfo->si_kobj);
12202 +static const struct file_operations au_fhsm_fops = {
12203 + .owner = THIS_MODULE,
12204 + .llseek = noop_llseek,
12205 + .read = au_fhsm_read,
12206 + .poll = au_fhsm_poll,
12207 + .release = au_fhsm_release
12210 +int au_fhsm_fd(struct super_block *sb, int oflags)
12213 + struct au_sbinfo *sbinfo;
12214 + struct au_fhsm *fhsm;
12217 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12221 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12225 + sbinfo = au_sbi(sb);
12226 + fhsm = &sbinfo->si_fhsm;
12227 + spin_lock(&fhsm->fhsm_spin);
12228 + if (!fhsm->fhsm_pid)
12229 + fhsm->fhsm_pid = current->pid;
12232 + spin_unlock(&fhsm->fhsm_spin);
12233 + if (unlikely(err))
12236 + oflags |= O_RDONLY;
12237 + /* oflags |= FMODE_NONOTIFY; */
12238 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12240 + if (unlikely(fd < 0))
12243 + /* succeed reglardless 'fhsm' status */
12244 + kobject_get(&sbinfo->si_kobj);
12245 + si_noflush_read_lock(sb);
12246 + if (au_ftest_si(sbinfo, FHSM))
12247 + au_fhsm_wrote_all(sb, /*force*/0);
12248 + si_read_unlock(sb);
12249 + goto out; /* success */
12252 + spin_lock(&fhsm->fhsm_spin);
12253 + fhsm->fhsm_pid = 0;
12254 + spin_unlock(&fhsm->fhsm_spin);
12260 +/* ---------------------------------------------------------------------- */
12262 +int au_fhsm_br_alloc(struct au_branch *br)
12267 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12269 + au_br_fhsm_init(br->br_fhsm);
12276 +/* ---------------------------------------------------------------------- */
12278 +void au_fhsm_fin(struct super_block *sb)
12280 + au_fhsm_notify(sb, /*val*/-1);
12283 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12285 + struct au_fhsm *fhsm;
12287 + fhsm = &sbinfo->si_fhsm;
12288 + spin_lock_init(&fhsm->fhsm_spin);
12289 + init_waitqueue_head(&fhsm->fhsm_wqh);
12290 + atomic_set(&fhsm->fhsm_readable, 0);
12291 + fhsm->fhsm_expire
12292 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12293 + fhsm->fhsm_bottom = -1;
12296 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12298 + sbinfo->si_fhsm.fhsm_expire
12299 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12302 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12306 + if (!au_ftest_si(sbinfo, FHSM))
12309 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12310 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12311 + seq_printf(seq, ",fhsm_sec=%u", u);
12313 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12314 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12315 +++ linux/fs/aufs/file.c 2017-05-06 22:16:52.778220093 +0200
12318 + * Copyright (C) 2005-2017 Junjiro R. Okajima
12320 + * This program, aufs is free software; you can redistribute it and/or modify
12321 + * it under the terms of the GNU General Public License as published by
12322 + * the Free Software Foundation; either version 2 of the License, or
12323 + * (at your option) any later version.
12325 + * This program is distributed in the hope that it will be useful,
12326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12328 + * GNU General Public License for more details.
12330 + * You should have received a copy of the GNU General Public License
12331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12335 + * handling file/dir, and address_space operation
12338 +#ifdef CONFIG_AUFS_DEBUG
12339 +#include <linux/migrate.h>
12341 +#include <linux/pagemap.h>
12344 +/* drop flags for writing */
12345 +unsigned int au_file_roflags(unsigned int flags)
12347 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12348 + flags |= O_RDONLY | O_NOATIME;
12352 +/* common functions to regular file and dir */
12353 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12354 + struct file *file, int force_wr)
12356 + struct file *h_file;
12357 + struct dentry *h_dentry;
12358 + struct inode *h_inode;
12359 + struct super_block *sb;
12360 + struct au_branch *br;
12361 + struct path h_path;
12364 + /* a race condition can happen between open and unlink/rmdir */
12365 + h_file = ERR_PTR(-ENOENT);
12366 + h_dentry = au_h_dptr(dentry, bindex);
12367 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12369 + h_inode = d_inode(h_dentry);
12370 + spin_lock(&h_dentry->d_lock);
12371 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12372 + /* || !d_inode(dentry)->i_nlink */
12374 + spin_unlock(&h_dentry->d_lock);
12375 + if (unlikely(err))
12378 + sb = dentry->d_sb;
12379 + br = au_sbr(sb, bindex);
12380 + err = au_br_test_oflag(flags, br);
12381 + h_file = ERR_PTR(err);
12382 + if (unlikely(err))
12385 + /* drop flags for writing */
12386 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12387 + if (force_wr && !(flags & O_WRONLY))
12389 + flags = au_file_roflags(flags);
12391 + h_file = ERR_PTR(-EROFS);
12392 + flags = au_file_roflags(flags);
12393 + if (unlikely(vfsub_native_ro(h_inode)
12394 + || IS_APPEND(h_inode)))
12396 + flags &= ~O_ACCMODE;
12397 + flags |= O_WRONLY;
12400 + flags &= ~O_CREAT;
12402 + h_path.dentry = h_dentry;
12403 + h_path.mnt = au_br_mnt(br);
12404 + h_file = vfsub_dentry_open(&h_path, flags);
12405 + if (IS_ERR(h_file))
12408 + if (flags & __FMODE_EXEC) {
12409 + err = deny_write_access(h_file);
12410 + if (unlikely(err)) {
12412 + h_file = ERR_PTR(err);
12416 + fsnotify_open(h_file);
12417 + goto out; /* success */
12425 +static int au_cmoo(struct dentry *dentry)
12428 + unsigned int udba;
12429 + struct path h_path;
12430 + struct au_pin pin;
12431 + struct au_cp_generic cpg = {
12432 + .dentry = dentry,
12437 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12439 + struct inode *delegated;
12440 + struct super_block *sb;
12441 + struct au_sbinfo *sbinfo;
12442 + struct au_fhsm *fhsm;
12444 + struct au_branch *br;
12445 + struct dentry *parent;
12446 + struct au_hinode *hdir;
12448 + DiMustWriteLock(dentry);
12449 + IiMustWriteLock(d_inode(dentry));
12452 + if (IS_ROOT(dentry))
12454 + cpg.bsrc = au_dbtop(dentry);
12458 + sb = dentry->d_sb;
12459 + sbinfo = au_sbi(sb);
12460 + fhsm = &sbinfo->si_fhsm;
12461 + pid = au_fhsm_pid(fhsm);
12463 + && (current->pid == pid
12464 + || current->real_parent->pid == pid))
12467 + br = au_sbr(sb, cpg.bsrc);
12468 + cmoo = au_br_cmoo(br->br_perm);
12471 + if (!d_is_reg(dentry))
12472 + cmoo &= AuBrAttr_COO_ALL;
12476 + parent = dget_parent(dentry);
12477 + di_write_lock_parent(parent);
12478 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12480 + if (unlikely(err < 0)) {
12481 + err = 0; /* there is no upper writable branch */
12484 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12486 + /* do not respect the coo attrib for the target branch */
12487 + err = au_cpup_dirs(dentry, cpg.bdst);
12488 + if (unlikely(err))
12491 + di_downgrade_lock(parent, AuLock_IR);
12492 + udba = au_opt_udba(sb);
12493 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12494 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12495 + if (unlikely(err))
12498 + err = au_sio_cpup_simple(&cpg);
12500 + if (unlikely(err))
12502 + if (!(cmoo & AuBrWAttr_MOO))
12503 + goto out_parent; /* success */
12505 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12506 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12507 + if (unlikely(err))
12510 + h_path.mnt = au_br_mnt(br);
12511 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12512 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12513 + delegated = NULL;
12514 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12516 + /* todo: keep h_dentry or not? */
12517 + if (unlikely(err == -EWOULDBLOCK)) {
12518 + pr_warn("cannot retry for NFSv4 delegation"
12519 + " for an internal unlink\n");
12522 + if (unlikely(err)) {
12523 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12527 + goto out_parent; /* success */
12530 + di_downgrade_lock(parent, AuLock_IR);
12532 + di_read_unlock(parent, AuLock_IR);
12539 +int au_do_open(struct file *file, struct au_do_open_args *args)
12541 + int err, no_lock = args->no_lock;
12542 + struct dentry *dentry;
12543 + struct au_finfo *finfo;
12546 + err = au_finfo_init(file, args->fidir);
12549 + err = au_finfo_init(file, args->fidir);
12552 + if (unlikely(err))
12555 + dentry = file->f_path.dentry;
12556 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12558 + di_write_lock_child(dentry);
12559 + err = au_cmoo(dentry);
12560 + di_downgrade_lock(dentry, AuLock_IR);
12562 + err = args->open(file, vfsub_file_flags(file), NULL);
12563 + di_read_unlock(dentry, AuLock_IR);
12565 + err = au_cmoo(dentry);
12567 + err = args->open(file, vfsub_file_flags(file),
12569 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12571 + * cmoo happens after h_file was opened.
12572 + * need to refresh file later.
12574 + atomic_dec(&au_fi(file)->fi_generation);
12577 + finfo = au_fi(file);
12579 + finfo->fi_file = file;
12580 + au_sphl_add(&finfo->fi_hlist,
12581 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12584 + fi_write_unlock(file);
12587 + fi_write_unlock(file);
12590 + if (unlikely(err)) {
12591 + finfo->fi_hdir = NULL;
12592 + au_finfo_fin(file, /*atonce*/0);
12599 +int au_reopen_nondir(struct file *file)
12602 + aufs_bindex_t btop;
12603 + struct dentry *dentry;
12604 + struct file *h_file, *h_file_tmp;
12606 + dentry = file->f_path.dentry;
12607 + btop = au_dbtop(dentry);
12608 + h_file_tmp = NULL;
12609 + if (au_fbtop(file) == btop) {
12610 + h_file = au_hf_top(file);
12611 + if (file->f_mode == h_file->f_mode)
12612 + return 0; /* success */
12613 + h_file_tmp = h_file;
12614 + get_file(h_file_tmp);
12615 + au_set_h_fptr(file, btop, NULL);
12617 + AuDebugOn(au_fi(file)->fi_hdir);
12620 + * file exists on both of rw and ro
12621 + * open --> dbtop and fbtop are both 0
12622 + * prepend a branch as rw, "rw" become ro
12624 + * delete the top branch, "rw" becomes rw again
12625 + * --> dbtop is 1, fbtop is still 0
12626 + * write --> fbtop is 0 but dbtop is 1
12628 + /* AuDebugOn(au_fbtop(file) < btop); */
12630 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12631 + file, /*force_wr*/0);
12632 + err = PTR_ERR(h_file);
12633 + if (IS_ERR(h_file)) {
12634 + if (h_file_tmp) {
12635 + au_sbr_get(dentry->d_sb, btop);
12636 + au_set_h_fptr(file, btop, h_file_tmp);
12637 + h_file_tmp = NULL;
12639 + goto out; /* todo: close all? */
12643 + au_set_fbtop(file, btop);
12644 + au_set_h_fptr(file, btop, h_file);
12645 + au_update_figen(file);
12646 + /* todo: necessary? */
12647 + /* file->f_ra = h_file->f_ra; */
12651 + fput(h_file_tmp);
12655 +/* ---------------------------------------------------------------------- */
12657 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12658 + struct dentry *hi_wh)
12661 + aufs_bindex_t btop;
12662 + struct au_dinfo *dinfo;
12663 + struct dentry *h_dentry;
12664 + struct au_hdentry *hdp;
12666 + dinfo = au_di(file->f_path.dentry);
12667 + AuRwMustWriteLock(&dinfo->di_rwsem);
12669 + btop = dinfo->di_btop;
12670 + dinfo->di_btop = btgt;
12671 + hdp = au_hdentry(dinfo, btgt);
12672 + h_dentry = hdp->hd_dentry;
12673 + hdp->hd_dentry = hi_wh;
12674 + err = au_reopen_nondir(file);
12675 + hdp->hd_dentry = h_dentry;
12676 + dinfo->di_btop = btop;
12681 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12682 + aufs_bindex_t bcpup, struct au_pin *pin)
12685 + struct inode *inode, *h_inode;
12686 + struct dentry *h_dentry, *hi_wh;
12687 + struct au_cp_generic cpg = {
12688 + .dentry = file->f_path.dentry,
12695 + au_update_dbtop(cpg.dentry);
12696 + inode = d_inode(cpg.dentry);
12698 + if (au_dbtop(cpg.dentry) <= bcpup
12699 + && au_dbbot(cpg.dentry) >= bcpup) {
12700 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12701 + if (h_dentry && d_is_positive(h_dentry))
12702 + h_inode = d_inode(h_dentry);
12704 + hi_wh = au_hi_wh(inode, bcpup);
12705 + if (!hi_wh && !h_inode)
12706 + err = au_sio_cpup_wh(&cpg, file);
12708 + /* already copied-up after unlink */
12709 + err = au_reopen_wh(file, bcpup, hi_wh);
12712 + && (inode->i_nlink > 1
12713 + || (inode->i_state & I_LINKABLE))
12714 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12715 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12721 + * prepare the @file for writing.
12723 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12726 + aufs_bindex_t dbtop;
12727 + struct dentry *parent;
12728 + struct inode *inode;
12729 + struct super_block *sb;
12730 + struct file *h_file;
12731 + struct au_cp_generic cpg = {
12732 + .dentry = file->f_path.dentry,
12737 + .flags = AuCpup_DTIME
12740 + sb = cpg.dentry->d_sb;
12741 + inode = d_inode(cpg.dentry);
12742 + cpg.bsrc = au_fbtop(file);
12743 + err = au_test_ro(sb, cpg.bsrc, inode);
12744 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12745 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12750 + /* need to cpup or reopen */
12751 + parent = dget_parent(cpg.dentry);
12752 + di_write_lock_parent(parent);
12753 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12755 + if (unlikely(err < 0))
12759 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12760 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12761 + if (unlikely(err))
12765 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12766 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12767 + if (unlikely(err))
12770 + dbtop = au_dbtop(cpg.dentry);
12771 + if (dbtop <= cpg.bdst)
12772 + cpg.bsrc = cpg.bdst;
12774 + if (dbtop <= cpg.bdst /* just reopen */
12775 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12777 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12778 + if (IS_ERR(h_file))
12779 + err = PTR_ERR(h_file);
12781 + di_downgrade_lock(parent, AuLock_IR);
12782 + if (dbtop > cpg.bdst)
12783 + err = au_sio_cpup_simple(&cpg);
12785 + err = au_reopen_nondir(file);
12786 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12788 + } else { /* copyup as wh and reopen */
12790 + * since writable hfsplus branch is not supported,
12791 + * h_open_pre/post() are unnecessary.
12793 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12794 + di_downgrade_lock(parent, AuLock_IR);
12798 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12799 + goto out_dput; /* success */
12805 + di_downgrade_lock(parent, AuLock_IR);
12807 + di_read_unlock(parent, AuLock_IR);
12814 +/* ---------------------------------------------------------------------- */
12816 +int au_do_flush(struct file *file, fl_owner_t id,
12817 + int (*flush)(struct file *file, fl_owner_t id))
12820 + struct super_block *sb;
12821 + struct inode *inode;
12823 + inode = file_inode(file);
12824 + sb = inode->i_sb;
12825 + si_noflush_read_lock(sb);
12826 + fi_read_lock(file);
12827 + ii_read_lock_child(inode);
12829 + err = flush(file, id);
12830 + au_cpup_attr_timesizes(inode);
12832 + ii_read_unlock(inode);
12833 + fi_read_unlock(file);
12834 + si_read_unlock(sb);
12838 +/* ---------------------------------------------------------------------- */
12840 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12843 + struct au_pin pin;
12844 + struct au_finfo *finfo;
12845 + struct dentry *parent, *hi_wh;
12846 + struct inode *inode;
12847 + struct super_block *sb;
12848 + struct au_cp_generic cpg = {
12849 + .dentry = file->f_path.dentry,
12854 + .flags = AuCpup_DTIME
12857 + FiMustWriteLock(file);
12860 + finfo = au_fi(file);
12861 + sb = cpg.dentry->d_sb;
12862 + inode = d_inode(cpg.dentry);
12863 + cpg.bdst = au_ibtop(inode);
12864 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12867 + parent = dget_parent(cpg.dentry);
12868 + if (au_test_ro(sb, cpg.bdst, inode)) {
12869 + di_read_lock_parent(parent, !AuLock_IR);
12870 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12872 + di_read_unlock(parent, !AuLock_IR);
12873 + if (unlikely(err < 0))
12878 + di_read_lock_parent(parent, AuLock_IR);
12879 + hi_wh = au_hi_wh(inode, cpg.bdst);
12880 + if (!S_ISDIR(inode->i_mode)
12881 + && au_opt_test(au_mntflags(sb), PLINK)
12882 + && au_plink_test(inode)
12883 + && !d_unhashed(cpg.dentry)
12884 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12885 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12886 + if (unlikely(err))
12889 + /* always superio. */
12890 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12891 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12893 + err = au_sio_cpup_simple(&cpg);
12896 + } else if (hi_wh) {
12897 + /* already copied-up after unlink */
12898 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12899 + *need_reopen = 0;
12903 + di_read_unlock(parent, AuLock_IR);
12910 +static void au_do_refresh_dir(struct file *file)
12913 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12914 + struct au_hfile *p, tmp, *q;
12915 + struct au_finfo *finfo;
12916 + struct super_block *sb;
12917 + struct au_fidir *fidir;
12919 + FiMustWriteLock(file);
12921 + sb = file->f_path.dentry->d_sb;
12922 + finfo = au_fi(file);
12923 + fidir = finfo->fi_hdir;
12924 + AuDebugOn(!fidir);
12925 + p = fidir->fd_hfile + finfo->fi_btop;
12926 + brid = p->hf_br->br_id;
12927 + bbot = fidir->fd_bbot;
12928 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12932 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12933 + if (new_bindex == bindex)
12935 + if (new_bindex < 0) {
12936 + au_set_h_fptr(file, bindex, NULL);
12940 + /* swap two lower inode, and loop again */
12941 + q = fidir->fd_hfile + new_bindex;
12945 + if (tmp.hf_file) {
12951 + execed = vfsub_file_execed(file);
12952 + p = fidir->fd_hfile;
12953 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12954 + bbot = au_sbbot(sb);
12955 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12956 + finfo->fi_btop++, p++)
12957 + if (p->hf_file) {
12958 + if (file_inode(p->hf_file))
12960 + au_hfput(p, execed);
12963 + bbot = au_br_index(sb, brid);
12964 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12965 + finfo->fi_btop++, p++)
12967 + au_hfput(p, execed);
12968 + bbot = au_sbbot(sb);
12971 + p = fidir->fd_hfile + bbot;
12972 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12973 + fidir->fd_bbot--, p--)
12974 + if (p->hf_file) {
12975 + if (file_inode(p->hf_file))
12977 + au_hfput(p, execed);
12979 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12983 + * after branch manipulating, refresh the file.
12985 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12987 + int err, need_reopen, nbr;
12988 + aufs_bindex_t bbot, bindex;
12989 + struct dentry *dentry;
12990 + struct super_block *sb;
12991 + struct au_finfo *finfo;
12992 + struct au_hfile *hfile;
12994 + dentry = file->f_path.dentry;
12995 + sb = dentry->d_sb;
12996 + nbr = au_sbbot(sb) + 1;
12997 + finfo = au_fi(file);
12998 + if (!finfo->fi_hdir) {
12999 + hfile = &finfo->fi_htop;
13000 + AuDebugOn(!hfile->hf_file);
13001 + bindex = au_br_index(sb, hfile->hf_br->br_id);
13002 + AuDebugOn(bindex < 0);
13003 + if (bindex != finfo->fi_btop)
13004 + au_set_fbtop(file, bindex);
13006 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
13007 + if (unlikely(err))
13009 + au_do_refresh_dir(file);
13014 + if (!au_test_mmapped(file))
13015 + err = au_file_refresh_by_inode(file, &need_reopen);
13016 + if (finfo->fi_hdir)
13017 + /* harmless if err */
13018 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
13019 + if (!err && need_reopen && !d_unlinked(dentry))
13020 + err = reopen(file);
13022 + au_update_figen(file);
13023 + goto out; /* success */
13026 + /* error, close all lower files */
13027 + if (finfo->fi_hdir) {
13028 + bbot = au_fbbot_dir(file);
13029 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
13030 + au_set_h_fptr(file, bindex, NULL);
13037 +/* common function to regular file and dir */
13038 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13039 + int wlock, unsigned int fi_lsc)
13042 + unsigned int sigen, figen;
13043 + aufs_bindex_t btop;
13044 + unsigned char pseudo_link;
13045 + struct dentry *dentry;
13046 + struct inode *inode;
13049 + dentry = file->f_path.dentry;
13050 + inode = d_inode(dentry);
13051 + sigen = au_sigen(dentry->d_sb);
13052 + fi_write_lock_nested(file, fi_lsc);
13053 + figen = au_figen(file);
13055 + di_write_lock_child(dentry);
13057 + di_write_lock_child2(dentry);
13058 + btop = au_dbtop(dentry);
13059 + pseudo_link = (btop != au_ibtop(inode));
13060 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
13062 + di_downgrade_lock(dentry, AuLock_IR);
13063 + fi_downgrade_lock(file);
13065 + goto out; /* success */
13068 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13069 + if (au_digen_test(dentry, sigen)) {
13070 + err = au_reval_dpath(dentry, sigen);
13071 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13075 + err = refresh_file(file, reopen);
13078 + di_downgrade_lock(dentry, AuLock_IR);
13079 + fi_downgrade_lock(file);
13082 + di_write_unlock(dentry);
13083 + fi_write_unlock(file);
13090 +/* ---------------------------------------------------------------------- */
13092 +/* cf. aufs_nopage() */
13093 +/* for madvise(2) */
13094 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13096 + unlock_page(page);
13100 +/* it will never be called, but necessary to support O_DIRECT */
13101 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13102 +{ BUG(); return 0; }
13104 +/* they will never be called. */
13105 +#ifdef CONFIG_AUFS_DEBUG
13106 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13107 + loff_t pos, unsigned len, unsigned flags,
13108 + struct page **pagep, void **fsdata)
13109 +{ AuUnsupport(); return 0; }
13110 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13111 + loff_t pos, unsigned len, unsigned copied,
13112 + struct page *page, void *fsdata)
13113 +{ AuUnsupport(); return 0; }
13114 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13115 +{ AuUnsupport(); return 0; }
13117 +static int aufs_set_page_dirty(struct page *page)
13118 +{ AuUnsupport(); return 0; }
13119 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13120 + unsigned int length)
13121 +{ AuUnsupport(); }
13122 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13123 +{ AuUnsupport(); return 0; }
13124 +#if 0 /* called by memory compaction regardless file */
13125 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13126 + struct page *page, enum migrate_mode mode)
13127 +{ AuUnsupport(); return 0; }
13129 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13130 +{ AuUnsupport(); return true; }
13131 +static void aufs_putback_page(struct page *page)
13132 +{ AuUnsupport(); }
13133 +static int aufs_launder_page(struct page *page)
13134 +{ AuUnsupport(); return 0; }
13135 +static int aufs_is_partially_uptodate(struct page *page,
13136 + unsigned long from,
13137 + unsigned long count)
13138 +{ AuUnsupport(); return 0; }
13139 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13141 +{ AuUnsupport(); }
13142 +static int aufs_error_remove_page(struct address_space *mapping,
13143 + struct page *page)
13144 +{ AuUnsupport(); return 0; }
13145 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13147 +{ AuUnsupport(); return 0; }
13148 +static void aufs_swap_deactivate(struct file *file)
13149 +{ AuUnsupport(); }
13150 +#endif /* CONFIG_AUFS_DEBUG */
13152 +const struct address_space_operations aufs_aop = {
13153 + .readpage = aufs_readpage,
13154 + .direct_IO = aufs_direct_IO,
13155 +#ifdef CONFIG_AUFS_DEBUG
13156 + .writepage = aufs_writepage,
13157 + /* no writepages, because of writepage */
13158 + .set_page_dirty = aufs_set_page_dirty,
13159 + /* no readpages, because of readpage */
13160 + .write_begin = aufs_write_begin,
13161 + .write_end = aufs_write_end,
13162 + /* no bmap, no block device */
13163 + .invalidatepage = aufs_invalidatepage,
13164 + .releasepage = aufs_releasepage,
13165 + /* is fallback_migrate_page ok? */
13166 + /* .migratepage = aufs_migratepage, */
13167 + .isolate_page = aufs_isolate_page,
13168 + .putback_page = aufs_putback_page,
13169 + .launder_page = aufs_launder_page,
13170 + .is_partially_uptodate = aufs_is_partially_uptodate,
13171 + .is_dirty_writeback = aufs_is_dirty_writeback,
13172 + .error_remove_page = aufs_error_remove_page,
13173 + .swap_activate = aufs_swap_activate,
13174 + .swap_deactivate = aufs_swap_deactivate
13175 +#endif /* CONFIG_AUFS_DEBUG */
13177 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13178 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13179 +++ linux/fs/aufs/file.h 2017-05-06 22:16:52.778220093 +0200
13182 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13184 + * This program, aufs is free software; you can redistribute it and/or modify
13185 + * it under the terms of the GNU General Public License as published by
13186 + * the Free Software Foundation; either version 2 of the License, or
13187 + * (at your option) any later version.
13189 + * This program is distributed in the hope that it will be useful,
13190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13192 + * GNU General Public License for more details.
13194 + * You should have received a copy of the GNU General Public License
13195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13199 + * file operations
13202 +#ifndef __AUFS_FILE_H__
13203 +#define __AUFS_FILE_H__
13207 +#include <linux/file.h>
13208 +#include <linux/fs.h>
13209 +#include <linux/poll.h>
13210 +#include "rwsem.h"
13214 + struct file *hf_file;
13215 + struct au_branch *hf_br;
13220 + aufs_bindex_t fd_bbot;
13221 + aufs_bindex_t fd_nent;
13222 + struct au_vdir *fd_vdir_cache;
13223 + struct au_hfile fd_hfile[];
13226 +static inline int au_fidir_sz(int nent)
13228 + AuDebugOn(nent < 0);
13229 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13233 + atomic_t fi_generation;
13235 + struct au_rwsem fi_rwsem;
13236 + aufs_bindex_t fi_btop;
13238 + /* do not union them */
13239 + struct { /* for non-dir */
13240 + struct au_hfile fi_htop;
13241 + atomic_t fi_mmapped;
13243 + struct au_fidir *fi_hdir; /* for dir only */
13245 + struct hlist_node fi_hlist;
13247 + struct file *fi_file; /* very ugly */
13248 + struct llist_node fi_lnode; /* delayed free */
13250 +} ____cacheline_aligned_in_smp;
13252 +/* ---------------------------------------------------------------------- */
13255 +extern const struct address_space_operations aufs_aop;
13256 +unsigned int au_file_roflags(unsigned int flags);
13257 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13258 + struct file *file, int force_wr);
13259 +struct au_do_open_args {
13261 + int (*open)(struct file *file, int flags,
13262 + struct file *h_file);
13263 + struct au_fidir *fidir;
13264 + struct file *h_file;
13266 +int au_do_open(struct file *file, struct au_do_open_args *args);
13267 +int au_reopen_nondir(struct file *file);
13269 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13270 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13271 + int wlock, unsigned int fi_lsc);
13272 +int au_do_flush(struct file *file, fl_owner_t id,
13273 + int (*flush)(struct file *file, fl_owner_t id));
13276 +#ifdef CONFIG_AUFS_POLL
13277 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13280 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13282 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13284 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13285 + struct file *h_file);
13287 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13288 + aufs_bindex_t bindex, int force_wr)
13289 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13290 + struct file *h_file);
13294 +extern const struct file_operations aufs_file_fop;
13295 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13296 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13297 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
13300 +void au_hfput(struct au_hfile *hf, int execed);
13301 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13302 + struct file *h_file);
13304 +void au_update_figen(struct file *file);
13305 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13306 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13308 +void au_fi_init_once(void *_fi);
13309 +void au_finfo_fin(struct file *file, int atonce);
13310 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13313 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13314 +#ifdef CONFIG_COMPAT
13315 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13316 + unsigned long arg);
13317 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13318 + unsigned long arg);
13321 +/* ---------------------------------------------------------------------- */
13323 +static inline struct au_finfo *au_fi(struct file *file)
13325 + return file->private_data;
13328 +/* ---------------------------------------------------------------------- */
13331 + * fi_read_lock, fi_write_lock,
13332 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13334 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13336 +/* lock subclass for finfo */
13342 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
13344 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13347 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
13349 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13353 + * fi_read_lock_1, fi_write_lock_1,
13354 + * fi_read_lock_2, fi_write_lock_2
13356 +#define AuReadLockFunc(name) \
13357 +static inline void fi_read_lock_##name(struct file *f) \
13358 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
13360 +#define AuWriteLockFunc(name) \
13361 +static inline void fi_write_lock_##name(struct file *f) \
13362 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
13364 +#define AuRWLockFuncs(name) \
13365 + AuReadLockFunc(name) \
13366 + AuWriteLockFunc(name)
13371 +#undef AuReadLockFunc
13372 +#undef AuWriteLockFunc
13373 +#undef AuRWLockFuncs
13375 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13376 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13377 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13379 +/* ---------------------------------------------------------------------- */
13381 +/* todo: hard/soft set? */
13382 +static inline aufs_bindex_t au_fbtop(struct file *file)
13384 + FiMustAnyLock(file);
13385 + return au_fi(file)->fi_btop;
13388 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13390 + FiMustAnyLock(file);
13391 + AuDebugOn(!au_fi(file)->fi_hdir);
13392 + return au_fi(file)->fi_hdir->fd_bbot;
13395 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13397 + FiMustAnyLock(file);
13398 + AuDebugOn(!au_fi(file)->fi_hdir);
13399 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13402 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13404 + FiMustWriteLock(file);
13405 + au_fi(file)->fi_btop = bindex;
13408 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13410 + FiMustWriteLock(file);
13411 + AuDebugOn(!au_fi(file)->fi_hdir);
13412 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13415 +static inline void au_set_fvdir_cache(struct file *file,
13416 + struct au_vdir *vdir_cache)
13418 + FiMustWriteLock(file);
13419 + AuDebugOn(!au_fi(file)->fi_hdir);
13420 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13423 +static inline struct file *au_hf_top(struct file *file)
13425 + FiMustAnyLock(file);
13426 + AuDebugOn(au_fi(file)->fi_hdir);
13427 + return au_fi(file)->fi_htop.hf_file;
13430 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13432 + FiMustAnyLock(file);
13433 + AuDebugOn(!au_fi(file)->fi_hdir);
13434 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13437 +/* todo: memory barrier? */
13438 +static inline unsigned int au_figen(struct file *f)
13440 + return atomic_read(&au_fi(f)->fi_generation);
13443 +static inline void au_set_mmapped(struct file *f)
13445 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13447 + pr_warn("fi_mmapped wrapped around\n");
13448 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13452 +static inline void au_unset_mmapped(struct file *f)
13454 + atomic_dec(&au_fi(f)->fi_mmapped);
13457 +static inline int au_test_mmapped(struct file *f)
13459 + return atomic_read(&au_fi(f)->fi_mmapped);
13462 +/* customize vma->vm_file */
13464 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13465 + struct file *file)
13469 + f = vma->vm_file;
13471 + vma->vm_file = file;
13476 +#define AuDbgVmRegion(file, vma) do {} while (0)
13478 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13479 + struct file *file)
13481 + au_do_vm_file_reset(vma, file);
13484 +#define AuDbgVmRegion(file, vma) \
13485 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13487 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13488 + struct file *file)
13492 + au_do_vm_file_reset(vma, file);
13493 + f = vma->vm_region->vm_file;
13495 + vma->vm_region->vm_file = file;
13498 +#endif /* CONFIG_MMU */
13500 +/* handle vma->vm_prfile */
13501 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13502 + struct file *file)
13505 + vma->vm_prfile = file;
13506 +#ifndef CONFIG_MMU
13508 + vma->vm_region->vm_prfile = file;
13512 +#endif /* __KERNEL__ */
13513 +#endif /* __AUFS_FILE_H__ */
13514 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13515 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13516 +++ linux/fs/aufs/finfo.c 2017-05-06 22:16:52.778220093 +0200
13519 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13521 + * This program, aufs is free software; you can redistribute it and/or modify
13522 + * it under the terms of the GNU General Public License as published by
13523 + * the Free Software Foundation; either version 2 of the License, or
13524 + * (at your option) any later version.
13526 + * This program is distributed in the hope that it will be useful,
13527 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13528 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13529 + * GNU General Public License for more details.
13531 + * You should have received a copy of the GNU General Public License
13532 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13536 + * file private data
13541 +void au_hfput(struct au_hfile *hf, int execed)
13544 + allow_write_access(hf->hf_file);
13545 + fput(hf->hf_file);
13546 + hf->hf_file = NULL;
13547 + au_br_put(hf->hf_br);
13548 + hf->hf_br = NULL;
13551 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13553 + struct au_finfo *finfo = au_fi(file);
13554 + struct au_hfile *hf;
13555 + struct au_fidir *fidir;
13557 + fidir = finfo->fi_hdir;
13559 + AuDebugOn(finfo->fi_btop != bindex);
13560 + hf = &finfo->fi_htop;
13562 + hf = fidir->fd_hfile + bindex;
13564 + if (hf && hf->hf_file)
13565 + au_hfput(hf, vfsub_file_execed(file));
13567 + FiMustWriteLock(file);
13568 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13569 + hf->hf_file = val;
13570 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13574 +void au_update_figen(struct file *file)
13576 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13577 + /* smp_mb(); */ /* atomic_set */
13580 +/* ---------------------------------------------------------------------- */
13582 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13584 + struct au_fidir *fidir;
13587 + nbr = au_sbbot(sb) + 1;
13589 + nbr = 2; /* initial allocate for 2 branches */
13590 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13592 + fidir->fd_bbot = -1;
13593 + fidir->fd_nent = nbr;
13599 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13602 + struct au_fidir *fidir, *p;
13604 + AuRwMustWriteLock(&finfo->fi_rwsem);
13605 + fidir = finfo->fi_hdir;
13606 + AuDebugOn(!fidir);
13609 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13610 + GFP_NOFS, may_shrink);
13612 + p->fd_nent = nbr;
13613 + finfo->fi_hdir = p;
13620 +/* ---------------------------------------------------------------------- */
13622 +void au_finfo_fin(struct file *file, int atonce)
13624 + struct au_finfo *finfo;
13626 + au_nfiles_dec(file->f_path.dentry->d_sb);
13628 + finfo = au_fi(file);
13629 + AuDebugOn(finfo->fi_hdir);
13630 + AuRwDestroy(&finfo->fi_rwsem);
13632 + au_cache_dfree_finfo(finfo);
13634 + au_cache_free_finfo(finfo);
13637 +void au_fi_init_once(void *_finfo)
13639 + struct au_finfo *finfo = _finfo;
13641 + au_rw_init(&finfo->fi_rwsem);
13644 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13647 + struct au_finfo *finfo;
13648 + struct dentry *dentry;
13651 + dentry = file->f_path.dentry;
13652 + finfo = au_cache_alloc_finfo();
13653 + if (unlikely(!finfo))
13657 + au_nfiles_inc(dentry->d_sb);
13658 + au_rw_write_lock(&finfo->fi_rwsem);
13659 + finfo->fi_btop = -1;
13660 + finfo->fi_hdir = fidir;
13661 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13662 + /* smp_mb(); */ /* atomic_set */
13664 + file->private_data = finfo;
13669 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13670 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13671 +++ linux/fs/aufs/f_op.c 2017-05-06 22:16:52.778220093 +0200
13674 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13676 + * This program, aufs is free software; you can redistribute it and/or modify
13677 + * it under the terms of the GNU General Public License as published by
13678 + * the Free Software Foundation; either version 2 of the License, or
13679 + * (at your option) any later version.
13681 + * This program is distributed in the hope that it will be useful,
13682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13684 + * GNU General Public License for more details.
13686 + * You should have received a copy of the GNU General Public License
13687 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13691 + * file and vm operations
13694 +#include <linux/aio.h>
13695 +#include <linux/fs_stack.h>
13696 +#include <linux/mman.h>
13697 +#include <linux/security.h>
13700 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13703 + aufs_bindex_t bindex;
13704 + struct dentry *dentry, *h_dentry;
13705 + struct au_finfo *finfo;
13706 + struct inode *h_inode;
13708 + FiMustWriteLock(file);
13711 + dentry = file->f_path.dentry;
13712 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13713 + finfo = au_fi(file);
13714 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13715 + atomic_set(&finfo->fi_mmapped, 0);
13716 + bindex = au_dbtop(dentry);
13718 + h_dentry = au_h_dptr(dentry, bindex);
13719 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13720 + if (unlikely(err))
13722 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13724 + h_dentry = h_file->f_path.dentry;
13725 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13726 + if (unlikely(err))
13728 + get_file(h_file);
13730 + if (IS_ERR(h_file))
13731 + err = PTR_ERR(h_file);
13733 + if ((flags & __O_TMPFILE)
13734 + && !(flags & O_EXCL)) {
13735 + h_inode = file_inode(h_file);
13736 + spin_lock(&h_inode->i_lock);
13737 + h_inode->i_state |= I_LINKABLE;
13738 + spin_unlock(&h_inode->i_lock);
13740 + au_set_fbtop(file, bindex);
13741 + au_set_h_fptr(file, bindex, h_file);
13742 + au_update_figen(file);
13743 + /* todo: necessary? */
13744 + /* file->f_ra = h_file->f_ra; */
13751 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13752 + struct file *file)
13755 + struct super_block *sb;
13756 + struct au_do_open_args args = {
13757 + .open = au_do_open_nondir
13760 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13761 + file, vfsub_file_flags(file), file->f_mode);
13763 + sb = file->f_path.dentry->d_sb;
13764 + si_read_lock(sb, AuLock_FLUSH);
13765 + err = au_do_open(file, &args);
13766 + si_read_unlock(sb);
13770 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13772 + struct au_finfo *finfo;
13773 + aufs_bindex_t bindex;
13776 + finfo = au_fi(file);
13777 + au_sphl_del(&finfo->fi_hlist,
13778 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13779 + bindex = finfo->fi_btop;
13781 + au_set_h_fptr(file, bindex, NULL);
13783 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
13784 + au_finfo_fin(file, delayed);
13788 +/* ---------------------------------------------------------------------- */
13790 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13793 + struct file *h_file;
13796 + h_file = au_hf_top(file);
13798 + err = vfsub_flush(h_file, id);
13802 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13804 + return au_do_flush(file, id, au_do_flush_nondir);
13807 +/* ---------------------------------------------------------------------- */
13809 + * read and write functions acquire [fdi]_rwsem once, but release before
13810 + * mmap_sem. This is because to stop a race condition between mmap(2).
13811 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13812 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13813 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13816 +/* Callers should call au_read_post() or fput() in the end */
13817 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
13819 + struct file *h_file;
13822 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
13824 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13825 + h_file = au_hf_top(file);
13826 + get_file(h_file);
13828 + fi_read_unlock(file);
13830 + h_file = ERR_PTR(err);
13835 +static void au_read_post(struct inode *inode, struct file *h_file)
13837 + /* update without lock, I don't think it a problem */
13838 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13842 +struct au_write_pre {
13844 + unsigned int lsc;
13848 + aufs_bindex_t btop;
13852 + * return with iinfo is write-locked
13853 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13856 +static struct file *au_write_pre(struct file *file, int do_ready,
13857 + struct au_write_pre *wpre)
13859 + struct file *h_file;
13860 + struct dentry *dentry;
13862 + unsigned int lsc;
13863 + struct au_pin pin;
13868 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
13869 + h_file = ERR_PTR(err);
13870 + if (unlikely(err))
13873 + dentry = file->f_path.dentry;
13875 + err = au_ready_to_write(file, -1, &pin);
13876 + if (unlikely(err)) {
13877 + h_file = ERR_PTR(err);
13878 + di_write_unlock(dentry);
13883 + di_downgrade_lock(dentry, /*flags*/0);
13885 + wpre->btop = au_fbtop(file);
13886 + h_file = au_hf_top(file);
13887 + get_file(h_file);
13889 + wpre->blks = file_inode(h_file)->i_blocks;
13892 + di_read_unlock(dentry, /*flags*/0);
13895 + fi_write_unlock(file);
13900 +static void au_write_post(struct inode *inode, struct file *h_file,
13901 + struct au_write_pre *wpre, ssize_t written)
13903 + struct inode *h_inode;
13905 + au_cpup_attr_timesizes(inode);
13906 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13907 + h_inode = file_inode(h_file);
13908 + inode->i_mode = h_inode->i_mode;
13909 + ii_write_unlock(inode);
13912 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13914 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13915 + /*force*/h_inode->i_blocks > wpre->blks);
13918 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13922 + struct inode *inode;
13923 + struct file *h_file;
13924 + struct super_block *sb;
13926 + inode = file_inode(file);
13927 + sb = inode->i_sb;
13928 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13930 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
13931 + err = PTR_ERR(h_file);
13932 + if (IS_ERR(h_file))
13935 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13936 + err = vfsub_read_u(h_file, buf, count, ppos);
13937 + /* todo: necessary? */
13938 + /* file->f_ra = h_file->f_ra; */
13939 + au_read_post(inode, h_file);
13942 + si_read_unlock(sb);
13947 + * todo: very ugly
13948 + * it locks both of i_mutex and si_rwsem for read in safe.
13949 + * if the plink maintenance mode continues forever (that is the problem),
13950 + * may loop forever.
13952 +static void au_mtx_and_read_lock(struct inode *inode)
13955 + struct super_block *sb = inode->i_sb;
13958 + inode_lock(inode);
13959 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13962 + inode_unlock(inode);
13963 + si_read_lock(sb, AuLock_NOPLMW);
13964 + si_read_unlock(sb);
13968 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13969 + size_t count, loff_t *ppos)
13972 + struct au_write_pre wpre;
13973 + struct inode *inode;
13974 + struct file *h_file;
13975 + char __user *buf = (char __user *)ubuf;
13977 + inode = file_inode(file);
13978 + au_mtx_and_read_lock(inode);
13981 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13982 + err = PTR_ERR(h_file);
13983 + if (IS_ERR(h_file))
13986 + err = vfsub_write_u(h_file, buf, count, ppos);
13987 + au_write_post(inode, h_file, &wpre, err);
13990 + si_read_unlock(inode->i_sb);
13991 + inode_unlock(inode);
13995 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13996 + struct iov_iter *iov_iter)
13999 + struct file *file;
14000 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
14002 + err = security_file_permission(h_file, rw);
14003 + if (unlikely(err))
14008 + if (rw == MAY_READ)
14009 + iter = h_file->f_op->read_iter;
14010 + else if (rw == MAY_WRITE)
14011 + iter = h_file->f_op->write_iter;
14013 + file = kio->ki_filp;
14014 + kio->ki_filp = h_file;
14017 + err = iter(kio, iov_iter);
14020 + /* currently there is no such fs */
14022 + kio->ki_filp = file;
14028 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14031 + struct file *file, *h_file;
14032 + struct inode *inode;
14033 + struct super_block *sb;
14035 + file = kio->ki_filp;
14036 + inode = file_inode(file);
14037 + sb = inode->i_sb;
14038 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14040 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
14041 + err = PTR_ERR(h_file);
14042 + if (IS_ERR(h_file))
14045 + if (au_test_loopback_kthread()) {
14046 + au_warn_loopback(h_file->f_path.dentry->d_sb);
14047 + if (file->f_mapping != h_file->f_mapping) {
14048 + file->f_mapping = h_file->f_mapping;
14049 + smp_mb(); /* unnecessary? */
14052 + fi_read_unlock(file);
14054 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
14055 + /* todo: necessary? */
14056 + /* file->f_ra = h_file->f_ra; */
14057 + au_read_post(inode, h_file);
14060 + si_read_unlock(sb);
14064 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14067 + struct au_write_pre wpre;
14068 + struct inode *inode;
14069 + struct file *file, *h_file;
14071 + file = kio->ki_filp;
14072 + inode = file_inode(file);
14073 + au_mtx_and_read_lock(inode);
14076 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14077 + err = PTR_ERR(h_file);
14078 + if (IS_ERR(h_file))
14081 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
14082 + au_write_post(inode, h_file, &wpre, err);
14085 + si_read_unlock(inode->i_sb);
14086 + inode_unlock(inode);
14090 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
14091 + struct pipe_inode_info *pipe, size_t len,
14092 + unsigned int flags)
14095 + struct file *h_file;
14096 + struct inode *inode;
14097 + struct super_block *sb;
14099 + inode = file_inode(file);
14100 + sb = inode->i_sb;
14101 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14103 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14104 + err = PTR_ERR(h_file);
14105 + if (IS_ERR(h_file))
14108 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14109 + /* todo: necessasry? */
14110 + /* file->f_ra = h_file->f_ra; */
14111 + au_read_post(inode, h_file);
14114 + si_read_unlock(sb);
14119 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14120 + size_t len, unsigned int flags)
14123 + struct au_write_pre wpre;
14124 + struct inode *inode;
14125 + struct file *h_file;
14127 + inode = file_inode(file);
14128 + au_mtx_and_read_lock(inode);
14131 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14132 + err = PTR_ERR(h_file);
14133 + if (IS_ERR(h_file))
14136 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14137 + au_write_post(inode, h_file, &wpre, err);
14140 + si_read_unlock(inode->i_sb);
14141 + inode_unlock(inode);
14145 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14149 + struct au_write_pre wpre;
14150 + struct inode *inode;
14151 + struct file *h_file;
14153 + inode = file_inode(file);
14154 + au_mtx_and_read_lock(inode);
14157 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14158 + err = PTR_ERR(h_file);
14159 + if (IS_ERR(h_file))
14163 + err = vfs_fallocate(h_file, mode, offset, len);
14165 + au_write_post(inode, h_file, &wpre, /*written*/1);
14168 + si_read_unlock(inode->i_sb);
14169 + inode_unlock(inode);
14173 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
14174 + struct file *dst, loff_t dst_pos,
14175 + size_t len, unsigned int flags)
14178 + struct au_write_pre wpre;
14179 + enum { SRC, DST };
14181 + struct inode *inode;
14182 + struct file *h_file;
14183 + struct super_block *h_sb;
14185 +#define a_src a[SRC]
14186 +#define a_dst a[DST]
14189 + a_src.inode = file_inode(src);
14190 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
14192 + a_dst.inode = file_inode(dst);
14193 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
14196 + au_mtx_and_read_lock(a_dst.inode);
14198 + * in order to match the order in di_write_lock2_{child,parent}(),
14199 + * use f_path.dentry for this comparision.
14201 + if (src->f_path.dentry < dst->f_path.dentry) {
14202 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
14203 + err = PTR_ERR(a_src.h_file);
14204 + if (IS_ERR(a_src.h_file))
14207 + wpre.lsc = AuLsc_FI_2;
14208 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14209 + err = PTR_ERR(a_dst.h_file);
14210 + if (IS_ERR(a_dst.h_file)) {
14211 + au_read_post(a_src.inode, a_src.h_file);
14215 + wpre.lsc = AuLsc_FI_1;
14216 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14217 + err = PTR_ERR(a_dst.h_file);
14218 + if (IS_ERR(a_dst.h_file))
14221 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
14222 + err = PTR_ERR(a_src.h_file);
14223 + if (IS_ERR(a_src.h_file)) {
14224 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
14231 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
14232 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
14233 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
14239 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
14240 + dst_pos, len, flags);
14243 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
14244 + fi_read_unlock(src);
14245 + au_read_post(a_src.inode, a_src.h_file);
14247 + si_read_unlock(a_dst.inode->i_sb);
14248 + inode_unlock(a_dst.inode);
14255 +/* ---------------------------------------------------------------------- */
14258 + * The locking order around current->mmap_sem.
14259 + * - in most and regular cases
14260 + * file I/O syscall -- aufs_read() or something
14261 + * -- si_rwsem for read -- mmap_sem
14262 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14264 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14265 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14266 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14267 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14268 + * It means that when aufs acquires si_rwsem for write, the process should never
14269 + * acquire mmap_sem.
14271 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14272 + * problem either since any directory is not able to be mmap-ed.
14273 + * The similar scenario is applied to aufs_readlink() too.
14276 +#if 0 /* stop calling security_file_mmap() */
14277 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14278 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14280 +static unsigned long au_arch_prot_conv(unsigned long flags)
14282 + /* currently ppc64 only */
14283 +#ifdef CONFIG_PPC64
14284 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14285 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14286 + return AuConv_VM_PROT(flags, SAO);
14288 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14293 +static unsigned long au_prot_conv(unsigned long flags)
14295 + return AuConv_VM_PROT(flags, READ)
14296 + | AuConv_VM_PROT(flags, WRITE)
14297 + | AuConv_VM_PROT(flags, EXEC)
14298 + | au_arch_prot_conv(flags);
14301 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14302 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14304 +static unsigned long au_flag_conv(unsigned long flags)
14306 + return AuConv_VM_MAP(flags, GROWSDOWN)
14307 + | AuConv_VM_MAP(flags, DENYWRITE)
14308 + | AuConv_VM_MAP(flags, LOCKED);
14312 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14315 + const unsigned char wlock
14316 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14317 + struct super_block *sb;
14318 + struct file *h_file;
14319 + struct inode *inode;
14321 + AuDbgVmRegion(file, vma);
14323 + inode = file_inode(file);
14324 + sb = inode->i_sb;
14326 + si_read_lock(sb, AuLock_NOPLMW);
14328 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14330 + err = PTR_ERR(h_file);
14331 + if (IS_ERR(h_file))
14335 + au_set_mmapped(file);
14336 + au_vm_file_reset(vma, h_file);
14338 + * we cannot call security_mmap_file() here since it may acquire
14339 + * mmap_sem or i_mutex.
14341 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14342 + * au_flag_conv(vma->vm_flags));
14345 + err = call_mmap(h_file, vma);
14347 + au_vm_prfile_set(vma, file);
14348 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14349 + goto out_fput; /* success */
14351 + au_unset_mmapped(file);
14352 + au_vm_file_reset(vma, file);
14356 + ii_write_unlock(inode);
14361 + si_read_unlock(sb);
14367 +/* ---------------------------------------------------------------------- */
14369 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14373 + struct au_write_pre wpre;
14374 + struct inode *inode;
14375 + struct file *h_file;
14377 + err = 0; /* -EBADF; */ /* posix? */
14378 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14381 + inode = file_inode(file);
14382 + au_mtx_and_read_lock(inode);
14385 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14386 + err = PTR_ERR(h_file);
14387 + if (IS_ERR(h_file))
14390 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14391 + au_write_post(inode, h_file, &wpre, /*written*/0);
14394 + si_read_unlock(inode->i_sb);
14395 + inode_unlock(inode);
14400 +static int aufs_fasync(int fd, struct file *file, int flag)
14403 + struct file *h_file;
14404 + struct super_block *sb;
14406 + sb = file->f_path.dentry->d_sb;
14407 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14409 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14410 + err = PTR_ERR(h_file);
14411 + if (IS_ERR(h_file))
14414 + if (h_file->f_op->fasync)
14415 + err = h_file->f_op->fasync(fd, h_file, flag);
14416 + fput(h_file); /* instead of au_read_post() */
14419 + si_read_unlock(sb);
14423 +static int aufs_setfl(struct file *file, unsigned long arg)
14426 + struct file *h_file;
14427 + struct super_block *sb;
14429 + sb = file->f_path.dentry->d_sb;
14430 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14432 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14433 + err = PTR_ERR(h_file);
14434 + if (IS_ERR(h_file))
14437 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14438 + err = setfl(/*unused fd*/-1, h_file, arg);
14439 + fput(h_file); /* instead of au_read_post() */
14442 + si_read_unlock(sb);
14446 +/* ---------------------------------------------------------------------- */
14448 +/* no one supports this operation, currently */
14450 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14451 + size_t len, loff_t *pos, int more)
14456 +/* ---------------------------------------------------------------------- */
14458 +const struct file_operations aufs_file_fop = {
14459 + .owner = THIS_MODULE,
14461 + .llseek = default_llseek,
14463 + .read = aufs_read,
14464 + .write = aufs_write,
14465 + .read_iter = aufs_read_iter,
14466 + .write_iter = aufs_write_iter,
14468 +#ifdef CONFIG_AUFS_POLL
14469 + .poll = aufs_poll,
14471 + .unlocked_ioctl = aufs_ioctl_nondir,
14472 +#ifdef CONFIG_COMPAT
14473 + .compat_ioctl = aufs_compat_ioctl_nondir,
14475 + .mmap = aufs_mmap,
14476 + .open = aufs_open_nondir,
14477 + .flush = aufs_flush_nondir,
14478 + .release = aufs_release_nondir,
14479 + .fsync = aufs_fsync_nondir,
14480 + .fasync = aufs_fasync,
14481 + /* .sendpage = aufs_sendpage, */
14482 + .setfl = aufs_setfl,
14483 + .splice_write = aufs_splice_write,
14484 + .splice_read = aufs_splice_read,
14486 + .aio_splice_write = aufs_aio_splice_write,
14487 + .aio_splice_read = aufs_aio_splice_read,
14489 + .fallocate = aufs_fallocate,
14490 + .copy_file_range = aufs_copy_file_range
14492 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14493 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14494 +++ linux/fs/aufs/fstype.h 2017-05-06 22:16:52.778220093 +0200
14497 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14499 + * This program, aufs is free software; you can redistribute it and/or modify
14500 + * it under the terms of the GNU General Public License as published by
14501 + * the Free Software Foundation; either version 2 of the License, or
14502 + * (at your option) any later version.
14504 + * This program is distributed in the hope that it will be useful,
14505 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14507 + * GNU General Public License for more details.
14509 + * You should have received a copy of the GNU General Public License
14510 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14514 + * judging filesystem type
14517 +#ifndef __AUFS_FSTYPE_H__
14518 +#define __AUFS_FSTYPE_H__
14522 +#include <linux/fs.h>
14523 +#include <linux/magic.h>
14524 +#include <linux/nfs_fs.h>
14525 +#include <linux/romfs_fs.h>
14527 +static inline int au_test_aufs(struct super_block *sb)
14529 + return sb->s_magic == AUFS_SUPER_MAGIC;
14532 +static inline const char *au_sbtype(struct super_block *sb)
14534 + return sb->s_type->name;
14537 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14539 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14540 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14546 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14548 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14549 + return sb->s_magic == ROMFS_MAGIC;
14555 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14557 +#if IS_ENABLED(CONFIG_CRAMFS)
14558 + return sb->s_magic == CRAMFS_MAGIC;
14563 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14565 +#if IS_ENABLED(CONFIG_NFS_FS)
14566 + return sb->s_magic == NFS_SUPER_MAGIC;
14572 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14574 +#if IS_ENABLED(CONFIG_FUSE_FS)
14575 + return sb->s_magic == FUSE_SUPER_MAGIC;
14581 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14583 +#if IS_ENABLED(CONFIG_XFS_FS)
14584 + return sb->s_magic == XFS_SB_MAGIC;
14590 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14592 +#ifdef CONFIG_TMPFS
14593 + return sb->s_magic == TMPFS_MAGIC;
14599 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14601 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14602 + return !strcmp(au_sbtype(sb), "ecryptfs");
14608 +static inline int au_test_ramfs(struct super_block *sb)
14610 + return sb->s_magic == RAMFS_MAGIC;
14613 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14615 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14616 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14622 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14624 +#ifdef CONFIG_PROC_FS
14625 + return sb->s_magic == PROC_SUPER_MAGIC;
14631 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14633 +#ifdef CONFIG_SYSFS
14634 + return sb->s_magic == SYSFS_MAGIC;
14640 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14642 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14643 + return sb->s_magic == CONFIGFS_MAGIC;
14649 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14651 +#if IS_ENABLED(CONFIG_MINIX_FS)
14652 + return sb->s_magic == MINIX3_SUPER_MAGIC
14653 + || sb->s_magic == MINIX2_SUPER_MAGIC
14654 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14655 + || sb->s_magic == MINIX_SUPER_MAGIC
14656 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14662 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14664 +#if IS_ENABLED(CONFIG_FAT_FS)
14665 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14671 +static inline int au_test_msdos(struct super_block *sb)
14673 + return au_test_fat(sb);
14676 +static inline int au_test_vfat(struct super_block *sb)
14678 + return au_test_fat(sb);
14681 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14683 +#ifdef CONFIG_SECURITYFS
14684 + return sb->s_magic == SECURITYFS_MAGIC;
14690 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14692 +#if IS_ENABLED(CONFIG_SQUASHFS)
14693 + return sb->s_magic == SQUASHFS_MAGIC;
14699 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14701 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14702 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14708 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14710 +#if IS_ENABLED(CONFIG_XENFS)
14711 + return sb->s_magic == XENFS_SUPER_MAGIC;
14717 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14719 +#ifdef CONFIG_DEBUG_FS
14720 + return sb->s_magic == DEBUGFS_MAGIC;
14726 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14728 +#if IS_ENABLED(CONFIG_NILFS)
14729 + return sb->s_magic == NILFS_SUPER_MAGIC;
14735 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14737 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14738 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14744 +/* ---------------------------------------------------------------------- */
14746 + * they can't be an aufs branch.
14748 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14751 +#ifndef CONFIG_AUFS_BR_RAMFS
14752 + au_test_ramfs(sb) ||
14754 + au_test_procfs(sb)
14755 + || au_test_sysfs(sb)
14756 + || au_test_configfs(sb)
14757 + || au_test_debugfs(sb)
14758 + || au_test_securityfs(sb)
14759 + || au_test_xenfs(sb)
14760 + || au_test_ecryptfs(sb)
14761 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14762 + || au_test_aufs(sb); /* will be supported in next version */
14765 +static inline int au_test_fs_remote(struct super_block *sb)
14767 + return !au_test_tmpfs(sb)
14768 +#ifdef CONFIG_AUFS_BR_RAMFS
14769 + && !au_test_ramfs(sb)
14771 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14774 +/* ---------------------------------------------------------------------- */
14777 + * Note: these functions (below) are created after reading ->getattr() in all
14778 + * filesystems under linux/fs. it means we have to do so in every update...
14782 + * some filesystems require getattr to refresh the inode attributes before
14784 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14785 + * and leave the work for d_revalidate()
14787 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14789 + return au_test_nfs(sb)
14790 + || au_test_fuse(sb)
14791 + /* || au_test_btrfs(sb) */ /* untested */
14796 + * filesystems which don't maintain i_size or i_blocks.
14798 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14800 + return au_test_xfs(sb)
14801 + || au_test_btrfs(sb)
14802 + || au_test_ubifs(sb)
14803 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14804 + /* || au_test_minix(sb) */ /* untested */
14809 + * filesystems which don't store the correct value in some of their inode
14812 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14814 + return au_test_fs_bad_iattr_size(sb)
14815 + || au_test_fat(sb)
14816 + || au_test_msdos(sb)
14817 + || au_test_vfat(sb);
14820 +/* they don't check i_nlink in link(2) */
14821 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14823 + return au_test_tmpfs(sb)
14824 +#ifdef CONFIG_AUFS_BR_RAMFS
14825 + || au_test_ramfs(sb)
14827 + || au_test_ubifs(sb)
14828 + || au_test_hfsplus(sb);
14832 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14834 +static inline int au_test_fs_notime(struct super_block *sb)
14836 + return au_test_nfs(sb)
14837 + || au_test_fuse(sb)
14838 + || au_test_ubifs(sb)
14842 +/* temporary support for i#1 in cramfs */
14843 +static inline int au_test_fs_unique_ino(struct inode *inode)
14845 + if (au_test_cramfs(inode->i_sb))
14846 + return inode->i_ino != 1;
14850 +/* ---------------------------------------------------------------------- */
14853 + * the filesystem where the xino files placed must support i/o after unlink and
14854 + * maintain i_size and i_blocks.
14856 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14858 + return au_test_fs_remote(sb)
14859 + || au_test_fs_bad_iattr_size(sb)
14860 + /* don't want unnecessary work for xino */
14861 + || au_test_aufs(sb)
14862 + || au_test_ecryptfs(sb)
14863 + || au_test_nilfs(sb);
14866 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14868 + return au_test_tmpfs(sb)
14869 + || au_test_ramfs(sb);
14873 + * test if the @sb is real-readonly.
14875 +static inline int au_test_fs_rr(struct super_block *sb)
14877 + return au_test_squashfs(sb)
14878 + || au_test_iso9660(sb)
14879 + || au_test_cramfs(sb)
14880 + || au_test_romfs(sb);
14884 + * test if the @inode is nfs with 'noacl' option
14885 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14887 +static inline int au_test_nfs_noacl(struct inode *inode)
14889 + return au_test_nfs(inode->i_sb)
14890 + /* && IS_POSIXACL(inode) */
14891 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14894 +#endif /* __KERNEL__ */
14895 +#endif /* __AUFS_FSTYPE_H__ */
14896 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14897 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14898 +++ linux/fs/aufs/hfsnotify.c 2017-05-06 22:16:52.778220093 +0200
14901 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14903 + * This program, aufs is free software; you can redistribute it and/or modify
14904 + * it under the terms of the GNU General Public License as published by
14905 + * the Free Software Foundation; either version 2 of the License, or
14906 + * (at your option) any later version.
14908 + * This program is distributed in the hope that it will be useful,
14909 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14910 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14911 + * GNU General Public License for more details.
14913 + * You should have received a copy of the GNU General Public License
14914 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14918 + * fsnotify for the lower directories
14923 +/* FS_IN_IGNORED is unnecessary */
14924 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14925 + | FS_CREATE | FS_EVENT_ON_CHILD);
14926 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14927 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14929 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14931 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14933 + /* AuDbg("here\n"); */
14934 + au_cache_dfree_hnotify(hn);
14935 + smp_mb__before_atomic();
14936 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14937 + wake_up(&au_hfsn_wq);
14940 +static int au_hfsn_alloc(struct au_hinode *hinode)
14943 + struct au_hnotify *hn;
14944 + struct super_block *sb;
14945 + struct au_branch *br;
14946 + struct fsnotify_mark *mark;
14947 + aufs_bindex_t bindex;
14949 + hn = hinode->hi_notify;
14950 + sb = hn->hn_aufs_inode->i_sb;
14951 + bindex = au_br_index(sb, hinode->hi_id);
14952 + br = au_sbr(sb, bindex);
14953 + AuDebugOn(!br->br_hfsn);
14955 + mark = &hn->hn_mark;
14956 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14957 + mark->mask = AuHfsnMask;
14959 + * by udba rename or rmdir, aufs assign a new inode to the known
14960 + * h_inode, so specify 1 to allow dups.
14963 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14964 + /*mnt*/NULL, /*allow_dups*/1);
14970 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14972 + struct fsnotify_mark *mark;
14973 + unsigned long long ull;
14974 + struct fsnotify_group *group;
14976 + ull = atomic64_inc_return(&au_hfsn_ifree);
14979 + mark = &hn->hn_mark;
14980 + spin_lock(&mark->lock);
14981 + group = mark->group;
14982 + fsnotify_get_group(group);
14983 + spin_unlock(&mark->lock);
14985 + fsnotify_destroy_mark(mark, group);
14986 + fsnotify_put_mark(mark);
14987 + fsnotify_put_group(group);
14990 + /* free hn by myself */
14994 +/* ---------------------------------------------------------------------- */
14996 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14998 + struct fsnotify_mark *mark;
15000 + mark = &hinode->hi_notify->hn_mark;
15001 + spin_lock(&mark->lock);
15003 + AuDebugOn(mark->mask & AuHfsnMask);
15004 + mark->mask |= AuHfsnMask;
15006 + AuDebugOn(!(mark->mask & AuHfsnMask));
15007 + mark->mask &= ~AuHfsnMask;
15009 + spin_unlock(&mark->lock);
15010 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
15013 +/* ---------------------------------------------------------------------- */
15015 +/* #define AuDbgHnotify */
15016 +#ifdef AuDbgHnotify
15017 +static char *au_hfsn_name(u32 mask)
15019 +#ifdef CONFIG_AUFS_DEBUG
15020 +#define test_ret(flag) \
15022 + if (mask & flag) \
15025 + test_ret(FS_ACCESS);
15026 + test_ret(FS_MODIFY);
15027 + test_ret(FS_ATTRIB);
15028 + test_ret(FS_CLOSE_WRITE);
15029 + test_ret(FS_CLOSE_NOWRITE);
15030 + test_ret(FS_OPEN);
15031 + test_ret(FS_MOVED_FROM);
15032 + test_ret(FS_MOVED_TO);
15033 + test_ret(FS_CREATE);
15034 + test_ret(FS_DELETE);
15035 + test_ret(FS_DELETE_SELF);
15036 + test_ret(FS_MOVE_SELF);
15037 + test_ret(FS_UNMOUNT);
15038 + test_ret(FS_Q_OVERFLOW);
15039 + test_ret(FS_IN_IGNORED);
15040 + test_ret(FS_ISDIR);
15041 + test_ret(FS_IN_ONESHOT);
15042 + test_ret(FS_EVENT_ON_CHILD);
15051 +/* ---------------------------------------------------------------------- */
15053 +static void au_hfsn_free_group(struct fsnotify_group *group)
15055 + struct au_br_hfsnotify *hfsn = group->private;
15057 + /* AuDbg("here\n"); */
15058 + au_delayed_kfree(hfsn);
15061 +static int au_hfsn_handle_event(struct fsnotify_group *group,
15062 + struct inode *inode,
15063 + struct fsnotify_mark *inode_mark,
15064 + struct fsnotify_mark *vfsmount_mark,
15065 + u32 mask, const void *data, int data_type,
15066 + const unsigned char *file_name, u32 cookie)
15069 + struct au_hnotify *hnotify;
15070 + struct inode *h_dir, *h_inode;
15071 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
15073 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
15076 + /* if FS_UNMOUNT happens, there must be another bug */
15077 + AuDebugOn(mask & FS_UNMOUNT);
15078 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
15083 +#ifdef AuDbgHnotify
15085 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
15086 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
15087 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
15088 + h_dir->i_ino, mask, au_hfsn_name(mask),
15089 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
15090 + /* WARN_ON(1); */
15095 + AuDebugOn(!inode_mark);
15096 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
15097 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
15103 +static struct fsnotify_ops au_hfsn_ops = {
15104 + .handle_event = au_hfsn_handle_event,
15105 + .free_group_priv = au_hfsn_free_group
15108 +/* ---------------------------------------------------------------------- */
15110 +static void au_hfsn_fin_br(struct au_branch *br)
15112 + struct au_br_hfsnotify *hfsn;
15114 + hfsn = br->br_hfsn;
15117 + fsnotify_put_group(hfsn->hfsn_group);
15122 +static int au_hfsn_init_br(struct au_branch *br, int perm)
15125 + struct fsnotify_group *group;
15126 + struct au_br_hfsnotify *hfsn;
15129 + br->br_hfsn = NULL;
15130 + if (!au_br_hnotifyable(perm))
15134 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
15135 + if (unlikely(!hfsn))
15139 + group = fsnotify_alloc_group(&au_hfsn_ops);
15140 + if (IS_ERR(group)) {
15141 + err = PTR_ERR(group);
15142 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
15146 + group->private = hfsn;
15147 + hfsn->hfsn_group = group;
15148 + br->br_hfsn = hfsn;
15149 + goto out; /* success */
15152 + au_delayed_kfree(hfsn);
15157 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
15162 + if (!br->br_hfsn)
15163 + err = au_hfsn_init_br(br, perm);
15168 +/* ---------------------------------------------------------------------- */
15170 +static void au_hfsn_fin(void)
15172 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
15173 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
15176 +const struct au_hnotify_op au_hnotify_op = {
15177 + .ctl = au_hfsn_ctl,
15178 + .alloc = au_hfsn_alloc,
15179 + .free = au_hfsn_free,
15181 + .fin = au_hfsn_fin,
15183 + .reset_br = au_hfsn_reset_br,
15184 + .fin_br = au_hfsn_fin_br,
15185 + .init_br = au_hfsn_init_br
15187 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15188 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15189 +++ linux/fs/aufs/hfsplus.c 2017-05-06 22:16:52.778220093 +0200
15192 + * Copyright (C) 2010-2017 Junjiro R. Okajima
15194 + * This program, aufs is free software; you can redistribute it and/or modify
15195 + * it under the terms of the GNU General Public License as published by
15196 + * the Free Software Foundation; either version 2 of the License, or
15197 + * (at your option) any later version.
15199 + * This program is distributed in the hope that it will be useful,
15200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15202 + * GNU General Public License for more details.
15204 + * You should have received a copy of the GNU General Public License
15205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15209 + * special support for filesystems which aqucires an inode mutex
15210 + * at final closing a file, eg, hfsplus.
15212 + * This trick is very simple and stupid, just to open the file before really
15213 + * neceeary open to tell hfsplus that this is not the final closing.
15214 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15215 + * and au_h_open_post() after releasing it.
15220 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15223 + struct file *h_file;
15224 + struct dentry *h_dentry;
15226 + h_dentry = au_h_dptr(dentry, bindex);
15227 + AuDebugOn(!h_dentry);
15228 + AuDebugOn(d_is_negative(h_dentry));
15231 + if (au_test_hfsplus(h_dentry->d_sb)
15232 + && d_is_reg(h_dentry))
15233 + h_file = au_h_open(dentry, bindex,
15234 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15235 + /*file*/NULL, force_wr);
15239 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15240 + struct file *h_file)
15244 + au_sbr_put(dentry->d_sb, bindex);
15247 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15248 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15249 +++ linux/fs/aufs/hnotify.c 2017-05-06 22:16:52.778220093 +0200
15252 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15254 + * This program, aufs is free software; you can redistribute it and/or modify
15255 + * it under the terms of the GNU General Public License as published by
15256 + * the Free Software Foundation; either version 2 of the License, or
15257 + * (at your option) any later version.
15259 + * This program is distributed in the hope that it will be useful,
15260 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15261 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15262 + * GNU General Public License for more details.
15264 + * You should have received a copy of the GNU General Public License
15265 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15269 + * abstraction to notify the direct changes on lower directories
15274 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15277 + struct au_hnotify *hn;
15280 + hn = au_cache_alloc_hnotify();
15282 + hn->hn_aufs_inode = inode;
15283 + hinode->hi_notify = hn;
15284 + err = au_hnotify_op.alloc(hinode);
15286 + if (unlikely(err)) {
15287 + hinode->hi_notify = NULL;
15288 + au_cache_dfree_hnotify(hn);
15290 + * The upper dir was removed by udba, but the same named
15291 + * dir left. In this case, aufs assignes a new inode
15292 + * number and set the monitor again.
15293 + * For the lower dir, the old monitnor is still left.
15295 + if (err == -EEXIST)
15304 +void au_hn_free(struct au_hinode *hinode)
15306 + struct au_hnotify *hn;
15308 + hn = hinode->hi_notify;
15310 + hinode->hi_notify = NULL;
15311 + if (au_hnotify_op.free(hinode, hn))
15312 + au_cache_dfree_hnotify(hn);
15316 +/* ---------------------------------------------------------------------- */
15318 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15320 + if (hinode->hi_notify)
15321 + au_hnotify_op.ctl(hinode, do_set);
15324 +void au_hn_reset(struct inode *inode, unsigned int flags)
15326 + aufs_bindex_t bindex, bbot;
15327 + struct inode *hi;
15328 + struct dentry *iwhdentry;
15330 + bbot = au_ibbot(inode);
15331 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15332 + hi = au_h_iptr(inode, bindex);
15336 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15337 + iwhdentry = au_hi_wh(inode, bindex);
15341 + au_set_h_iptr(inode, bindex, NULL, 0);
15342 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15343 + flags & ~AuHi_XINO);
15346 + /* inode_unlock(hi); */
15350 +/* ---------------------------------------------------------------------- */
15352 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15355 + aufs_bindex_t bindex, bbot, bfound, btop;
15356 + struct inode *h_i;
15359 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15360 + pr_warn("branch root dir was changed\n");
15365 + bbot = au_ibbot(inode);
15366 + btop = au_ibtop(inode);
15367 +#if 0 /* reserved for future use */
15368 + if (bindex == bbot) {
15369 + /* keep this ino in rename case */
15373 + for (bindex = btop; bindex <= bbot; bindex++)
15374 + if (au_h_iptr(inode, bindex) == h_inode) {
15381 + for (bindex = btop; bindex <= bbot; bindex++) {
15382 + h_i = au_h_iptr(inode, bindex);
15386 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15387 + /* ignore this error */
15388 + /* bad action? */
15391 + /* children inode number will be broken */
15398 +static int hn_gen_tree(struct dentry *dentry)
15400 + int err, i, j, ndentry;
15401 + struct au_dcsub_pages dpages;
15402 + struct au_dpage *dpage;
15403 + struct dentry **dentries;
15405 + err = au_dpages_init(&dpages, GFP_NOFS);
15406 + if (unlikely(err))
15408 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15409 + if (unlikely(err))
15412 + for (i = 0; i < dpages.ndpage; i++) {
15413 + dpage = dpages.dpages + i;
15414 + dentries = dpage->dentries;
15415 + ndentry = dpage->ndentry;
15416 + for (j = 0; j < ndentry; j++) {
15417 + struct dentry *d;
15424 + if (d_really_is_positive(d))
15425 + /* todo: reset children xino?
15426 + cached children only? */
15427 + au_iigen_dec(d_inode(d));
15432 + au_dpages_free(&dpages);
15435 + /* discard children */
15436 + dentry_unhash(dentry);
15444 + * return 0 if processed.
15446 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15447 + const unsigned int isdir)
15450 + struct dentry *d;
15451 + struct qstr *dname;
15454 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15455 + pr_warn("branch root dir was changed\n");
15461 + AuDebugOn(!name);
15462 + au_iigen_dec(inode);
15463 + spin_lock(&inode->i_lock);
15464 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15465 + spin_lock(&d->d_lock);
15466 + dname = &d->d_name;
15467 + if (dname->len != nlen
15468 + && memcmp(dname->name, name, nlen)) {
15469 + spin_unlock(&d->d_lock);
15474 + spin_unlock(&d->d_lock);
15477 + spin_unlock(&inode->i_lock);
15479 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15480 + d = d_find_any_alias(inode);
15482 + au_iigen_dec(inode);
15486 + spin_lock(&d->d_lock);
15487 + dname = &d->d_name;
15488 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15489 + spin_unlock(&d->d_lock);
15490 + err = hn_gen_tree(d);
15491 + spin_lock(&d->d_lock);
15493 + spin_unlock(&d->d_lock);
15502 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15506 + if (IS_ROOT(dentry)) {
15507 + pr_warn("branch root dir was changed\n");
15513 + au_digen_dec(dentry);
15514 + if (d_really_is_positive(dentry))
15515 + au_iigen_dec(d_inode(dentry));
15517 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15518 + if (d_really_is_positive(dentry))
15519 + err = hn_gen_tree(dentry);
15526 +/* ---------------------------------------------------------------------- */
15528 +/* hnotify job flags */
15529 +#define AuHnJob_XINO0 1
15530 +#define AuHnJob_GEN (1 << 1)
15531 +#define AuHnJob_DIRENT (1 << 2)
15532 +#define AuHnJob_ISDIR (1 << 3)
15533 +#define AuHnJob_TRYXINO0 (1 << 4)
15534 +#define AuHnJob_MNTPNT (1 << 5)
15535 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15536 +#define au_fset_hnjob(flags, name) \
15537 + do { (flags) |= AuHnJob_##name; } while (0)
15538 +#define au_fclr_hnjob(flags, name) \
15539 + do { (flags) &= ~AuHnJob_##name; } while (0)
15547 +struct au_hnotify_args {
15548 + struct inode *h_dir, *dir, *h_child_inode;
15550 + unsigned int flags[AuHnLast];
15551 + unsigned int h_child_nlen;
15552 + char h_child_name[];
15555 +struct hn_job_args {
15556 + unsigned int flags;
15557 + struct inode *inode, *h_inode, *dir, *h_dir;
15558 + struct dentry *dentry;
15563 +static int hn_job(struct hn_job_args *a)
15565 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15569 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15570 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15572 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15575 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15576 + if (!a->h_inode->i_nlink
15577 + && !(a->h_inode->i_state & I_LINKABLE))
15578 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15579 + inode_unlock(a->h_inode);
15582 + /* make the generation obsolete */
15583 + if (au_ftest_hnjob(a->flags, GEN)) {
15586 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15588 + if (e && a->dentry)
15589 + hn_gen_by_name(a->dentry, isdir);
15590 + /* ignore this error */
15593 + /* make dir entries obsolete */
15594 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15595 + struct au_vdir *vdir;
15597 + vdir = au_ivdir(a->inode);
15599 + vdir->vd_jiffy = 0;
15600 + /* IMustLock(a->inode); */
15601 + /* a->inode->i_version++; */
15604 + /* can do nothing but warn */
15605 + if (au_ftest_hnjob(a->flags, MNTPNT)
15607 + && d_mountpoint(a->dentry))
15608 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15613 +/* ---------------------------------------------------------------------- */
15615 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15616 + struct inode *dir)
15618 + struct dentry *dentry, *d, *parent;
15619 + struct qstr *dname;
15621 + parent = d_find_any_alias(dir);
15626 + spin_lock(&parent->d_lock);
15627 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15628 + /* AuDbg("%pd\n", d); */
15629 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15630 + dname = &d->d_name;
15631 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15632 + goto cont_unlock;
15636 + goto cont_unlock;
15637 + if (au_dcount(d) > 0) {
15638 + dentry = dget_dlock(d);
15639 + spin_unlock(&d->d_lock);
15644 + spin_unlock(&d->d_lock);
15646 + spin_unlock(&parent->d_lock);
15650 + di_write_lock_child(dentry);
15655 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15656 + aufs_bindex_t bindex, ino_t h_ino)
15658 + struct inode *inode;
15663 + err = au_xino_read(sb, bindex, h_ino, &ino);
15665 + inode = ilookup(sb, ino);
15669 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15670 + pr_warn("wrong root branch\n");
15676 + ii_write_lock_child(inode);
15682 +static void au_hn_bh(void *_args)
15684 + struct au_hnotify_args *a = _args;
15685 + struct super_block *sb;
15686 + aufs_bindex_t bindex, bbot, bfound;
15687 + unsigned char xino, try_iput;
15689 + struct inode *inode;
15691 + struct hn_job_args args;
15692 + struct dentry *dentry;
15693 + struct au_sbinfo *sbinfo;
15695 + AuDebugOn(!_args);
15696 + AuDebugOn(!a->h_dir);
15697 + AuDebugOn(!a->dir);
15698 + AuDebugOn(!a->mask);
15699 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15700 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15701 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15706 + * do not lock a->dir->i_mutex here
15707 + * because of d_revalidate() may cause a deadlock.
15709 + sb = a->dir->i_sb;
15711 + sbinfo = au_sbi(sb);
15712 + AuDebugOn(!sbinfo);
15713 + si_write_lock(sb, AuLock_NOPLMW);
15715 + ii_read_lock_parent(a->dir);
15717 + bbot = au_ibbot(a->dir);
15718 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15719 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15723 + ii_read_unlock(a->dir);
15724 + if (unlikely(bfound < 0))
15727 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15729 + if (a->h_child_inode)
15730 + h_ino = a->h_child_inode->i_ino;
15732 + if (a->h_child_nlen
15733 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15734 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15735 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15738 + if (dentry && d_really_is_positive(dentry))
15739 + inode = d_inode(dentry);
15740 + if (xino && !inode && h_ino
15741 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15742 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15743 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15744 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15748 + args.flags = a->flags[AuHn_CHILD];
15749 + args.dentry = dentry;
15750 + args.inode = inode;
15751 + args.h_inode = a->h_child_inode;
15752 + args.dir = a->dir;
15753 + args.h_dir = a->h_dir;
15754 + args.h_name = a->h_child_name;
15755 + args.h_nlen = a->h_child_nlen;
15756 + err = hn_job(&args);
15758 + if (au_di(dentry))
15759 + di_write_unlock(dentry);
15762 + if (inode && try_iput) {
15763 + ii_write_unlock(inode);
15767 + ii_write_lock_parent(a->dir);
15768 + args.flags = a->flags[AuHn_PARENT];
15769 + args.dentry = NULL;
15770 + args.inode = a->dir;
15771 + args.h_inode = a->h_dir;
15773 + args.h_dir = NULL;
15774 + args.h_name = NULL;
15776 + err = hn_job(&args);
15777 + ii_write_unlock(a->dir);
15780 + iput(a->h_child_inode);
15783 + si_write_unlock(sb);
15784 + au_nwt_done(&sbinfo->si_nowait);
15785 + au_delayed_kfree(a);
15788 +/* ---------------------------------------------------------------------- */
15790 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15791 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15794 + unsigned int flags[AuHnLast], f;
15795 + unsigned char isdir, isroot, wh;
15796 + struct inode *dir;
15797 + struct au_hnotify_args *args;
15798 + char *p, *h_child_name;
15801 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15802 + dir = igrab(hnotify->hn_aufs_inode);
15806 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15808 + h_child_name = (void *)h_child_qstr->name;
15809 + len = h_child_qstr->len;
15810 + if (h_child_name) {
15811 + if (len > AUFS_WH_PFX_LEN
15812 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15813 + h_child_name += AUFS_WH_PFX_LEN;
15814 + len -= AUFS_WH_PFX_LEN;
15820 + if (h_child_inode)
15821 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15822 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15823 + flags[AuHn_CHILD] = 0;
15825 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15826 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15827 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15828 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15829 + case FS_MOVED_FROM:
15830 + case FS_MOVED_TO:
15831 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15832 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15835 + AuDebugOn(!h_child_name);
15840 + * aufs never be able to get this child inode.
15841 + * revalidation should be in d_revalidate()
15842 + * by checking i_nlink, i_generation or d_unhashed().
15844 + AuDebugOn(!h_child_name);
15845 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15846 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15854 + h_child_inode = NULL;
15857 + /* iput() and kfree() will be called in au_hnotify() */
15858 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15859 + if (unlikely(!args)) {
15860 + AuErr1("no memory\n");
15864 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15865 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15866 + args->mask = mask;
15868 + args->h_dir = igrab(h_dir);
15869 + if (h_child_inode)
15870 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15871 + args->h_child_inode = h_child_inode;
15872 + args->h_child_nlen = len;
15874 + p = (void *)args;
15875 + p += sizeof(*args);
15876 + memcpy(p, h_child_name, len);
15880 + /* NFS fires the event for silly-renamed one from kworker */
15882 + if (!dir->i_nlink
15883 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15885 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15886 + if (unlikely(err)) {
15887 + pr_err("wkq %d\n", err);
15888 + iput(args->h_child_inode);
15889 + iput(args->h_dir);
15891 + au_delayed_kfree(args);
15898 +/* ---------------------------------------------------------------------- */
15900 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15904 + AuDebugOn(!(udba & AuOptMask_UDBA));
15907 + if (au_hnotify_op.reset_br)
15908 + err = au_hnotify_op.reset_br(udba, br, perm);
15913 +int au_hnotify_init_br(struct au_branch *br, int perm)
15918 + if (au_hnotify_op.init_br)
15919 + err = au_hnotify_op.init_br(br, perm);
15924 +void au_hnotify_fin_br(struct au_branch *br)
15926 + if (au_hnotify_op.fin_br)
15927 + au_hnotify_op.fin_br(br);
15930 +static void au_hn_destroy_cache(void)
15932 + struct au_cache *cp;
15934 + flush_delayed_work(&au_dfree.dwork);
15935 + cp = au_dfree.cache + AuCache_HNOTIFY;
15936 + AuDebugOn(!llist_empty(&cp->llist));
15937 + kmem_cache_destroy(cp->cache);
15938 + cp->cache = NULL;
15941 +AU_CACHE_DFREE_FUNC(hnotify, HNOTIFY, hn_lnode);
15943 +int __init au_hnotify_init(void)
15946 + struct au_cache *cp;
15949 + cp = au_dfree.cache + AuCache_HNOTIFY;
15950 + cp->cache = AuCache(au_hnotify);
15953 + if (au_hnotify_op.init)
15954 + err = au_hnotify_op.init();
15955 + if (unlikely(err))
15956 + au_hn_destroy_cache();
15962 +void au_hnotify_fin(void)
15964 + struct au_cache *cp;
15966 + if (au_hnotify_op.fin)
15967 + au_hnotify_op.fin();
15969 + /* cf. au_cache_fin() */
15970 + cp = au_dfree.cache + AuCache_HNOTIFY;
15972 + au_hn_destroy_cache();
15974 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15975 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15976 +++ linux/fs/aufs/iinfo.c 2017-05-06 22:16:52.778220093 +0200
15979 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15981 + * This program, aufs is free software; you can redistribute it and/or modify
15982 + * it under the terms of the GNU General Public License as published by
15983 + * the Free Software Foundation; either version 2 of the License, or
15984 + * (at your option) any later version.
15986 + * This program is distributed in the hope that it will be useful,
15987 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15988 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15989 + * GNU General Public License for more details.
15991 + * You should have received a copy of the GNU General Public License
15992 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15996 + * inode private data
16001 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
16003 + struct inode *h_inode;
16004 + struct au_hinode *hinode;
16006 + IiMustAnyLock(inode);
16008 + hinode = au_hinode(au_ii(inode), bindex);
16009 + h_inode = hinode->hi_inode;
16010 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16014 +/* todo: hard/soft set? */
16015 +void au_hiput(struct au_hinode *hinode)
16017 + au_hn_free(hinode);
16018 + dput(hinode->hi_whdentry);
16019 + iput(hinode->hi_inode);
16022 +unsigned int au_hi_flags(struct inode *inode, int isdir)
16024 + unsigned int flags;
16025 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
16028 + if (au_opt_test(mnt_flags, XINO))
16029 + au_fset_hi(flags, XINO);
16030 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
16031 + au_fset_hi(flags, HNOTIFY);
16035 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16036 + struct inode *h_inode, unsigned int flags)
16038 + struct au_hinode *hinode;
16039 + struct inode *hi;
16040 + struct au_iinfo *iinfo = au_ii(inode);
16042 + IiMustWriteLock(inode);
16044 + hinode = au_hinode(iinfo, bindex);
16045 + hi = hinode->hi_inode;
16046 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16049 + au_hiput(hinode);
16050 + hinode->hi_inode = h_inode;
16053 + struct super_block *sb = inode->i_sb;
16054 + struct au_branch *br;
16056 + AuDebugOn(inode->i_mode
16057 + && (h_inode->i_mode & S_IFMT)
16058 + != (inode->i_mode & S_IFMT));
16059 + if (bindex == iinfo->ii_btop)
16060 + au_cpup_igen(inode, h_inode);
16061 + br = au_sbr(sb, bindex);
16062 + hinode->hi_id = br->br_id;
16063 + if (au_ftest_hi(flags, XINO)) {
16064 + err = au_xino_write(sb, bindex, h_inode->i_ino,
16066 + if (unlikely(err))
16067 + AuIOErr1("failed au_xino_write() %d\n", err);
16070 + if (au_ftest_hi(flags, HNOTIFY)
16071 + && au_br_hnotifyable(br->br_perm)) {
16072 + err = au_hn_alloc(hinode, inode);
16073 + if (unlikely(err))
16074 + AuIOErr1("au_hn_alloc() %d\n", err);
16079 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16080 + struct dentry *h_wh)
16082 + struct au_hinode *hinode;
16084 + IiMustWriteLock(inode);
16086 + hinode = au_hinode(au_ii(inode), bindex);
16087 + AuDebugOn(hinode->hi_whdentry);
16088 + hinode->hi_whdentry = h_wh;
16091 +void au_update_iigen(struct inode *inode, int half)
16093 + struct au_iinfo *iinfo;
16094 + struct au_iigen *iigen;
16095 + unsigned int sigen;
16097 + sigen = au_sigen(inode->i_sb);
16098 + iinfo = au_ii(inode);
16099 + iigen = &iinfo->ii_generation;
16100 + spin_lock(&iigen->ig_spin);
16101 + iigen->ig_generation = sigen;
16103 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
16105 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
16106 + spin_unlock(&iigen->ig_spin);
16109 +/* it may be called at remount time, too */
16110 +void au_update_ibrange(struct inode *inode, int do_put_zero)
16112 + struct au_iinfo *iinfo;
16113 + aufs_bindex_t bindex, bbot;
16115 + AuDebugOn(au_is_bad_inode(inode));
16116 + IiMustWriteLock(inode);
16118 + iinfo = au_ii(inode);
16119 + if (do_put_zero && iinfo->ii_btop >= 0) {
16120 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16122 + struct inode *h_i;
16124 + h_i = au_hinode(iinfo, bindex)->hi_inode;
16127 + && !(h_i->i_state & I_LINKABLE))
16128 + au_set_h_iptr(inode, bindex, NULL, 0);
16132 + iinfo->ii_btop = -1;
16133 + iinfo->ii_bbot = -1;
16134 + bbot = au_sbbot(inode->i_sb);
16135 + for (bindex = 0; bindex <= bbot; bindex++)
16136 + if (au_hinode(iinfo, bindex)->hi_inode) {
16137 + iinfo->ii_btop = bindex;
16140 + if (iinfo->ii_btop >= 0)
16141 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
16142 + if (au_hinode(iinfo, bindex)->hi_inode) {
16143 + iinfo->ii_bbot = bindex;
16146 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
16149 +/* ---------------------------------------------------------------------- */
16151 +void au_icntnr_init_once(void *_c)
16153 + struct au_icntnr *c = _c;
16154 + struct au_iinfo *iinfo = &c->iinfo;
16156 + spin_lock_init(&iinfo->ii_generation.ig_spin);
16157 + au_rw_init(&iinfo->ii_rwsem);
16158 + inode_init_once(&c->vfs_inode);
16161 +void au_hinode_init(struct au_hinode *hinode)
16163 + hinode->hi_inode = NULL;
16164 + hinode->hi_id = -1;
16165 + au_hn_init(hinode);
16166 + hinode->hi_whdentry = NULL;
16169 +int au_iinfo_init(struct inode *inode)
16171 + struct au_iinfo *iinfo;
16172 + struct super_block *sb;
16173 + struct au_hinode *hi;
16176 + sb = inode->i_sb;
16177 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16178 + nbr = au_sbbot(sb) + 1;
16179 + if (unlikely(nbr <= 0))
16181 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
16183 + au_ninodes_inc(sb);
16185 + iinfo->ii_hinode = hi;
16186 + for (i = 0; i < nbr; i++, hi++)
16187 + au_hinode_init(hi);
16189 + iinfo->ii_generation.ig_generation = au_sigen(sb);
16190 + iinfo->ii_btop = -1;
16191 + iinfo->ii_bbot = -1;
16192 + iinfo->ii_vdir = NULL;
16198 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16201 + struct au_hinode *hip;
16203 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16206 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16209 + iinfo->ii_hinode = hip;
16210 + i = iinfo->ii_bbot + 1;
16212 + for (; i < nbr; i++, hip++)
16213 + au_hinode_init(hip);
16220 +void au_iinfo_fin(struct inode *inode)
16222 + struct au_iinfo *iinfo;
16223 + struct au_hinode *hi;
16224 + struct super_block *sb;
16225 + aufs_bindex_t bindex, bbot;
16226 + const unsigned char unlinked = !inode->i_nlink;
16228 + AuDebugOn(au_is_bad_inode(inode));
16230 + sb = inode->i_sb;
16231 + au_ninodes_dec(sb);
16232 + if (si_pid_test(sb))
16233 + au_xino_delete_inode(inode, unlinked);
16236 + * it is safe to hide the dependency between sbinfo and
16240 + si_noflush_read_lock(sb);
16241 + au_xino_delete_inode(inode, unlinked);
16242 + si_read_unlock(sb);
16246 + iinfo = au_ii(inode);
16247 + if (iinfo->ii_vdir)
16248 + au_vdir_free(iinfo->ii_vdir, /*atonce*/0);
16250 + bindex = iinfo->ii_btop;
16251 + if (bindex >= 0) {
16252 + hi = au_hinode(iinfo, bindex);
16253 + bbot = iinfo->ii_bbot;
16254 + while (bindex++ <= bbot) {
16255 + if (hi->hi_inode)
16260 + au_delayed_kfree(iinfo->ii_hinode);
16261 + AuRwDestroy(&iinfo->ii_rwsem);
16263 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16264 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16265 +++ linux/fs/aufs/inode.c 2017-05-06 22:16:52.781553511 +0200
16268 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16270 + * This program, aufs is free software; you can redistribute it and/or modify
16271 + * it under the terms of the GNU General Public License as published by
16272 + * the Free Software Foundation; either version 2 of the License, or
16273 + * (at your option) any later version.
16275 + * This program is distributed in the hope that it will be useful,
16276 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16277 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16278 + * GNU General Public License for more details.
16280 + * You should have received a copy of the GNU General Public License
16281 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16285 + * inode functions
16290 +struct inode *au_igrab(struct inode *inode)
16293 + AuDebugOn(!atomic_read(&inode->i_count));
16299 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16301 + au_cpup_attr_all(inode, /*force*/0);
16302 + au_update_iigen(inode, /*half*/1);
16304 + inode->i_version++;
16307 +static int au_ii_refresh(struct inode *inode, int *update)
16311 + aufs_bindex_t bindex, new_bindex;
16312 + struct super_block *sb;
16313 + struct au_iinfo *iinfo;
16314 + struct au_hinode *p, *q, tmp;
16316 + AuDebugOn(au_is_bad_inode(inode));
16317 + IiMustWriteLock(inode);
16320 + sb = inode->i_sb;
16321 + nbr = au_sbbot(sb) + 1;
16322 + type = inode->i_mode & S_IFMT;
16323 + iinfo = au_ii(inode);
16324 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16325 + if (unlikely(err))
16328 + AuDebugOn(iinfo->ii_btop < 0);
16329 + p = au_hinode(iinfo, iinfo->ii_btop);
16330 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16332 + if (!p->hi_inode)
16335 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16336 + new_bindex = au_br_index(sb, p->hi_id);
16337 + if (new_bindex == bindex)
16340 + if (new_bindex < 0) {
16343 + p->hi_inode = NULL;
16347 + if (new_bindex < iinfo->ii_btop)
16348 + iinfo->ii_btop = new_bindex;
16349 + if (iinfo->ii_bbot < new_bindex)
16350 + iinfo->ii_bbot = new_bindex;
16351 + /* swap two lower inode, and loop again */
16352 + q = au_hinode(iinfo, new_bindex);
16356 + if (tmp.hi_inode) {
16361 + au_update_ibrange(inode, /*do_put_zero*/0);
16362 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16363 + e = au_dy_irefresh(inode);
16364 + if (unlikely(e && !err))
16372 +void au_refresh_iop(struct inode *inode, int force_getattr)
16375 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16376 + const struct inode_operations *iop
16377 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16379 + if (inode->i_op == iop)
16382 + switch (inode->i_mode & S_IFMT) {
16384 + type = AuIop_DIR;
16387 + type = AuIop_SYMLINK;
16390 + type = AuIop_OTHER;
16394 + inode->i_op = iop + type;
16395 + /* unnecessary smp_wmb() */
16398 +int au_refresh_hinode_self(struct inode *inode)
16402 + err = au_ii_refresh(inode, &update);
16404 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16410 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16412 + int err, e, update;
16413 + unsigned int flags;
16415 + aufs_bindex_t bindex, bbot;
16416 + unsigned char isdir;
16417 + struct au_hinode *p;
16418 + struct au_iinfo *iinfo;
16420 + err = au_ii_refresh(inode, &update);
16421 + if (unlikely(err))
16425 + iinfo = au_ii(inode);
16426 + p = au_hinode(iinfo, iinfo->ii_btop);
16427 + mode = (inode->i_mode & S_IFMT);
16428 + isdir = S_ISDIR(mode);
16429 + flags = au_hi_flags(inode, isdir);
16430 + bbot = au_dbbot(dentry);
16431 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16432 + struct inode *h_i, *h_inode;
16433 + struct dentry *h_d;
16435 + h_d = au_h_dptr(dentry, bindex);
16436 + if (!h_d || d_is_negative(h_d))
16439 + h_inode = d_inode(h_d);
16440 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16441 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16442 + h_i = au_h_iptr(inode, bindex);
16444 + if (h_i == h_inode)
16450 + if (bindex < iinfo->ii_btop)
16451 + iinfo->ii_btop = bindex;
16452 + if (iinfo->ii_bbot < bindex)
16453 + iinfo->ii_bbot = bindex;
16454 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16457 + au_update_ibrange(inode, /*do_put_zero*/0);
16458 + e = au_dy_irefresh(inode);
16459 + if (unlikely(e && !err))
16462 + au_refresh_hinode_attr(inode, update && isdir);
16469 +static int set_inode(struct inode *inode, struct dentry *dentry)
16472 + unsigned int flags;
16474 + aufs_bindex_t bindex, btop, btail;
16475 + unsigned char isdir;
16476 + struct dentry *h_dentry;
16477 + struct inode *h_inode;
16478 + struct au_iinfo *iinfo;
16479 + struct inode_operations *iop;
16481 + IiMustWriteLock(inode);
16485 + iop = au_sbi(inode->i_sb)->si_iop_array;
16486 + btop = au_dbtop(dentry);
16487 + h_dentry = au_h_dptr(dentry, btop);
16488 + h_inode = d_inode(h_dentry);
16489 + mode = h_inode->i_mode;
16490 + switch (mode & S_IFMT) {
16492 + btail = au_dbtail(dentry);
16493 + inode->i_op = iop + AuIop_OTHER;
16494 + inode->i_fop = &aufs_file_fop;
16495 + err = au_dy_iaop(inode, btop, h_inode);
16496 + if (unlikely(err))
16501 + btail = au_dbtaildir(dentry);
16502 + inode->i_op = iop + AuIop_DIR;
16503 + inode->i_fop = &aufs_dir_fop;
16506 + btail = au_dbtail(dentry);
16507 + inode->i_op = iop + AuIop_SYMLINK;
16513 + btail = au_dbtail(dentry);
16514 + inode->i_op = iop + AuIop_OTHER;
16515 + init_special_inode(inode, mode, h_inode->i_rdev);
16518 + AuIOErr("Unknown file type 0%o\n", mode);
16523 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16524 + flags = au_hi_flags(inode, isdir);
16525 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16526 + && au_ftest_hi(flags, HNOTIFY)
16527 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16528 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16529 + au_fclr_hi(flags, HNOTIFY);
16530 + iinfo = au_ii(inode);
16531 + iinfo->ii_btop = btop;
16532 + iinfo->ii_bbot = btail;
16533 + for (bindex = btop; bindex <= btail; bindex++) {
16534 + h_dentry = au_h_dptr(dentry, bindex);
16536 + au_set_h_iptr(inode, bindex,
16537 + au_igrab(d_inode(h_dentry)), flags);
16539 + au_cpup_attr_all(inode, /*force*/1);
16541 + * to force calling aufs_get_acl() every time,
16542 + * do not call cache_no_acl() for aufs inode.
16550 + * successful returns with iinfo write_locked
16552 + * zero: success, matched
16553 + * plus: no error, but unmatched
16555 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16558 + unsigned int gen, igflags;
16559 + aufs_bindex_t bindex, bbot;
16560 + struct inode *h_inode, *h_dinode;
16561 + struct dentry *h_dentry;
16564 + * before this function, if aufs got any iinfo lock, it must be only
16565 + * one, the parent dir.
16566 + * it can happen by UDBA and the obsoleted inode number.
16569 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16573 + ii_write_lock_new_child(inode);
16574 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16575 + h_dinode = d_inode(h_dentry);
16576 + bbot = au_ibbot(inode);
16577 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16578 + h_inode = au_h_iptr(inode, bindex);
16579 + if (!h_inode || h_inode != h_dinode)
16583 + gen = au_iigen(inode, &igflags);
16584 + if (gen == au_digen(dentry)
16585 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16588 + /* fully refresh inode using dentry */
16589 + err = au_refresh_hinode(inode, dentry);
16591 + au_update_iigen(inode, /*half*/0);
16595 + if (unlikely(err))
16596 + ii_write_unlock(inode);
16601 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16602 + unsigned int d_type, ino_t *ino)
16605 + const int isnondir = d_type != DT_DIR;
16607 + /* prevent hardlinked inode number from race condition */
16609 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
16610 + if (unlikely(err))
16614 + err = au_xino_read(sb, bindex, h_ino, ino);
16615 + if (unlikely(err))
16616 + goto out_xinondir;
16620 + *ino = au_xino_new_ino(sb);
16621 + if (unlikely(!*ino))
16622 + goto out_xinondir;
16623 + err = au_xino_write(sb, bindex, h_ino, *ino);
16624 + if (unlikely(err))
16625 + goto out_xinondir;
16629 + if (isnondir && idx >= 0)
16630 + au_xinondir_leave(sb, bindex, h_ino, idx);
16635 +/* successful returns with iinfo write_locked */
16636 +/* todo: return with unlocked? */
16637 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16639 + struct inode *inode, *h_inode;
16640 + struct dentry *h_dentry;
16641 + struct super_block *sb;
16642 + ino_t h_ino, ino;
16643 + int err, idx, hlinked;
16644 + aufs_bindex_t btop;
16646 + sb = dentry->d_sb;
16647 + btop = au_dbtop(dentry);
16648 + h_dentry = au_h_dptr(dentry, btop);
16649 + h_inode = d_inode(h_dentry);
16650 + h_ino = h_inode->i_ino;
16651 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
16655 + * stop 'race'-ing between hardlinks under different
16659 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16660 + inode = ERR_PTR(err);
16661 + if (unlikely(err))
16665 + err = au_xino_read(sb, btop, h_ino, &ino);
16666 + inode = ERR_PTR(err);
16667 + if (unlikely(err))
16668 + goto out_xinondir;
16671 + ino = au_xino_new_ino(sb);
16672 + if (unlikely(!ino)) {
16673 + inode = ERR_PTR(-EIO);
16674 + goto out_xinondir;
16678 + AuDbg("i%lu\n", (unsigned long)ino);
16679 + inode = au_iget_locked(sb, ino);
16680 + err = PTR_ERR(inode);
16681 + if (IS_ERR(inode))
16682 + goto out_xinondir;
16684 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16685 + if (inode->i_state & I_NEW) {
16686 + ii_write_lock_new_child(inode);
16687 + err = set_inode(inode, dentry);
16689 + unlock_new_inode(inode);
16690 + goto out_xinondir; /* success */
16694 + * iget_failed() calls iput(), but we need to call
16695 + * ii_write_unlock() after iget_failed(). so dirty hack for
16698 + atomic_inc(&inode->i_count);
16699 + iget_failed(inode);
16700 + ii_write_unlock(inode);
16701 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16702 + /* ignore this error */
16704 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16706 + * horrible race condition between lookup, readdir and copyup
16707 + * (or something).
16709 + if (hlinked && idx >= 0)
16710 + au_xinondir_leave(sb, btop, h_ino, idx);
16711 + err = reval_inode(inode, dentry);
16712 + if (unlikely(err < 0)) {
16717 + goto out; /* success */
16718 + else if (hlinked && idx >= 0) {
16719 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16720 + if (unlikely(err)) {
16722 + inode = ERR_PTR(err);
16728 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16729 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16730 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16731 + btop, au_sbtype(h_dentry->d_sb), dentry,
16732 + (unsigned long)h_ino, (unsigned long)ino);
16734 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16737 + if (hlinked && idx >= 0)
16738 + au_xinondir_leave(sb, btop, h_ino, idx);
16744 + inode = ERR_PTR(err);
16746 + if (hlinked && idx >= 0)
16747 + au_xinondir_leave(sb, btop, h_ino, idx);
16752 +/* ---------------------------------------------------------------------- */
16754 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16755 + struct inode *inode)
16758 + struct inode *hi;
16760 + err = au_br_rdonly(au_sbr(sb, bindex));
16762 + /* pseudo-link after flushed may happen out of bounds */
16765 + && au_ibtop(inode) <= bindex
16766 + && bindex <= au_ibbot(inode)) {
16768 + * permission check is unnecessary since vfsub routine
16769 + * will be called later
16771 + hi = au_h_iptr(inode, bindex);
16773 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16779 +int au_test_h_perm(struct inode *h_inode, int mask)
16781 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16783 + return inode_permission(h_inode, mask);
16786 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16788 + if (au_test_nfs(h_inode->i_sb)
16789 + && (mask & MAY_WRITE)
16790 + && S_ISDIR(h_inode->i_mode))
16791 + mask |= MAY_READ; /* force permission check */
16792 + return au_test_h_perm(h_inode, mask);
16794 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16795 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16796 +++ linux/fs/aufs/inode.h 2017-05-06 22:16:52.781553511 +0200
16799 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16801 + * This program, aufs is free software; you can redistribute it and/or modify
16802 + * it under the terms of the GNU General Public License as published by
16803 + * the Free Software Foundation; either version 2 of the License, or
16804 + * (at your option) any later version.
16806 + * This program is distributed in the hope that it will be useful,
16807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16809 + * GNU General Public License for more details.
16811 + * You should have received a copy of the GNU General Public License
16812 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16816 + * inode operations
16819 +#ifndef __AUFS_INODE_H__
16820 +#define __AUFS_INODE_H__
16824 +#include <linux/fsnotify.h>
16825 +#include "rwsem.h"
16829 +struct au_hnotify {
16830 +#ifdef CONFIG_AUFS_HNOTIFY
16831 +#ifdef CONFIG_AUFS_HFSNOTIFY
16832 + /* never use fsnotify_add_vfsmount_mark() */
16833 + struct fsnotify_mark hn_mark;
16836 + struct inode *hn_aufs_inode; /* no get/put */
16837 + struct llist_node hn_lnode; /* delayed free */
16840 +} ____cacheline_aligned_in_smp;
16842 +struct au_hinode {
16843 + struct inode *hi_inode;
16844 + aufs_bindex_t hi_id;
16845 +#ifdef CONFIG_AUFS_HNOTIFY
16846 + struct au_hnotify *hi_notify;
16849 + /* reference to the copied-up whiteout with get/put */
16850 + struct dentry *hi_whdentry;
16854 +#define AuIG_HALF_REFRESHED 1
16855 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16856 +#define au_ig_fset(flags, name) \
16857 + do { (flags) |= AuIG_##name; } while (0)
16858 +#define au_ig_fclr(flags, name) \
16859 + do { (flags) &= ~AuIG_##name; } while (0)
16862 + spinlock_t ig_spin;
16863 + __u32 ig_generation, ig_flags;
16868 + struct au_iigen ii_generation;
16869 + struct super_block *ii_hsb1; /* no get/put */
16871 + struct au_rwsem ii_rwsem;
16872 + aufs_bindex_t ii_btop, ii_bbot;
16874 + struct au_hinode *ii_hinode;
16875 + struct au_vdir *ii_vdir;
16878 +struct au_icntnr {
16879 + struct au_iinfo iinfo;
16880 + struct inode vfs_inode;
16882 + struct hlist_node plink;
16883 + struct llist_node lnode; /* delayed free */
16885 +} ____cacheline_aligned_in_smp;
16887 +/* au_pin flags */
16888 +#define AuPin_DI_LOCKED 1
16889 +#define AuPin_MNT_WRITE (1 << 1)
16890 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16891 +#define au_fset_pin(flags, name) \
16892 + do { (flags) |= AuPin_##name; } while (0)
16893 +#define au_fclr_pin(flags, name) \
16894 + do { (flags) &= ~AuPin_##name; } while (0)
16898 + struct dentry *dentry;
16899 + unsigned int udba;
16900 + unsigned char lsc_di, lsc_hi, flags;
16901 + aufs_bindex_t bindex;
16904 + struct dentry *parent;
16905 + struct au_hinode *hdir;
16906 + struct vfsmount *h_mnt;
16908 + /* temporary unlock/relock for copyup */
16909 + struct dentry *h_dentry, *h_parent;
16910 + struct au_branch *br;
16911 + struct task_struct *task;
16914 +void au_pin_hdir_unlock(struct au_pin *p);
16915 +int au_pin_hdir_lock(struct au_pin *p);
16916 +int au_pin_hdir_relock(struct au_pin *p);
16917 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16918 +void au_pin_hdir_release(struct au_pin *p);
16920 +/* ---------------------------------------------------------------------- */
16922 +static inline struct au_iinfo *au_ii(struct inode *inode)
16924 + BUG_ON(is_bad_inode(inode));
16925 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16928 +/* ---------------------------------------------------------------------- */
16931 +struct inode *au_igrab(struct inode *inode);
16932 +void au_refresh_iop(struct inode *inode, int force_getattr);
16933 +int au_refresh_hinode_self(struct inode *inode);
16934 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16935 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16936 + unsigned int d_type, ino_t *ino);
16937 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16938 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16939 + struct inode *inode);
16940 +int au_test_h_perm(struct inode *h_inode, int mask);
16941 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16943 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16944 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16946 +#ifdef CONFIG_AUFS_SHWH
16947 + return au_ino(sb, bindex, h_ino, d_type, ino);
16960 +extern struct inode_operations aufs_iop[AuIop_Last],
16961 + aufs_iop_nogetattr[AuIop_Last];
16963 +/* au_wr_dir flags */
16964 +#define AuWrDir_ADD_ENTRY 1
16965 +#define AuWrDir_ISDIR (1 << 1)
16966 +#define AuWrDir_TMPFILE (1 << 2)
16967 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16968 +#define au_fset_wrdir(flags, name) \
16969 + do { (flags) |= AuWrDir_##name; } while (0)
16970 +#define au_fclr_wrdir(flags, name) \
16971 + do { (flags) &= ~AuWrDir_##name; } while (0)
16973 +struct au_wr_dir_args {
16974 + aufs_bindex_t force_btgt;
16975 + unsigned char flags;
16977 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16978 + struct au_wr_dir_args *args);
16980 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16981 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16982 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16983 + unsigned int udba, unsigned char flags);
16984 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16985 + unsigned int udba, unsigned char flags) __must_check;
16986 +int au_do_pin(struct au_pin *pin) __must_check;
16987 +void au_unpin(struct au_pin *pin);
16988 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16990 +#define AuIcpup_DID_CPUP 1
16991 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16992 +#define au_fset_icpup(flags, name) \
16993 + do { (flags) |= AuIcpup_##name; } while (0)
16994 +#define au_fclr_icpup(flags, name) \
16995 + do { (flags) &= ~AuIcpup_##name; } while (0)
16997 +struct au_icpup_args {
16998 + unsigned char flags;
16999 + unsigned char pin_flags;
17000 + aufs_bindex_t btgt;
17001 + unsigned int udba;
17002 + struct au_pin pin;
17003 + struct path h_path;
17004 + struct inode *h_inode;
17007 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17008 + struct au_icpup_args *a);
17010 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
17014 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17015 + struct dentry *h_parent, int isdir);
17016 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17018 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
17019 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17021 +struct vfsub_aopen_args;
17022 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17023 + struct vfsub_aopen_args *args);
17024 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
17025 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17026 + struct dentry *dentry);
17027 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
17030 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
17031 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17032 + struct dentry *h_parent, int isdir);
17033 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
17034 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
17037 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
17038 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
17039 + struct inode *dir, struct dentry *dentry,
17040 + unsigned int flags);
17043 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
17044 +void au_hiput(struct au_hinode *hinode);
17045 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17046 + struct dentry *h_wh);
17047 +unsigned int au_hi_flags(struct inode *inode, int isdir);
17049 +/* hinode flags */
17050 +#define AuHi_XINO 1
17051 +#define AuHi_HNOTIFY (1 << 1)
17052 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
17053 +#define au_fset_hi(flags, name) \
17054 + do { (flags) |= AuHi_##name; } while (0)
17055 +#define au_fclr_hi(flags, name) \
17056 + do { (flags) &= ~AuHi_##name; } while (0)
17058 +#ifndef CONFIG_AUFS_HNOTIFY
17059 +#undef AuHi_HNOTIFY
17060 +#define AuHi_HNOTIFY 0
17063 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17064 + struct inode *h_inode, unsigned int flags);
17066 +void au_update_iigen(struct inode *inode, int half);
17067 +void au_update_ibrange(struct inode *inode, int do_put_zero);
17069 +void au_icntnr_init_once(void *_c);
17070 +void au_hinode_init(struct au_hinode *hinode);
17071 +int au_iinfo_init(struct inode *inode);
17072 +void au_iinfo_fin(struct inode *inode);
17073 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
17075 +#ifdef CONFIG_PROC_FS
17077 +int au_plink_maint(struct super_block *sb, int flags);
17079 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
17080 +int au_plink_maint_enter(struct super_block *sb);
17081 +#ifdef CONFIG_AUFS_DEBUG
17082 +void au_plink_list(struct super_block *sb);
17084 +AuStubVoid(au_plink_list, struct super_block *sb)
17086 +int au_plink_test(struct inode *inode);
17087 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
17088 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
17089 + struct dentry *h_dentry);
17090 +void au_plink_put(struct super_block *sb, int verbose);
17091 +void au_plink_clean(struct super_block *sb, int verbose);
17092 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
17094 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
17095 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
17096 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
17097 +AuStubVoid(au_plink_list, struct super_block *sb);
17098 +AuStubInt0(au_plink_test, struct inode *inode);
17099 +AuStub(struct dentry *, au_plink_lkup, return NULL,
17100 + struct inode *inode, aufs_bindex_t bindex);
17101 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
17102 + struct dentry *h_dentry);
17103 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
17104 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
17105 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
17106 +#endif /* CONFIG_PROC_FS */
17108 +#ifdef CONFIG_AUFS_XATTR
17110 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
17111 + unsigned int verbose);
17112 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
17113 +void au_xattr_init(struct super_block *sb);
17115 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
17116 + int ignore_flags, unsigned int verbose);
17117 +AuStubVoid(au_xattr_init, struct super_block *sb);
17120 +#ifdef CONFIG_FS_POSIX_ACL
17121 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
17122 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
17125 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
17131 +struct au_sxattr {
17135 + const char *name;
17136 + const void *value;
17141 + struct posix_acl *acl;
17146 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
17147 + struct au_sxattr *arg);
17150 +/* ---------------------------------------------------------------------- */
17152 +/* lock subclass for iinfo */
17154 + AuLsc_II_CHILD, /* child first */
17155 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
17156 + AuLsc_II_CHILD3, /* copyup dirs */
17157 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
17158 + AuLsc_II_PARENT2,
17159 + AuLsc_II_PARENT3, /* copyup dirs */
17160 + AuLsc_II_NEW_CHILD
17164 + * ii_read_lock_child, ii_write_lock_child,
17165 + * ii_read_lock_child2, ii_write_lock_child2,
17166 + * ii_read_lock_child3, ii_write_lock_child3,
17167 + * ii_read_lock_parent, ii_write_lock_parent,
17168 + * ii_read_lock_parent2, ii_write_lock_parent2,
17169 + * ii_read_lock_parent3, ii_write_lock_parent3,
17170 + * ii_read_lock_new_child, ii_write_lock_new_child,
17172 +#define AuReadLockFunc(name, lsc) \
17173 +static inline void ii_read_lock_##name(struct inode *i) \
17175 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17178 +#define AuWriteLockFunc(name, lsc) \
17179 +static inline void ii_write_lock_##name(struct inode *i) \
17181 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17184 +#define AuRWLockFuncs(name, lsc) \
17185 + AuReadLockFunc(name, lsc) \
17186 + AuWriteLockFunc(name, lsc)
17188 +AuRWLockFuncs(child, CHILD);
17189 +AuRWLockFuncs(child2, CHILD2);
17190 +AuRWLockFuncs(child3, CHILD3);
17191 +AuRWLockFuncs(parent, PARENT);
17192 +AuRWLockFuncs(parent2, PARENT2);
17193 +AuRWLockFuncs(parent3, PARENT3);
17194 +AuRWLockFuncs(new_child, NEW_CHILD);
17196 +#undef AuReadLockFunc
17197 +#undef AuWriteLockFunc
17198 +#undef AuRWLockFuncs
17201 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17203 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17205 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17206 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17207 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17209 +/* ---------------------------------------------------------------------- */
17211 +static inline void au_icntnr_init(struct au_icntnr *c)
17213 +#ifdef CONFIG_AUFS_DEBUG
17214 + c->vfs_inode.i_mode = 0;
17218 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17220 + unsigned int gen;
17221 + struct au_iinfo *iinfo;
17222 + struct au_iigen *iigen;
17224 + iinfo = au_ii(inode);
17225 + iigen = &iinfo->ii_generation;
17226 + spin_lock(&iigen->ig_spin);
17228 + *igflags = iigen->ig_flags;
17229 + gen = iigen->ig_generation;
17230 + spin_unlock(&iigen->ig_spin);
17235 +/* tiny test for inode number */
17236 +/* tmpfs generation is too rough */
17237 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17239 + struct au_iinfo *iinfo;
17241 + iinfo = au_ii(inode);
17242 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17243 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17244 + && iinfo->ii_higen == h_inode->i_generation);
17247 +static inline void au_iigen_dec(struct inode *inode)
17249 + struct au_iinfo *iinfo;
17250 + struct au_iigen *iigen;
17252 + iinfo = au_ii(inode);
17253 + iigen = &iinfo->ii_generation;
17254 + spin_lock(&iigen->ig_spin);
17255 + iigen->ig_generation--;
17256 + spin_unlock(&iigen->ig_spin);
17259 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17264 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17270 +/* ---------------------------------------------------------------------- */
17272 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17273 + aufs_bindex_t bindex)
17275 + return iinfo->ii_hinode + bindex;
17278 +static inline int au_is_bad_inode(struct inode *inode)
17280 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17283 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17284 + aufs_bindex_t bindex)
17286 + IiMustAnyLock(inode);
17287 + return au_hinode(au_ii(inode), bindex)->hi_id;
17290 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17292 + IiMustAnyLock(inode);
17293 + return au_ii(inode)->ii_btop;
17296 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17298 + IiMustAnyLock(inode);
17299 + return au_ii(inode)->ii_bbot;
17302 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17304 + IiMustAnyLock(inode);
17305 + return au_ii(inode)->ii_vdir;
17308 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17310 + IiMustAnyLock(inode);
17311 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17314 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17316 + IiMustWriteLock(inode);
17317 + au_ii(inode)->ii_btop = bindex;
17320 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17322 + IiMustWriteLock(inode);
17323 + au_ii(inode)->ii_bbot = bindex;
17326 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17328 + IiMustWriteLock(inode);
17329 + au_ii(inode)->ii_vdir = vdir;
17332 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17334 + IiMustAnyLock(inode);
17335 + return au_hinode(au_ii(inode), bindex);
17338 +/* ---------------------------------------------------------------------- */
17340 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17343 + return pin->parent;
17347 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17349 + if (pin && pin->hdir)
17350 + return pin->hdir->hi_inode;
17354 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17357 + return pin->hdir;
17361 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17364 + pin->dentry = dentry;
17367 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17368 + unsigned char lflag)
17372 + au_fset_pin(pin->flags, DI_LOCKED);
17374 + au_fclr_pin(pin->flags, DI_LOCKED);
17378 +#if 0 /* reserved */
17379 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17382 + dput(pin->parent);
17383 + pin->parent = dget(parent);
17388 +/* ---------------------------------------------------------------------- */
17391 +#ifdef CONFIG_AUFS_HNOTIFY
17392 +struct au_hnotify_op {
17393 + void (*ctl)(struct au_hinode *hinode, int do_set);
17394 + int (*alloc)(struct au_hinode *hinode);
17397 + * if it returns true, the the caller should free hinode->hi_notify,
17398 + * otherwise ->free() frees it.
17400 + int (*free)(struct au_hinode *hinode,
17401 + struct au_hnotify *hn) __must_check;
17403 + void (*fin)(void);
17404 + int (*init)(void);
17406 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17407 + void (*fin_br)(struct au_branch *br);
17408 + int (*init_br)(struct au_branch *br, int perm);
17412 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17413 +void au_hn_free(struct au_hinode *hinode);
17414 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17415 +void au_hn_reset(struct inode *inode, unsigned int flags);
17416 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17417 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17418 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17419 +int au_hnotify_init_br(struct au_branch *br, int perm);
17420 +void au_hnotify_fin_br(struct au_branch *br);
17421 +int __init au_hnotify_init(void);
17422 +void au_hnotify_fin(void);
17425 +extern const struct au_hnotify_op au_hnotify_op;
17428 +void au_hn_init(struct au_hinode *hinode)
17430 + hinode->hi_notify = NULL;
17433 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17435 + return hinode->hi_notify;
17439 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17440 + struct au_hinode *hinode __maybe_unused,
17441 + struct inode *inode __maybe_unused)
17442 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17443 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17444 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17445 + int do_set __maybe_unused)
17446 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17447 + unsigned int flags __maybe_unused)
17448 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17449 + struct au_branch *br __maybe_unused,
17450 + int perm __maybe_unused)
17451 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17452 + int perm __maybe_unused)
17453 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17454 +AuStubInt0(__init au_hnotify_init, void)
17455 +AuStubVoid(au_hnotify_fin, void)
17456 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17457 +#endif /* CONFIG_AUFS_HNOTIFY */
17459 +static inline void au_hn_suspend(struct au_hinode *hdir)
17461 + au_hn_ctl(hdir, /*do_set*/0);
17464 +static inline void au_hn_resume(struct au_hinode *hdir)
17466 + au_hn_ctl(hdir, /*do_set*/1);
17469 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17471 + inode_lock(hdir->hi_inode);
17472 + au_hn_suspend(hdir);
17475 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17476 + unsigned int sc __maybe_unused)
17478 + inode_lock_nested(hdir->hi_inode, sc);
17479 + au_hn_suspend(hdir);
17482 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17484 + au_hn_resume(hdir);
17485 + inode_unlock(hdir->hi_inode);
17488 +#endif /* __KERNEL__ */
17489 +#endif /* __AUFS_INODE_H__ */
17490 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17491 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17492 +++ linux/fs/aufs/ioctl.c 2017-05-06 22:16:52.781553511 +0200
17495 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17497 + * This program, aufs is free software; you can redistribute it and/or modify
17498 + * it under the terms of the GNU General Public License as published by
17499 + * the Free Software Foundation; either version 2 of the License, or
17500 + * (at your option) any later version.
17502 + * This program is distributed in the hope that it will be useful,
17503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17505 + * GNU General Public License for more details.
17507 + * You should have received a copy of the GNU General Public License
17508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17513 + * plink-management and readdir in userspace.
17514 + * assist the pathconf(3) wrapper library.
17516 + * File-based Hierarchical Storage Management.
17519 +#include <linux/compat.h>
17520 +#include <linux/file.h>
17523 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17526 + aufs_bindex_t wbi, bindex, bbot;
17527 + struct file *h_file;
17528 + struct super_block *sb;
17529 + struct dentry *root;
17530 + struct au_branch *br;
17531 + struct aufs_wbr_fd wbrfd = {
17532 + .oflags = au_dir_roflags,
17535 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17536 + | O_NOATIME | O_CLOEXEC;
17538 + AuDebugOn(wbrfd.oflags & ~valid);
17541 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17542 + if (unlikely(err)) {
17548 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17549 + wbrfd.oflags |= au_dir_roflags;
17550 + AuDbg("0%o\n", wbrfd.oflags);
17551 + if (unlikely(wbrfd.oflags & ~valid))
17555 + fd = get_unused_fd_flags(0);
17557 + if (unlikely(fd < 0))
17560 + h_file = ERR_PTR(-EINVAL);
17563 + sb = path->dentry->d_sb;
17564 + root = sb->s_root;
17565 + aufs_read_lock(root, AuLock_IR);
17566 + bbot = au_sbbot(sb);
17567 + if (wbrfd.brid >= 0) {
17568 + wbi = au_br_index(sb, wbrfd.brid);
17569 + if (unlikely(wbi < 0 || wbi > bbot))
17573 + h_file = ERR_PTR(-ENOENT);
17574 + br = au_sbr(sb, wbi);
17575 + if (!au_br_writable(br->br_perm)) {
17579 + bindex = wbi + 1;
17581 + for (; bindex <= bbot; bindex++) {
17582 + br = au_sbr(sb, bindex);
17583 + if (au_br_writable(br->br_perm)) {
17585 + br = au_sbr(sb, wbi);
17590 + AuDbg("wbi %d\n", wbi);
17592 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17596 + aufs_read_unlock(root, AuLock_IR);
17597 + err = PTR_ERR(h_file);
17598 + if (IS_ERR(h_file))
17601 + au_br_put(br); /* cf. au_h_open() */
17602 + fd_install(fd, h_file);
17604 + goto out; /* success */
17607 + put_unused_fd(fd);
17613 +/* ---------------------------------------------------------------------- */
17615 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17618 + struct dentry *dentry;
17621 + case AUFS_CTL_RDU:
17622 + case AUFS_CTL_RDU_INO:
17623 + err = au_rdu_ioctl(file, cmd, arg);
17626 + case AUFS_CTL_WBR_FD:
17627 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17630 + case AUFS_CTL_IBUSY:
17631 + err = au_ibusy_ioctl(file, arg);
17634 + case AUFS_CTL_BRINFO:
17635 + err = au_brinfo_ioctl(file, arg);
17638 + case AUFS_CTL_FHSM_FD:
17639 + dentry = file->f_path.dentry;
17640 + if (IS_ROOT(dentry))
17641 + err = au_fhsm_fd(dentry->d_sb, arg);
17647 + /* do not call the lower */
17648 + AuDbg("0x%x\n", cmd);
17656 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17661 + case AUFS_CTL_MVDOWN:
17662 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17665 + case AUFS_CTL_WBR_FD:
17666 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17670 + /* do not call the lower */
17671 + AuDbg("0x%x\n", cmd);
17679 +#ifdef CONFIG_COMPAT
17680 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17681 + unsigned long arg)
17686 + case AUFS_CTL_RDU:
17687 + case AUFS_CTL_RDU_INO:
17688 + err = au_rdu_compat_ioctl(file, cmd, arg);
17691 + case AUFS_CTL_IBUSY:
17692 + err = au_ibusy_compat_ioctl(file, arg);
17695 + case AUFS_CTL_BRINFO:
17696 + err = au_brinfo_compat_ioctl(file, arg);
17700 + err = aufs_ioctl_dir(file, cmd, arg);
17707 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17708 + unsigned long arg)
17710 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17713 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17714 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17715 +++ linux/fs/aufs/i_op_add.c 2017-05-06 22:16:52.778220093 +0200
17718 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17720 + * This program, aufs is free software; you can redistribute it and/or modify
17721 + * it under the terms of the GNU General Public License as published by
17722 + * the Free Software Foundation; either version 2 of the License, or
17723 + * (at your option) any later version.
17725 + * This program is distributed in the hope that it will be useful,
17726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17728 + * GNU General Public License for more details.
17730 + * You should have received a copy of the GNU General Public License
17731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17735 + * inode operations (add entry)
17741 + * final procedure of adding a new entry, except link(2).
17742 + * remove whiteout, instantiate, copyup the parent dir's times and size
17743 + * and update version.
17744 + * if it failed, re-create the removed whiteout.
17746 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17747 + struct dentry *wh_dentry, struct dentry *dentry)
17750 + aufs_bindex_t bwh;
17751 + struct path h_path;
17752 + struct super_block *sb;
17753 + struct inode *inode, *h_dir;
17754 + struct dentry *wh;
17759 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17760 + IMustLock(h_dir);
17761 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17762 + bwh = au_dbwh(dentry);
17763 + h_path.dentry = wh_dentry;
17764 + h_path.mnt = au_sbr_mnt(sb, bindex);
17765 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17767 + if (unlikely(err))
17771 + inode = au_new_inode(dentry, /*must_new*/1);
17772 + if (!IS_ERR(inode)) {
17773 + d_instantiate(dentry, inode);
17774 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17776 + au_dir_ts(dir, bindex);
17777 + dir->i_version++;
17778 + au_fhsm_wrote(sb, bindex, /*force*/0);
17779 + return 0; /* success */
17782 + err = PTR_ERR(inode);
17787 + /* dir inode is locked */
17788 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17789 + rerr = PTR_ERR(wh);
17790 + if (IS_ERR(wh)) {
17791 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17792 + dentry, err, rerr);
17801 +static int au_d_may_add(struct dentry *dentry)
17806 + if (unlikely(d_unhashed(dentry)))
17808 + if (unlikely(d_really_is_positive(dentry)))
17814 + * simple tests for the adding inode operations.
17815 + * following the checks in vfs, plus the parent-child relationship.
17817 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17818 + struct dentry *h_parent, int isdir)
17822 + struct dentry *h_dentry;
17823 + struct inode *h_inode;
17825 + err = -ENAMETOOLONG;
17826 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17829 + h_dentry = au_h_dptr(dentry, bindex);
17830 + if (d_really_is_negative(dentry)) {
17832 + if (unlikely(d_is_positive(h_dentry)))
17835 + /* rename(2) case */
17837 + if (unlikely(d_is_negative(h_dentry)))
17839 + h_inode = d_inode(h_dentry);
17840 + if (unlikely(!h_inode->i_nlink))
17843 + h_mode = h_inode->i_mode;
17846 + if (unlikely(S_ISDIR(h_mode)))
17848 + } else if (unlikely(!S_ISDIR(h_mode))) {
17855 + /* expected parent dir is locked */
17856 + if (unlikely(h_parent != h_dentry->d_parent))
17865 + * initial procedure of adding a new entry.
17866 + * prepare writable branch and the parent dir, lock it,
17867 + * and lookup whiteout for the new entry.
17869 +static struct dentry*
17870 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17871 + struct dentry *src_dentry, struct au_pin *pin,
17872 + struct au_wr_dir_args *wr_dir_args)
17874 + struct dentry *wh_dentry, *h_parent;
17875 + struct super_block *sb;
17876 + struct au_branch *br;
17878 + unsigned int udba;
17879 + aufs_bindex_t bcpup;
17881 + AuDbg("%pd\n", dentry);
17883 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17885 + wh_dentry = ERR_PTR(err);
17886 + if (unlikely(err < 0))
17889 + sb = dentry->d_sb;
17890 + udba = au_opt_udba(sb);
17891 + err = au_pin(pin, dentry, bcpup, udba,
17892 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17893 + wh_dentry = ERR_PTR(err);
17894 + if (unlikely(err))
17897 + h_parent = au_pinned_h_parent(pin);
17898 + if (udba != AuOpt_UDBA_NONE
17899 + && au_dbtop(dentry) == bcpup)
17900 + err = au_may_add(dentry, bcpup, h_parent,
17901 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17902 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17903 + err = -ENAMETOOLONG;
17904 + wh_dentry = ERR_PTR(err);
17905 + if (unlikely(err))
17908 + br = au_sbr(sb, bcpup);
17910 + struct path tmp = {
17911 + .dentry = h_parent,
17912 + .mnt = au_br_mnt(br)
17914 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17917 + wh_dentry = NULL;
17918 + if (bcpup != au_dbwh(dentry))
17919 + goto out; /* success */
17922 + * ENAMETOOLONG here means that if we allowed create such name, then it
17923 + * would not be able to removed in the future. So we don't allow such
17924 + * name here and we don't handle ENAMETOOLONG differently here.
17926 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17929 + if (IS_ERR(wh_dentry))
17932 + return wh_dentry;
17935 +/* ---------------------------------------------------------------------- */
17937 +enum { Mknod, Symlink, Creat };
17938 +struct simple_arg {
17945 + struct vfsub_aopen_args *aopen;
17948 + const char *symname;
17957 +static int add_simple(struct inode *dir, struct dentry *dentry,
17958 + struct simple_arg *arg)
17961 + aufs_bindex_t btop;
17962 + unsigned char created;
17963 + const unsigned char try_aopen
17964 + = (arg->type == Creat && arg->u.c.try_aopen);
17965 + struct dentry *wh_dentry, *parent;
17966 + struct inode *h_dir;
17967 + struct super_block *sb;
17968 + struct au_branch *br;
17969 + /* to reuduce stack size */
17971 + struct au_dtime dt;
17972 + struct au_pin pin;
17973 + struct path h_path;
17974 + struct au_wr_dir_args wr_dir_args;
17977 + AuDbg("%pd\n", dentry);
17981 + a = kmalloc(sizeof(*a), GFP_NOFS);
17982 + if (unlikely(!a))
17984 + a->wr_dir_args.force_btgt = -1;
17985 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17987 + parent = dentry->d_parent; /* dir inode is locked */
17988 + if (!try_aopen) {
17989 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17990 + if (unlikely(err))
17993 + err = au_d_may_add(dentry);
17994 + if (unlikely(err))
17997 + di_write_lock_parent(parent);
17998 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17999 + &a->pin, &a->wr_dir_args);
18000 + err = PTR_ERR(wh_dentry);
18001 + if (IS_ERR(wh_dentry))
18004 + btop = au_dbtop(dentry);
18005 + sb = dentry->d_sb;
18006 + br = au_sbr(sb, btop);
18007 + a->h_path.dentry = au_h_dptr(dentry, btop);
18008 + a->h_path.mnt = au_br_mnt(br);
18009 + h_dir = au_pinned_h_dir(&a->pin);
18010 + switch (arg->type) {
18013 + if (!try_aopen || !h_dir->i_op->atomic_open)
18014 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
18015 + arg->u.c.want_excl);
18017 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
18018 + arg->u.c.aopen, br);
18021 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
18024 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
18032 + err = epilog(dir, btop, wh_dentry, dentry);
18035 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
18036 + /* no delegation since it is just created */
18037 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
18040 + AuIOErr("%pd revert failure(%d, %d)\n",
18041 + dentry, err, rerr);
18044 + au_dtime_revert(&a->dt);
18047 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
18048 + *arg->u.c.aopen->opened |= FILE_CREATED;
18050 + au_unpin(&a->pin);
18055 + di_write_unlock(parent);
18057 + if (unlikely(err)) {
18058 + au_update_dbtop(dentry);
18062 + aufs_read_unlock(dentry, AuLock_DW);
18064 + au_delayed_kfree(a);
18069 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18072 + struct simple_arg arg = {
18079 + return add_simple(dir, dentry, &arg);
18082 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
18084 + struct simple_arg arg = {
18086 + .u.s.symname = symname
18088 + return add_simple(dir, dentry, &arg);
18091 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18094 + struct simple_arg arg = {
18098 + .want_excl = want_excl
18101 + return add_simple(dir, dentry, &arg);
18104 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18105 + struct vfsub_aopen_args *aopen_args)
18107 + struct simple_arg arg = {
18110 + .mode = aopen_args->create_mode,
18111 + .want_excl = aopen_args->open_flag & O_EXCL,
18112 + .try_aopen = true,
18113 + .aopen = aopen_args
18116 + return add_simple(dir, dentry, &arg);
18119 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
18122 + aufs_bindex_t bindex;
18123 + struct super_block *sb;
18124 + struct dentry *parent, *h_parent, *h_dentry;
18125 + struct inode *h_dir, *inode;
18126 + struct vfsmount *h_mnt;
18127 + struct au_wr_dir_args wr_dir_args = {
18128 + .force_btgt = -1,
18129 + .flags = AuWrDir_TMPFILE
18132 + /* copy-up may happen */
18136 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18137 + if (unlikely(err))
18140 + err = au_di_init(dentry);
18141 + if (unlikely(err))
18145 + parent = d_find_any_alias(dir);
18146 + AuDebugOn(!parent);
18147 + di_write_lock_parent(parent);
18148 + if (unlikely(d_inode(parent) != dir))
18151 + err = au_digen_test(parent, au_sigen(sb));
18152 + if (unlikely(err))
18155 + bindex = au_dbtop(parent);
18156 + au_set_dbtop(dentry, bindex);
18157 + au_set_dbbot(dentry, bindex);
18158 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18160 + if (unlikely(err < 0))
18163 + err = -EOPNOTSUPP;
18164 + h_dir = au_h_iptr(dir, bindex);
18165 + if (unlikely(!h_dir->i_op->tmpfile))
18168 + h_mnt = au_sbr_mnt(sb, bindex);
18169 + err = vfsub_mnt_want_write(h_mnt);
18170 + if (unlikely(err))
18173 + h_parent = au_h_dptr(parent, bindex);
18174 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
18175 + if (IS_ERR(h_dentry)) {
18176 + err = PTR_ERR(h_dentry);
18180 + au_set_dbtop(dentry, bindex);
18181 + au_set_dbbot(dentry, bindex);
18182 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18183 + inode = au_new_inode(dentry, /*must_new*/1);
18184 + if (IS_ERR(inode)) {
18185 + err = PTR_ERR(inode);
18186 + au_set_h_dptr(dentry, bindex, NULL);
18187 + au_set_dbtop(dentry, -1);
18188 + au_set_dbbot(dentry, -1);
18190 + if (!inode->i_nlink)
18191 + set_nlink(inode, 1);
18192 + d_tmpfile(dentry, inode);
18193 + au_di(dentry)->di_tmpfile = 1;
18195 + /* update without i_mutex */
18196 + if (au_ibtop(dir) == au_dbtop(dentry))
18197 + au_cpup_attr_timesizes(dir);
18202 + vfsub_mnt_drop_write(h_mnt);
18204 + di_write_unlock(parent);
18206 + di_write_unlock(dentry);
18207 + if (unlikely(err)) {
18208 + au_di_fin(dentry);
18209 + dentry->d_fsdata = NULL;
18212 + si_read_unlock(sb);
18214 + inode_unlock(dir);
18218 +/* ---------------------------------------------------------------------- */
18220 +struct au_link_args {
18221 + aufs_bindex_t bdst, bsrc;
18222 + struct au_pin pin;
18223 + struct path h_path;
18224 + struct dentry *src_parent, *parent;
18227 +static int au_cpup_before_link(struct dentry *src_dentry,
18228 + struct au_link_args *a)
18231 + struct dentry *h_src_dentry;
18232 + struct au_cp_generic cpg = {
18233 + .dentry = src_dentry,
18238 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18241 + di_read_lock_parent(a->src_parent, AuLock_IR);
18242 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18243 + if (unlikely(err))
18246 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18247 + err = au_pin(&a->pin, src_dentry, a->bdst,
18248 + au_opt_udba(src_dentry->d_sb),
18249 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18250 + if (unlikely(err))
18253 + err = au_sio_cpup_simple(&cpg);
18254 + au_unpin(&a->pin);
18257 + di_read_unlock(a->src_parent, AuLock_IR);
18261 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18262 + struct au_link_args *a)
18265 + unsigned char plink;
18266 + aufs_bindex_t bbot;
18267 + struct dentry *h_src_dentry;
18268 + struct inode *h_inode, *inode, *delegated;
18269 + struct super_block *sb;
18270 + struct file *h_file;
18274 + sb = src_dentry->d_sb;
18275 + inode = d_inode(src_dentry);
18276 + if (au_ibtop(inode) <= a->bdst)
18277 + h_inode = au_h_iptr(inode, a->bdst);
18278 + if (!h_inode || !h_inode->i_nlink) {
18279 + /* copyup src_dentry as the name of dentry. */
18280 + bbot = au_dbbot(dentry);
18281 + if (bbot < a->bsrc)
18282 + au_set_dbbot(dentry, a->bsrc);
18283 + au_set_h_dptr(dentry, a->bsrc,
18284 + dget(au_h_dptr(src_dentry, a->bsrc)));
18285 + dget(a->h_path.dentry);
18286 + au_set_h_dptr(dentry, a->bdst, NULL);
18287 + AuDbg("temporary d_inode...\n");
18288 + spin_lock(&dentry->d_lock);
18289 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18290 + spin_unlock(&dentry->d_lock);
18291 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18292 + if (IS_ERR(h_file))
18293 + err = PTR_ERR(h_file);
18295 + struct au_cp_generic cpg = {
18296 + .dentry = dentry,
18301 + .flags = AuCpup_KEEPLINO
18303 + err = au_sio_cpup_simple(&cpg);
18304 + au_h_open_post(dentry, a->bsrc, h_file);
18306 + dput(a->h_path.dentry);
18307 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18309 + au_set_h_dptr(dentry, a->bdst,
18310 + a->h_path.dentry);
18312 + spin_lock(&dentry->d_lock);
18313 + dentry->d_inode = NULL; /* restore */
18314 + spin_unlock(&dentry->d_lock);
18315 + AuDbg("temporary d_inode...done\n");
18316 + au_set_h_dptr(dentry, a->bsrc, NULL);
18317 + au_set_dbbot(dentry, bbot);
18319 + /* the inode of src_dentry already exists on a.bdst branch */
18320 + h_src_dentry = d_find_alias(h_inode);
18321 + if (!h_src_dentry && au_plink_test(inode)) {
18323 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18324 + err = PTR_ERR(h_src_dentry);
18325 + if (IS_ERR(h_src_dentry))
18328 + if (unlikely(d_is_negative(h_src_dentry))) {
18329 + dput(h_src_dentry);
18330 + h_src_dentry = NULL;
18334 + if (h_src_dentry) {
18335 + delegated = NULL;
18336 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18337 + &a->h_path, &delegated);
18338 + if (unlikely(err == -EWOULDBLOCK)) {
18339 + pr_warn("cannot retry for NFSv4 delegation"
18340 + " for an internal link\n");
18343 + dput(h_src_dentry);
18345 + AuIOErr("no dentry found for hi%lu on b%d\n",
18346 + h_inode->i_ino, a->bdst);
18351 + if (!err && !plink)
18352 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18359 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18360 + struct dentry *dentry)
18363 + struct au_dtime dt;
18364 + struct au_link_args *a;
18365 + struct dentry *wh_dentry, *h_src_dentry;
18366 + struct inode *inode, *delegated;
18367 + struct super_block *sb;
18368 + struct au_wr_dir_args wr_dir_args = {
18369 + /* .force_btgt = -1, */
18370 + .flags = AuWrDir_ADD_ENTRY
18374 + inode = d_inode(src_dentry);
18375 + IMustLock(inode);
18378 + a = kzalloc(sizeof(*a), GFP_NOFS);
18379 + if (unlikely(!a))
18382 + a->parent = dentry->d_parent; /* dir inode is locked */
18383 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18384 + AuLock_NOPLM | AuLock_GEN);
18385 + if (unlikely(err))
18387 + err = au_d_linkable(src_dentry);
18388 + if (unlikely(err))
18390 + err = au_d_may_add(dentry);
18391 + if (unlikely(err))
18394 + a->src_parent = dget_parent(src_dentry);
18395 + wr_dir_args.force_btgt = au_ibtop(inode);
18397 + di_write_lock_parent(a->parent);
18398 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18399 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18401 + err = PTR_ERR(wh_dentry);
18402 + if (IS_ERR(wh_dentry))
18406 + sb = dentry->d_sb;
18407 + a->bdst = au_dbtop(dentry);
18408 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18409 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18410 + a->bsrc = au_ibtop(inode);
18411 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18412 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18413 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18414 + if (!h_src_dentry) {
18415 + a->bsrc = au_dbtop(src_dentry);
18416 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18417 + AuDebugOn(!h_src_dentry);
18418 + } else if (IS_ERR(h_src_dentry)) {
18419 + err = PTR_ERR(h_src_dentry);
18424 + * aufs doesn't touch the credential so
18425 + * security_dentry_create_files_as() is unnecrssary.
18427 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18428 + if (a->bdst < a->bsrc
18429 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18430 + err = au_cpup_or_link(src_dentry, dentry, a);
18432 + delegated = NULL;
18433 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18434 + &a->h_path, &delegated);
18435 + if (unlikely(err == -EWOULDBLOCK)) {
18436 + pr_warn("cannot retry for NFSv4 delegation"
18437 + " for an internal link\n");
18441 + dput(h_src_dentry);
18444 + * copyup src_dentry to the branch we process,
18445 + * and then link(2) to it.
18447 + dput(h_src_dentry);
18448 + if (a->bdst < a->bsrc
18449 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18450 + au_unpin(&a->pin);
18451 + di_write_unlock(a->parent);
18452 + err = au_cpup_before_link(src_dentry, a);
18453 + di_write_lock_parent(a->parent);
18455 + err = au_pin(&a->pin, dentry, a->bdst,
18457 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18458 + if (unlikely(err))
18462 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18464 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18465 + delegated = NULL;
18466 + err = vfsub_link(h_src_dentry,
18467 + au_pinned_h_dir(&a->pin),
18468 + &a->h_path, &delegated);
18469 + if (unlikely(err == -EWOULDBLOCK)) {
18470 + pr_warn("cannot retry"
18471 + " for NFSv4 delegation"
18472 + " for an internal link\n");
18478 + if (unlikely(err))
18482 + a->h_path.dentry = wh_dentry;
18483 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18485 + if (unlikely(err))
18489 + au_dir_ts(dir, a->bdst);
18490 + dir->i_version++;
18491 + inc_nlink(inode);
18492 + inode->i_ctime = dir->i_ctime;
18493 + d_instantiate(dentry, au_igrab(inode));
18494 + if (d_unhashed(a->h_path.dentry))
18495 + /* some filesystem calls d_drop() */
18497 + /* some filesystems consume an inode even hardlink */
18498 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18499 + goto out_unpin; /* success */
18502 + /* no delegation since it is just created */
18503 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18504 + /*delegated*/NULL, /*force*/0);
18505 + if (unlikely(rerr)) {
18506 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18509 + au_dtime_revert(&dt);
18511 + au_unpin(&a->pin);
18515 + di_write_unlock(a->parent);
18516 + dput(a->src_parent);
18518 + if (unlikely(err)) {
18519 + au_update_dbtop(dentry);
18522 + aufs_read_and_write_unlock2(dentry, src_dentry);
18524 + au_delayed_kfree(a);
18530 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18533 + aufs_bindex_t bindex;
18534 + unsigned char diropq;
18535 + struct path h_path;
18536 + struct dentry *wh_dentry, *parent, *opq_dentry;
18537 + struct inode *h_inode;
18538 + struct super_block *sb;
18540 + struct au_pin pin;
18541 + struct au_dtime dt;
18542 + } *a; /* reduce the stack usage */
18543 + struct au_wr_dir_args wr_dir_args = {
18544 + .force_btgt = -1,
18545 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18551 + a = kmalloc(sizeof(*a), GFP_NOFS);
18552 + if (unlikely(!a))
18555 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18556 + if (unlikely(err))
18558 + err = au_d_may_add(dentry);
18559 + if (unlikely(err))
18562 + parent = dentry->d_parent; /* dir inode is locked */
18563 + di_write_lock_parent(parent);
18564 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18565 + &a->pin, &wr_dir_args);
18566 + err = PTR_ERR(wh_dentry);
18567 + if (IS_ERR(wh_dentry))
18570 + sb = dentry->d_sb;
18571 + bindex = au_dbtop(dentry);
18572 + h_path.dentry = au_h_dptr(dentry, bindex);
18573 + h_path.mnt = au_sbr_mnt(sb, bindex);
18574 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18575 + if (unlikely(err))
18578 + /* make the dir opaque */
18580 + h_inode = d_inode(h_path.dentry);
18582 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18583 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18584 + opq_dentry = au_diropq_create(dentry, bindex);
18585 + inode_unlock(h_inode);
18586 + err = PTR_ERR(opq_dentry);
18587 + if (IS_ERR(opq_dentry))
18589 + dput(opq_dentry);
18593 + err = epilog(dir, bindex, wh_dentry, dentry);
18596 + goto out_unpin; /* success */
18601 + AuLabel(revert opq);
18602 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18603 + rerr = au_diropq_remove(dentry, bindex);
18604 + inode_unlock(h_inode);
18606 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18607 + dentry, err, rerr);
18613 + AuLabel(revert dir);
18614 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18616 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18617 + dentry, err, rerr);
18620 + au_dtime_revert(&a->dt);
18622 + au_unpin(&a->pin);
18625 + di_write_unlock(parent);
18627 + if (unlikely(err)) {
18628 + au_update_dbtop(dentry);
18631 + aufs_read_unlock(dentry, AuLock_DW);
18633 + au_delayed_kfree(a);
18637 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18638 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18639 +++ linux/fs/aufs/i_op.c 2017-05-06 22:16:52.778220093 +0200
18642 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18644 + * This program, aufs is free software; you can redistribute it and/or modify
18645 + * it under the terms of the GNU General Public License as published by
18646 + * the Free Software Foundation; either version 2 of the License, or
18647 + * (at your option) any later version.
18649 + * This program is distributed in the hope that it will be useful,
18650 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18651 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18652 + * GNU General Public License for more details.
18654 + * You should have received a copy of the GNU General Public License
18655 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18659 + * inode operations (except add/del/rename)
18662 +#include <linux/device_cgroup.h>
18663 +#include <linux/fs_stack.h>
18664 +#include <linux/namei.h>
18665 +#include <linux/security.h>
18668 +static int h_permission(struct inode *h_inode, int mask,
18669 + struct path *h_path, int brperm)
18672 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18675 + if (write_mask && IS_IMMUTABLE(h_inode))
18679 + if (((mask & MAY_EXEC)
18680 + && S_ISREG(h_inode->i_mode)
18681 + && (path_noexec(h_path)
18682 + || !(h_inode->i_mode & S_IXUGO))))
18686 + * - skip the lower fs test in the case of write to ro branch.
18687 + * - nfs dir permission write check is optimized, but a policy for
18688 + * link/rename requires a real check.
18689 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18690 + * in this case, generic_permission() returns -EOPNOTSUPP.
18692 + if ((write_mask && !au_br_writable(brperm))
18693 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18694 + && write_mask && !(mask & MAY_READ))
18695 + || !h_inode->i_op->permission) {
18696 + /* AuLabel(generic_permission); */
18697 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18698 + err = generic_permission(h_inode, mask);
18699 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18700 + err = h_inode->i_op->permission(h_inode, mask);
18703 + /* AuLabel(h_inode->permission); */
18704 + err = h_inode->i_op->permission(h_inode, mask);
18709 + err = devcgroup_inode_permission(h_inode, mask);
18711 + err = security_inode_permission(h_inode, mask);
18715 + /* todo: do we need to call ima_path_check()? */
18716 + struct path h_path = {
18720 + err = ima_path_check(&h_path,
18721 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18722 + IMA_COUNT_LEAVE);
18730 +static int aufs_permission(struct inode *inode, int mask)
18733 + aufs_bindex_t bindex, bbot;
18734 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18735 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18736 + struct inode *h_inode;
18737 + struct super_block *sb;
18738 + struct au_branch *br;
18740 + /* todo: support rcu-walk? */
18741 + if (mask & MAY_NOT_BLOCK)
18744 + sb = inode->i_sb;
18745 + si_read_lock(sb, AuLock_FLUSH);
18746 + ii_read_lock_child(inode);
18748 + err = au_iigen_test(inode, au_sigen(sb));
18749 + if (unlikely(err))
18755 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18756 + err = au_busy_or_stale();
18757 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18758 + if (unlikely(!h_inode
18759 + || (h_inode->i_mode & S_IFMT)
18760 + != (inode->i_mode & S_IFMT)))
18764 + bindex = au_ibtop(inode);
18765 + br = au_sbr(sb, bindex);
18766 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18769 + && !special_file(h_inode->i_mode)) {
18770 + /* test whether the upper writable branch exists */
18772 + for (; bindex >= 0; bindex--)
18773 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18781 + /* non-write to dir */
18783 + bbot = au_ibbot(inode);
18784 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18785 + h_inode = au_h_iptr(inode, bindex);
18787 + err = au_busy_or_stale();
18788 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18791 + br = au_sbr(sb, bindex);
18792 + err = h_permission(h_inode, mask, &br->br_path,
18798 + ii_read_unlock(inode);
18799 + si_read_unlock(sb);
18803 +/* ---------------------------------------------------------------------- */
18805 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18806 + unsigned int flags)
18808 + struct dentry *ret, *parent;
18809 + struct inode *inode;
18810 + struct super_block *sb;
18811 + int err, npositive;
18815 + /* todo: support rcu-walk? */
18816 + ret = ERR_PTR(-ECHILD);
18817 + if (flags & LOOKUP_RCU)
18820 + ret = ERR_PTR(-ENAMETOOLONG);
18821 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18825 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18826 + ret = ERR_PTR(err);
18827 + if (unlikely(err))
18830 + err = au_di_init(dentry);
18831 + ret = ERR_PTR(err);
18832 + if (unlikely(err))
18836 + npositive = 0; /* suppress a warning */
18837 + parent = dentry->d_parent; /* dir inode is locked */
18838 + di_read_lock_parent(parent, AuLock_IR);
18839 + err = au_alive_dir(parent);
18841 + err = au_digen_test(parent, au_sigen(sb));
18843 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18844 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18845 + AuLkup_ALLOW_NEG);
18848 + di_read_unlock(parent, AuLock_IR);
18849 + ret = ERR_PTR(err);
18850 + if (unlikely(err < 0))
18854 + inode = au_new_inode(dentry, /*must_new*/0);
18855 + if (IS_ERR(inode)) {
18856 + ret = (void *)inode;
18863 + atomic_inc(&inode->i_count);
18864 + ret = d_splice_alias(inode, dentry);
18866 + if (unlikely(d_need_lookup(dentry))) {
18867 + spin_lock(&dentry->d_lock);
18868 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18869 + spin_unlock(&dentry->d_lock);
18873 + if (!IS_ERR(ret)) {
18875 + if (ret && ret != dentry)
18876 + ii_write_unlock(inode);
18878 + ii_write_unlock(inode);
18885 + di_write_unlock(dentry);
18887 + si_read_unlock(sb);
18892 +/* ---------------------------------------------------------------------- */
18894 +struct aopen_node {
18895 + struct hlist_node hlist;
18896 + struct file *file, *h_file;
18899 +static int au_do_aopen(struct inode *inode, struct file *file)
18901 + struct au_sphlhead *aopen;
18902 + struct aopen_node *node;
18903 + struct au_do_open_args args = {
18905 + .open = au_do_open_nondir
18908 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18909 + spin_lock(&aopen->spin);
18910 + hlist_for_each_entry(node, &aopen->head, hlist)
18911 + if (node->file == file) {
18912 + args.h_file = node->h_file;
18915 + spin_unlock(&aopen->spin);
18916 + /* AuDebugOn(!args.h_file); */
18918 + return au_do_open(file, &args);
18921 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18922 + struct file *file, unsigned int open_flag,
18923 + umode_t create_mode, int *opened)
18925 + int err, h_opened = *opened;
18926 + unsigned int lkup_flags;
18927 + struct dentry *parent, *d;
18928 + struct au_sphlhead *aopen;
18929 + struct vfsub_aopen_args args = {
18930 + .open_flag = open_flag,
18931 + .create_mode = create_mode,
18932 + .opened = &h_opened
18934 + struct aopen_node aopen_node = {
18939 + AuDbg("open_flag 0%o\n", open_flag);
18940 + AuDbgDentry(dentry);
18943 + if (!au_di(dentry)) {
18944 + lkup_flags = LOOKUP_OPEN;
18945 + if (open_flag & O_CREAT)
18946 + lkup_flags |= LOOKUP_CREATE;
18947 + d = aufs_lookup(dir, dentry, lkup_flags);
18949 + err = PTR_ERR(d);
18954 + * obsoleted dentry found.
18955 + * another error will be returned later.
18961 + AuDbgDentry(dentry);
18964 + if (d_is_positive(dentry)
18965 + || d_unhashed(dentry)
18966 + || d_unlinked(dentry)
18967 + || !(open_flag & O_CREAT))
18968 + goto out_no_open;
18970 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18971 + if (unlikely(err))
18974 + parent = dentry->d_parent; /* dir is locked */
18975 + di_write_lock_parent(parent);
18976 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18977 + if (unlikely(err))
18980 + AuDbgDentry(dentry);
18981 + if (d_is_positive(dentry))
18984 + args.file = get_empty_filp();
18985 + err = PTR_ERR(args.file);
18986 + if (IS_ERR(args.file))
18989 + args.file->f_flags = file->f_flags;
18990 + err = au_aopen_or_create(dir, dentry, &args);
18992 + AuDbgFile(args.file);
18993 + if (unlikely(err < 0)) {
18994 + if (h_opened & FILE_OPENED)
18997 + put_filp(args.file);
19001 + /* some filesystems don't set FILE_CREATED while succeeded? */
19002 + *opened |= FILE_CREATED;
19003 + if (h_opened & FILE_OPENED)
19004 + aopen_node.h_file = args.file;
19006 + put_filp(args.file);
19007 + args.file = NULL;
19009 + aopen = &au_sbi(dir->i_sb)->si_aopen;
19010 + au_sphl_add(&aopen_node.hlist, aopen);
19011 + err = finish_open(file, dentry, au_do_aopen, opened);
19012 + au_sphl_del(&aopen_node.hlist, aopen);
19015 + if (aopen_node.h_file)
19016 + fput(aopen_node.h_file);
19019 + di_write_unlock(parent);
19020 + aufs_read_unlock(dentry, AuLock_DW);
19021 + AuDbgDentry(dentry);
19022 + if (unlikely(err < 0))
19025 + if (err >= 0 && !(*opened & FILE_CREATED)) {
19026 + AuLabel(out_no_open);
19028 + err = finish_no_open(file, dentry);
19031 + AuDbg("%pd%s%s\n", dentry,
19032 + (*opened & FILE_CREATED) ? " created" : "",
19033 + (*opened & FILE_OPENED) ? " opened" : "");
19039 +/* ---------------------------------------------------------------------- */
19041 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
19042 + const unsigned char add_entry, aufs_bindex_t bcpup,
19043 + aufs_bindex_t btop)
19046 + struct dentry *h_parent;
19047 + struct inode *h_dir;
19050 + IMustLock(d_inode(parent));
19052 + di_write_lock_parent(parent);
19055 + if (!au_h_dptr(parent, bcpup)) {
19056 + if (btop > bcpup)
19057 + err = au_cpup_dirs(dentry, bcpup);
19058 + else if (btop < bcpup)
19059 + err = au_cpdown_dirs(dentry, bcpup);
19063 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
19064 + h_parent = au_h_dptr(parent, bcpup);
19065 + h_dir = d_inode(h_parent);
19066 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
19067 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
19068 + /* todo: no unlock here */
19069 + inode_unlock(h_dir);
19071 + AuDbg("bcpup %d\n", bcpup);
19073 + if (d_really_is_negative(dentry))
19074 + au_set_h_dptr(dentry, btop, NULL);
19075 + au_update_dbrange(dentry, /*do_put_zero*/0);
19080 + di_write_unlock(parent);
19082 + err = bcpup; /* success */
19089 + * decide the branch and the parent dir where we will create a new entry.
19090 + * returns new bindex or an error.
19091 + * copyup the parent dir if needed.
19093 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19094 + struct au_wr_dir_args *args)
19097 + unsigned int flags;
19098 + aufs_bindex_t bcpup, btop, src_btop;
19099 + const unsigned char add_entry
19100 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
19101 + | au_ftest_wrdir(args->flags, TMPFILE);
19102 + struct super_block *sb;
19103 + struct dentry *parent;
19104 + struct au_sbinfo *sbinfo;
19106 + sb = dentry->d_sb;
19107 + sbinfo = au_sbi(sb);
19108 + parent = dget_parent(dentry);
19109 + btop = au_dbtop(dentry);
19111 + if (args->force_btgt < 0) {
19112 + if (src_dentry) {
19113 + src_btop = au_dbtop(src_dentry);
19114 + if (src_btop < btop)
19115 + bcpup = src_btop;
19116 + } else if (add_entry) {
19118 + if (au_ftest_wrdir(args->flags, ISDIR))
19119 + au_fset_wbr(flags, DIR);
19120 + err = AuWbrCreate(sbinfo, dentry, flags);
19124 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
19126 + err = AuWbrCopyup(sbinfo, dentry);
19128 + if (!IS_ROOT(dentry)) {
19129 + di_read_lock_parent(parent, !AuLock_IR);
19130 + err = AuWbrCopyup(sbinfo, dentry);
19131 + di_read_unlock(parent, !AuLock_IR);
19133 + err = AuWbrCopyup(sbinfo, dentry);
19136 + if (unlikely(err < 0))
19140 + bcpup = args->force_btgt;
19141 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
19144 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
19146 + if (bcpup == btop)
19147 + goto out; /* success */
19149 + /* copyup the new parent into the branch we process */
19150 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
19152 + if (d_really_is_negative(dentry)) {
19153 + au_set_h_dptr(dentry, btop, NULL);
19154 + au_set_dbtop(dentry, bcpup);
19155 + au_set_dbbot(dentry, bcpup);
19157 + AuDebugOn(add_entry
19158 + && !au_ftest_wrdir(args->flags, TMPFILE)
19159 + && !au_h_dptr(dentry, bcpup));
19167 +/* ---------------------------------------------------------------------- */
19169 +void au_pin_hdir_unlock(struct au_pin *p)
19172 + au_hn_inode_unlock(p->hdir);
19175 +int au_pin_hdir_lock(struct au_pin *p)
19183 + /* even if an error happens later, keep this lock */
19184 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19187 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19192 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19193 + p->h_parent, p->br);
19199 +int au_pin_hdir_relock(struct au_pin *p)
19202 + struct inode *h_i;
19203 + struct dentry *h_d[] = {
19208 + err = au_pin_hdir_lock(p);
19209 + if (unlikely(err))
19212 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19215 + if (d_is_positive(h_d[i])) {
19216 + h_i = d_inode(h_d[i]);
19217 + err = !h_i->i_nlink;
19225 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19227 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19228 + p->hdir->hi_inode->i_rwsem.owner = task;
19232 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19235 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19236 + p->lsc_hi, 0, NULL, _RET_IP_);
19237 + au_pin_hdir_set_owner(p, current);
19241 +void au_pin_hdir_release(struct au_pin *p)
19244 + au_pin_hdir_set_owner(p, p->task);
19245 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19249 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19251 + if (pin && pin->parent)
19252 + return au_h_dptr(pin->parent, pin->bindex);
19256 +void au_unpin(struct au_pin *p)
19259 + au_pin_hdir_unlock(p);
19260 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19261 + vfsub_mnt_drop_write(p->h_mnt);
19265 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19266 + di_read_unlock(p->parent, AuLock_IR);
19267 + iput(p->hdir->hi_inode);
19269 + p->parent = NULL;
19272 + /* do not clear p->task */
19275 +int au_do_pin(struct au_pin *p)
19278 + struct super_block *sb;
19279 + struct inode *h_dir;
19282 + sb = p->dentry->d_sb;
19283 + p->br = au_sbr(sb, p->bindex);
19284 + if (IS_ROOT(p->dentry)) {
19285 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19286 + p->h_mnt = au_br_mnt(p->br);
19287 + err = vfsub_mnt_want_write(p->h_mnt);
19288 + if (unlikely(err)) {
19289 + au_fclr_pin(p->flags, MNT_WRITE);
19296 + p->h_dentry = NULL;
19297 + if (p->bindex <= au_dbbot(p->dentry))
19298 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19300 + p->parent = dget_parent(p->dentry);
19301 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19302 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19305 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19306 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19308 + h_dir = p->hdir->hi_inode;
19312 + * if DI_LOCKED is not set, then p->parent may be different
19313 + * and h_parent can be NULL.
19315 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19317 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19318 + di_read_unlock(p->parent, AuLock_IR);
19320 + p->parent = NULL;
19324 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19325 + p->h_mnt = au_br_mnt(p->br);
19326 + err = vfsub_mnt_want_write(p->h_mnt);
19327 + if (unlikely(err)) {
19328 + au_fclr_pin(p->flags, MNT_WRITE);
19329 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19330 + di_read_unlock(p->parent, AuLock_IR);
19332 + p->parent = NULL;
19338 + err = au_pin_hdir_lock(p);
19340 + goto out; /* success */
19345 + pr_err("err %d\n", err);
19346 + err = au_busy_or_stale();
19351 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19352 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19353 + unsigned int udba, unsigned char flags)
19355 + p->dentry = dentry;
19357 + p->lsc_di = lsc_di;
19358 + p->lsc_hi = lsc_hi;
19359 + p->flags = flags;
19360 + p->bindex = bindex;
19362 + p->parent = NULL;
19366 + p->h_dentry = NULL;
19367 + p->h_parent = NULL;
19369 + p->task = current;
19372 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19373 + unsigned int udba, unsigned char flags)
19375 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19377 + return au_do_pin(pin);
19380 +/* ---------------------------------------------------------------------- */
19383 + * ->setattr() and ->getattr() are called in various cases.
19384 + * chmod, stat: dentry is revalidated.
19385 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19387 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19389 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19390 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19393 + struct dentry *parent;
19396 + if (au_digen_test(dentry, sigen)) {
19397 + parent = dget_parent(dentry);
19398 + di_read_lock_parent(parent, AuLock_IR);
19399 + err = au_refresh_dentry(dentry, parent);
19400 + di_read_unlock(parent, AuLock_IR);
19408 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19409 + struct au_icpup_args *a)
19413 + aufs_bindex_t btop, ibtop;
19414 + struct dentry *hi_wh, *parent;
19415 + struct inode *inode;
19416 + struct au_wr_dir_args wr_dir_args = {
19417 + .force_btgt = -1,
19421 + if (d_is_dir(dentry))
19422 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19423 + /* plink or hi_wh() case */
19424 + btop = au_dbtop(dentry);
19425 + inode = d_inode(dentry);
19426 + ibtop = au_ibtop(inode);
19427 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19428 + wr_dir_args.force_btgt = ibtop;
19429 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19430 + if (unlikely(err < 0))
19434 + au_fset_icpup(a->flags, DID_CPUP);
19437 + a->pin_flags = AuPin_MNT_WRITE;
19439 + if (!IS_ROOT(dentry)) {
19440 + au_fset_pin(a->pin_flags, DI_LOCKED);
19441 + parent = dget_parent(dentry);
19442 + di_write_lock_parent(parent);
19445 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19446 + if (unlikely(err))
19450 + a->h_path.dentry = au_h_dptr(dentry, btop);
19451 + a->h_inode = d_inode(a->h_path.dentry);
19452 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19453 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19454 + if (ia->ia_size < i_size_read(a->h_inode))
19455 + sz = ia->ia_size;
19456 + inode_unlock(a->h_inode);
19460 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19461 + hi_wh = au_hi_wh(inode, a->btgt);
19463 + struct au_cp_generic cpg = {
19464 + .dentry = dentry,
19470 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19471 + if (unlikely(err))
19473 + hi_wh = au_hi_wh(inode, a->btgt);
19474 + /* todo: revalidate hi_wh? */
19479 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19480 + di_downgrade_lock(parent, AuLock_IR);
19484 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19485 + goto out; /* success */
19487 + if (!d_unhashed(dentry)) {
19488 + struct au_cp_generic cpg = {
19489 + .dentry = dentry,
19494 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19496 + err = au_sio_cpup_simple(&cpg);
19498 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19499 + } else if (!hi_wh)
19500 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19502 + a->h_path.dentry = hi_wh; /* do not dget here */
19505 + a->h_inode = d_inode(a->h_path.dentry);
19507 + goto out; /* success */
19508 + au_unpin(&a->pin);
19511 + di_write_unlock(parent);
19516 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19520 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19523 + struct inode *inode, *delegated;
19524 + struct super_block *sb;
19525 + struct file *file;
19526 + struct au_icpup_args *a;
19528 + inode = d_inode(dentry);
19529 + IMustLock(inode);
19531 + err = setattr_prepare(dentry, ia);
19532 + if (unlikely(err))
19536 + a = kzalloc(sizeof(*a), GFP_NOFS);
19537 + if (unlikely(!a))
19540 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19541 + ia->ia_valid &= ~ATTR_MODE;
19544 + sb = dentry->d_sb;
19545 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19546 + if (unlikely(err))
19549 + if (ia->ia_valid & ATTR_FILE) {
19550 + /* currently ftruncate(2) only */
19551 + AuDebugOn(!d_is_reg(dentry));
19552 + file = ia->ia_file;
19553 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
19555 + if (unlikely(err))
19557 + ia->ia_file = au_hf_top(file);
19558 + a->udba = AuOpt_UDBA_NONE;
19560 + /* fchmod() doesn't pass ia_file */
19561 + a->udba = au_opt_udba(sb);
19562 + di_write_lock_child(dentry);
19563 + /* no d_unlinked(), to set UDBA_NONE for root */
19564 + if (d_unhashed(dentry))
19565 + a->udba = AuOpt_UDBA_NONE;
19566 + if (a->udba != AuOpt_UDBA_NONE) {
19567 + AuDebugOn(IS_ROOT(dentry));
19568 + err = au_reval_for_attr(dentry, au_sigen(sb));
19569 + if (unlikely(err))
19574 + err = au_pin_and_icpup(dentry, ia, a);
19575 + if (unlikely(err < 0))
19577 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19578 + ia->ia_file = NULL;
19579 + ia->ia_valid &= ~ATTR_FILE;
19582 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19583 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19584 + == (ATTR_MODE | ATTR_CTIME)) {
19585 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19586 + if (unlikely(err))
19588 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19589 + && (ia->ia_valid & ATTR_CTIME)) {
19590 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19591 + if (unlikely(err))
19595 + if (ia->ia_valid & ATTR_SIZE) {
19598 + if (ia->ia_size < i_size_read(inode))
19600 + truncate_setsize(inode, ia->ia_size);
19603 + if (ia->ia_valid & ATTR_FILE)
19605 + inode_unlock(a->h_inode);
19606 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19607 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19609 + delegated = NULL;
19611 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19613 + err = break_deleg_wait(&delegated);
19621 + * regardless aufs 'acl' option setting.
19622 + * why don't all acl-aware fs call this func from their ->setattr()?
19624 + if (!err && (ia->ia_valid & ATTR_MODE))
19625 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19627 + au_cpup_attr_changeable(inode);
19630 + inode_unlock(a->h_inode);
19631 + au_unpin(&a->pin);
19632 + if (unlikely(err))
19633 + au_update_dbtop(dentry);
19635 + di_write_unlock(dentry);
19637 + fi_write_unlock(file);
19638 + ia->ia_file = file;
19639 + ia->ia_valid |= ATTR_FILE;
19642 + si_read_unlock(sb);
19644 + au_delayed_kfree(a);
19650 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19651 +static int au_h_path_to_set_attr(struct dentry *dentry,
19652 + struct au_icpup_args *a, struct path *h_path)
19655 + struct super_block *sb;
19657 + sb = dentry->d_sb;
19658 + a->udba = au_opt_udba(sb);
19659 + /* no d_unlinked(), to set UDBA_NONE for root */
19660 + if (d_unhashed(dentry))
19661 + a->udba = AuOpt_UDBA_NONE;
19662 + if (a->udba != AuOpt_UDBA_NONE) {
19663 + AuDebugOn(IS_ROOT(dentry));
19664 + err = au_reval_for_attr(dentry, au_sigen(sb));
19665 + if (unlikely(err))
19668 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19669 + if (unlikely(err < 0))
19672 + h_path->dentry = a->h_path.dentry;
19673 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19679 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19680 + struct au_sxattr *arg)
19683 + struct path h_path;
19684 + struct super_block *sb;
19685 + struct au_icpup_args *a;
19686 + struct inode *h_inode;
19688 + IMustLock(inode);
19691 + a = kzalloc(sizeof(*a), GFP_NOFS);
19692 + if (unlikely(!a))
19695 + sb = dentry->d_sb;
19696 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19697 + if (unlikely(err))
19700 + h_path.dentry = NULL; /* silence gcc */
19701 + di_write_lock_child(dentry);
19702 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19703 + if (unlikely(err))
19706 + inode_unlock(a->h_inode);
19707 + switch (arg->type) {
19708 + case AU_XATTR_SET:
19709 + AuDebugOn(d_is_negative(h_path.dentry));
19710 + err = vfsub_setxattr(h_path.dentry,
19711 + arg->u.set.name, arg->u.set.value,
19712 + arg->u.set.size, arg->u.set.flags);
19715 + err = -EOPNOTSUPP;
19716 + h_inode = d_inode(h_path.dentry);
19717 + if (h_inode->i_op->set_acl)
19718 + /* this will call posix_acl_update_mode */
19719 + err = h_inode->i_op->set_acl(h_inode,
19720 + arg->u.acl_set.acl,
19721 + arg->u.acl_set.type);
19725 + au_cpup_attr_timesizes(inode);
19727 + au_unpin(&a->pin);
19728 + if (unlikely(err))
19729 + au_update_dbtop(dentry);
19732 + di_write_unlock(dentry);
19733 + si_read_unlock(sb);
19735 + au_delayed_kfree(a);
19742 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19743 + unsigned int nlink)
19747 + inode->i_mode = st->mode;
19748 + /* don't i_[ug]id_write() here */
19749 + inode->i_uid = st->uid;
19750 + inode->i_gid = st->gid;
19751 + inode->i_atime = st->atime;
19752 + inode->i_mtime = st->mtime;
19753 + inode->i_ctime = st->ctime;
19755 + au_cpup_attr_nlink(inode, /*force*/0);
19756 + if (S_ISDIR(inode->i_mode)) {
19757 + n = inode->i_nlink;
19760 + smp_mb(); /* for i_nlink */
19761 + /* 0 can happen */
19762 + set_nlink(inode, n);
19765 + spin_lock(&inode->i_lock);
19766 + inode->i_blocks = st->blocks;
19767 + i_size_write(inode, st->size);
19768 + spin_unlock(&inode->i_lock);
19772 + * common routine for aufs_getattr() and au_getxattr().
19773 + * returns zero or negative (an error).
19774 + * @dentry will be read-locked in success.
19776 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19780 + unsigned int mnt_flags, sigen;
19781 + unsigned char udba_none;
19782 + aufs_bindex_t bindex;
19783 + struct super_block *sb, *h_sb;
19784 + struct inode *inode;
19786 + h_path->mnt = NULL;
19787 + h_path->dentry = NULL;
19790 + sb = dentry->d_sb;
19791 + mnt_flags = au_mntflags(sb);
19792 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19794 + if (unlikely(locked))
19795 + goto body; /* skip locking dinfo */
19797 + /* support fstat(2) */
19798 + if (!d_unlinked(dentry) && !udba_none) {
19799 + sigen = au_sigen(sb);
19800 + err = au_digen_test(dentry, sigen);
19802 + di_read_lock_child(dentry, AuLock_IR);
19803 + err = au_dbrange_test(dentry);
19804 + if (unlikely(err)) {
19805 + di_read_unlock(dentry, AuLock_IR);
19809 + AuDebugOn(IS_ROOT(dentry));
19810 + di_write_lock_child(dentry);
19811 + err = au_dbrange_test(dentry);
19813 + err = au_reval_for_attr(dentry, sigen);
19815 + di_downgrade_lock(dentry, AuLock_IR);
19817 + di_write_unlock(dentry);
19822 + di_read_lock_child(dentry, AuLock_IR);
19825 + inode = d_inode(dentry);
19826 + bindex = au_ibtop(inode);
19827 + h_path->mnt = au_sbr_mnt(sb, bindex);
19828 + h_sb = h_path->mnt->mnt_sb;
19830 + && !au_test_fs_bad_iattr(h_sb)
19832 + goto out; /* success */
19834 + if (au_dbtop(dentry) == bindex)
19835 + h_path->dentry = au_h_dptr(dentry, bindex);
19836 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19837 + h_path->dentry = au_plink_lkup(inode, bindex);
19838 + if (IS_ERR(h_path->dentry))
19839 + /* pretending success */
19840 + h_path->dentry = NULL;
19842 + dput(h_path->dentry);
19849 +static int aufs_getattr(const struct path *path, struct kstat *st,
19850 + u32 request, unsigned int query)
19853 + unsigned char positive;
19854 + struct path h_path;
19855 + struct dentry *dentry;
19856 + struct inode *inode;
19857 + struct super_block *sb;
19859 + dentry = path->dentry;
19860 + inode = d_inode(dentry);
19861 + sb = dentry->d_sb;
19862 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19863 + if (unlikely(err))
19865 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
19866 + if (unlikely(err))
19868 + if (unlikely(!h_path.dentry))
19869 + /* illegally overlapped or something */
19870 + goto out_fill; /* pretending success */
19872 + positive = d_is_positive(h_path.dentry);
19874 + /* no vfsub version */
19875 + err = vfs_getattr(&h_path, st, request, query);
19878 + au_refresh_iattr(inode, st,
19879 + d_inode(h_path.dentry)->i_nlink);
19880 + goto out_fill; /* success */
19886 + generic_fillattr(inode, st);
19888 + di_read_unlock(dentry, AuLock_IR);
19890 + si_read_unlock(sb);
19896 +/* ---------------------------------------------------------------------- */
19898 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19899 + struct delayed_call *done)
19902 + struct dentry *h_dentry;
19903 + struct inode *h_inode;
19905 + aufs_bindex_t bindex;
19907 + ret = NULL; /* suppress a warning */
19912 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19913 + if (unlikely(err))
19916 + err = au_d_hashed_positive(dentry);
19917 + if (unlikely(err))
19921 + inode = d_inode(dentry);
19922 + bindex = au_ibtop(inode);
19923 + h_inode = au_h_iptr(inode, bindex);
19924 + if (unlikely(!h_inode->i_op->get_link))
19929 + if (au_dbtop(dentry) <= bindex) {
19930 + h_dentry = au_h_dptr(dentry, bindex);
19935 + h_dentry = d_find_any_alias(h_inode);
19936 + if (IS_ERR(h_dentry)) {
19937 + err = PTR_ERR(h_dentry);
19941 + if (unlikely(!h_dentry))
19945 + AuDbg("%pf\n", h_inode->i_op->get_link);
19946 + AuDbgDentry(h_dentry);
19947 + ret = vfs_get_link(h_dentry, done);
19950 + err = PTR_ERR(ret);
19953 + aufs_read_unlock(dentry, AuLock_IR);
19955 + if (unlikely(err))
19956 + ret = ERR_PTR(err);
19957 + AuTraceErrPtr(ret);
19961 +/* ---------------------------------------------------------------------- */
19963 +static int au_is_special(struct inode *inode)
19965 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19968 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19971 + aufs_bindex_t bindex;
19972 + struct super_block *sb;
19973 + struct inode *h_inode;
19974 + struct vfsmount *h_mnt;
19976 + sb = inode->i_sb;
19977 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19978 + "unexpected s_flags 0x%lx", sb->s_flags);
19980 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19982 + si_read_lock(sb, AuLock_FLUSH);
19983 + ii_write_lock_child(inode);
19987 + bindex = au_ibtop(inode);
19988 + h_inode = au_h_iptr(inode, bindex);
19989 + if (!au_test_ro(sb, bindex, inode)) {
19990 + h_mnt = au_sbr_mnt(sb, bindex);
19991 + err = vfsub_mnt_want_write(h_mnt);
19993 + err = vfsub_update_time(h_inode, ts, flags);
19994 + vfsub_mnt_drop_write(h_mnt);
19996 + } else if (au_is_special(h_inode)) {
19998 + * Never copy-up here.
19999 + * These special files may already be opened and used for
20000 + * communicating. If we copied it up, then the communication
20001 + * would be corrupted.
20003 + AuWarn1("timestamps for i%lu are ignored "
20004 + "since it is on readonly branch (hi%lu).\n",
20005 + inode->i_ino, h_inode->i_ino);
20006 + } else if (flags & ~S_ATIME) {
20008 + AuIOErr1("unexpected flags 0x%x\n", flags);
20014 + au_cpup_attr_timesizes(inode);
20015 + ii_write_unlock(inode);
20016 + si_read_unlock(sb);
20019 + if (!err && (flags & S_VERSION))
20020 + inode_inc_iversion(inode);
20025 +/* ---------------------------------------------------------------------- */
20027 +/* no getattr version will be set by module.c:aufs_init() */
20028 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
20030 + [AuIop_SYMLINK] = {
20031 + .permission = aufs_permission,
20032 +#ifdef CONFIG_FS_POSIX_ACL
20033 + .get_acl = aufs_get_acl,
20034 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
20037 + .setattr = aufs_setattr,
20038 + .getattr = aufs_getattr,
20040 +#ifdef CONFIG_AUFS_XATTR
20041 + .listxattr = aufs_listxattr,
20044 + .get_link = aufs_get_link,
20046 + /* .update_time = aufs_update_time */
20049 + .create = aufs_create,
20050 + .lookup = aufs_lookup,
20051 + .link = aufs_link,
20052 + .unlink = aufs_unlink,
20053 + .symlink = aufs_symlink,
20054 + .mkdir = aufs_mkdir,
20055 + .rmdir = aufs_rmdir,
20056 + .mknod = aufs_mknod,
20057 + .rename = aufs_rename,
20059 + .permission = aufs_permission,
20060 +#ifdef CONFIG_FS_POSIX_ACL
20061 + .get_acl = aufs_get_acl,
20062 + .set_acl = aufs_set_acl,
20065 + .setattr = aufs_setattr,
20066 + .getattr = aufs_getattr,
20068 +#ifdef CONFIG_AUFS_XATTR
20069 + .listxattr = aufs_listxattr,
20072 + .update_time = aufs_update_time,
20073 + .atomic_open = aufs_atomic_open,
20074 + .tmpfile = aufs_tmpfile
20076 + [AuIop_OTHER] = {
20077 + .permission = aufs_permission,
20078 +#ifdef CONFIG_FS_POSIX_ACL
20079 + .get_acl = aufs_get_acl,
20080 + .set_acl = aufs_set_acl,
20083 + .setattr = aufs_setattr,
20084 + .getattr = aufs_getattr,
20086 +#ifdef CONFIG_AUFS_XATTR
20087 + .listxattr = aufs_listxattr,
20090 + .update_time = aufs_update_time
20093 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
20094 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
20095 +++ linux/fs/aufs/i_op_del.c 2017-05-06 22:16:52.778220093 +0200
20098 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20100 + * This program, aufs is free software; you can redistribute it and/or modify
20101 + * it under the terms of the GNU General Public License as published by
20102 + * the Free Software Foundation; either version 2 of the License, or
20103 + * (at your option) any later version.
20105 + * This program is distributed in the hope that it will be useful,
20106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20108 + * GNU General Public License for more details.
20110 + * You should have received a copy of the GNU General Public License
20111 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20115 + * inode operations (del entry)
20121 + * decide if a new whiteout for @dentry is necessary or not.
20122 + * when it is necessary, prepare the parent dir for the upper branch whose
20123 + * branch index is @bcpup for creation. the actual creation of the whiteout will
20124 + * be done by caller.
20126 + * 0: wh is unnecessary
20127 + * plus: wh is necessary
20130 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
20132 + int need_wh, err;
20133 + aufs_bindex_t btop;
20134 + struct super_block *sb;
20136 + sb = dentry->d_sb;
20137 + btop = au_dbtop(dentry);
20138 + if (*bcpup < 0) {
20140 + if (au_test_ro(sb, btop, d_inode(dentry))) {
20141 + err = AuWbrCopyup(au_sbi(sb), dentry);
20143 + if (unlikely(err < 0))
20147 + AuDebugOn(btop < *bcpup
20148 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
20149 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
20151 + if (*bcpup != btop) {
20152 + err = au_cpup_dirs(dentry, *bcpup);
20153 + if (unlikely(err))
20157 + struct au_dinfo *dinfo, *tmp;
20159 + need_wh = -ENOMEM;
20160 + dinfo = au_di(dentry);
20161 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
20163 + au_di_cp(tmp, dinfo);
20164 + au_di_swap(tmp, dinfo);
20165 + /* returns the number of positive dentries */
20166 + need_wh = au_lkup_dentry(dentry, btop + 1,
20167 + /* AuLkup_IGNORE_PERM */ 0);
20168 + au_di_swap(tmp, dinfo);
20169 + au_rw_write_unlock(&tmp->di_rwsem);
20173 + AuDbg("need_wh %d\n", need_wh);
20181 + * simple tests for the del-entry operations.
20182 + * following the checks in vfs, plus the parent-child relationship.
20184 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20185 + struct dentry *h_parent, int isdir)
20189 + struct dentry *h_dentry, *h_latest;
20190 + struct inode *h_inode;
20192 + h_dentry = au_h_dptr(dentry, bindex);
20193 + if (d_really_is_positive(dentry)) {
20195 + if (unlikely(d_is_negative(h_dentry)))
20197 + h_inode = d_inode(h_dentry);
20198 + if (unlikely(!h_inode->i_nlink))
20201 + h_mode = h_inode->i_mode;
20204 + if (unlikely(S_ISDIR(h_mode)))
20206 + } else if (unlikely(!S_ISDIR(h_mode))) {
20211 + /* rename(2) case */
20213 + if (unlikely(d_is_positive(h_dentry)))
20218 + /* expected parent dir is locked */
20219 + if (unlikely(h_parent != h_dentry->d_parent))
20224 + * rmdir a dir may break the consistency on some filesystem.
20225 + * let's try heavy test.
20228 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20229 + && au_test_h_perm(d_inode(h_parent),
20230 + MAY_EXEC | MAY_WRITE)))
20233 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20235 + if (IS_ERR(h_latest))
20237 + if (h_latest == h_dentry)
20246 + * decide the branch where we operate for @dentry. the branch index will be set
20247 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20248 + * dir for reverting.
20249 + * when a new whiteout is necessary, create it.
20251 +static struct dentry*
20252 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20253 + struct au_dtime *dt, struct au_pin *pin)
20255 + struct dentry *wh_dentry;
20256 + struct super_block *sb;
20257 + struct path h_path;
20258 + int err, need_wh;
20259 + unsigned int udba;
20260 + aufs_bindex_t bcpup;
20262 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20263 + wh_dentry = ERR_PTR(need_wh);
20264 + if (unlikely(need_wh < 0))
20267 + sb = dentry->d_sb;
20268 + udba = au_opt_udba(sb);
20270 + err = au_pin(pin, dentry, bcpup, udba,
20271 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20272 + wh_dentry = ERR_PTR(err);
20273 + if (unlikely(err))
20276 + h_path.dentry = au_pinned_h_parent(pin);
20277 + if (udba != AuOpt_UDBA_NONE
20278 + && au_dbtop(dentry) == bcpup) {
20279 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20280 + wh_dentry = ERR_PTR(err);
20281 + if (unlikely(err))
20285 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20286 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20287 + wh_dentry = NULL;
20289 + goto out; /* success, no need to create whiteout */
20291 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20292 + if (IS_ERR(wh_dentry))
20295 + /* returns with the parent is locked and wh_dentry is dget-ed */
20296 + goto out; /* success */
20301 + return wh_dentry;
20305 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20306 + * in order to be revertible and save time for removing many child whiteouts
20308 + * returns 1 when there are too many child whiteout and caller should remove
20309 + * them asynchronously. returns 0 when the number of children is enough small to
20310 + * remove now or the branch fs is a remote fs.
20311 + * otherwise return an error.
20313 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20314 + struct au_nhash *whlist, struct inode *dir)
20316 + int rmdir_later, err, dirwh;
20317 + struct dentry *h_dentry;
20318 + struct super_block *sb;
20319 + struct inode *inode;
20321 + sb = dentry->d_sb;
20322 + SiMustAnyLock(sb);
20323 + h_dentry = au_h_dptr(dentry, bindex);
20324 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20325 + if (unlikely(err))
20328 + /* stop monitoring */
20329 + inode = d_inode(dentry);
20330 + au_hn_free(au_hi(inode, bindex));
20332 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20333 + dirwh = au_sbi(sb)->si_dirwh;
20334 + rmdir_later = (dirwh <= 1);
20335 + if (!rmdir_later)
20336 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20339 + return rmdir_later;
20342 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20343 + if (unlikely(err)) {
20344 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20345 + h_dentry, bindex, err);
20355 + * final procedure for deleting a entry.
20356 + * maintain dentry and iattr.
20358 +static void epilog(struct inode *dir, struct dentry *dentry,
20359 + aufs_bindex_t bindex)
20361 + struct inode *inode;
20363 + inode = d_inode(dentry);
20365 + inode->i_ctime = dir->i_ctime;
20367 + au_dir_ts(dir, bindex);
20368 + dir->i_version++;
20372 + * when an error happened, remove the created whiteout and revert everything.
20374 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20375 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20376 + struct dentry *dentry, struct au_dtime *dt)
20379 + struct path h_path = {
20380 + .dentry = wh_dentry,
20381 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20384 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20386 + au_set_dbwh(dentry, bwh);
20387 + au_dtime_revert(dt);
20391 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20395 +/* ---------------------------------------------------------------------- */
20397 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20400 + aufs_bindex_t bwh, bindex, btop;
20401 + struct inode *inode, *h_dir, *delegated;
20402 + struct dentry *parent, *wh_dentry;
20403 + /* to reuduce stack size */
20405 + struct au_dtime dt;
20406 + struct au_pin pin;
20407 + struct path h_path;
20413 + a = kmalloc(sizeof(*a), GFP_NOFS);
20414 + if (unlikely(!a))
20417 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20418 + if (unlikely(err))
20420 + err = au_d_hashed_positive(dentry);
20421 + if (unlikely(err))
20423 + inode = d_inode(dentry);
20424 + IMustLock(inode);
20426 + if (unlikely(d_is_dir(dentry)))
20427 + goto out_unlock; /* possible? */
20429 + btop = au_dbtop(dentry);
20430 + bwh = au_dbwh(dentry);
20432 + parent = dentry->d_parent; /* dir inode is locked */
20433 + di_write_lock_parent(parent);
20434 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20436 + err = PTR_ERR(wh_dentry);
20437 + if (IS_ERR(wh_dentry))
20440 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20441 + a->h_path.dentry = au_h_dptr(dentry, btop);
20442 + dget(a->h_path.dentry);
20443 + if (bindex == btop) {
20444 + h_dir = au_pinned_h_dir(&a->pin);
20445 + delegated = NULL;
20446 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20447 + if (unlikely(err == -EWOULDBLOCK)) {
20448 + pr_warn("cannot retry for NFSv4 delegation"
20449 + " for an internal unlink\n");
20453 + /* dir inode is locked */
20454 + h_dir = d_inode(wh_dentry->d_parent);
20455 + IMustLock(h_dir);
20460 + vfsub_drop_nlink(inode);
20461 + epilog(dir, dentry, bindex);
20463 + /* update target timestamps */
20464 + if (bindex == btop) {
20465 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20467 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20469 + /* todo: this timestamp may be reverted later */
20470 + inode->i_ctime = h_dir->i_ctime;
20471 + goto out_unpin; /* success */
20478 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20485 + au_unpin(&a->pin);
20487 + dput(a->h_path.dentry);
20489 + di_write_unlock(parent);
20491 + aufs_read_unlock(dentry, AuLock_DW);
20493 + au_delayed_kfree(a);
20498 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20500 + int err, rmdir_later;
20501 + aufs_bindex_t bwh, bindex, btop;
20502 + struct inode *inode;
20503 + struct dentry *parent, *wh_dentry, *h_dentry;
20504 + struct au_whtmp_rmdir *args;
20505 + /* to reuduce stack size */
20507 + struct au_dtime dt;
20508 + struct au_pin pin;
20514 + a = kmalloc(sizeof(*a), GFP_NOFS);
20515 + if (unlikely(!a))
20518 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20519 + if (unlikely(err))
20521 + err = au_alive_dir(dentry);
20522 + if (unlikely(err))
20524 + inode = d_inode(dentry);
20525 + IMustLock(inode);
20527 + if (unlikely(!d_is_dir(dentry)))
20528 + goto out_unlock; /* possible? */
20531 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20532 + if (unlikely(!args))
20535 + parent = dentry->d_parent; /* dir inode is locked */
20536 + di_write_lock_parent(parent);
20537 + err = au_test_empty(dentry, &args->whlist);
20538 + if (unlikely(err))
20541 + btop = au_dbtop(dentry);
20542 + bwh = au_dbwh(dentry);
20544 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20546 + err = PTR_ERR(wh_dentry);
20547 + if (IS_ERR(wh_dentry))
20550 + h_dentry = au_h_dptr(dentry, btop);
20553 + if (bindex == btop) {
20554 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20556 + rmdir_later = err;
20560 + /* stop monitoring */
20561 + au_hn_free(au_hi(inode, btop));
20563 + /* dir inode is locked */
20564 + IMustLock(d_inode(wh_dentry->d_parent));
20569 + vfsub_dead_dir(inode);
20570 + au_set_dbdiropq(dentry, -1);
20571 + epilog(dir, dentry, bindex);
20573 + if (rmdir_later) {
20574 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20578 + goto out_unpin; /* success */
20586 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20593 + au_unpin(&a->pin);
20597 + di_write_unlock(parent);
20599 + au_whtmp_rmdir_free(args);
20601 + aufs_read_unlock(dentry, AuLock_DW);
20603 + au_delayed_kfree(a);
20608 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20609 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20610 +++ linux/fs/aufs/i_op_ren.c 2017-05-06 22:16:52.778220093 +0200
20613 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20615 + * This program, aufs is free software; you can redistribute it and/or modify
20616 + * it under the terms of the GNU General Public License as published by
20617 + * the Free Software Foundation; either version 2 of the License, or
20618 + * (at your option) any later version.
20620 + * This program is distributed in the hope that it will be useful,
20621 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20622 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20623 + * GNU General Public License for more details.
20625 + * You should have received a copy of the GNU General Public License
20626 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20630 + * inode operation (rename entry)
20631 + * todo: this is crazy monster
20636 +enum { AuSRC, AuDST, AuSrcDst };
20637 +enum { AuPARENT, AuCHILD, AuParentChild };
20639 +#define AuRen_ISDIR_SRC 1
20640 +#define AuRen_ISDIR_DST (1 << 1)
20641 +#define AuRen_ISSAMEDIR (1 << 2)
20642 +#define AuRen_WHSRC (1 << 3)
20643 +#define AuRen_WHDST (1 << 4)
20644 +#define AuRen_MNT_WRITE (1 << 5)
20645 +#define AuRen_DT_DSTDIR (1 << 6)
20646 +#define AuRen_DIROPQ_SRC (1 << 7)
20647 +#define AuRen_DIROPQ_DST (1 << 8)
20648 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20649 +#define au_fset_ren(flags, name) \
20650 + do { (flags) |= AuRen_##name; } while (0)
20651 +#define au_fclr_ren(flags, name) \
20652 + do { (flags) &= ~AuRen_##name; } while (0)
20654 +struct au_ren_args {
20656 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20658 + struct inode *dir, *inode;
20659 + struct au_hinode *hdir, *hinode;
20660 + struct au_dtime dt[AuParentChild];
20661 + aufs_bindex_t btop, bdiropq;
20664 +#define src_dentry sd[AuSRC].dentry
20665 +#define src_dir sd[AuSRC].dir
20666 +#define src_inode sd[AuSRC].inode
20667 +#define src_h_dentry sd[AuSRC].h_dentry
20668 +#define src_parent sd[AuSRC].parent
20669 +#define src_h_parent sd[AuSRC].h_parent
20670 +#define src_wh_dentry sd[AuSRC].wh_dentry
20671 +#define src_hdir sd[AuSRC].hdir
20672 +#define src_hinode sd[AuSRC].hinode
20673 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20674 +#define src_dt sd[AuSRC].dt
20675 +#define src_btop sd[AuSRC].btop
20676 +#define src_bdiropq sd[AuSRC].bdiropq
20678 +#define dst_dentry sd[AuDST].dentry
20679 +#define dst_dir sd[AuDST].dir
20680 +#define dst_inode sd[AuDST].inode
20681 +#define dst_h_dentry sd[AuDST].h_dentry
20682 +#define dst_parent sd[AuDST].parent
20683 +#define dst_h_parent sd[AuDST].h_parent
20684 +#define dst_wh_dentry sd[AuDST].wh_dentry
20685 +#define dst_hdir sd[AuDST].hdir
20686 +#define dst_hinode sd[AuDST].hinode
20687 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20688 +#define dst_dt sd[AuDST].dt
20689 +#define dst_btop sd[AuDST].btop
20690 +#define dst_bdiropq sd[AuDST].bdiropq
20692 + struct dentry *h_trap;
20693 + struct au_branch *br;
20694 + struct path h_path;
20695 + struct au_nhash whlist;
20696 + aufs_bindex_t btgt, src_bwh;
20699 + unsigned short auren_flags;
20700 + unsigned char flags; /* syscall parameter */
20701 + unsigned char exchange;
20704 + struct au_whtmp_rmdir *thargs;
20705 + struct dentry *h_dst;
20708 +/* ---------------------------------------------------------------------- */
20711 + * functions for reverting.
20712 + * when an error happened in a single rename systemcall, we should revert
20713 + * everything as if nothing happened.
20714 + * we don't need to revert the copied-up/down the parent dir since they are
20718 +#define RevertFailure(fmt, ...) do { \
20719 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20720 + ##__VA_ARGS__, err, rerr); \
20724 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20727 + struct dentry *d;
20728 +#define src_or_dst(member) a->sd[idx].member
20730 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20731 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20732 + rerr = au_diropq_remove(d, a->btgt);
20733 + au_hn_inode_unlock(src_or_dst(hinode));
20734 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20736 + RevertFailure("remove diropq %pd", d);
20738 +#undef src_or_dst_
20741 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20743 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20744 + au_ren_do_rev_diropq(err, a, AuSRC);
20745 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20746 + au_ren_do_rev_diropq(err, a, AuDST);
20749 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20752 + struct inode *delegated;
20754 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20755 + a->src_h_parent);
20756 + rerr = PTR_ERR(a->h_path.dentry);
20757 + if (IS_ERR(a->h_path.dentry)) {
20758 + RevertFailure("lkup one %pd", a->src_dentry);
20762 + delegated = NULL;
20763 + rerr = vfsub_rename(a->dst_h_dir,
20764 + au_h_dptr(a->src_dentry, a->btgt),
20765 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20766 + if (unlikely(rerr == -EWOULDBLOCK)) {
20767 + pr_warn("cannot retry for NFSv4 delegation"
20768 + " for an internal rename\n");
20771 + d_drop(a->h_path.dentry);
20772 + dput(a->h_path.dentry);
20773 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20775 + RevertFailure("rename %pd", a->src_dentry);
20778 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20781 + struct inode *delegated;
20783 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20784 + a->dst_h_parent);
20785 + rerr = PTR_ERR(a->h_path.dentry);
20786 + if (IS_ERR(a->h_path.dentry)) {
20787 + RevertFailure("lkup one %pd", a->dst_dentry);
20790 + if (d_is_positive(a->h_path.dentry)) {
20791 + d_drop(a->h_path.dentry);
20792 + dput(a->h_path.dentry);
20796 + delegated = NULL;
20797 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20798 + &delegated, a->flags);
20799 + if (unlikely(rerr == -EWOULDBLOCK)) {
20800 + pr_warn("cannot retry for NFSv4 delegation"
20801 + " for an internal rename\n");
20804 + d_drop(a->h_path.dentry);
20805 + dput(a->h_path.dentry);
20807 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20809 + RevertFailure("rename %pd", a->h_dst);
20812 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20816 + a->h_path.dentry = a->src_wh_dentry;
20817 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20818 + au_set_dbwh(a->src_dentry, a->src_bwh);
20820 + RevertFailure("unlink %pd", a->src_wh_dentry);
20822 +#undef RevertFailure
20824 +/* ---------------------------------------------------------------------- */
20827 + * when we have to copyup the renaming entry, do it with the rename-target name
20828 + * in order to minimize the cost (the later actual rename is unnecessary).
20829 + * otherwise rename it on the target branch.
20831 +static int au_ren_or_cpup(struct au_ren_args *a)
20834 + struct dentry *d;
20835 + struct inode *delegated;
20837 + d = a->src_dentry;
20838 + if (au_dbtop(d) == a->btgt) {
20839 + a->h_path.dentry = a->dst_h_dentry;
20840 + AuDebugOn(au_dbtop(d) != a->btgt);
20841 + delegated = NULL;
20842 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20843 + a->dst_h_dir, &a->h_path, &delegated,
20845 + if (unlikely(err == -EWOULDBLOCK)) {
20846 + pr_warn("cannot retry for NFSv4 delegation"
20847 + " for an internal rename\n");
20853 + if (!err && a->h_dst)
20854 + /* it will be set to dinfo later */
20860 +/* cf. aufs_rmdir() */
20861 +static int au_ren_del_whtmp(struct au_ren_args *a)
20864 + struct inode *dir;
20866 + dir = a->dst_dir;
20867 + SiMustAnyLock(dir->i_sb);
20868 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20869 + au_sbi(dir->i_sb)->si_dirwh)
20870 + || au_test_fs_remote(a->h_dst->d_sb)) {
20871 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20872 + if (unlikely(err))
20873 + pr_warn("failed removing whtmp dir %pd (%d), "
20874 + "ignored.\n", a->h_dst, err);
20876 + au_nhash_wh_free(&a->thargs->whlist);
20877 + a->thargs->whlist = a->whlist;
20878 + a->whlist.nh_num = 0;
20879 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20881 + a->thargs = NULL;
20887 +/* make it 'opaque' dir. */
20888 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20891 + struct dentry *d, *diropq;
20892 +#define src_or_dst(member) a->sd[idx].member
20895 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20896 + src_or_dst(bdiropq) = au_dbdiropq(d);
20897 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20898 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20899 + diropq = au_diropq_create(d, a->btgt);
20900 + au_hn_inode_unlock(src_or_dst(hinode));
20901 + if (IS_ERR(diropq))
20902 + err = PTR_ERR(diropq);
20906 +#undef src_or_dst_
20910 +static int au_ren_diropq(struct au_ren_args *a)
20913 + unsigned char always;
20914 + struct dentry *d;
20917 + d = a->dst_dentry; /* already renamed on the branch */
20918 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20919 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20920 + && a->btgt != au_dbdiropq(a->src_dentry)
20921 + && (a->dst_wh_dentry
20922 + || a->btgt <= au_dbdiropq(d)
20923 + /* hide the lower to keep xino */
20924 + /* the lowers may not be a dir, but we hide them anyway */
20925 + || a->btgt < au_dbbot(d)
20928 + err = au_ren_do_diropq(a, AuSRC);
20929 + if (unlikely(err))
20931 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20933 + if (!a->exchange)
20934 + goto out; /* success */
20936 + d = a->src_dentry; /* already renamed on the branch */
20937 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20938 + && a->btgt != au_dbdiropq(a->dst_dentry)
20939 + && (a->btgt < au_dbdiropq(d)
20940 + || a->btgt < au_dbbot(d)
20942 + AuDbgDentry(a->src_dentry);
20943 + AuDbgDentry(a->dst_dentry);
20944 + err = au_ren_do_diropq(a, AuDST);
20945 + if (unlikely(err))
20946 + goto out_rev_src;
20947 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20949 + goto out; /* success */
20952 + AuDbg("err %d, reverting src\n", err);
20953 + au_ren_rev_diropq(err, a);
20958 +static int do_rename(struct au_ren_args *a)
20961 + struct dentry *d, *h_d;
20963 + if (!a->exchange) {
20964 + /* prepare workqueue args for asynchronous rmdir */
20965 + h_d = a->dst_h_dentry;
20966 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20967 + && d_is_positive(h_d)) {
20969 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20971 + if (unlikely(!a->thargs))
20973 + a->h_dst = dget(h_d);
20976 + /* create whiteout for src_dentry */
20977 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20978 + a->src_bwh = au_dbwh(a->src_dentry);
20979 + AuDebugOn(a->src_bwh >= 0);
20980 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20981 + a->src_h_parent);
20982 + err = PTR_ERR(a->src_wh_dentry);
20983 + if (IS_ERR(a->src_wh_dentry))
20987 + /* lookup whiteout for dentry */
20988 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20989 + h_d = au_wh_lkup(a->dst_h_parent,
20990 + &a->dst_dentry->d_name, a->br);
20991 + err = PTR_ERR(h_d);
20994 + if (d_is_negative(h_d))
20997 + a->dst_wh_dentry = h_d;
21000 + /* rename dentry to tmpwh */
21002 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
21003 + if (unlikely(err))
21006 + d = a->dst_dentry;
21007 + au_set_h_dptr(d, a->btgt, NULL);
21008 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
21009 + if (unlikely(err))
21011 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
21015 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
21017 + /* rename by vfs_rename or cpup */
21018 + err = au_ren_or_cpup(a);
21019 + if (unlikely(err))
21020 + /* leave the copied-up one */
21023 + /* make dir opaque */
21024 + err = au_ren_diropq(a);
21025 + if (unlikely(err))
21028 + /* update target timestamps */
21029 + if (a->exchange) {
21030 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
21031 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
21032 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21033 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21035 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
21036 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
21037 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21038 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21040 + if (!a->exchange) {
21041 + /* remove whiteout for dentry */
21042 + if (a->dst_wh_dentry) {
21043 + a->h_path.dentry = a->dst_wh_dentry;
21044 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
21046 + if (unlikely(err))
21050 + /* remove whtmp */
21052 + au_ren_del_whtmp(a); /* ignore this error */
21054 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
21057 + goto out_success;
21060 + au_ren_rev_diropq(err, a);
21062 + au_ren_rev_rename(err, a);
21066 + au_ren_rev_whtmp(err, a);
21068 + dput(a->dst_wh_dentry);
21069 + a->dst_wh_dentry = NULL;
21071 + if (a->src_wh_dentry)
21072 + au_ren_rev_whsrc(err, a);
21074 + dput(a->src_wh_dentry);
21075 + dput(a->dst_wh_dentry);
21079 + au_whtmp_rmdir_free(a->thargs);
21080 + a->thargs = NULL;
21086 +/* ---------------------------------------------------------------------- */
21089 + * test if @dentry dir can be rename destination or not.
21090 + * success means, it is a logically empty dir.
21092 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
21094 + return au_test_empty(dentry, whlist);
21098 + * test if @dentry dir can be rename source or not.
21099 + * if it can, return 0 and @children is filled.
21101 + * - it is a logically empty dir.
21102 + * - or, it exists on writable branch and has no children including whiteouts
21103 + * on the lower branch.
21105 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
21108 + unsigned int rdhash;
21109 + aufs_bindex_t btop;
21111 + btop = au_dbtop(dentry);
21112 + if (btop != btgt) {
21113 + struct au_nhash whlist;
21115 + SiMustAnyLock(dentry->d_sb);
21116 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
21118 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
21120 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
21121 + if (unlikely(err))
21123 + err = au_test_empty(dentry, &whlist);
21124 + au_nhash_wh_free(&whlist);
21128 + if (btop == au_dbtaildir(dentry))
21129 + return 0; /* success */
21131 + err = au_test_empty_lower(dentry);
21134 + if (err == -ENOTEMPTY) {
21135 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
21136 + " is not supported\n");
21142 +/* side effect: sets whlist and h_dentry */
21143 +static int au_ren_may_dir(struct au_ren_args *a)
21146 + unsigned int rdhash;
21147 + struct dentry *d;
21149 + d = a->dst_dentry;
21150 + SiMustAnyLock(d->d_sb);
21153 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
21154 + rdhash = au_sbi(d->d_sb)->si_rdhash;
21156 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
21157 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
21158 + if (unlikely(err))
21161 + if (!a->exchange) {
21162 + au_set_dbtop(d, a->dst_btop);
21163 + err = may_rename_dstdir(d, &a->whlist);
21164 + au_set_dbtop(d, a->btgt);
21166 + err = may_rename_srcdir(d, a->btgt);
21168 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
21169 + if (unlikely(err))
21172 + d = a->src_dentry;
21173 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
21174 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21175 + err = may_rename_srcdir(d, a->btgt);
21176 + if (unlikely(err)) {
21177 + au_nhash_wh_free(&a->whlist);
21178 + a->whlist.nh_num = 0;
21185 +/* ---------------------------------------------------------------------- */
21188 + * simple tests for rename.
21189 + * following the checks in vfs, plus the parent-child relationship.
21191 +static int au_may_ren(struct au_ren_args *a)
21194 + struct inode *h_inode;
21196 + if (a->src_btop == a->btgt) {
21197 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
21198 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
21199 + if (unlikely(err))
21202 + if (unlikely(a->src_h_dentry == a->h_trap))
21207 + if (a->dst_btop != a->btgt)
21210 + err = -ENOTEMPTY;
21211 + if (unlikely(a->dst_h_dentry == a->h_trap))
21215 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21216 + if (d_really_is_negative(a->dst_dentry)) {
21217 + if (d_is_negative(a->dst_h_dentry))
21218 + err = au_may_add(a->dst_dentry, a->btgt,
21219 + a->dst_h_parent, isdir);
21221 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21223 + h_inode = d_inode(a->dst_h_dentry);
21224 + if (h_inode->i_nlink)
21225 + err = au_may_del(a->dst_dentry, a->btgt,
21226 + a->dst_h_parent, isdir);
21230 + if (unlikely(err == -ENOENT || err == -EEXIST))
21236 +/* ---------------------------------------------------------------------- */
21241 + * - src_dir and dir by lock_rename()
21242 + * - inode if exitsts
21245 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21247 + * + di_write_lock2_child()
21248 + * + di_write_lock_child()
21249 + * + ii_write_lock_child()
21250 + * + di_write_lock_child2()
21251 + * + ii_write_lock_child2()
21252 + * + src_parent and parent
21253 + * + di_write_lock_parent()
21254 + * + ii_write_lock_parent()
21255 + * + di_write_lock_parent2()
21256 + * + ii_write_lock_parent2()
21257 + * + lower src_dir and dir by vfsub_lock_rename()
21258 + * + verify the every relationships between child and parent. if any
21259 + * of them failed, unlock all and return -EBUSY.
21261 +static void au_ren_unlock(struct au_ren_args *a)
21263 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21264 + a->dst_h_parent, a->dst_hdir);
21265 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21266 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21269 +static int au_ren_lock(struct au_ren_args *a)
21272 + unsigned int udba;
21275 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21276 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21277 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21278 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21280 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21281 + if (unlikely(err))
21283 + au_fset_ren(a->auren_flags, MNT_WRITE);
21284 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21285 + a->dst_h_parent, a->dst_hdir);
21286 + udba = au_opt_udba(a->src_dentry->d_sb);
21287 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21288 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21289 + err = au_busy_or_stale();
21290 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21291 + err = au_h_verify(a->src_h_dentry, udba,
21292 + d_inode(a->src_h_parent), a->src_h_parent,
21294 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21295 + err = au_h_verify(a->dst_h_dentry, udba,
21296 + d_inode(a->dst_h_parent), a->dst_h_parent,
21299 + goto out; /* success */
21301 + err = au_busy_or_stale();
21302 + au_ren_unlock(a);
21308 +/* ---------------------------------------------------------------------- */
21310 +static void au_ren_refresh_dir(struct au_ren_args *a)
21312 + struct inode *dir;
21314 + dir = a->dst_dir;
21315 + dir->i_version++;
21316 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21317 + /* is this updating defined in POSIX? */
21318 + au_cpup_attr_timesizes(a->src_inode);
21319 + au_cpup_attr_nlink(dir, /*force*/1);
21321 + au_dir_ts(dir, a->btgt);
21323 + if (a->exchange) {
21324 + dir = a->src_dir;
21325 + dir->i_version++;
21326 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21327 + /* is this updating defined in POSIX? */
21328 + au_cpup_attr_timesizes(a->dst_inode);
21329 + au_cpup_attr_nlink(dir, /*force*/1);
21331 + au_dir_ts(dir, a->btgt);
21334 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21337 + dir = a->src_dir;
21338 + dir->i_version++;
21339 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21340 + au_cpup_attr_nlink(dir, /*force*/1);
21341 + au_dir_ts(dir, a->btgt);
21344 +static void au_ren_refresh(struct au_ren_args *a)
21346 + aufs_bindex_t bbot, bindex;
21347 + struct dentry *d, *h_d;
21348 + struct inode *i, *h_i;
21349 + struct super_block *sb;
21351 + d = a->dst_dentry;
21354 + /* already dget-ed by au_ren_or_cpup() */
21355 + au_set_h_dptr(d, a->btgt, a->h_dst);
21357 + i = a->dst_inode;
21359 + if (!a->exchange) {
21360 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21361 + vfsub_drop_nlink(i);
21363 + vfsub_dead_dir(i);
21364 + au_cpup_attr_timesizes(i);
21366 + au_update_dbrange(d, /*do_put_zero*/1);
21368 + au_cpup_attr_nlink(i, /*force*/1);
21371 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21372 + au_set_h_dptr(d, bindex, NULL);
21373 + bbot = au_dbbot(d);
21374 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21375 + au_set_h_dptr(d, bindex, NULL);
21376 + au_update_dbrange(d, /*do_put_zero*/0);
21379 + d = a->src_dentry;
21380 + if (!a->exchange) {
21381 + au_set_dbwh(d, -1);
21382 + bbot = au_dbbot(d);
21383 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21384 + h_d = au_h_dptr(d, bindex);
21386 + au_set_h_dptr(d, bindex, NULL);
21388 + au_set_dbbot(d, a->btgt);
21391 + i = a->src_inode;
21392 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21393 + return; /* success */
21395 + bbot = au_ibbot(i);
21396 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21397 + h_i = au_h_iptr(i, bindex);
21399 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21400 + /* ignore this error */
21401 + au_set_h_iptr(i, bindex, NULL, 0);
21404 + au_set_ibbot(i, a->btgt);
21406 + d_drop(a->src_dentry);
21409 +/* ---------------------------------------------------------------------- */
21411 +/* mainly for link(2) and rename(2) */
21412 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21414 + aufs_bindex_t bdiropq, bwh;
21415 + struct dentry *parent;
21416 + struct au_branch *br;
21418 + parent = dentry->d_parent;
21419 + IMustLock(d_inode(parent)); /* dir is locked */
21421 + bdiropq = au_dbdiropq(parent);
21422 + bwh = au_dbwh(dentry);
21423 + br = au_sbr(dentry->d_sb, btgt);
21424 + if (au_br_rdonly(br)
21425 + || (0 <= bdiropq && bdiropq < btgt)
21426 + || (0 <= bwh && bwh < btgt))
21429 + AuDbg("btgt %d\n", btgt);
21433 +/* sets src_btop, dst_btop and btgt */
21434 +static int au_ren_wbr(struct au_ren_args *a)
21437 + struct au_wr_dir_args wr_dir_args = {
21438 + /* .force_btgt = -1, */
21439 + .flags = AuWrDir_ADD_ENTRY
21442 + a->src_btop = au_dbtop(a->src_dentry);
21443 + a->dst_btop = au_dbtop(a->dst_dentry);
21444 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21445 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21446 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21447 + wr_dir_args.force_btgt = a->src_btop;
21448 + if (a->dst_inode && a->dst_btop < a->src_btop)
21449 + wr_dir_args.force_btgt = a->dst_btop;
21450 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21451 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21454 + au_update_dbtop(a->dst_dentry);
21459 +static void au_ren_dt(struct au_ren_args *a)
21461 + a->h_path.dentry = a->src_h_parent;
21462 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21463 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21464 + a->h_path.dentry = a->dst_h_parent;
21465 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21468 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21469 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21473 + a->h_path.dentry = a->src_h_dentry;
21474 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21475 + if (d_is_positive(a->dst_h_dentry)) {
21476 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21477 + a->h_path.dentry = a->dst_h_dentry;
21478 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21482 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21484 + struct dentry *h_d;
21485 + struct inode *h_inode;
21487 + au_dtime_revert(a->src_dt + AuPARENT);
21488 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21489 + au_dtime_revert(a->dst_dt + AuPARENT);
21491 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21492 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21493 + h_inode = d_inode(h_d);
21494 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21495 + au_dtime_revert(a->src_dt + AuCHILD);
21496 + inode_unlock(h_inode);
21498 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21499 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21500 + h_inode = d_inode(h_d);
21501 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21502 + au_dtime_revert(a->dst_dt + AuCHILD);
21503 + inode_unlock(h_inode);
21508 +/* ---------------------------------------------------------------------- */
21510 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21511 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21512 + unsigned int _flags)
21514 + int err, lock_flags;
21515 + /* reduce stack space */
21516 + struct au_ren_args *a;
21517 + struct au_pin pin;
21519 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21520 + IMustLock(_src_dir);
21521 + IMustLock(_dst_dir);
21524 + if (unlikely(_flags & RENAME_WHITEOUT))
21528 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21529 + a = kzalloc(sizeof(*a), GFP_NOFS);
21530 + if (unlikely(!a))
21533 + a->flags = _flags;
21534 + a->exchange = _flags & RENAME_EXCHANGE;
21535 + a->src_dir = _src_dir;
21536 + a->src_dentry = _src_dentry;
21537 + a->src_inode = NULL;
21538 + if (d_really_is_positive(a->src_dentry))
21539 + a->src_inode = d_inode(a->src_dentry);
21540 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21541 + a->dst_dir = _dst_dir;
21542 + a->dst_dentry = _dst_dentry;
21543 + a->dst_inode = NULL;
21544 + if (d_really_is_positive(a->dst_dentry))
21545 + a->dst_inode = d_inode(a->dst_dentry);
21546 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21547 + if (a->dst_inode) {
21549 + * if EXCHANGE && src is non-dir && dst is dir,
21550 + * dst is not locked.
21552 + /* IMustLock(a->dst_inode); */
21553 + au_igrab(a->dst_inode);
21557 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21558 + if (d_is_dir(a->src_dentry)) {
21559 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21560 + if (unlikely(!a->exchange
21561 + && d_really_is_positive(a->dst_dentry)
21562 + && !d_is_dir(a->dst_dentry)))
21564 + lock_flags |= AuLock_DIRS;
21566 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21567 + au_fset_ren(a->auren_flags, ISDIR_DST);
21568 + if (unlikely(!a->exchange
21569 + && d_really_is_positive(a->src_dentry)
21570 + && !d_is_dir(a->src_dentry)))
21572 + lock_flags |= AuLock_DIRS;
21574 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21575 + if (unlikely(err))
21578 + err = au_d_hashed_positive(a->src_dentry);
21579 + if (unlikely(err))
21582 + if (a->dst_inode) {
21584 + * If it is a dir, VFS unhash it before this
21585 + * function. It means we cannot rely upon d_unhashed().
21587 + if (unlikely(!a->dst_inode->i_nlink))
21589 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21590 + err = au_d_hashed_positive(a->dst_dentry);
21591 + if (unlikely(err && !a->exchange))
21593 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21595 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21599 + * is it possible?
21600 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21601 + * there may exist a problem somewhere else.
21604 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21607 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21608 + di_write_lock_parent(a->dst_parent);
21610 + /* which branch we process */
21611 + err = au_ren_wbr(a);
21612 + if (unlikely(err < 0))
21614 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21615 + a->h_path.mnt = au_br_mnt(a->br);
21617 + /* are they available to be renamed */
21618 + err = au_ren_may_dir(a);
21619 + if (unlikely(err))
21620 + goto out_children;
21622 + /* prepare the writable parent dir on the same branch */
21623 + if (a->dst_btop == a->btgt) {
21624 + au_fset_ren(a->auren_flags, WHDST);
21626 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21627 + if (unlikely(err))
21628 + goto out_children;
21632 + if (!a->exchange) {
21633 + if (a->src_dir != a->dst_dir) {
21635 + * this temporary unlock is safe,
21636 + * because both dir->i_mutex are locked.
21638 + di_write_unlock(a->dst_parent);
21639 + di_write_lock_parent(a->src_parent);
21640 + err = au_wr_dir_need_wh(a->src_dentry,
21641 + au_ftest_ren(a->auren_flags,
21644 + di_write_unlock(a->src_parent);
21645 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21647 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21649 + err = au_wr_dir_need_wh(a->src_dentry,
21650 + au_ftest_ren(a->auren_flags,
21654 + if (unlikely(err < 0))
21655 + goto out_children;
21657 + au_fset_ren(a->auren_flags, WHSRC);
21660 + if (a->src_btop != a->btgt) {
21661 + err = au_pin(&pin, a->src_dentry, a->btgt,
21662 + au_opt_udba(a->src_dentry->d_sb),
21663 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21665 + struct au_cp_generic cpg = {
21666 + .dentry = a->src_dentry,
21668 + .bsrc = a->src_btop,
21671 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21673 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21674 + err = au_sio_cpup_simple(&cpg);
21677 + if (unlikely(err))
21678 + goto out_children;
21679 + a->src_btop = a->btgt;
21680 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21681 + if (!a->exchange)
21682 + au_fset_ren(a->auren_flags, WHSRC);
21686 + if (a->exchange && a->dst_inode
21687 + && a->dst_btop != a->btgt) {
21688 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21689 + au_opt_udba(a->dst_dentry->d_sb),
21690 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21692 + struct au_cp_generic cpg = {
21693 + .dentry = a->dst_dentry,
21695 + .bsrc = a->dst_btop,
21698 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21700 + err = au_sio_cpup_simple(&cpg);
21703 + if (unlikely(err))
21704 + goto out_children;
21705 + a->dst_btop = a->btgt;
21706 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21709 + /* lock them all */
21710 + err = au_ren_lock(a);
21711 + if (unlikely(err))
21712 + /* leave the copied-up one */
21713 + goto out_children;
21715 + if (!a->exchange) {
21716 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21717 + err = au_may_ren(a);
21718 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21719 + err = -ENAMETOOLONG;
21720 + if (unlikely(err))
21724 + /* store timestamps to be revertible */
21728 + err = do_rename(a);
21729 + if (unlikely(err))
21732 + /* update dir attributes */
21733 + au_ren_refresh_dir(a);
21735 + /* dput/iput all lower dentries */
21736 + au_ren_refresh(a);
21738 + goto out_hdir; /* success */
21741 + au_ren_rev_dt(err, a);
21743 + au_ren_unlock(a);
21745 + au_nhash_wh_free(&a->whlist);
21746 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21747 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21748 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21749 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21753 + if (!a->exchange)
21754 + d_move(a->src_dentry, a->dst_dentry);
21756 + d_exchange(a->src_dentry, a->dst_dentry);
21758 + au_update_dbtop(a->dst_dentry);
21759 + if (!a->dst_inode)
21760 + d_drop(a->dst_dentry);
21762 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21763 + di_write_unlock(a->dst_parent);
21765 + di_write_unlock2(a->src_parent, a->dst_parent);
21767 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21769 + iput(a->dst_inode);
21771 + au_whtmp_rmdir_free(a->thargs);
21772 + au_delayed_kfree(a);
21777 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21778 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21779 +++ linux/fs/aufs/Kconfig 2017-05-06 22:16:52.774886674 +0200
21782 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21784 + Aufs is a stackable unification filesystem such as Unionfs,
21785 + which unifies several directories and provides a merged single
21787 + In the early days, aufs was entirely re-designed and
21788 + re-implemented Unionfs Version 1.x series. Introducing many
21789 + original ideas, approaches and improvements, it becomes totally
21790 + different from Unionfs while keeping the basic features.
21794 + prompt "Maximum number of branches"
21795 + default AUFS_BRANCH_MAX_127
21797 + Specifies the maximum number of branches (or member directories)
21798 + in a single aufs. The larger value consumes more system
21799 + resources and has a minor impact to performance.
21800 +config AUFS_BRANCH_MAX_127
21803 + Specifies the maximum number of branches (or member directories)
21804 + in a single aufs. The larger value consumes more system
21805 + resources and has a minor impact to performance.
21806 +config AUFS_BRANCH_MAX_511
21809 + Specifies the maximum number of branches (or member directories)
21810 + in a single aufs. The larger value consumes more system
21811 + resources and has a minor impact to performance.
21812 +config AUFS_BRANCH_MAX_1023
21815 + Specifies the maximum number of branches (or member directories)
21816 + in a single aufs. The larger value consumes more system
21817 + resources and has a minor impact to performance.
21818 +config AUFS_BRANCH_MAX_32767
21821 + Specifies the maximum number of branches (or member directories)
21822 + in a single aufs. The larger value consumes more system
21823 + resources and has a minor impact to performance.
21826 +config AUFS_SBILIST
21828 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21831 + Automatic configuration for internal use.
21832 + When aufs supports Magic SysRq or /proc, enabled automatically.
21834 +config AUFS_HNOTIFY
21835 + bool "Detect direct branch access (bypassing aufs)"
21837 + If you want to modify files on branches directly, eg. bypassing aufs,
21838 + and want aufs to detect the changes of them fully, then enable this
21839 + option and use 'udba=notify' mount option.
21840 + Currently there is only one available configuration, "fsnotify".
21841 + It will have a negative impact to the performance.
21842 + See detail in aufs.5.
21845 + prompt "method" if AUFS_HNOTIFY
21846 + default AUFS_HFSNOTIFY
21847 +config AUFS_HFSNOTIFY
21852 +config AUFS_EXPORT
21853 + bool "NFS-exportable aufs"
21854 + depends on EXPORTFS
21856 + If you want to export your mounted aufs via NFS, then enable this
21857 + option. There are several requirements for this configuration.
21858 + See detail in aufs.5.
21860 +config AUFS_INO_T_64
21862 + depends on AUFS_EXPORT
21863 + depends on 64BIT && !(ALPHA || S390)
21866 + Automatic configuration for internal use.
21867 + /* typedef unsigned long/int __kernel_ino_t */
21868 + /* alpha and s390x are int */
21871 + bool "support for XATTR/EA (including Security Labels)"
21873 + If your branch fs supports XATTR/EA and you want to make them
21874 + available in aufs too, then enable this opsion and specify the
21875 + branch attributes for EA.
21876 + See detail in aufs.5.
21879 + bool "File-based Hierarchical Storage Management"
21881 + Hierarchical Storage Management (or HSM) is a well-known feature
21882 + in the storage world. Aufs provides this feature as file-based.
21883 + with multiple branches.
21884 + These multiple branches are prioritized, ie. the topmost one
21885 + should be the fastest drive and be used heavily.
21888 + bool "Readdir in userspace"
21890 + Aufs has two methods to provide a merged view for a directory,
21891 + by a user-space library and by kernel-space natively. The latter
21892 + is always enabled but sometimes large and slow.
21893 + If you enable this option, install the library in aufs2-util
21894 + package, and set some environment variables for your readdir(3),
21895 + then the work will be handled in user-space which generally
21896 + shows better performance in most cases.
21897 + See detail in aufs.5.
21900 + bool "Show whiteouts"
21902 + If you want to make the whiteouts in aufs visible, then enable
21903 + this option and specify 'shwh' mount option. Although it may
21904 + sounds like philosophy or something, but in technically it
21905 + simply shows the name of whiteout with keeping its behaviour.
21907 +config AUFS_BR_RAMFS
21908 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21910 + If you want to use ramfs as an aufs branch fs, then enable this
21911 + option. Generally tmpfs is recommended.
21912 + Aufs prohibited them to be a branch fs by default, because
21913 + initramfs becomes unusable after switch_root or something
21914 + generally. If you sets initramfs as an aufs branch and boot your
21915 + system by switch_root, you will meet a problem easily since the
21916 + files in initramfs may be inaccessible.
21917 + Unless you are going to use ramfs as an aufs branch fs without
21918 + switch_root or something, leave it N.
21920 +config AUFS_BR_FUSE
21921 + bool "Fuse fs as an aufs branch"
21922 + depends on FUSE_FS
21925 + If you want to use fuse-based userspace filesystem as an aufs
21926 + branch fs, then enable this option.
21927 + It implements the internal poll(2) operation which is
21928 + implemented by fuse only (curretnly).
21933 + Automatic configuration for internal use.
21935 +config AUFS_BR_HFSPLUS
21936 + bool "Hfsplus as an aufs branch"
21937 + depends on HFSPLUS_FS
21940 + If you want to use hfsplus fs as an aufs branch fs, then enable
21941 + this option. This option introduces a small overhead at
21942 + copying-up a file on hfsplus.
21944 +config AUFS_BDEV_LOOP
21946 + depends on BLK_DEV_LOOP
21949 + Automatic configuration for internal use.
21950 + Convert =[ym] into =y.
21953 + bool "Debug aufs"
21955 + Enable this to compile aufs internal debug code.
21956 + It will have a negative impact to the performance.
21958 +config AUFS_MAGIC_SYSRQ
21960 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21963 + Automatic configuration for internal use.
21964 + When aufs supports Magic SysRq, enabled automatically.
21966 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21967 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21968 +++ linux/fs/aufs/loop.c 2017-05-06 22:16:52.781553511 +0200
21971 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21973 + * This program, aufs is free software; you can redistribute it and/or modify
21974 + * it under the terms of the GNU General Public License as published by
21975 + * the Free Software Foundation; either version 2 of the License, or
21976 + * (at your option) any later version.
21978 + * This program is distributed in the hope that it will be useful,
21979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21981 + * GNU General Public License for more details.
21983 + * You should have received a copy of the GNU General Public License
21984 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21988 + * support for loopback block device as a branch
21993 +/* added into drivers/block/loop.c */
21994 +static struct file *(*backing_file_func)(struct super_block *sb);
21997 + * test if two lower dentries have overlapping branches.
21999 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
22001 + struct super_block *h_sb;
22002 + struct file *backing_file;
22004 + if (unlikely(!backing_file_func)) {
22005 + /* don't load "loop" module here */
22006 + backing_file_func = symbol_get(loop_backing_file);
22007 + if (unlikely(!backing_file_func))
22008 + /* "loop" module is not loaded */
22012 + h_sb = h_adding->d_sb;
22013 + backing_file = backing_file_func(h_sb);
22014 + if (!backing_file)
22017 + h_adding = backing_file->f_path.dentry;
22019 + * h_adding can be local NFS.
22020 + * in this case aufs cannot detect the loop.
22022 + if (unlikely(h_adding->d_sb == sb))
22024 + return !!au_test_subdir(h_adding, sb->s_root);
22027 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
22028 +int au_test_loopback_kthread(void)
22031 + struct task_struct *tsk = current;
22032 + char c, comm[sizeof(tsk->comm)];
22035 + if (tsk->flags & PF_KTHREAD) {
22036 + get_task_comm(comm, tsk);
22038 + ret = ('0' <= c && c <= '9'
22039 + && !strncmp(comm, "loop", 4));
22045 +/* ---------------------------------------------------------------------- */
22047 +#define au_warn_loopback_step 16
22048 +static int au_warn_loopback_nelem = au_warn_loopback_step;
22049 +static unsigned long *au_warn_loopback_array;
22051 +void au_warn_loopback(struct super_block *h_sb)
22053 + int i, new_nelem;
22054 + unsigned long *a, magic;
22055 + static DEFINE_SPINLOCK(spin);
22057 + magic = h_sb->s_magic;
22058 + spin_lock(&spin);
22059 + a = au_warn_loopback_array;
22060 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
22061 + if (a[i] == magic) {
22062 + spin_unlock(&spin);
22066 + /* h_sb is new to us, print it */
22067 + if (i < au_warn_loopback_nelem) {
22072 + /* expand the array */
22073 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
22074 + a = au_kzrealloc(au_warn_loopback_array,
22075 + au_warn_loopback_nelem * sizeof(unsigned long),
22076 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
22077 + /*may_shrink*/0);
22079 + au_warn_loopback_nelem = new_nelem;
22080 + au_warn_loopback_array = a;
22085 + spin_unlock(&spin);
22086 + AuWarn1("realloc failed, ignored\n");
22090 + spin_unlock(&spin);
22091 + pr_warn("you may want to try another patch for loopback file "
22092 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
22095 +int au_loopback_init(void)
22098 + struct super_block *sb __maybe_unused;
22100 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
22103 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
22104 + sizeof(unsigned long), GFP_NOFS);
22105 + if (unlikely(!au_warn_loopback_array))
22111 +void au_loopback_fin(void)
22113 + if (backing_file_func)
22114 + symbol_put(loop_backing_file);
22115 + au_delayed_kfree(au_warn_loopback_array);
22117 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
22118 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
22119 +++ linux/fs/aufs/loop.h 2017-05-06 22:16:52.781553511 +0200
22122 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22124 + * This program, aufs is free software; you can redistribute it and/or modify
22125 + * it under the terms of the GNU General Public License as published by
22126 + * the Free Software Foundation; either version 2 of the License, or
22127 + * (at your option) any later version.
22129 + * This program is distributed in the hope that it will be useful,
22130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22132 + * GNU General Public License for more details.
22134 + * You should have received a copy of the GNU General Public License
22135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22139 + * support for loopback mount as a branch
22142 +#ifndef __AUFS_LOOP_H__
22143 +#define __AUFS_LOOP_H__
22148 +struct super_block;
22150 +#ifdef CONFIG_AUFS_BDEV_LOOP
22151 +/* drivers/block/loop.c */
22152 +struct file *loop_backing_file(struct super_block *sb);
22155 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
22156 +int au_test_loopback_kthread(void);
22157 +void au_warn_loopback(struct super_block *h_sb);
22159 +int au_loopback_init(void);
22160 +void au_loopback_fin(void);
22162 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
22163 + struct dentry *h_adding)
22164 +AuStubInt0(au_test_loopback_kthread, void)
22165 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
22167 +AuStubInt0(au_loopback_init, void)
22168 +AuStubVoid(au_loopback_fin, void)
22169 +#endif /* BLK_DEV_LOOP */
22171 +#endif /* __KERNEL__ */
22172 +#endif /* __AUFS_LOOP_H__ */
22173 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
22174 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
22175 +++ linux/fs/aufs/magic.mk 2017-05-06 22:16:52.781553511 +0200
22178 +# defined in ${srctree}/fs/fuse/inode.c
22180 +ifdef CONFIG_FUSE_FS
22181 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
22184 +# defined in ${srctree}/fs/xfs/xfs_sb.h
22186 +ifdef CONFIG_XFS_FS
22187 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
22190 +# defined in ${srctree}/fs/configfs/mount.c
22192 +ifdef CONFIG_CONFIGFS_FS
22193 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
22196 +# defined in ${srctree}/fs/ubifs/ubifs.h
22198 +ifdef CONFIG_UBIFS_FS
22199 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
22202 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22204 +ifdef CONFIG_HFSPLUS_FS
22205 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22207 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22208 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22209 +++ linux/fs/aufs/Makefile 2017-05-06 22:16:52.774886674 +0200
22212 +include ${src}/magic.mk
22213 +ifeq (${CONFIG_AUFS_FS},m)
22214 +include ${src}/conf.mk
22216 +-include ${src}/priv_def.mk
22218 +# cf. include/linux/kernel.h
22220 +ccflags-y += -DDEBUG
22221 +# sparse requires the full pathname
22223 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22225 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22228 +obj-$(CONFIG_AUFS_FS) += aufs.o
22229 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22230 + wkq.o vfsub.o dcsub.o \
22231 + cpup.o whout.o wbr_policy.o \
22232 + dinfo.o dentry.o \
22234 + finfo.o file.o f_op.o \
22236 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22240 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22241 +aufs-$(CONFIG_SYSFS) += sysfs.o
22242 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22243 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22244 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22245 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22246 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22247 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22248 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22249 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22250 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22251 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22252 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22253 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22254 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22255 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22256 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22257 +++ linux/fs/aufs/module.c 2017-05-06 22:16:52.781553511 +0200
22260 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22262 + * This program, aufs is free software; you can redistribute it and/or modify
22263 + * it under the terms of the GNU General Public License as published by
22264 + * the Free Software Foundation; either version 2 of the License, or
22265 + * (at your option) any later version.
22267 + * This program is distributed in the hope that it will be useful,
22268 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22269 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22270 + * GNU General Public License for more details.
22272 + * You should have received a copy of the GNU General Public License
22273 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22277 + * module global variables and operations
22280 +#include <linux/module.h>
22281 +#include <linux/seq_file.h>
22284 +/* shrinkable realloc */
22285 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22293 +#if 0 /* unused */
22295 + au_delayed_kfree(p);
22300 + AuDebugOn(!new_sz);
22303 + diff = au_kmidx_sub(sz, new_sz);
22309 + /* expand or SLOB */
22310 + p = krealloc(p, new_sz, gfp);
22311 + else if (new_sz < sz && may_shrink) {
22315 + q = kmalloc(new_sz, gfp);
22318 + memcpy(q, p, new_sz);
22319 + au_delayed_kfree(p);
22330 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22333 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22334 + if (p && new_sz > nused)
22335 + memset(p + nused, 0, new_sz - nused);
22339 +/* ---------------------------------------------------------------------- */
22344 +struct au_dfree au_dfree;
22346 +/* delayed free */
22347 +static void au_do_dfree(struct work_struct *work __maybe_unused)
22349 + struct llist_head *head;
22350 + struct llist_node *node, *next;
22352 +#define AU_CACHE_DFREE_DO_BODY(name, idx, lnode) do { \
22353 + head = &au_dfree.cache[AuCache_##idx].llist; \
22354 + node = llist_del_all(head); \
22355 + for (; node; node = next) { \
22356 + struct au_##name *p \
22357 + = llist_entry(node, struct au_##name, \
22359 + next = llist_next(node); \
22360 + au_cache_free_##name(p); \
22364 + AU_CACHE_DFREE_DO_BODY(dinfo, DINFO, di_lnode);
22365 + AU_CACHE_DFREE_DO_BODY(icntnr, ICNTNR, lnode);
22366 + AU_CACHE_DFREE_DO_BODY(finfo, FINFO, fi_lnode);
22367 + AU_CACHE_DFREE_DO_BODY(vdir, VDIR, vd_lnode);
22368 + AU_CACHE_DFREE_DO_BODY(vdir_dehstr, DEHSTR, lnode);
22369 +#ifdef CONFIG_AUFS_HNOTIFY
22370 + AU_CACHE_DFREE_DO_BODY(hnotify, HNOTIFY, hn_lnode);
22373 +#define AU_DFREE_DO_BODY(llist, func) do { \
22374 + node = llist_del_all(llist); \
22375 + for (; node; node = next) { \
22376 + next = llist_next(node); \
22381 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_KFREE, kfree);
22382 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_FREE_PAGE, au_free_page);
22384 +#undef AU_CACHE_DFREE_DO_BODY
22385 +#undef AU_DFREE_DO_BODY
22388 +AU_CACHE_DFREE_FUNC(dinfo, DINFO, di_lnode);
22389 +AU_CACHE_DFREE_FUNC(icntnr, ICNTNR, lnode);
22390 +AU_CACHE_DFREE_FUNC(finfo, FINFO, fi_lnode);
22391 +AU_CACHE_DFREE_FUNC(vdir, VDIR, vd_lnode);
22392 +AU_CACHE_DFREE_FUNC(vdir_dehstr, DEHSTR, lnode);
22394 +static void au_cache_fin(void)
22397 + struct au_cache *cp;
22400 + * Make sure all delayed rcu free inodes are flushed before we
22405 + /* excluding AuCache_HNOTIFY */
22406 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22407 + flush_delayed_work(&au_dfree.dwork);
22408 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22409 + cp = au_dfree.cache + i;
22410 + AuDebugOn(!llist_empty(&cp->llist));
22411 + kmem_cache_destroy(cp->cache);
22412 + cp->cache = NULL;
22416 +static int __init au_cache_init(void)
22418 + struct au_cache *cp;
22420 + cp = au_dfree.cache;
22421 + cp[AuCache_DINFO].cache = AuCacheCtor(au_dinfo, au_di_init_once);
22422 + if (cp[AuCache_DINFO].cache)
22423 + /* SLAB_DESTROY_BY_RCU */
22424 + cp[AuCache_ICNTNR].cache = AuCacheCtor(au_icntnr,
22425 + au_icntnr_init_once);
22426 + if (cp[AuCache_ICNTNR].cache)
22427 + cp[AuCache_FINFO].cache = AuCacheCtor(au_finfo,
22428 + au_fi_init_once);
22429 + if (cp[AuCache_FINFO].cache)
22430 + cp[AuCache_VDIR].cache = AuCache(au_vdir);
22431 + if (cp[AuCache_VDIR].cache)
22432 + cp[AuCache_DEHSTR].cache = AuCache(au_vdir_dehstr);
22433 + if (cp[AuCache_DEHSTR].cache)
22440 +/* ---------------------------------------------------------------------- */
22442 +int au_dir_roflags;
22444 +#ifdef CONFIG_AUFS_SBILIST
22446 + * iterate_supers_type() doesn't protect us from
22447 + * remounting (branch management)
22449 +struct au_sphlhead au_sbilist;
22453 + * functions for module interface.
22455 +MODULE_LICENSE("GPL");
22456 +/* MODULE_LICENSE("GPL v2"); */
22457 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22458 +MODULE_DESCRIPTION(AUFS_NAME
22459 + " -- Advanced multi layered unification filesystem");
22460 +MODULE_VERSION(AUFS_VERSION);
22461 +MODULE_ALIAS_FS(AUFS_NAME);
22463 +/* this module parameter has no meaning when SYSFS is disabled */
22464 +int sysaufs_brs = 1;
22465 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22466 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22468 +/* this module parameter has no meaning when USER_NS is disabled */
22470 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22471 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22473 +/* ---------------------------------------------------------------------- */
22475 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22477 +int au_seq_path(struct seq_file *seq, struct path *path)
22481 + err = seq_path(seq, path, au_esc_chars);
22484 + else if (err < 0)
22490 +/* ---------------------------------------------------------------------- */
22492 +static int __init aufs_init(void)
22496 + struct au_cache *cp;
22498 + p = au_esc_chars;
22499 + for (i = 1; i <= ' '; i++)
22505 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22507 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22508 + for (i = 0; i < AuIop_Last; i++)
22509 + aufs_iop_nogetattr[i].getattr = NULL;
22511 + /* First, initialize au_dfree */
22512 + for (i = 0; i < AuCache_Last; i++) { /* including hnotify */
22513 + cp = au_dfree.cache + i;
22514 + cp->cache = NULL;
22515 + init_llist_head(&cp->llist);
22517 + for (i = 0; i < AU_DFREE_Last; i++)
22518 + init_llist_head(au_dfree.llist + i);
22519 + INIT_DELAYED_WORK(&au_dfree.dwork, au_do_dfree);
22521 + au_sbilist_init();
22522 + sysaufs_brs_init();
22525 + err = sysaufs_init();
22526 + if (unlikely(err))
22528 + err = au_procfs_init();
22529 + if (unlikely(err))
22530 + goto out_sysaufs;
22531 + err = au_wkq_init();
22532 + if (unlikely(err))
22534 + err = au_loopback_init();
22535 + if (unlikely(err))
22537 + err = au_hnotify_init();
22538 + if (unlikely(err))
22539 + goto out_loopback;
22540 + err = au_sysrq_init();
22541 + if (unlikely(err))
22543 + err = au_cache_init();
22544 + if (unlikely(err))
22547 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22548 + err = register_filesystem(&aufs_fs_type);
22549 + if (unlikely(err))
22552 + /* since we define pr_fmt, call printk directly */
22553 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22554 + goto out; /* success */
22561 + au_hnotify_fin();
22563 + au_loopback_fin();
22571 + flush_delayed_work(&au_dfree.dwork);
22576 +static void __exit aufs_exit(void)
22578 + unregister_filesystem(&aufs_fs_type);
22581 + au_hnotify_fin();
22582 + au_loopback_fin();
22587 + flush_delayed_work(&au_dfree.dwork);
22590 +module_init(aufs_init);
22591 +module_exit(aufs_exit);
22592 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22593 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22594 +++ linux/fs/aufs/module.h 2017-05-06 22:16:52.781553511 +0200
22597 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22599 + * This program, aufs is free software; you can redistribute it and/or modify
22600 + * it under the terms of the GNU General Public License as published by
22601 + * the Free Software Foundation; either version 2 of the License, or
22602 + * (at your option) any later version.
22604 + * This program is distributed in the hope that it will be useful,
22605 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22606 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22607 + * GNU General Public License for more details.
22609 + * You should have received a copy of the GNU General Public License
22610 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22614 + * module initialization and module-global
22617 +#ifndef __AUFS_MODULE_H__
22618 +#define __AUFS_MODULE_H__
22622 +#include <linux/slab.h>
22623 +#include "debug.h"
22628 +/* module parameters */
22629 +extern int sysaufs_brs;
22630 +extern bool au_userns;
22632 +/* ---------------------------------------------------------------------- */
22634 +extern int au_dir_roflags;
22636 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22637 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22640 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22642 +#ifndef CONFIG_SLOB
22643 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22645 + return -1; /* SLOB is untested */
22649 +int au_seq_path(struct seq_file *seq, struct path *path);
22651 +#ifdef CONFIG_PROC_FS
22653 +int __init au_procfs_init(void);
22654 +void au_procfs_fin(void);
22656 +AuStubInt0(au_procfs_init, void);
22657 +AuStubVoid(au_procfs_fin, void);
22660 +/* ---------------------------------------------------------------------- */
22662 +/* kmem cache and delayed free */
22669 + AuCache_HNOTIFY, /* must be last */
22675 + AU_DFREE_FREE_PAGE,
22680 + struct kmem_cache *cache;
22681 + struct llist_head llist; /* delayed free */
22685 + * in order to reduce the cost of the internal timer, consolidate all the
22686 + * delayed free works into a single delayed_work.
22689 + struct au_cache cache[AuCache_Last];
22690 + struct llist_head llist[AU_DFREE_Last];
22691 + struct delayed_work dwork;
22694 +extern struct au_dfree au_dfree;
22696 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22697 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22698 +#define AuCacheCtor(type, ctor) \
22699 + kmem_cache_create(#type, sizeof(struct type), \
22700 + __alignof__(struct type), AuCacheFlags, ctor)
22702 +#define AU_DFREE_DELAY msecs_to_jiffies(10)
22703 +#define AU_DFREE_BODY(lnode, llist) do { \
22704 + if (llist_add(lnode, llist)) \
22705 + schedule_delayed_work(&au_dfree.dwork, \
22706 + AU_DFREE_DELAY); \
22708 +#define AU_CACHE_DFREE_FUNC(name, idx, lnode) \
22709 + void au_cache_dfree_##name(struct au_##name *p) \
22711 + struct au_cache *cp = au_dfree.cache + AuCache_##idx; \
22712 + AU_DFREE_BODY(&p->lnode, &cp->llist); \
22715 +#define AuCacheFuncs(name, index) \
22716 +static inline struct au_##name *au_cache_alloc_##name(void) \
22717 +{ return kmem_cache_alloc(au_dfree.cache[AuCache_##index].cache, GFP_NOFS); } \
22718 +static inline void au_cache_free_##name(struct au_##name *p) \
22719 +{ kmem_cache_free(au_dfree.cache[AuCache_##index].cache, p); } \
22720 +void au_cache_dfree_##name(struct au_##name *p)
22722 +AuCacheFuncs(dinfo, DINFO);
22723 +AuCacheFuncs(icntnr, ICNTNR);
22724 +AuCacheFuncs(finfo, FINFO);
22725 +AuCacheFuncs(vdir, VDIR);
22726 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22727 +#ifdef CONFIG_AUFS_HNOTIFY
22728 +AuCacheFuncs(hnotify, HNOTIFY);
22731 +static inline void au_delayed_kfree(const void *p)
22734 + AuDebugOn(ksize(p) < sizeof(struct llist_node));
22736 + AU_DFREE_BODY((void *)p, au_dfree.llist + AU_DFREE_KFREE);
22740 +static inline void au_free_page(void *p)
22742 + free_page((unsigned long)p);
22745 +static inline void au_delayed_free_page(unsigned long addr)
22747 + AU_DFREE_BODY((void *)addr, au_dfree.llist + AU_DFREE_FREE_PAGE);
22750 +#endif /* __KERNEL__ */
22751 +#endif /* __AUFS_MODULE_H__ */
22752 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22753 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22754 +++ linux/fs/aufs/mvdown.c 2017-05-06 22:16:52.781553511 +0200
22757 + * Copyright (C) 2011-2017 Junjiro R. Okajima
22759 + * This program, aufs is free software; you can redistribute it and/or modify
22760 + * it under the terms of the GNU General Public License as published by
22761 + * the Free Software Foundation; either version 2 of the License, or
22762 + * (at your option) any later version.
22764 + * This program is distributed in the hope that it will be useful,
22765 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22767 + * GNU General Public License for more details.
22769 + * You should have received a copy of the GNU General Public License
22770 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22774 + * move-down, opposite of copy-up
22779 +struct au_mvd_args {
22781 + struct super_block *h_sb;
22782 + struct dentry *h_parent;
22783 + struct au_hinode *hdir;
22784 + struct inode *h_dir, *h_inode;
22785 + struct au_pin pin;
22786 + } info[AUFS_MVDOWN_NARRAY];
22788 + struct aufs_mvdown mvdown;
22789 + struct dentry *dentry, *parent;
22790 + struct inode *inode, *dir;
22791 + struct super_block *sb;
22792 + aufs_bindex_t bopq, bwh, bfound;
22793 + unsigned char rename_lock;
22796 +#define mvd_errno mvdown.au_errno
22797 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22798 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22799 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22800 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22802 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22803 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22804 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22805 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22806 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22807 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22809 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22810 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22811 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22812 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22813 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22814 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22816 +#define AU_MVD_PR(flag, ...) do { \
22818 + pr_err(__VA_ARGS__); \
22821 +static int find_lower_writable(struct au_mvd_args *a)
22823 + struct super_block *sb;
22824 + aufs_bindex_t bindex, bbot;
22825 + struct au_branch *br;
22828 + bindex = a->mvd_bsrc;
22829 + bbot = au_sbbot(sb);
22830 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22831 + for (bindex++; bindex <= bbot; bindex++) {
22832 + br = au_sbr(sb, bindex);
22833 + if (au_br_fhsm(br->br_perm)
22834 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22837 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22838 + for (bindex++; bindex <= bbot; bindex++) {
22839 + br = au_sbr(sb, bindex);
22840 + if (!au_br_rdonly(br))
22844 + for (bindex++; bindex <= bbot; bindex++) {
22845 + br = au_sbr(sb, bindex);
22846 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22847 + if (au_br_rdonly(br))
22849 + |= AUFS_MVDOWN_ROLOWER_R;
22857 +/* make the parent dir on bdst */
22858 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22863 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22864 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22865 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22866 + a->mvd_h_dst_parent = NULL;
22867 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22868 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22869 + if (!a->mvd_h_dst_parent) {
22870 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22871 + if (unlikely(err)) {
22872 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22875 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22883 +/* lock them all */
22884 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22887 + struct dentry *h_trap;
22889 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22890 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22891 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22892 + au_opt_udba(a->sb),
22893 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22895 + if (unlikely(err)) {
22896 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22900 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22901 + a->rename_lock = 0;
22902 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22903 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22904 + au_opt_udba(a->sb),
22905 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22906 + err = au_do_pin(&a->mvd_pin_src);
22908 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22909 + if (unlikely(err)) {
22910 + AU_MVD_PR(dmsg, "pin_src failed\n");
22913 + goto out; /* success */
22916 + a->rename_lock = 1;
22917 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22918 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22919 + au_opt_udba(a->sb),
22920 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22922 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22923 + if (unlikely(err)) {
22924 + AU_MVD_PR(dmsg, "pin_src failed\n");
22925 + au_pin_hdir_lock(&a->mvd_pin_dst);
22928 + au_pin_hdir_unlock(&a->mvd_pin_src);
22929 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22930 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22932 + err = (h_trap != a->mvd_h_src_parent);
22934 + err = (h_trap != a->mvd_h_dst_parent);
22936 + BUG_ON(err); /* it should never happen */
22937 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22940 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22941 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22942 + au_pin_hdir_lock(&a->mvd_pin_src);
22943 + au_unpin(&a->mvd_pin_src);
22944 + au_pin_hdir_lock(&a->mvd_pin_dst);
22947 + goto out; /* success */
22950 + au_unpin(&a->mvd_pin_dst);
22956 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22958 + if (!a->rename_lock)
22959 + au_unpin(&a->mvd_pin_src);
22961 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22962 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22963 + au_pin_hdir_lock(&a->mvd_pin_src);
22964 + au_unpin(&a->mvd_pin_src);
22965 + au_pin_hdir_lock(&a->mvd_pin_dst);
22967 + au_unpin(&a->mvd_pin_dst);
22970 +/* copy-down the file */
22971 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22974 + struct au_cp_generic cpg = {
22975 + .dentry = a->dentry,
22976 + .bdst = a->mvd_bdst,
22977 + .bsrc = a->mvd_bsrc,
22979 + .pin = &a->mvd_pin_dst,
22980 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22983 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22984 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22985 + au_fset_cpup(cpg.flags, OVERWRITE);
22986 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22987 + au_fset_cpup(cpg.flags, RWDST);
22988 + err = au_sio_cpdown_simple(&cpg);
22989 + if (unlikely(err))
22990 + AU_MVD_PR(dmsg, "cpdown failed\n");
22997 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
23000 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
23003 + struct path h_path;
23004 + struct au_branch *br;
23005 + struct inode *delegated;
23007 + br = au_sbr(a->sb, a->mvd_bdst);
23008 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
23009 + err = PTR_ERR(h_path.dentry);
23010 + if (IS_ERR(h_path.dentry)) {
23011 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
23016 + if (d_is_positive(h_path.dentry)) {
23017 + h_path.mnt = au_br_mnt(br);
23018 + delegated = NULL;
23019 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
23020 + &delegated, /*force*/0);
23021 + if (unlikely(err == -EWOULDBLOCK)) {
23022 + pr_warn("cannot retry for NFSv4 delegation"
23023 + " for an internal unlink\n");
23026 + if (unlikely(err))
23027 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
23029 + dput(h_path.dentry);
23037 + * unlink the topmost h_dentry
23039 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
23042 + struct path h_path;
23043 + struct inode *delegated;
23045 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
23046 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
23047 + delegated = NULL;
23048 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
23049 + if (unlikely(err == -EWOULDBLOCK)) {
23050 + pr_warn("cannot retry for NFSv4 delegation"
23051 + " for an internal unlink\n");
23054 + if (unlikely(err))
23055 + AU_MVD_PR(dmsg, "unlink failed\n");
23061 +/* Since mvdown succeeded, we ignore an error of this function */
23062 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
23065 + struct au_branch *br;
23067 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
23068 + br = au_sbr(a->sb, a->mvd_bsrc);
23069 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
23071 + br = au_sbr(a->sb, a->mvd_bdst);
23072 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
23073 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
23076 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
23078 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
23082 + * copy-down the file and unlink the bsrc file.
23083 + * - unlink the bdst whout if exist
23084 + * - copy-down the file (with whtmp name and rename)
23085 + * - unlink the bsrc file
23087 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
23091 + err = au_do_mkdir(dmsg, a);
23093 + err = au_do_lock(dmsg, a);
23094 + if (unlikely(err))
23098 + * do not revert the activities we made on bdst since they should be
23099 + * harmless in aufs.
23102 + err = au_do_cpdown(dmsg, a);
23104 + err = au_do_unlink_wh(dmsg, a);
23105 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
23106 + err = au_do_unlink(dmsg, a);
23107 + if (unlikely(err))
23110 + AuDbg("%pd2, 0x%x, %d --> %d\n",
23111 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
23112 + if (find_lower_writable(a) < 0)
23113 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
23115 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
23116 + au_do_stfs(dmsg, a);
23118 + /* maintain internal array */
23119 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
23120 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
23121 + au_set_dbtop(a->dentry, a->mvd_bdst);
23122 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
23123 + au_set_ibtop(a->inode, a->mvd_bdst);
23125 + /* hide the lower */
23126 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
23127 + au_set_dbbot(a->dentry, a->mvd_bsrc);
23128 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
23129 + au_set_ibbot(a->inode, a->mvd_bsrc);
23131 + if (au_dbbot(a->dentry) < a->mvd_bdst)
23132 + au_set_dbbot(a->dentry, a->mvd_bdst);
23133 + if (au_ibbot(a->inode) < a->mvd_bdst)
23134 + au_set_ibbot(a->inode, a->mvd_bdst);
23137 + au_do_unlock(dmsg, a);
23143 +/* ---------------------------------------------------------------------- */
23145 +/* make sure the file is idle */
23146 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
23148 + int err, plinked;
23151 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
23152 + if (au_dbtop(a->dentry) == a->mvd_bsrc
23153 + && au_dcount(a->dentry) == 1
23154 + && atomic_read(&a->inode->i_count) == 1
23155 + /* && a->mvd_h_src_inode->i_nlink == 1 */
23156 + && (!plinked || !au_plink_test(a->inode))
23157 + && a->inode->i_nlink == 1)
23162 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
23163 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
23164 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
23165 + a->mvd_h_src_inode->i_nlink,
23166 + plinked, plinked ? au_plink_test(a->inode) : 0);
23173 +/* make sure the parent dir is fine */
23174 +static int au_mvd_args_parent(const unsigned char dmsg,
23175 + struct au_mvd_args *a)
23178 + aufs_bindex_t bindex;
23181 + if (unlikely(au_alive_dir(a->parent))) {
23183 + AU_MVD_PR(dmsg, "parent dir is dead\n");
23187 + a->bopq = au_dbdiropq(a->parent);
23188 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
23189 + AuDbg("b%d\n", bindex);
23190 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
23191 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
23193 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
23194 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
23195 + a->bopq, a->mvd_bdst);
23203 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23204 + struct au_mvd_args *a)
23207 + struct au_dinfo *dinfo, *tmp;
23209 + /* lookup the next lower positive entry */
23211 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23212 + if (unlikely(!tmp))
23217 + dinfo = au_di(a->dentry);
23218 + au_di_cp(tmp, dinfo);
23219 + au_di_swap(tmp, dinfo);
23221 + /* returns the number of positive dentries */
23222 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23223 + /* AuLkup_IGNORE_PERM */ 0);
23225 + a->bwh = au_dbwh(a->dentry);
23226 + else if (err > 0)
23227 + a->bfound = au_dbtop(a->dentry);
23229 + au_di_swap(tmp, dinfo);
23230 + au_rw_write_unlock(&tmp->di_rwsem);
23232 + if (unlikely(err < 0))
23233 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23236 + * here, we have these cases.
23238 + * no positive dentry under bsrc. there are more sub-cases.
23240 + * there no whiteout, we can safely move-down.
23243 + * bsrc < bwh && bwh < bdst
23244 + * there is a whiteout on RO branch. cannot proceed.
23246 + * there is a whiteout on the RW target branch. it should
23249 + * there is a whiteout somewhere unrelated branch.
23250 + * -1 < bfound && bfound <= bsrc
23253 + * found, but it is on RO branch between bsrc and bdst. cannot
23256 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23259 + * found, after we create the file on bdst, it will be hidden.
23262 + AuDebugOn(a->bfound == -1
23264 + && a->bwh <= a->mvd_bsrc);
23265 + AuDebugOn(-1 < a->bfound
23266 + && a->bfound <= a->mvd_bsrc);
23269 + if (a->bfound == -1
23270 + && a->mvd_bsrc < a->bwh
23272 + && a->bwh < a->mvd_bdst) {
23273 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23274 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23275 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23277 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23278 + a->mvd_errno = EAU_MVDOWN_UPPER;
23279 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23280 + a->mvd_bdst, a->bfound);
23284 + err = 0; /* success */
23291 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23296 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23297 + && a->bfound == a->mvd_bdst)
23303 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23306 + struct au_branch *br;
23309 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23313 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23314 + a->mvd_bsrc = au_ibtop(a->inode);
23316 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23317 + if (unlikely(a->mvd_bsrc < 0
23318 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23319 + || au_dbbot(a->dentry) < a->mvd_bsrc
23320 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23321 + || (a->mvd_bsrc < au_ibtop(a->inode)
23322 + || au_ibbot(a->inode) < a->mvd_bsrc
23323 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23324 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23325 + AU_MVD_PR(dmsg, "no upper\n");
23329 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23330 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23331 + AU_MVD_PR(dmsg, "on the bottom\n");
23334 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23335 + br = au_sbr(a->sb, a->mvd_bsrc);
23336 + err = au_br_rdonly(br);
23337 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23338 + if (unlikely(err))
23340 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23341 + || IS_APPEND(a->mvd_h_src_inode))) {
23343 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23349 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23350 + a->mvd_bdst = find_lower_writable(a);
23351 + if (unlikely(a->mvd_bdst < 0)) {
23352 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23353 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23357 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23358 + if (unlikely(a->mvd_bdst < 0
23359 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23360 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23361 + AU_MVD_PR(dmsg, "no lower brid\n");
23366 + err = au_mvd_args_busy(dmsg, a);
23368 + err = au_mvd_args_parent(dmsg, a);
23370 + err = au_mvd_args_intermediate(dmsg, a);
23372 + err = au_mvd_args_exist(dmsg, a);
23374 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23381 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23384 + unsigned char dmsg;
23385 + struct au_mvd_args *args;
23386 + struct inode *inode;
23388 + inode = d_inode(dentry);
23390 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23394 + args = kmalloc(sizeof(*args), GFP_NOFS);
23395 + if (unlikely(!args))
23398 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23400 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23401 + if (unlikely(err)) {
23406 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23407 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23408 + args->mvdown.au_errno = 0;
23409 + args->dentry = dentry;
23410 + args->inode = inode;
23411 + args->sb = dentry->d_sb;
23414 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23415 + args->parent = dget_parent(dentry);
23416 + args->dir = d_inode(args->parent);
23417 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23418 + dput(args->parent);
23419 + if (unlikely(args->parent != dentry->d_parent)) {
23420 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23424 + inode_lock_nested(inode, I_MUTEX_CHILD);
23425 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23426 + if (unlikely(err))
23429 + di_write_lock_parent(args->parent);
23430 + err = au_mvd_args(dmsg, args);
23431 + if (unlikely(err))
23434 + err = au_do_mvdown(dmsg, args);
23435 + if (unlikely(err))
23438 + au_cpup_attr_timesizes(args->dir);
23439 + au_cpup_attr_timesizes(inode);
23440 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23441 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23442 + /* au_digen_dec(dentry); */
23445 + di_write_unlock(args->parent);
23446 + aufs_read_unlock(dentry, AuLock_DW);
23448 + inode_unlock(inode);
23450 + inode_unlock(args->dir);
23452 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23455 + au_delayed_kfree(args);
23460 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23461 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23462 +++ linux/fs/aufs/opts.c 2017-05-06 22:16:52.781553511 +0200
23465 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23467 + * This program, aufs is free software; you can redistribute it and/or modify
23468 + * it under the terms of the GNU General Public License as published by
23469 + * the Free Software Foundation; either version 2 of the License, or
23470 + * (at your option) any later version.
23472 + * This program is distributed in the hope that it will be useful,
23473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23475 + * GNU General Public License for more details.
23477 + * You should have received a copy of the GNU General Public License
23478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23482 + * mount options/flags
23485 +#include <linux/namei.h>
23486 +#include <linux/types.h> /* a distribution requires */
23487 +#include <linux/parser.h>
23490 +/* ---------------------------------------------------------------------- */
23494 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23495 + Opt_idel, Opt_imod,
23496 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23497 + Opt_rdblk_def, Opt_rdhash_def,
23498 + Opt_xino, Opt_noxino,
23499 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23500 + Opt_trunc_xino_path, Opt_itrunc_xino,
23501 + Opt_trunc_xib, Opt_notrunc_xib,
23502 + Opt_shwh, Opt_noshwh,
23503 + Opt_plink, Opt_noplink, Opt_list_plink,
23505 + Opt_dio, Opt_nodio,
23506 + Opt_diropq_a, Opt_diropq_w,
23507 + Opt_warn_perm, Opt_nowarn_perm,
23508 + Opt_wbr_copyup, Opt_wbr_create,
23510 + Opt_verbose, Opt_noverbose,
23511 + Opt_sum, Opt_nosum, Opt_wsum,
23512 + Opt_dirperm1, Opt_nodirperm1,
23513 + Opt_acl, Opt_noacl,
23514 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23517 +static match_table_t options = {
23518 + {Opt_br, "br=%s"},
23519 + {Opt_br, "br:%s"},
23521 + {Opt_add, "add=%d:%s"},
23522 + {Opt_add, "add:%d:%s"},
23523 + {Opt_add, "ins=%d:%s"},
23524 + {Opt_add, "ins:%d:%s"},
23525 + {Opt_append, "append=%s"},
23526 + {Opt_append, "append:%s"},
23527 + {Opt_prepend, "prepend=%s"},
23528 + {Opt_prepend, "prepend:%s"},
23530 + {Opt_del, "del=%s"},
23531 + {Opt_del, "del:%s"},
23532 + /* {Opt_idel, "idel:%d"}, */
23533 + {Opt_mod, "mod=%s"},
23534 + {Opt_mod, "mod:%s"},
23535 + /* {Opt_imod, "imod:%d:%s"}, */
23537 + {Opt_dirwh, "dirwh=%d"},
23539 + {Opt_xino, "xino=%s"},
23540 + {Opt_noxino, "noxino"},
23541 + {Opt_trunc_xino, "trunc_xino"},
23542 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23543 + {Opt_notrunc_xino, "notrunc_xino"},
23544 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23545 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23546 + /* {Opt_zxino, "zxino=%s"}, */
23547 + {Opt_trunc_xib, "trunc_xib"},
23548 + {Opt_notrunc_xib, "notrunc_xib"},
23550 +#ifdef CONFIG_PROC_FS
23551 + {Opt_plink, "plink"},
23553 + {Opt_ignore_silent, "plink"},
23556 + {Opt_noplink, "noplink"},
23558 +#ifdef CONFIG_AUFS_DEBUG
23559 + {Opt_list_plink, "list_plink"},
23562 + {Opt_udba, "udba=%s"},
23564 + {Opt_dio, "dio"},
23565 + {Opt_nodio, "nodio"},
23567 +#ifdef CONFIG_AUFS_FHSM
23568 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23570 + {Opt_ignore_silent, "fhsm_sec=%d"},
23573 + {Opt_diropq_a, "diropq=always"},
23574 + {Opt_diropq_a, "diropq=a"},
23575 + {Opt_diropq_w, "diropq=whiteouted"},
23576 + {Opt_diropq_w, "diropq=w"},
23578 + {Opt_warn_perm, "warn_perm"},
23579 + {Opt_nowarn_perm, "nowarn_perm"},
23581 + /* keep them temporary */
23582 + {Opt_ignore_silent, "nodlgt"},
23583 + {Opt_ignore_silent, "clean_plink"},
23585 +#ifdef CONFIG_AUFS_SHWH
23586 + {Opt_shwh, "shwh"},
23588 + {Opt_noshwh, "noshwh"},
23590 + {Opt_dirperm1, "dirperm1"},
23591 + {Opt_nodirperm1, "nodirperm1"},
23593 + {Opt_verbose, "verbose"},
23594 + {Opt_verbose, "v"},
23595 + {Opt_noverbose, "noverbose"},
23596 + {Opt_noverbose, "quiet"},
23597 + {Opt_noverbose, "q"},
23598 + {Opt_noverbose, "silent"},
23600 + {Opt_sum, "sum"},
23601 + {Opt_nosum, "nosum"},
23602 + {Opt_wsum, "wsum"},
23604 + {Opt_rdcache, "rdcache=%d"},
23605 + {Opt_rdblk, "rdblk=%d"},
23606 + {Opt_rdblk_def, "rdblk=def"},
23607 + {Opt_rdhash, "rdhash=%d"},
23608 + {Opt_rdhash_def, "rdhash=def"},
23610 + {Opt_wbr_create, "create=%s"},
23611 + {Opt_wbr_create, "create_policy=%s"},
23612 + {Opt_wbr_copyup, "cpup=%s"},
23613 + {Opt_wbr_copyup, "copyup=%s"},
23614 + {Opt_wbr_copyup, "copyup_policy=%s"},
23616 + /* generic VFS flag */
23617 +#ifdef CONFIG_FS_POSIX_ACL
23618 + {Opt_acl, "acl"},
23619 + {Opt_noacl, "noacl"},
23621 + {Opt_ignore_silent, "acl"},
23622 + {Opt_ignore_silent, "noacl"},
23625 + /* internal use for the scripts */
23626 + {Opt_ignore_silent, "si=%s"},
23628 + {Opt_br, "dirs=%s"},
23629 + {Opt_ignore, "debug=%d"},
23630 + {Opt_ignore, "delete=whiteout"},
23631 + {Opt_ignore, "delete=all"},
23632 + {Opt_ignore, "imap=%s"},
23634 + /* temporary workaround, due to old mount(8)? */
23635 + {Opt_ignore_silent, "relatime"},
23640 +/* ---------------------------------------------------------------------- */
23642 +static const char *au_parser_pattern(int val, match_table_t tbl)
23644 + struct match_token *p;
23647 + while (p->pattern) {
23648 + if (p->token == val)
23649 + return p->pattern;
23656 +static const char *au_optstr(int *val, match_table_t tbl)
23658 + struct match_token *p;
23665 + while (p->pattern) {
23667 + && (v & p->token) == p->token) {
23668 + *val &= ~p->token;
23669 + return p->pattern;
23678 +/* ---------------------------------------------------------------------- */
23680 +static match_table_t brperm = {
23681 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23682 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23683 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23687 +static match_table_t brattr = {
23689 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23690 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23691 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23692 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23693 +#ifdef CONFIG_AUFS_FHSM
23694 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23696 +#ifdef CONFIG_AUFS_XATTR
23697 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23698 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23699 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23700 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23701 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23702 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23705 + /* ro/rr branch */
23706 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23709 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23710 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23715 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23722 + p = strchr(str, '+');
23725 + v = match_token(str, table, args);
23727 + if (v & AuBrAttr_CMOO_Mask)
23728 + attr &= ~AuBrAttr_CMOO_Mask;
23733 + pr_warn("ignored branch attribute %s\n", str);
23743 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23751 + p = au_optstr(&perm, brattr);
23754 + memcpy(q, p, sz + 1);
23760 + p = au_optstr(&perm, brattr);
23764 + memcpy(q, p, sz + 1);
23770 + return q - str->a;
23773 +static int noinline_for_stack br_perm_val(char *perm)
23775 + int val, bad, sz;
23777 + substring_t args[MAX_OPT_ARGS];
23778 + au_br_perm_str_t attr;
23780 + p = strchr(perm, '+');
23783 + val = match_token(perm, brperm, args);
23787 + pr_warn("ignored branch permission %s\n", perm);
23788 + val = AuBrPerm_RO;
23794 + val |= br_attr_val(p + 1, brattr, args);
23797 + switch (val & AuBrPerm_Mask) {
23798 + case AuBrPerm_RO:
23799 + case AuBrPerm_RR:
23800 + bad = val & AuBrWAttr_Mask;
23801 + val &= ~AuBrWAttr_Mask;
23803 + case AuBrPerm_RW:
23804 + bad = val & AuBrRAttr_Mask;
23805 + val &= ~AuBrRAttr_Mask;
23810 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23811 + * does not treat it as an error, just warning.
23812 + * this is a tiny guard for the user operation.
23814 + if (val & AuBrAttr_UNPIN) {
23815 + bad |= AuBrAttr_UNPIN;
23816 + val &= ~AuBrAttr_UNPIN;
23819 + if (unlikely(bad)) {
23820 + sz = au_do_optstr_br_attr(&attr, bad);
23822 + pr_warn("ignored branch attribute %s\n", attr.a);
23829 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23831 + au_br_perm_str_t attr;
23837 + p = au_optstr(&perm, brperm);
23838 + AuDebugOn(!p || !*p);
23840 + memcpy(q, p, sz + 1);
23843 + sz = au_do_optstr_br_attr(&attr, perm);
23846 + memcpy(q, attr.a, sz + 1);
23849 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23852 +/* ---------------------------------------------------------------------- */
23854 +static match_table_t udbalevel = {
23855 + {AuOpt_UDBA_REVAL, "reval"},
23856 + {AuOpt_UDBA_NONE, "none"},
23857 +#ifdef CONFIG_AUFS_HNOTIFY
23858 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23859 +#ifdef CONFIG_AUFS_HFSNOTIFY
23860 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23866 +static int noinline_for_stack udba_val(char *str)
23868 + substring_t args[MAX_OPT_ARGS];
23870 + return match_token(str, udbalevel, args);
23873 +const char *au_optstr_udba(int udba)
23875 + return au_parser_pattern(udba, udbalevel);
23878 +/* ---------------------------------------------------------------------- */
23880 +static match_table_t au_wbr_create_policy = {
23881 + {AuWbrCreate_TDP, "tdp"},
23882 + {AuWbrCreate_TDP, "top-down-parent"},
23883 + {AuWbrCreate_RR, "rr"},
23884 + {AuWbrCreate_RR, "round-robin"},
23885 + {AuWbrCreate_MFS, "mfs"},
23886 + {AuWbrCreate_MFS, "most-free-space"},
23887 + {AuWbrCreate_MFSV, "mfs:%d"},
23888 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23890 + /* top-down regardless the parent, and then mfs */
23891 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23892 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23894 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23895 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23896 + {AuWbrCreate_PMFS, "pmfs"},
23897 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23898 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23899 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23904 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23905 + struct au_opt_wbr_create *create)
23908 + unsigned long long ull;
23911 + if (!match_u64(arg, &ull))
23912 + create->mfsrr_watermark = ull;
23914 + pr_err("bad integer in %s\n", str);
23921 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23922 + struct au_opt_wbr_create *create)
23927 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23928 + create->mfs_second = n;
23930 + pr_err("bad integer in %s\n", str);
23937 +static int noinline_for_stack
23938 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23941 + substring_t args[MAX_OPT_ARGS];
23943 + err = match_token(str, au_wbr_create_policy, args);
23944 + create->wbr_create = err;
23946 + case AuWbrCreate_MFSRRV:
23947 + case AuWbrCreate_TDMFSV:
23948 + case AuWbrCreate_PMFSRRV:
23949 + e = au_wbr_mfs_wmark(&args[0], str, create);
23951 + e = au_wbr_mfs_sec(&args[1], str, create);
23955 + case AuWbrCreate_MFSRR:
23956 + case AuWbrCreate_TDMFS:
23957 + case AuWbrCreate_PMFSRR:
23958 + e = au_wbr_mfs_wmark(&args[0], str, create);
23959 + if (unlikely(e)) {
23964 + case AuWbrCreate_MFS:
23965 + case AuWbrCreate_PMFS:
23966 + create->mfs_second = AUFS_MFS_DEF_SEC;
23968 + case AuWbrCreate_MFSV:
23969 + case AuWbrCreate_PMFSV:
23970 + e = au_wbr_mfs_sec(&args[0], str, create);
23979 +const char *au_optstr_wbr_create(int wbr_create)
23981 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23984 +static match_table_t au_wbr_copyup_policy = {
23985 + {AuWbrCopyup_TDP, "tdp"},
23986 + {AuWbrCopyup_TDP, "top-down-parent"},
23987 + {AuWbrCopyup_BUP, "bup"},
23988 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23989 + {AuWbrCopyup_BU, "bu"},
23990 + {AuWbrCopyup_BU, "bottom-up"},
23994 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23996 + substring_t args[MAX_OPT_ARGS];
23998 + return match_token(str, au_wbr_copyup_policy, args);
24001 +const char *au_optstr_wbr_copyup(int wbr_copyup)
24003 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
24006 +/* ---------------------------------------------------------------------- */
24008 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
24010 +static void dump_opts(struct au_opts *opts)
24012 +#ifdef CONFIG_AUFS_DEBUG
24013 + /* reduce stack space */
24015 + struct au_opt_add *add;
24016 + struct au_opt_del *del;
24017 + struct au_opt_mod *mod;
24018 + struct au_opt_xino *xino;
24019 + struct au_opt_xino_itrunc *xino_itrunc;
24020 + struct au_opt_wbr_create *create;
24022 + struct au_opt *opt;
24025 + while (opt->type != Opt_tail) {
24026 + switch (opt->type) {
24028 + u.add = &opt->add;
24029 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
24030 + u.add->bindex, u.add->pathname, u.add->perm,
24031 + u.add->path.dentry);
24035 + u.del = &opt->del;
24036 + AuDbg("del {%s, %p}\n",
24037 + u.del->pathname, u.del->h_path.dentry);
24041 + u.mod = &opt->mod;
24042 + AuDbg("mod {%s, 0x%x, %p}\n",
24043 + u.mod->path, u.mod->perm, u.mod->h_root);
24046 + u.add = &opt->add;
24047 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
24048 + u.add->bindex, u.add->pathname, u.add->perm,
24049 + u.add->path.dentry);
24051 + case Opt_prepend:
24052 + u.add = &opt->add;
24053 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
24054 + u.add->bindex, u.add->pathname, u.add->perm,
24055 + u.add->path.dentry);
24058 + AuDbg("dirwh %d\n", opt->dirwh);
24060 + case Opt_rdcache:
24061 + AuDbg("rdcache %d\n", opt->rdcache);
24064 + AuDbg("rdblk %u\n", opt->rdblk);
24066 + case Opt_rdblk_def:
24067 + AuDbg("rdblk_def\n");
24070 + AuDbg("rdhash %u\n", opt->rdhash);
24072 + case Opt_rdhash_def:
24073 + AuDbg("rdhash_def\n");
24076 + u.xino = &opt->xino;
24077 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
24079 + case Opt_trunc_xino:
24080 + AuLabel(trunc_xino);
24082 + case Opt_notrunc_xino:
24083 + AuLabel(notrunc_xino);
24085 + case Opt_trunc_xino_path:
24086 + case Opt_itrunc_xino:
24087 + u.xino_itrunc = &opt->xino_itrunc;
24088 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
24093 + case Opt_trunc_xib:
24094 + AuLabel(trunc_xib);
24096 + case Opt_notrunc_xib:
24097 + AuLabel(notrunc_xib);
24105 + case Opt_dirperm1:
24106 + AuLabel(dirperm1);
24108 + case Opt_nodirperm1:
24109 + AuLabel(nodirperm1);
24114 + case Opt_noplink:
24115 + AuLabel(noplink);
24117 + case Opt_list_plink:
24118 + AuLabel(list_plink);
24121 + AuDbg("udba %d, %s\n",
24122 + opt->udba, au_optstr_udba(opt->udba));
24130 + case Opt_diropq_a:
24131 + AuLabel(diropq_a);
24133 + case Opt_diropq_w:
24134 + AuLabel(diropq_w);
24136 + case Opt_warn_perm:
24137 + AuLabel(warn_perm);
24139 + case Opt_nowarn_perm:
24140 + AuLabel(nowarn_perm);
24142 + case Opt_verbose:
24143 + AuLabel(verbose);
24145 + case Opt_noverbose:
24146 + AuLabel(noverbose);
24157 + case Opt_wbr_create:
24158 + u.create = &opt->wbr_create;
24159 + AuDbg("create %d, %s\n", u.create->wbr_create,
24160 + au_optstr_wbr_create(u.create->wbr_create));
24161 + switch (u.create->wbr_create) {
24162 + case AuWbrCreate_MFSV:
24163 + case AuWbrCreate_PMFSV:
24164 + AuDbg("%d sec\n", u.create->mfs_second);
24166 + case AuWbrCreate_MFSRR:
24167 + case AuWbrCreate_TDMFS:
24168 + AuDbg("%llu watermark\n",
24169 + u.create->mfsrr_watermark);
24171 + case AuWbrCreate_MFSRRV:
24172 + case AuWbrCreate_TDMFSV:
24173 + case AuWbrCreate_PMFSRRV:
24174 + AuDbg("%llu watermark, %d sec\n",
24175 + u.create->mfsrr_watermark,
24176 + u.create->mfs_second);
24180 + case Opt_wbr_copyup:
24181 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
24182 + au_optstr_wbr_copyup(opt->wbr_copyup));
24184 + case Opt_fhsm_sec:
24185 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24201 +void au_opts_free(struct au_opts *opts)
24203 + struct au_opt *opt;
24206 + while (opt->type != Opt_tail) {
24207 + switch (opt->type) {
24210 + case Opt_prepend:
24211 + path_put(&opt->add.path);
24215 + path_put(&opt->del.h_path);
24219 + dput(opt->mod.h_root);
24222 + fput(opt->xino.file);
24229 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24230 + aufs_bindex_t bindex)
24233 + struct au_opt_add *add = &opt->add;
24236 + add->bindex = bindex;
24237 + add->perm = AuBrPerm_RO;
24238 + add->pathname = opt_str;
24239 + p = strchr(opt_str, '=');
24243 + add->perm = br_perm_val(p);
24246 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24249 + add->perm = AuBrPerm_RO;
24250 + if (au_test_fs_rr(add->path.dentry->d_sb))
24251 + add->perm = AuBrPerm_RR;
24252 + else if (!bindex && !(sb_flags & MS_RDONLY))
24253 + add->perm = AuBrPerm_RW;
24255 + opt->type = Opt_add;
24258 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24265 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24269 + del->pathname = args[0].from;
24270 + AuDbg("del path %s\n", del->pathname);
24272 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24273 + if (unlikely(err))
24274 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24279 +#if 0 /* reserved for future use */
24280 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24281 + struct au_opt_del *del, substring_t args[])
24284 + struct dentry *root;
24287 + root = sb->s_root;
24288 + aufs_read_lock(root, AuLock_FLUSH);
24289 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24290 + pr_err("out of bounds, %d\n", bindex);
24295 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24296 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24299 + aufs_read_unlock(root, !AuLock_IR);
24304 +static int noinline_for_stack
24305 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24308 + struct path path;
24312 + mod->path = args[0].from;
24313 + p = strchr(mod->path, '=');
24314 + if (unlikely(!p)) {
24315 + pr_err("no permssion %s\n", args[0].from);
24320 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24321 + if (unlikely(err)) {
24322 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24326 + mod->perm = br_perm_val(p);
24327 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24328 + mod->h_root = dget(path.dentry);
24335 +#if 0 /* reserved for future use */
24336 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24337 + struct au_opt_mod *mod, substring_t args[])
24340 + struct dentry *root;
24343 + root = sb->s_root;
24344 + aufs_read_lock(root, AuLock_FLUSH);
24345 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24346 + pr_err("out of bounds, %d\n", bindex);
24351 + mod->perm = br_perm_val(args[1].from);
24352 + AuDbg("mod path %s, perm 0x%x, %s\n",
24353 + mod->path, mod->perm, args[1].from);
24354 + mod->h_root = dget(au_h_dptr(root, bindex));
24357 + aufs_read_unlock(root, !AuLock_IR);
24362 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24363 + substring_t args[])
24366 + struct file *file;
24368 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24369 + err = PTR_ERR(file);
24370 + if (IS_ERR(file))
24374 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24376 + pr_err("%s must be outside\n", args[0].from);
24381 + xino->file = file;
24382 + xino->path = args[0].from;
24388 +static int noinline_for_stack
24389 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24390 + struct au_opt_xino_itrunc *xino_itrunc,
24391 + substring_t args[])
24394 + aufs_bindex_t bbot, bindex;
24395 + struct path path;
24396 + struct dentry *root;
24398 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24399 + if (unlikely(err)) {
24400 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24404 + xino_itrunc->bindex = -1;
24405 + root = sb->s_root;
24406 + aufs_read_lock(root, AuLock_FLUSH);
24407 + bbot = au_sbbot(sb);
24408 + for (bindex = 0; bindex <= bbot; bindex++) {
24409 + if (au_h_dptr(root, bindex) == path.dentry) {
24410 + xino_itrunc->bindex = bindex;
24414 + aufs_read_unlock(root, !AuLock_IR);
24417 + if (unlikely(xino_itrunc->bindex < 0)) {
24418 + pr_err("no such branch %s\n", args[0].from);
24426 +/* called without aufs lock */
24427 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24429 + int err, n, token;
24430 + aufs_bindex_t bindex;
24431 + unsigned char skipped;
24432 + struct dentry *root;
24433 + struct au_opt *opt, *opt_tail;
24435 + /* reduce the stack space */
24437 + struct au_opt_xino_itrunc *xino_itrunc;
24438 + struct au_opt_wbr_create *create;
24441 + substring_t args[MAX_OPT_ARGS];
24445 + a = kmalloc(sizeof(*a), GFP_NOFS);
24446 + if (unlikely(!a))
24449 + root = sb->s_root;
24453 + opt_tail = opt + opts->max_opt - 1;
24454 + opt->type = Opt_tail;
24455 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24458 + token = match_token(opt_str, options, a->args);
24462 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24464 + err = opt_add(opt, opt_str, opts->sb_flags,
24466 + if (unlikely(!err && ++opt > opt_tail)) {
24470 + opt->type = Opt_tail;
24475 + if (unlikely(match_int(&a->args[0], &n))) {
24476 + pr_err("bad integer in %s\n", opt_str);
24480 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24483 + opt->type = token;
24486 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24487 + /*dummy bindex*/1);
24489 + opt->type = token;
24491 + case Opt_prepend:
24492 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24495 + opt->type = token;
24498 + err = au_opts_parse_del(&opt->del, a->args);
24500 + opt->type = token;
24502 +#if 0 /* reserved for future use */
24504 + del->pathname = "(indexed)";
24505 + if (unlikely(match_int(&args[0], &n))) {
24506 + pr_err("bad integer in %s\n", opt_str);
24509 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24511 + opt->type = token;
24515 + err = au_opts_parse_mod(&opt->mod, a->args);
24517 + opt->type = token;
24519 +#ifdef IMOD /* reserved for future use */
24521 + u.mod->path = "(indexed)";
24522 + if (unlikely(match_int(&a->args[0], &n))) {
24523 + pr_err("bad integer in %s\n", opt_str);
24526 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24528 + opt->type = token;
24532 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24534 + opt->type = token;
24537 + case Opt_trunc_xino_path:
24538 + err = au_opts_parse_xino_itrunc_path
24539 + (sb, &opt->xino_itrunc, a->args);
24541 + opt->type = token;
24544 + case Opt_itrunc_xino:
24545 + u.xino_itrunc = &opt->xino_itrunc;
24546 + if (unlikely(match_int(&a->args[0], &n))) {
24547 + pr_err("bad integer in %s\n", opt_str);
24550 + u.xino_itrunc->bindex = n;
24551 + aufs_read_lock(root, AuLock_FLUSH);
24552 + if (n < 0 || au_sbbot(sb) < n) {
24553 + pr_err("out of bounds, %d\n", n);
24554 + aufs_read_unlock(root, !AuLock_IR);
24557 + aufs_read_unlock(root, !AuLock_IR);
24559 + opt->type = token;
24563 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24566 + opt->type = token;
24569 + case Opt_rdcache:
24570 + if (unlikely(match_int(&a->args[0], &n))) {
24571 + pr_err("bad integer in %s\n", opt_str);
24574 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24575 + pr_err("rdcache must be smaller than %d\n",
24576 + AUFS_RDCACHE_MAX);
24579 + opt->rdcache = n;
24581 + opt->type = token;
24584 + if (unlikely(match_int(&a->args[0], &n)
24586 + || n > KMALLOC_MAX_SIZE)) {
24587 + pr_err("bad integer in %s\n", opt_str);
24590 + if (unlikely(n && n < NAME_MAX)) {
24591 + pr_err("rdblk must be larger than %d\n",
24597 + opt->type = token;
24600 + if (unlikely(match_int(&a->args[0], &n)
24602 + || n * sizeof(struct hlist_head)
24603 + > KMALLOC_MAX_SIZE)) {
24604 + pr_err("bad integer in %s\n", opt_str);
24609 + opt->type = token;
24612 + case Opt_trunc_xino:
24613 + case Opt_notrunc_xino:
24615 + case Opt_trunc_xib:
24616 + case Opt_notrunc_xib:
24619 + case Opt_dirperm1:
24620 + case Opt_nodirperm1:
24622 + case Opt_noplink:
24623 + case Opt_list_plink:
24626 + case Opt_diropq_a:
24627 + case Opt_diropq_w:
24628 + case Opt_warn_perm:
24629 + case Opt_nowarn_perm:
24630 + case Opt_verbose:
24631 + case Opt_noverbose:
24635 + case Opt_rdblk_def:
24636 + case Opt_rdhash_def:
24640 + opt->type = token;
24644 + opt->udba = udba_val(a->args[0].from);
24645 + if (opt->udba >= 0) {
24647 + opt->type = token;
24649 + pr_err("wrong value, %s\n", opt_str);
24652 + case Opt_wbr_create:
24653 + u.create = &opt->wbr_create;
24654 + u.create->wbr_create
24655 + = au_wbr_create_val(a->args[0].from, u.create);
24656 + if (u.create->wbr_create >= 0) {
24658 + opt->type = token;
24660 + pr_err("wrong value, %s\n", opt_str);
24662 + case Opt_wbr_copyup:
24663 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24664 + if (opt->wbr_copyup >= 0) {
24666 + opt->type = token;
24668 + pr_err("wrong value, %s\n", opt_str);
24671 + case Opt_fhsm_sec:
24672 + if (unlikely(match_int(&a->args[0], &n)
24674 + pr_err("bad integer in %s\n", opt_str);
24677 + if (sysaufs_brs) {
24678 + opt->fhsm_second = n;
24679 + opt->type = token;
24681 + pr_warn("ignored %s\n", opt_str);
24686 + pr_warn("ignored %s\n", opt_str);
24688 + case Opt_ignore_silent:
24693 + pr_err("unknown option %s\n", opt_str);
24697 + if (!err && !skipped) {
24698 + if (unlikely(++opt > opt_tail)) {
24701 + opt->type = Opt_tail;
24704 + opt->type = Opt_tail;
24708 + au_delayed_kfree(a);
24710 + if (unlikely(err))
24711 + au_opts_free(opts);
24717 +static int au_opt_wbr_create(struct super_block *sb,
24718 + struct au_opt_wbr_create *create)
24721 + struct au_sbinfo *sbinfo;
24723 + SiMustWriteLock(sb);
24725 + err = 1; /* handled */
24726 + sbinfo = au_sbi(sb);
24727 + if (sbinfo->si_wbr_create_ops->fin) {
24728 + err = sbinfo->si_wbr_create_ops->fin(sb);
24733 + sbinfo->si_wbr_create = create->wbr_create;
24734 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24735 + switch (create->wbr_create) {
24736 + case AuWbrCreate_MFSRRV:
24737 + case AuWbrCreate_MFSRR:
24738 + case AuWbrCreate_TDMFS:
24739 + case AuWbrCreate_TDMFSV:
24740 + case AuWbrCreate_PMFSRR:
24741 + case AuWbrCreate_PMFSRRV:
24742 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24744 + case AuWbrCreate_MFS:
24745 + case AuWbrCreate_MFSV:
24746 + case AuWbrCreate_PMFS:
24747 + case AuWbrCreate_PMFSV:
24748 + sbinfo->si_wbr_mfs.mfs_expire
24749 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24753 + if (sbinfo->si_wbr_create_ops->init)
24754 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24761 + * plus: processed without an error
24762 + * zero: unprocessed
24764 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24765 + struct au_opts *opts)
24768 + struct au_sbinfo *sbinfo;
24770 + SiMustWriteLock(sb);
24772 + err = 1; /* handled */
24773 + sbinfo = au_sbi(sb);
24774 + switch (opt->type) {
24776 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24777 + sbinfo->si_mntflags |= opt->udba;
24778 + opts->given_udba |= opt->udba;
24782 + au_opt_set(sbinfo->si_mntflags, PLINK);
24784 + case Opt_noplink:
24785 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24786 + au_plink_put(sb, /*verbose*/1);
24787 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24789 + case Opt_list_plink:
24790 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24791 + au_plink_list(sb);
24795 + au_opt_set(sbinfo->si_mntflags, DIO);
24796 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24799 + au_opt_clr(sbinfo->si_mntflags, DIO);
24800 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24803 + case Opt_fhsm_sec:
24804 + au_fhsm_set(sbinfo, opt->fhsm_second);
24807 + case Opt_diropq_a:
24808 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24810 + case Opt_diropq_w:
24811 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24814 + case Opt_warn_perm:
24815 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24817 + case Opt_nowarn_perm:
24818 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24821 + case Opt_verbose:
24822 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24824 + case Opt_noverbose:
24825 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24829 + au_opt_set(sbinfo->si_mntflags, SUM);
24832 + au_opt_clr(sbinfo->si_mntflags, SUM);
24833 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24835 + au_opt_clr(sbinfo->si_mntflags, SUM);
24836 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24839 + case Opt_wbr_create:
24840 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24842 + case Opt_wbr_copyup:
24843 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24844 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24848 + sbinfo->si_dirwh = opt->dirwh;
24851 + case Opt_rdcache:
24852 + sbinfo->si_rdcache
24853 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24856 + sbinfo->si_rdblk = opt->rdblk;
24858 + case Opt_rdblk_def:
24859 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24862 + sbinfo->si_rdhash = opt->rdhash;
24864 + case Opt_rdhash_def:
24865 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24869 + au_opt_set(sbinfo->si_mntflags, SHWH);
24872 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24875 + case Opt_dirperm1:
24876 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24878 + case Opt_nodirperm1:
24879 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24882 + case Opt_trunc_xino:
24883 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24885 + case Opt_notrunc_xino:
24886 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24889 + case Opt_trunc_xino_path:
24890 + case Opt_itrunc_xino:
24891 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24896 + case Opt_trunc_xib:
24897 + au_fset_opts(opts->flags, TRUNC_XIB);
24899 + case Opt_notrunc_xib:
24900 + au_fclr_opts(opts->flags, TRUNC_XIB);
24904 + sb->s_flags |= MS_POSIXACL;
24907 + sb->s_flags &= ~MS_POSIXACL;
24919 + * returns tri-state.
24920 + * plus: processed without an error
24921 + * zero: unprocessed
24924 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24925 + struct au_opts *opts)
24927 + int err, do_refresh;
24930 + switch (opt->type) {
24932 + opt->add.bindex = au_sbbot(sb) + 1;
24933 + if (opt->add.bindex < 0)
24934 + opt->add.bindex = 0;
24936 + case Opt_prepend:
24937 + opt->add.bindex = 0;
24938 + add: /* indented label */
24940 + err = au_br_add(sb, &opt->add,
24941 + au_ftest_opts(opts->flags, REMOUNT));
24944 + au_fset_opts(opts->flags, REFRESH);
24950 + err = au_br_del(sb, &opt->del,
24951 + au_ftest_opts(opts->flags, REMOUNT));
24954 + au_fset_opts(opts->flags, TRUNC_XIB);
24955 + au_fset_opts(opts->flags, REFRESH);
24961 + err = au_br_mod(sb, &opt->mod,
24962 + au_ftest_opts(opts->flags, REMOUNT),
24967 + au_fset_opts(opts->flags, REFRESH);
24975 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24976 + struct au_opt_xino **opt_xino,
24977 + struct au_opts *opts)
24980 + aufs_bindex_t bbot, bindex;
24981 + struct dentry *root, *parent, *h_root;
24984 + switch (opt->type) {
24986 + err = au_xino_set(sb, &opt->xino,
24987 + !!au_ftest_opts(opts->flags, REMOUNT));
24988 + if (unlikely(err))
24991 + *opt_xino = &opt->xino;
24992 + au_xino_brid_set(sb, -1);
24994 + /* safe d_parent access */
24995 + parent = opt->xino.file->f_path.dentry->d_parent;
24996 + root = sb->s_root;
24997 + bbot = au_sbbot(sb);
24998 + for (bindex = 0; bindex <= bbot; bindex++) {
24999 + h_root = au_h_dptr(root, bindex);
25000 + if (h_root == parent) {
25001 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
25009 + au_xino_brid_set(sb, -1);
25010 + *opt_xino = (void *)-1;
25017 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25018 + unsigned int pending)
25021 + aufs_bindex_t bindex, bbot;
25022 + unsigned char do_plink, skip, do_free, can_no_dreval;
25023 + struct au_branch *br;
25024 + struct au_wbr *wbr;
25025 + struct dentry *root, *dentry;
25026 + struct inode *dir, *h_dir;
25027 + struct au_sbinfo *sbinfo;
25028 + struct au_hinode *hdir;
25030 + SiMustAnyLock(sb);
25032 + sbinfo = au_sbi(sb);
25033 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
25035 + if (!(sb_flags & MS_RDONLY)) {
25036 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
25037 + pr_warn("first branch should be rw\n");
25038 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
25039 + pr_warn_once("shwh should be used with ro\n");
25042 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
25043 + && !au_opt_test(sbinfo->si_mntflags, XINO))
25044 + pr_warn_once("udba=*notify requires xino\n");
25046 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
25047 + pr_warn_once("dirperm1 breaks the protection"
25048 + " by the permission bits on the lower branch\n");
25052 + root = sb->s_root;
25053 + dir = d_inode(root);
25054 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
25055 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
25057 + bbot = au_sbbot(sb);
25058 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
25060 + h_dir = au_h_iptr(dir, bindex);
25061 + br = au_sbr(sb, bindex);
25063 + if ((br->br_perm & AuBrAttr_ICEX)
25064 + && !h_dir->i_op->listxattr)
25065 + br->br_perm &= ~AuBrAttr_ICEX;
25067 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
25068 + && (au_br_sb(br)->s_flags & MS_NOSEC))
25069 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
25073 + wbr = br->br_wbr;
25075 + wbr_wh_read_lock(wbr);
25077 + if (!au_br_writable(br->br_perm)) {
25080 + || (!wbr->wbr_whbase
25081 + && !wbr->wbr_plink
25082 + && !wbr->wbr_orph));
25083 + } else if (!au_br_wh_linkable(br->br_perm)) {
25084 + /* skip = (!br->br_whbase && !br->br_orph); */
25085 + skip = (!wbr || !wbr->wbr_whbase);
25086 + if (skip && wbr) {
25088 + skip = !!wbr->wbr_plink;
25090 + skip = !wbr->wbr_plink;
25093 + /* skip = (br->br_whbase && br->br_ohph); */
25094 + skip = (wbr && wbr->wbr_whbase);
25097 + skip = !!wbr->wbr_plink;
25099 + skip = !wbr->wbr_plink;
25103 + wbr_wh_read_unlock(wbr);
25105 + if (can_no_dreval) {
25106 + dentry = br->br_path.dentry;
25107 + spin_lock(&dentry->d_lock);
25108 + if (dentry->d_flags &
25109 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
25110 + can_no_dreval = 0;
25111 + spin_unlock(&dentry->d_lock);
25114 + if (au_br_fhsm(br->br_perm)) {
25116 + AuDebugOn(!br->br_fhsm);
25122 + hdir = au_hi(dir, bindex);
25123 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
25125 + wbr_wh_write_lock(wbr);
25126 + err = au_wh_init(br, sb);
25128 + wbr_wh_write_unlock(wbr);
25129 + au_hn_inode_unlock(hdir);
25131 + if (!err && do_free) {
25133 + au_delayed_kfree(wbr);
25134 + br->br_wbr = NULL;
25138 + if (can_no_dreval)
25139 + au_fset_si(sbinfo, NO_DREVAL);
25141 + au_fclr_si(sbinfo, NO_DREVAL);
25144 + au_fset_si(sbinfo, FHSM);
25145 + for (bindex = bbot; bindex >= 0; bindex--) {
25146 + br = au_sbr(sb, bindex);
25147 + if (au_br_fhsm(br->br_perm)) {
25148 + au_fhsm_set_bottom(sb, bindex);
25153 + au_fclr_si(sbinfo, FHSM);
25154 + au_fhsm_set_bottom(sb, -1);
25160 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
25163 + unsigned int tmp;
25164 + aufs_bindex_t bindex, bbot;
25165 + struct au_opt *opt;
25166 + struct au_opt_xino *opt_xino, xino;
25167 + struct au_sbinfo *sbinfo;
25168 + struct au_branch *br;
25169 + struct inode *dir;
25171 + SiMustWriteLock(sb);
25176 + while (err >= 0 && opt->type != Opt_tail)
25177 + err = au_opt_simple(sb, opt++, opts);
25180 + else if (unlikely(err < 0))
25183 + /* disable xino and udba temporary */
25184 + sbinfo = au_sbi(sb);
25185 + tmp = sbinfo->si_mntflags;
25186 + au_opt_clr(sbinfo->si_mntflags, XINO);
25187 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25190 + while (err >= 0 && opt->type != Opt_tail)
25191 + err = au_opt_br(sb, opt++, opts);
25194 + else if (unlikely(err < 0))
25197 + bbot = au_sbbot(sb);
25198 + if (unlikely(bbot < 0)) {
25200 + pr_err("no branches\n");
25204 + if (au_opt_test(tmp, XINO))
25205 + au_opt_set(sbinfo->si_mntflags, XINO);
25207 + while (!err && opt->type != Opt_tail)
25208 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25209 + if (unlikely(err))
25212 + err = au_opts_verify(sb, sb->s_flags, tmp);
25213 + if (unlikely(err))
25216 + /* restore xino */
25217 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25218 + xino.file = au_xino_def(sb);
25219 + err = PTR_ERR(xino.file);
25220 + if (IS_ERR(xino.file))
25223 + err = au_xino_set(sb, &xino, /*remount*/0);
25225 + if (unlikely(err))
25229 + /* restore udba */
25230 + tmp &= AuOptMask_UDBA;
25231 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25232 + sbinfo->si_mntflags |= tmp;
25233 + bbot = au_sbbot(sb);
25234 + for (bindex = 0; bindex <= bbot; bindex++) {
25235 + br = au_sbr(sb, bindex);
25236 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25237 + if (unlikely(err))
25238 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25240 + /* go on even if err */
25242 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25243 + dir = d_inode(sb->s_root);
25244 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25251 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25254 + unsigned char no_dreval;
25255 + struct inode *dir;
25256 + struct au_opt_xino *opt_xino;
25257 + struct au_opt *opt;
25258 + struct au_sbinfo *sbinfo;
25260 + SiMustWriteLock(sb);
25263 + dir = d_inode(sb->s_root);
25264 + sbinfo = au_sbi(sb);
25267 + while (err >= 0 && opt->type != Opt_tail) {
25268 + err = au_opt_simple(sb, opt, opts);
25270 + err = au_opt_br(sb, opt, opts);
25272 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25278 + /* go on even err */
25280 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25281 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25282 + if (unlikely(rerr && !err))
25285 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25286 + au_fset_opts(opts->flags, REFRESH_IDOP);
25288 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25289 + rerr = au_xib_trunc(sb);
25290 + if (unlikely(rerr && !err))
25294 + /* will be handled by the caller */
25295 + if (!au_ftest_opts(opts->flags, REFRESH)
25296 + && (opts->given_udba
25297 + || au_opt_test(sbinfo->si_mntflags, XINO)
25298 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25300 + au_fset_opts(opts->flags, REFRESH);
25302 + AuDbg("status 0x%x\n", opts->flags);
25306 +/* ---------------------------------------------------------------------- */
25308 +unsigned int au_opt_udba(struct super_block *sb)
25310 + return au_mntflags(sb) & AuOptMask_UDBA;
25312 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25313 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25314 +++ linux/fs/aufs/opts.h 2017-05-06 22:16:52.781553511 +0200
25317 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25319 + * This program, aufs is free software; you can redistribute it and/or modify
25320 + * it under the terms of the GNU General Public License as published by
25321 + * the Free Software Foundation; either version 2 of the License, or
25322 + * (at your option) any later version.
25324 + * This program is distributed in the hope that it will be useful,
25325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25327 + * GNU General Public License for more details.
25329 + * You should have received a copy of the GNU General Public License
25330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25334 + * mount options/flags
25337 +#ifndef __AUFS_OPTS_H__
25338 +#define __AUFS_OPTS_H__
25342 +#include <linux/path.h>
25345 +struct super_block;
25347 +/* ---------------------------------------------------------------------- */
25350 +#define AuOpt_XINO 1 /* external inode number bitmap
25351 + and translation table */
25352 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25353 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25354 +#define AuOpt_UDBA_REVAL (1 << 3)
25355 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25356 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25357 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25358 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25360 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25361 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25362 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25363 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25364 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25365 +#define AuOpt_DIO (1 << 14) /* direct io */
25367 +#ifndef CONFIG_AUFS_HNOTIFY
25368 +#undef AuOpt_UDBA_HNOTIFY
25369 +#define AuOpt_UDBA_HNOTIFY 0
25371 +#ifndef CONFIG_AUFS_SHWH
25373 +#define AuOpt_SHWH 0
25376 +#define AuOpt_Def (AuOpt_XINO \
25377 + | AuOpt_UDBA_REVAL \
25379 + /* | AuOpt_DIRPERM1 */ \
25380 + | AuOpt_WARN_PERM)
25381 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25382 + | AuOpt_UDBA_REVAL \
25383 + | AuOpt_UDBA_HNOTIFY)
25385 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25386 +#define au_opt_set(flags, name) do { \
25387 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25388 + ((flags) |= AuOpt_##name); \
25390 +#define au_opt_set_udba(flags, name) do { \
25391 + (flags) &= ~AuOptMask_UDBA; \
25392 + ((flags) |= AuOpt_##name); \
25394 +#define au_opt_clr(flags, name) do { \
25395 + ((flags) &= ~AuOpt_##name); \
25398 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25400 +#ifdef CONFIG_PROC_FS
25403 + return mntflags & ~AuOpt_PLINK;
25407 +/* ---------------------------------------------------------------------- */
25409 +/* policies to select one among multiple writable branches */
25411 + AuWbrCreate_TDP, /* top down parent */
25412 + AuWbrCreate_RR, /* round robin */
25413 + AuWbrCreate_MFS, /* most free space */
25414 + AuWbrCreate_MFSV, /* mfs with seconds */
25415 + AuWbrCreate_MFSRR, /* mfs then rr */
25416 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25417 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25418 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25419 + AuWbrCreate_PMFS, /* parent and mfs */
25420 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25421 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25422 + AuWbrCreate_PMFSRRV, /* plus seconds */
25424 + AuWbrCreate_Def = AuWbrCreate_TDP
25428 + AuWbrCopyup_TDP, /* top down parent */
25429 + AuWbrCopyup_BUP, /* bottom up parent */
25430 + AuWbrCopyup_BU, /* bottom up */
25432 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25435 +/* ---------------------------------------------------------------------- */
25437 +struct au_opt_add {
25438 + aufs_bindex_t bindex;
25441 + struct path path;
25444 +struct au_opt_del {
25446 + struct path h_path;
25449 +struct au_opt_mod {
25452 + struct dentry *h_root;
25455 +struct au_opt_xino {
25457 + struct file *file;
25460 +struct au_opt_xino_itrunc {
25461 + aufs_bindex_t bindex;
25464 +struct au_opt_wbr_create {
25467 + unsigned long long mfsrr_watermark;
25473 + struct au_opt_xino xino;
25474 + struct au_opt_xino_itrunc xino_itrunc;
25475 + struct au_opt_add add;
25476 + struct au_opt_del del;
25477 + struct au_opt_mod mod;
25480 + unsigned int rdblk;
25481 + unsigned int rdhash;
25483 + struct au_opt_wbr_create wbr_create;
25485 + unsigned int fhsm_second;
25490 +#define AuOpts_REMOUNT 1
25491 +#define AuOpts_REFRESH (1 << 1)
25492 +#define AuOpts_TRUNC_XIB (1 << 2)
25493 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25494 +#define AuOpts_REFRESH_IDOP (1 << 4)
25495 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25496 +#define au_fset_opts(flags, name) \
25497 + do { (flags) |= AuOpts_##name; } while (0)
25498 +#define au_fclr_opts(flags, name) \
25499 + do { (flags) &= ~AuOpts_##name; } while (0)
25502 + struct au_opt *opt;
25505 + unsigned int given_udba;
25506 + unsigned int flags;
25507 + unsigned long sb_flags;
25510 +/* ---------------------------------------------------------------------- */
25513 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25514 +const char *au_optstr_udba(int udba);
25515 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25516 +const char *au_optstr_wbr_create(int wbr_create);
25518 +void au_opts_free(struct au_opts *opts);
25519 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25520 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25521 + unsigned int pending);
25522 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25523 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25525 +unsigned int au_opt_udba(struct super_block *sb);
25527 +#endif /* __KERNEL__ */
25528 +#endif /* __AUFS_OPTS_H__ */
25529 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25530 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25531 +++ linux/fs/aufs/plink.c 2017-05-06 22:16:52.781553511 +0200
25534 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25536 + * This program, aufs is free software; you can redistribute it and/or modify
25537 + * it under the terms of the GNU General Public License as published by
25538 + * the Free Software Foundation; either version 2 of the License, or
25539 + * (at your option) any later version.
25541 + * This program is distributed in the hope that it will be useful,
25542 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25543 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25544 + * GNU General Public License for more details.
25546 + * You should have received a copy of the GNU General Public License
25547 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25557 + * the pseudo-link maintenance mode.
25558 + * during a user process maintains the pseudo-links,
25559 + * prohibit adding a new plink and branch manipulation.
25563 + * For entry functions which will handle plink, and i_mutex is already held
25565 + * They cannot wait and should return an error at once.
25566 + * Callers has to check the error.
25568 + * For entry functions which will handle plink, but i_mutex is not held
25570 + * They can wait the plink maintenance mode to finish.
25572 + * They behave like F_SETLK and F_SETLKW.
25573 + * If the caller never handle plink, then both flags are unnecessary.
25576 +int au_plink_maint(struct super_block *sb, int flags)
25580 + struct task_struct *parent, *prev;
25581 + struct au_sbinfo *sbi;
25583 + SiMustAnyLock(sb);
25586 + if (!au_opt_test(au_mntflags(sb), PLINK))
25589 + sbi = au_sbi(sb);
25590 + pid = sbi->si_plink_maint_pid;
25591 + if (!pid || pid == current->pid)
25594 + /* todo: it highly depends upon /sbin/mount.aufs */
25596 + parent = current;
25600 + parent = rcu_dereference(parent->real_parent);
25601 + if (parent == prev)
25603 + ppid = task_pid_vnr(parent);
25604 + if (pid == ppid) {
25605 + rcu_read_unlock();
25610 + rcu_read_unlock();
25612 + if (au_ftest_lock(flags, NOPLMW)) {
25613 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25614 + /* AuDebugOn(!lockdep_depth(current)); */
25615 + while (sbi->si_plink_maint_pid) {
25616 + si_read_unlock(sb);
25617 + /* gave up wake_up_bit() */
25618 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25620 + if (au_ftest_lock(flags, FLUSH))
25621 + au_nwt_flush(&sbi->si_nowait);
25622 + si_noflush_read_lock(sb);
25624 + } else if (au_ftest_lock(flags, NOPLM)) {
25625 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25633 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25635 + spin_lock(&sbinfo->si_plink_maint_lock);
25636 + sbinfo->si_plink_maint_pid = 0;
25637 + spin_unlock(&sbinfo->si_plink_maint_lock);
25638 + wake_up_all(&sbinfo->si_plink_wq);
25641 +int au_plink_maint_enter(struct super_block *sb)
25644 + struct au_sbinfo *sbinfo;
25647 + sbinfo = au_sbi(sb);
25648 + /* make sure i am the only one in this fs */
25649 + si_write_lock(sb, AuLock_FLUSH);
25650 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25651 + spin_lock(&sbinfo->si_plink_maint_lock);
25652 + if (!sbinfo->si_plink_maint_pid)
25653 + sbinfo->si_plink_maint_pid = current->pid;
25656 + spin_unlock(&sbinfo->si_plink_maint_lock);
25658 + si_write_unlock(sb);
25663 +/* ---------------------------------------------------------------------- */
25665 +#ifdef CONFIG_AUFS_DEBUG
25666 +void au_plink_list(struct super_block *sb)
25669 + struct au_sbinfo *sbinfo;
25670 + struct hlist_head *plink_hlist;
25671 + struct au_icntnr *icntnr;
25673 + SiMustAnyLock(sb);
25675 + sbinfo = au_sbi(sb);
25676 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25677 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25679 + for (i = 0; i < AuPlink_NHASH; i++) {
25680 + plink_hlist = &sbinfo->si_plink[i].head;
25682 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25683 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25684 + rcu_read_unlock();
25689 +/* is the inode pseudo-linked? */
25690 +int au_plink_test(struct inode *inode)
25693 + struct au_sbinfo *sbinfo;
25694 + struct hlist_head *plink_hlist;
25695 + struct au_icntnr *icntnr;
25697 + sbinfo = au_sbi(inode->i_sb);
25698 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25699 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25700 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25703 + i = au_plink_hash(inode->i_ino);
25704 + plink_hlist = &sbinfo->si_plink[i].head;
25706 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25707 + if (&icntnr->vfs_inode == inode) {
25711 + rcu_read_unlock();
25715 +/* ---------------------------------------------------------------------- */
25718 + * generate a name for plink.
25719 + * the file will be stored under AUFS_WH_PLINKDIR.
25721 +/* 20 is max digits length of ulong 64 */
25722 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25724 +static int plink_name(char *name, int len, struct inode *inode,
25725 + aufs_bindex_t bindex)
25728 + struct inode *h_inode;
25730 + h_inode = au_h_iptr(inode, bindex);
25731 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25735 +struct au_do_plink_lkup_args {
25736 + struct dentry **errp;
25737 + struct qstr *tgtname;
25738 + struct dentry *h_parent;
25739 + struct au_branch *br;
25742 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25743 + struct dentry *h_parent,
25744 + struct au_branch *br)
25746 + struct dentry *h_dentry;
25747 + struct inode *h_inode;
25749 + h_inode = d_inode(h_parent);
25750 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25751 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25752 + inode_unlock(h_inode);
25756 +static void au_call_do_plink_lkup(void *args)
25758 + struct au_do_plink_lkup_args *a = args;
25759 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25762 +/* lookup the plink-ed @inode under the branch at @bindex */
25763 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25765 + struct dentry *h_dentry, *h_parent;
25766 + struct au_branch *br;
25768 + char a[PLINK_NAME_LEN];
25769 + struct qstr tgtname = QSTR_INIT(a, 0);
25771 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25773 + br = au_sbr(inode->i_sb, bindex);
25774 + h_parent = br->br_wbr->wbr_plink;
25775 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25777 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25778 + struct au_do_plink_lkup_args args = {
25779 + .errp = &h_dentry,
25780 + .tgtname = &tgtname,
25781 + .h_parent = h_parent,
25785 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25786 + if (unlikely(wkq_err))
25787 + h_dentry = ERR_PTR(wkq_err);
25789 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25794 +/* create a pseudo-link */
25795 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25796 + struct dentry *h_dentry, struct au_branch *br)
25799 + struct path h_path = {
25800 + .mnt = au_br_mnt(br)
25802 + struct inode *h_dir, *delegated;
25804 + h_dir = d_inode(h_parent);
25805 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25807 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25808 + err = PTR_ERR(h_path.dentry);
25809 + if (IS_ERR(h_path.dentry))
25813 + /* wh.plink dir is not monitored */
25814 + /* todo: is it really safe? */
25815 + if (d_is_positive(h_path.dentry)
25816 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25817 + delegated = NULL;
25818 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25819 + if (unlikely(err == -EWOULDBLOCK)) {
25820 + pr_warn("cannot retry for NFSv4 delegation"
25821 + " for an internal unlink\n");
25824 + dput(h_path.dentry);
25825 + h_path.dentry = NULL;
25829 + if (!err && d_is_negative(h_path.dentry)) {
25830 + delegated = NULL;
25831 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25832 + if (unlikely(err == -EWOULDBLOCK)) {
25833 + pr_warn("cannot retry for NFSv4 delegation"
25834 + " for an internal link\n");
25838 + dput(h_path.dentry);
25841 + inode_unlock(h_dir);
25845 +struct do_whplink_args {
25847 + struct qstr *tgt;
25848 + struct dentry *h_parent;
25849 + struct dentry *h_dentry;
25850 + struct au_branch *br;
25853 +static void call_do_whplink(void *args)
25855 + struct do_whplink_args *a = args;
25856 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25859 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25860 + aufs_bindex_t bindex, struct au_branch *br)
25862 + int err, wkq_err;
25863 + struct au_wbr *wbr;
25864 + struct dentry *h_parent;
25865 + char a[PLINK_NAME_LEN];
25866 + struct qstr tgtname = QSTR_INIT(a, 0);
25868 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25869 + h_parent = wbr->wbr_plink;
25870 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25872 + /* always superio. */
25873 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25874 + struct do_whplink_args args = {
25877 + .h_parent = h_parent,
25878 + .h_dentry = h_dentry,
25881 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25882 + if (unlikely(wkq_err))
25885 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25891 + * create a new pseudo-link for @h_dentry on @bindex.
25892 + * the linked inode is held in aufs @inode.
25894 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25895 + struct dentry *h_dentry)
25897 + struct super_block *sb;
25898 + struct au_sbinfo *sbinfo;
25899 + struct hlist_head *plink_hlist;
25900 + struct au_icntnr *icntnr;
25901 + struct au_sphlhead *sphl;
25902 + int found, err, cnt, i;
25904 + sb = inode->i_sb;
25905 + sbinfo = au_sbi(sb);
25906 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25907 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25909 + found = au_plink_test(inode);
25913 + i = au_plink_hash(inode->i_ino);
25914 + sphl = sbinfo->si_plink + i;
25915 + plink_hlist = &sphl->head;
25918 + spin_lock(&sphl->spin);
25919 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25920 + if (&icntnr->vfs_inode == inode) {
25926 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25927 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25929 + spin_unlock(&sphl->spin);
25931 + cnt = au_sphl_count(sphl);
25932 +#define msg "unexpectedly unblanced or too many pseudo-links"
25933 + if (cnt > AUFS_PLINK_WARN)
25934 + AuWarn1(msg ", %d\n", cnt);
25936 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25937 + if (unlikely(err)) {
25938 + pr_warn("err %d, damaged pseudo link.\n", err);
25939 + au_sphl_del_rcu(&icntnr->plink, sphl);
25940 + iput(&icntnr->vfs_inode);
25943 + iput(&icntnr->vfs_inode);
25946 +/* free all plinks */
25947 +void au_plink_put(struct super_block *sb, int verbose)
25950 + struct au_sbinfo *sbinfo;
25951 + struct hlist_head *plink_hlist;
25952 + struct hlist_node *tmp;
25953 + struct au_icntnr *icntnr;
25955 + SiMustWriteLock(sb);
25957 + sbinfo = au_sbi(sb);
25958 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25959 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25961 + /* no spin_lock since sbinfo is write-locked */
25963 + for (i = 0; i < AuPlink_NHASH; i++) {
25964 + plink_hlist = &sbinfo->si_plink[i].head;
25965 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25966 + pr_warn("pseudo-link is not flushed");
25969 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25970 + iput(&icntnr->vfs_inode);
25971 + INIT_HLIST_HEAD(plink_hlist);
25975 +void au_plink_clean(struct super_block *sb, int verbose)
25977 + struct dentry *root;
25979 + root = sb->s_root;
25980 + aufs_write_lock(root);
25981 + if (au_opt_test(au_mntflags(sb), PLINK))
25982 + au_plink_put(sb, verbose);
25983 + aufs_write_unlock(root);
25986 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25989 + aufs_bindex_t btop, bbot, bindex;
25992 + btop = au_ibtop(inode);
25993 + bbot = au_ibbot(inode);
25995 + for (bindex = btop; bindex <= bbot; bindex++) {
25996 + if (!au_h_iptr(inode, bindex)
25997 + || au_ii_br_id(inode, bindex) != br_id)
25999 + au_set_h_iptr(inode, bindex, NULL, 0);
26004 + for (bindex = btop; bindex <= bbot; bindex++)
26005 + if (au_h_iptr(inode, bindex)) {
26015 +/* free the plinks on a branch specified by @br_id */
26016 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
26018 + struct au_sbinfo *sbinfo;
26019 + struct hlist_head *plink_hlist;
26020 + struct hlist_node *tmp;
26021 + struct au_icntnr *icntnr;
26022 + struct inode *inode;
26025 + SiMustWriteLock(sb);
26027 + sbinfo = au_sbi(sb);
26028 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
26029 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
26031 + /* no spin_lock since sbinfo is write-locked */
26032 + for (i = 0; i < AuPlink_NHASH; i++) {
26033 + plink_hlist = &sbinfo->si_plink[i].head;
26034 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
26035 + inode = au_igrab(&icntnr->vfs_inode);
26036 + ii_write_lock_child(inode);
26037 + do_put = au_plink_do_half_refresh(inode, br_id);
26039 + hlist_del(&icntnr->plink);
26042 + ii_write_unlock(inode);
26047 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
26048 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
26049 +++ linux/fs/aufs/poll.c 2017-05-06 22:16:52.781553511 +0200
26052 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26054 + * This program, aufs is free software; you can redistribute it and/or modify
26055 + * it under the terms of the GNU General Public License as published by
26056 + * the Free Software Foundation; either version 2 of the License, or
26057 + * (at your option) any later version.
26059 + * This program is distributed in the hope that it will be useful,
26060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26062 + * GNU General Public License for more details.
26064 + * You should have received a copy of the GNU General Public License
26065 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26070 + * There is only one filesystem which implements ->poll operation, currently.
26075 +unsigned int aufs_poll(struct file *file, poll_table *wait)
26077 + unsigned int mask;
26079 + struct file *h_file;
26080 + struct super_block *sb;
26082 + /* We should pretend an error happened. */
26083 + mask = POLLERR /* | POLLIN | POLLOUT */;
26084 + sb = file->f_path.dentry->d_sb;
26085 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
26087 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
26088 + err = PTR_ERR(h_file);
26089 + if (IS_ERR(h_file))
26092 + /* it is not an error if h_file has no operation */
26093 + mask = DEFAULT_POLLMASK;
26094 + if (h_file->f_op->poll)
26095 + mask = h_file->f_op->poll(h_file, wait);
26096 + fput(h_file); /* instead of au_read_post() */
26099 + si_read_unlock(sb);
26100 + AuTraceErr((int)mask);
26103 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
26104 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
26105 +++ linux/fs/aufs/posix_acl.c 2017-05-06 22:16:52.781553511 +0200
26108 + * Copyright (C) 2014-2017 Junjiro R. Okajima
26110 + * This program, aufs is free software; you can redistribute it and/or modify
26111 + * it under the terms of the GNU General Public License as published by
26112 + * the Free Software Foundation; either version 2 of the License, or
26113 + * (at your option) any later version.
26115 + * This program is distributed in the hope that it will be useful,
26116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26118 + * GNU General Public License for more details.
26120 + * You should have received a copy of the GNU General Public License
26121 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26125 + * posix acl operations
26128 +#include <linux/fs.h>
26131 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
26133 + struct posix_acl *acl;
26135 + aufs_bindex_t bindex;
26136 + struct inode *h_inode;
26137 + struct super_block *sb;
26140 + sb = inode->i_sb;
26141 + si_read_lock(sb, AuLock_FLUSH);
26142 + ii_read_lock_child(inode);
26143 + if (!(sb->s_flags & MS_POSIXACL))
26146 + bindex = au_ibtop(inode);
26147 + h_inode = au_h_iptr(inode, bindex);
26148 + if (unlikely(!h_inode
26149 + || ((h_inode->i_mode & S_IFMT)
26150 + != (inode->i_mode & S_IFMT)))) {
26151 + err = au_busy_or_stale();
26152 + acl = ERR_PTR(err);
26156 + /* always topmost only */
26157 + acl = get_acl(h_inode, type);
26158 + if (!IS_ERR_OR_NULL(acl))
26159 + set_cached_acl(inode, type, acl);
26162 + ii_read_unlock(inode);
26163 + si_read_unlock(sb);
26165 + AuTraceErrPtr(acl);
26169 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
26173 + struct dentry *dentry;
26174 + struct au_sxattr arg = {
26175 + .type = AU_ACL_SET,
26182 + IMustLock(inode);
26184 + if (inode->i_ino == AUFS_ROOT_INO)
26185 + dentry = dget(inode->i_sb->s_root);
26187 + dentry = d_find_alias(inode);
26189 + dentry = d_find_any_alias(inode);
26191 + pr_warn("cannot handle this inode, "
26192 + "please report to aufs-users ML\n");
26198 + ssz = au_sxattr(dentry, inode, &arg);
26203 + set_cached_acl(inode, type, acl);
26209 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
26210 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
26211 +++ linux/fs/aufs/procfs.c 2017-05-06 22:16:52.781553511 +0200
26214 + * Copyright (C) 2010-2017 Junjiro R. Okajima
26216 + * This program, aufs is free software; you can redistribute it and/or modify
26217 + * it under the terms of the GNU General Public License as published by
26218 + * the Free Software Foundation; either version 2 of the License, or
26219 + * (at your option) any later version.
26221 + * This program is distributed in the hope that it will be useful,
26222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26224 + * GNU General Public License for more details.
26226 + * You should have received a copy of the GNU General Public License
26227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26231 + * procfs interfaces
26234 +#include <linux/proc_fs.h>
26237 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
26239 + struct au_sbinfo *sbinfo;
26241 + sbinfo = file->private_data;
26243 + au_plink_maint_leave(sbinfo);
26244 + kobject_put(&sbinfo->si_kobj);
26250 +static void au_procfs_plm_write_clean(struct file *file)
26252 + struct au_sbinfo *sbinfo;
26254 + sbinfo = file->private_data;
26256 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
26259 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
26262 + struct super_block *sb;
26263 + struct au_sbinfo *sbinfo;
26266 + if (unlikely(file->private_data))
26270 + /* don't use au_sbilist_lock() here */
26271 + spin_lock(&au_sbilist.spin);
26272 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26273 + if (id == sysaufs_si_id(sbinfo)) {
26274 + kobject_get(&sbinfo->si_kobj);
26275 + sb = sbinfo->si_sb;
26278 + spin_unlock(&au_sbilist.spin);
26281 + if (unlikely(!sb))
26284 + err = au_plink_maint_enter(sb);
26286 + /* keep kobject_get() */
26287 + file->private_data = sbinfo;
26289 + kobject_put(&sbinfo->si_kobj);
26295 + * Accept a valid "si=xxxx" only.
26296 + * Once it is accepted successfully, accept "clean" too.
26298 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26299 + size_t count, loff_t *ppos)
26302 + unsigned long id;
26303 + /* last newline is allowed */
26304 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26307 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26311 + if (unlikely(count > sizeof(buf)))
26314 + err = copy_from_user(buf, ubuf, count);
26315 + if (unlikely(err)) {
26322 + if (!strcmp("clean", buf)) {
26323 + au_procfs_plm_write_clean(file);
26324 + goto out_success;
26325 + } else if (unlikely(strncmp("si=", buf, 3)))
26328 + err = kstrtoul(buf + 3, 16, &id);
26329 + if (unlikely(err))
26332 + err = au_procfs_plm_write_si(file, id);
26333 + if (unlikely(err))
26337 + err = count; /* success */
26342 +static const struct file_operations au_procfs_plm_fop = {
26343 + .write = au_procfs_plm_write,
26344 + .release = au_procfs_plm_release,
26345 + .owner = THIS_MODULE
26348 +/* ---------------------------------------------------------------------- */
26350 +static struct proc_dir_entry *au_procfs_dir;
26352 +void au_procfs_fin(void)
26354 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26355 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26358 +int __init au_procfs_init(void)
26361 + struct proc_dir_entry *entry;
26364 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26365 + if (unlikely(!au_procfs_dir))
26368 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26369 + au_procfs_dir, &au_procfs_plm_fop);
26370 + if (unlikely(!entry))
26374 + goto out; /* success */
26378 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26382 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26383 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26384 +++ linux/fs/aufs/rdu.c 2017-05-06 22:16:52.781553511 +0200
26387 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26389 + * This program, aufs is free software; you can redistribute it and/or modify
26390 + * it under the terms of the GNU General Public License as published by
26391 + * the Free Software Foundation; either version 2 of the License, or
26392 + * (at your option) any later version.
26394 + * This program is distributed in the hope that it will be useful,
26395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26397 + * GNU General Public License for more details.
26399 + * You should have received a copy of the GNU General Public License
26400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26404 + * readdir in userspace.
26407 +#include <linux/compat.h>
26408 +#include <linux/fs_stack.h>
26409 +#include <linux/security.h>
26412 +/* bits for struct aufs_rdu.flags */
26413 +#define AuRdu_CALLED 1
26414 +#define AuRdu_CONT (1 << 1)
26415 +#define AuRdu_FULL (1 << 2)
26416 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26417 +#define au_fset_rdu(flags, name) \
26418 + do { (flags) |= AuRdu_##name; } while (0)
26419 +#define au_fclr_rdu(flags, name) \
26420 + do { (flags) &= ~AuRdu_##name; } while (0)
26422 +struct au_rdu_arg {
26423 + struct dir_context ctx;
26424 + struct aufs_rdu *rdu;
26425 + union au_rdu_ent_ul ent;
26426 + unsigned long end;
26428 + struct super_block *sb;
26432 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26433 + loff_t offset, u64 h_ino, unsigned int d_type)
26436 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26437 + struct aufs_rdu *rdu = arg->rdu;
26438 + struct au_rdu_ent ent;
26442 + au_fset_rdu(rdu->cookie.flags, CALLED);
26443 + len = au_rdu_len(nlen);
26444 + if (arg->ent.ul + len < arg->end) {
26446 + ent.bindex = rdu->cookie.bindex;
26447 + ent.type = d_type;
26449 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26450 + ent.type = DT_UNKNOWN;
26452 + /* unnecessary to support mmap_sem since this is a dir */
26454 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26456 + if (copy_to_user(arg->ent.e->name, name, nlen))
26458 + /* the terminating NULL */
26459 + if (__put_user(0, arg->ent.e->name + nlen))
26462 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26463 + arg->ent.ul += len;
26467 + au_fset_rdu(rdu->cookie.flags, FULL);
26469 + rdu->tail = arg->ent;
26473 + /* AuTraceErr(err); */
26477 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26481 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26483 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26484 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26486 + if (unlikely(offset != cookie->h_pos))
26492 + au_fclr_rdu(cookie->flags, CALLED);
26494 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26498 + && au_ftest_rdu(cookie->flags, CALLED)
26499 + && !au_ftest_rdu(cookie->flags, FULL));
26500 + cookie->h_pos = h_file->f_pos;
26507 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26510 + aufs_bindex_t bbot;
26511 + struct au_rdu_arg arg = {
26513 + .actor = au_rdu_fill
26516 + struct dentry *dentry;
26517 + struct inode *inode;
26518 + struct file *h_file;
26519 + struct au_rdu_cookie *cookie = &rdu->cookie;
26521 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26522 + if (unlikely(err)) {
26528 + rdu->tail = rdu->ent;
26531 + arg.ent = rdu->ent;
26532 + arg.end = arg.ent.ul;
26533 + arg.end += rdu->sz;
26536 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26539 + err = security_file_permission(file, MAY_READ);
26541 + if (unlikely(err))
26544 + dentry = file->f_path.dentry;
26545 + inode = d_inode(dentry);
26546 + inode_lock_shared(inode);
26548 + arg.sb = inode->i_sb;
26549 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26550 + if (unlikely(err))
26552 + err = au_alive_dir(dentry);
26553 + if (unlikely(err))
26555 + /* todo: reval? */
26556 + fi_read_lock(file);
26559 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26560 + && cookie->generation != au_figen(file)))
26565 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26567 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26569 + bbot = au_fbtop(file);
26570 + if (cookie->bindex < bbot)
26571 + cookie->bindex = bbot;
26572 + bbot = au_fbbot_dir(file);
26573 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26574 + for (; !err && cookie->bindex <= bbot;
26575 + cookie->bindex++, cookie->h_pos = 0) {
26576 + h_file = au_hf_dir(file, cookie->bindex);
26580 + au_fclr_rdu(cookie->flags, FULL);
26581 + err = au_rdu_do(h_file, &arg);
26583 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26586 + AuDbg("rent %llu\n", rdu->rent);
26588 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26589 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26590 + au_fset_rdu(cookie->flags, CONT);
26591 + cookie->generation = au_figen(file);
26594 + ii_read_lock_child(inode);
26595 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26596 + ii_read_unlock(inode);
26599 + fi_read_unlock(file);
26601 + si_read_unlock(arg.sb);
26603 + inode_unlock_shared(inode);
26609 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26613 + unsigned long long nent;
26614 + union au_rdu_ent_ul *u;
26615 + struct au_rdu_ent ent;
26616 + struct super_block *sb;
26619 + nent = rdu->nent;
26621 + sb = file->f_path.dentry->d_sb;
26622 + si_read_lock(sb, AuLock_FLUSH);
26623 + while (nent-- > 0) {
26624 + /* unnecessary to support mmap_sem since this is a dir */
26625 + err = copy_from_user(&ent, u->e, sizeof(ent));
26627 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26628 + if (unlikely(err)) {
26634 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26636 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26638 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26640 + if (unlikely(err)) {
26645 + err = __put_user(ino, &u->e->ino);
26646 + if (unlikely(err)) {
26651 + u->ul += au_rdu_len(ent.nlen);
26653 + si_read_unlock(sb);
26658 +/* ---------------------------------------------------------------------- */
26660 +static int au_rdu_verify(struct aufs_rdu *rdu)
26662 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26663 + "%llu, b%d, 0x%x, g%u}\n",
26664 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26666 + rdu->rent, rdu->shwh, rdu->full,
26667 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26668 + rdu->cookie.generation);
26670 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26674 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26678 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26681 + struct aufs_rdu rdu;
26682 + void __user *p = (void __user *)arg;
26684 + err = copy_from_user(&rdu, p, sizeof(rdu));
26685 + if (unlikely(err)) {
26690 + err = au_rdu_verify(&rdu);
26691 + if (unlikely(err))
26695 + case AUFS_CTL_RDU:
26696 + err = au_rdu(file, &rdu);
26697 + if (unlikely(err))
26700 + e = copy_to_user(p, &rdu, sizeof(rdu));
26701 + if (unlikely(e)) {
26706 + case AUFS_CTL_RDU_INO:
26707 + err = au_rdu_ino(file, &rdu);
26711 + /* err = -ENOTTY; */
26720 +#ifdef CONFIG_COMPAT
26721 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26724 + struct aufs_rdu rdu;
26725 + void __user *p = compat_ptr(arg);
26727 + /* todo: get_user()? */
26728 + err = copy_from_user(&rdu, p, sizeof(rdu));
26729 + if (unlikely(err)) {
26734 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26735 + err = au_rdu_verify(&rdu);
26736 + if (unlikely(err))
26740 + case AUFS_CTL_RDU:
26741 + err = au_rdu(file, &rdu);
26742 + if (unlikely(err))
26745 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26746 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26747 + e = copy_to_user(p, &rdu, sizeof(rdu));
26748 + if (unlikely(e)) {
26753 + case AUFS_CTL_RDU_INO:
26754 + err = au_rdu_ino(file, &rdu);
26758 + /* err = -ENOTTY; */
26767 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26768 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26769 +++ linux/fs/aufs/rwsem.h 2017-05-06 22:16:52.781553511 +0200
26772 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26774 + * This program, aufs is free software; you can redistribute it and/or modify
26775 + * it under the terms of the GNU General Public License as published by
26776 + * the Free Software Foundation; either version 2 of the License, or
26777 + * (at your option) any later version.
26779 + * This program is distributed in the hope that it will be useful,
26780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26782 + * GNU General Public License for more details.
26784 + * You should have received a copy of the GNU General Public License
26785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26789 + * simple read-write semaphore wrappers
26792 +#ifndef __AUFS_RWSEM_H__
26793 +#define __AUFS_RWSEM_H__
26797 +#include "debug.h"
26800 + struct rw_semaphore rwsem;
26801 +#ifdef CONFIG_AUFS_DEBUG
26802 + /* just for debugging, not almighty counter */
26803 + atomic_t rcnt, wcnt;
26807 +#ifdef CONFIG_LOCKDEP
26808 +#define au_lockdep_set_name(rw) \
26809 + lockdep_set_class_and_name(&(rw)->rwsem, \
26810 + /*original key*/(rw)->rwsem.dep_map.key, \
26813 +#define au_lockdep_set_name(rw) do {} while (0)
26816 +#ifdef CONFIG_AUFS_DEBUG
26817 +#define AuDbgCntInit(rw) do { \
26818 + atomic_set(&(rw)->rcnt, 0); \
26819 + atomic_set(&(rw)->wcnt, 0); \
26820 + smp_mb(); /* atomic set */ \
26823 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26824 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26825 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26826 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26827 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26828 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26829 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26831 +#define AuDbgCnt(rw, cnt) 0
26832 +#define AuDbgCntInit(rw) do {} while (0)
26833 +#define AuDbgRcntInc(rw) do {} while (0)
26834 +#define AuDbgRcntDec(rw) do {} while (0)
26835 +#define AuDbgWcntInc(rw) do {} while (0)
26836 +#define AuDbgWcntDec(rw) do {} while (0)
26837 +#endif /* CONFIG_AUFS_DEBUG */
26839 +/* to debug easier, do not make them inlined functions */
26840 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26841 +/* rwsem_is_locked() is unusable */
26842 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26843 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26844 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26845 + && AuDbgCnt(rw, wcnt) <= 0)
26846 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26847 + || AuDbgCnt(rw, wcnt))
26849 +#define au_rw_init(rw) do { \
26850 + AuDbgCntInit(rw); \
26851 + init_rwsem(&(rw)->rwsem); \
26852 + au_lockdep_set_name(rw); \
26855 +#define au_rw_init_wlock(rw) do { \
26856 + au_rw_init(rw); \
26857 + down_write(&(rw)->rwsem); \
26858 + AuDbgWcntInc(rw); \
26861 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26862 + au_rw_init(rw); \
26863 + down_write_nested(&(rw)->rwsem, lsc); \
26864 + AuDbgWcntInc(rw); \
26867 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26869 + down_read(&rw->rwsem);
26870 + AuDbgRcntInc(rw);
26873 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26875 + down_read_nested(&rw->rwsem, lsc);
26876 + AuDbgRcntInc(rw);
26879 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26881 + AuRwMustReadLock(rw);
26882 + AuDbgRcntDec(rw);
26883 + up_read(&rw->rwsem);
26886 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26888 + AuRwMustWriteLock(rw);
26889 + AuDbgRcntInc(rw);
26890 + AuDbgWcntDec(rw);
26891 + downgrade_write(&rw->rwsem);
26894 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26896 + down_write(&rw->rwsem);
26897 + AuDbgWcntInc(rw);
26900 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26901 + unsigned int lsc)
26903 + down_write_nested(&rw->rwsem, lsc);
26904 + AuDbgWcntInc(rw);
26907 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26909 + AuRwMustWriteLock(rw);
26910 + AuDbgWcntDec(rw);
26911 + up_write(&rw->rwsem);
26914 +/* why is not _nested version defined */
26915 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26919 + ret = down_read_trylock(&rw->rwsem);
26921 + AuDbgRcntInc(rw);
26925 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26929 + ret = down_write_trylock(&rw->rwsem);
26931 + AuDbgWcntInc(rw);
26935 +#undef AuDbgCntDec
26936 +#undef AuDbgRcntInc
26937 +#undef AuDbgRcntDec
26938 +#undef AuDbgWcntDec
26940 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26941 +static inline void prefix##_read_lock(param) \
26942 +{ au_rw_read_lock(rwsem); } \
26943 +static inline void prefix##_write_lock(param) \
26944 +{ au_rw_write_lock(rwsem); } \
26945 +static inline int prefix##_read_trylock(param) \
26946 +{ return au_rw_read_trylock(rwsem); } \
26947 +static inline int prefix##_write_trylock(param) \
26948 +{ return au_rw_write_trylock(rwsem); }
26949 +/* why is not _nested version defined */
26950 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26951 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26952 +static inline void prefix##_write_trylock_nestd(param, lsc)
26953 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26955 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26956 +static inline void prefix##_read_unlock(param) \
26957 +{ au_rw_read_unlock(rwsem); } \
26958 +static inline void prefix##_write_unlock(param) \
26959 +{ au_rw_write_unlock(rwsem); } \
26960 +static inline void prefix##_downgrade_lock(param) \
26961 +{ au_rw_dgrade_lock(rwsem); }
26963 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26964 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26965 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26967 +#endif /* __KERNEL__ */
26968 +#endif /* __AUFS_RWSEM_H__ */
26969 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26970 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26971 +++ linux/fs/aufs/sbinfo.c 2017-05-06 22:16:52.781553511 +0200
26974 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26976 + * This program, aufs is free software; you can redistribute it and/or modify
26977 + * it under the terms of the GNU General Public License as published by
26978 + * the Free Software Foundation; either version 2 of the License, or
26979 + * (at your option) any later version.
26981 + * This program is distributed in the hope that it will be useful,
26982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26984 + * GNU General Public License for more details.
26986 + * You should have received a copy of the GNU General Public License
26987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26991 + * superblock private data
26997 + * they are necessary regardless sysfs is disabled.
26999 +void au_si_free(struct kobject *kobj)
27002 + struct au_sbinfo *sbinfo;
27003 + char *locked __maybe_unused; /* debug only */
27005 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
27006 + for (i = 0; i < AuPlink_NHASH; i++)
27007 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
27008 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
27010 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
27011 + percpu_counter_destroy(&sbinfo->si_ninodes);
27012 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
27013 + percpu_counter_destroy(&sbinfo->si_nfiles);
27015 + au_rw_write_lock(&sbinfo->si_rwsem);
27016 + au_br_free(sbinfo);
27017 + au_rw_write_unlock(&sbinfo->si_rwsem);
27019 + au_delayed_kfree(sbinfo->si_branch);
27020 + mutex_destroy(&sbinfo->si_xib_mtx);
27021 + AuRwDestroy(&sbinfo->si_rwsem);
27023 + au_delayed_kfree(sbinfo);
27026 +int au_si_alloc(struct super_block *sb)
27029 + struct au_sbinfo *sbinfo;
27032 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
27033 + if (unlikely(!sbinfo))
27036 + /* will be reallocated separately */
27037 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
27038 + if (unlikely(!sbinfo->si_branch))
27041 + err = sysaufs_si_init(sbinfo);
27042 + if (unlikely(err))
27045 + au_nwt_init(&sbinfo->si_nowait);
27046 + au_rw_init_wlock(&sbinfo->si_rwsem);
27048 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
27049 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
27051 + sbinfo->si_bbot = -1;
27052 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
27054 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
27055 + sbinfo->si_wbr_create = AuWbrCreate_Def;
27056 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
27057 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
27059 + au_fhsm_init(sbinfo);
27061 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
27063 + sbinfo->si_xino_jiffy = jiffies;
27064 + sbinfo->si_xino_expire
27065 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
27066 + mutex_init(&sbinfo->si_xib_mtx);
27067 + sbinfo->si_xino_brid = -1;
27068 + /* leave si_xib_last_pindex and si_xib_next_bit */
27070 + au_sphl_init(&sbinfo->si_aopen);
27072 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
27073 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27074 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27075 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
27077 + for (i = 0; i < AuPlink_NHASH; i++)
27078 + au_sphl_init(sbinfo->si_plink + i);
27079 + init_waitqueue_head(&sbinfo->si_plink_wq);
27080 + spin_lock_init(&sbinfo->si_plink_maint_lock);
27082 + au_sphl_init(&sbinfo->si_files);
27084 + /* with getattr by default */
27085 + sbinfo->si_iop_array = aufs_iop;
27087 + /* leave other members for sysaufs and si_mnt. */
27088 + sbinfo->si_sb = sb;
27089 + sb->s_fs_info = sbinfo;
27091 + return 0; /* success */
27094 + au_delayed_kfree(sbinfo->si_branch);
27096 + au_delayed_kfree(sbinfo);
27101 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
27104 + struct au_branch **brp;
27106 + AuRwMustWriteLock(&sbinfo->si_rwsem);
27109 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
27110 + if (unlikely(!sz))
27111 + sz = sizeof(*brp);
27112 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
27115 + sbinfo->si_branch = brp;
27122 +/* ---------------------------------------------------------------------- */
27124 +unsigned int au_sigen_inc(struct super_block *sb)
27126 + unsigned int gen;
27127 + struct inode *inode;
27129 + SiMustWriteLock(sb);
27131 + gen = ++au_sbi(sb)->si_generation;
27132 + au_update_digen(sb->s_root);
27133 + inode = d_inode(sb->s_root);
27134 + au_update_iigen(inode, /*half*/0);
27135 + inode->i_version++;
27139 +aufs_bindex_t au_new_br_id(struct super_block *sb)
27141 + aufs_bindex_t br_id;
27143 + struct au_sbinfo *sbinfo;
27145 + SiMustWriteLock(sb);
27147 + sbinfo = au_sbi(sb);
27148 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
27149 + br_id = ++sbinfo->si_last_br_id;
27150 + AuDebugOn(br_id < 0);
27151 + if (br_id && au_br_index(sb, br_id) < 0)
27158 +/* ---------------------------------------------------------------------- */
27160 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
27161 +int si_read_lock(struct super_block *sb, int flags)
27166 + if (au_ftest_lock(flags, FLUSH))
27167 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27169 + si_noflush_read_lock(sb);
27170 + err = au_plink_maint(sb, flags);
27171 + if (unlikely(err))
27172 + si_read_unlock(sb);
27177 +int si_write_lock(struct super_block *sb, int flags)
27181 + if (au_ftest_lock(flags, FLUSH))
27182 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27184 + si_noflush_write_lock(sb);
27185 + err = au_plink_maint(sb, flags);
27186 + if (unlikely(err))
27187 + si_write_unlock(sb);
27192 +/* dentry and super_block lock. call at entry point */
27193 +int aufs_read_lock(struct dentry *dentry, int flags)
27196 + struct super_block *sb;
27198 + sb = dentry->d_sb;
27199 + err = si_read_lock(sb, flags);
27200 + if (unlikely(err))
27203 + if (au_ftest_lock(flags, DW))
27204 + di_write_lock_child(dentry);
27206 + di_read_lock_child(dentry, flags);
27208 + if (au_ftest_lock(flags, GEN)) {
27209 + err = au_digen_test(dentry, au_sigen(sb));
27210 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
27211 + AuDebugOn(!err && au_dbrange_test(dentry));
27213 + err = au_dbrange_test(dentry);
27214 + if (unlikely(err))
27215 + aufs_read_unlock(dentry, flags);
27222 +void aufs_read_unlock(struct dentry *dentry, int flags)
27224 + if (au_ftest_lock(flags, DW))
27225 + di_write_unlock(dentry);
27227 + di_read_unlock(dentry, flags);
27228 + si_read_unlock(dentry->d_sb);
27231 +void aufs_write_lock(struct dentry *dentry)
27233 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
27234 + di_write_lock_child(dentry);
27237 +void aufs_write_unlock(struct dentry *dentry)
27239 + di_write_unlock(dentry);
27240 + si_write_unlock(dentry->d_sb);
27243 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
27246 + unsigned int sigen;
27247 + struct super_block *sb;
27250 + err = si_read_lock(sb, flags);
27251 + if (unlikely(err))
27254 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
27256 + if (au_ftest_lock(flags, GEN)) {
27257 + sigen = au_sigen(sb);
27258 + err = au_digen_test(d1, sigen);
27259 + AuDebugOn(!err && au_dbrange_test(d1));
27261 + err = au_digen_test(d2, sigen);
27262 + AuDebugOn(!err && au_dbrange_test(d2));
27264 + if (unlikely(err))
27265 + aufs_read_and_write_unlock2(d1, d2);
27272 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
27274 + di_write_unlock2(d1, d2);
27275 + si_read_unlock(d1->d_sb);
27277 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27278 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27279 +++ linux/fs/aufs/spl.h 2017-05-06 22:16:52.781553511 +0200
27282 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27284 + * This program, aufs is free software; you can redistribute it and/or modify
27285 + * it under the terms of the GNU General Public License as published by
27286 + * the Free Software Foundation; either version 2 of the License, or
27287 + * (at your option) any later version.
27289 + * This program is distributed in the hope that it will be useful,
27290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27292 + * GNU General Public License for more details.
27294 + * You should have received a copy of the GNU General Public License
27295 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27299 + * simple list protected by a spinlock
27302 +#ifndef __AUFS_SPL_H__
27303 +#define __AUFS_SPL_H__
27308 +struct au_splhead {
27310 + struct list_head head;
27313 +static inline void au_spl_init(struct au_splhead *spl)
27315 + spin_lock_init(&spl->spin);
27316 + INIT_LIST_HEAD(&spl->head);
27319 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27321 + spin_lock(&spl->spin);
27322 + list_add(list, &spl->head);
27323 + spin_unlock(&spl->spin);
27326 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27328 + spin_lock(&spl->spin);
27330 + spin_unlock(&spl->spin);
27333 +static inline void au_spl_del_rcu(struct list_head *list,
27334 + struct au_splhead *spl)
27336 + spin_lock(&spl->spin);
27337 + list_del_rcu(list);
27338 + spin_unlock(&spl->spin);
27342 +/* ---------------------------------------------------------------------- */
27344 +struct au_sphlhead {
27346 + struct hlist_head head;
27349 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27351 + spin_lock_init(&sphl->spin);
27352 + INIT_HLIST_HEAD(&sphl->head);
27355 +static inline void au_sphl_add(struct hlist_node *hlist,
27356 + struct au_sphlhead *sphl)
27358 + spin_lock(&sphl->spin);
27359 + hlist_add_head(hlist, &sphl->head);
27360 + spin_unlock(&sphl->spin);
27363 +static inline void au_sphl_del(struct hlist_node *hlist,
27364 + struct au_sphlhead *sphl)
27366 + spin_lock(&sphl->spin);
27367 + hlist_del(hlist);
27368 + spin_unlock(&sphl->spin);
27371 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27372 + struct au_sphlhead *sphl)
27374 + spin_lock(&sphl->spin);
27375 + hlist_del_rcu(hlist);
27376 + spin_unlock(&sphl->spin);
27379 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27381 + unsigned long cnt;
27382 + struct hlist_node *pos;
27385 + spin_lock(&sphl->spin);
27386 + hlist_for_each(pos, &sphl->head)
27388 + spin_unlock(&sphl->spin);
27392 +#endif /* __KERNEL__ */
27393 +#endif /* __AUFS_SPL_H__ */
27394 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27395 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27396 +++ linux/fs/aufs/super.c 2017-05-06 22:16:52.781553511 +0200
27399 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27401 + * This program, aufs is free software; you can redistribute it and/or modify
27402 + * it under the terms of the GNU General Public License as published by
27403 + * the Free Software Foundation; either version 2 of the License, or
27404 + * (at your option) any later version.
27406 + * This program is distributed in the hope that it will be useful,
27407 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27408 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27409 + * GNU General Public License for more details.
27411 + * You should have received a copy of the GNU General Public License
27412 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27416 + * mount and super_block operations
27419 +#include <linux/mm.h>
27420 +#include <linux/seq_file.h>
27421 +#include <linux/statfs.h>
27422 +#include <linux/vmalloc.h>
27426 + * super_operations
27428 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27430 + struct au_icntnr *c;
27432 + c = au_cache_alloc_icntnr();
27434 + au_icntnr_init(c);
27435 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27436 + c->iinfo.ii_hinode = NULL;
27437 + return &c->vfs_inode;
27442 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27444 + struct inode *inode = container_of(head, struct inode, i_rcu);
27446 + au_cache_dfree_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27449 +static void aufs_destroy_inode(struct inode *inode)
27451 + if (!au_is_bad_inode(inode))
27452 + au_iinfo_fin(inode);
27453 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27456 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27458 + struct inode *inode;
27461 + inode = iget_locked(sb, ino);
27462 + if (unlikely(!inode)) {
27463 + inode = ERR_PTR(-ENOMEM);
27466 + if (!(inode->i_state & I_NEW))
27469 + err = au_xigen_new(inode);
27471 + err = au_iinfo_init(inode);
27473 + inode->i_version++;
27475 + iget_failed(inode);
27476 + inode = ERR_PTR(err);
27480 + /* never return NULL */
27481 + AuDebugOn(!inode);
27482 + AuTraceErrPtr(inode);
27486 +/* lock free root dinfo */
27487 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27490 + aufs_bindex_t bindex, bbot;
27491 + struct path path;
27492 + struct au_hdentry *hdp;
27493 + struct au_branch *br;
27494 + au_br_perm_str_t perm;
27497 + bbot = au_sbbot(sb);
27499 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27500 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27501 + br = au_sbr(sb, bindex);
27502 + path.mnt = au_br_mnt(br);
27503 + path.dentry = hdp->hd_dentry;
27504 + err = au_seq_path(seq, &path);
27506 + au_optstr_br_perm(&perm, br->br_perm);
27507 + seq_printf(seq, "=%s", perm.a);
27508 + if (bindex != bbot)
27509 + seq_putc(seq, ':');
27512 + if (unlikely(err || seq_has_overflowed(seq)))
27518 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
27519 + const char *append)
27524 + while (*pat != ':')
27527 + strcpy(p, append);
27528 + AuDebugOn(strlen(fmt) >= len);
27531 +static void au_show_wbr_create(struct seq_file *m, int v,
27532 + struct au_sbinfo *sbinfo)
27536 + struct au_wbr_mfs *mfs;
27538 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27540 + seq_puts(m, ",create=");
27541 + pat = au_optstr_wbr_create(v);
27542 + mfs = &sbinfo->si_wbr_mfs;
27544 + case AuWbrCreate_TDP:
27545 + case AuWbrCreate_RR:
27546 + case AuWbrCreate_MFS:
27547 + case AuWbrCreate_PMFS:
27548 + seq_puts(m, pat);
27550 + case AuWbrCreate_MFSRR:
27551 + case AuWbrCreate_TDMFS:
27552 + case AuWbrCreate_PMFSRR:
27553 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
27554 + seq_printf(m, fmt, mfs->mfsrr_watermark);
27556 + case AuWbrCreate_MFSV:
27557 + case AuWbrCreate_PMFSV:
27558 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
27559 + seq_printf(m, fmt,
27560 + jiffies_to_msecs(mfs->mfs_expire)
27563 + case AuWbrCreate_MFSRRV:
27564 + case AuWbrCreate_TDMFSV:
27565 + case AuWbrCreate_PMFSRRV:
27566 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
27567 + seq_printf(m, fmt, mfs->mfsrr_watermark,
27568 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
27575 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27577 +#ifdef CONFIG_SYSFS
27581 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27582 + aufs_bindex_t bindex, brid;
27583 + struct qstr *name;
27585 + struct dentry *d, *h_root;
27587 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27590 + f = au_sbi(sb)->si_xib;
27594 + /* stop printing the default xino path on the first writable branch */
27596 + brid = au_xino_brid(sb);
27598 + bindex = au_br_index(sb, brid);
27599 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27601 + d = f->f_path.dentry;
27602 + name = &d->d_name;
27603 + /* safe ->d_parent because the file is unlinked */
27604 + if (d->d_parent == h_root
27605 + && name->len == len
27606 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27609 + seq_puts(seq, ",xino=");
27610 + err = au_xino_path(seq, f);
27617 +/* seq_file will re-call me in case of too long string */
27618 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27621 + unsigned int mnt_flags, v;
27622 + struct super_block *sb;
27623 + struct au_sbinfo *sbinfo;
27625 +#define AuBool(name, str) do { \
27626 + v = au_opt_test(mnt_flags, name); \
27627 + if (v != au_opt_test(AuOpt_Def, name)) \
27628 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27631 +#define AuStr(name, str) do { \
27632 + v = mnt_flags & AuOptMask_##name; \
27633 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27634 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27637 +#define AuUInt(name, str, val) do { \
27638 + if (val != AUFS_##name##_DEF) \
27639 + seq_printf(m, "," #str "=%u", val); \
27642 + sb = dentry->d_sb;
27643 + if (sb->s_flags & MS_POSIXACL)
27644 + seq_puts(m, ",acl");
27646 + /* lock free root dinfo */
27647 + si_noflush_read_lock(sb);
27648 + sbinfo = au_sbi(sb);
27649 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27651 + mnt_flags = au_mntflags(sb);
27652 + if (au_opt_test(mnt_flags, XINO)) {
27653 + err = au_show_xino(m, sb);
27654 + if (unlikely(err))
27657 + seq_puts(m, ",noxino");
27659 + AuBool(TRUNC_XINO, trunc_xino);
27660 + AuStr(UDBA, udba);
27661 + AuBool(SHWH, shwh);
27662 + AuBool(PLINK, plink);
27663 + AuBool(DIO, dio);
27664 + AuBool(DIRPERM1, dirperm1);
27666 + v = sbinfo->si_wbr_create;
27667 + if (v != AuWbrCreate_Def)
27668 + au_show_wbr_create(m, v, sbinfo);
27670 + v = sbinfo->si_wbr_copyup;
27671 + if (v != AuWbrCopyup_Def)
27672 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27674 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27675 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27676 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27678 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27680 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27681 + AuUInt(RDCACHE, rdcache, v);
27683 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27684 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27686 + au_fhsm_show(m, sbinfo);
27688 + AuBool(SUM, sum);
27689 + /* AuBool(SUM_W, wsum); */
27690 + AuBool(WARN_PERM, warn_perm);
27691 + AuBool(VERBOSE, verbose);
27694 + /* be sure to print "br:" last */
27695 + if (!sysaufs_brs) {
27696 + seq_puts(m, ",br:");
27697 + au_show_brs(m, sb);
27699 + si_read_unlock(sb);
27707 +/* ---------------------------------------------------------------------- */
27709 +/* sum mode which returns the summation for statfs(2) */
27711 +static u64 au_add_till_max(u64 a, u64 b)
27719 + return ULLONG_MAX;
27722 +static u64 au_mul_till_max(u64 a, long mul)
27730 + return ULLONG_MAX;
27733 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27736 + long bsize, factor;
27737 + u64 blocks, bfree, bavail, files, ffree;
27738 + aufs_bindex_t bbot, bindex, i;
27739 + unsigned char shared;
27740 + struct path h_path;
27741 + struct super_block *h_sb;
27744 + bsize = LONG_MAX;
27750 + bbot = au_sbbot(sb);
27751 + for (bindex = 0; bindex <= bbot; bindex++) {
27752 + h_path.mnt = au_sbr_mnt(sb, bindex);
27753 + h_sb = h_path.mnt->mnt_sb;
27755 + for (i = 0; !shared && i < bindex; i++)
27756 + shared = (au_sbr_sb(sb, i) == h_sb);
27760 + /* sb->s_root for NFS is unreliable */
27761 + h_path.dentry = h_path.mnt->mnt_root;
27762 + err = vfs_statfs(&h_path, buf);
27763 + if (unlikely(err))
27766 + if (bsize > buf->f_bsize) {
27768 + * we will reduce bsize, so we have to expand blocks
27769 + * etc. to match them again
27771 + factor = (bsize / buf->f_bsize);
27772 + blocks = au_mul_till_max(blocks, factor);
27773 + bfree = au_mul_till_max(bfree, factor);
27774 + bavail = au_mul_till_max(bavail, factor);
27775 + bsize = buf->f_bsize;
27778 + factor = (buf->f_bsize / bsize);
27779 + blocks = au_add_till_max(blocks,
27780 + au_mul_till_max(buf->f_blocks, factor));
27781 + bfree = au_add_till_max(bfree,
27782 + au_mul_till_max(buf->f_bfree, factor));
27783 + bavail = au_add_till_max(bavail,
27784 + au_mul_till_max(buf->f_bavail, factor));
27785 + files = au_add_till_max(files, buf->f_files);
27786 + ffree = au_add_till_max(ffree, buf->f_ffree);
27789 + buf->f_bsize = bsize;
27790 + buf->f_blocks = blocks;
27791 + buf->f_bfree = bfree;
27792 + buf->f_bavail = bavail;
27793 + buf->f_files = files;
27794 + buf->f_ffree = ffree;
27795 + buf->f_frsize = 0;
27801 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27804 + struct path h_path;
27805 + struct super_block *sb;
27807 + /* lock free root dinfo */
27808 + sb = dentry->d_sb;
27809 + si_noflush_read_lock(sb);
27810 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27811 + /* sb->s_root for NFS is unreliable */
27812 + h_path.mnt = au_sbr_mnt(sb, 0);
27813 + h_path.dentry = h_path.mnt->mnt_root;
27814 + err = vfs_statfs(&h_path, buf);
27816 + err = au_statfs_sum(sb, buf);
27817 + si_read_unlock(sb);
27820 + buf->f_type = AUFS_SUPER_MAGIC;
27821 + buf->f_namelen = AUFS_MAX_NAMELEN;
27822 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27824 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27829 +/* ---------------------------------------------------------------------- */
27831 +static int aufs_sync_fs(struct super_block *sb, int wait)
27834 + aufs_bindex_t bbot, bindex;
27835 + struct au_branch *br;
27836 + struct super_block *h_sb;
27839 + si_noflush_read_lock(sb);
27840 + bbot = au_sbbot(sb);
27841 + for (bindex = 0; bindex <= bbot; bindex++) {
27842 + br = au_sbr(sb, bindex);
27843 + if (!au_br_writable(br->br_perm))
27846 + h_sb = au_sbr_sb(sb, bindex);
27847 + e = vfsub_sync_filesystem(h_sb, wait);
27848 + if (unlikely(e && !err))
27850 + /* go on even if an error happens */
27852 + si_read_unlock(sb);
27857 +/* ---------------------------------------------------------------------- */
27859 +/* final actions when unmounting a file system */
27860 +static void aufs_put_super(struct super_block *sb)
27862 + struct au_sbinfo *sbinfo;
27864 + sbinfo = au_sbi(sb);
27868 + dbgaufs_si_fin(sbinfo);
27869 + kobject_put(&sbinfo->si_kobj);
27872 +/* ---------------------------------------------------------------------- */
27874 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27875 + struct super_block *sb, void *arg)
27878 + unsigned long long n, sz;
27885 + if (*hint > ULLONG_MAX / sizeof(array)) {
27886 + array = ERR_PTR(-EMFILE);
27887 + pr_err("hint %llu\n", *hint);
27891 + sz = sizeof(array) * *hint;
27892 + array = kzalloc(sz, GFP_NOFS);
27893 + if (unlikely(!array))
27894 + array = vzalloc(sz);
27895 + if (unlikely(!array)) {
27896 + array = ERR_PTR(-ENOMEM);
27900 + n = cb(sb, array, *hint, arg);
27901 + AuDebugOn(n > *hint);
27908 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27909 + unsigned long long max __maybe_unused,
27912 + unsigned long long n;
27913 + struct inode **p, *inode;
27914 + struct list_head *head;
27919 + spin_lock(&sb->s_inode_list_lock);
27920 + list_for_each_entry(inode, head, i_sb_list) {
27921 + if (!au_is_bad_inode(inode)
27922 + && au_ii(inode)->ii_btop >= 0) {
27923 + spin_lock(&inode->i_lock);
27924 + if (atomic_read(&inode->i_count)) {
27928 + AuDebugOn(n > max);
27930 + spin_unlock(&inode->i_lock);
27933 + spin_unlock(&sb->s_inode_list_lock);
27938 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27940 + *max = au_ninodes(sb);
27941 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27944 +void au_iarray_free(struct inode **a, unsigned long long max)
27946 + unsigned long long ull;
27948 + for (ull = 0; ull < max; ull++)
27953 +/* ---------------------------------------------------------------------- */
27956 + * refresh dentry and inode at remount time.
27958 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27959 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27960 + struct dentry *parent)
27964 + di_write_lock_child(dentry);
27965 + di_read_lock_parent(parent, AuLock_IR);
27966 + err = au_refresh_dentry(dentry, parent);
27967 + if (!err && dir_flags)
27968 + au_hn_reset(d_inode(dentry), dir_flags);
27969 + di_read_unlock(parent, AuLock_IR);
27970 + di_write_unlock(dentry);
27975 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27976 + struct au_sbinfo *sbinfo,
27977 + const unsigned int dir_flags, unsigned int do_idop)
27980 + struct dentry *parent;
27983 + parent = dget_parent(dentry);
27984 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27985 + if (d_really_is_positive(dentry)) {
27986 + if (!d_is_dir(dentry))
27987 + err = au_do_refresh(dentry, /*dir_flags*/0,
27990 + err = au_do_refresh(dentry, dir_flags, parent);
27991 + if (unlikely(err))
27992 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27995 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27996 + AuDbgDentry(dentry);
28002 + au_refresh_dop(dentry, /*force_reval*/0);
28004 + au_refresh_dop(dentry, /*force_reval*/1);
28010 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
28012 + int err, i, j, ndentry, e;
28013 + unsigned int sigen;
28014 + struct au_dcsub_pages dpages;
28015 + struct au_dpage *dpage;
28016 + struct dentry **dentries, *d;
28017 + struct au_sbinfo *sbinfo;
28018 + struct dentry *root = sb->s_root;
28019 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
28022 + au_refresh_dop(root, /*force_reval*/0);
28024 + err = au_dpages_init(&dpages, GFP_NOFS);
28025 + if (unlikely(err))
28027 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
28028 + if (unlikely(err))
28031 + sigen = au_sigen(sb);
28032 + sbinfo = au_sbi(sb);
28033 + for (i = 0; i < dpages.ndpage; i++) {
28034 + dpage = dpages.dpages + i;
28035 + dentries = dpage->dentries;
28036 + ndentry = dpage->ndentry;
28037 + for (j = 0; j < ndentry; j++) {
28039 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
28041 + if (unlikely(e && !err))
28043 + /* go on even err */
28048 + au_dpages_free(&dpages);
28053 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
28056 + unsigned int sigen;
28057 + unsigned long long max, ull;
28058 + struct inode *inode, **array;
28060 + array = au_iarray_alloc(sb, &max);
28061 + err = PTR_ERR(array);
28062 + if (IS_ERR(array))
28066 + sigen = au_sigen(sb);
28067 + for (ull = 0; ull < max; ull++) {
28068 + inode = array[ull];
28069 + if (unlikely(!inode))
28073 + ii_write_lock_child(inode);
28074 + if (au_iigen(inode, NULL) != sigen) {
28075 + e = au_refresh_hinode_self(inode);
28076 + if (unlikely(e)) {
28077 + au_refresh_iop(inode, /*force_getattr*/1);
28078 + pr_err("error %d, i%lu\n", e, inode->i_ino);
28081 + /* go on even if err */
28084 + if (!e && do_idop)
28085 + au_refresh_iop(inode, /*force_getattr*/0);
28086 + ii_write_unlock(inode);
28089 + au_iarray_free(array, max);
28095 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
28098 + unsigned int udba;
28099 + aufs_bindex_t bindex, bbot;
28100 + struct dentry *root;
28101 + struct inode *inode;
28102 + struct au_branch *br;
28103 + struct au_sbinfo *sbi;
28105 + au_sigen_inc(sb);
28106 + sbi = au_sbi(sb);
28107 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
28109 + root = sb->s_root;
28110 + DiMustNoWaiters(root);
28111 + inode = d_inode(root);
28112 + IiMustNoWaiters(inode);
28114 + udba = au_opt_udba(sb);
28115 + bbot = au_sbbot(sb);
28116 + for (bindex = 0; bindex <= bbot; bindex++) {
28117 + br = au_sbr(sb, bindex);
28118 + err = au_hnotify_reset_br(udba, br, br->br_perm);
28119 + if (unlikely(err))
28120 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
28122 + /* go on even if err */
28124 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
28127 + if (au_ftest_si(sbi, NO_DREVAL)) {
28128 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
28129 + sb->s_d_op = &aufs_dop_noreval;
28130 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
28131 + sbi->si_iop_array = aufs_iop_nogetattr;
28133 + AuDebugOn(sb->s_d_op == &aufs_dop);
28134 + sb->s_d_op = &aufs_dop;
28135 + AuDebugOn(sbi->si_iop_array == aufs_iop);
28136 + sbi->si_iop_array = aufs_iop;
28138 + pr_info("reset to %pf and %pf\n",
28139 + sb->s_d_op, sbi->si_iop_array);
28142 + di_write_unlock(root);
28143 + err = au_refresh_d(sb, do_idop);
28144 + e = au_refresh_i(sb, do_idop);
28145 + if (unlikely(e && !err))
28147 + /* aufs_write_lock() calls ..._child() */
28148 + di_write_lock_child(root);
28150 + au_cpup_attr_all(inode, /*force*/1);
28152 + if (unlikely(err))
28153 + AuIOErr("refresh failed, ignored, %d\n", err);
28156 +/* stop extra interpretation of errno in mount(8), and strange error messages */
28157 +static int cvt_err(int err)
28171 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
28174 + unsigned int mntflags;
28175 + struct au_opts opts = {
28178 + struct dentry *root;
28179 + struct inode *inode;
28180 + struct au_sbinfo *sbinfo;
28183 + root = sb->s_root;
28184 + if (!data || !*data) {
28185 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28187 + di_write_lock_child(root);
28188 + err = au_opts_verify(sb, *flags, /*pending*/0);
28189 + aufs_write_unlock(root);
28195 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28196 + if (unlikely(!opts.opt))
28198 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28199 + opts.flags = AuOpts_REMOUNT;
28200 + opts.sb_flags = *flags;
28202 + /* parse it before aufs lock */
28203 + err = au_opts_parse(sb, data, &opts);
28204 + if (unlikely(err))
28207 + sbinfo = au_sbi(sb);
28208 + inode = d_inode(root);
28209 + inode_lock(inode);
28210 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28211 + if (unlikely(err))
28213 + di_write_lock_child(root);
28215 + /* au_opts_remount() may return an error */
28216 + err = au_opts_remount(sb, &opts);
28217 + au_opts_free(&opts);
28219 + if (au_ftest_opts(opts.flags, REFRESH))
28220 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
28222 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
28223 + mntflags = au_mntflags(sb);
28224 + do_dx = !!au_opt_test(mntflags, DIO);
28225 + au_dy_arefresh(do_dx);
28228 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
28229 + aufs_write_unlock(root);
28232 + inode_unlock(inode);
28234 + au_delayed_free_page((unsigned long)opts.opt);
28236 + err = cvt_err(err);
28241 +static const struct super_operations aufs_sop = {
28242 + .alloc_inode = aufs_alloc_inode,
28243 + .destroy_inode = aufs_destroy_inode,
28244 + /* always deleting, no clearing */
28245 + .drop_inode = generic_delete_inode,
28246 + .show_options = aufs_show_options,
28247 + .statfs = aufs_statfs,
28248 + .put_super = aufs_put_super,
28249 + .sync_fs = aufs_sync_fs,
28250 + .remount_fs = aufs_remount_fs
28253 +/* ---------------------------------------------------------------------- */
28255 +static int alloc_root(struct super_block *sb)
28258 + struct inode *inode;
28259 + struct dentry *root;
28262 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28263 + err = PTR_ERR(inode);
28264 + if (IS_ERR(inode))
28267 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28268 + inode->i_fop = &aufs_dir_fop;
28269 + inode->i_mode = S_IFDIR;
28270 + set_nlink(inode, 2);
28271 + unlock_new_inode(inode);
28273 + root = d_make_root(inode);
28274 + if (unlikely(!root))
28276 + err = PTR_ERR(root);
28277 + if (IS_ERR(root))
28280 + err = au_di_init(root);
28282 + sb->s_root = root;
28283 + return 0; /* success */
28291 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28292 + int silent __maybe_unused)
28295 + struct au_opts opts = {
28298 + struct au_sbinfo *sbinfo;
28299 + struct dentry *root;
28300 + struct inode *inode;
28301 + char *arg = raw_data;
28303 + if (unlikely(!arg || !*arg)) {
28305 + pr_err("no arg\n");
28310 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28311 + if (unlikely(!opts.opt))
28313 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28314 + opts.sb_flags = sb->s_flags;
28316 + err = au_si_alloc(sb);
28317 + if (unlikely(err))
28319 + sbinfo = au_sbi(sb);
28321 + /* all timestamps always follow the ones on the branch */
28322 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28323 + sb->s_op = &aufs_sop;
28324 + sb->s_d_op = &aufs_dop;
28325 + sb->s_magic = AUFS_SUPER_MAGIC;
28326 + sb->s_maxbytes = 0;
28327 + sb->s_stack_depth = 1;
28328 + au_export_init(sb);
28329 + au_xattr_init(sb);
28331 + err = alloc_root(sb);
28332 + if (unlikely(err)) {
28333 + si_write_unlock(sb);
28336 + root = sb->s_root;
28337 + inode = d_inode(root);
28340 + * actually we can parse options regardless aufs lock here.
28341 + * but at remount time, parsing must be done before aufs lock.
28342 + * so we follow the same rule.
28344 + ii_write_lock_parent(inode);
28345 + aufs_write_unlock(root);
28346 + err = au_opts_parse(sb, arg, &opts);
28347 + if (unlikely(err))
28350 + /* lock vfs_inode first, then aufs. */
28351 + inode_lock(inode);
28352 + aufs_write_lock(root);
28353 + err = au_opts_mount(sb, &opts);
28354 + au_opts_free(&opts);
28355 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28356 + sb->s_d_op = &aufs_dop_noreval;
28357 + pr_info("%pf\n", sb->s_d_op);
28358 + au_refresh_dop(root, /*force_reval*/0);
28359 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28360 + au_refresh_iop(inode, /*force_getattr*/0);
28362 + aufs_write_unlock(root);
28363 + inode_unlock(inode);
28365 + goto out_opts; /* success */
28369 + sb->s_root = NULL;
28371 + dbgaufs_si_fin(sbinfo);
28372 + kobject_put(&sbinfo->si_kobj);
28373 + sb->s_fs_info = NULL;
28375 + au_delayed_free_page((unsigned long)opts.opt);
28378 + err = cvt_err(err);
28383 +/* ---------------------------------------------------------------------- */
28385 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28386 + const char *dev_name __maybe_unused,
28389 + struct dentry *root;
28390 + struct super_block *sb;
28392 + /* all timestamps always follow the ones on the branch */
28393 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28394 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28395 + if (IS_ERR(root))
28399 + si_write_lock(sb, !AuLock_FLUSH);
28400 + sysaufs_brs_add(sb, 0);
28401 + si_write_unlock(sb);
28402 + au_sbilist_add(sb);
28408 +static void aufs_kill_sb(struct super_block *sb)
28410 + struct au_sbinfo *sbinfo;
28412 + sbinfo = au_sbi(sb);
28414 + au_sbilist_del(sb);
28415 + aufs_write_lock(sb->s_root);
28417 + if (sbinfo->si_wbr_create_ops->fin)
28418 + sbinfo->si_wbr_create_ops->fin(sb);
28419 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28420 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28421 + au_remount_refresh(sb, /*do_idop*/0);
28423 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28424 + au_plink_put(sb, /*verbose*/1);
28426 + sbinfo->si_sb = NULL;
28427 + aufs_write_unlock(sb->s_root);
28428 + au_nwt_flush(&sbinfo->si_nowait);
28430 + kill_anon_super(sb);
28433 +struct file_system_type aufs_fs_type = {
28434 + .name = AUFS_FSTYPE,
28435 + /* a race between rename and others */
28436 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28437 + .mount = aufs_mount,
28438 + .kill_sb = aufs_kill_sb,
28439 + /* no need to __module_get() and module_put(). */
28440 + .owner = THIS_MODULE,
28442 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28443 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28444 +++ linux/fs/aufs/super.h 2017-05-06 22:16:52.781553511 +0200
28447 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28449 + * This program, aufs is free software; you can redistribute it and/or modify
28450 + * it under the terms of the GNU General Public License as published by
28451 + * the Free Software Foundation; either version 2 of the License, or
28452 + * (at your option) any later version.
28454 + * This program is distributed in the hope that it will be useful,
28455 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28457 + * GNU General Public License for more details.
28459 + * You should have received a copy of the GNU General Public License
28460 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28464 + * super_block operations
28467 +#ifndef __AUFS_SUPER_H__
28468 +#define __AUFS_SUPER_H__
28472 +#include <linux/fs.h>
28473 +#include <linux/kobject.h>
28474 +#include "rwsem.h"
28478 +/* policies to select one among multiple writable branches */
28479 +struct au_wbr_copyup_operations {
28480 + int (*copyup)(struct dentry *dentry);
28483 +#define AuWbr_DIR 1 /* target is a dir */
28484 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28486 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28487 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28488 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28490 +struct au_wbr_create_operations {
28491 + int (*create)(struct dentry *dentry, unsigned int flags);
28492 + int (*init)(struct super_block *sb);
28493 + int (*fin)(struct super_block *sb);
28496 +struct au_wbr_mfs {
28497 + struct mutex mfs_lock; /* protect this structure */
28498 + unsigned long mfs_jiffy;
28499 + unsigned long mfs_expire;
28500 + aufs_bindex_t mfs_bindex;
28502 + unsigned long long mfsrr_bytes;
28503 + unsigned long long mfsrr_watermark;
28506 +#define AuPlink_NHASH 100
28507 +static inline int au_plink_hash(ino_t ino)
28509 + return ino % AuPlink_NHASH;
28512 +/* File-based Hierarchical Storage Management */
28514 +#ifdef CONFIG_AUFS_FHSM
28515 + /* allow only one process who can receive the notification */
28516 + spinlock_t fhsm_spin;
28518 + wait_queue_head_t fhsm_wqh;
28519 + atomic_t fhsm_readable;
28521 + /* these are protected by si_rwsem */
28522 + unsigned long fhsm_expire;
28523 + aufs_bindex_t fhsm_bottom;
28528 +struct au_sbinfo {
28529 + /* nowait tasks in the system-wide workqueue */
28530 + struct au_nowait_tasks si_nowait;
28533 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28534 + * rwsem for au_sbinfo is necessary.
28536 + struct au_rwsem si_rwsem;
28539 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28542 + struct percpu_counter si_ninodes, si_nfiles;
28544 + /* branch management */
28545 + unsigned int si_generation;
28547 + /* see AuSi_ flags */
28548 + unsigned char au_si_status;
28550 + aufs_bindex_t si_bbot;
28552 + /* dirty trick to keep br_id plus */
28553 + unsigned int si_last_br_id :
28554 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28555 + struct au_branch **si_branch;
28557 + /* policy to select a writable branch */
28558 + unsigned char si_wbr_copyup;
28559 + unsigned char si_wbr_create;
28560 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28561 + struct au_wbr_create_operations *si_wbr_create_ops;
28563 + /* round robin */
28564 + atomic_t si_wbr_rr_next;
28566 + /* most free space */
28567 + struct au_wbr_mfs si_wbr_mfs;
28569 + /* File-based Hierarchical Storage Management */
28570 + struct au_fhsm si_fhsm;
28572 + /* mount flags */
28573 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28574 + unsigned int si_mntflags;
28576 + /* external inode number (bitmap and translation table) */
28577 + vfs_readf_t si_xread;
28578 + vfs_writef_t si_xwrite;
28579 + struct file *si_xib;
28580 + struct mutex si_xib_mtx; /* protect xib members */
28581 + unsigned long *si_xib_buf;
28582 + unsigned long si_xib_last_pindex;
28583 + int si_xib_next_bit;
28584 + aufs_bindex_t si_xino_brid;
28585 + unsigned long si_xino_jiffy;
28586 + unsigned long si_xino_expire;
28587 + /* reserved for future use */
28588 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28590 +#ifdef CONFIG_AUFS_EXPORT
28591 + /* i_generation */
28592 + struct file *si_xigen;
28593 + atomic_t si_xigen_next;
28596 + /* dirty trick to suppoer atomic_open */
28597 + struct au_sphlhead si_aopen;
28599 + /* vdir parameters */
28600 + unsigned long si_rdcache; /* max cache time in jiffies */
28601 + unsigned int si_rdblk; /* deblk size */
28602 + unsigned int si_rdhash; /* hash size */
28605 + * If the number of whiteouts are larger than si_dirwh, leave all of
28606 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28607 + * future fsck.aufs or kernel thread will remove them later.
28608 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28610 + unsigned int si_dirwh;
28612 + /* pseudo_link list */
28613 + struct au_sphlhead si_plink[AuPlink_NHASH];
28614 + wait_queue_head_t si_plink_wq;
28615 + spinlock_t si_plink_maint_lock;
28616 + pid_t si_plink_maint_pid;
28619 + struct au_sphlhead si_files;
28621 + /* with/without getattr, brother of sb->s_d_op */
28622 + struct inode_operations *si_iop_array;
28625 + * sysfs and lifetime management.
28626 + * this is not a small structure and it may be a waste of memory in case
28627 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28628 + * but using sysfs is majority.
28630 + struct kobject si_kobj;
28631 +#ifdef CONFIG_DEBUG_FS
28632 + struct dentry *si_dbgaufs;
28633 + struct dentry *si_dbgaufs_plink;
28634 + struct dentry *si_dbgaufs_xib;
28635 +#ifdef CONFIG_AUFS_EXPORT
28636 + struct dentry *si_dbgaufs_xigen;
28640 +#ifdef CONFIG_AUFS_SBILIST
28641 + struct hlist_node si_list;
28644 + /* dirty, necessary for unmounting, sysfs and sysrq */
28645 + struct super_block *si_sb;
28648 +/* sbinfo status flags */
28650 + * set true when refresh_dirs() failed at remount time.
28651 + * then try refreshing dirs at access time again.
28652 + * if it is false, refreshing dirs at access time is unnecesary
28654 +#define AuSi_FAILED_REFRESH_DIR 1
28655 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28656 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28658 +#ifndef CONFIG_AUFS_FHSM
28660 +#define AuSi_FHSM 0
28663 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28664 + unsigned int flag)
28666 + AuRwMustAnyLock(&sbi->si_rwsem);
28667 + return sbi->au_si_status & flag;
28669 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28670 +#define au_fset_si(sbinfo, name) do { \
28671 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28672 + (sbinfo)->au_si_status |= AuSi_##name; \
28674 +#define au_fclr_si(sbinfo, name) do { \
28675 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28676 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28679 +/* ---------------------------------------------------------------------- */
28681 +/* policy to select one among writable branches */
28682 +#define AuWbrCopyup(sbinfo, ...) \
28683 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28684 +#define AuWbrCreate(sbinfo, ...) \
28685 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28687 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28688 +#define AuLock_DW 1 /* write-lock dentry */
28689 +#define AuLock_IR (1 << 1) /* read-lock inode */
28690 +#define AuLock_IW (1 << 2) /* write-lock inode */
28691 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28692 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28693 + /* except RENAME_EXCHANGE */
28694 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28695 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28696 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28697 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28698 +#define au_fset_lock(flags, name) \
28699 + do { (flags) |= AuLock_##name; } while (0)
28700 +#define au_fclr_lock(flags, name) \
28701 + do { (flags) &= ~AuLock_##name; } while (0)
28703 +/* ---------------------------------------------------------------------- */
28706 +extern struct file_system_type aufs_fs_type;
28707 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28708 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28709 + unsigned long long max, void *arg);
28710 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28711 + struct super_block *sb, void *arg);
28712 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28713 +void au_iarray_free(struct inode **a, unsigned long long max);
28716 +void au_si_free(struct kobject *kobj);
28717 +int au_si_alloc(struct super_block *sb);
28718 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28720 +unsigned int au_sigen_inc(struct super_block *sb);
28721 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28723 +int si_read_lock(struct super_block *sb, int flags);
28724 +int si_write_lock(struct super_block *sb, int flags);
28725 +int aufs_read_lock(struct dentry *dentry, int flags);
28726 +void aufs_read_unlock(struct dentry *dentry, int flags);
28727 +void aufs_write_lock(struct dentry *dentry);
28728 +void aufs_write_unlock(struct dentry *dentry);
28729 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28730 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28732 +/* wbr_policy.c */
28733 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28734 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28735 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28736 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28737 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28740 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28742 +#ifdef CONFIG_AUFS_FHSM
28745 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28749 + spin_lock(&fhsm->fhsm_spin);
28750 + pid = fhsm->fhsm_pid;
28751 + spin_unlock(&fhsm->fhsm_spin);
28756 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28757 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28758 +int au_fhsm_fd(struct super_block *sb, int oflags);
28759 +int au_fhsm_br_alloc(struct au_branch *br);
28760 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28761 +void au_fhsm_fin(struct super_block *sb);
28762 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28763 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28764 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28766 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28768 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28769 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28770 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28771 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28772 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28773 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28774 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28775 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28776 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28779 +/* ---------------------------------------------------------------------- */
28781 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28783 + return sb->s_fs_info;
28786 +/* ---------------------------------------------------------------------- */
28788 +#ifdef CONFIG_AUFS_EXPORT
28789 +int au_test_nfsd(void);
28790 +void au_export_init(struct super_block *sb);
28791 +void au_xigen_inc(struct inode *inode);
28792 +int au_xigen_new(struct inode *inode);
28793 +int au_xigen_set(struct super_block *sb, struct file *base);
28794 +void au_xigen_clr(struct super_block *sb);
28796 +static inline int au_busy_or_stale(void)
28798 + if (!au_test_nfsd())
28803 +AuStubInt0(au_test_nfsd, void)
28804 +AuStubVoid(au_export_init, struct super_block *sb)
28805 +AuStubVoid(au_xigen_inc, struct inode *inode)
28806 +AuStubInt0(au_xigen_new, struct inode *inode)
28807 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28808 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28809 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28810 +#endif /* CONFIG_AUFS_EXPORT */
28812 +/* ---------------------------------------------------------------------- */
28814 +#ifdef CONFIG_AUFS_SBILIST
28816 +extern struct au_sphlhead au_sbilist;
28818 +static inline void au_sbilist_init(void)
28820 + au_sphl_init(&au_sbilist);
28823 +static inline void au_sbilist_add(struct super_block *sb)
28825 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28828 +static inline void au_sbilist_del(struct super_block *sb)
28830 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28833 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28834 +static inline void au_sbilist_lock(void)
28836 + spin_lock(&au_sbilist.spin);
28839 +static inline void au_sbilist_unlock(void)
28841 + spin_unlock(&au_sbilist.spin);
28843 +#define AuGFP_SBILIST GFP_ATOMIC
28845 +AuStubVoid(au_sbilist_lock, void)
28846 +AuStubVoid(au_sbilist_unlock, void)
28847 +#define AuGFP_SBILIST GFP_NOFS
28848 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28850 +AuStubVoid(au_sbilist_init, void)
28851 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28852 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28853 +AuStubVoid(au_sbilist_lock, void)
28854 +AuStubVoid(au_sbilist_unlock, void)
28855 +#define AuGFP_SBILIST GFP_NOFS
28858 +/* ---------------------------------------------------------------------- */
28860 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28863 + * This function is a dynamic '__init' function actually,
28864 + * so the tiny check for si_rwsem is unnecessary.
28866 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28867 +#ifdef CONFIG_DEBUG_FS
28868 + sbinfo->si_dbgaufs = NULL;
28869 + sbinfo->si_dbgaufs_plink = NULL;
28870 + sbinfo->si_dbgaufs_xib = NULL;
28871 +#ifdef CONFIG_AUFS_EXPORT
28872 + sbinfo->si_dbgaufs_xigen = NULL;
28877 +/* ---------------------------------------------------------------------- */
28879 +/* current->atomic_flags */
28880 +/* this value should never corrupt the ones defined in linux/sched.h */
28881 +#define PFA_AUFS 7
28883 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
28884 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
28885 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
28887 +static inline int si_pid_test(struct super_block *sb)
28889 + return !!task_test_aufs(current);
28892 +static inline void si_pid_clr(struct super_block *sb)
28894 + AuDebugOn(!task_test_aufs(current));
28895 + task_clear_aufs(current);
28898 +static inline void si_pid_set(struct super_block *sb)
28900 + AuDebugOn(task_test_aufs(current));
28901 + task_set_aufs(current);
28904 +/* ---------------------------------------------------------------------- */
28906 +/* lock superblock. mainly for entry point functions */
28908 + * __si_read_lock, __si_write_lock,
28909 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28911 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28913 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28914 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28915 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28917 +static inline void si_noflush_read_lock(struct super_block *sb)
28919 + __si_read_lock(sb);
28923 +static inline int si_noflush_read_trylock(struct super_block *sb)
28927 + locked = __si_read_trylock(sb);
28933 +static inline void si_noflush_write_lock(struct super_block *sb)
28935 + __si_write_lock(sb);
28939 +static inline int si_noflush_write_trylock(struct super_block *sb)
28943 + locked = __si_write_trylock(sb);
28949 +#if 0 /* reserved */
28950 +static inline int si_read_trylock(struct super_block *sb, int flags)
28952 + if (au_ftest_lock(flags, FLUSH))
28953 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28954 + return si_noflush_read_trylock(sb);
28958 +static inline void si_read_unlock(struct super_block *sb)
28961 + __si_read_unlock(sb);
28964 +#if 0 /* reserved */
28965 +static inline int si_write_trylock(struct super_block *sb, int flags)
28967 + if (au_ftest_lock(flags, FLUSH))
28968 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28969 + return si_noflush_write_trylock(sb);
28973 +static inline void si_write_unlock(struct super_block *sb)
28976 + __si_write_unlock(sb);
28979 +#if 0 /* reserved */
28980 +static inline void si_downgrade_lock(struct super_block *sb)
28982 + __si_downgrade_lock(sb);
28986 +/* ---------------------------------------------------------------------- */
28988 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28990 + SiMustAnyLock(sb);
28991 + return au_sbi(sb)->si_bbot;
28994 +static inline unsigned int au_mntflags(struct super_block *sb)
28996 + SiMustAnyLock(sb);
28997 + return au_sbi(sb)->si_mntflags;
29000 +static inline unsigned int au_sigen(struct super_block *sb)
29002 + SiMustAnyLock(sb);
29003 + return au_sbi(sb)->si_generation;
29006 +static inline unsigned long long au_ninodes(struct super_block *sb)
29008 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
29014 +static inline void au_ninodes_inc(struct super_block *sb)
29016 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
29019 +static inline void au_ninodes_dec(struct super_block *sb)
29021 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
29024 +static inline unsigned long long au_nfiles(struct super_block *sb)
29026 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
29032 +static inline void au_nfiles_inc(struct super_block *sb)
29034 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
29037 +static inline void au_nfiles_dec(struct super_block *sb)
29039 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
29042 +static inline struct au_branch *au_sbr(struct super_block *sb,
29043 + aufs_bindex_t bindex)
29045 + SiMustAnyLock(sb);
29046 + return au_sbi(sb)->si_branch[0 + bindex];
29049 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
29051 + SiMustWriteLock(sb);
29052 + au_sbi(sb)->si_xino_brid = brid;
29055 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
29057 + SiMustAnyLock(sb);
29058 + return au_sbi(sb)->si_xino_brid;
29061 +#endif /* __KERNEL__ */
29062 +#endif /* __AUFS_SUPER_H__ */
29063 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
29064 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
29065 +++ linux/fs/aufs/sysaufs.c 2017-05-06 22:16:52.781553511 +0200
29068 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29070 + * This program, aufs is free software; you can redistribute it and/or modify
29071 + * it under the terms of the GNU General Public License as published by
29072 + * the Free Software Foundation; either version 2 of the License, or
29073 + * (at your option) any later version.
29075 + * This program is distributed in the hope that it will be useful,
29076 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29077 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29078 + * GNU General Public License for more details.
29080 + * You should have received a copy of the GNU General Public License
29081 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29085 + * sysfs interface and lifetime management
29086 + * they are necessary regardless sysfs is disabled.
29089 +#include <linux/random.h>
29092 +unsigned long sysaufs_si_mask;
29093 +struct kset *sysaufs_kset;
29095 +#define AuSiAttr(_name) { \
29096 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
29097 + .show = sysaufs_si_##_name, \
29100 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
29101 +struct attribute *sysaufs_si_attrs[] = {
29102 + &sysaufs_si_attr_xi_path.attr,
29106 +static const struct sysfs_ops au_sbi_ops = {
29107 + .show = sysaufs_si_show
29110 +static struct kobj_type au_sbi_ktype = {
29111 + .release = au_si_free,
29112 + .sysfs_ops = &au_sbi_ops,
29113 + .default_attrs = sysaufs_si_attrs
29116 +/* ---------------------------------------------------------------------- */
29118 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
29122 + sbinfo->si_kobj.kset = sysaufs_kset;
29123 + /* cf. sysaufs_name() */
29124 + err = kobject_init_and_add
29125 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
29126 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
29128 + dbgaufs_si_null(sbinfo);
29130 + err = dbgaufs_si_init(sbinfo);
29131 + if (unlikely(err))
29132 + kobject_put(&sbinfo->si_kobj);
29137 +void sysaufs_fin(void)
29140 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29141 + kset_unregister(sysaufs_kset);
29144 +int __init sysaufs_init(void)
29149 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
29150 + } while (!sysaufs_si_mask);
29153 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
29154 + if (unlikely(!sysaufs_kset))
29156 + err = PTR_ERR(sysaufs_kset);
29157 + if (IS_ERR(sysaufs_kset))
29159 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29160 + if (unlikely(err)) {
29161 + kset_unregister(sysaufs_kset);
29165 + err = dbgaufs_init();
29166 + if (unlikely(err))
29171 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
29172 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
29173 +++ linux/fs/aufs/sysaufs.h 2017-05-06 22:16:52.781553511 +0200
29176 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29178 + * This program, aufs is free software; you can redistribute it and/or modify
29179 + * it under the terms of the GNU General Public License as published by
29180 + * the Free Software Foundation; either version 2 of the License, or
29181 + * (at your option) any later version.
29183 + * This program is distributed in the hope that it will be useful,
29184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29186 + * GNU General Public License for more details.
29188 + * You should have received a copy of the GNU General Public License
29189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29193 + * sysfs interface and mount lifetime management
29196 +#ifndef __SYSAUFS_H__
29197 +#define __SYSAUFS_H__
29201 +#include <linux/sysfs.h>
29202 +#include "module.h"
29204 +struct super_block;
29207 +struct sysaufs_si_attr {
29208 + struct attribute attr;
29209 + int (*show)(struct seq_file *seq, struct super_block *sb);
29212 +/* ---------------------------------------------------------------------- */
29215 +extern unsigned long sysaufs_si_mask;
29216 +extern struct kset *sysaufs_kset;
29217 +extern struct attribute *sysaufs_si_attrs[];
29218 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
29219 +int __init sysaufs_init(void);
29220 +void sysaufs_fin(void);
29222 +/* ---------------------------------------------------------------------- */
29224 +/* some people doesn't like to show a pointer in kernel */
29225 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
29227 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
29230 +#define SysaufsSiNamePrefix "si_"
29231 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29232 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29234 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29235 + sysaufs_si_id(sbinfo));
29239 +#ifdef CONFIG_SYSFS
29241 +extern struct attribute_group *sysaufs_attr_group;
29243 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29244 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29246 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29247 +#ifdef CONFIG_COMPAT
29248 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29251 +void sysaufs_br_init(struct au_branch *br);
29252 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29253 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29255 +#define sysaufs_brs_init() do {} while (0)
29258 +#define sysaufs_attr_group NULL
29260 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29261 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29262 + struct attribute *attr, char *buf)
29263 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29264 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29265 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29267 +static inline void sysaufs_brs_init(void)
29272 +#endif /* CONFIG_SYSFS */
29274 +#endif /* __KERNEL__ */
29275 +#endif /* __SYSAUFS_H__ */
29276 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29277 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29278 +++ linux/fs/aufs/sysfs.c 2017-05-06 22:16:52.781553511 +0200
29281 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29283 + * This program, aufs is free software; you can redistribute it and/or modify
29284 + * it under the terms of the GNU General Public License as published by
29285 + * the Free Software Foundation; either version 2 of the License, or
29286 + * (at your option) any later version.
29288 + * This program is distributed in the hope that it will be useful,
29289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29291 + * GNU General Public License for more details.
29293 + * You should have received a copy of the GNU General Public License
29294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29298 + * sysfs interface
29301 +#include <linux/compat.h>
29302 +#include <linux/seq_file.h>
29305 +#ifdef CONFIG_AUFS_FS_MODULE
29306 +/* this entry violates the "one line per file" policy of sysfs */
29307 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29311 + static char *conf =
29312 +/* this file is generated at compiling */
29313 +#include "conf.str"
29316 + err = snprintf(buf, PAGE_SIZE, conf);
29317 + if (unlikely(err >= PAGE_SIZE))
29322 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29325 +static struct attribute *au_attr[] = {
29326 +#ifdef CONFIG_AUFS_FS_MODULE
29327 + &au_config_attr.attr,
29329 + NULL, /* need to NULL terminate the list of attributes */
29332 +static struct attribute_group sysaufs_attr_group_body = {
29336 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29338 +/* ---------------------------------------------------------------------- */
29340 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29344 + SiMustAnyLock(sb);
29347 + if (au_opt_test(au_mntflags(sb), XINO)) {
29348 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29349 + seq_putc(seq, '\n');
29355 + * the lifetime of branch is independent from the entry under sysfs.
29356 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29359 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29360 + aufs_bindex_t bindex, int idx)
29363 + struct path path;
29364 + struct dentry *root;
29365 + struct au_branch *br;
29366 + au_br_perm_str_t perm;
29368 + AuDbg("b%d\n", bindex);
29371 + root = sb->s_root;
29372 + di_read_lock_parent(root, !AuLock_IR);
29373 + br = au_sbr(sb, bindex);
29376 + case AuBrSysfs_BR:
29377 + path.mnt = au_br_mnt(br);
29378 + path.dentry = au_h_dptr(root, bindex);
29379 + err = au_seq_path(seq, &path);
29381 + au_optstr_br_perm(&perm, br->br_perm);
29382 + seq_printf(seq, "=%s\n", perm.a);
29385 + case AuBrSysfs_BRID:
29386 + seq_printf(seq, "%d\n", br->br_id);
29389 + di_read_unlock(root, !AuLock_IR);
29390 + if (unlikely(err || seq_has_overflowed(seq)))
29396 +/* ---------------------------------------------------------------------- */
29398 +static struct seq_file *au_seq(char *p, ssize_t len)
29400 + struct seq_file *seq;
29402 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29404 + /* mutex_init(&seq.lock); */
29407 + return seq; /* success */
29410 + seq = ERR_PTR(-ENOMEM);
29414 +#define SysaufsBr_PREFIX "br"
29415 +#define SysaufsBrid_PREFIX "brid"
29417 +/* todo: file size may exceed PAGE_SIZE */
29418 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29424 + aufs_bindex_t bbot;
29425 + struct au_sbinfo *sbinfo;
29426 + struct super_block *sb;
29427 + struct seq_file *seq;
29429 + struct attribute **cattr;
29431 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29432 + sb = sbinfo->si_sb;
29435 + * prevent a race condition between sysfs and aufs.
29436 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29437 + * prohibits maintaining the sysfs entries.
29438 + * hew we acquire read lock after sysfs_get_active_two().
29439 + * on the other hand, the remount process may maintain the sysfs/aufs
29440 + * entries after acquiring write lock.
29441 + * it can cause a deadlock.
29442 + * simply we gave up processing read here.
29445 + if (unlikely(!si_noflush_read_trylock(sb)))
29448 + seq = au_seq(buf, PAGE_SIZE);
29449 + err = PTR_ERR(seq);
29453 + name = (void *)attr->name;
29454 + cattr = sysaufs_si_attrs;
29456 + if (!strcmp(name, (*cattr)->name)) {
29457 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29464 + if (!strncmp(name, SysaufsBrid_PREFIX,
29465 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29466 + idx = AuBrSysfs_BRID;
29467 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29468 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29469 + sizeof(SysaufsBr_PREFIX) - 1)) {
29470 + idx = AuBrSysfs_BR;
29471 + name += sizeof(SysaufsBr_PREFIX) - 1;
29475 + err = kstrtol(name, 10, &l);
29477 + bbot = au_sbbot(sb);
29479 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29486 + err = seq->count;
29487 + /* sysfs limit */
29488 + if (unlikely(err == PAGE_SIZE))
29491 + au_delayed_kfree(seq);
29493 + si_read_unlock(sb);
29498 +/* ---------------------------------------------------------------------- */
29500 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29504 + aufs_bindex_t bindex, bbot;
29507 + struct seq_file *seq;
29508 + struct au_branch *br;
29510 + si_read_lock(sb, AuLock_FLUSH);
29511 + bbot = au_sbbot(sb);
29517 + buf = (void *)__get_free_page(GFP_NOFS);
29518 + if (unlikely(!buf))
29521 + seq = au_seq(buf, PAGE_SIZE);
29522 + err = PTR_ERR(seq);
29526 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29527 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29528 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29529 + if (unlikely(err))
29532 + br = au_sbr(sb, bindex);
29533 + brid = br->br_id;
29534 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29535 + err = __put_user(brid, &arg->id);
29536 + if (unlikely(err))
29539 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29540 + err = __put_user(br->br_perm, &arg->perm);
29541 + if (unlikely(err))
29544 + err = au_seq_path(seq, &br->br_path);
29545 + if (unlikely(err))
29547 + seq_putc(seq, '\0');
29548 + if (!seq_has_overflowed(seq)) {
29549 + err = copy_to_user(arg->path, seq->buf, seq->count);
29551 + if (unlikely(err))
29558 + if (unlikely(err))
29562 + au_delayed_kfree(seq);
29564 + au_delayed_free_page((unsigned long)buf);
29566 + si_read_unlock(sb);
29570 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29572 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29575 +#ifdef CONFIG_COMPAT
29576 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29578 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29582 +/* ---------------------------------------------------------------------- */
29584 +void sysaufs_br_init(struct au_branch *br)
29587 + struct au_brsysfs *br_sysfs;
29588 + struct attribute *attr;
29590 + br_sysfs = br->br_sysfs;
29591 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29592 + attr = &br_sysfs->attr;
29593 + sysfs_attr_init(attr);
29594 + attr->name = br_sysfs->name;
29595 + attr->mode = S_IRUGO;
29600 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29602 + struct au_branch *br;
29603 + struct kobject *kobj;
29604 + struct au_brsysfs *br_sysfs;
29606 + aufs_bindex_t bbot;
29608 + dbgaufs_brs_del(sb, bindex);
29610 + if (!sysaufs_brs)
29613 + kobj = &au_sbi(sb)->si_kobj;
29614 + bbot = au_sbbot(sb);
29615 + for (; bindex <= bbot; bindex++) {
29616 + br = au_sbr(sb, bindex);
29617 + br_sysfs = br->br_sysfs;
29618 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29619 + sysfs_remove_file(kobj, &br_sysfs->attr);
29625 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29628 + aufs_bindex_t bbot;
29629 + struct kobject *kobj;
29630 + struct au_branch *br;
29631 + struct au_brsysfs *br_sysfs;
29633 + dbgaufs_brs_add(sb, bindex);
29635 + if (!sysaufs_brs)
29638 + kobj = &au_sbi(sb)->si_kobj;
29639 + bbot = au_sbbot(sb);
29640 + for (; bindex <= bbot; bindex++) {
29641 + br = au_sbr(sb, bindex);
29642 + br_sysfs = br->br_sysfs;
29643 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29644 + SysaufsBr_PREFIX "%d", bindex);
29645 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29646 + SysaufsBrid_PREFIX "%d", bindex);
29647 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29648 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29649 + if (unlikely(err))
29650 + pr_warn("failed %s under sysfs(%d)\n",
29651 + br_sysfs->name, err);
29656 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29657 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29658 +++ linux/fs/aufs/sysrq.c 2017-05-06 22:16:52.781553511 +0200
29661 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29663 + * This program, aufs is free software; you can redistribute it and/or modify
29664 + * it under the terms of the GNU General Public License as published by
29665 + * the Free Software Foundation; either version 2 of the License, or
29666 + * (at your option) any later version.
29668 + * This program is distributed in the hope that it will be useful,
29669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29671 + * GNU General Public License for more details.
29673 + * You should have received a copy of the GNU General Public License
29674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29678 + * magic sysrq hanlder
29681 +/* #include <linux/sysrq.h> */
29682 +#include <linux/writeback.h>
29685 +/* ---------------------------------------------------------------------- */
29687 +static void sysrq_sb(struct super_block *sb)
29690 + struct au_sbinfo *sbinfo;
29691 + struct file *file;
29692 + struct au_sphlhead *files;
29693 + struct au_finfo *finfo;
29695 + plevel = au_plevel;
29696 + au_plevel = KERN_WARNING;
29698 + /* since we define pr_fmt, call printk directly */
29699 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29701 + sbinfo = au_sbi(sb);
29702 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29703 + pr("superblock\n");
29707 + pr("root dentry\n");
29708 + au_dpri_dentry(sb->s_root);
29709 + pr("root inode\n");
29710 + au_dpri_inode(d_inode(sb->s_root));
29715 + int err, i, j, ndentry;
29716 + struct au_dcsub_pages dpages;
29717 + struct au_dpage *dpage;
29719 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29720 + if (unlikely(err))
29722 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29724 + for (i = 0; i < dpages.ndpage; i++) {
29725 + dpage = dpages.dpages + i;
29726 + ndentry = dpage->ndentry;
29727 + for (j = 0; j < ndentry; j++)
29728 + au_dpri_dentry(dpage->dentries[j]);
29730 + au_dpages_free(&dpages);
29738 + pr("isolated inode\n");
29739 + spin_lock(&sb->s_inode_list_lock);
29740 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29741 + spin_lock(&i->i_lock);
29742 + if (1 || hlist_empty(&i->i_dentry))
29743 + au_dpri_inode(i);
29744 + spin_unlock(&i->i_lock);
29746 + spin_unlock(&sb->s_inode_list_lock);
29750 + files = &au_sbi(sb)->si_files;
29751 + spin_lock(&files->spin);
29752 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29755 + file = finfo->fi_file;
29756 + mode = file_inode(file)->i_mode;
29757 + if (!special_file(mode))
29758 + au_dpri_file(file);
29760 + spin_unlock(&files->spin);
29764 + au_plevel = plevel;
29767 +/* ---------------------------------------------------------------------- */
29769 +/* module parameter */
29770 +static char *aufs_sysrq_key = "a";
29771 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29772 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29774 +static void au_sysrq(int key __maybe_unused)
29776 + struct au_sbinfo *sbinfo;
29779 + au_sbilist_lock();
29780 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29781 + sysrq_sb(sbinfo->si_sb);
29782 + au_sbilist_unlock();
29786 +static struct sysrq_key_op au_sysrq_op = {
29787 + .handler = au_sysrq,
29788 + .help_msg = "Aufs",
29789 + .action_msg = "Aufs",
29790 + .enable_mask = SYSRQ_ENABLE_DUMP
29793 +/* ---------------------------------------------------------------------- */
29795 +int __init au_sysrq_init(void)
29801 + key = *aufs_sysrq_key;
29802 + if ('a' <= key && key <= 'z')
29803 + err = register_sysrq_key(key, &au_sysrq_op);
29804 + if (unlikely(err))
29805 + pr_err("err %d, sysrq=%c\n", err, key);
29809 +void au_sysrq_fin(void)
29813 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29814 + if (unlikely(err))
29815 + pr_err("err %d (ignored)\n", err);
29817 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29818 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29819 +++ linux/fs/aufs/vdir.c 2017-05-06 22:16:52.781553511 +0200
29822 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29824 + * This program, aufs is free software; you can redistribute it and/or modify
29825 + * it under the terms of the GNU General Public License as published by
29826 + * the Free Software Foundation; either version 2 of the License, or
29827 + * (at your option) any later version.
29829 + * This program is distributed in the hope that it will be useful,
29830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29832 + * GNU General Public License for more details.
29834 + * You should have received a copy of the GNU General Public License
29835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29839 + * virtual or vertical directory
29844 +static unsigned int calc_size(int nlen)
29846 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29849 +static int set_deblk_end(union au_vdir_deblk_p *p,
29850 + union au_vdir_deblk_p *deblk_end)
29852 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29853 + p->de->de_str.len = 0;
29857 + return -1; /* error */
29860 +/* returns true or false */
29861 +static int is_deblk_end(union au_vdir_deblk_p *p,
29862 + union au_vdir_deblk_p *deblk_end)
29864 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29865 + return !p->de->de_str.len;
29869 +static unsigned char *last_deblk(struct au_vdir *vdir)
29871 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29874 +/* ---------------------------------------------------------------------- */
29876 +/* estimate the appropriate size for name hash table */
29877 +unsigned int au_rdhash_est(loff_t sz)
29885 + if (sz < AUFS_RDHASH_DEF)
29886 + n = AUFS_RDHASH_DEF;
29887 + /* pr_info("n %u\n", n); */
29892 + * the allocated memory has to be freed by
29893 + * au_nhash_wh_free() or au_nhash_de_free().
29895 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29897 + struct hlist_head *head;
29901 + sz = sizeof(*nhash->nh_head) * num_hash;
29902 + head = kmalloc(sz, gfp);
29904 + nhash->nh_num = num_hash;
29905 + nhash->nh_head = head;
29906 + for (u = 0; u < num_hash; u++)
29907 + INIT_HLIST_HEAD(head++);
29908 + return 0; /* success */
29914 +static void nhash_count(struct hlist_head *head)
29918 + struct hlist_node *pos;
29921 + hlist_for_each(pos, head)
29923 + pr_info("%lu\n", n);
29927 +static void au_nhash_wh_do_free(struct hlist_head *head)
29929 + struct au_vdir_wh *pos;
29930 + struct hlist_node *node;
29932 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29933 + au_delayed_kfree(pos);
29936 +static void au_nhash_de_do_free(struct hlist_head *head)
29938 + struct au_vdir_dehstr *pos;
29939 + struct hlist_node *node;
29941 + hlist_for_each_entry_safe(pos, node, head, hash)
29942 + au_cache_dfree_vdir_dehstr(pos);
29945 +static void au_nhash_do_free(struct au_nhash *nhash,
29946 + void (*free)(struct hlist_head *head))
29949 + struct hlist_head *head;
29951 + n = nhash->nh_num;
29955 + head = nhash->nh_head;
29956 + while (n-- > 0) {
29957 + nhash_count(head);
29960 + au_delayed_kfree(nhash->nh_head);
29963 +void au_nhash_wh_free(struct au_nhash *whlist)
29965 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29968 +static void au_nhash_de_free(struct au_nhash *delist)
29970 + au_nhash_do_free(delist, au_nhash_de_do_free);
29973 +/* ---------------------------------------------------------------------- */
29975 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29979 + unsigned int u, n;
29980 + struct hlist_head *head;
29981 + struct au_vdir_wh *pos;
29984 + n = whlist->nh_num;
29985 + head = whlist->nh_head;
29986 + for (u = 0; u < n; u++, head++)
29987 + hlist_for_each_entry(pos, head, wh_hash)
29988 + if (pos->wh_bindex == btgt && ++num > limit)
29993 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29994 + unsigned char *name,
29995 + unsigned int len)
29998 + /* const unsigned int magic_bit = 12; */
30000 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
30007 + /* v = hash_long(v, magic_bit); */
30008 + v %= nhash->nh_num;
30009 + return nhash->nh_head + v;
30012 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
30015 + return str->len == nlen && !memcmp(str->name, name, nlen);
30018 +/* returns found or not */
30019 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
30021 + struct hlist_head *head;
30022 + struct au_vdir_wh *pos;
30023 + struct au_vdir_destr *str;
30025 + head = au_name_hash(whlist, name, nlen);
30026 + hlist_for_each_entry(pos, head, wh_hash) {
30027 + str = &pos->wh_str;
30028 + AuDbg("%.*s\n", str->len, str->name);
30029 + if (au_nhash_test_name(str, name, nlen))
30035 +/* returns found(true) or not */
30036 +static int test_known(struct au_nhash *delist, char *name, int nlen)
30038 + struct hlist_head *head;
30039 + struct au_vdir_dehstr *pos;
30040 + struct au_vdir_destr *str;
30042 + head = au_name_hash(delist, name, nlen);
30043 + hlist_for_each_entry(pos, head, hash) {
30045 + AuDbg("%.*s\n", str->len, str->name);
30046 + if (au_nhash_test_name(str, name, nlen))
30052 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
30053 + unsigned char d_type)
30055 +#ifdef CONFIG_AUFS_SHWH
30056 + wh->wh_ino = ino;
30057 + wh->wh_type = d_type;
30061 +/* ---------------------------------------------------------------------- */
30063 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
30064 + unsigned int d_type, aufs_bindex_t bindex,
30065 + unsigned char shwh)
30068 + struct au_vdir_destr *str;
30069 + struct au_vdir_wh *wh;
30071 + AuDbg("%.*s\n", nlen, name);
30072 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
30075 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
30076 + if (unlikely(!wh))
30080 + wh->wh_bindex = bindex;
30082 + au_shwh_init_wh(wh, ino, d_type);
30083 + str = &wh->wh_str;
30085 + memcpy(str->name, name, nlen);
30086 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
30093 +static int append_deblk(struct au_vdir *vdir)
30096 + unsigned long ul;
30097 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
30098 + union au_vdir_deblk_p p, deblk_end;
30099 + unsigned char **o;
30102 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
30103 + GFP_NOFS, /*may_shrink*/0);
30104 + if (unlikely(!o))
30107 + vdir->vd_deblk = o;
30108 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
30110 + ul = vdir->vd_nblk++;
30111 + vdir->vd_deblk[ul] = p.deblk;
30112 + vdir->vd_last.ul = ul;
30113 + vdir->vd_last.p.deblk = p.deblk;
30114 + deblk_end.deblk = p.deblk + deblk_sz;
30115 + err = set_deblk_end(&p, &deblk_end);
30122 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
30123 + unsigned int d_type, struct au_nhash *delist)
30127 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
30128 + union au_vdir_deblk_p p, *room, deblk_end;
30129 + struct au_vdir_dehstr *dehstr;
30131 + p.deblk = last_deblk(vdir);
30132 + deblk_end.deblk = p.deblk + deblk_sz;
30133 + room = &vdir->vd_last.p;
30134 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
30135 + || !is_deblk_end(room, &deblk_end));
30137 + sz = calc_size(nlen);
30138 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
30139 + err = append_deblk(vdir);
30140 + if (unlikely(err))
30143 + p.deblk = last_deblk(vdir);
30144 + deblk_end.deblk = p.deblk + deblk_sz;
30146 + AuDebugOn(room->deblk != p.deblk);
30150 + dehstr = au_cache_alloc_vdir_dehstr();
30151 + if (unlikely(!dehstr))
30154 + dehstr->str = &room->de->de_str;
30155 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
30156 + room->de->de_ino = ino;
30157 + room->de->de_type = d_type;
30158 + room->de->de_str.len = nlen;
30159 + memcpy(room->de->de_str.name, name, nlen);
30162 + room->deblk += sz;
30163 + if (unlikely(set_deblk_end(room, &deblk_end)))
30164 + err = append_deblk(vdir);
30171 +/* ---------------------------------------------------------------------- */
30173 +void au_vdir_free(struct au_vdir *vdir, int atonce)
30175 + unsigned char **deblk;
30177 + deblk = vdir->vd_deblk;
30179 + while (vdir->vd_nblk--)
30180 + au_delayed_kfree(*deblk++);
30181 + au_delayed_kfree(vdir->vd_deblk);
30182 + au_cache_dfree_vdir(vdir);
30184 + /* not delayed */
30185 + while (vdir->vd_nblk--)
30187 + kfree(vdir->vd_deblk);
30188 + au_cache_free_vdir(vdir);
30192 +static struct au_vdir *alloc_vdir(struct file *file)
30194 + struct au_vdir *vdir;
30195 + struct super_block *sb;
30198 + sb = file->f_path.dentry->d_sb;
30199 + SiMustAnyLock(sb);
30202 + vdir = au_cache_alloc_vdir();
30203 + if (unlikely(!vdir))
30206 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
30207 + if (unlikely(!vdir->vd_deblk))
30210 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
30211 + if (!vdir->vd_deblk_sz) {
30212 + /* estimate the appropriate size for deblk */
30213 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
30214 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
30216 + vdir->vd_nblk = 0;
30217 + vdir->vd_version = 0;
30218 + vdir->vd_jiffy = 0;
30219 + err = append_deblk(vdir);
30221 + return vdir; /* success */
30223 + au_delayed_kfree(vdir->vd_deblk);
30226 + au_cache_dfree_vdir(vdir);
30228 + vdir = ERR_PTR(err);
30232 +static int reinit_vdir(struct au_vdir *vdir)
30235 + union au_vdir_deblk_p p, deblk_end;
30237 + while (vdir->vd_nblk > 1) {
30238 + au_delayed_kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30239 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30242 + p.deblk = vdir->vd_deblk[0];
30243 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30244 + err = set_deblk_end(&p, &deblk_end);
30245 + /* keep vd_dblk_sz */
30246 + vdir->vd_last.ul = 0;
30247 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30248 + vdir->vd_version = 0;
30249 + vdir->vd_jiffy = 0;
30254 +/* ---------------------------------------------------------------------- */
30256 +#define AuFillVdir_CALLED 1
30257 +#define AuFillVdir_WHABLE (1 << 1)
30258 +#define AuFillVdir_SHWH (1 << 2)
30259 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30260 +#define au_fset_fillvdir(flags, name) \
30261 + do { (flags) |= AuFillVdir_##name; } while (0)
30262 +#define au_fclr_fillvdir(flags, name) \
30263 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30265 +#ifndef CONFIG_AUFS_SHWH
30266 +#undef AuFillVdir_SHWH
30267 +#define AuFillVdir_SHWH 0
30270 +struct fillvdir_arg {
30271 + struct dir_context ctx;
30272 + struct file *file;
30273 + struct au_vdir *vdir;
30274 + struct au_nhash delist;
30275 + struct au_nhash whlist;
30276 + aufs_bindex_t bindex;
30277 + unsigned int flags;
30281 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30282 + loff_t offset __maybe_unused, u64 h_ino,
30283 + unsigned int d_type)
30285 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30286 + char *name = (void *)__name;
30287 + struct super_block *sb;
30289 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30292 + sb = arg->file->f_path.dentry->d_sb;
30293 + au_fset_fillvdir(arg->flags, CALLED);
30295 + if (nlen <= AUFS_WH_PFX_LEN
30296 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30297 + if (test_known(&arg->delist, name, nlen)
30298 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30299 + goto out; /* already exists or whiteouted */
30301 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30303 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30304 + d_type = DT_UNKNOWN;
30305 + arg->err = append_de(arg->vdir, name, nlen, ino,
30306 + d_type, &arg->delist);
30308 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30309 + name += AUFS_WH_PFX_LEN;
30310 + nlen -= AUFS_WH_PFX_LEN;
30311 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30312 + goto out; /* already whiteouted */
30315 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30318 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30319 + d_type = DT_UNKNOWN;
30320 + arg->err = au_nhash_append_wh
30321 + (&arg->whlist, name, nlen, ino, d_type,
30322 + arg->bindex, shwh);
30328 + arg->vdir->vd_jiffy = jiffies;
30330 + AuTraceErr(arg->err);
30334 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30335 + struct au_nhash *whlist, struct au_nhash *delist)
30337 +#ifdef CONFIG_AUFS_SHWH
30339 + unsigned int nh, u;
30340 + struct hlist_head *head;
30341 + struct au_vdir_wh *pos;
30342 + struct hlist_node *n;
30344 + struct au_vdir_destr *destr;
30346 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30349 + o = p = (void *)__get_free_page(GFP_NOFS);
30350 + if (unlikely(!p))
30354 + nh = whlist->nh_num;
30355 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30356 + p += AUFS_WH_PFX_LEN;
30357 + for (u = 0; u < nh; u++) {
30358 + head = whlist->nh_head + u;
30359 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30360 + destr = &pos->wh_str;
30361 + memcpy(p, destr->name, destr->len);
30362 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30363 + pos->wh_ino, pos->wh_type, delist);
30364 + if (unlikely(err))
30369 + au_delayed_free_page((unsigned long)o);
30379 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30382 + unsigned int rdhash;
30384 + aufs_bindex_t bbot, bindex, btop;
30385 + unsigned char shwh;
30386 + struct file *hf, *file;
30387 + struct super_block *sb;
30389 + file = arg->file;
30390 + sb = file->f_path.dentry->d_sb;
30391 + SiMustAnyLock(sb);
30393 + rdhash = au_sbi(sb)->si_rdhash;
30395 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30396 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30397 + if (unlikely(err))
30399 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30400 + if (unlikely(err))
30406 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30408 + au_fset_fillvdir(arg->flags, SHWH);
30410 + btop = au_fbtop(file);
30411 + bbot = au_fbbot_dir(file);
30412 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30413 + hf = au_hf_dir(file, bindex);
30417 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30419 + if (unlikely(offset))
30422 + arg->bindex = bindex;
30423 + au_fclr_fillvdir(arg->flags, WHABLE);
30425 + || (bindex != bbot
30426 + && au_br_whable(au_sbr_perm(sb, bindex))))
30427 + au_fset_fillvdir(arg->flags, WHABLE);
30430 + au_fclr_fillvdir(arg->flags, CALLED);
30432 + err = vfsub_iterate_dir(hf, &arg->ctx);
30435 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30438 + * dir_relax() may be good for concurrency, but aufs should not
30439 + * use it since it will cause a lockdep problem.
30443 + if (!err && shwh)
30444 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30446 + au_nhash_wh_free(&arg->whlist);
30449 + au_nhash_de_free(&arg->delist);
30454 +static int read_vdir(struct file *file, int may_read)
30457 + unsigned long expire;
30458 + unsigned char do_read;
30459 + struct fillvdir_arg arg = {
30461 + .actor = fillvdir
30464 + struct inode *inode;
30465 + struct au_vdir *vdir, *allocated;
30468 + inode = file_inode(file);
30469 + IMustLock(inode);
30470 + IiMustWriteLock(inode);
30471 + SiMustAnyLock(inode->i_sb);
30473 + allocated = NULL;
30475 + expire = au_sbi(inode->i_sb)->si_rdcache;
30476 + vdir = au_ivdir(inode);
30479 + vdir = alloc_vdir(file);
30480 + err = PTR_ERR(vdir);
30481 + if (IS_ERR(vdir))
30484 + allocated = vdir;
30485 + } else if (may_read
30486 + && (inode->i_version != vdir->vd_version
30487 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30489 + err = reinit_vdir(vdir);
30490 + if (unlikely(err))
30495 + return 0; /* success */
30499 + err = au_do_read_vdir(&arg);
30501 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30502 + vdir->vd_version = inode->i_version;
30503 + vdir->vd_last.ul = 0;
30504 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30506 + au_set_ivdir(inode, allocated);
30507 + } else if (allocated)
30508 + au_vdir_free(allocated, /*atonce*/0);
30514 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30517 + unsigned long ul, n;
30518 + const unsigned int deblk_sz = src->vd_deblk_sz;
30520 + AuDebugOn(tgt->vd_nblk != 1);
30523 + if (tgt->vd_nblk < src->vd_nblk) {
30524 + unsigned char **p;
30526 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30527 + GFP_NOFS, /*may_shrink*/0);
30528 + if (unlikely(!p))
30530 + tgt->vd_deblk = p;
30533 + if (tgt->vd_deblk_sz != deblk_sz) {
30534 + unsigned char *p;
30536 + tgt->vd_deblk_sz = deblk_sz;
30537 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30538 + /*may_shrink*/1);
30539 + if (unlikely(!p))
30541 + tgt->vd_deblk[0] = p;
30543 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30544 + tgt->vd_version = src->vd_version;
30545 + tgt->vd_jiffy = src->vd_jiffy;
30547 + n = src->vd_nblk;
30548 + for (ul = 1; ul < n; ul++) {
30549 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30551 + if (unlikely(!tgt->vd_deblk[ul]))
30555 + tgt->vd_nblk = n;
30556 + tgt->vd_last.ul = tgt->vd_last.ul;
30557 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30558 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30559 + - src->vd_deblk[src->vd_last.ul];
30561 + return 0; /* success */
30564 + rerr = reinit_vdir(tgt);
30569 +int au_vdir_init(struct file *file)
30572 + struct inode *inode;
30573 + struct au_vdir *vdir_cache, *allocated;
30575 + /* test file->f_pos here instead of ctx->pos */
30576 + err = read_vdir(file, !file->f_pos);
30577 + if (unlikely(err))
30580 + allocated = NULL;
30581 + vdir_cache = au_fvdir_cache(file);
30582 + if (!vdir_cache) {
30583 + vdir_cache = alloc_vdir(file);
30584 + err = PTR_ERR(vdir_cache);
30585 + if (IS_ERR(vdir_cache))
30587 + allocated = vdir_cache;
30588 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30589 + /* test file->f_pos here instead of ctx->pos */
30590 + err = reinit_vdir(vdir_cache);
30591 + if (unlikely(err))
30594 + return 0; /* success */
30596 + inode = file_inode(file);
30597 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30599 + file->f_version = inode->i_version;
30601 + au_set_fvdir_cache(file, allocated);
30602 + } else if (allocated)
30603 + au_vdir_free(allocated, /*atonce*/0);
30609 +static loff_t calc_offset(struct au_vdir *vdir)
30612 + union au_vdir_deblk_p p;
30614 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30615 + offset = vdir->vd_last.p.deblk - p.deblk;
30616 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30620 +/* returns true or false */
30621 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30624 + unsigned int deblk_sz;
30625 + unsigned long ul, n;
30627 + union au_vdir_deblk_p p, deblk_end;
30628 + struct au_vdir *vdir_cache;
30631 + vdir_cache = au_fvdir_cache(file);
30632 + offset = calc_offset(vdir_cache);
30633 + AuDbg("offset %lld\n", offset);
30634 + if (ctx->pos == offset)
30637 + vdir_cache->vd_last.ul = 0;
30638 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30643 + deblk_sz = vdir_cache->vd_deblk_sz;
30644 + ul = div64_u64(ctx->pos, deblk_sz);
30645 + AuDbg("ul %lu\n", ul);
30646 + if (ul >= vdir_cache->vd_nblk)
30649 + n = vdir_cache->vd_nblk;
30650 + for (; ul < n; ul++) {
30651 + p.deblk = vdir_cache->vd_deblk[ul];
30652 + deblk_end.deblk = p.deblk + deblk_sz;
30654 + offset *= deblk_sz;
30655 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30658 + l = calc_size(p.de->de_str.len);
30662 + if (!is_deblk_end(&p, &deblk_end)) {
30664 + vdir_cache->vd_last.ul = ul;
30665 + vdir_cache->vd_last.p = p;
30672 + AuTraceErr(!valid);
30676 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30678 + unsigned int l, deblk_sz;
30679 + union au_vdir_deblk_p deblk_end;
30680 + struct au_vdir *vdir_cache;
30681 + struct au_vdir_de *de;
30683 + vdir_cache = au_fvdir_cache(file);
30684 + if (!seek_vdir(file, ctx))
30687 + deblk_sz = vdir_cache->vd_deblk_sz;
30689 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30690 + deblk_end.deblk += deblk_sz;
30691 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30692 + de = vdir_cache->vd_last.p.de;
30693 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30694 + de->de_str.len, de->de_str.name, ctx->pos,
30695 + (unsigned long)de->de_ino, de->de_type);
30696 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30697 + de->de_str.len, de->de_ino,
30699 + /* todo: ignore the error caused by udba? */
30700 + /* return err; */
30704 + l = calc_size(de->de_str.len);
30705 + vdir_cache->vd_last.p.deblk += l;
30708 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30709 + vdir_cache->vd_last.ul++;
30710 + vdir_cache->vd_last.p.deblk
30711 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30712 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30721 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30722 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30723 +++ linux/fs/aufs/vfsub.c 2017-05-06 22:16:52.781553511 +0200
30726 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30728 + * This program, aufs is free software; you can redistribute it and/or modify
30729 + * it under the terms of the GNU General Public License as published by
30730 + * the Free Software Foundation; either version 2 of the License, or
30731 + * (at your option) any later version.
30733 + * This program is distributed in the hope that it will be useful,
30734 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30735 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30736 + * GNU General Public License for more details.
30738 + * You should have received a copy of the GNU General Public License
30739 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30743 + * sub-routines for VFS
30746 +#include <linux/namei.h>
30747 +#include <linux/nsproxy.h>
30748 +#include <linux/security.h>
30749 +#include <linux/splice.h>
30750 +#ifdef CONFIG_AUFS_BR_FUSE
30751 +#include "../fs/mount.h"
30755 +#ifdef CONFIG_AUFS_BR_FUSE
30756 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30758 + struct nsproxy *ns;
30760 + if (!au_test_fuse(h_sb) || !au_userns)
30763 + ns = current->nsproxy;
30764 + /* no {get,put}_nsproxy(ns) */
30765 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30769 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
30774 + down_read(&h_sb->s_umount);
30775 + err = __sync_filesystem(h_sb, wait);
30776 + up_read(&h_sb->s_umount);
30782 +/* ---------------------------------------------------------------------- */
30784 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30788 + struct super_block *h_sb;
30790 + /* for remote fs, leave work for its getattr or d_revalidate */
30791 + /* for bad i_attr fs, handle them in aufs_getattr() */
30792 + /* still some fs may acquire i_mutex. we need to skip them */
30796 + h_sb = h_path->dentry->d_sb;
30797 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30799 + err = vfsub_getattr(h_path, &st);
30804 +/* ---------------------------------------------------------------------- */
30806 +struct file *vfsub_dentry_open(struct path *path, int flags)
30808 + struct file *file;
30810 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30812 + if (!IS_ERR_OR_NULL(file)
30813 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30814 + i_readcount_inc(d_inode(path->dentry));
30819 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30821 + struct file *file;
30824 + file = filp_open(path,
30825 + oflags /* | __FMODE_NONOTIFY */,
30828 + if (IS_ERR(file))
30830 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30837 + * Ideally this function should call VFS:do_last() in order to keep all its
30838 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30839 + * structure such as nameidata. This is a second (or third) best approach.
30840 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30842 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30843 + struct vfsub_aopen_args *args, struct au_branch *br)
30846 + struct file *file = args->file;
30847 + /* copied from linux/fs/namei.c:atomic_open() */
30848 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30851 + AuDebugOn(!dir->i_op->atomic_open);
30853 + err = au_br_test_oflag(args->open_flag, br);
30854 + if (unlikely(err))
30857 + args->file->f_path.dentry = DENTRY_NOT_SET;
30858 + args->file->f_path.mnt = au_br_mnt(br);
30859 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30860 + args->create_mode, args->opened);
30862 + /* some filesystems don't set FILE_CREATED while succeeded? */
30863 + if (*args->opened & FILE_CREATED)
30864 + fsnotify_create(dir, dentry);
30870 + /* todo: call VFS:may_open() here */
30871 + err = open_check_o_direct(file);
30872 + /* todo: ima_file_check() too? */
30873 + if (!err && (args->open_flag & __FMODE_EXEC))
30874 + err = deny_write_access(file);
30875 + if (unlikely(err))
30876 + /* note that the file is created and still opened */
30881 + fsnotify_open(file);
30887 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30891 + err = kern_path(name, flags, path);
30892 + if (!err && d_is_positive(path->dentry))
30893 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30897 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30898 + struct dentry *parent, int len)
30900 + struct path path = {
30904 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30905 + if (IS_ERR(path.dentry))
30907 + if (d_is_positive(path.dentry))
30908 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30911 + AuTraceErrPtr(path.dentry);
30912 + return path.dentry;
30915 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30918 + struct path path = {
30922 + /* VFS checks it too, but by WARN_ON_ONCE() */
30923 + IMustLock(d_inode(parent));
30925 + path.dentry = lookup_one_len(name, parent, len);
30926 + if (IS_ERR(path.dentry))
30928 + if (d_is_positive(path.dentry))
30929 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30932 + AuTraceErrPtr(path.dentry);
30933 + return path.dentry;
30936 +void vfsub_call_lkup_one(void *args)
30938 + struct vfsub_lkup_one_args *a = args;
30939 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30942 +/* ---------------------------------------------------------------------- */
30944 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30945 + struct dentry *d2, struct au_hinode *hdir2)
30947 + struct dentry *d;
30950 + d = lock_rename(d1, d2);
30952 + au_hn_suspend(hdir1);
30953 + if (hdir1 != hdir2)
30954 + au_hn_suspend(hdir2);
30959 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30960 + struct dentry *d2, struct au_hinode *hdir2)
30962 + au_hn_resume(hdir1);
30963 + if (hdir1 != hdir2)
30964 + au_hn_resume(hdir2);
30966 + unlock_rename(d1, d2);
30970 +/* ---------------------------------------------------------------------- */
30972 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30975 + struct dentry *d;
30979 + d = path->dentry;
30980 + path->dentry = d->d_parent;
30981 + err = security_path_mknod(path, d, mode, 0);
30982 + path->dentry = d;
30983 + if (unlikely(err))
30987 + err = vfs_create(dir, path->dentry, mode, want_excl);
30990 + struct path tmp = *path;
30993 + vfsub_update_h_iattr(&tmp, &did);
30995 + tmp.dentry = path->dentry->d_parent;
30996 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31005 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
31008 + struct dentry *d;
31012 + d = path->dentry;
31013 + path->dentry = d->d_parent;
31014 + err = security_path_symlink(path, d, symname);
31015 + path->dentry = d;
31016 + if (unlikely(err))
31020 + err = vfs_symlink(dir, path->dentry, symname);
31023 + struct path tmp = *path;
31026 + vfsub_update_h_iattr(&tmp, &did);
31028 + tmp.dentry = path->dentry->d_parent;
31029 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31038 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
31041 + struct dentry *d;
31045 + d = path->dentry;
31046 + path->dentry = d->d_parent;
31047 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
31048 + path->dentry = d;
31049 + if (unlikely(err))
31053 + err = vfs_mknod(dir, path->dentry, mode, dev);
31056 + struct path tmp = *path;
31059 + vfsub_update_h_iattr(&tmp, &did);
31061 + tmp.dentry = path->dentry->d_parent;
31062 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31071 +static int au_test_nlink(struct inode *inode)
31073 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
31075 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
31076 + || inode->i_nlink < link_max)
31081 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
31082 + struct inode **delegated_inode)
31085 + struct dentry *d;
31089 + err = au_test_nlink(d_inode(src_dentry));
31090 + if (unlikely(err))
31093 + /* we don't call may_linkat() */
31094 + d = path->dentry;
31095 + path->dentry = d->d_parent;
31096 + err = security_path_link(src_dentry, path, d);
31097 + path->dentry = d;
31098 + if (unlikely(err))
31102 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
31105 + struct path tmp = *path;
31108 + /* fuse has different memory inode for the same inumber */
31109 + vfsub_update_h_iattr(&tmp, &did);
31111 + tmp.dentry = path->dentry->d_parent;
31112 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31113 + tmp.dentry = src_dentry;
31114 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31123 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
31124 + struct inode *dir, struct path *path,
31125 + struct inode **delegated_inode, unsigned int flags)
31128 + struct path tmp = {
31131 + struct dentry *d;
31134 + IMustLock(src_dir);
31136 + d = path->dentry;
31137 + path->dentry = d->d_parent;
31138 + tmp.dentry = src_dentry->d_parent;
31139 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
31140 + path->dentry = d;
31141 + if (unlikely(err))
31145 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
31146 + delegated_inode, flags);
31151 + tmp.dentry = d->d_parent;
31152 + vfsub_update_h_iattr(&tmp, &did);
31154 + tmp.dentry = src_dentry;
31155 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31156 + tmp.dentry = src_dentry->d_parent;
31157 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31166 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
31169 + struct dentry *d;
31173 + d = path->dentry;
31174 + path->dentry = d->d_parent;
31175 + err = security_path_mkdir(path, d, mode);
31176 + path->dentry = d;
31177 + if (unlikely(err))
31181 + err = vfs_mkdir(dir, path->dentry, mode);
31184 + struct path tmp = *path;
31187 + vfsub_update_h_iattr(&tmp, &did);
31189 + tmp.dentry = path->dentry->d_parent;
31190 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31199 +int vfsub_rmdir(struct inode *dir, struct path *path)
31202 + struct dentry *d;
31206 + d = path->dentry;
31207 + path->dentry = d->d_parent;
31208 + err = security_path_rmdir(path, d);
31209 + path->dentry = d;
31210 + if (unlikely(err))
31214 + err = vfs_rmdir(dir, path->dentry);
31217 + struct path tmp = {
31218 + .dentry = path->dentry->d_parent,
31222 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31229 +/* ---------------------------------------------------------------------- */
31231 +/* todo: support mmap_sem? */
31232 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31238 + err = vfs_read(file, ubuf, count, ppos);
31241 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31245 +/* todo: kernel_read()? */
31246 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31250 + mm_segment_t oldfs;
31257 + oldfs = get_fs();
31258 + set_fs(KERNEL_DS);
31259 + err = vfsub_read_u(file, buf.u, count, ppos);
31264 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31270 + err = vfs_write(file, ubuf, count, ppos);
31273 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31277 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31280 + mm_segment_t oldfs;
31283 + const char __user *u;
31287 + oldfs = get_fs();
31288 + set_fs(KERNEL_DS);
31289 + err = vfsub_write_u(file, buf.u, count, ppos);
31294 +int vfsub_flush(struct file *file, fl_owner_t id)
31299 + if (file->f_op->flush) {
31300 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31301 + err = file->f_op->flush(file, id);
31304 + err = file->f_op->flush(file, id);
31308 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31314 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31318 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31321 + err = iterate_dir(file, ctx);
31324 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31328 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31329 + struct pipe_inode_info *pipe, size_t len,
31330 + unsigned int flags)
31335 + err = do_splice_to(in, ppos, pipe, len, flags);
31337 + file_accessed(in);
31339 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31343 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31344 + loff_t *ppos, size_t len, unsigned int flags)
31349 + err = do_splice_from(pipe, out, ppos, len, flags);
31352 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31356 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31360 + /* file can be NULL */
31362 + err = vfs_fsync(file, datasync);
31366 + AuDebugOn(!file);
31367 + path = &file->f_path;
31369 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31374 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31375 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31376 + struct file *h_file)
31379 + struct inode *h_inode;
31380 + struct super_block *h_sb;
31383 + err = vfsub_truncate(h_path, length);
31387 + h_inode = d_inode(h_path->dentry);
31388 + h_sb = h_inode->i_sb;
31390 + sb_start_write(h_sb);
31392 + err = locks_verify_truncate(h_inode, h_file, length);
31394 + err = security_path_truncate(h_path);
31397 + err = do_truncate(h_path->dentry, length, attr, h_file);
31401 + sb_end_write(h_sb);
31408 +/* ---------------------------------------------------------------------- */
31410 +struct au_vfsub_mkdir_args {
31412 + struct inode *dir;
31413 + struct path *path;
31417 +static void au_call_vfsub_mkdir(void *args)
31419 + struct au_vfsub_mkdir_args *a = args;
31420 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31423 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31425 + int err, do_sio, wkq_err;
31427 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31430 + err = vfsub_mkdir(dir, path, mode);
31433 + struct au_vfsub_mkdir_args args = {
31439 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31440 + if (unlikely(wkq_err))
31447 +struct au_vfsub_rmdir_args {
31449 + struct inode *dir;
31450 + struct path *path;
31453 +static void au_call_vfsub_rmdir(void *args)
31455 + struct au_vfsub_rmdir_args *a = args;
31456 + *a->errp = vfsub_rmdir(a->dir, a->path);
31459 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31461 + int err, do_sio, wkq_err;
31463 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31466 + err = vfsub_rmdir(dir, path);
31469 + struct au_vfsub_rmdir_args args = {
31474 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31475 + if (unlikely(wkq_err))
31482 +/* ---------------------------------------------------------------------- */
31484 +struct notify_change_args {
31486 + struct path *path;
31487 + struct iattr *ia;
31488 + struct inode **delegated_inode;
31491 +static void call_notify_change(void *args)
31493 + struct notify_change_args *a = args;
31494 + struct inode *h_inode;
31496 + h_inode = d_inode(a->path->dentry);
31497 + IMustLock(h_inode);
31499 + *a->errp = -EPERM;
31500 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31502 + *a->errp = notify_change(a->path->dentry, a->ia,
31503 + a->delegated_inode);
31506 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31508 + AuTraceErr(*a->errp);
31511 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31512 + struct inode **delegated_inode)
31515 + struct notify_change_args args = {
31519 + .delegated_inode = delegated_inode
31522 + call_notify_change(&args);
31527 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31528 + struct inode **delegated_inode)
31530 + int err, wkq_err;
31531 + struct notify_change_args args = {
31535 + .delegated_inode = delegated_inode
31538 + wkq_err = au_wkq_wait(call_notify_change, &args);
31539 + if (unlikely(wkq_err))
31545 +/* ---------------------------------------------------------------------- */
31547 +struct unlink_args {
31549 + struct inode *dir;
31550 + struct path *path;
31551 + struct inode **delegated_inode;
31554 +static void call_unlink(void *args)
31556 + struct unlink_args *a = args;
31557 + struct dentry *d = a->path->dentry;
31558 + struct inode *h_inode;
31559 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31560 + && au_dcount(d) == 1);
31562 + IMustLock(a->dir);
31564 + a->path->dentry = d->d_parent;
31565 + *a->errp = security_path_unlink(a->path, d);
31566 + a->path->dentry = d;
31567 + if (unlikely(*a->errp))
31570 + if (!stop_sillyrename)
31573 + if (d_is_positive(d)) {
31574 + h_inode = d_inode(d);
31579 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31582 + struct path tmp = {
31583 + .dentry = d->d_parent,
31584 + .mnt = a->path->mnt
31586 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31589 + if (!stop_sillyrename)
31594 + AuTraceErr(*a->errp);
31598 + * @dir: must be locked.
31599 + * @dentry: target dentry.
31601 +int vfsub_unlink(struct inode *dir, struct path *path,
31602 + struct inode **delegated_inode, int force)
31605 + struct unlink_args args = {
31609 + .delegated_inode = delegated_inode
31613 + call_unlink(&args);
31617 + wkq_err = au_wkq_wait(call_unlink, &args);
31618 + if (unlikely(wkq_err))
31624 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31625 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31626 +++ linux/fs/aufs/vfsub.h 2017-05-06 22:16:52.781553511 +0200
31629 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31631 + * This program, aufs is free software; you can redistribute it and/or modify
31632 + * it under the terms of the GNU General Public License as published by
31633 + * the Free Software Foundation; either version 2 of the License, or
31634 + * (at your option) any later version.
31636 + * This program is distributed in the hope that it will be useful,
31637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31639 + * GNU General Public License for more details.
31641 + * You should have received a copy of the GNU General Public License
31642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31646 + * sub-routines for VFS
31649 +#ifndef __AUFS_VFSUB_H__
31650 +#define __AUFS_VFSUB_H__
31654 +#include <linux/fs.h>
31655 +#include <linux/mount.h>
31656 +#include <linux/posix_acl.h>
31657 +#include <linux/xattr.h>
31658 +#include "debug.h"
31660 +/* copied from linux/fs/internal.h */
31661 +/* todo: BAD approach!! */
31662 +extern void __mnt_drop_write(struct vfsmount *);
31663 +extern int open_check_o_direct(struct file *f);
31665 +/* ---------------------------------------------------------------------- */
31667 +/* lock subclass for lower inode */
31668 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31669 +/* reduce? gave up. */
31671 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31672 + AuLsc_I_PARENT, /* lower inode, parent first */
31673 + AuLsc_I_PARENT2, /* copyup dirs */
31674 + AuLsc_I_PARENT3, /* copyup wh */
31680 +/* to debug easier, do not make them inlined functions */
31681 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31682 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31684 +/* ---------------------------------------------------------------------- */
31686 +static inline void vfsub_drop_nlink(struct inode *inode)
31688 + AuDebugOn(!inode->i_nlink);
31689 + drop_nlink(inode);
31692 +static inline void vfsub_dead_dir(struct inode *inode)
31694 + AuDebugOn(!S_ISDIR(inode->i_mode));
31695 + inode->i_flags |= S_DEAD;
31696 + clear_nlink(inode);
31699 +static inline int vfsub_native_ro(struct inode *inode)
31701 + return (inode->i_sb->s_flags & MS_RDONLY)
31702 + || IS_RDONLY(inode)
31703 + /* || IS_APPEND(inode) */
31704 + || IS_IMMUTABLE(inode);
31707 +#ifdef CONFIG_AUFS_BR_FUSE
31708 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31710 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31713 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
31715 +/* ---------------------------------------------------------------------- */
31717 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31718 +struct file *vfsub_dentry_open(struct path *path, int flags);
31719 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31720 +struct vfsub_aopen_args {
31721 + struct file *file;
31722 + unsigned int open_flag;
31723 + umode_t create_mode;
31727 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31728 + struct vfsub_aopen_args *args, struct au_branch *br);
31729 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31731 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31732 + struct dentry *parent, int len);
31733 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31736 +struct vfsub_lkup_one_args {
31737 + struct dentry **errp;
31738 + struct qstr *name;
31739 + struct dentry *parent;
31742 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31743 + struct dentry *parent)
31745 + return vfsub_lookup_one_len(name->name, parent, name->len);
31748 +void vfsub_call_lkup_one(void *args);
31750 +/* ---------------------------------------------------------------------- */
31752 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31757 + err = mnt_want_write(mnt);
31762 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31765 + mnt_drop_write(mnt);
31769 +#if 0 /* reserved */
31770 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31773 + mnt_drop_write_file(file);
31778 +/* ---------------------------------------------------------------------- */
31781 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31782 + struct dentry *d2, struct au_hinode *hdir2);
31783 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31784 + struct dentry *d2, struct au_hinode *hdir2);
31786 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31788 +int vfsub_symlink(struct inode *dir, struct path *path,
31789 + const char *symname);
31790 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31791 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31792 + struct path *path, struct inode **delegated_inode);
31793 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31794 + struct inode *hdir, struct path *path,
31795 + struct inode **delegated_inode, unsigned int flags);
31796 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31797 +int vfsub_rmdir(struct inode *dir, struct path *path);
31799 +/* ---------------------------------------------------------------------- */
31801 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31803 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31805 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31807 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31809 +int vfsub_flush(struct file *file, fl_owner_t id);
31810 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31812 +static inline loff_t vfsub_f_size_read(struct file *file)
31814 + return i_size_read(file_inode(file));
31817 +static inline unsigned int vfsub_file_flags(struct file *file)
31819 + unsigned int flags;
31821 + spin_lock(&file->f_lock);
31822 + flags = file->f_flags;
31823 + spin_unlock(&file->f_lock);
31828 +static inline int vfsub_file_execed(struct file *file)
31830 + /* todo: direct access f_flags */
31831 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31834 +#if 0 /* reserved */
31835 +static inline void vfsub_file_accessed(struct file *h_file)
31837 + file_accessed(h_file);
31838 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31842 +#if 0 /* reserved */
31843 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31844 + struct dentry *h_dentry)
31846 + struct path h_path = {
31847 + .dentry = h_dentry,
31850 + touch_atime(&h_path);
31851 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31855 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31858 + return update_time(h_inode, ts, flags);
31859 + /* no vfsub_update_h_iattr() since we don't have struct path */
31862 +#ifdef CONFIG_FS_POSIX_ACL
31863 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31867 + err = posix_acl_chmod(h_inode, h_mode);
31868 + if (err == -EOPNOTSUPP)
31873 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31876 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31877 + struct pipe_inode_info *pipe, size_t len,
31878 + unsigned int flags);
31879 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31880 + loff_t *ppos, size_t len, unsigned int flags);
31882 +static inline long vfsub_truncate(struct path *path, loff_t length)
31887 + err = vfs_truncate(path, length);
31892 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31893 + struct file *h_file);
31894 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31897 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
31900 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
31906 + err = vfs_clone_file_range(src, 0, dst, 0, len);
31912 +/* copy_file_range(2) is a systemcall */
31913 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
31914 + struct file *dst, loff_t dst_pos,
31915 + size_t len, unsigned int flags)
31920 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
31926 +/* ---------------------------------------------------------------------- */
31928 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31933 + err = vfs_llseek(file, offset, origin);
31938 +/* ---------------------------------------------------------------------- */
31940 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31941 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31942 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31943 + struct inode **delegated_inode);
31944 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31945 + struct inode **delegated_inode);
31946 +int vfsub_unlink(struct inode *dir, struct path *path,
31947 + struct inode **delegated_inode, int force);
31949 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
31951 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
31954 +/* ---------------------------------------------------------------------- */
31956 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31957 + const void *value, size_t size, int flags)
31962 + err = vfs_setxattr(dentry, name, value, size, flags);
31968 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31973 + err = vfs_removexattr(dentry, name);
31979 +#endif /* __KERNEL__ */
31980 +#endif /* __AUFS_VFSUB_H__ */
31981 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31982 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31983 +++ linux/fs/aufs/wbr_policy.c 2017-05-06 22:16:52.784886929 +0200
31986 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31988 + * This program, aufs is free software; you can redistribute it and/or modify
31989 + * it under the terms of the GNU General Public License as published by
31990 + * the Free Software Foundation; either version 2 of the License, or
31991 + * (at your option) any later version.
31993 + * This program is distributed in the hope that it will be useful,
31994 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31995 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31996 + * GNU General Public License for more details.
31998 + * You should have received a copy of the GNU General Public License
31999 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32003 + * policies for selecting one among multiple writable branches
32006 +#include <linux/statfs.h>
32009 +/* subset of cpup_attr() */
32010 +static noinline_for_stack
32011 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
32015 + struct inode *h_isrc;
32017 + h_isrc = d_inode(h_src);
32018 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
32019 + ia.ia_mode = h_isrc->i_mode;
32020 + ia.ia_uid = h_isrc->i_uid;
32021 + ia.ia_gid = h_isrc->i_gid;
32022 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
32023 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
32024 + /* no delegation since it is just created */
32025 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
32027 + /* is this nfs only? */
32028 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
32029 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
32030 + ia.ia_mode = h_isrc->i_mode;
32031 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
32037 +#define AuCpdown_PARENT_OPQ 1
32038 +#define AuCpdown_WHED (1 << 1)
32039 +#define AuCpdown_MADE_DIR (1 << 2)
32040 +#define AuCpdown_DIROPQ (1 << 3)
32041 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
32042 +#define au_fset_cpdown(flags, name) \
32043 + do { (flags) |= AuCpdown_##name; } while (0)
32044 +#define au_fclr_cpdown(flags, name) \
32045 + do { (flags) &= ~AuCpdown_##name; } while (0)
32047 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
32048 + unsigned int *flags)
32051 + struct dentry *opq_dentry;
32053 + opq_dentry = au_diropq_create(dentry, bdst);
32054 + err = PTR_ERR(opq_dentry);
32055 + if (IS_ERR(opq_dentry))
32057 + dput(opq_dentry);
32058 + au_fset_cpdown(*flags, DIROPQ);
32064 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
32065 + struct inode *dir, aufs_bindex_t bdst)
32068 + struct path h_path;
32069 + struct au_branch *br;
32071 + br = au_sbr(dentry->d_sb, bdst);
32072 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
32073 + err = PTR_ERR(h_path.dentry);
32074 + if (IS_ERR(h_path.dentry))
32078 + if (d_is_positive(h_path.dentry)) {
32079 + h_path.mnt = au_br_mnt(br);
32080 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
32083 + dput(h_path.dentry);
32089 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
32090 + struct au_pin *pin,
32091 + struct dentry *h_parent, void *arg)
32094 + aufs_bindex_t bopq, btop;
32095 + struct path h_path;
32096 + struct dentry *parent;
32097 + struct inode *h_dir, *h_inode, *inode, *dir;
32098 + unsigned int *flags = arg;
32100 + btop = au_dbtop(dentry);
32101 + /* dentry is di-locked */
32102 + parent = dget_parent(dentry);
32103 + dir = d_inode(parent);
32104 + h_dir = d_inode(h_parent);
32105 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
32106 + IMustLock(h_dir);
32108 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
32109 + if (unlikely(err < 0))
32111 + h_path.dentry = au_h_dptr(dentry, bdst);
32112 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
32113 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
32114 + S_IRWXU | S_IRUGO | S_IXUGO);
32115 + if (unlikely(err))
32117 + au_fset_cpdown(*flags, MADE_DIR);
32119 + bopq = au_dbdiropq(dentry);
32120 + au_fclr_cpdown(*flags, WHED);
32121 + au_fclr_cpdown(*flags, DIROPQ);
32122 + if (au_dbwh(dentry) == bdst)
32123 + au_fset_cpdown(*flags, WHED);
32124 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
32125 + au_fset_cpdown(*flags, PARENT_OPQ);
32126 + h_inode = d_inode(h_path.dentry);
32127 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
32128 + if (au_ftest_cpdown(*flags, WHED)) {
32129 + err = au_cpdown_dir_opq(dentry, bdst, flags);
32130 + if (unlikely(err)) {
32131 + inode_unlock(h_inode);
32136 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
32137 + inode_unlock(h_inode);
32138 + if (unlikely(err))
32141 + if (au_ftest_cpdown(*flags, WHED)) {
32142 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
32143 + if (unlikely(err))
32147 + inode = d_inode(dentry);
32148 + if (au_ibbot(inode) < bdst)
32149 + au_set_ibbot(inode, bdst);
32150 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
32151 + au_hi_flags(inode, /*isdir*/1));
32152 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
32153 + goto out; /* success */
32157 + if (au_ftest_cpdown(*flags, DIROPQ)) {
32158 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
32159 + rerr = au_diropq_remove(dentry, bdst);
32160 + inode_unlock(h_inode);
32161 + if (unlikely(rerr)) {
32162 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
32163 + dentry, bdst, rerr);
32169 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
32170 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
32171 + if (unlikely(rerr)) {
32172 + AuIOErr("failed removing %pd b%d (%d)\n",
32173 + dentry, bdst, rerr);
32178 + au_set_h_dptr(dentry, bdst, NULL);
32179 + if (au_dbbot(dentry) == bdst)
32180 + au_update_dbbot(dentry);
32186 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
32189 + unsigned int flags;
32192 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
32197 +/* ---------------------------------------------------------------------- */
32199 +/* policies for create */
32201 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
32203 + int err, i, j, ndentry;
32204 + aufs_bindex_t bopq;
32205 + struct au_dcsub_pages dpages;
32206 + struct au_dpage *dpage;
32207 + struct dentry **dentries, *parent, *d;
32209 + err = au_dpages_init(&dpages, GFP_NOFS);
32210 + if (unlikely(err))
32212 + parent = dget_parent(dentry);
32213 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
32214 + if (unlikely(err))
32218 + for (i = 0; i < dpages.ndpage; i++) {
32219 + dpage = dpages.dpages + i;
32220 + dentries = dpage->dentries;
32221 + ndentry = dpage->ndentry;
32222 + for (j = 0; j < ndentry; j++) {
32224 + di_read_lock_parent2(d, !AuLock_IR);
32225 + bopq = au_dbdiropq(d);
32226 + di_read_unlock(d, !AuLock_IR);
32227 + if (bopq >= 0 && bopq < err)
32234 + au_dpages_free(&dpages);
32239 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32241 + for (; bindex >= 0; bindex--)
32242 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32247 +/* top down parent */
32248 +static int au_wbr_create_tdp(struct dentry *dentry,
32249 + unsigned int flags __maybe_unused)
32252 + aufs_bindex_t btop, bindex;
32253 + struct super_block *sb;
32254 + struct dentry *parent, *h_parent;
32256 + sb = dentry->d_sb;
32257 + btop = au_dbtop(dentry);
32259 + if (!au_br_rdonly(au_sbr(sb, btop)))
32263 + parent = dget_parent(dentry);
32264 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32265 + h_parent = au_h_dptr(parent, bindex);
32266 + if (!h_parent || d_is_negative(h_parent))
32269 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32276 + /* bottom up here */
32277 + if (unlikely(err < 0)) {
32278 + err = au_wbr_bu(sb, btop - 1);
32280 + err = au_wbr_nonopq(dentry, err);
32284 + AuDbg("b%d\n", err);
32288 +/* ---------------------------------------------------------------------- */
32290 +/* an exception for the policy other than tdp */
32291 +static int au_wbr_create_exp(struct dentry *dentry)
32294 + aufs_bindex_t bwh, bdiropq;
32295 + struct dentry *parent;
32298 + bwh = au_dbwh(dentry);
32299 + parent = dget_parent(dentry);
32300 + bdiropq = au_dbdiropq(parent);
32302 + if (bdiropq >= 0)
32303 + err = min(bdiropq, bwh);
32306 + AuDbg("%d\n", err);
32307 + } else if (bdiropq >= 0) {
32309 + AuDbg("%d\n", err);
32314 + err = au_wbr_nonopq(dentry, err);
32316 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32319 + AuDbg("%d\n", err);
32323 +/* ---------------------------------------------------------------------- */
32326 +static int au_wbr_create_init_rr(struct super_block *sb)
32330 + err = au_wbr_bu(sb, au_sbbot(sb));
32331 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32334 + AuDbg("b%d\n", err);
32338 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32342 + aufs_bindex_t bindex, bbot;
32343 + struct super_block *sb;
32346 + err = au_wbr_create_exp(dentry);
32350 + sb = dentry->d_sb;
32351 + next = &au_sbi(sb)->si_wbr_rr_next;
32352 + bbot = au_sbbot(sb);
32354 + for (bindex = 0; bindex <= bbot; bindex++) {
32355 + if (!au_ftest_wbr(flags, DIR)) {
32356 + err = atomic_dec_return(next) + 1;
32357 + /* modulo for 0 is meaningless */
32358 + if (unlikely(!err))
32359 + err = atomic_dec_return(next) + 1;
32361 + err = atomic_read(next);
32362 + AuDbg("%d\n", err);
32365 + AuDbg("%d\n", err);
32366 + if (!au_br_rdonly(au_sbr(sb, err)))
32372 + err = au_wbr_nonopq(dentry, err);
32375 + AuDbg("%d\n", err);
32379 +/* ---------------------------------------------------------------------- */
32381 +/* most free space */
32382 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32384 + struct super_block *sb;
32385 + struct au_branch *br;
32386 + struct au_wbr_mfs *mfs;
32387 + struct dentry *h_parent;
32388 + aufs_bindex_t bindex, bbot;
32390 + unsigned long long b, bavail;
32391 + struct path h_path;
32392 + /* reduce the stack usage */
32393 + struct kstatfs *st;
32395 + st = kmalloc(sizeof(*st), GFP_NOFS);
32396 + if (unlikely(!st)) {
32397 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32402 + sb = dentry->d_sb;
32403 + mfs = &au_sbi(sb)->si_wbr_mfs;
32404 + MtxMustLock(&mfs->mfs_lock);
32405 + mfs->mfs_bindex = -EROFS;
32406 + mfs->mfsrr_bytes = 0;
32409 + bbot = au_sbbot(sb);
32411 + bindex = au_dbtop(parent);
32412 + bbot = au_dbtaildir(parent);
32415 + for (; bindex <= bbot; bindex++) {
32417 + h_parent = au_h_dptr(parent, bindex);
32418 + if (!h_parent || d_is_negative(h_parent))
32421 + br = au_sbr(sb, bindex);
32422 + if (au_br_rdonly(br))
32425 + /* sb->s_root for NFS is unreliable */
32426 + h_path.mnt = au_br_mnt(br);
32427 + h_path.dentry = h_path.mnt->mnt_root;
32428 + err = vfs_statfs(&h_path, st);
32429 + if (unlikely(err)) {
32430 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32434 + /* when the available size is equal, select the lower one */
32435 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32436 + || sizeof(b) < sizeof(st->f_bsize));
32437 + b = st->f_bavail * st->f_bsize;
32438 + br->br_wbr->wbr_bytes = b;
32439 + if (b >= bavail) {
32441 + mfs->mfs_bindex = bindex;
32442 + mfs->mfs_jiffy = jiffies;
32446 + mfs->mfsrr_bytes = bavail;
32447 + AuDbg("b%d\n", mfs->mfs_bindex);
32448 + au_delayed_kfree(st);
32451 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32454 + struct dentry *parent;
32455 + struct super_block *sb;
32456 + struct au_wbr_mfs *mfs;
32458 + err = au_wbr_create_exp(dentry);
32462 + sb = dentry->d_sb;
32464 + if (au_ftest_wbr(flags, PARENT))
32465 + parent = dget_parent(dentry);
32466 + mfs = &au_sbi(sb)->si_wbr_mfs;
32467 + mutex_lock(&mfs->mfs_lock);
32468 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32469 + || mfs->mfs_bindex < 0
32470 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32471 + au_mfs(dentry, parent);
32472 + mutex_unlock(&mfs->mfs_lock);
32473 + err = mfs->mfs_bindex;
32477 + err = au_wbr_nonopq(dentry, err);
32480 + AuDbg("b%d\n", err);
32484 +static int au_wbr_create_init_mfs(struct super_block *sb)
32486 + struct au_wbr_mfs *mfs;
32488 + mfs = &au_sbi(sb)->si_wbr_mfs;
32489 + mutex_init(&mfs->mfs_lock);
32490 + mfs->mfs_jiffy = 0;
32491 + mfs->mfs_bindex = -EROFS;
32496 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32498 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32502 +/* ---------------------------------------------------------------------- */
32504 +/* top down regardless parent, and then mfs */
32505 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32506 + unsigned int flags __maybe_unused)
32509 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32510 + unsigned long long watermark;
32511 + struct super_block *sb;
32512 + struct au_wbr_mfs *mfs;
32513 + struct au_branch *br;
32514 + struct dentry *parent;
32516 + sb = dentry->d_sb;
32517 + mfs = &au_sbi(sb)->si_wbr_mfs;
32518 + mutex_lock(&mfs->mfs_lock);
32519 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32520 + || mfs->mfs_bindex < 0)
32521 + au_mfs(dentry, /*parent*/NULL);
32522 + watermark = mfs->mfsrr_watermark;
32523 + bmfs = mfs->mfs_bindex;
32524 + mutex_unlock(&mfs->mfs_lock);
32526 + /* another style of au_wbr_create_exp() */
32527 + bwh = au_dbwh(dentry);
32528 + parent = dget_parent(dentry);
32529 + btail = au_dbtaildir(parent);
32530 + if (bwh >= 0 && bwh < btail)
32533 + err = au_wbr_nonopq(dentry, btail);
32534 + if (unlikely(err < 0))
32538 + for (bindex = 0; bindex <= btail; bindex++) {
32539 + br = au_sbr(sb, bindex);
32540 + if (au_br_rdonly(br))
32542 + if (br->br_wbr->wbr_bytes > watermark) {
32553 + AuDbg("b%d\n", err);
32557 +/* ---------------------------------------------------------------------- */
32559 +/* most free space and then round robin */
32560 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32563 + struct au_wbr_mfs *mfs;
32565 + err = au_wbr_create_mfs(dentry, flags);
32567 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32568 + mutex_lock(&mfs->mfs_lock);
32569 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32570 + err = au_wbr_create_rr(dentry, flags);
32571 + mutex_unlock(&mfs->mfs_lock);
32574 + AuDbg("b%d\n", err);
32578 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32582 + au_wbr_create_init_mfs(sb); /* ignore */
32583 + err = au_wbr_create_init_rr(sb);
32588 +/* ---------------------------------------------------------------------- */
32590 +/* top down parent and most free space */
32591 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32594 + unsigned long long b;
32595 + aufs_bindex_t bindex, btop, bbot;
32596 + struct super_block *sb;
32597 + struct dentry *parent, *h_parent;
32598 + struct au_branch *br;
32600 + err = au_wbr_create_tdp(dentry, flags);
32601 + if (unlikely(err < 0))
32603 + parent = dget_parent(dentry);
32604 + btop = au_dbtop(parent);
32605 + bbot = au_dbtaildir(parent);
32606 + if (btop == bbot)
32607 + goto out_parent; /* success */
32609 + e2 = au_wbr_create_mfs(dentry, flags);
32611 + goto out_parent; /* success */
32613 + /* when the available size is equal, select upper one */
32614 + sb = dentry->d_sb;
32615 + br = au_sbr(sb, err);
32616 + b = br->br_wbr->wbr_bytes;
32617 + AuDbg("b%d, %llu\n", err, b);
32619 + for (bindex = btop; bindex <= bbot; bindex++) {
32620 + h_parent = au_h_dptr(parent, bindex);
32621 + if (!h_parent || d_is_negative(h_parent))
32624 + br = au_sbr(sb, bindex);
32625 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32626 + b = br->br_wbr->wbr_bytes;
32628 + AuDbg("b%d, %llu\n", err, b);
32633 + err = au_wbr_nonopq(dentry, err);
32638 + AuDbg("b%d\n", err);
32642 +/* ---------------------------------------------------------------------- */
32645 + * - top down parent
32646 + * - most free space with parent
32647 + * - most free space round-robin regardless parent
32649 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32652 + unsigned long long watermark;
32653 + struct super_block *sb;
32654 + struct au_branch *br;
32655 + struct au_wbr_mfs *mfs;
32657 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32658 + if (unlikely(err < 0))
32661 + sb = dentry->d_sb;
32662 + br = au_sbr(sb, err);
32663 + mfs = &au_sbi(sb)->si_wbr_mfs;
32664 + mutex_lock(&mfs->mfs_lock);
32665 + watermark = mfs->mfsrr_watermark;
32666 + mutex_unlock(&mfs->mfs_lock);
32667 + if (br->br_wbr->wbr_bytes < watermark)
32668 + /* regardless the parent dir */
32669 + err = au_wbr_create_mfsrr(dentry, flags);
32672 + AuDbg("b%d\n", err);
32676 +/* ---------------------------------------------------------------------- */
32678 +/* policies for copyup */
32680 +/* top down parent */
32681 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32683 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32686 +/* bottom up parent */
32687 +static int au_wbr_copyup_bup(struct dentry *dentry)
32690 + aufs_bindex_t bindex, btop;
32691 + struct dentry *parent, *h_parent;
32692 + struct super_block *sb;
32695 + sb = dentry->d_sb;
32696 + parent = dget_parent(dentry);
32697 + btop = au_dbtop(parent);
32698 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32699 + h_parent = au_h_dptr(parent, bindex);
32700 + if (!h_parent || d_is_negative(h_parent))
32703 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32710 + /* bottom up here */
32711 + if (unlikely(err < 0))
32712 + err = au_wbr_bu(sb, btop - 1);
32714 + AuDbg("b%d\n", err);
32719 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32723 + err = au_wbr_bu(dentry->d_sb, btop);
32724 + AuDbg("b%d\n", err);
32726 + err = au_wbr_nonopq(dentry, err);
32728 + AuDbg("b%d\n", err);
32732 +static int au_wbr_copyup_bu(struct dentry *dentry)
32735 + aufs_bindex_t btop;
32737 + btop = au_dbtop(dentry);
32738 + err = au_wbr_do_copyup_bu(dentry, btop);
32742 +/* ---------------------------------------------------------------------- */
32744 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32745 + [AuWbrCopyup_TDP] = {
32746 + .copyup = au_wbr_copyup_tdp
32748 + [AuWbrCopyup_BUP] = {
32749 + .copyup = au_wbr_copyup_bup
32751 + [AuWbrCopyup_BU] = {
32752 + .copyup = au_wbr_copyup_bu
32756 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32757 + [AuWbrCreate_TDP] = {
32758 + .create = au_wbr_create_tdp
32760 + [AuWbrCreate_RR] = {
32761 + .create = au_wbr_create_rr,
32762 + .init = au_wbr_create_init_rr
32764 + [AuWbrCreate_MFS] = {
32765 + .create = au_wbr_create_mfs,
32766 + .init = au_wbr_create_init_mfs,
32767 + .fin = au_wbr_create_fin_mfs
32769 + [AuWbrCreate_MFSV] = {
32770 + .create = au_wbr_create_mfs,
32771 + .init = au_wbr_create_init_mfs,
32772 + .fin = au_wbr_create_fin_mfs
32774 + [AuWbrCreate_MFSRR] = {
32775 + .create = au_wbr_create_mfsrr,
32776 + .init = au_wbr_create_init_mfsrr,
32777 + .fin = au_wbr_create_fin_mfs
32779 + [AuWbrCreate_MFSRRV] = {
32780 + .create = au_wbr_create_mfsrr,
32781 + .init = au_wbr_create_init_mfsrr,
32782 + .fin = au_wbr_create_fin_mfs
32784 + [AuWbrCreate_TDMFS] = {
32785 + .create = au_wbr_create_tdmfs,
32786 + .init = au_wbr_create_init_mfs,
32787 + .fin = au_wbr_create_fin_mfs
32789 + [AuWbrCreate_TDMFSV] = {
32790 + .create = au_wbr_create_tdmfs,
32791 + .init = au_wbr_create_init_mfs,
32792 + .fin = au_wbr_create_fin_mfs
32794 + [AuWbrCreate_PMFS] = {
32795 + .create = au_wbr_create_pmfs,
32796 + .init = au_wbr_create_init_mfs,
32797 + .fin = au_wbr_create_fin_mfs
32799 + [AuWbrCreate_PMFSV] = {
32800 + .create = au_wbr_create_pmfs,
32801 + .init = au_wbr_create_init_mfs,
32802 + .fin = au_wbr_create_fin_mfs
32804 + [AuWbrCreate_PMFSRR] = {
32805 + .create = au_wbr_create_pmfsrr,
32806 + .init = au_wbr_create_init_mfsrr,
32807 + .fin = au_wbr_create_fin_mfs
32809 + [AuWbrCreate_PMFSRRV] = {
32810 + .create = au_wbr_create_pmfsrr,
32811 + .init = au_wbr_create_init_mfsrr,
32812 + .fin = au_wbr_create_fin_mfs
32815 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32816 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32817 +++ linux/fs/aufs/whout.c 2017-05-06 22:16:52.784886929 +0200
32820 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32822 + * This program, aufs is free software; you can redistribute it and/or modify
32823 + * it under the terms of the GNU General Public License as published by
32824 + * the Free Software Foundation; either version 2 of the License, or
32825 + * (at your option) any later version.
32827 + * This program is distributed in the hope that it will be useful,
32828 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32829 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32830 + * GNU General Public License for more details.
32832 + * You should have received a copy of the GNU General Public License
32833 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32837 + * whiteout for logical deletion and opaque directory
32842 +#define WH_MASK S_IRUGO
32845 + * If a directory contains this file, then it is opaque. We start with the
32846 + * .wh. flag so that it is blocked by lookup.
32848 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32849 + sizeof(AUFS_WH_DIROPQ) - 1);
32852 + * generate whiteout name, which is NOT terminated by NULL.
32853 + * @name: original d_name.name
32854 + * @len: original d_name.len
32855 + * @wh: whiteout qstr
32856 + * returns zero when succeeds, otherwise error.
32857 + * succeeded value as wh->name should be freed by kfree().
32859 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32863 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32864 + return -ENAMETOOLONG;
32866 + wh->len = name->len + AUFS_WH_PFX_LEN;
32867 + p = kmalloc(wh->len, GFP_NOFS);
32870 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32871 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32878 +/* ---------------------------------------------------------------------- */
32881 + * test if the @wh_name exists under @h_parent.
32882 + * @try_sio specifies the necessary of super-io.
32884 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32887 + struct dentry *wh_dentry;
32890 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32892 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32893 + err = PTR_ERR(wh_dentry);
32894 + if (IS_ERR(wh_dentry)) {
32895 + if (err == -ENAMETOOLONG)
32901 + if (d_is_negative(wh_dentry))
32902 + goto out_wh; /* success */
32905 + if (d_is_reg(wh_dentry))
32906 + goto out_wh; /* success */
32909 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32910 + wh_dentry, d_inode(wh_dentry)->i_mode);
32919 + * test if the @h_dentry sets opaque or not.
32921 +int au_diropq_test(struct dentry *h_dentry)
32924 + struct inode *h_dir;
32926 + h_dir = d_inode(h_dentry);
32927 + err = au_wh_test(h_dentry, &diropq_name,
32928 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32933 + * returns a negative dentry whose name is unique and temporary.
32935 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32936 + struct qstr *prefix)
32938 + struct dentry *dentry;
32940 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32942 + /* strict atomic_t is unnecessary here */
32943 + static unsigned short cnt;
32946 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32949 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32950 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32951 + dentry = ERR_PTR(-ENAMETOOLONG);
32952 + if (unlikely(qs.len > NAME_MAX))
32954 + dentry = ERR_PTR(-ENOMEM);
32955 + name = kmalloc(qs.len + 1, GFP_NOFS);
32956 + if (unlikely(!name))
32960 + /* doubly whiteout-ed */
32961 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32962 + p = name + AUFS_WH_PFX_LEN * 2;
32963 + memcpy(p, prefix->name, prefix->len);
32964 + p += prefix->len;
32966 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32969 + for (i = 0; i < 3; i++) {
32970 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32971 + dentry = au_sio_lkup_one(&qs, h_parent);
32972 + if (IS_ERR(dentry) || d_is_negative(dentry))
32976 + /* pr_warn("could not get random name\n"); */
32977 + dentry = ERR_PTR(-EEXIST);
32978 + AuDbg("%.*s\n", AuLNPair(&qs));
32982 + if (name != defname)
32983 + au_delayed_kfree(name);
32985 + AuTraceErrPtr(dentry);
32990 + * rename the @h_dentry on @br to the whiteouted temporary name.
32992 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32995 + struct path h_path = {
32996 + .mnt = au_br_mnt(br)
32998 + struct inode *h_dir, *delegated;
32999 + struct dentry *h_parent;
33001 + h_parent = h_dentry->d_parent; /* dir inode is locked */
33002 + h_dir = d_inode(h_parent);
33003 + IMustLock(h_dir);
33005 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
33006 + err = PTR_ERR(h_path.dentry);
33007 + if (IS_ERR(h_path.dentry))
33010 + /* under the same dir, no need to lock_rename() */
33011 + delegated = NULL;
33012 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
33015 + if (unlikely(err == -EWOULDBLOCK)) {
33016 + pr_warn("cannot retry for NFSv4 delegation"
33017 + " for an internal rename\n");
33020 + dput(h_path.dentry);
33027 +/* ---------------------------------------------------------------------- */
33029 + * functions for removing a whiteout
33032 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
33035 + struct inode *delegated;
33038 + * forces superio when the dir has a sticky bit.
33039 + * this may be a violation of unix fs semantics.
33041 + force = (h_dir->i_mode & S_ISVTX)
33042 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
33043 + delegated = NULL;
33044 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
33045 + if (unlikely(err == -EWOULDBLOCK)) {
33046 + pr_warn("cannot retry for NFSv4 delegation"
33047 + " for an internal unlink\n");
33053 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33054 + struct dentry *dentry)
33058 + err = do_unlink_wh(h_dir, h_path);
33059 + if (!err && dentry)
33060 + au_set_dbwh(dentry, -1);
33065 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
33066 + struct au_branch *br)
33069 + struct path h_path = {
33070 + .mnt = au_br_mnt(br)
33074 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
33075 + if (IS_ERR(h_path.dentry))
33076 + err = PTR_ERR(h_path.dentry);
33078 + if (d_is_reg(h_path.dentry))
33079 + err = do_unlink_wh(d_inode(h_parent), &h_path);
33080 + dput(h_path.dentry);
33086 +/* ---------------------------------------------------------------------- */
33088 + * initialize/clean whiteout for a branch
33091 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
33095 + struct inode *delegated;
33097 + if (d_is_negative(whpath->dentry))
33101 + err = vfsub_rmdir(h_dir, whpath);
33103 + delegated = NULL;
33104 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
33105 + if (unlikely(err == -EWOULDBLOCK)) {
33106 + pr_warn("cannot retry for NFSv4 delegation"
33107 + " for an internal unlink\n");
33111 + if (unlikely(err))
33112 + pr_warn("failed removing %pd (%d), ignored.\n",
33113 + whpath->dentry, err);
33116 +static int test_linkable(struct dentry *h_root)
33118 + struct inode *h_dir = d_inode(h_root);
33120 + if (h_dir->i_op->link)
33123 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
33124 + h_root, au_sbtype(h_root->d_sb));
33128 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
33129 +static int au_whdir(struct inode *h_dir, struct path *path)
33134 + if (d_is_negative(path->dentry)) {
33135 + int mode = S_IRWXU;
33137 + if (au_test_nfs(path->dentry->d_sb))
33139 + err = vfsub_mkdir(h_dir, path, mode);
33140 + } else if (d_is_dir(path->dentry))
33143 + pr_err("unknown %pd exists\n", path->dentry);
33148 +struct au_wh_base {
33149 + const struct qstr *name;
33150 + struct dentry *dentry;
33153 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
33154 + struct path *h_path)
33156 + h_path->dentry = base[AuBrWh_BASE].dentry;
33157 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33158 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33159 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33160 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33161 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33165 + * returns tri-state,
33166 + * minus: error, caller should print the message
33168 + * plus: error, caller should NOT print the message
33170 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
33171 + int do_plink, struct au_wh_base base[],
33172 + struct path *h_path)
33175 + struct inode *h_dir;
33177 + h_dir = d_inode(h_root);
33178 + h_path->dentry = base[AuBrWh_BASE].dentry;
33179 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33180 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33182 + err = test_linkable(h_root);
33183 + if (unlikely(err)) {
33188 + err = au_whdir(h_dir, h_path);
33189 + if (unlikely(err))
33191 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33193 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33194 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33195 + err = au_whdir(h_dir, h_path);
33196 + if (unlikely(err))
33198 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33205 + * for the moment, aufs supports the branch filesystem which does not support
33206 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
33207 + * copyup failed. finally, such filesystem will not be used as the writable
33210 + * returns tri-state, see above.
33212 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
33213 + int do_plink, struct au_wh_base base[],
33214 + struct path *h_path)
33217 + struct inode *h_dir;
33219 + WbrWhMustWriteLock(wbr);
33221 + err = test_linkable(h_root);
33222 + if (unlikely(err)) {
33228 + * todo: should this create be done in /sbin/mount.aufs helper?
33231 + h_dir = d_inode(h_root);
33232 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33233 + h_path->dentry = base[AuBrWh_BASE].dentry;
33234 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33235 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33238 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33239 + if (unlikely(err))
33242 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33244 + err = au_whdir(h_dir, h_path);
33245 + if (unlikely(err))
33247 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33249 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33250 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33252 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33253 + err = au_whdir(h_dir, h_path);
33254 + if (unlikely(err))
33256 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33263 + * initialize the whiteout base file/dir for @br.
33265 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33268 + const unsigned char do_plink
33269 + = !!au_opt_test(au_mntflags(sb), PLINK);
33270 + struct inode *h_dir;
33271 + struct path path = br->br_path;
33272 + struct dentry *h_root = path.dentry;
33273 + struct au_wbr *wbr = br->br_wbr;
33274 + static const struct qstr base_name[] = {
33275 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33276 + sizeof(AUFS_BASE_NAME) - 1),
33277 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33278 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33279 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33280 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33282 + struct au_wh_base base[] = {
33283 + [AuBrWh_BASE] = {
33284 + .name = base_name + AuBrWh_BASE,
33287 + [AuBrWh_PLINK] = {
33288 + .name = base_name + AuBrWh_PLINK,
33291 + [AuBrWh_ORPH] = {
33292 + .name = base_name + AuBrWh_ORPH,
33298 + WbrWhMustWriteLock(wbr);
33300 + for (i = 0; i < AuBrWh_Last; i++) {
33301 + /* doubly whiteouted */
33302 + struct dentry *d;
33304 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33305 + err = PTR_ERR(d);
33309 + base[i].dentry = d;
33311 + && wbr->wbr_wh[i]
33312 + && wbr->wbr_wh[i] != base[i].dentry);
33316 + for (i = 0; i < AuBrWh_Last; i++) {
33317 + dput(wbr->wbr_wh[i]);
33318 + wbr->wbr_wh[i] = NULL;
33322 + if (!au_br_writable(br->br_perm)) {
33323 + h_dir = d_inode(h_root);
33324 + au_wh_init_ro(h_dir, base, &path);
33325 + } else if (!au_br_wh_linkable(br->br_perm)) {
33326 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33332 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33338 + goto out; /* success */
33341 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33342 + err, h_root, au_sbtype(h_root->d_sb));
33344 + for (i = 0; i < AuBrWh_Last; i++)
33345 + dput(base[i].dentry);
33349 +/* ---------------------------------------------------------------------- */
33351 + * whiteouts are all hard-linked usually.
33352 + * when its link count reaches a ceiling, we create a new whiteout base
33353 + * asynchronously.
33356 +struct reinit_br_wh {
33357 + struct super_block *sb;
33358 + struct au_branch *br;
33361 +static void reinit_br_wh(void *arg)
33364 + aufs_bindex_t bindex;
33365 + struct path h_path;
33366 + struct reinit_br_wh *a = arg;
33367 + struct au_wbr *wbr;
33368 + struct inode *dir, *delegated;
33369 + struct dentry *h_root;
33370 + struct au_hinode *hdir;
33373 + wbr = a->br->br_wbr;
33374 + /* big aufs lock */
33375 + si_noflush_write_lock(a->sb);
33376 + if (!au_br_writable(a->br->br_perm))
33378 + bindex = au_br_index(a->sb, a->br->br_id);
33379 + if (unlikely(bindex < 0))
33382 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33383 + dir = d_inode(a->sb->s_root);
33384 + hdir = au_hi(dir, bindex);
33385 + h_root = au_h_dptr(a->sb->s_root, bindex);
33386 + AuDebugOn(h_root != au_br_dentry(a->br));
33388 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33389 + wbr_wh_write_lock(wbr);
33390 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33393 + h_path.dentry = wbr->wbr_whbase;
33394 + h_path.mnt = au_br_mnt(a->br);
33395 + delegated = NULL;
33396 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33398 + if (unlikely(err == -EWOULDBLOCK)) {
33399 + pr_warn("cannot retry for NFSv4 delegation"
33400 + " for an internal unlink\n");
33404 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33407 + dput(wbr->wbr_whbase);
33408 + wbr->wbr_whbase = NULL;
33410 + err = au_wh_init(a->br, a->sb);
33411 + wbr_wh_write_unlock(wbr);
33412 + au_hn_inode_unlock(hdir);
33413 + di_read_unlock(a->sb->s_root, AuLock_IR);
33415 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33419 + atomic_dec(&wbr->wbr_wh_running);
33420 + au_br_put(a->br);
33421 + si_write_unlock(a->sb);
33422 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33423 + au_delayed_kfree(arg);
33424 + if (unlikely(err))
33425 + AuIOErr("err %d\n", err);
33428 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33430 + int do_dec, wkq_err;
33431 + struct reinit_br_wh *arg;
33434 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33437 + /* ignore ENOMEM */
33438 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33441 + * dec(wh_running), kfree(arg) and dec(br_count)
33442 + * in reinit function
33447 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33448 + if (unlikely(wkq_err)) {
33449 + atomic_dec(&br->br_wbr->wbr_wh_running);
33451 + au_delayed_kfree(arg);
33458 + atomic_dec(&br->br_wbr->wbr_wh_running);
33461 +/* ---------------------------------------------------------------------- */
33464 + * create the whiteout @wh.
33466 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33467 + struct dentry *wh)
33470 + struct path h_path = {
33473 + struct au_branch *br;
33474 + struct au_wbr *wbr;
33475 + struct dentry *h_parent;
33476 + struct inode *h_dir, *delegated;
33478 + h_parent = wh->d_parent; /* dir inode is locked */
33479 + h_dir = d_inode(h_parent);
33480 + IMustLock(h_dir);
33482 + br = au_sbr(sb, bindex);
33483 + h_path.mnt = au_br_mnt(br);
33484 + wbr = br->br_wbr;
33485 + wbr_wh_read_lock(wbr);
33486 + if (wbr->wbr_whbase) {
33487 + delegated = NULL;
33488 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33489 + if (unlikely(err == -EWOULDBLOCK)) {
33490 + pr_warn("cannot retry for NFSv4 delegation"
33491 + " for an internal link\n");
33494 + if (!err || err != -EMLINK)
33497 + /* link count full. re-initialize br_whbase. */
33498 + kick_reinit_br_wh(sb, br);
33501 + /* return this error in this context */
33502 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33504 + au_fhsm_wrote(sb, bindex, /*force*/0);
33507 + wbr_wh_read_unlock(wbr);
33511 +/* ---------------------------------------------------------------------- */
33514 + * create or remove the diropq.
33516 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33517 + unsigned int flags)
33519 + struct dentry *opq_dentry, *h_dentry;
33520 + struct super_block *sb;
33521 + struct au_branch *br;
33524 + sb = dentry->d_sb;
33525 + br = au_sbr(sb, bindex);
33526 + h_dentry = au_h_dptr(dentry, bindex);
33527 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33528 + if (IS_ERR(opq_dentry))
33531 + if (au_ftest_diropq(flags, CREATE)) {
33532 + err = link_or_create_wh(sb, bindex, opq_dentry);
33534 + au_set_dbdiropq(dentry, bindex);
33535 + goto out; /* success */
33538 + struct path tmp = {
33539 + .dentry = opq_dentry,
33540 + .mnt = au_br_mnt(br)
33542 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33544 + au_set_dbdiropq(dentry, -1);
33546 + dput(opq_dentry);
33547 + opq_dentry = ERR_PTR(err);
33550 + return opq_dentry;
33553 +struct do_diropq_args {
33554 + struct dentry **errp;
33555 + struct dentry *dentry;
33556 + aufs_bindex_t bindex;
33557 + unsigned int flags;
33560 +static void call_do_diropq(void *args)
33562 + struct do_diropq_args *a = args;
33563 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33566 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33567 + unsigned int flags)
33569 + struct dentry *diropq, *h_dentry;
33571 + h_dentry = au_h_dptr(dentry, bindex);
33572 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33573 + diropq = do_diropq(dentry, bindex, flags);
33576 + struct do_diropq_args args = {
33578 + .dentry = dentry,
33579 + .bindex = bindex,
33583 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33584 + if (unlikely(wkq_err))
33585 + diropq = ERR_PTR(wkq_err);
33591 +/* ---------------------------------------------------------------------- */
33594 + * lookup whiteout dentry.
33595 + * @h_parent: lower parent dentry which must exist and be locked
33596 + * @base_name: name of dentry which will be whiteouted
33597 + * returns dentry for whiteout.
33599 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33600 + struct au_branch *br)
33603 + struct qstr wh_name;
33604 + struct dentry *wh_dentry;
33606 + err = au_wh_name_alloc(&wh_name, base_name);
33607 + wh_dentry = ERR_PTR(err);
33609 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33610 + au_delayed_kfree(wh_name.name);
33612 + return wh_dentry;
33616 + * link/create a whiteout for @dentry on @bindex.
33618 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33619 + struct dentry *h_parent)
33621 + struct dentry *wh_dentry;
33622 + struct super_block *sb;
33625 + sb = dentry->d_sb;
33626 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33627 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33628 + err = link_or_create_wh(sb, bindex, wh_dentry);
33630 + au_set_dbwh(dentry, bindex);
33631 + au_fhsm_wrote(sb, bindex, /*force*/0);
33634 + wh_dentry = ERR_PTR(err);
33638 + return wh_dentry;
33641 +/* ---------------------------------------------------------------------- */
33643 +/* Delete all whiteouts in this directory on branch bindex. */
33644 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33645 + aufs_bindex_t bindex, struct au_branch *br)
33648 + unsigned long ul, n;
33649 + struct qstr wh_name;
33651 + struct hlist_head *head;
33652 + struct au_vdir_wh *pos;
33653 + struct au_vdir_destr *str;
33656 + p = (void *)__get_free_page(GFP_NOFS);
33657 + wh_name.name = p;
33658 + if (unlikely(!wh_name.name))
33662 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33663 + p += AUFS_WH_PFX_LEN;
33664 + n = whlist->nh_num;
33665 + head = whlist->nh_head;
33666 + for (ul = 0; !err && ul < n; ul++, head++) {
33667 + hlist_for_each_entry(pos, head, wh_hash) {
33668 + if (pos->wh_bindex != bindex)
33671 + str = &pos->wh_str;
33672 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33673 + memcpy(p, str->name, str->len);
33674 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33675 + err = unlink_wh_name(h_dentry, &wh_name, br);
33680 + AuIOErr("whiteout name too long %.*s\n",
33681 + str->len, str->name);
33686 + au_delayed_free_page((unsigned long)wh_name.name);
33692 +struct del_wh_children_args {
33694 + struct dentry *h_dentry;
33695 + struct au_nhash *whlist;
33696 + aufs_bindex_t bindex;
33697 + struct au_branch *br;
33700 +static void call_del_wh_children(void *args)
33702 + struct del_wh_children_args *a = args;
33703 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33706 +/* ---------------------------------------------------------------------- */
33708 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33710 + struct au_whtmp_rmdir *whtmp;
33712 + unsigned int rdhash;
33714 + SiMustAnyLock(sb);
33716 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33717 + if (unlikely(!whtmp)) {
33718 + whtmp = ERR_PTR(-ENOMEM);
33722 + /* no estimation for dir size */
33723 + rdhash = au_sbi(sb)->si_rdhash;
33725 + rdhash = AUFS_RDHASH_DEF;
33726 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33727 + if (unlikely(err)) {
33728 + au_delayed_kfree(whtmp);
33729 + whtmp = ERR_PTR(err);
33736 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33739 + au_br_put(whtmp->br);
33740 + dput(whtmp->wh_dentry);
33741 + iput(whtmp->dir);
33742 + au_nhash_wh_free(&whtmp->whlist);
33743 + au_delayed_kfree(whtmp);
33747 + * rmdir the whiteouted temporary named dir @h_dentry.
33748 + * @whlist: whiteouted children.
33750 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33751 + struct dentry *wh_dentry, struct au_nhash *whlist)
33754 + unsigned int h_nlink;
33755 + struct path h_tmp;
33756 + struct inode *wh_inode, *h_dir;
33757 + struct au_branch *br;
33759 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33760 + IMustLock(h_dir);
33762 + br = au_sbr(dir->i_sb, bindex);
33763 + wh_inode = d_inode(wh_dentry);
33764 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33767 + * someone else might change some whiteouts while we were sleeping.
33768 + * it means this whlist may have an obsoleted entry.
33770 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33771 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33774 + struct del_wh_children_args args = {
33776 + .h_dentry = wh_dentry,
33777 + .whlist = whlist,
33778 + .bindex = bindex,
33782 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33783 + if (unlikely(wkq_err))
33786 + inode_unlock(wh_inode);
33789 + h_tmp.dentry = wh_dentry;
33790 + h_tmp.mnt = au_br_mnt(br);
33791 + h_nlink = h_dir->i_nlink;
33792 + err = vfsub_rmdir(h_dir, &h_tmp);
33793 + /* some fs doesn't change the parent nlink in some cases */
33794 + h_nlink -= h_dir->i_nlink;
33798 + if (au_ibtop(dir) == bindex) {
33799 + /* todo: dir->i_mutex is necessary */
33800 + au_cpup_attr_timesizes(dir);
33802 + vfsub_drop_nlink(dir);
33804 + return 0; /* success */
33807 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33811 +static void call_rmdir_whtmp(void *args)
33814 + aufs_bindex_t bindex;
33815 + struct au_whtmp_rmdir *a = args;
33816 + struct super_block *sb;
33817 + struct dentry *h_parent;
33818 + struct inode *h_dir;
33819 + struct au_hinode *hdir;
33821 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33822 + /* inode_lock(a->dir); */
33824 + sb = a->dir->i_sb;
33825 + si_read_lock(sb, !AuLock_FLUSH);
33826 + if (!au_br_writable(a->br->br_perm))
33828 + bindex = au_br_index(sb, a->br->br_id);
33829 + if (unlikely(bindex < 0))
33833 + ii_write_lock_parent(a->dir);
33834 + h_parent = dget_parent(a->wh_dentry);
33835 + h_dir = d_inode(h_parent);
33836 + hdir = au_hi(a->dir, bindex);
33837 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33838 + if (unlikely(err))
33840 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33841 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33844 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33845 + au_hn_inode_unlock(hdir);
33846 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33850 + ii_write_unlock(a->dir);
33852 + /* inode_unlock(a->dir); */
33853 + au_whtmp_rmdir_free(a);
33854 + si_read_unlock(sb);
33855 + au_nwt_done(&au_sbi(sb)->si_nowait);
33856 + if (unlikely(err))
33857 + AuIOErr("err %d\n", err);
33860 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33861 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33864 + struct super_block *sb;
33868 + /* all post-process will be done in do_rmdir_whtmp(). */
33870 + args->dir = au_igrab(dir);
33871 + args->br = au_sbr(sb, bindex);
33872 + au_br_get(args->br);
33873 + args->wh_dentry = dget(wh_dentry);
33874 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33875 + if (unlikely(wkq_err)) {
33876 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33877 + au_whtmp_rmdir_free(args);
33880 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33881 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33882 +++ linux/fs/aufs/whout.h 2017-05-06 22:16:52.784886929 +0200
33885 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33887 + * This program, aufs is free software; you can redistribute it and/or modify
33888 + * it under the terms of the GNU General Public License as published by
33889 + * the Free Software Foundation; either version 2 of the License, or
33890 + * (at your option) any later version.
33892 + * This program is distributed in the hope that it will be useful,
33893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33895 + * GNU General Public License for more details.
33897 + * You should have received a copy of the GNU General Public License
33898 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33902 + * whiteout for logical deletion and opaque directory
33905 +#ifndef __AUFS_WHOUT_H__
33906 +#define __AUFS_WHOUT_H__
33913 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33914 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33915 +int au_diropq_test(struct dentry *h_dentry);
33917 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33918 + struct qstr *prefix);
33919 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33920 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33921 + struct dentry *dentry);
33922 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33924 +/* diropq flags */
33925 +#define AuDiropq_CREATE 1
33926 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33927 +#define au_fset_diropq(flags, name) \
33928 + do { (flags) |= AuDiropq_##name; } while (0)
33929 +#define au_fclr_diropq(flags, name) \
33930 + do { (flags) &= ~AuDiropq_##name; } while (0)
33932 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33933 + unsigned int flags);
33934 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33935 + struct au_branch *br);
33936 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33937 + struct dentry *h_parent);
33939 +/* real rmdir for the whiteout-ed dir */
33940 +struct au_whtmp_rmdir {
33941 + struct inode *dir;
33942 + struct au_branch *br;
33943 + struct dentry *wh_dentry;
33944 + struct au_nhash whlist;
33947 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33948 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33949 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33950 + struct dentry *wh_dentry, struct au_nhash *whlist);
33951 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33952 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33954 +/* ---------------------------------------------------------------------- */
33956 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33957 + aufs_bindex_t bindex)
33959 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33962 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33964 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33967 +#endif /* __KERNEL__ */
33968 +#endif /* __AUFS_WHOUT_H__ */
33969 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33970 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33971 +++ linux/fs/aufs/wkq.c 2017-05-06 22:16:52.784886929 +0200
33974 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33976 + * This program, aufs is free software; you can redistribute it and/or modify
33977 + * it under the terms of the GNU General Public License as published by
33978 + * the Free Software Foundation; either version 2 of the License, or
33979 + * (at your option) any later version.
33981 + * This program is distributed in the hope that it will be useful,
33982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33984 + * GNU General Public License for more details.
33986 + * You should have received a copy of the GNU General Public License
33987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33991 + * workqueue for asynchronous/super-io operations
33992 + * todo: try new dredential scheme
33995 +#include <linux/module.h>
33998 +/* internal workqueue named AUFS_WKQ_NAME */
34000 +static struct workqueue_struct *au_wkq;
34002 +struct au_wkinfo {
34003 + struct work_struct wk;
34004 + struct kobject *kobj;
34006 + unsigned int flags; /* see wkq.h */
34008 + au_wkq_func_t func;
34011 + struct completion *comp;
34014 +/* ---------------------------------------------------------------------- */
34016 +static void wkq_func(struct work_struct *wk)
34018 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
34020 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
34021 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
34023 + wkinfo->func(wkinfo->args);
34024 + if (au_ftest_wkq(wkinfo->flags, WAIT))
34025 + complete(wkinfo->comp);
34027 + kobject_put(wkinfo->kobj);
34028 + module_put(THIS_MODULE); /* todo: ?? */
34029 + au_delayed_kfree(wkinfo);
34034 + * Since struct completion is large, try allocating it dynamically.
34036 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
34037 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
34039 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
34041 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
34043 + init_completion(*comp);
34044 + wkinfo->comp = *comp;
34050 +static void au_wkq_comp_free(struct completion *comp)
34052 + au_delayed_kfree(comp);
34058 +#define AuWkqCompDeclare(name) \
34059 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
34060 + struct completion *comp = &_ ## name
34062 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
34064 + wkinfo->comp = *comp;
34068 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
34072 +#endif /* 4KSTACKS */
34074 +static void au_wkq_run(struct au_wkinfo *wkinfo)
34076 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
34077 + if (au_wkq_test()) {
34078 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
34079 + " due to a dead dir by UDBA?\n");
34080 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
34083 + au_dbg_verify_kthread();
34085 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
34086 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
34087 + queue_work(au_wkq, &wkinfo->wk);
34089 + INIT_WORK(&wkinfo->wk, wkq_func);
34090 + schedule_work(&wkinfo->wk);
34095 + * Be careful. It is easy to make deadlock happen.
34096 + * processA: lock, wkq and wait
34097 + * processB: wkq and wait, lock in wkq
34100 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
34103 + AuWkqCompDeclare(comp);
34104 + struct au_wkinfo wkinfo = {
34110 + err = au_wkq_comp_alloc(&wkinfo, &comp);
34112 + au_wkq_run(&wkinfo);
34113 + /* no timeout, no interrupt */
34114 + wait_for_completion(wkinfo.comp);
34115 + au_wkq_comp_free(comp);
34116 + destroy_work_on_stack(&wkinfo.wk);
34124 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
34125 + * problem in a concurrent umounting.
34127 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34128 + unsigned int flags)
34131 + struct au_wkinfo *wkinfo;
34133 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
34136 + * wkq_func() must free this wkinfo.
34137 + * it highly depends upon the implementation of workqueue.
34140 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
34142 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
34143 + wkinfo->flags = flags & ~AuWkq_WAIT;
34144 + wkinfo->func = func;
34145 + wkinfo->args = args;
34146 + wkinfo->comp = NULL;
34147 + kobject_get(wkinfo->kobj);
34148 + __module_get(THIS_MODULE); /* todo: ?? */
34150 + au_wkq_run(wkinfo);
34153 + au_nwt_done(&au_sbi(sb)->si_nowait);
34159 +/* ---------------------------------------------------------------------- */
34161 +void au_nwt_init(struct au_nowait_tasks *nwt)
34163 + atomic_set(&nwt->nw_len, 0);
34164 + /* smp_mb(); */ /* atomic_set */
34165 + init_waitqueue_head(&nwt->nw_wq);
34168 +void au_wkq_fin(void)
34170 + destroy_workqueue(au_wkq);
34173 +int __init au_wkq_init(void)
34178 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
34179 + if (IS_ERR(au_wkq))
34180 + err = PTR_ERR(au_wkq);
34181 + else if (!au_wkq)
34186 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
34187 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
34188 +++ linux/fs/aufs/wkq.h 2017-05-06 22:16:52.784886929 +0200
34191 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34193 + * This program, aufs is free software; you can redistribute it and/or modify
34194 + * it under the terms of the GNU General Public License as published by
34195 + * the Free Software Foundation; either version 2 of the License, or
34196 + * (at your option) any later version.
34198 + * This program is distributed in the hope that it will be useful,
34199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34201 + * GNU General Public License for more details.
34203 + * You should have received a copy of the GNU General Public License
34204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34208 + * workqueue for asynchronous/super-io operations
34209 + * todo: try new credentials management scheme
34212 +#ifndef __AUFS_WKQ_H__
34213 +#define __AUFS_WKQ_H__
34217 +#include <linux/percpu_counter.h>
34219 +struct super_block;
34221 +/* ---------------------------------------------------------------------- */
34224 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34226 +struct au_nowait_tasks {
34228 + wait_queue_head_t nw_wq;
34231 +/* ---------------------------------------------------------------------- */
34233 +typedef void (*au_wkq_func_t)(void *args);
34236 +#define AuWkq_WAIT 1
34237 +#define AuWkq_NEST (1 << 1)
34238 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34239 +#define au_fset_wkq(flags, name) \
34240 + do { (flags) |= AuWkq_##name; } while (0)
34241 +#define au_fclr_wkq(flags, name) \
34242 + do { (flags) &= ~AuWkq_##name; } while (0)
34244 +#ifndef CONFIG_AUFS_HNOTIFY
34246 +#define AuWkq_NEST 0
34250 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34251 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34252 + unsigned int flags);
34253 +void au_nwt_init(struct au_nowait_tasks *nwt);
34254 +int __init au_wkq_init(void);
34255 +void au_wkq_fin(void);
34257 +/* ---------------------------------------------------------------------- */
34259 +static inline int au_wkq_test(void)
34261 + return current->flags & PF_WQ_WORKER;
34264 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34266 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34269 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34271 + if (atomic_dec_and_test(&nwt->nw_len))
34272 + wake_up_all(&nwt->nw_wq);
34275 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34277 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34281 +#endif /* __KERNEL__ */
34282 +#endif /* __AUFS_WKQ_H__ */
34283 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34284 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34285 +++ linux/fs/aufs/xattr.c 2017-05-06 22:16:52.784886929 +0200
34288 + * Copyright (C) 2014-2017 Junjiro R. Okajima
34290 + * This program, aufs is free software; you can redistribute it and/or modify
34291 + * it under the terms of the GNU General Public License as published by
34292 + * the Free Software Foundation; either version 2 of the License, or
34293 + * (at your option) any later version.
34295 + * This program is distributed in the hope that it will be useful,
34296 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34297 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34298 + * GNU General Public License for more details.
34300 + * You should have received a copy of the GNU General Public License
34301 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34305 + * handling xattr functions
34308 +#include <linux/fs.h>
34309 +#include <linux/posix_acl_xattr.h>
34310 +#include <linux/xattr.h>
34313 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34315 + if (!ignore_flags)
34323 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34328 +#define cmp(brattr, prefix) do { \
34329 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34330 + XATTR_##prefix##_PREFIX_LEN)) { \
34331 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34337 + cmp(SEC, SECURITY);
34338 + cmp(SYS, SYSTEM);
34339 + cmp(TR, TRUSTED);
34343 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34350 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34352 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34353 + char *name, char **buf, unsigned int ignore_flags,
34354 + unsigned int verbose)
34358 + struct inode *h_idst;
34360 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34362 + if (unlikely(err <= 0)) {
34363 + if (err == -ENODATA
34364 + || (err == -EOPNOTSUPP
34365 + && ((ignore_flags & au_xattr_out_of_list)
34366 + || (au_test_nfs_noacl(d_inode(h_src))
34367 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34369 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34372 + if (err && (verbose || au_debug_test()))
34373 + pr_err("%s, err %d\n", name, err);
34377 + /* unlock it temporary */
34378 + h_idst = d_inode(h_dst);
34379 + inode_unlock(h_idst);
34380 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34381 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34382 + if (unlikely(err)) {
34383 + if (verbose || au_debug_test())
34384 + pr_err("%s, err %d\n", name, err);
34385 + err = au_xattr_ignore(err, name, ignore_flags);
34392 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34393 + unsigned int verbose)
34395 + int err, unlocked, acl_access, acl_default;
34397 + struct inode *h_isrc, *h_idst;
34398 + char *value, *p, *o, *e;
34400 + /* try stopping to update the source inode while we are referencing */
34401 + /* there should not be the parent-child relationship between them */
34402 + h_isrc = d_inode(h_src);
34403 + h_idst = d_inode(h_dst);
34404 + inode_unlock(h_idst);
34405 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34406 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34409 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34410 + ssz = vfs_listxattr(h_src, NULL, 0);
34412 + if (unlikely(err < 0)) {
34414 + if (err == -ENODATA
34415 + || err == -EOPNOTSUPP)
34416 + err = 0; /* ignore */
34425 + p = kmalloc(ssz, GFP_NOFS);
34427 + if (unlikely(!p))
34429 + err = vfs_listxattr(h_src, p, ssz);
34431 + inode_unlock(h_isrc);
34433 + AuDbg("err %d, ssz %zd\n", err, ssz);
34434 + if (unlikely(err < 0))
34442 + while (!err && p < e) {
34443 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34444 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34445 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34446 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34448 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34450 + p += strlen(p) + 1;
34453 + ignore_flags |= au_xattr_out_of_list;
34454 + if (!err && !acl_access) {
34455 + err = au_do_cpup_xattr(h_dst, h_src,
34456 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34457 + ignore_flags, verbose);
34460 + if (!err && !acl_default) {
34461 + err = au_do_cpup_xattr(h_dst, h_src,
34462 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34463 + ignore_flags, verbose);
34468 + au_delayed_kfree(value);
34472 + au_delayed_kfree(o);
34475 + inode_unlock(h_isrc);
34480 +/* ---------------------------------------------------------------------- */
34482 +static int au_smack_reentering(struct super_block *sb)
34484 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
34486 + * as a part of lookup, smack_d_instantiate() is called, and it calls
34487 + * i_op->getxattr(). ouch.
34489 + return si_pid_test(sb);
34500 +struct au_lgxattr {
34508 + const char *name;
34515 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34519 + struct path h_path;
34520 + struct super_block *sb;
34522 + sb = dentry->d_sb;
34523 + reenter = au_smack_reentering(sb);
34525 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34526 + if (unlikely(err))
34529 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
34530 + if (unlikely(err))
34532 + if (unlikely(!h_path.dentry))
34533 + /* illegally overlapped or something */
34534 + goto out_di; /* pretending success */
34536 + /* always topmost entry only */
34537 + switch (arg->type) {
34538 + case AU_XATTR_LIST:
34539 + err = vfs_listxattr(h_path.dentry,
34540 + arg->u.list.list, arg->u.list.size);
34542 + case AU_XATTR_GET:
34543 + AuDebugOn(d_is_negative(h_path.dentry));
34544 + err = vfs_getxattr(h_path.dentry,
34545 + arg->u.get.name, arg->u.get.value,
34546 + arg->u.get.size);
34552 + di_read_unlock(dentry, AuLock_IR);
34555 + si_read_unlock(sb);
34561 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34563 + struct au_lgxattr arg = {
34564 + .type = AU_XATTR_LIST,
34571 + return au_lgxattr(dentry, &arg);
34574 +static ssize_t au_getxattr(struct dentry *dentry,
34575 + struct inode *inode __maybe_unused,
34576 + const char *name, void *value, size_t size)
34578 + struct au_lgxattr arg = {
34579 + .type = AU_XATTR_GET,
34587 + return au_lgxattr(dentry, &arg);
34590 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34591 + const char *name, const void *value, size_t size,
34594 + struct au_sxattr arg = {
34595 + .type = AU_XATTR_SET,
34604 + return au_sxattr(dentry, inode, &arg);
34607 +/* ---------------------------------------------------------------------- */
34609 +static int au_xattr_get(const struct xattr_handler *handler,
34610 + struct dentry *dentry, struct inode *inode,
34611 + const char *name, void *buffer, size_t size)
34613 + return au_getxattr(dentry, inode, name, buffer, size);
34616 +static int au_xattr_set(const struct xattr_handler *handler,
34617 + struct dentry *dentry, struct inode *inode,
34618 + const char *name, const void *value, size_t size,
34621 + return au_setxattr(dentry, inode, name, value, size, flags);
34624 +static const struct xattr_handler au_xattr_handler = {
34627 + .get = au_xattr_get,
34628 + .set = au_xattr_set
34631 +static const struct xattr_handler *au_xattr_handlers[] = {
34632 +#ifdef CONFIG_FS_POSIX_ACL
34633 + &posix_acl_access_xattr_handler,
34634 + &posix_acl_default_xattr_handler,
34636 + &au_xattr_handler, /* must be last */
34640 +void au_xattr_init(struct super_block *sb)
34642 + sb->s_xattr = au_xattr_handlers;
34644 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34645 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34646 +++ linux/fs/aufs/xino.c 2017-05-06 22:16:52.784886929 +0200
34649 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34651 + * This program, aufs is free software; you can redistribute it and/or modify
34652 + * it under the terms of the GNU General Public License as published by
34653 + * the Free Software Foundation; either version 2 of the License, or
34654 + * (at your option) any later version.
34656 + * This program is distributed in the hope that it will be useful,
34657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34659 + * GNU General Public License for more details.
34661 + * You should have received a copy of the GNU General Public License
34662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34666 + * external inode number translation table and bitmap
34669 +#include <linux/seq_file.h>
34670 +#include <linux/statfs.h>
34673 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34674 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34678 + mm_segment_t oldfs;
34685 + oldfs = get_fs();
34686 + set_fs(KERNEL_DS);
34688 + /* todo: signal_pending? */
34689 + err = func(file, buf.u, size, pos);
34690 + } while (err == -EAGAIN || err == -EINTR);
34693 +#if 0 /* reserved for future use */
34695 + fsnotify_access(file->f_path.dentry);
34701 +/* ---------------------------------------------------------------------- */
34703 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34704 + size_t size, loff_t *pos);
34706 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34707 + size_t size, loff_t *pos)
34710 + mm_segment_t oldfs;
34713 + const char __user *u;
34716 + const int prevent_endless = 10;
34720 + oldfs = get_fs();
34721 + set_fs(KERNEL_DS);
34723 + err = func(file, buf.u, size, pos);
34724 + if (err == -EINTR
34725 + && !au_wkq_test()
34726 + && fatal_signal_pending(current)) {
34728 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34729 + BUG_ON(err == -EINTR);
34730 + oldfs = get_fs();
34731 + set_fs(KERNEL_DS);
34733 + } while (i++ < prevent_endless
34734 + && (err == -EAGAIN || err == -EINTR));
34737 +#if 0 /* reserved for future use */
34739 + fsnotify_modify(file->f_path.dentry);
34745 +struct do_xino_fwrite_args {
34747 + vfs_writef_t func;
34748 + struct file *file;
34754 +static void call_do_xino_fwrite(void *args)
34756 + struct do_xino_fwrite_args *a = args;
34757 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34760 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34761 + size_t size, loff_t *pos)
34765 + struct do_xino_fwrite_args args = {
34775 + * it breaks RLIMIT_FSIZE and normal user's limit,
34776 + * users should care about quota and real 'filesystem full.'
34778 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34779 + if (unlikely(wkq_err))
34785 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34786 + size_t size, loff_t *pos)
34790 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34792 + err = do_xino_fwrite(func, file, buf, size, pos);
34795 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34800 +/* ---------------------------------------------------------------------- */
34803 + * create a new xinofile at the same place/path as @base_file.
34805 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34807 + struct file *file;
34808 + struct dentry *base, *parent;
34809 + struct inode *dir, *delegated;
34810 + struct qstr *name;
34811 + struct path path;
34814 + base = base_file->f_path.dentry;
34815 + parent = base->d_parent; /* dir inode is locked */
34816 + dir = d_inode(parent);
34819 + file = ERR_PTR(-EINVAL);
34820 + name = &base->d_name;
34821 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34822 + if (IS_ERR(path.dentry)) {
34823 + file = (void *)path.dentry;
34824 + pr_err("%pd lookup err %ld\n",
34825 + base, PTR_ERR(path.dentry));
34829 + /* no need to mnt_want_write() since we call dentry_open() later */
34830 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34831 + if (unlikely(err)) {
34832 + file = ERR_PTR(err);
34833 + pr_err("%pd create err %d\n", base, err);
34837 + path.mnt = base_file->f_path.mnt;
34838 + file = vfsub_dentry_open(&path,
34839 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34840 + /* | __FMODE_NONOTIFY */);
34841 + if (IS_ERR(file)) {
34842 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34846 + delegated = NULL;
34847 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34848 + if (unlikely(err == -EWOULDBLOCK)) {
34849 + pr_warn("cannot retry for NFSv4 delegation"
34850 + " for an internal unlink\n");
34853 + if (unlikely(err)) {
34854 + pr_err("%pd unlink err %d\n", base, err);
34859 + /* no one can touch copy_src xino */
34860 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34861 + if (unlikely(err)) {
34862 + pr_err("%pd copy err %d\n", base, err);
34866 + goto out_dput; /* success */
34870 + file = ERR_PTR(err);
34872 + dput(path.dentry);
34877 +struct au_xino_lock_dir {
34878 + struct au_hinode *hdir;
34879 + struct dentry *parent;
34880 + struct inode *dir;
34883 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34884 + struct au_xino_lock_dir *ldir)
34886 + aufs_bindex_t brid, bindex;
34888 + ldir->hdir = NULL;
34890 + brid = au_xino_brid(sb);
34892 + bindex = au_br_index(sb, brid);
34893 + if (bindex >= 0) {
34894 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34895 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34897 + ldir->parent = dget_parent(xino->f_path.dentry);
34898 + ldir->dir = d_inode(ldir->parent);
34899 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34903 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34906 + au_hn_inode_unlock(ldir->hdir);
34908 + inode_unlock(ldir->dir);
34909 + dput(ldir->parent);
34913 +/* ---------------------------------------------------------------------- */
34915 +/* trucate xino files asynchronously */
34917 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34920 + unsigned long jiffy;
34922 + aufs_bindex_t bi, bbot;
34923 + struct kstatfs *st;
34924 + struct au_branch *br;
34925 + struct file *new_xino, *file;
34926 + struct super_block *h_sb;
34927 + struct au_xino_lock_dir ldir;
34930 + st = kmalloc(sizeof(*st), GFP_NOFS);
34931 + if (unlikely(!st))
34935 + bbot = au_sbbot(sb);
34936 + if (unlikely(bindex < 0 || bbot < bindex))
34938 + br = au_sbr(sb, bindex);
34939 + file = br->br_xino.xi_file;
34943 + err = vfs_statfs(&file->f_path, st);
34944 + if (unlikely(err))
34945 + AuErr1("statfs err %d, ignored\n", err);
34947 + blocks = file_inode(file)->i_blocks;
34948 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34949 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34951 + au_xino_lock_dir(sb, file, &ldir);
34952 + /* mnt_want_write() is unnecessary here */
34953 + new_xino = au_xino_create2(file, file);
34954 + au_xino_unlock_dir(&ldir);
34955 + err = PTR_ERR(new_xino);
34956 + if (IS_ERR(new_xino)) {
34957 + pr_err("err %d, ignored\n", err);
34962 + br->br_xino.xi_file = new_xino;
34964 + h_sb = au_br_sb(br);
34965 + for (bi = 0; bi <= bbot; bi++) {
34966 + if (unlikely(bi == bindex))
34968 + br = au_sbr(sb, bi);
34969 + if (au_br_sb(br) != h_sb)
34972 + fput(br->br_xino.xi_file);
34973 + br->br_xino.xi_file = new_xino;
34974 + get_file(new_xino);
34977 + err = vfs_statfs(&new_xino->f_path, st);
34979 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34980 + bindex, (u64)file_inode(new_xino)->i_blocks,
34981 + st->f_bfree, st->f_blocks);
34982 + if (file_inode(new_xino)->i_blocks < blocks)
34983 + au_sbi(sb)->si_xino_jiffy = jiffy;
34985 + AuErr1("statfs err %d, ignored\n", err);
34988 + au_delayed_kfree(st);
34993 +struct xino_do_trunc_args {
34994 + struct super_block *sb;
34995 + struct au_branch *br;
34998 +static void xino_do_trunc(void *_args)
35000 + struct xino_do_trunc_args *args = _args;
35001 + struct super_block *sb;
35002 + struct au_branch *br;
35003 + struct inode *dir;
35005 + aufs_bindex_t bindex;
35009 + dir = d_inode(sb->s_root);
35012 + si_noflush_write_lock(sb);
35013 + ii_read_lock_parent(dir);
35014 + bindex = au_br_index(sb, br->br_id);
35015 + err = au_xino_trunc(sb, bindex);
35016 + ii_read_unlock(dir);
35017 + if (unlikely(err))
35018 + pr_warn("err b%d, (%d)\n", bindex, err);
35019 + atomic_dec(&br->br_xino_running);
35021 + si_write_unlock(sb);
35022 + au_nwt_done(&au_sbi(sb)->si_nowait);
35023 + au_delayed_kfree(args);
35026 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
35029 + struct kstatfs st;
35030 + struct au_sbinfo *sbinfo;
35032 + /* todo: si_xino_expire and the ratio should be customizable */
35033 + sbinfo = au_sbi(sb);
35034 + if (time_before(jiffies,
35035 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
35038 + /* truncation border */
35039 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
35040 + if (unlikely(err)) {
35041 + AuErr1("statfs err %d, ignored\n", err);
35044 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
35050 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
35052 + struct xino_do_trunc_args *args;
35055 + if (!xino_trunc_test(sb, br))
35058 + if (atomic_inc_return(&br->br_xino_running) > 1)
35061 + /* lock and kfree() will be called in trunc_xino() */
35062 + args = kmalloc(sizeof(*args), GFP_NOFS);
35063 + if (unlikely(!args)) {
35064 + AuErr1("no memory\n");
35071 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
35073 + return; /* success */
35075 + pr_err("wkq %d\n", wkq_err);
35077 + au_delayed_kfree(args);
35080 + atomic_dec(&br->br_xino_running);
35083 +/* ---------------------------------------------------------------------- */
35085 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
35086 + ino_t h_ino, ino_t ino)
35092 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
35093 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35096 + pos *= sizeof(ino);
35097 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
35098 + if (sz == sizeof(ino))
35099 + return 0; /* success */
35101 + AuIOErr("write failed (%zd)\n", sz);
35106 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
35107 + * at the position of @h_ino.
35108 + * even if @ino is zero, it is written to the xinofile and means no entry.
35109 + * if the size of the xino file on a specific filesystem exceeds the watermark,
35110 + * try truncating it.
35112 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35116 + unsigned int mnt_flags;
35117 + struct au_branch *br;
35119 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
35120 + || ((loff_t)-1) > 0);
35121 + SiMustAnyLock(sb);
35123 + mnt_flags = au_mntflags(sb);
35124 + if (!au_opt_test(mnt_flags, XINO))
35127 + br = au_sbr(sb, bindex);
35128 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35131 + if (au_opt_test(mnt_flags, TRUNC_XINO)
35132 + && au_test_fs_trunc_xino(au_br_sb(br)))
35133 + xino_try_trunc(sb, br);
35134 + return 0; /* success */
35137 + AuIOErr("write failed (%d)\n", err);
35141 +/* ---------------------------------------------------------------------- */
35143 +/* aufs inode number bitmap */
35145 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
35146 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
35150 + AuDebugOn(bit < 0 || page_bits <= bit);
35151 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
35155 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
35157 + AuDebugOn(ino < AUFS_FIRST_INO);
35158 + ino -= AUFS_FIRST_INO;
35159 + *pindex = ino / page_bits;
35160 + *bit = ino % page_bits;
35163 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
35168 + struct au_sbinfo *sbinfo;
35169 + struct file *xib;
35170 + unsigned long *p;
35172 + sbinfo = au_sbi(sb);
35173 + MtxMustLock(&sbinfo->si_xib_mtx);
35174 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
35175 + || !au_opt_test(sbinfo->si_mntflags, XINO));
35177 + if (pindex == sbinfo->si_xib_last_pindex)
35180 + xib = sbinfo->si_xib;
35181 + p = sbinfo->si_xib_buf;
35182 + pos = sbinfo->si_xib_last_pindex;
35183 + pos *= PAGE_SIZE;
35184 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35185 + if (unlikely(sz != PAGE_SIZE))
35189 + pos *= PAGE_SIZE;
35190 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
35191 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
35193 + memset(p, 0, PAGE_SIZE);
35194 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35196 + if (sz == PAGE_SIZE) {
35197 + sbinfo->si_xib_last_pindex = pindex;
35198 + return 0; /* success */
35202 + AuIOErr1("write failed (%zd)\n", sz);
35209 +/* ---------------------------------------------------------------------- */
35211 +static void au_xib_clear_bit(struct inode *inode)
35214 + unsigned long pindex;
35215 + struct super_block *sb;
35216 + struct au_sbinfo *sbinfo;
35218 + AuDebugOn(inode->i_nlink);
35220 + sb = inode->i_sb;
35221 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35222 + AuDebugOn(page_bits <= bit);
35223 + sbinfo = au_sbi(sb);
35224 + mutex_lock(&sbinfo->si_xib_mtx);
35225 + err = xib_pindex(sb, pindex);
35227 + clear_bit(bit, sbinfo->si_xib_buf);
35228 + sbinfo->si_xib_next_bit = bit;
35230 + mutex_unlock(&sbinfo->si_xib_mtx);
35233 +/* for s_op->delete_inode() */
35234 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35237 + unsigned int mnt_flags;
35238 + aufs_bindex_t bindex, bbot, bi;
35239 + unsigned char try_trunc;
35240 + struct au_iinfo *iinfo;
35241 + struct super_block *sb;
35242 + struct au_hinode *hi;
35243 + struct inode *h_inode;
35244 + struct au_branch *br;
35245 + vfs_writef_t xwrite;
35247 + AuDebugOn(au_is_bad_inode(inode));
35249 + sb = inode->i_sb;
35250 + mnt_flags = au_mntflags(sb);
35251 + if (!au_opt_test(mnt_flags, XINO)
35252 + || inode->i_ino == AUFS_ROOT_INO)
35256 + au_xigen_inc(inode);
35257 + au_xib_clear_bit(inode);
35260 + iinfo = au_ii(inode);
35261 + bindex = iinfo->ii_btop;
35265 + xwrite = au_sbi(sb)->si_xwrite;
35266 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35267 + hi = au_hinode(iinfo, bindex);
35268 + bbot = iinfo->ii_bbot;
35269 + for (; bindex <= bbot; bindex++, hi++) {
35270 + h_inode = hi->hi_inode;
35272 + || (!unlinked && h_inode->i_nlink))
35275 + /* inode may not be revalidated */
35276 + bi = au_br_index(sb, hi->hi_id);
35280 + br = au_sbr(sb, bi);
35281 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35282 + h_inode->i_ino, /*ino*/0);
35283 + if (!err && try_trunc
35284 + && au_test_fs_trunc_xino(au_br_sb(br)))
35285 + xino_try_trunc(sb, br);
35289 +/* get an unused inode number from bitmap */
35290 +ino_t au_xino_new_ino(struct super_block *sb)
35293 + unsigned long *p, pindex, ul, pend;
35294 + struct au_sbinfo *sbinfo;
35295 + struct file *file;
35296 + int free_bit, err;
35298 + if (!au_opt_test(au_mntflags(sb), XINO))
35299 + return iunique(sb, AUFS_FIRST_INO);
35301 + sbinfo = au_sbi(sb);
35302 + mutex_lock(&sbinfo->si_xib_mtx);
35303 + p = sbinfo->si_xib_buf;
35304 + free_bit = sbinfo->si_xib_next_bit;
35305 + if (free_bit < page_bits && !test_bit(free_bit, p))
35306 + goto out; /* success */
35307 + free_bit = find_first_zero_bit(p, page_bits);
35308 + if (free_bit < page_bits)
35309 + goto out; /* success */
35311 + pindex = sbinfo->si_xib_last_pindex;
35312 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35313 + err = xib_pindex(sb, ul);
35314 + if (unlikely(err))
35316 + free_bit = find_first_zero_bit(p, page_bits);
35317 + if (free_bit < page_bits)
35318 + goto out; /* success */
35321 + file = sbinfo->si_xib;
35322 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35323 + for (ul = pindex + 1; ul <= pend; ul++) {
35324 + err = xib_pindex(sb, ul);
35325 + if (unlikely(err))
35327 + free_bit = find_first_zero_bit(p, page_bits);
35328 + if (free_bit < page_bits)
35329 + goto out; /* success */
35334 + set_bit(free_bit, p);
35335 + sbinfo->si_xib_next_bit = free_bit + 1;
35336 + pindex = sbinfo->si_xib_last_pindex;
35337 + mutex_unlock(&sbinfo->si_xib_mtx);
35338 + ino = xib_calc_ino(pindex, free_bit);
35339 + AuDbg("i%lu\n", (unsigned long)ino);
35342 + mutex_unlock(&sbinfo->si_xib_mtx);
35348 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35349 + * at the position of @h_ino.
35350 + * if @ino does not exist and @do_new is true, get new one.
35352 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35358 + struct file *file;
35359 + struct au_sbinfo *sbinfo;
35362 + if (!au_opt_test(au_mntflags(sb), XINO))
35363 + return 0; /* no xino */
35366 + sbinfo = au_sbi(sb);
35368 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35369 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35372 + pos *= sizeof(*ino);
35374 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35375 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35376 + return 0; /* no ino */
35378 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35379 + if (sz == sizeof(*ino))
35380 + return 0; /* success */
35383 + if (unlikely(sz >= 0)) {
35385 + AuIOErr("xino read error (%zd)\n", sz);
35391 +/* ---------------------------------------------------------------------- */
35393 +/* create and set a new xino file */
35395 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35397 + struct file *file;
35398 + struct dentry *h_parent, *d;
35399 + struct inode *h_dir, *inode;
35403 + * at mount-time, and the xino file is the default path,
35404 + * hnotify is disabled so we have no notify events to ignore.
35405 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35407 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35408 + /* | __FMODE_NONOTIFY */,
35409 + S_IRUGO | S_IWUGO);
35410 + if (IS_ERR(file)) {
35412 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35416 + /* keep file count */
35418 + inode = file_inode(file);
35419 + h_parent = dget_parent(file->f_path.dentry);
35420 + h_dir = d_inode(h_parent);
35421 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35422 + /* mnt_want_write() is unnecessary here */
35423 + /* no delegation since it is just created */
35424 + if (inode->i_nlink)
35425 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35427 + inode_unlock(h_dir);
35429 + if (unlikely(err)) {
35431 + pr_err("unlink %s(%d)\n", fname, err);
35436 + d = file->f_path.dentry;
35437 + if (unlikely(sb == d->d_sb)) {
35439 + pr_err("%s must be outside\n", fname);
35442 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35444 + pr_err("xino doesn't support %s(%s)\n",
35445 + fname, au_sbtype(d->d_sb));
35448 + return file; /* success */
35452 + file = ERR_PTR(err);
35457 + * find another branch who is on the same filesystem of the specified
35458 + * branch{@btgt}. search until @bbot.
35460 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35461 + aufs_bindex_t bbot)
35463 + aufs_bindex_t bindex;
35464 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35466 + for (bindex = 0; bindex < btgt; bindex++)
35467 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35469 + for (bindex++; bindex <= bbot; bindex++)
35470 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35475 +/* ---------------------------------------------------------------------- */
35478 + * initialize the xinofile for the specified branch @br
35479 + * at the place/path where @base_file indicates.
35480 + * test whether another branch is on the same filesystem or not,
35481 + * if @do_test is true.
35483 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35484 + struct file *base_file, int do_test)
35488 + aufs_bindex_t bbot, bindex;
35489 + struct au_branch *shared_br, *b;
35490 + struct file *file;
35491 + struct super_block *tgt_sb;
35493 + shared_br = NULL;
35494 + bbot = au_sbbot(sb);
35496 + tgt_sb = au_br_sb(br);
35497 + for (bindex = 0; bindex <= bbot; bindex++) {
35498 + b = au_sbr(sb, bindex);
35499 + if (tgt_sb == au_br_sb(b)) {
35506 + if (!shared_br || !shared_br->br_xino.xi_file) {
35507 + struct au_xino_lock_dir ldir;
35509 + au_xino_lock_dir(sb, base_file, &ldir);
35510 + /* mnt_want_write() is unnecessary here */
35511 + file = au_xino_create2(base_file, NULL);
35512 + au_xino_unlock_dir(&ldir);
35513 + err = PTR_ERR(file);
35514 + if (IS_ERR(file))
35516 + br->br_xino.xi_file = file;
35518 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35519 + get_file(br->br_xino.xi_file);
35522 + ino = AUFS_ROOT_INO;
35523 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35525 + if (unlikely(err)) {
35526 + fput(br->br_xino.xi_file);
35527 + br->br_xino.xi_file = NULL;
35534 +/* ---------------------------------------------------------------------- */
35536 +/* trucate a xino bitmap file */
35539 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35543 + unsigned long pindex;
35544 + loff_t pos, pend;
35545 + struct au_sbinfo *sbinfo;
35546 + vfs_readf_t func;
35548 + unsigned long *p;
35551 + sbinfo = au_sbi(sb);
35552 + MtxMustLock(&sbinfo->si_xib_mtx);
35553 + p = sbinfo->si_xib_buf;
35554 + func = sbinfo->si_xread;
35555 + pend = vfsub_f_size_read(file);
35557 + while (pos < pend) {
35558 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35560 + if (unlikely(sz <= 0))
35564 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35565 + if (unlikely(*ino < AUFS_FIRST_INO))
35568 + xib_calc_bit(*ino, &pindex, &bit);
35569 + AuDebugOn(page_bits <= bit);
35570 + err = xib_pindex(sb, pindex);
35582 +static int xib_restore(struct super_block *sb)
35585 + aufs_bindex_t bindex, bbot;
35589 + page = (void *)__get_free_page(GFP_NOFS);
35590 + if (unlikely(!page))
35594 + bbot = au_sbbot(sb);
35595 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35596 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35597 + err = do_xib_restore
35598 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35600 + AuDbg("b%d\n", bindex);
35601 + au_delayed_free_page((unsigned long)page);
35607 +int au_xib_trunc(struct super_block *sb)
35612 + struct au_xino_lock_dir ldir;
35613 + struct au_sbinfo *sbinfo;
35614 + unsigned long *p;
35615 + struct file *file;
35617 + SiMustWriteLock(sb);
35620 + sbinfo = au_sbi(sb);
35621 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35624 + file = sbinfo->si_xib;
35625 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35628 + au_xino_lock_dir(sb, file, &ldir);
35629 + /* mnt_want_write() is unnecessary here */
35630 + file = au_xino_create2(sbinfo->si_xib, NULL);
35631 + au_xino_unlock_dir(&ldir);
35632 + err = PTR_ERR(file);
35633 + if (IS_ERR(file))
35635 + fput(sbinfo->si_xib);
35636 + sbinfo->si_xib = file;
35638 + p = sbinfo->si_xib_buf;
35639 + memset(p, 0, PAGE_SIZE);
35641 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35642 + if (unlikely(sz != PAGE_SIZE)) {
35644 + AuIOErr("err %d\n", err);
35650 + mutex_lock(&sbinfo->si_xib_mtx);
35651 + /* mnt_want_write() is unnecessary here */
35652 + err = xib_restore(sb);
35653 + mutex_unlock(&sbinfo->si_xib_mtx);
35659 +/* ---------------------------------------------------------------------- */
35662 + * xino mount option handlers
35666 +static void xino_clear_xib(struct super_block *sb)
35668 + struct au_sbinfo *sbinfo;
35670 + SiMustWriteLock(sb);
35672 + sbinfo = au_sbi(sb);
35673 + sbinfo->si_xread = NULL;
35674 + sbinfo->si_xwrite = NULL;
35675 + if (sbinfo->si_xib)
35676 + fput(sbinfo->si_xib);
35677 + sbinfo->si_xib = NULL;
35678 + if (sbinfo->si_xib_buf)
35679 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35680 + sbinfo->si_xib_buf = NULL;
35683 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35687 + struct au_sbinfo *sbinfo;
35688 + struct file *file;
35690 + SiMustWriteLock(sb);
35692 + sbinfo = au_sbi(sb);
35693 + file = au_xino_create2(base, sbinfo->si_xib);
35694 + err = PTR_ERR(file);
35695 + if (IS_ERR(file))
35697 + if (sbinfo->si_xib)
35698 + fput(sbinfo->si_xib);
35699 + sbinfo->si_xib = file;
35700 + sbinfo->si_xread = vfs_readf(file);
35701 + sbinfo->si_xwrite = vfs_writef(file);
35704 + if (!sbinfo->si_xib_buf)
35705 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35706 + if (unlikely(!sbinfo->si_xib_buf))
35709 + sbinfo->si_xib_last_pindex = 0;
35710 + sbinfo->si_xib_next_bit = 0;
35711 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35713 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35714 + PAGE_SIZE, &pos);
35715 + if (unlikely(err != PAGE_SIZE))
35719 + goto out; /* success */
35722 + if (sbinfo->si_xib_buf)
35723 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35724 + sbinfo->si_xib_buf = NULL;
35728 + fput(sbinfo->si_xib);
35729 + sbinfo->si_xib = NULL;
35730 + sbinfo->si_xread = NULL;
35731 + sbinfo->si_xwrite = NULL;
35736 +/* xino for each branch */
35737 +static void xino_clear_br(struct super_block *sb)
35739 + aufs_bindex_t bindex, bbot;
35740 + struct au_branch *br;
35742 + bbot = au_sbbot(sb);
35743 + for (bindex = 0; bindex <= bbot; bindex++) {
35744 + br = au_sbr(sb, bindex);
35745 + if (!br || !br->br_xino.xi_file)
35748 + fput(br->br_xino.xi_file);
35749 + br->br_xino.xi_file = NULL;
35753 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35757 + aufs_bindex_t bindex, bbot, bshared;
35759 + struct file *old, *new;
35761 + struct au_branch *br;
35762 + struct inode *inode;
35763 + vfs_writef_t writef;
35765 + SiMustWriteLock(sb);
35768 + bbot = au_sbbot(sb);
35769 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35770 + if (unlikely(!fpair))
35773 + inode = d_inode(sb->s_root);
35774 + ino = AUFS_ROOT_INO;
35775 + writef = au_sbi(sb)->si_xwrite;
35776 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35777 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35778 + if (bshared >= 0) {
35779 + /* shared xino */
35780 + *p = fpair[bshared];
35781 + get_file(p->new);
35786 + br = au_sbr(sb, bindex);
35787 + p->old = br->br_xino.xi_file;
35788 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35789 + err = PTR_ERR(p->new);
35790 + if (IS_ERR(p->new)) {
35796 + err = au_xino_do_write(writef, p->new,
35797 + au_h_iptr(inode, bindex)->i_ino, ino);
35798 + if (unlikely(err))
35802 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35803 + br = au_sbr(sb, bindex);
35804 + if (br->br_xino.xi_file)
35805 + fput(br->br_xino.xi_file);
35806 + get_file(p->new);
35807 + br->br_xino.xi_file = p->new;
35811 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35816 + au_delayed_kfree(fpair);
35821 +void au_xino_clr(struct super_block *sb)
35823 + struct au_sbinfo *sbinfo;
35825 + au_xigen_clr(sb);
35826 + xino_clear_xib(sb);
35827 + xino_clear_br(sb);
35828 + sbinfo = au_sbi(sb);
35829 + /* lvalue, do not call au_mntflags() */
35830 + au_opt_clr(sbinfo->si_mntflags, XINO);
35833 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35836 + struct dentry *parent, *cur_parent;
35837 + struct qstr *dname, *cur_name;
35838 + struct file *cur_xino;
35839 + struct inode *dir;
35840 + struct au_sbinfo *sbinfo;
35842 + SiMustWriteLock(sb);
35845 + sbinfo = au_sbi(sb);
35846 + parent = dget_parent(xino->file->f_path.dentry);
35849 + dname = &xino->file->f_path.dentry->d_name;
35850 + cur_xino = sbinfo->si_xib;
35852 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35853 + cur_name = &cur_xino->f_path.dentry->d_name;
35854 + skip = (cur_parent == parent
35855 + && au_qstreq(dname, cur_name));
35856 + dput(cur_parent);
35862 + au_opt_set(sbinfo->si_mntflags, XINO);
35863 + dir = d_inode(parent);
35864 + inode_lock_nested(dir, AuLsc_I_PARENT);
35865 + /* mnt_want_write() is unnecessary here */
35866 + err = au_xino_set_xib(sb, xino->file);
35868 + err = au_xigen_set(sb, xino->file);
35870 + err = au_xino_set_br(sb, xino->file);
35871 + inode_unlock(dir);
35873 + goto out; /* success */
35876 + AuIOErr("failed creating xino(%d).\n", err);
35877 + au_xigen_clr(sb);
35878 + xino_clear_xib(sb);
35885 +/* ---------------------------------------------------------------------- */
35888 + * create a xinofile at the default place/path.
35890 +struct file *au_xino_def(struct super_block *sb)
35892 + struct file *file;
35894 + struct au_branch *br;
35895 + struct super_block *h_sb;
35896 + struct path path;
35897 + aufs_bindex_t bbot, bindex, bwr;
35900 + bbot = au_sbbot(sb);
35902 + for (bindex = 0; bindex <= bbot; bindex++) {
35903 + br = au_sbr(sb, bindex);
35904 + if (au_br_writable(br->br_perm)
35905 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35912 + file = ERR_PTR(-ENOMEM);
35913 + page = (void *)__get_free_page(GFP_NOFS);
35914 + if (unlikely(!page))
35916 + path.mnt = au_br_mnt(br);
35917 + path.dentry = au_h_dptr(sb->s_root, bwr);
35918 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35919 + file = (void *)p;
35920 + if (!IS_ERR(p)) {
35921 + strcat(p, "/" AUFS_XINO_FNAME);
35922 + AuDbg("%s\n", p);
35923 + file = au_xino_create(sb, p, /*silent*/0);
35924 + if (!IS_ERR(file))
35925 + au_xino_brid_set(sb, br->br_id);
35927 + au_delayed_free_page((unsigned long)page);
35929 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35930 + if (IS_ERR(file))
35932 + h_sb = file->f_path.dentry->d_sb;
35933 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35934 + pr_err("xino doesn't support %s(%s)\n",
35935 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35937 + file = ERR_PTR(-EINVAL);
35939 + if (!IS_ERR(file))
35940 + au_xino_brid_set(sb, -1);
35947 +/* ---------------------------------------------------------------------- */
35949 +int au_xino_path(struct seq_file *seq, struct file *file)
35953 + err = au_seq_path(seq, &file->f_path);
35954 + if (unlikely(err))
35957 +#define Deleted "\\040(deleted)"
35958 + seq->count -= sizeof(Deleted) - 1;
35959 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35960 + sizeof(Deleted) - 1));
35967 +/* ---------------------------------------------------------------------- */
35969 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
35970 + ino_t h_ino, int idx)
35972 + struct au_xino_file *xino;
35974 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
35975 + xino = &au_sbr(sb, bindex)->br_xino;
35976 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
35978 + spin_lock(&xino->xi_nondir.spin);
35979 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
35980 + xino->xi_nondir.array[idx] = 0;
35981 + spin_unlock(&xino->xi_nondir.spin);
35982 + wake_up_all(&xino->xi_nondir.wqh);
35985 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
35987 + int found, total, i;
35990 + total = xino->xi_nondir.total;
35991 + for (i = 0; i < total; i++) {
35992 + if (xino->xi_nondir.array[i] != h_ino)
36001 +static int au_xinondir_expand(struct au_xino_file *xino)
36006 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
36009 + sz = xino->xi_nondir.total * sizeof(ino_t);
36010 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
36012 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
36013 + /*may_shrink*/0);
36015 + xino->xi_nondir.array = p;
36016 + xino->xi_nondir.total <<= 1;
36017 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
36025 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
36028 + int err, found, empty;
36029 + struct au_xino_file *xino;
36033 + if (!au_opt_test(au_mntflags(sb), XINO))
36034 + goto out; /* no xino */
36036 + xino = &au_sbr(sb, bindex)->br_xino;
36039 + spin_lock(&xino->xi_nondir.spin);
36040 + found = au_xinondir_find(xino, h_ino);
36041 + if (found == -1) {
36042 + empty = au_xinondir_find(xino, /*h_ino*/0);
36043 + if (empty == -1) {
36044 + empty = xino->xi_nondir.total;
36045 + err = au_xinondir_expand(xino);
36046 + if (unlikely(err))
36049 + xino->xi_nondir.array[empty] = h_ino;
36052 + spin_unlock(&xino->xi_nondir.spin);
36053 + wait_event(xino->xi_nondir.wqh,
36054 + xino->xi_nondir.array[found] != h_ino);
36059 + spin_unlock(&xino->xi_nondir.spin);
36063 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
36064 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
36065 +++ linux/include/uapi/linux/aufs_type.h 2017-05-06 22:16:52.784886929 +0200
36068 + * Copyright (C) 2005-2017 Junjiro R. Okajima
36070 + * This program, aufs is free software; you can redistribute it and/or modify
36071 + * it under the terms of the GNU General Public License as published by
36072 + * the Free Software Foundation; either version 2 of the License, or
36073 + * (at your option) any later version.
36075 + * This program is distributed in the hope that it will be useful,
36076 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36077 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36078 + * GNU General Public License for more details.
36080 + * You should have received a copy of the GNU General Public License
36081 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36084 +#ifndef __AUFS_TYPE_H__
36085 +#define __AUFS_TYPE_H__
36087 +#define AUFS_NAME "aufs"
36091 + * define it before including all other headers.
36092 + * sched.h may use pr_* macros before defining "current", so define the
36093 + * no-current version first, and re-define later.
36095 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
36096 +#include <linux/sched.h>
36098 +#define pr_fmt(fmt) \
36099 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
36100 + (int)sizeof(current->comm), current->comm, current->pid
36102 +#include <stdint.h>
36103 +#include <sys/types.h>
36104 +#endif /* __KERNEL__ */
36106 +#include <linux/limits.h>
36108 +#define AUFS_VERSION "4.x-rcN-20170410"
36110 +/* todo? move this to linux-2.6.19/include/magic.h */
36111 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
36113 +/* ---------------------------------------------------------------------- */
36115 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
36116 +typedef int8_t aufs_bindex_t;
36117 +#define AUFS_BRANCH_MAX 127
36119 +typedef int16_t aufs_bindex_t;
36120 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
36121 +#define AUFS_BRANCH_MAX 511
36122 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
36123 +#define AUFS_BRANCH_MAX 1023
36124 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
36125 +#define AUFS_BRANCH_MAX 32767
36130 +#ifndef AUFS_BRANCH_MAX
36131 +#error unknown CONFIG_AUFS_BRANCH_MAX value
36133 +#endif /* __KERNEL__ */
36135 +/* ---------------------------------------------------------------------- */
36137 +#define AUFS_FSTYPE AUFS_NAME
36139 +#define AUFS_ROOT_INO 2
36140 +#define AUFS_FIRST_INO 11
36142 +#define AUFS_WH_PFX ".wh."
36143 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
36144 +#define AUFS_WH_TMP_LEN 4
36145 +/* a limit for rmdir/rename a dir and copyup */
36146 +#define AUFS_MAX_NAMELEN (NAME_MAX \
36147 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
36149 + - AUFS_WH_TMP_LEN) /* hex */
36150 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
36151 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
36152 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
36153 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
36154 +#define AUFS_DIRWH_DEF 3
36155 +#define AUFS_RDCACHE_DEF 10 /* seconds */
36156 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
36157 +#define AUFS_RDBLK_DEF 512 /* bytes */
36158 +#define AUFS_RDHASH_DEF 32
36159 +#define AUFS_WKQ_NAME AUFS_NAME "d"
36160 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
36161 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
36162 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
36163 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
36165 +/* pseudo-link maintenace under /proc */
36166 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
36167 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
36168 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
36170 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
36171 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
36173 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
36174 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
36175 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
36177 +/* doubly whiteouted */
36178 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
36179 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
36180 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
36182 +/* branch permissions and attributes */
36183 +#define AUFS_BRPERM_RW "rw"
36184 +#define AUFS_BRPERM_RO "ro"
36185 +#define AUFS_BRPERM_RR "rr"
36186 +#define AUFS_BRATTR_COO_REG "coo_reg"
36187 +#define AUFS_BRATTR_COO_ALL "coo_all"
36188 +#define AUFS_BRATTR_FHSM "fhsm"
36189 +#define AUFS_BRATTR_UNPIN "unpin"
36190 +#define AUFS_BRATTR_ICEX "icex"
36191 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
36192 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
36193 +#define AUFS_BRATTR_ICEX_TR "icextr"
36194 +#define AUFS_BRATTR_ICEX_USR "icexusr"
36195 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
36196 +#define AUFS_BRRATTR_WH "wh"
36197 +#define AUFS_BRWATTR_NLWH "nolwh"
36198 +#define AUFS_BRWATTR_MOO "moo"
36200 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
36201 +#define AuBrPerm_RO (1 << 1) /* readonly */
36202 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
36203 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
36205 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
36206 +#define AuBrAttr_COO_ALL (1 << 4)
36207 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
36209 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
36210 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
36211 + branch. meaningless since
36212 + linux-3.18-rc1 */
36214 +/* ignore error in copying XATTR */
36215 +#define AuBrAttr_ICEX_SEC (1 << 7)
36216 +#define AuBrAttr_ICEX_SYS (1 << 8)
36217 +#define AuBrAttr_ICEX_TR (1 << 9)
36218 +#define AuBrAttr_ICEX_USR (1 << 10)
36219 +#define AuBrAttr_ICEX_OTH (1 << 11)
36220 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
36221 + | AuBrAttr_ICEX_SYS \
36222 + | AuBrAttr_ICEX_TR \
36223 + | AuBrAttr_ICEX_USR \
36224 + | AuBrAttr_ICEX_OTH)
36226 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
36227 +#define AuBrRAttr_Mask AuBrRAttr_WH
36229 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
36230 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
36231 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
36233 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
36235 +/* #warning test userspace */
36237 +#ifndef CONFIG_AUFS_FHSM
36238 +#undef AuBrAttr_FHSM
36239 +#define AuBrAttr_FHSM 0
36241 +#ifndef CONFIG_AUFS_XATTR
36242 +#undef AuBrAttr_ICEX
36243 +#define AuBrAttr_ICEX 0
36244 +#undef AuBrAttr_ICEX_SEC
36245 +#define AuBrAttr_ICEX_SEC 0
36246 +#undef AuBrAttr_ICEX_SYS
36247 +#define AuBrAttr_ICEX_SYS 0
36248 +#undef AuBrAttr_ICEX_TR
36249 +#define AuBrAttr_ICEX_TR 0
36250 +#undef AuBrAttr_ICEX_USR
36251 +#define AuBrAttr_ICEX_USR 0
36252 +#undef AuBrAttr_ICEX_OTH
36253 +#define AuBrAttr_ICEX_OTH 0
36257 +/* the longest combination */
36258 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
36259 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
36260 + "+" AUFS_BRATTR_COO_REG \
36261 + "+" AUFS_BRATTR_FHSM \
36262 + "+" AUFS_BRATTR_UNPIN \
36263 + "+" AUFS_BRATTR_ICEX_SEC \
36264 + "+" AUFS_BRATTR_ICEX_SYS \
36265 + "+" AUFS_BRATTR_ICEX_USR \
36266 + "+" AUFS_BRATTR_ICEX_OTH \
36267 + "+" AUFS_BRWATTR_NLWH)
36270 + char a[AuBrPermStrSz];
36271 +} au_br_perm_str_t;
36273 +static inline int au_br_writable(int brperm)
36275 + return brperm & AuBrPerm_RW;
36278 +static inline int au_br_whable(int brperm)
36280 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
36283 +static inline int au_br_wh_linkable(int brperm)
36285 + return !(brperm & AuBrWAttr_NoLinkWH);
36288 +static inline int au_br_cmoo(int brperm)
36290 + return brperm & AuBrAttr_CMOO_Mask;
36293 +static inline int au_br_fhsm(int brperm)
36295 + return brperm & AuBrAttr_FHSM;
36298 +/* ---------------------------------------------------------------------- */
36302 + /* readdir in userspace */
36306 + AuCtl_WBR_FD, /* pathconf wrapper */
36307 + AuCtl_IBUSY, /* busy inode */
36308 + AuCtl_MVDOWN, /* move-down */
36309 + AuCtl_BR, /* info about branches */
36310 + AuCtl_FHSM_FD /* connection for fhsm */
36313 +/* borrowed from linux/include/linux/kernel.h */
36315 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36316 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36319 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36321 +#define __aligned(x) __attribute__((aligned(x)))
36326 +#define __packed __attribute__((packed))
36330 +struct au_rdu_cookie {
36335 + uint32_t generation;
36338 +struct au_rdu_ent {
36347 +static inline int au_rdu_len(int nlen)
36349 + /* include the terminating NULL */
36350 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36351 + sizeof(uint64_t));
36354 +union au_rdu_ent_ul {
36355 + struct au_rdu_ent __user *e;
36367 + uint64_t sz; /* AuCtl_RDU */
36368 + uint64_t nent; /* AuCtl_RDU_INO */
36370 + union au_rdu_ent_ul ent;
36371 + uint16_t verify[AufsCtlRduV_End];
36373 + /* input/output */
36377 + union au_rdu_ent_ul tail;
36378 + /* number of entries which were added in a single call */
36383 + struct au_rdu_cookie cookie;
36386 +/* ---------------------------------------------------------------------- */
36388 +struct aufs_wbr_fd {
36393 +/* ---------------------------------------------------------------------- */
36395 +struct aufs_ibusy {
36396 + uint64_t ino, h_ino;
36400 +/* ---------------------------------------------------------------------- */
36402 +/* error code for move-down */
36403 +/* the actual message strings are implemented in aufs-util.git */
36405 + EAU_MVDOWN_OPAQUE = 1,
36406 + EAU_MVDOWN_WHITEOUT,
36407 + EAU_MVDOWN_UPPER,
36408 + EAU_MVDOWN_BOTTOM,
36409 + EAU_MVDOWN_NOUPPER,
36410 + EAU_MVDOWN_NOLOWERBR,
36414 +/* flags for move-down */
36415 +#define AUFS_MVDOWN_DMSG 1
36416 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36417 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36418 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36419 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36420 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36421 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36422 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36423 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36424 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36425 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36426 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36427 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36429 +/* index for move-down */
36431 + AUFS_MVDOWN_UPPER,
36432 + AUFS_MVDOWN_LOWER,
36433 + AUFS_MVDOWN_NARRAY
36437 + * additional info of move-down
36438 + * number of free blocks and inodes.
36439 + * subset of struct kstatfs, but smaller and always 64bit.
36441 +struct aufs_stfs {
36442 + uint64_t f_blocks;
36443 + uint64_t f_bavail;
36444 + uint64_t f_files;
36445 + uint64_t f_ffree;
36448 +struct aufs_stbr {
36449 + int16_t brid; /* optional input */
36450 + int16_t bindex; /* output */
36451 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36454 +struct aufs_mvdown {
36455 + uint32_t flags; /* input/output */
36456 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36457 + int8_t au_errno; /* output */
36460 +/* ---------------------------------------------------------------------- */
36462 +union aufs_brinfo {
36463 + /* PATH_MAX may differ between kernel-space and user-space */
36464 + char _spacer[4096];
36472 +/* ---------------------------------------------------------------------- */
36474 +#define AuCtlType 'A'
36475 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36476 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36477 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36478 + struct aufs_wbr_fd)
36479 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36480 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36481 + struct aufs_mvdown)
36482 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36483 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36485 +#endif /* __AUFS_TYPE_H__ */
36486 aufs4.x-rcN loopback patch
36488 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36489 index cf39138..29b33b2 100644
36490 --- a/drivers/block/loop.c
36491 +++ b/drivers/block/loop.c
36492 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36495 struct switch_request {
36496 - struct file *file;
36497 + struct file *file, *virt_file;
36498 struct completion wait;
36501 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36502 mapping = file->f_mapping;
36503 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36504 lo->lo_backing_file = file;
36505 + lo->lo_backing_virt_file = p->virt_file;
36506 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36507 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36508 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36509 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36510 * First it needs to flush existing IO, it does this by sending a magic
36511 * BIO down the pipe. The completion of this BIO does the actual switch.
36513 -static int loop_switch(struct loop_device *lo, struct file *file)
36514 +static int loop_switch(struct loop_device *lo, struct file *file,
36515 + struct file *virt_file)
36517 struct switch_request w;
36520 + w.virt_file = virt_file;
36522 /* freeze queue and wait for completion of scheduled requests */
36523 blk_mq_freeze_queue(lo->lo_queue);
36524 @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
36526 static int loop_flush(struct loop_device *lo)
36528 - return loop_switch(lo, NULL);
36529 + return loop_switch(lo, NULL, NULL);
36532 +static struct file *loop_real_file(struct file *file)
36534 + struct file *f = NULL;
36536 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36537 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36541 static void loop_reread_partitions(struct loop_device *lo,
36542 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36545 struct file *file, *old_file;
36546 + struct file *f, *virt_file = NULL, *old_virt_file;
36547 struct inode *inode;
36550 @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36554 + f = loop_real_file(file);
36556 + virt_file = file;
36561 inode = file->f_mapping->host;
36562 old_file = lo->lo_backing_file;
36563 + old_virt_file = lo->lo_backing_virt_file;
36567 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36570 /* and ... switch */
36571 - error = loop_switch(lo, file);
36572 + error = loop_switch(lo, file, virt_file);
36577 + if (old_virt_file)
36578 + fput(old_virt_file);
36579 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36580 loop_reread_partitions(lo, bdev);
36590 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36591 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36592 struct block_device *bdev, unsigned int arg)
36594 - struct file *file, *f;
36595 + struct file *file, *f, *virt_file = NULL;
36596 struct inode *inode;
36597 struct address_space *mapping;
36598 unsigned lo_blocksize;
36599 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36603 + f = loop_real_file(file);
36605 + virt_file = file;
36611 if (lo->lo_state != Lo_unbound)
36612 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36613 lo->lo_device = bdev;
36614 lo->lo_flags = lo_flags;
36615 lo->lo_backing_file = file;
36616 + lo->lo_backing_virt_file = virt_file;
36617 lo->transfer = NULL;
36619 lo->lo_sizelimit = 0;
36620 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36627 /* This is safe: open() is still holding a reference. */
36628 module_put(THIS_MODULE);
36629 @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36630 static int loop_clr_fd(struct loop_device *lo)
36632 struct file *filp = lo->lo_backing_file;
36633 + struct file *virt_filp = lo->lo_backing_virt_file;
36634 gfp_t gfp = lo->old_gfp_mask;
36635 struct block_device *bdev = lo->lo_device;
36637 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
36638 spin_lock_irq(&lo->lo_lock);
36639 lo->lo_state = Lo_rundown;
36640 lo->lo_backing_file = NULL;
36641 + lo->lo_backing_virt_file = NULL;
36642 spin_unlock_irq(&lo->lo_lock);
36644 loop_release_xfer(lo);
36645 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
36646 * bd_mutex which is usually taken before lo_ctl_mutex.
36654 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36655 index fb2237c..c3888c5 100644
36656 --- a/drivers/block/loop.h
36657 +++ b/drivers/block/loop.h
36658 @@ -46,7 +46,7 @@ struct loop_device {
36659 int (*ioctl)(struct loop_device *, int cmd,
36660 unsigned long arg);
36662 - struct file * lo_backing_file;
36663 + struct file * lo_backing_file, *lo_backing_virt_file;
36664 struct block_device *lo_device;
36665 unsigned lo_blocksize;
36667 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36668 index 7e03507..f31af1d 100644
36669 --- a/fs/aufs/f_op.c
36670 +++ b/fs/aufs/f_op.c
36671 @@ -360,7 +360,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36672 if (IS_ERR(h_file))
36675 - if (au_test_loopback_kthread()) {
36676 + if (0 && au_test_loopback_kthread()) {
36677 au_warn_loopback(h_file->f_path.dentry->d_sb);
36678 if (file->f_mapping != h_file->f_mapping) {
36679 file->f_mapping = h_file->f_mapping;
36680 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36681 index 61e9197..9910bea 100644
36682 --- a/fs/aufs/loop.c
36683 +++ b/fs/aufs/loop.c
36684 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36685 symbol_put(loop_backing_file);
36686 au_delayed_kfree(au_warn_loopback_array);
36689 +/* ---------------------------------------------------------------------- */
36691 +/* support the loopback block device insude aufs */
36693 +struct file *aufs_real_loop(struct file *file)
36697 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36698 + fi_read_lock(file);
36699 + f = au_hf_top(file);
36700 + fi_read_unlock(file);
36704 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36705 index e2df495..36e5052 100644
36706 --- a/fs/aufs/loop.h
36707 +++ b/fs/aufs/loop.h
36708 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36710 int au_loopback_init(void);
36711 void au_loopback_fin(void);
36713 +struct file *aufs_real_loop(struct file *file);
36715 +AuStub(struct file *, loop_backing_file, return NULL)
36717 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36718 struct dentry *h_adding)
36719 AuStubInt0(au_test_loopback_kthread, void)
36720 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36722 AuStubInt0(au_loopback_init, void)
36723 AuStubVoid(au_loopback_fin, void)
36725 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36726 #endif /* BLK_DEV_LOOP */
36728 #endif /* __KERNEL__ */
36729 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36730 index 0e9bbc3..b90d52f 100644
36731 --- a/fs/aufs/super.c
36732 +++ b/fs/aufs/super.c
36733 @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = {
36734 .statfs = aufs_statfs,
36735 .put_super = aufs_put_super,
36736 .sync_fs = aufs_sync_fs,
36737 - .remount_fs = aufs_remount_fs
36738 + .remount_fs = aufs_remount_fs,
36739 +#ifdef CONFIG_AUFS_BDEV_LOOP
36740 + .real_loop = aufs_real_loop
36744 /* ---------------------------------------------------------------------- */
36745 diff --git a/include/linux/fs.h b/include/linux/fs.h
36746 index 3668627..2cbc8fe 100644
36747 --- a/include/linux/fs.h
36748 +++ b/include/linux/fs.h
36749 @@ -1810,6 +1810,10 @@ struct super_operations {
36750 struct shrink_control *);
36751 long (*free_cached_objects)(struct super_block *,
36752 struct shrink_control *);
36753 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36755 + struct file *(*real_loop)(struct file *);