1 aufs4.11.7+ 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 f8d9fed..902305e 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.11.7+ base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 38d3e4e..c2b31bf 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 f77eb22..eba4e7e 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 7415630..433e314 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.11.7+ 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 f401682..79ea96a 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 @@ -1632,7 +1635,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 cec423b..b6b2f901 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 4f7151d..ebe8415 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 157c047..0cf15d2 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 cde1262..72ca169 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 @@ -895,7 +895,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 @@ -1745,8 +1745,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 @@ -2571,7 +2571,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 @@ -2590,7 +2590,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 @@ -2744,7 +2744,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 @@ -2819,10 +2819,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 @@ -3113,7 +3130,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..1ef053b
601 + * Mainly for aufs which mmap(2) different file and wants to print different
602 + * path 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-2017 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, %pD2\n", func, line, func2, f);
625 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
628 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
630 + prfile_trace(f, pr, func, line, __func__);
631 + file_update_time(f);
633 + file_update_time(pr);
636 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
639 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
641 + prfile_trace(f, pr, func, line, __func__);
642 + return (f && pr) ? pr : f;
645 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
647 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
649 + prfile_trace(f, pr, func, line, __func__);
655 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
657 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
659 + prfile_trace(f, pr, func, line, __func__);
666 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
669 + struct file *f = region->vm_file, *pr = region->vm_prfile;
671 + prfile_trace(f, pr, func, line, __func__);
672 + return (f && pr) ? pr : f;
675 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
677 + struct file *f = region->vm_file, *pr = region->vm_prfile;
679 + prfile_trace(f, pr, func, line, __func__);
684 +#endif /* !CONFIG_MMU */
685 aufs4.11.7+ standalone patch
687 diff --git a/fs/dcache.c b/fs/dcache.c
688 index 8ca5f09..b1ff5be 100644
691 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
695 +EXPORT_SYMBOL_GPL(d_walk);
698 struct vfsmount *mnt;
699 @@ -2864,6 +2865,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
701 write_sequnlock(&rename_lock);
703 +EXPORT_SYMBOL_GPL(d_exchange);
706 * d_ancestor - search for an ancestor
707 diff --git a/fs/exec.c b/fs/exec.c
708 index 65145a3..8d35776 100644
711 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
712 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
713 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
715 +EXPORT_SYMBOL_GPL(path_noexec);
719 diff --git a/fs/fcntl.c b/fs/fcntl.c
720 index f5f4f94..c671660 100644
723 @@ -83,6 +83,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
727 +EXPORT_SYMBOL_GPL(setfl);
729 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
731 diff --git a/fs/file_table.c b/fs/file_table.c
732 index 954d510..4fb5b10 100644
733 --- a/fs/file_table.c
734 +++ b/fs/file_table.c
735 @@ -148,6 +148,7 @@ struct file *get_empty_filp(void)
737 return ERR_PTR(-ENFILE);
739 +EXPORT_SYMBOL_GPL(get_empty_filp);
742 * alloc_file - allocate and initialize a 'struct file'
743 @@ -259,6 +260,7 @@ void flush_delayed_fput(void)
747 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
749 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
751 @@ -301,6 +303,7 @@ void __fput_sync(struct file *file)
755 +EXPORT_SYMBOL_GPL(__fput_sync);
757 void put_filp(struct file *file)
759 @@ -309,6 +312,7 @@ void put_filp(struct file *file)
763 +EXPORT_SYMBOL_GPL(put_filp);
765 void __init files_init(void)
767 diff --git a/fs/inode.c b/fs/inode.c
768 index 9a9ba3a..a3a18d8 100644
771 @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
773 return update_time(inode, time, flags);
775 +EXPORT_SYMBOL_GPL(update_time);
778 * touch_atime - update the access time
779 diff --git a/fs/namespace.c b/fs/namespace.c
780 index cc1375ef..9b4c67c 100644
783 @@ -465,6 +465,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
784 mnt_dec_writers(real_mount(mnt));
787 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
790 * mnt_drop_write - give up write access to a mount
791 @@ -1884,6 +1885,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
795 +EXPORT_SYMBOL_GPL(iterate_mounts);
797 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
799 diff --git a/fs/notify/group.c b/fs/notify/group.c
800 index fbe3cbe..bdfc61e 100644
801 --- a/fs/notify/group.c
802 +++ b/fs/notify/group.c
804 #include <linux/srcu.h>
805 #include <linux/rculist.h>
806 #include <linux/wait.h>
807 +#include <linux/module.h>
809 #include <linux/fsnotify_backend.h>
810 #include "fsnotify.h"
811 @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
813 atomic_inc(&group->refcnt);
815 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
818 * Drop a reference to a group. Free it if it's through.
819 @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
820 if (atomic_dec_and_test(&group->refcnt))
821 fsnotify_final_destroy_group(group);
823 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
826 * Create a new fsnotify_group and hold a reference for the group returned.
827 @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
831 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
833 int fsnotify_fasync(int fd, struct file *file, int on)
835 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
836 index 6043306..fdb50e4 100644
837 --- a/fs/notify/mark.c
838 +++ b/fs/notify/mark.c
839 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
840 mark->free_mark(mark);
843 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
845 /* Calculate mask of events for a list of marks */
846 u32 fsnotify_recalc_mask(struct hlist_head *head)
847 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
848 mutex_unlock(&group->mark_mutex);
849 fsnotify_free_mark(mark);
851 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
853 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
855 @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
859 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
861 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
862 struct inode *inode, struct vfsmount *mnt, int allow_dups)
863 @@ -521,6 +524,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
864 atomic_set(&mark->refcnt, 1);
865 mark->free_mark = free_mark;
867 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
870 * Destroy all marks in destroy_list, waits for SRCU period to finish before
871 diff --git a/fs/open.c b/fs/open.c
872 index 949cef2..9a892fb8 100644
875 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
876 inode_unlock(dentry->d_inode);
879 +EXPORT_SYMBOL_GPL(do_truncate);
881 long vfs_truncate(const struct path *path, loff_t length)
883 @@ -693,6 +694,7 @@ int open_check_o_direct(struct file *f)
887 +EXPORT_SYMBOL_GPL(open_check_o_direct);
889 static int do_dentry_open(struct file *f,
891 diff --git a/fs/read_write.c b/fs/read_write.c
892 index eba4e7e..ec9e88a 100644
893 --- a/fs/read_write.c
894 +++ b/fs/read_write.c
895 @@ -523,6 +523,7 @@ vfs_readf_t vfs_readf(struct file *file)
896 return new_sync_read;
897 return ERR_PTR(-ENOSYS);
899 +EXPORT_SYMBOL_GPL(vfs_readf);
901 vfs_writef_t vfs_writef(struct file *file)
903 @@ -534,6 +535,7 @@ vfs_writef_t vfs_writef(struct file *file)
904 return new_sync_write;
905 return ERR_PTR(-ENOSYS);
907 +EXPORT_SYMBOL_GPL(vfs_writef);
909 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
911 diff --git a/fs/splice.c b/fs/splice.c
912 index 46c87af..0efa652 100644
915 @@ -872,6 +872,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
917 return splice_write(pipe, out, ppos, len, flags);
919 +EXPORT_SYMBOL_GPL(do_splice_from);
922 * Attempt to initiate a splice from a file to a pipe.
923 @@ -901,6 +902,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
925 return splice_read(in, ppos, pipe, len, flags);
927 +EXPORT_SYMBOL_GPL(do_splice_to);
930 * splice_direct_to_actor - splices data directly between two non-pipes
931 diff --git a/fs/sync.c b/fs/sync.c
932 index abf6a5d..c86fe9c 100644
935 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
936 sb->s_op->sync_fs(sb, wait);
937 return __sync_blockdev(sb->s_bdev, wait);
939 +EXPORT_SYMBOL_GPL(__sync_filesystem);
942 * Write out and wait upon all dirty data associated with this
943 diff --git a/fs/xattr.c b/fs/xattr.c
944 index 94f49a0..243f57e 100644
947 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
948 *xattr_value = value;
951 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
954 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
955 diff --git a/kernel/task_work.c b/kernel/task_work.c
956 index d513051..e056d54 100644
957 --- a/kernel/task_work.c
958 +++ b/kernel/task_work.c
959 @@ -119,3 +119,4 @@ void task_work_run(void)
963 +EXPORT_SYMBOL_GPL(task_work_run);
964 diff --git a/security/commoncap.c b/security/commoncap.c
965 index 78b3783..c8b3e88 100644
966 --- a/security/commoncap.c
967 +++ b/security/commoncap.c
968 @@ -1062,12 +1062,14 @@ int cap_mmap_addr(unsigned long addr)
972 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
974 int cap_mmap_file(struct file *file, unsigned long reqprot,
975 unsigned long prot, unsigned long flags)
979 +EXPORT_SYMBOL_GPL(cap_mmap_file);
981 #ifdef CONFIG_SECURITY
983 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
984 index 03c1652..f88c84b 100644
985 --- a/security/device_cgroup.c
986 +++ b/security/device_cgroup.c
988 #include <linux/device_cgroup.h>
989 #include <linux/cgroup.h>
990 #include <linux/ctype.h>
991 +#include <linux/export.h>
992 #include <linux/list.h>
993 #include <linux/uaccess.h>
994 #include <linux/seq_file.h>
995 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
996 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
999 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
1001 int devcgroup_inode_mknod(int mode, dev_t dev)
1003 diff --git a/security/security.c b/security/security.c
1004 index d0e07f2..5e323b0 100644
1005 --- a/security/security.c
1006 +++ b/security/security.c
1007 @@ -481,6 +481,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1009 return call_int_hook(path_rmdir, 0, dir, dentry);
1011 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1013 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1015 @@ -497,6 +498,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1017 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1019 +EXPORT_SYMBOL_GPL(security_path_symlink);
1021 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1022 struct dentry *new_dentry)
1023 @@ -505,6 +507,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1025 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1027 +EXPORT_SYMBOL_GPL(security_path_link);
1029 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1030 const struct path *new_dir, struct dentry *new_dentry,
1031 @@ -532,6 +535,7 @@ int security_path_truncate(const struct path *path)
1033 return call_int_hook(path_truncate, 0, path);
1035 +EXPORT_SYMBOL_GPL(security_path_truncate);
1037 int security_path_chmod(const struct path *path, umode_t mode)
1039 @@ -539,6 +543,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1041 return call_int_hook(path_chmod, 0, path, mode);
1043 +EXPORT_SYMBOL_GPL(security_path_chmod);
1045 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1047 @@ -546,6 +551,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1049 return call_int_hook(path_chown, 0, path, uid, gid);
1051 +EXPORT_SYMBOL_GPL(security_path_chown);
1053 int security_path_chroot(const struct path *path)
1055 @@ -631,6 +637,7 @@ int security_inode_readlink(struct dentry *dentry)
1057 return call_int_hook(inode_readlink, 0, dentry);
1059 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1061 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1063 @@ -646,6 +653,7 @@ int security_inode_permission(struct inode *inode, int mask)
1065 return call_int_hook(inode_permission, 0, inode, mask);
1067 +EXPORT_SYMBOL_GPL(security_inode_permission);
1069 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1071 @@ -817,6 +825,7 @@ int security_file_permission(struct file *file, int mask)
1073 return fsnotify_perm(file, mask);
1075 +EXPORT_SYMBOL_GPL(security_file_permission);
1077 int security_file_alloc(struct file *file)
1079 @@ -876,6 +885,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1081 return ima_file_mmap(file, prot);
1083 +EXPORT_SYMBOL_GPL(security_mmap_file);
1085 int security_mmap_addr(unsigned long addr)
1087 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1088 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1089 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-07-29 12:14:25.893041746 +0200
1091 +What: /debug/aufs/si_<id>/
1093 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1095 + Under /debug/aufs, a directory named si_<id> is created
1096 + per aufs mount, where <id> is a unique id generated
1099 +What: /debug/aufs/si_<id>/plink
1101 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1103 + It has three lines and shows the information about the
1104 + pseudo-link. The first line is a single number
1105 + representing a number of buckets. The second line is a
1106 + number of pseudo-links per buckets (separated by a
1107 + blank). The last line is a single number representing a
1108 + total number of psedo-links.
1109 + When the aufs mount option 'noplink' is specified, it
1110 + will show "1\n0\n0\n".
1112 +What: /debug/aufs/si_<id>/xib
1114 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1116 + It shows the consumed blocks by xib (External Inode Number
1117 + Bitmap), its block size and file size.
1118 + When the aufs mount option 'noxino' is specified, it
1119 + will be empty. About XINO files, see the aufs manual.
1121 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1123 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1125 + It shows the consumed blocks by xino (External Inode Number
1126 + Translation Table), its link count, block size and file
1128 + When the aufs mount option 'noxino' is specified, it
1129 + will be empty. About XINO files, see the aufs manual.
1131 +What: /debug/aufs/si_<id>/xigen
1133 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1135 + It shows the consumed blocks by xigen (External Inode
1136 + Generation Table), its block size and file size.
1137 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1139 + When the aufs mount option 'noxino' is specified, it
1140 + will be empty. About XINO files, see the aufs manual.
1141 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1142 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1143 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1145 +What: /sys/fs/aufs/si_<id>/
1147 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1149 + Under /sys/fs/aufs, a directory named si_<id> is created
1150 + per aufs mount, where <id> is a unique id generated
1153 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1155 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1157 + It shows the abolute path of a member directory (which
1158 + is called branch) in aufs, and its permission.
1160 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1162 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1164 + It shows the id of a member directory (which is called
1167 +What: /sys/fs/aufs/si_<id>/xi_path
1169 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1171 + It shows the abolute path of XINO (External Inode Number
1172 + Bitmap, Translation Table and Generation Table) file
1173 + even if it is the default path.
1174 + When the aufs mount option 'noxino' is specified, it
1175 + will be empty. About XINO files, see the aufs manual.
1176 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1177 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1178 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-07-29 12:14:25.893041746 +0200
1181 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1183 +# This program is free software; you can redistribute it and/or modify
1184 +# it under the terms of the GNU General Public License as published by
1185 +# the Free Software Foundation; either version 2 of the License, or
1186 +# (at your option) any later version.
1188 +# This program is distributed in the hope that it will be useful,
1189 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1190 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1191 +# GNU General Public License for more details.
1193 +# You should have received a copy of the GNU General Public License
1194 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1197 +----------------------------------------
1199 +aufs [ei ju: ef es] | [a u f s]
1200 +1. abbrev. for "advanced multi-layered unification filesystem".
1201 +2. abbrev. for "another unionfs".
1202 +3. abbrev. for "auf das" in German which means "on the" in English.
1203 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1204 + But "Filesystem aufs Filesystem" is hard to understand.
1205 +4. abbrev. for "African Urban Fashion Show".
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-07-29 12:14:25.893041746 +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-07-29 12:14:25.893041746 +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-07-29 12:14:25.893041746 +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-07-29 12:14:25.893041746 +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-07-29 12:14:25.893041746 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.893041746 +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-07-29 12:14:25.896375188 +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-07-29 12:14:25.896375188 +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 + 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 + 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);
2972 + * frees all branches
2974 +void au_br_free(struct au_sbinfo *sbinfo)
2976 + aufs_bindex_t bmax;
2977 + struct au_branch **br;
2979 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2981 + bmax = sbinfo->si_bbot + 1;
2982 + br = sbinfo->si_branch;
2984 + au_br_do_free(*br++);
2988 + * find the index of a branch which is specified by @br_id.
2990 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2992 + aufs_bindex_t bindex, bbot;
2994 + bbot = au_sbbot(sb);
2995 + for (bindex = 0; bindex <= bbot; bindex++)
2996 + if (au_sbr_id(sb, bindex) == br_id)
3001 +/* ---------------------------------------------------------------------- */
3007 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3008 + struct dentry *h_root)
3010 + if (unlikely(h_adding == h_root
3011 + || au_test_loopback_overlap(sb, h_adding)))
3013 + if (h_adding->d_sb != h_root->d_sb)
3015 + return au_test_subdir(h_adding, h_root)
3016 + || au_test_subdir(h_root, h_adding);
3020 + * returns a newly allocated branch. @new_nbranch is a number of branches
3021 + * after adding a branch.
3023 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3026 + struct au_branch *add_branch;
3027 + struct dentry *root;
3028 + struct inode *inode;
3032 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3033 + if (unlikely(!add_branch))
3035 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3036 + add_branch->br_xino.xi_nondir.array
3037 + = kzalloc(sizeof(ino_t) * add_branch->br_xino.xi_nondir.total,
3039 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3042 + err = au_hnotify_init_br(add_branch, perm);
3043 + if (unlikely(err))
3044 + goto out_xinondir;
3046 + if (au_br_writable(perm)) {
3047 + /* may be freed separately at changing the branch permission */
3048 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3050 + if (unlikely(!add_branch->br_wbr))
3054 + if (au_br_fhsm(perm)) {
3055 + err = au_fhsm_br_alloc(add_branch);
3056 + if (unlikely(err))
3060 + root = sb->s_root;
3061 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3063 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3065 + inode = d_inode(root);
3066 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3070 + return add_branch; /* success */
3073 + kfree(add_branch->br_wbr);
3075 + au_hnotify_fin_br(add_branch);
3077 + kfree(add_branch->br_xino.xi_nondir.array);
3079 + kfree(add_branch);
3081 + return ERR_PTR(err);
3085 + * test if the branch permission is legal or not.
3087 +static int test_br(struct inode *inode, int brperm, char *path)
3091 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3096 + pr_err("write permission for readonly mount or inode, %s\n", path);
3104 + * 0: success, the caller will add it
3105 + * plus: success, it is already unified, the caller should ignore it
3108 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3111 + aufs_bindex_t bbot, bindex;
3112 + struct dentry *root, *h_dentry;
3113 + struct inode *inode, *h_inode;
3115 + root = sb->s_root;
3116 + bbot = au_sbbot(sb);
3117 + if (unlikely(bbot >= 0
3118 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3122 + pr_err("%s duplicated\n", add->pathname);
3127 + err = -ENOSPC; /* -E2BIG; */
3128 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3129 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3130 + pr_err("number of branches exceeded %s\n", add->pathname);
3135 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3136 + pr_err("bad index %d\n", add->bindex);
3140 + inode = d_inode(add->path.dentry);
3142 + if (unlikely(!inode->i_nlink)) {
3143 + pr_err("no existence %s\n", add->pathname);
3148 + if (unlikely(inode->i_sb == sb)) {
3149 + pr_err("%s must be outside\n", add->pathname);
3153 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3154 + pr_err("unsupported filesystem, %s (%s)\n",
3155 + add->pathname, au_sbtype(inode->i_sb));
3159 + if (unlikely(inode->i_sb->s_stack_depth)) {
3160 + pr_err("already stacked, %s (%s)\n",
3161 + add->pathname, au_sbtype(inode->i_sb));
3165 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3166 + if (unlikely(err))
3170 + return 0; /* success */
3173 + for (bindex = 0; bindex <= bbot; bindex++)
3174 + if (unlikely(test_overlap(sb, add->path.dentry,
3175 + au_h_dptr(root, bindex)))) {
3176 + pr_err("%s is overlapped\n", add->pathname);
3181 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3182 + h_dentry = au_h_dptr(root, 0);
3183 + h_inode = d_inode(h_dentry);
3184 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3185 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3186 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3187 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3189 + i_uid_read(inode), i_gid_read(inode),
3190 + (inode->i_mode & S_IALLUGO),
3191 + i_uid_read(h_inode), i_gid_read(h_inode),
3192 + (h_inode->i_mode & S_IALLUGO));
3200 + * initialize or clean the whiteouts for an adding branch
3202 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3205 + int err, old_perm;
3206 + aufs_bindex_t bindex;
3207 + struct inode *h_inode;
3208 + struct au_wbr *wbr;
3209 + struct au_hinode *hdir;
3210 + struct dentry *h_dentry;
3212 + err = vfsub_mnt_want_write(au_br_mnt(br));
3213 + if (unlikely(err))
3217 + old_perm = br->br_perm;
3218 + br->br_perm = new_perm;
3221 + bindex = au_br_index(sb, br->br_id);
3222 + if (0 <= bindex) {
3223 + hdir = au_hi(d_inode(sb->s_root), bindex);
3224 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3226 + h_dentry = au_br_dentry(br);
3227 + h_inode = d_inode(h_dentry);
3228 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3231 + err = au_wh_init(br, sb);
3233 + wbr_wh_write_lock(wbr);
3234 + err = au_wh_init(br, sb);
3235 + wbr_wh_write_unlock(wbr);
3238 + au_hn_inode_unlock(hdir);
3240 + inode_unlock(h_inode);
3241 + vfsub_mnt_drop_write(au_br_mnt(br));
3242 + br->br_perm = old_perm;
3244 + if (!err && wbr && !au_br_writable(new_perm)) {
3246 + br->br_wbr = NULL;
3253 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3257 + struct kstatfs kst;
3258 + struct au_wbr *wbr;
3261 + au_rw_init(&wbr->wbr_wh_rwsem);
3262 + atomic_set(&wbr->wbr_wh_running, 0);
3265 + * a limit for rmdir/rename a dir
3266 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3268 + err = vfs_statfs(&br->br_path, &kst);
3269 + if (unlikely(err))
3272 + if (kst.f_namelen >= NAME_MAX)
3273 + err = au_br_init_wh(sb, br, perm);
3275 + pr_err("%pd(%s), unsupported namelen %ld\n",
3277 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3283 +/* initialize a new branch */
3284 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3285 + struct au_opt_add *add)
3288 + struct inode *h_inode;
3291 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3292 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3293 + br->br_perm = add->perm;
3294 + br->br_path = add->path; /* set first, path_get() later */
3295 + spin_lock_init(&br->br_dykey_lock);
3296 + au_br_count_init(br);
3297 + atomic_set(&br->br_xino_running, 0);
3298 + br->br_id = au_new_br_id(sb);
3299 + AuDebugOn(br->br_id < 0);
3301 + if (au_br_writable(add->perm)) {
3302 + err = au_wbr_init(br, sb, add->perm);
3303 + if (unlikely(err))
3307 + if (au_opt_test(au_mntflags(sb), XINO)) {
3308 + h_inode = d_inode(add->path.dentry);
3309 + err = au_xino_br(sb, br, h_inode->i_ino,
3310 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3311 + if (unlikely(err)) {
3312 + AuDebugOn(br->br_xino.xi_file);
3317 + sysaufs_br_init(br);
3318 + path_get(&br->br_path);
3319 + goto out; /* success */
3322 + memset(&br->br_path, 0, sizeof(br->br_path));
3327 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3328 + struct au_branch *br, aufs_bindex_t bbot,
3329 + aufs_bindex_t amount)
3331 + struct au_branch **brp;
3333 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3335 + brp = sbinfo->si_branch + bindex;
3336 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3338 + sbinfo->si_bbot++;
3339 + if (unlikely(bbot < 0))
3340 + sbinfo->si_bbot = 0;
3343 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3344 + aufs_bindex_t bbot, aufs_bindex_t amount)
3346 + struct au_hdentry *hdp;
3348 + AuRwMustWriteLock(&dinfo->di_rwsem);
3350 + hdp = au_hdentry(dinfo, bindex);
3351 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3352 + au_h_dentry_init(hdp);
3354 + if (unlikely(bbot < 0))
3355 + dinfo->di_btop = 0;
3358 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3359 + aufs_bindex_t bbot, aufs_bindex_t amount)
3361 + struct au_hinode *hip;
3363 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3365 + hip = au_hinode(iinfo, bindex);
3366 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3367 + au_hinode_init(hip);
3369 + if (unlikely(bbot < 0))
3370 + iinfo->ii_btop = 0;
3373 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3374 + aufs_bindex_t bindex)
3376 + struct dentry *root, *h_dentry;
3377 + struct inode *root_inode, *h_inode;
3378 + aufs_bindex_t bbot, amount;
3380 + root = sb->s_root;
3381 + root_inode = d_inode(root);
3382 + bbot = au_sbbot(sb);
3383 + amount = bbot + 1 - bindex;
3384 + h_dentry = au_br_dentry(br);
3385 + au_sbilist_lock();
3386 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3387 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3388 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3389 + au_set_h_dptr(root, bindex, dget(h_dentry));
3390 + h_inode = d_inode(h_dentry);
3391 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3392 + au_sbilist_unlock();
3395 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3398 + aufs_bindex_t bbot, add_bindex;
3399 + struct dentry *root, *h_dentry;
3400 + struct inode *root_inode;
3401 + struct au_branch *add_branch;
3403 + root = sb->s_root;
3404 + root_inode = d_inode(root);
3405 + IMustLock(root_inode);
3406 + IiMustWriteLock(root_inode);
3407 + err = test_add(sb, add, remount);
3408 + if (unlikely(err < 0))
3412 + goto out; /* success */
3415 + bbot = au_sbbot(sb);
3416 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3417 + err = PTR_ERR(add_branch);
3418 + if (IS_ERR(add_branch))
3421 + err = au_br_init(add_branch, sb, add);
3422 + if (unlikely(err)) {
3423 + au_br_do_free(add_branch);
3427 + add_bindex = add->bindex;
3429 + au_br_do_add(sb, add_branch, add_bindex);
3431 + sysaufs_brs_del(sb, add_bindex);
3432 + au_br_do_add(sb, add_branch, add_bindex);
3433 + sysaufs_brs_add(sb, add_bindex);
3436 + h_dentry = add->path.dentry;
3437 + if (!add_bindex) {
3438 + au_cpup_attr_all(root_inode, /*force*/1);
3439 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3441 + au_add_nlink(root_inode, d_inode(h_dentry));
3444 + * this test/set prevents aufs from handling unnecesary notify events
3445 + * of xino files, in case of re-adding a writable branch which was
3446 + * once detached from aufs.
3448 + if (au_xino_brid(sb) < 0
3449 + && au_br_writable(add_branch->br_perm)
3450 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3451 + && add_branch->br_xino.xi_file
3452 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3453 + au_xino_brid_set(sb, add_branch->br_id);
3459 +/* ---------------------------------------------------------------------- */
3461 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3462 + unsigned long long max __maybe_unused,
3465 + unsigned long long n;
3466 + struct file **p, *f;
3467 + struct au_sphlhead *files;
3468 + struct au_finfo *finfo;
3472 + files = &au_sbi(sb)->si_files;
3473 + spin_lock(&files->spin);
3474 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3475 + f = finfo->fi_file;
3477 + && !special_file(file_inode(f)->i_mode)) {
3481 + AuDebugOn(n > max);
3484 + spin_unlock(&files->spin);
3489 +static struct file **au_farray_alloc(struct super_block *sb,
3490 + unsigned long long *max)
3492 + *max = au_nfiles(sb);
3493 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3496 +static void au_farray_free(struct file **a, unsigned long long max)
3498 + unsigned long long ull;
3500 + for (ull = 0; ull < max; ull++)
3506 +/* ---------------------------------------------------------------------- */
3512 +/* to show the line number, do not make it inlined function */
3513 +#define AuVerbose(do_info, fmt, ...) do { \
3515 + pr_info(fmt, ##__VA_ARGS__); \
3518 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3519 + aufs_bindex_t bbot)
3521 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3524 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3525 + aufs_bindex_t bbot)
3527 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3531 + * test if the branch is deletable or not.
3533 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3534 + unsigned int sigen, const unsigned int verbose)
3536 + int err, i, j, ndentry;
3537 + aufs_bindex_t btop, bbot;
3538 + struct au_dcsub_pages dpages;
3539 + struct au_dpage *dpage;
3542 + err = au_dpages_init(&dpages, GFP_NOFS);
3543 + if (unlikely(err))
3545 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3546 + if (unlikely(err))
3549 + for (i = 0; !err && i < dpages.ndpage; i++) {
3550 + dpage = dpages.dpages + i;
3551 + ndentry = dpage->ndentry;
3552 + for (j = 0; !err && j < ndentry; j++) {
3553 + d = dpage->dentries[j];
3554 + AuDebugOn(au_dcount(d) <= 0);
3555 + if (!au_digen_test(d, sigen)) {
3556 + di_read_lock_child(d, AuLock_IR);
3557 + if (unlikely(au_dbrange_test(d))) {
3558 + di_read_unlock(d, AuLock_IR);
3562 + di_write_lock_child(d);
3563 + if (unlikely(au_dbrange_test(d))) {
3564 + di_write_unlock(d);
3567 + err = au_reval_dpath(d, sigen);
3569 + di_downgrade_lock(d, AuLock_IR);
3571 + di_write_unlock(d);
3576 + /* AuDbgDentry(d); */
3577 + btop = au_dbtop(d);
3578 + bbot = au_dbbot(d);
3579 + if (btop <= bindex
3581 + && au_h_dptr(d, bindex)
3582 + && au_test_dbusy(d, btop, bbot)) {
3584 + AuVerbose(verbose, "busy %pd\n", d);
3587 + di_read_unlock(d, AuLock_IR);
3592 + au_dpages_free(&dpages);
3597 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3598 + unsigned int sigen, const unsigned int verbose)
3601 + unsigned long long max, ull;
3602 + struct inode *i, **array;
3603 + aufs_bindex_t btop, bbot;
3605 + array = au_iarray_alloc(sb, &max);
3606 + err = PTR_ERR(array);
3607 + if (IS_ERR(array))
3611 + AuDbg("b%d\n", bindex);
3612 + for (ull = 0; !err && ull < max; ull++) {
3616 + if (i->i_ino == AUFS_ROOT_INO)
3619 + /* AuDbgInode(i); */
3620 + if (au_iigen(i, NULL) == sigen)
3621 + ii_read_lock_child(i);
3623 + ii_write_lock_child(i);
3624 + err = au_refresh_hinode_self(i);
3627 + ii_downgrade_lock(i);
3629 + ii_write_unlock(i);
3634 + btop = au_ibtop(i);
3635 + bbot = au_ibbot(i);
3636 + if (btop <= bindex
3638 + && au_h_iptr(i, bindex)
3639 + && au_test_ibusy(i, btop, bbot)) {
3641 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3644 + ii_read_unlock(i);
3646 + au_iarray_free(array, max);
3652 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3653 + const unsigned int verbose)
3656 + unsigned int sigen;
3658 + sigen = au_sigen(root->d_sb);
3659 + DiMustNoWaiters(root);
3660 + IiMustNoWaiters(d_inode(root));
3661 + di_write_unlock(root);
3662 + err = test_dentry_busy(root, bindex, sigen, verbose);
3664 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3665 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3670 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3671 + struct file **to_free, int *idx)
3674 + unsigned char matched, root;
3675 + aufs_bindex_t bindex, bbot;
3676 + struct au_fidir *fidir;
3677 + struct au_hfile *hfile;
3680 + root = IS_ROOT(file->f_path.dentry);
3683 + to_free[*idx] = file;
3689 + fidir = au_fi(file)->fi_hdir;
3690 + AuDebugOn(!fidir);
3691 + bbot = au_fbbot_dir(file);
3692 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3693 + hfile = fidir->fd_hfile + bindex;
3694 + if (!hfile->hf_file)
3697 + if (hfile->hf_br->br_id == br_id) {
3709 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3710 + struct file **to_free, int opened)
3713 + unsigned long long ull, max;
3714 + aufs_bindex_t btop;
3715 + struct file *file, **array;
3716 + struct dentry *root;
3717 + struct au_hfile *hfile;
3719 + array = au_farray_alloc(sb, &max);
3720 + err = PTR_ERR(array);
3721 + if (IS_ERR(array))
3726 + root = sb->s_root;
3727 + di_write_unlock(root);
3728 + for (ull = 0; ull < max; ull++) {
3729 + file = array[ull];
3730 + if (unlikely(!file))
3733 + /* AuDbg("%pD\n", file); */
3734 + fi_read_lock(file);
3735 + btop = au_fbtop(file);
3736 + if (!d_is_dir(file->f_path.dentry)) {
3737 + hfile = &au_fi(file)->fi_htop;
3738 + if (hfile->hf_br->br_id == br_id)
3741 + err = test_dir_busy(file, br_id, to_free, &idx);
3742 + fi_read_unlock(file);
3743 + if (unlikely(err))
3746 + di_write_lock_child(root);
3747 + au_farray_free(array, max);
3748 + AuDebugOn(idx > opened);
3754 +static void br_del_file(struct file **to_free, unsigned long long opened,
3755 + aufs_bindex_t br_id)
3757 + unsigned long long ull;
3758 + aufs_bindex_t bindex, btop, bbot, bfound;
3759 + struct file *file;
3760 + struct au_fidir *fidir;
3761 + struct au_hfile *hfile;
3763 + for (ull = 0; ull < opened; ull++) {
3764 + file = to_free[ull];
3765 + if (unlikely(!file))
3768 + /* AuDbg("%pD\n", file); */
3769 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3771 + fidir = au_fi(file)->fi_hdir;
3772 + AuDebugOn(!fidir);
3773 + fi_write_lock(file);
3774 + btop = au_fbtop(file);
3775 + bbot = au_fbbot_dir(file);
3776 + for (bindex = btop; bindex <= bbot; bindex++) {
3777 + hfile = fidir->fd_hfile + bindex;
3778 + if (!hfile->hf_file)
3781 + if (hfile->hf_br->br_id == br_id) {
3786 + AuDebugOn(bfound < 0);
3787 + au_set_h_fptr(file, bfound, NULL);
3788 + if (bfound == btop) {
3789 + for (btop++; btop <= bbot; btop++)
3790 + if (au_hf_dir(file, btop)) {
3791 + au_set_fbtop(file, btop);
3795 + fi_write_unlock(file);
3799 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3800 + const aufs_bindex_t bindex,
3801 + const aufs_bindex_t bbot)
3803 + struct au_branch **brp, **p;
3805 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3807 + brp = sbinfo->si_branch + bindex;
3808 + if (bindex < bbot)
3809 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3810 + sbinfo->si_branch[0 + bbot] = NULL;
3811 + sbinfo->si_bbot--;
3813 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3816 + sbinfo->si_branch = p;
3817 + /* harmless error */
3820 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3821 + const aufs_bindex_t bbot)
3823 + struct au_hdentry *hdp, *p;
3825 + AuRwMustWriteLock(&dinfo->di_rwsem);
3827 + hdp = au_hdentry(dinfo, bindex);
3828 + if (bindex < bbot)
3829 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3830 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3833 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3836 + dinfo->di_hdentry = p;
3837 + /* harmless error */
3840 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3841 + const aufs_bindex_t bbot)
3843 + struct au_hinode *hip, *p;
3845 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3847 + hip = au_hinode(iinfo, bindex);
3848 + if (bindex < bbot)
3849 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3850 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3853 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3856 + iinfo->ii_hinode = p;
3857 + /* harmless error */
3860 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3861 + struct au_branch *br)
3863 + aufs_bindex_t bbot;
3864 + struct au_sbinfo *sbinfo;
3865 + struct dentry *root, *h_root;
3866 + struct inode *inode, *h_inode;
3867 + struct au_hinode *hinode;
3869 + SiMustWriteLock(sb);
3871 + root = sb->s_root;
3872 + inode = d_inode(root);
3873 + sbinfo = au_sbi(sb);
3874 + bbot = sbinfo->si_bbot;
3876 + h_root = au_h_dptr(root, bindex);
3877 + hinode = au_hi(inode, bindex);
3878 + h_inode = au_igrab(hinode->hi_inode);
3881 + au_sbilist_lock();
3882 + au_br_do_del_brp(sbinfo, bindex, bbot);
3883 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3884 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3885 + au_sbilist_unlock();
3889 + au_br_do_free(br);
3892 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3893 + unsigned long long max, void *arg)
3898 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3901 + unsigned long long opened;
3902 + unsigned int mnt_flags;
3903 + aufs_bindex_t bindex, bbot, br_id;
3904 + unsigned char do_wh, verbose;
3905 + struct au_branch *br;
3906 + struct au_wbr *wbr;
3907 + struct dentry *root;
3908 + struct file **to_free;
3913 + root = sb->s_root;
3914 + bindex = au_find_dbindex(root, del->h_path.dentry);
3917 + goto out; /* success */
3919 + pr_err("%s no such branch\n", del->pathname);
3922 + AuDbg("bindex b%d\n", bindex);
3925 + mnt_flags = au_mntflags(sb);
3926 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3927 + bbot = au_sbbot(sb);
3928 + if (unlikely(!bbot)) {
3929 + AuVerbose(verbose, "no more branches left\n");
3932 + br = au_sbr(sb, bindex);
3933 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3935 + br_id = br->br_id;
3936 + opened = au_br_count(br);
3937 + if (unlikely(opened)) {
3938 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3939 + err = PTR_ERR(to_free);
3940 + if (IS_ERR(to_free))
3943 + err = test_file_busy(sb, br_id, to_free, opened);
3944 + if (unlikely(err)) {
3945 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3951 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3953 + /* instead of WbrWhMustWriteLock(wbr) */
3954 + SiMustWriteLock(sb);
3955 + for (i = 0; i < AuBrWh_Last; i++) {
3956 + dput(wbr->wbr_wh[i]);
3957 + wbr->wbr_wh[i] = NULL;
3961 + err = test_children_busy(root, bindex, verbose);
3962 + if (unlikely(err)) {
3971 + * now we confirmed the branch is deletable.
3972 + * let's free the remaining opened dirs on the branch.
3974 + di_write_unlock(root);
3975 + br_del_file(to_free, opened, br_id);
3976 + di_write_lock_child(root);
3980 + au_br_do_del(sb, bindex, br);
3982 + sysaufs_brs_del(sb, bindex);
3983 + au_br_do_del(sb, bindex, br);
3984 + sysaufs_brs_add(sb, bindex);
3988 + au_cpup_attr_all(d_inode(root), /*force*/1);
3989 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3991 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3992 + if (au_opt_test(mnt_flags, PLINK))
3993 + au_plink_half_refresh(sb, br_id);
3995 + if (au_xino_brid(sb) == br_id)
3996 + au_xino_brid_set(sb, -1);
3997 + goto out; /* success */
4001 + rerr = au_br_init_wh(sb, br, br->br_perm);
4003 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4004 + del->pathname, rerr);
4007 + au_farray_free(to_free, opened);
4011 +/* ---------------------------------------------------------------------- */
4013 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4016 + aufs_bindex_t btop, bbot;
4017 + struct aufs_ibusy ibusy;
4018 + struct inode *inode, *h_inode;
4021 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4024 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4026 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4027 + if (unlikely(err)) {
4034 + si_read_lock(sb, AuLock_FLUSH);
4035 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4039 + ibusy.h_ino = 0; /* invalid */
4040 + inode = ilookup(sb, ibusy.ino);
4042 + || inode->i_ino == AUFS_ROOT_INO
4043 + || au_is_bad_inode(inode))
4046 + ii_read_lock_child(inode);
4047 + btop = au_ibtop(inode);
4048 + bbot = au_ibbot(inode);
4049 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4050 + h_inode = au_h_iptr(inode, ibusy.bindex);
4051 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4052 + ibusy.h_ino = h_inode->i_ino;
4054 + ii_read_unlock(inode);
4058 + si_read_unlock(sb);
4060 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4061 + if (unlikely(err)) {
4070 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4072 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4075 +#ifdef CONFIG_COMPAT
4076 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4078 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4082 +/* ---------------------------------------------------------------------- */
4085 + * change a branch permission
4088 +static void au_warn_ima(void)
4091 + /* since it doesn't support mark_files_ro() */
4092 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4096 +static int do_need_sigen_inc(int a, int b)
4098 + return au_br_whable(a) && !au_br_whable(b);
4101 +static int need_sigen_inc(int old, int new)
4103 + return do_need_sigen_inc(old, new)
4104 + || do_need_sigen_inc(new, old);
4107 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4110 + unsigned int mnt_flags;
4111 + unsigned long long ull, max;
4112 + aufs_bindex_t br_id;
4113 + unsigned char verbose, writer;
4114 + struct file *file, *hf, **array;
4115 + struct au_hfile *hfile;
4117 + mnt_flags = au_mntflags(sb);
4118 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4120 + array = au_farray_alloc(sb, &max);
4121 + err = PTR_ERR(array);
4122 + if (IS_ERR(array))
4126 + br_id = au_sbr_id(sb, bindex);
4127 + for (ull = 0; ull < max; ull++) {
4128 + file = array[ull];
4129 + if (unlikely(!file))
4132 + /* AuDbg("%pD\n", file); */
4133 + fi_read_lock(file);
4134 + if (unlikely(au_test_mmapped(file))) {
4136 + AuVerbose(verbose, "mmapped %pD\n", file);
4138 + FiMustNoWaiters(file);
4139 + fi_read_unlock(file);
4143 + hfile = &au_fi(file)->fi_htop;
4144 + hf = hfile->hf_file;
4145 + if (!d_is_reg(file->f_path.dentry)
4146 + || !(file->f_mode & FMODE_WRITE)
4147 + || hfile->hf_br->br_id != br_id
4148 + || !(hf->f_mode & FMODE_WRITE))
4149 + array[ull] = NULL;
4155 + FiMustNoWaiters(file);
4156 + fi_read_unlock(file);
4164 + for (ull = 0; ull < max; ull++) {
4165 + file = array[ull];
4169 + /* todo: already flushed? */
4171 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4172 + * approach which resets f_mode and calls mnt_drop_write() and
4173 + * file_release_write() for each file, because the branch
4174 + * attribute in aufs world is totally different from the native
4177 + /* fi_read_lock(file); */
4178 + hfile = &au_fi(file)->fi_htop;
4179 + hf = hfile->hf_file;
4180 + /* fi_read_unlock(file); */
4181 + spin_lock(&hf->f_lock);
4182 + writer = !!(hf->f_mode & FMODE_WRITER);
4183 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4184 + spin_unlock(&hf->f_lock);
4186 + put_write_access(file_inode(hf));
4187 + __mnt_drop_write(hf->f_path.mnt);
4192 + au_farray_free(array, max);
4198 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4202 + aufs_bindex_t bindex;
4203 + struct dentry *root;
4204 + struct au_branch *br;
4205 + struct au_br_fhsm *bf;
4207 + root = sb->s_root;
4208 + bindex = au_find_dbindex(root, mod->h_root);
4211 + return 0; /* success */
4213 + pr_err("%s no such branch\n", mod->path);
4216 + AuDbg("bindex b%d\n", bindex);
4218 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4219 + if (unlikely(err))
4222 + br = au_sbr(sb, bindex);
4223 + AuDebugOn(mod->h_root != au_br_dentry(br));
4224 + if (br->br_perm == mod->perm)
4225 + return 0; /* success */
4227 + /* pre-allocate for non-fhsm --> fhsm */
4229 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4230 + err = au_fhsm_br_alloc(br);
4231 + if (unlikely(err))
4234 + br->br_fhsm = NULL;
4237 + if (au_br_writable(br->br_perm)) {
4238 + /* remove whiteout base */
4239 + err = au_br_init_wh(sb, br, mod->perm);
4240 + if (unlikely(err))
4243 + if (!au_br_writable(mod->perm)) {
4244 + /* rw --> ro, file might be mmapped */
4245 + DiMustNoWaiters(root);
4246 + IiMustNoWaiters(d_inode(root));
4247 + di_write_unlock(root);
4248 + err = au_br_mod_files_ro(sb, bindex);
4249 + /* aufs_write_lock() calls ..._child() */
4250 + di_write_lock_child(root);
4252 + if (unlikely(err)) {
4254 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4257 + rerr = au_wbr_init(br, sb, br->br_perm);
4258 + if (unlikely(rerr)) {
4259 + AuIOErr("nested error %d (%d)\n",
4261 + br->br_perm = mod->perm;
4265 + } else if (au_br_writable(mod->perm)) {
4268 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4270 + err = au_wbr_init(br, sb, mod->perm);
4271 + if (unlikely(err)) {
4272 + kfree(br->br_wbr);
4273 + br->br_wbr = NULL;
4277 + if (unlikely(err))
4280 + if (au_br_fhsm(br->br_perm)) {
4281 + if (!au_br_fhsm(mod->perm)) {
4282 + /* fhsm --> non-fhsm */
4283 + au_br_fhsm_fin(br->br_fhsm);
4284 + kfree(br->br_fhsm);
4285 + br->br_fhsm = NULL;
4287 + } else if (au_br_fhsm(mod->perm))
4288 + /* non-fhsm --> fhsm */
4291 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4292 + br->br_perm = mod->perm;
4293 + goto out; /* success */
4303 +/* ---------------------------------------------------------------------- */
4305 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4308 + struct kstatfs kstfs;
4310 + err = vfs_statfs(&br->br_path, &kstfs);
4312 + stfs->f_blocks = kstfs.f_blocks;
4313 + stfs->f_bavail = kstfs.f_bavail;
4314 + stfs->f_files = kstfs.f_files;
4315 + stfs->f_ffree = kstfs.f_ffree;
4320 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4321 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4322 +++ linux/fs/aufs/branch.h 2017-07-29 12:14:25.896375188 +0200
4325 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4327 + * This program, aufs is free software; you can redistribute it and/or modify
4328 + * it under the terms of the GNU General Public License as published by
4329 + * the Free Software Foundation; either version 2 of the License, or
4330 + * (at your option) any later version.
4332 + * This program is distributed in the hope that it will be useful,
4333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4335 + * GNU General Public License for more details.
4337 + * You should have received a copy of the GNU General Public License
4338 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4342 + * branch filesystems and xino for them
4345 +#ifndef __AUFS_BRANCH_H__
4346 +#define __AUFS_BRANCH_H__
4350 +#include <linux/mount.h>
4355 +/* ---------------------------------------------------------------------- */
4358 +struct au_xino_file {
4359 + struct file *xi_file;
4364 + /* reserved for future use */
4365 + /* unsigned long *bitmap; */
4366 + wait_queue_head_t wqh;
4369 + /* todo: make xino files an array to support huge inode number */
4371 +#ifdef CONFIG_DEBUG_FS
4372 + struct dentry *xi_dbgaufs;
4376 +/* File-based Hierarchical Storage Management */
4377 +struct au_br_fhsm {
4378 +#ifdef CONFIG_AUFS_FHSM
4379 + struct mutex bf_lock;
4380 + unsigned long bf_jiffy;
4381 + struct aufs_stfs bf_stfs;
4386 +/* members for writable branch only */
4387 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4389 + struct au_rwsem wbr_wh_rwsem;
4390 + struct dentry *wbr_wh[AuBrWh_Last];
4391 + atomic_t wbr_wh_running;
4392 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4393 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4394 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4397 + unsigned long long wbr_bytes;
4400 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4401 +#define AuBrDynOp (AuDyLast * 4)
4403 +#ifdef CONFIG_AUFS_HFSNOTIFY
4404 +/* support for asynchronous destruction */
4405 +struct au_br_hfsnotify {
4406 + struct fsnotify_group *hfsn_group;
4410 +/* sysfs entries */
4411 +struct au_brsysfs {
4413 + struct attribute attr;
4422 +/* protected by superblock rwsem */
4424 + struct au_xino_file br_xino;
4426 + aufs_bindex_t br_id;
4429 + struct path br_path;
4430 + spinlock_t br_dykey_lock;
4431 + struct au_dykey *br_dykey[AuBrDynOp];
4432 + struct percpu_counter br_count;
4434 + struct au_wbr *br_wbr;
4435 + struct au_br_fhsm *br_fhsm;
4437 + /* xino truncation */
4438 + atomic_t br_xino_running;
4440 +#ifdef CONFIG_AUFS_HFSNOTIFY
4441 + struct au_br_hfsnotify *br_hfsn;
4444 +#ifdef CONFIG_SYSFS
4445 + /* entries under sysfs per mount-point */
4446 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4450 +/* ---------------------------------------------------------------------- */
4452 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4454 + return br->br_path.mnt;
4457 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4459 + return br->br_path.dentry;
4462 +static inline struct super_block *au_br_sb(struct au_branch *br)
4464 + return au_br_mnt(br)->mnt_sb;
4467 +static inline void au_br_get(struct au_branch *br)
4469 + percpu_counter_inc(&br->br_count);
4472 +static inline void au_br_put(struct au_branch *br)
4474 + percpu_counter_dec(&br->br_count);
4477 +static inline s64 au_br_count(struct au_branch *br)
4479 + return percpu_counter_sum(&br->br_count);
4482 +static inline void au_br_count_init(struct au_branch *br)
4484 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4487 +static inline void au_br_count_fin(struct au_branch *br)
4489 + percpu_counter_destroy(&br->br_count);
4492 +static inline int au_br_rdonly(struct au_branch *br)
4494 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4495 + || !au_br_writable(br->br_perm))
4499 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4501 +#ifdef CONFIG_AUFS_HNOTIFY
4502 + return !(brperm & AuBrPerm_RR);
4508 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4510 + int err, exec_flag;
4513 + exec_flag = oflag & __FMODE_EXEC;
4514 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4520 +/* ---------------------------------------------------------------------- */
4524 +void au_br_free(struct au_sbinfo *sinfo);
4525 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4527 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4529 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4530 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4531 +#ifdef CONFIG_COMPAT
4532 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4535 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4538 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4541 +static const loff_t au_loff_max = LLONG_MAX;
4543 +int au_xib_trunc(struct super_block *sb);
4544 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4546 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4547 + size_t size, loff_t *pos);
4548 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4549 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4550 +ino_t au_xino_new_ino(struct super_block *sb);
4551 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4552 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4554 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4556 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4557 + struct file *base_file, int do_test);
4558 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4560 +struct au_opt_xino;
4561 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4562 +void au_xino_clr(struct super_block *sb);
4563 +struct file *au_xino_def(struct super_block *sb);
4564 +int au_xino_path(struct seq_file *seq, struct file *file);
4566 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4567 + ino_t h_ino, int idx);
4568 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4571 +/* ---------------------------------------------------------------------- */
4573 +/* Superblock to branch */
4575 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4577 + return au_sbr(sb, bindex)->br_id;
4581 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4583 + return au_br_mnt(au_sbr(sb, bindex));
4587 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4589 + return au_br_sb(au_sbr(sb, bindex));
4592 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4594 + au_br_get(au_sbr(sb, bindex));
4597 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4599 + au_br_put(au_sbr(sb, bindex));
4602 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4604 + return au_sbr(sb, bindex)->br_perm;
4607 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4609 + return au_br_whable(au_sbr_perm(sb, bindex));
4612 +/* ---------------------------------------------------------------------- */
4615 + * wbr_wh_read_lock, wbr_wh_write_lock
4616 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4618 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4620 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4621 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4622 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4624 +/* ---------------------------------------------------------------------- */
4626 +#ifdef CONFIG_AUFS_FHSM
4627 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4629 + mutex_init(&brfhsm->bf_lock);
4630 + brfhsm->bf_jiffy = 0;
4631 + brfhsm->bf_readable = 0;
4634 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4636 + mutex_destroy(&brfhsm->bf_lock);
4639 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4640 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4643 +#endif /* __KERNEL__ */
4644 +#endif /* __AUFS_BRANCH_H__ */
4645 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4646 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4647 +++ linux/fs/aufs/conf.mk 2017-07-29 12:14:25.899708630 +0200
4650 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4654 +AuConfStr += ${1}=${${1}}
4658 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4660 + HNOTIFY HFSNOTIFY \
4671 +$(foreach i, ${AuConfAll}, \
4672 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4674 +AuConfName = ${obj}/conf.str
4675 +${AuConfName}.tmp: FORCE
4676 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4677 +${AuConfName}: ${AuConfName}.tmp
4678 + @diff -q $< $@ > /dev/null 2>&1 || { \
4679 + echo ' GEN ' $@; \
4683 +clean-files += ${AuConfName} ${AuConfName}.tmp
4684 +${obj}/sysfs.o: ${AuConfName}
4686 +-include ${srctree}/${src}/conf_priv.mk
4687 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4688 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4689 +++ linux/fs/aufs/cpup.c 2017-07-29 12:14:25.899708630 +0200
4692 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4694 + * This program, aufs is free software; you can redistribute it and/or modify
4695 + * it under the terms of the GNU General Public License as published by
4696 + * the Free Software Foundation; either version 2 of the License, or
4697 + * (at your option) any later version.
4699 + * This program is distributed in the hope that it will be useful,
4700 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4701 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4702 + * GNU General Public License for more details.
4704 + * You should have received a copy of the GNU General Public License
4705 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4709 + * copy-up functions, see wbr_policy.c for copy-down
4712 +#include <linux/fs_stack.h>
4713 +#include <linux/mm.h>
4714 +#include <linux/task_work.h>
4717 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4719 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4720 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4722 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4724 + dst->i_flags |= iflags & ~mask;
4725 + if (au_test_fs_notime(dst->i_sb))
4726 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4729 +void au_cpup_attr_timesizes(struct inode *inode)
4731 + struct inode *h_inode;
4733 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4734 + fsstack_copy_attr_times(inode, h_inode);
4735 + fsstack_copy_inode_size(inode, h_inode);
4738 +void au_cpup_attr_nlink(struct inode *inode, int force)
4740 + struct inode *h_inode;
4741 + struct super_block *sb;
4742 + aufs_bindex_t bindex, bbot;
4745 + bindex = au_ibtop(inode);
4746 + h_inode = au_h_iptr(inode, bindex);
4748 + && !S_ISDIR(h_inode->i_mode)
4749 + && au_opt_test(au_mntflags(sb), PLINK)
4750 + && au_plink_test(inode))
4754 + * 0 can happen in revalidating.
4755 + * h_inode->i_mutex may not be held here, but it is harmless since once
4756 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4758 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4759 + * the incorrect link count.
4761 + set_nlink(inode, h_inode->i_nlink);
4764 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4765 + * it may includes whplink directory.
4767 + if (S_ISDIR(h_inode->i_mode)) {
4768 + bbot = au_ibbot(inode);
4769 + for (bindex++; bindex <= bbot; bindex++) {
4770 + h_inode = au_h_iptr(inode, bindex);
4772 + au_add_nlink(inode, h_inode);
4777 +void au_cpup_attr_changeable(struct inode *inode)
4779 + struct inode *h_inode;
4781 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4782 + inode->i_mode = h_inode->i_mode;
4783 + inode->i_uid = h_inode->i_uid;
4784 + inode->i_gid = h_inode->i_gid;
4785 + au_cpup_attr_timesizes(inode);
4786 + au_cpup_attr_flags(inode, h_inode->i_flags);
4789 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4791 + struct au_iinfo *iinfo = au_ii(inode);
4793 + IiMustWriteLock(inode);
4795 + iinfo->ii_higen = h_inode->i_generation;
4796 + iinfo->ii_hsb1 = h_inode->i_sb;
4799 +void au_cpup_attr_all(struct inode *inode, int force)
4801 + struct inode *h_inode;
4803 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4804 + au_cpup_attr_changeable(inode);
4805 + if (inode->i_nlink > 0)
4806 + au_cpup_attr_nlink(inode, force);
4807 + inode->i_rdev = h_inode->i_rdev;
4808 + inode->i_blkbits = h_inode->i_blkbits;
4809 + au_cpup_igen(inode, h_inode);
4812 +/* ---------------------------------------------------------------------- */
4814 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4816 +/* keep the timestamps of the parent dir when cpup */
4817 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4818 + struct path *h_path)
4820 + struct inode *h_inode;
4822 + dt->dt_dentry = dentry;
4823 + dt->dt_h_path = *h_path;
4824 + h_inode = d_inode(h_path->dentry);
4825 + dt->dt_atime = h_inode->i_atime;
4826 + dt->dt_mtime = h_inode->i_mtime;
4830 +void au_dtime_revert(struct au_dtime *dt)
4832 + struct iattr attr;
4835 + attr.ia_atime = dt->dt_atime;
4836 + attr.ia_mtime = dt->dt_mtime;
4837 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4838 + | ATTR_ATIME | ATTR_ATIME_SET;
4840 + /* no delegation since this is a directory */
4841 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4842 + if (unlikely(err))
4843 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4846 +/* ---------------------------------------------------------------------- */
4848 +/* internal use only */
4849 +struct au_cpup_reg_attr {
4852 + unsigned int iflags; /* inode->i_flags */
4855 +static noinline_for_stack
4856 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4857 + struct au_cpup_reg_attr *h_src_attr)
4859 + int err, sbits, icex;
4860 + unsigned int mnt_flags;
4861 + unsigned char verbose;
4863 + struct path h_path;
4864 + struct inode *h_isrc, *h_idst;
4865 + struct kstat *h_st;
4866 + struct au_branch *br;
4868 + h_path.dentry = au_h_dptr(dst, bindex);
4869 + h_idst = d_inode(h_path.dentry);
4870 + br = au_sbr(dst->d_sb, bindex);
4871 + h_path.mnt = au_br_mnt(br);
4872 + h_isrc = d_inode(h_src);
4873 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4874 + | ATTR_ATIME | ATTR_MTIME
4875 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4876 + if (h_src_attr && h_src_attr->valid) {
4877 + h_st = &h_src_attr->st;
4878 + ia.ia_uid = h_st->uid;
4879 + ia.ia_gid = h_st->gid;
4880 + ia.ia_atime = h_st->atime;
4881 + ia.ia_mtime = h_st->mtime;
4882 + if (h_idst->i_mode != h_st->mode
4883 + && !S_ISLNK(h_idst->i_mode)) {
4884 + ia.ia_valid |= ATTR_MODE;
4885 + ia.ia_mode = h_st->mode;
4887 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4888 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4890 + ia.ia_uid = h_isrc->i_uid;
4891 + ia.ia_gid = h_isrc->i_gid;
4892 + ia.ia_atime = h_isrc->i_atime;
4893 + ia.ia_mtime = h_isrc->i_mtime;
4894 + if (h_idst->i_mode != h_isrc->i_mode
4895 + && !S_ISLNK(h_idst->i_mode)) {
4896 + ia.ia_valid |= ATTR_MODE;
4897 + ia.ia_mode = h_isrc->i_mode;
4899 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4900 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4902 + /* no delegation since it is just created */
4903 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4905 + /* is this nfs only? */
4906 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4907 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4908 + ia.ia_mode = h_isrc->i_mode;
4909 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4912 + icex = br->br_perm & AuBrAttr_ICEX;
4914 + mnt_flags = au_mntflags(dst->d_sb);
4915 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4916 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4922 +/* ---------------------------------------------------------------------- */
4924 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4925 + char *buf, unsigned long blksize)
4928 + size_t sz, rbytes, wbytes;
4929 + unsigned char all_zero;
4931 + struct inode *h_inode;
4932 + /* reduce stack usage */
4935 + zp = page_address(ZERO_PAGE(0));
4936 + if (unlikely(!zp))
4937 + return -ENOMEM; /* possible? */
4942 + AuDbg("len %lld\n", len);
4944 + if (len < blksize)
4948 + /* todo: signal_pending? */
4949 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4950 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4953 + if (unlikely(err < 0))
4957 + if (len >= rbytes && rbytes == blksize)
4958 + all_zero = !memcmp(buf, zp, rbytes);
4965 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4967 + /* todo: signal_pending? */
4968 + if (unlikely(err == -EAGAIN || err == -EINTR))
4970 + if (unlikely(err < 0))
4975 + if (unlikely(err < 0))
4981 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4983 + if (unlikely(res < 0))
4990 + /* the last block may be a hole */
4991 + if (!err && all_zero) {
4992 + AuLabel(last hole);
4995 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4996 + /* nfs requires this step to make last hole */
4997 + /* is this only nfs? */
4999 + /* todo: signal_pending? */
5000 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5001 + } while (err == -EAGAIN || err == -EINTR);
5008 + ia->ia_size = dst->f_pos;
5009 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5010 + ia->ia_file = dst;
5011 + h_inode = file_inode(dst);
5012 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5013 + /* no delegation since it is just created */
5014 + err = vfsub_notify_change(&dst->f_path, ia,
5015 + /*delegated*/NULL);
5016 + inode_unlock(h_inode);
5023 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5026 + unsigned long blksize;
5027 + unsigned char do_kfree;
5031 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5032 + if (!blksize || PAGE_SIZE < blksize)
5033 + blksize = PAGE_SIZE;
5034 + AuDbg("blksize %lu\n", blksize);
5035 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5037 + buf = kmalloc(blksize, GFP_NOFS);
5039 + buf = (void *)__get_free_page(GFP_NOFS);
5040 + if (unlikely(!buf))
5043 + if (len > (1 << 22))
5044 + AuDbg("copying a large file %lld\n", (long long)len);
5048 + err = au_do_copy_file(dst, src, len, buf, blksize);
5052 + free_page((unsigned long)buf);
5058 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5061 + struct super_block *h_src_sb;
5062 + struct inode *h_src_inode;
5064 + h_src_inode = file_inode(src);
5065 + h_src_sb = h_src_inode->i_sb;
5067 + /* XFS acquires inode_lock */
5068 + if (!au_test_xfs(h_src_sb))
5069 + err = au_copy_file(dst, src, len);
5071 + inode_unlock(h_src_inode);
5072 + err = au_copy_file(dst, src, len);
5073 + inode_lock(h_src_inode);
5079 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5082 + struct super_block *h_src_sb;
5083 + struct inode *h_src_inode;
5085 + h_src_inode = file_inode(src);
5086 + h_src_sb = h_src_inode->i_sb;
5087 + if (h_src_sb != file_inode(dst)->i_sb
5088 + || !dst->f_op->clone_file_range) {
5089 + err = au_do_copy(dst, src, len);
5093 + if (!au_test_nfs(h_src_sb)) {
5094 + inode_unlock(h_src_inode);
5095 + err = vfsub_clone_file_range(src, dst, len);
5096 + inode_lock(h_src_inode);
5098 + err = vfsub_clone_file_range(src, dst, len);
5099 + /* older XFS has a condition in cloning */
5100 + if (unlikely(err != -EOPNOTSUPP))
5103 + /* the backend fs on NFS may not support cloning */
5104 + err = au_do_copy(dst, src, len);
5112 + * to support a sparse file which is opened with O_APPEND,
5113 + * we need to close the file.
5115 +static int au_cp_regular(struct au_cp_generic *cpg)
5118 + enum { SRC, DST };
5120 + aufs_bindex_t bindex;
5121 + unsigned int flags;
5122 + struct dentry *dentry;
5124 + struct file *file;
5128 + .bindex = cpg->bsrc,
5129 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5133 + .bindex = cpg->bdst,
5134 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5135 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5136 + .label = &&out_src
5139 + struct super_block *sb, *h_src_sb;
5140 + struct inode *h_src_inode;
5141 + struct task_struct *tsk = current;
5143 + /* bsrc branch can be ro/rw. */
5144 + sb = cpg->dentry->d_sb;
5146 + for (i = 0; i < 2; i++, f++) {
5147 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5148 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5149 + /*file*/NULL, f->force_wr);
5150 + err = PTR_ERR(f->file);
5151 + if (IS_ERR(f->file))
5155 + /* try stopping to update while we copyup */
5156 + h_src_inode = d_inode(file[SRC].dentry);
5157 + h_src_sb = h_src_inode->i_sb;
5158 + if (!au_test_nfs(h_src_sb))
5159 + IMustLock(h_src_inode);
5160 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5162 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5163 + if (tsk->flags & PF_KTHREAD)
5164 + __fput_sync(file[DST].file);
5166 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5168 + fput(file[DST].file);
5171 + * we have to call both since we don't know which place the file
5175 + flush_delayed_fput();
5177 + au_sbr_put(sb, file[DST].bindex);
5180 + fput(file[SRC].file);
5181 + au_sbr_put(sb, file[SRC].bindex);
5186 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5187 + struct au_cpup_reg_attr *h_src_attr)
5191 + struct path h_path;
5192 + struct inode *h_src_inode, *h_dst_inode;
5195 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5196 + l = i_size_read(h_src_inode);
5197 + if (cpg->len == -1 || l < cpg->len)
5200 + /* try stopping to update while we are referencing */
5201 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5202 + au_pin_hdir_unlock(cpg->pin);
5204 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5205 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5206 + h_src_attr->iflags = h_src_inode->i_flags;
5207 + if (!au_test_nfs(h_src_inode->i_sb))
5208 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5210 + inode_unlock(h_src_inode);
5211 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5212 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5214 + if (unlikely(err)) {
5215 + inode_unlock(h_src_inode);
5218 + h_src_attr->valid = 1;
5219 + if (!au_test_nfs(h_src_inode->i_sb)) {
5220 + err = au_cp_regular(cpg);
5221 + inode_unlock(h_src_inode);
5223 + inode_unlock(h_src_inode);
5224 + err = au_cp_regular(cpg);
5226 + rerr = au_pin_hdir_relock(cpg->pin);
5230 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5231 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5232 + h_dst_inode = d_inode(h_path.dentry);
5233 + spin_lock(&h_dst_inode->i_lock);
5234 + h_dst_inode->i_state |= I_LINKABLE;
5235 + spin_unlock(&h_dst_inode->i_lock);
5242 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5243 + struct inode *h_dir)
5246 + mm_segment_t old_fs;
5253 + sym.k = (void *)__get_free_page(GFP_NOFS);
5254 + if (unlikely(!sym.k))
5257 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5258 + old_fs = get_fs();
5259 + set_fs(KERNEL_DS);
5260 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5265 + sym.k[symlen] = 0;
5266 + err = vfsub_symlink(h_dir, h_path, sym.k);
5268 + free_page((unsigned long)sym.k);
5275 + * regardless 'acl' option, reset all ACL.
5276 + * All ACL will be copied up later from the original entry on the lower branch.
5278 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5281 + struct dentry *h_dentry;
5282 + struct inode *h_inode;
5284 + h_dentry = h_path->dentry;
5285 + h_inode = d_inode(h_dentry);
5286 + /* forget_all_cached_acls(h_inode)); */
5287 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5289 + if (err == -EOPNOTSUPP)
5292 + err = vfsub_acl_chmod(h_inode, mode);
5298 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5299 + struct inode *h_dir, struct path *h_path)
5302 + struct inode *dir, *inode;
5304 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5306 + if (err == -EOPNOTSUPP)
5308 + if (unlikely(err))
5312 + * strange behaviour from the users view,
5313 + * particularry setattr case
5315 + dir = d_inode(dst_parent);
5316 + if (au_ibtop(dir) == cpg->bdst)
5317 + au_cpup_attr_nlink(dir, /*force*/1);
5318 + inode = d_inode(cpg->dentry);
5319 + au_cpup_attr_nlink(inode, /*force*/1);
5325 +static noinline_for_stack
5326 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5327 + struct au_cpup_reg_attr *h_src_attr)
5331 + unsigned int mnt_flags;
5332 + unsigned char isdir, isreg, force;
5333 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5334 + struct au_dtime dt;
5335 + struct path h_path;
5336 + struct dentry *h_src, *h_dst, *h_parent;
5337 + struct inode *h_inode, *h_dir;
5338 + struct super_block *sb;
5340 + /* bsrc branch can be ro/rw. */
5341 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5342 + h_inode = d_inode(h_src);
5343 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5345 + /* try stopping to be referenced while we are creating */
5346 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5347 + if (au_ftest_cpup(cpg->flags, RENAME))
5348 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5349 + AUFS_WH_PFX_LEN));
5350 + h_parent = h_dst->d_parent; /* dir inode is locked */
5351 + h_dir = d_inode(h_parent);
5353 + AuDebugOn(h_parent != h_dst->d_parent);
5355 + sb = cpg->dentry->d_sb;
5356 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5358 + h_path.dentry = h_parent;
5359 + au_dtime_store(&dt, dst_parent, &h_path);
5361 + h_path.dentry = h_dst;
5365 + mode = h_inode->i_mode;
5366 + switch (mode & S_IFMT) {
5369 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5370 + /*want_excl*/true);
5372 + err = au_do_cpup_regular(cpg, h_src_attr);
5376 + err = vfsub_mkdir(h_dir, &h_path, mode);
5378 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5381 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5385 + AuDebugOn(!capable(CAP_MKNOD));
5389 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5392 + AuIOErr("Unknown inode type 0%o\n", mode);
5396 + err = au_reset_acl(h_dir, &h_path, mode);
5398 + mnt_flags = au_mntflags(sb);
5399 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5401 + && au_opt_test(mnt_flags, XINO)
5402 + && (h_inode->i_nlink == 1
5403 + || (h_inode->i_state & I_LINKABLE))
5404 + /* todo: unnecessary? */
5405 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5406 + && cpg->bdst < cpg->bsrc
5407 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5408 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5409 + /* ignore this error */
5414 + force = !!cpg->len;
5415 + if (cpg->len == -1)
5416 + force = !!i_size_read(h_inode);
5418 + au_fhsm_wrote(sb, cpg->bdst, force);
5422 + au_dtime_revert(&dt);
5426 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5429 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5430 + struct inode *h_dir;
5431 + aufs_bindex_t bdst;
5433 + dentry = cpg->dentry;
5435 + h_dentry = au_h_dptr(dentry, bdst);
5436 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5438 + au_set_h_dptr(dentry, bdst, NULL);
5439 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5441 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5442 + au_set_h_dptr(dentry, bdst, h_dentry);
5445 + parent = dget_parent(dentry);
5446 + h_parent = au_h_dptr(parent, bdst);
5448 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5449 + if (IS_ERR(h_path->dentry))
5450 + err = PTR_ERR(h_path->dentry);
5452 + if (unlikely(err))
5455 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5456 + h_dir = d_inode(h_parent);
5458 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5459 + /* no delegation since it is just created */
5460 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5462 + dput(h_path->dentry);
5469 + * copyup the @dentry from @bsrc to @bdst.
5470 + * the caller must set the both of lower dentries.
5471 + * @len is for truncating when it is -1 copyup the entire file.
5472 + * in link/rename cases, @dst_parent may be different from the real one.
5473 + * basic->bsrc can be larger than basic->bdst.
5474 + * aufs doesn't touch the credential so
5475 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5477 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5480 + aufs_bindex_t old_ibtop;
5481 + unsigned char isdir, plink;
5482 + struct dentry *h_src, *h_dst, *h_parent;
5483 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5484 + struct super_block *sb;
5485 + struct au_branch *br;
5486 + /* to reuduce stack size */
5488 + struct au_dtime dt;
5489 + struct path h_path;
5490 + struct au_cpup_reg_attr h_src_attr;
5494 + a = kmalloc(sizeof(*a), GFP_NOFS);
5497 + a->h_src_attr.valid = 0;
5499 + sb = cpg->dentry->d_sb;
5500 + br = au_sbr(sb, cpg->bdst);
5501 + a->h_path.mnt = au_br_mnt(br);
5502 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5503 + h_parent = h_dst->d_parent; /* dir inode is locked */
5504 + h_dir = d_inode(h_parent);
5507 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5508 + inode = d_inode(cpg->dentry);
5511 + dst_parent = dget_parent(cpg->dentry);
5515 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5516 + dst_inode = au_h_iptr(inode, cpg->bdst);
5518 + if (unlikely(!plink)) {
5520 + AuIOErr("hi%lu(i%lu) exists on b%d "
5521 + "but plink is disabled\n",
5522 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5526 + if (dst_inode->i_nlink) {
5527 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5529 + h_src = au_plink_lkup(inode, cpg->bdst);
5530 + err = PTR_ERR(h_src);
5531 + if (IS_ERR(h_src))
5533 + if (unlikely(d_is_negative(h_src))) {
5535 + AuIOErr("i%lu exists on b%d "
5536 + "but not pseudo-linked\n",
5537 + inode->i_ino, cpg->bdst);
5543 + a->h_path.dentry = h_parent;
5544 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5547 + a->h_path.dentry = h_dst;
5549 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5550 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5551 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5553 + au_dtime_revert(&a->dt);
5554 + if (unlikely(err == -EWOULDBLOCK)) {
5555 + pr_warn("cannot retry for NFSv4 delegation"
5556 + " for an internal link\n");
5562 + /* todo: cpup_wh_file? */
5564 + au_update_ibrange(inode, /*do_put_zero*/1);
5567 + isdir = S_ISDIR(inode->i_mode);
5568 + old_ibtop = au_ibtop(inode);
5569 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5570 + if (unlikely(err))
5572 + dst_inode = d_inode(h_dst);
5573 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5574 + /* todo: necessary? */
5575 + /* au_pin_hdir_unlock(cpg->pin); */
5577 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5578 + if (unlikely(err)) {
5579 + /* todo: necessary? */
5580 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5581 + inode_unlock(dst_inode);
5585 + if (cpg->bdst < old_ibtop) {
5586 + if (S_ISREG(inode->i_mode)) {
5587 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5588 + if (unlikely(err)) {
5589 + /* ignore an error */
5590 + /* au_pin_hdir_relock(cpg->pin); */
5591 + inode_unlock(dst_inode);
5595 + au_set_ibtop(inode, cpg->bdst);
5597 + au_set_ibbot(inode, cpg->bdst);
5598 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5599 + au_hi_flags(inode, isdir));
5601 + /* todo: necessary? */
5602 + /* err = au_pin_hdir_relock(cpg->pin); */
5603 + inode_unlock(dst_inode);
5604 + if (unlikely(err))
5607 + src_inode = d_inode(h_src);
5609 + && (src_inode->i_nlink > 1
5610 + || src_inode->i_state & I_LINKABLE)
5612 + au_plink_append(inode, cpg->bdst, h_dst);
5614 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5615 + a->h_path.dentry = h_dst;
5616 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5619 + goto out_parent; /* success */
5623 + a->h_path.dentry = h_parent;
5624 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5625 + a->h_path.dentry = h_dst;
5627 + if (d_is_positive(h_dst)) {
5629 + /* no delegation since it is just created */
5630 + rerr = vfsub_unlink(h_dir, &a->h_path,
5631 + /*delegated*/NULL, /*force*/0);
5633 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5635 + au_dtime_revert(&a->dt);
5637 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5647 +#if 0 /* reserved */
5648 +struct au_cpup_single_args {
5650 + struct au_cp_generic *cpg;
5651 + struct dentry *dst_parent;
5654 +static void au_call_cpup_single(void *args)
5656 + struct au_cpup_single_args *a = args;
5658 + au_pin_hdir_acquire_nest(a->cpg->pin);
5659 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5660 + au_pin_hdir_release(a->cpg->pin);
5665 + * prevent SIGXFSZ in copy-up.
5666 + * testing CAP_MKNOD is for generic fs,
5667 + * but CAP_FSETID is for xfs only, currently.
5669 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5672 + struct super_block *sb;
5673 + struct inode *h_dir;
5676 + sb = au_pinned_parent(pin)->d_sb;
5677 + if (!au_wkq_test()
5678 + && (!au_sbi(sb)->si_plink_maint_pid
5679 + || au_plink_maint(sb, AuLock_NOPLM))) {
5680 + switch (mode & S_IFMT) {
5682 + /* no condition about RLIMIT_FSIZE and the file size */
5687 + do_sio = !capable(CAP_MKNOD);
5691 + do_sio = ((mode & (S_ISUID | S_ISGID))
5692 + && !capable(CAP_FSETID));
5693 + /* this workaround may be removed in the future */
5695 + h_dir = au_pinned_h_dir(pin);
5696 + do_sio = h_dir->i_mode & S_ISVTX;
5703 +#if 0 /* reserved */
5704 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5707 + struct dentry *h_dentry;
5709 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5710 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5711 + err = au_cpup_single(cpg, dst_parent);
5713 + struct au_cpup_single_args args = {
5716 + .dst_parent = dst_parent
5718 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5719 + if (unlikely(wkq_err))
5728 + * copyup the @dentry from the first active lower branch to @bdst,
5729 + * using au_cpup_single().
5731 +static int au_cpup_simple(struct au_cp_generic *cpg)
5734 + unsigned int flags_orig;
5735 + struct dentry *dentry;
5737 + AuDebugOn(cpg->bsrc < 0);
5739 + dentry = cpg->dentry;
5740 + DiMustWriteLock(dentry);
5742 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5744 + flags_orig = cpg->flags;
5745 + au_fset_cpup(cpg->flags, RENAME);
5746 + err = au_cpup_single(cpg, NULL);
5747 + cpg->flags = flags_orig;
5749 + return 0; /* success */
5752 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5753 + au_set_dbtop(dentry, cpg->bsrc);
5759 +struct au_cpup_simple_args {
5761 + struct au_cp_generic *cpg;
5764 +static void au_call_cpup_simple(void *args)
5766 + struct au_cpup_simple_args *a = args;
5768 + au_pin_hdir_acquire_nest(a->cpg->pin);
5769 + *a->errp = au_cpup_simple(a->cpg);
5770 + au_pin_hdir_release(a->cpg->pin);
5773 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5776 + struct dentry *dentry, *parent;
5777 + struct file *h_file;
5778 + struct inode *h_dir;
5780 + dentry = cpg->dentry;
5782 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5783 + AuDebugOn(cpg->bsrc < 0);
5784 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5785 + err = PTR_ERR(h_file);
5786 + if (IS_ERR(h_file))
5790 + parent = dget_parent(dentry);
5791 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5792 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5793 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5794 + err = au_cpup_simple(cpg);
5796 + struct au_cpup_simple_args args = {
5800 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5801 + if (unlikely(wkq_err))
5807 + au_h_open_post(dentry, cpg->bsrc, h_file);
5813 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5815 + aufs_bindex_t bsrc, bbot;
5816 + struct dentry *dentry, *h_dentry;
5818 + if (cpg->bsrc < 0) {
5819 + dentry = cpg->dentry;
5820 + bbot = au_dbbot(dentry);
5821 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5822 + h_dentry = au_h_dptr(dentry, bsrc);
5824 + AuDebugOn(d_is_negative(h_dentry));
5828 + AuDebugOn(bsrc > bbot);
5831 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5832 + return au_do_sio_cpup_simple(cpg);
5835 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5837 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5838 + return au_do_sio_cpup_simple(cpg);
5841 +/* ---------------------------------------------------------------------- */
5844 + * copyup the deleted file for writing.
5846 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5847 + struct file *file)
5850 + unsigned int flags_orig;
5851 + aufs_bindex_t bsrc_orig;
5852 + struct au_dinfo *dinfo;
5854 + struct au_hdentry *hd;
5855 + struct dentry *h_dentry;
5858 + dinfo = au_di(cpg->dentry);
5859 + AuRwMustWriteLock(&dinfo->di_rwsem);
5861 + bsrc_orig = cpg->bsrc;
5862 + cpg->bsrc = dinfo->di_btop;
5863 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5864 + hdst.h_dentry = hdst.hd->hd_dentry;
5865 + hdst.hd->hd_dentry = wh_dentry;
5866 + dinfo->di_btop = cpg->bdst;
5868 + hsrc.h_dentry = NULL;
5870 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5871 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5872 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5874 + flags_orig = cpg->flags;
5875 + cpg->flags = !AuCpup_DTIME;
5876 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5877 + cpg->flags = flags_orig;
5880 + err = au_reopen_nondir(file);
5881 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5883 + hdst.hd->hd_dentry = hdst.h_dentry;
5884 + dinfo->di_btop = cpg->bsrc;
5885 + cpg->bsrc = bsrc_orig;
5890 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5893 + aufs_bindex_t bdst;
5894 + struct au_dtime dt;
5895 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5896 + struct au_branch *br;
5897 + struct path h_path;
5899 + dentry = cpg->dentry;
5901 + br = au_sbr(dentry->d_sb, bdst);
5902 + parent = dget_parent(dentry);
5903 + h_parent = au_h_dptr(parent, bdst);
5904 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5905 + err = PTR_ERR(wh_dentry);
5906 + if (IS_ERR(wh_dentry))
5909 + h_path.dentry = h_parent;
5910 + h_path.mnt = au_br_mnt(br);
5911 + au_dtime_store(&dt, parent, &h_path);
5912 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5913 + if (unlikely(err))
5917 + h_path.dentry = wh_dentry;
5918 + if (!d_is_dir(wh_dentry)) {
5919 + /* no delegation since it is just created */
5920 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5921 + /*delegated*/NULL, /*force*/0);
5923 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5924 + if (unlikely(err)) {
5925 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5929 + au_dtime_revert(&dt);
5930 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5939 +struct au_cpup_wh_args {
5941 + struct au_cp_generic *cpg;
5942 + struct file *file;
5945 +static void au_call_cpup_wh(void *args)
5947 + struct au_cpup_wh_args *a = args;
5949 + au_pin_hdir_acquire_nest(a->cpg->pin);
5950 + *a->errp = au_cpup_wh(a->cpg, a->file);
5951 + au_pin_hdir_release(a->cpg->pin);
5954 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5957 + aufs_bindex_t bdst;
5958 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5959 + struct inode *dir, *h_dir, *h_tmpdir;
5960 + struct au_wbr *wbr;
5961 + struct au_pin wh_pin, *pin_orig;
5963 + dentry = cpg->dentry;
5965 + parent = dget_parent(dentry);
5966 + dir = d_inode(parent);
5969 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5972 + if (!h_dir->i_nlink) {
5973 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5974 + h_orph = wbr->wbr_orph;
5976 + h_parent = dget(au_h_dptr(parent, bdst));
5977 + au_set_h_dptr(parent, bdst, dget(h_orph));
5978 + h_tmpdir = d_inode(h_orph);
5979 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5981 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5982 + /* todo: au_h_open_pre()? */
5984 + pin_orig = cpg->pin;
5985 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5986 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5987 + cpg->pin = &wh_pin;
5990 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5991 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5992 + err = au_cpup_wh(cpg, file);
5994 + struct au_cpup_wh_args args = {
5999 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6000 + if (unlikely(wkq_err))
6005 + inode_unlock(h_tmpdir);
6006 + /* todo: au_h_open_post()? */
6007 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6008 + au_set_h_dptr(parent, bdst, h_parent);
6009 + AuDebugOn(!pin_orig);
6010 + cpg->pin = pin_orig;
6018 +/* ---------------------------------------------------------------------- */
6021 + * generic routine for both of copy-up and copy-down.
6023 +/* cf. revalidate function in file.c */
6024 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6025 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6026 + struct au_pin *pin,
6027 + struct dentry *h_parent, void *arg),
6031 + struct au_pin pin;
6032 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6035 + parent = dget_parent(dentry);
6036 + if (IS_ROOT(parent))
6039 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6040 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6042 + /* do not use au_dpage */
6043 + real_parent = parent;
6046 + parent = dget_parent(dentry);
6047 + h_parent = au_h_dptr(parent, bdst);
6049 + goto out; /* success */
6051 + /* find top dir which is necessary to cpup */
6055 + parent = dget_parent(d);
6056 + di_read_lock_parent3(parent, !AuLock_IR);
6057 + h_parent = au_h_dptr(parent, bdst);
6058 + di_read_unlock(parent, !AuLock_IR);
6059 + } while (!h_parent);
6061 + if (d != real_parent)
6062 + di_write_lock_child3(d);
6064 + /* somebody else might create while we were sleeping */
6065 + h_dentry = au_h_dptr(d, bdst);
6066 + if (!h_dentry || d_is_negative(h_dentry)) {
6068 + au_update_dbtop(d);
6070 + au_pin_set_dentry(&pin, d);
6071 + err = au_do_pin(&pin);
6073 + err = cp(d, bdst, &pin, h_parent, arg);
6078 + if (d != real_parent)
6079 + di_write_unlock(d);
6080 + if (unlikely(err))
6089 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6090 + struct au_pin *pin,
6091 + struct dentry *h_parent __maybe_unused,
6092 + void *arg __maybe_unused)
6094 + struct au_cp_generic cpg = {
6100 + .flags = AuCpup_DTIME
6102 + return au_sio_cpup_simple(&cpg);
6105 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6107 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6110 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6113 + struct dentry *parent;
6114 + struct inode *dir;
6116 + parent = dget_parent(dentry);
6117 + dir = d_inode(parent);
6119 + if (au_h_iptr(dir, bdst))
6122 + di_read_unlock(parent, AuLock_IR);
6123 + di_write_lock_parent(parent);
6124 + /* someone else might change our inode while we were sleeping */
6125 + if (!au_h_iptr(dir, bdst))
6126 + err = au_cpup_dirs(dentry, bdst);
6127 + di_downgrade_lock(parent, AuLock_IR);
6133 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6134 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6135 +++ linux/fs/aufs/cpup.h 2017-07-29 12:14:25.899708630 +0200
6138 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6140 + * This program, aufs is free software; you can redistribute it and/or modify
6141 + * it under the terms of the GNU General Public License as published by
6142 + * the Free Software Foundation; either version 2 of the License, or
6143 + * (at your option) any later version.
6145 + * This program is distributed in the hope that it will be useful,
6146 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6147 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6148 + * GNU General Public License for more details.
6150 + * You should have received a copy of the GNU General Public License
6151 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6155 + * copy-up/down functions
6158 +#ifndef __AUFS_CPUP_H__
6159 +#define __AUFS_CPUP_H__
6163 +#include <linux/path.h>
6169 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6170 +void au_cpup_attr_timesizes(struct inode *inode);
6171 +void au_cpup_attr_nlink(struct inode *inode, int force);
6172 +void au_cpup_attr_changeable(struct inode *inode);
6173 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6174 +void au_cpup_attr_all(struct inode *inode, int force);
6176 +/* ---------------------------------------------------------------------- */
6178 +struct au_cp_generic {
6179 + struct dentry *dentry;
6180 + aufs_bindex_t bdst, bsrc;
6182 + struct au_pin *pin;
6183 + unsigned int flags;
6187 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6188 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6190 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6191 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6193 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6195 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6196 + the branch is marked as RO */
6198 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6199 +#define au_fset_cpup(flags, name) \
6200 + do { (flags) |= AuCpup_##name; } while (0)
6201 +#define au_fclr_cpup(flags, name) \
6202 + do { (flags) &= ~AuCpup_##name; } while (0)
6204 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6205 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6206 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6207 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6209 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6210 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6211 + struct au_pin *pin,
6212 + struct dentry *h_parent, void *arg),
6214 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6215 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6217 +/* ---------------------------------------------------------------------- */
6219 +/* keep timestamps when copyup */
6221 + struct dentry *dt_dentry;
6222 + struct path dt_h_path;
6223 + struct timespec dt_atime, dt_mtime;
6225 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6226 + struct path *h_path);
6227 +void au_dtime_revert(struct au_dtime *dt);
6229 +#endif /* __KERNEL__ */
6230 +#endif /* __AUFS_CPUP_H__ */
6231 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6232 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6233 +++ linux/fs/aufs/dbgaufs.c 2017-07-29 12:14:25.899708630 +0200
6236 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6238 + * This program, aufs is free software; you can redistribute it and/or modify
6239 + * it under the terms of the GNU General Public License as published by
6240 + * the Free Software Foundation; either version 2 of the License, or
6241 + * (at your option) any later version.
6243 + * This program is distributed in the hope that it will be useful,
6244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6246 + * GNU General Public License for more details.
6248 + * You should have received a copy of the GNU General Public License
6249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6253 + * debugfs interface
6256 +#include <linux/debugfs.h>
6259 +#ifndef CONFIG_SYSFS
6260 +#error DEBUG_FS depends upon SYSFS
6263 +static struct dentry *dbgaufs;
6264 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6266 +/* 20 is max digits length of ulong 64 */
6267 +struct dbgaufs_arg {
6273 + * common function for all XINO files
6275 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6276 + struct file *file)
6278 + kfree(file->private_data);
6282 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6286 + struct dbgaufs_arg *p;
6289 + p = kmalloc(sizeof(*p), GFP_NOFS);
6295 + file->private_data = p;
6299 + err = vfsub_getattr(&xf->f_path, &st);
6303 + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n",
6304 + (long)file_count(xf), st.blocks, st.blksize,
6305 + (long long)st.size);
6307 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6308 + st.blocks, st.blksize,
6309 + (long long)st.size);
6310 + AuDebugOn(p->n >= sizeof(p->a));
6312 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6321 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6322 + size_t count, loff_t *ppos)
6324 + struct dbgaufs_arg *p;
6326 + p = file->private_data;
6327 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6330 +/* ---------------------------------------------------------------------- */
6332 +struct dbgaufs_plink_arg {
6337 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6338 + struct file *file)
6340 + free_page((unsigned long)file->private_data);
6344 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6346 + int err, i, limit;
6347 + unsigned long n, sum;
6348 + struct dbgaufs_plink_arg *p;
6349 + struct au_sbinfo *sbinfo;
6350 + struct super_block *sb;
6351 + struct au_sphlhead *sphl;
6354 + p = (void *)get_zeroed_page(GFP_NOFS);
6359 + sbinfo = inode->i_private;
6360 + sb = sbinfo->si_sb;
6361 + si_noflush_read_lock(sb);
6362 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6363 + limit = PAGE_SIZE - sizeof(p->n);
6365 + /* the number of buckets */
6366 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6371 + for (i = 0, sphl = sbinfo->si_plink;
6372 + i < AuPlink_NHASH;
6374 + n = au_sphl_count(sphl);
6377 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6380 + if (unlikely(limit <= 0))
6383 + p->a[p->n - 1] = '\n';
6385 + /* the sum of plinks */
6386 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6389 + if (unlikely(limit <= 0))
6392 +#define str "1\n0\n0\n"
6393 + p->n = sizeof(str) - 1;
6394 + strcpy(p->a, str);
6397 + si_read_unlock(sb);
6400 + file->private_data = p;
6401 + goto out; /* success */
6404 + free_page((unsigned long)p);
6409 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6410 + size_t count, loff_t *ppos)
6412 + struct dbgaufs_plink_arg *p;
6414 + p = file->private_data;
6415 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6418 +static const struct file_operations dbgaufs_plink_fop = {
6419 + .owner = THIS_MODULE,
6420 + .open = dbgaufs_plink_open,
6421 + .release = dbgaufs_plink_release,
6422 + .read = dbgaufs_plink_read
6425 +/* ---------------------------------------------------------------------- */
6427 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6430 + struct au_sbinfo *sbinfo;
6431 + struct super_block *sb;
6433 + sbinfo = inode->i_private;
6434 + sb = sbinfo->si_sb;
6435 + si_noflush_read_lock(sb);
6436 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6437 + si_read_unlock(sb);
6441 +static const struct file_operations dbgaufs_xib_fop = {
6442 + .owner = THIS_MODULE,
6443 + .open = dbgaufs_xib_open,
6444 + .release = dbgaufs_xi_release,
6445 + .read = dbgaufs_xi_read
6448 +/* ---------------------------------------------------------------------- */
6450 +#define DbgaufsXi_PREFIX "xi"
6452 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6456 + struct au_sbinfo *sbinfo;
6457 + struct super_block *sb;
6459 + struct qstr *name;
6463 + name = &file->f_path.dentry->d_name;
6464 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6465 + || memcmp(name->name, DbgaufsXi_PREFIX,
6466 + sizeof(DbgaufsXi_PREFIX) - 1)))
6468 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6469 + if (unlikely(err))
6472 + sbinfo = inode->i_private;
6473 + sb = sbinfo->si_sb;
6474 + si_noflush_read_lock(sb);
6475 + if (l <= au_sbbot(sb)) {
6476 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6477 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6480 + si_read_unlock(sb);
6486 +static const struct file_operations dbgaufs_xino_fop = {
6487 + .owner = THIS_MODULE,
6488 + .open = dbgaufs_xino_open,
6489 + .release = dbgaufs_xi_release,
6490 + .read = dbgaufs_xi_read
6493 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6495 + aufs_bindex_t bbot;
6496 + struct au_branch *br;
6497 + struct au_xino_file *xi;
6499 + if (!au_sbi(sb)->si_dbgaufs)
6502 + bbot = au_sbbot(sb);
6503 + for (; bindex <= bbot; bindex++) {
6504 + br = au_sbr(sb, bindex);
6505 + xi = &br->br_xino;
6506 + /* debugfs acquires the parent i_mutex */
6508 + debugfs_remove(xi->xi_dbgaufs);
6510 + xi->xi_dbgaufs = NULL;
6514 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6516 + struct au_sbinfo *sbinfo;
6517 + struct dentry *parent;
6518 + struct au_branch *br;
6519 + struct au_xino_file *xi;
6520 + aufs_bindex_t bbot;
6521 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6523 + sbinfo = au_sbi(sb);
6524 + parent = sbinfo->si_dbgaufs;
6528 + bbot = au_sbbot(sb);
6529 + for (; bindex <= bbot; bindex++) {
6530 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6531 + br = au_sbr(sb, bindex);
6532 + xi = &br->br_xino;
6533 + AuDebugOn(xi->xi_dbgaufs);
6534 + /* debugfs acquires the parent i_mutex */
6536 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6537 + sbinfo, &dbgaufs_xino_fop);
6539 + /* ignore an error */
6540 + if (unlikely(!xi->xi_dbgaufs))
6541 + AuWarn1("failed %s under debugfs\n", name);
6545 +/* ---------------------------------------------------------------------- */
6547 +#ifdef CONFIG_AUFS_EXPORT
6548 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6551 + struct au_sbinfo *sbinfo;
6552 + struct super_block *sb;
6554 + sbinfo = inode->i_private;
6555 + sb = sbinfo->si_sb;
6556 + si_noflush_read_lock(sb);
6557 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6558 + si_read_unlock(sb);
6562 +static const struct file_operations dbgaufs_xigen_fop = {
6563 + .owner = THIS_MODULE,
6564 + .open = dbgaufs_xigen_open,
6565 + .release = dbgaufs_xi_release,
6566 + .read = dbgaufs_xi_read
6569 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6574 + * This function is a dynamic '__init' function actually,
6575 + * so the tiny check for si_rwsem is unnecessary.
6577 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6580 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6581 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6582 + &dbgaufs_xigen_fop);
6583 + if (sbinfo->si_dbgaufs_xigen)
6589 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6593 +#endif /* CONFIG_AUFS_EXPORT */
6595 +/* ---------------------------------------------------------------------- */
6597 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6600 + * This function is a dynamic '__fin' function actually,
6601 + * so the tiny check for si_rwsem is unnecessary.
6603 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6605 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6606 + sbinfo->si_dbgaufs = NULL;
6607 + kobject_put(&sbinfo->si_kobj);
6610 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6613 + char name[SysaufsSiNameLen];
6616 + * This function is a dynamic '__init' function actually,
6617 + * so the tiny check for si_rwsem is unnecessary.
6619 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6623 + AuErr1("/debug/aufs is uninitialized\n");
6628 + sysaufs_name(sbinfo, name);
6629 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6630 + if (unlikely(!sbinfo->si_dbgaufs))
6632 + kobject_get(&sbinfo->si_kobj);
6634 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6635 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6636 + &dbgaufs_xib_fop);
6637 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6640 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6641 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6642 + &dbgaufs_plink_fop);
6643 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6646 + err = dbgaufs_xigen_init(sbinfo);
6648 + goto out; /* success */
6651 + dbgaufs_si_fin(sbinfo);
6656 +/* ---------------------------------------------------------------------- */
6658 +void dbgaufs_fin(void)
6660 + debugfs_remove(dbgaufs);
6663 +int __init dbgaufs_init(void)
6668 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6673 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6674 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6675 +++ linux/fs/aufs/dbgaufs.h 2017-07-29 12:14:25.899708630 +0200
6678 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6680 + * This program, aufs is free software; you can redistribute it and/or modify
6681 + * it under the terms of the GNU General Public License as published by
6682 + * the Free Software Foundation; either version 2 of the License, or
6683 + * (at your option) any later version.
6685 + * This program is distributed in the hope that it will be useful,
6686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6688 + * GNU General Public License for more details.
6690 + * You should have received a copy of the GNU General Public License
6691 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6695 + * debugfs interface
6698 +#ifndef __DBGAUFS_H__
6699 +#define __DBGAUFS_H__
6703 +struct super_block;
6706 +#ifdef CONFIG_DEBUG_FS
6708 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6709 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6710 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6711 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6712 +void dbgaufs_fin(void);
6713 +int __init dbgaufs_init(void);
6715 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6716 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6717 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6718 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6719 +AuStubVoid(dbgaufs_fin, void)
6720 +AuStubInt0(__init dbgaufs_init, void)
6721 +#endif /* CONFIG_DEBUG_FS */
6723 +#endif /* __KERNEL__ */
6724 +#endif /* __DBGAUFS_H__ */
6725 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6726 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6727 +++ linux/fs/aufs/dcsub.c 2017-07-29 12:14:25.899708630 +0200
6730 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6732 + * This program, aufs is free software; you can redistribute it and/or modify
6733 + * it under the terms of the GNU General Public License as published by
6734 + * the Free Software Foundation; either version 2 of the License, or
6735 + * (at your option) any later version.
6737 + * This program is distributed in the hope that it will be useful,
6738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6740 + * GNU General Public License for more details.
6742 + * You should have received a copy of the GNU General Public License
6743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6747 + * sub-routines for dentry cache
6752 +static void au_dpage_free(struct au_dpage *dpage)
6755 + struct dentry **p;
6757 + p = dpage->dentries;
6758 + for (i = 0; i < dpage->ndentry; i++)
6760 + free_page((unsigned long)dpage->dentries);
6763 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6769 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6770 + if (unlikely(!dpages->dpages))
6773 + p = (void *)__get_free_page(gfp);
6777 + dpages->dpages[0].ndentry = 0;
6778 + dpages->dpages[0].dentries = p;
6779 + dpages->ndpage = 1;
6780 + return 0; /* success */
6783 + kfree(dpages->dpages);
6788 +void au_dpages_free(struct au_dcsub_pages *dpages)
6791 + struct au_dpage *p;
6793 + p = dpages->dpages;
6794 + for (i = 0; i < dpages->ndpage; i++)
6795 + au_dpage_free(p++);
6796 + kfree(dpages->dpages);
6799 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6800 + struct dentry *dentry, gfp_t gfp)
6803 + struct au_dpage *dpage;
6806 + dpage = dpages->dpages + dpages->ndpage - 1;
6807 + sz = PAGE_SIZE / sizeof(dentry);
6808 + if (unlikely(dpage->ndentry >= sz)) {
6809 + AuLabel(new dpage);
6811 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6812 + p = au_kzrealloc(dpages->dpages, sz,
6813 + sz + sizeof(*dpages->dpages), gfp,
6818 + dpages->dpages = p;
6819 + dpage = dpages->dpages + dpages->ndpage;
6820 + p = (void *)__get_free_page(gfp);
6824 + dpage->ndentry = 0;
6825 + dpage->dentries = p;
6829 + AuDebugOn(au_dcount(dentry) <= 0);
6830 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6831 + return 0; /* success */
6837 +/* todo: BAD approach */
6838 +/* copied from linux/fs/dcache.c */
6846 +extern void d_walk(struct dentry *parent, void *data,
6847 + enum d_walk_ret (*enter)(void *, struct dentry *),
6848 + void (*finish)(void *));
6850 +struct ac_dpages_arg {
6852 + struct au_dcsub_pages *dpages;
6853 + struct super_block *sb;
6854 + au_dpages_test test;
6858 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6860 + enum d_walk_ret ret;
6861 + struct ac_dpages_arg *arg = _arg;
6863 + ret = D_WALK_CONTINUE;
6864 + if (dentry->d_sb == arg->sb
6865 + && !IS_ROOT(dentry)
6866 + && au_dcount(dentry) > 0
6868 + && (!arg->test || arg->test(dentry, arg->arg))) {
6869 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6870 + if (unlikely(arg->err))
6871 + ret = D_WALK_QUIT;
6877 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6878 + au_dpages_test test, void *arg)
6880 + struct ac_dpages_arg args = {
6888 + d_walk(root, &args, au_call_dpages_append, NULL);
6893 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6894 + int do_include, au_dpages_test test, void *arg)
6899 + write_seqlock(&rename_lock);
6900 + spin_lock(&dentry->d_lock);
6902 + && au_dcount(dentry) > 0
6903 + && (!test || test(dentry, arg)))
6904 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6905 + spin_unlock(&dentry->d_lock);
6906 + if (unlikely(err))
6910 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6913 + while (!IS_ROOT(dentry)) {
6914 + dentry = dentry->d_parent; /* rename_lock is locked */
6915 + spin_lock(&dentry->d_lock);
6916 + if (au_dcount(dentry) > 0
6917 + && (!test || test(dentry, arg)))
6918 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6919 + spin_unlock(&dentry->d_lock);
6920 + if (unlikely(err))
6925 + write_sequnlock(&rename_lock);
6929 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6931 + return au_di(dentry) && dentry->d_sb == arg;
6934 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6935 + struct dentry *dentry, int do_include)
6937 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6938 + au_dcsub_dpages_aufs, dentry->d_sb);
6941 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6943 + struct path path[2] = {
6952 + return path_is_under(path + 0, path + 1);
6954 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6955 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6956 +++ linux/fs/aufs/dcsub.h 2017-07-29 12:14:25.899708630 +0200
6959 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6961 + * This program, aufs is free software; you can redistribute it and/or modify
6962 + * it under the terms of the GNU General Public License as published by
6963 + * the Free Software Foundation; either version 2 of the License, or
6964 + * (at your option) any later version.
6966 + * This program is distributed in the hope that it will be useful,
6967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6969 + * GNU General Public License for more details.
6971 + * You should have received a copy of the GNU General Public License
6972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6976 + * sub-routines for dentry cache
6979 +#ifndef __AUFS_DCSUB_H__
6980 +#define __AUFS_DCSUB_H__
6984 +#include <linux/dcache.h>
6985 +#include <linux/fs.h>
6989 + struct dentry **dentries;
6992 +struct au_dcsub_pages {
6994 + struct au_dpage *dpages;
6997 +/* ---------------------------------------------------------------------- */
7000 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7001 +void au_dpages_free(struct au_dcsub_pages *dpages);
7002 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7003 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7004 + au_dpages_test test, void *arg);
7005 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7006 + int do_include, au_dpages_test test, void *arg);
7007 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7008 + struct dentry *dentry, int do_include);
7009 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7011 +/* ---------------------------------------------------------------------- */
7014 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7015 + * include/linux/dcache.h. Try them (in the future).
7018 +static inline int au_d_hashed_positive(struct dentry *d)
7021 + struct inode *inode = d_inode(d);
7024 + if (unlikely(d_unhashed(d)
7025 + || d_is_negative(d)
7026 + || !inode->i_nlink))
7031 +static inline int au_d_linkable(struct dentry *d)
7034 + struct inode *inode = d_inode(d);
7036 + err = au_d_hashed_positive(d);
7038 + && d_is_positive(d)
7039 + && (inode->i_state & I_LINKABLE))
7044 +static inline int au_d_alive(struct dentry *d)
7047 + struct inode *inode;
7051 + err = au_d_hashed_positive(d);
7053 + inode = d_inode(d);
7054 + if (unlikely(d_unlinked(d)
7055 + || d_is_negative(d)
7056 + || !inode->i_nlink))
7062 +static inline int au_alive_dir(struct dentry *d)
7066 + err = au_d_alive(d);
7067 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7072 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7074 + return a->len == b->len
7075 + && !memcmp(a->name, b->name, a->len);
7080 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7082 + * the type of d_lockref.count became int, but the inlined function d_count()
7083 + * still returns unsigned int.
7084 + * I don't know why. Maybe it is for every d_count() users?
7085 + * Anyway au_dcount() lives on.
7087 +static inline int au_dcount(struct dentry *d)
7089 + return (int)d_count(d);
7092 +#endif /* __KERNEL__ */
7093 +#endif /* __AUFS_DCSUB_H__ */
7094 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7095 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7096 +++ linux/fs/aufs/debug.c 2017-07-29 12:14:25.899708630 +0200
7099 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7101 + * This program, aufs is free software; you can redistribute it and/or modify
7102 + * it under the terms of the GNU General Public License as published by
7103 + * the Free Software Foundation; either version 2 of the License, or
7104 + * (at your option) any later version.
7106 + * This program is distributed in the hope that it will be useful,
7107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7109 + * GNU General Public License for more details.
7111 + * You should have received a copy of the GNU General Public License
7112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7116 + * debug print functions
7121 +/* Returns 0, or -errno. arg is in kp->arg. */
7122 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7126 + err = kstrtoint(val, 0, &n);
7136 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7137 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7142 + return sprintf(buffer, "%d", atomic_read(a));
7145 +static struct kernel_param_ops param_ops_atomic_t = {
7146 + .set = param_atomic_t_set,
7147 + .get = param_atomic_t_get
7148 + /* void (*free)(void *arg) */
7151 +atomic_t aufs_debug = ATOMIC_INIT(0);
7152 +MODULE_PARM_DESC(debug, "debug print");
7153 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7155 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7156 +char *au_plevel = KERN_DEBUG;
7157 +#define dpri(fmt, ...) do { \
7159 + && strcmp(au_plevel, KERN_DEBUG)) \
7160 + || au_debug_test()) \
7161 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7164 +/* ---------------------------------------------------------------------- */
7166 +void au_dpri_whlist(struct au_nhash *whlist)
7168 + unsigned long ul, n;
7169 + struct hlist_head *head;
7170 + struct au_vdir_wh *pos;
7172 + n = whlist->nh_num;
7173 + head = whlist->nh_head;
7174 + for (ul = 0; ul < n; ul++) {
7175 + hlist_for_each_entry(pos, head, wh_hash)
7176 + dpri("b%d, %.*s, %d\n",
7178 + pos->wh_str.len, pos->wh_str.name,
7184 +void au_dpri_vdir(struct au_vdir *vdir)
7187 + union au_vdir_deblk_p p;
7190 + if (!vdir || IS_ERR(vdir)) {
7191 + dpri("err %ld\n", PTR_ERR(vdir));
7195 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7196 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7197 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7198 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7199 + p.deblk = vdir->vd_deblk[ul];
7201 + dpri("[%lu]: %p\n", ul, o);
7205 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7206 + struct dentry *wh)
7211 + if (!inode || IS_ERR(inode)) {
7212 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7216 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7217 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7218 + && sizeof(inode->i_blocks) != sizeof(u64));
7220 + n = (void *)wh->d_name.name;
7221 + l = wh->d_name.len;
7224 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7225 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7227 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7228 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7229 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7230 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7231 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7232 + inode->i_state, inode->i_flags, inode->i_version,
7233 + inode->i_generation,
7234 + l ? ", wh " : "", l, n);
7238 +void au_dpri_inode(struct inode *inode)
7240 + struct au_iinfo *iinfo;
7241 + struct au_hinode *hi;
7242 + aufs_bindex_t bindex;
7245 + err = do_pri_inode(-1, inode, -1, NULL);
7246 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7249 + iinfo = au_ii(inode);
7250 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7251 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7252 + if (iinfo->ii_btop < 0)
7255 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7256 + hi = au_hinode(iinfo, bindex);
7258 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7262 +void au_dpri_dalias(struct inode *inode)
7266 + spin_lock(&inode->i_lock);
7267 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7268 + au_dpri_dentry(d);
7269 + spin_unlock(&inode->i_lock);
7272 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7274 + struct dentry *wh = NULL;
7276 + struct inode *inode;
7277 + struct au_iinfo *iinfo;
7278 + struct au_hinode *hi;
7280 + if (!dentry || IS_ERR(dentry)) {
7281 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7284 + /* do not call dget_parent() here */
7285 + /* note: access d_xxx without d_lock */
7286 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7287 + bindex, dentry, dentry,
7288 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7289 + au_dcount(dentry), dentry->d_flags,
7290 + d_unhashed(dentry) ? "un" : "");
7293 + if (d_is_positive(dentry))
7294 + inode = d_inode(dentry);
7296 + && au_test_aufs(dentry->d_sb)
7298 + && !au_is_bad_inode(inode)) {
7299 + iinfo = au_ii(inode);
7300 + hi = au_hinode(iinfo, bindex);
7302 + wh = hi->hi_whdentry;
7304 + do_pri_inode(bindex, inode, hn, wh);
7308 +void au_dpri_dentry(struct dentry *dentry)
7310 + struct au_dinfo *dinfo;
7311 + aufs_bindex_t bindex;
7314 + err = do_pri_dentry(-1, dentry);
7315 + if (err || !au_test_aufs(dentry->d_sb))
7318 + dinfo = au_di(dentry);
7321 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7322 + dinfo->di_btop, dinfo->di_bbot,
7323 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7324 + dinfo->di_tmpfile);
7325 + if (dinfo->di_btop < 0)
7327 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7328 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7331 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7335 + if (!file || IS_ERR(file)) {
7336 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7341 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7342 + && au_test_aufs(file->f_path.dentry->d_sb)
7344 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7345 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7346 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7347 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7348 + file->f_version, file->f_pos, a);
7349 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7350 + do_pri_dentry(bindex, file->f_path.dentry);
7354 +void au_dpri_file(struct file *file)
7356 + struct au_finfo *finfo;
7357 + struct au_fidir *fidir;
7358 + struct au_hfile *hfile;
7359 + aufs_bindex_t bindex;
7362 + err = do_pri_file(-1, file);
7364 + || IS_ERR_OR_NULL(file->f_path.dentry)
7365 + || !au_test_aufs(file->f_path.dentry->d_sb))
7368 + finfo = au_fi(file);
7371 + if (finfo->fi_btop < 0)
7373 + fidir = finfo->fi_hdir;
7375 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7377 + for (bindex = finfo->fi_btop;
7378 + bindex >= 0 && bindex <= fidir->fd_bbot;
7380 + hfile = fidir->fd_hfile + bindex;
7381 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7385 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7387 + struct vfsmount *mnt;
7388 + struct super_block *sb;
7390 + if (!br || IS_ERR(br))
7392 + mnt = au_br_mnt(br);
7393 + if (!mnt || IS_ERR(mnt))
7396 + if (!sb || IS_ERR(sb))
7399 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7400 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7402 + bindex, br->br_perm, br->br_id, au_br_count(br),
7403 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7404 + sb->s_flags, sb->s_count,
7405 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7409 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7413 +void au_dpri_sb(struct super_block *sb)
7415 + struct au_sbinfo *sbinfo;
7416 + aufs_bindex_t bindex;
7418 + /* to reuduce stack size */
7420 + struct vfsmount mnt;
7421 + struct au_branch fake;
7424 + /* this function can be called from magic sysrq */
7425 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7426 + if (unlikely(!a)) {
7427 + dpri("no memory\n");
7431 + a->mnt.mnt_sb = sb;
7432 + a->fake.br_path.mnt = &a->mnt;
7433 + au_br_count_init(&a->fake);
7434 + err = do_pri_br(-1, &a->fake);
7435 + au_br_count_fin(&a->fake);
7437 + dpri("dev 0x%x\n", sb->s_dev);
7438 + if (err || !au_test_aufs(sb))
7441 + sbinfo = au_sbi(sb);
7444 + dpri("nw %d, gen %u, kobj %d\n",
7445 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7446 + kref_read(&sbinfo->si_kobj.kref));
7447 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7448 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7451 +/* ---------------------------------------------------------------------- */
7453 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7455 + struct inode *h_inode, *inode = d_inode(dentry);
7456 + struct dentry *h_dentry;
7457 + aufs_bindex_t bindex, bbot, bi;
7459 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7462 + bbot = au_dbbot(dentry);
7463 + bi = au_ibbot(inode);
7466 + bindex = au_dbtop(dentry);
7467 + bi = au_ibtop(inode);
7471 + for (; bindex <= bbot; bindex++) {
7472 + h_dentry = au_h_dptr(dentry, bindex);
7475 + h_inode = au_h_iptr(inode, bindex);
7476 + if (unlikely(h_inode != d_inode(h_dentry))) {
7478 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7479 + AuDbgDentry(dentry);
7480 + AuDbgInode(inode);
7487 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7490 + struct au_dcsub_pages dpages;
7491 + struct au_dpage *dpage;
7492 + struct dentry **dentries;
7494 + err = au_dpages_init(&dpages, GFP_NOFS);
7496 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7498 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7499 + dpage = dpages.dpages + i;
7500 + dentries = dpage->dentries;
7501 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7502 + AuDebugOn(au_digen_test(dentries[j], sigen));
7504 + au_dpages_free(&dpages);
7507 +void au_dbg_verify_kthread(void)
7509 + if (au_wkq_test()) {
7512 + * It may be recursive, but udba=notify between two aufs mounts,
7513 + * where a single ro branch is shared, is not a problem.
7519 +/* ---------------------------------------------------------------------- */
7521 +int __init au_debug_init(void)
7523 + aufs_bindex_t bindex;
7524 + struct au_vdir_destr destr;
7527 + AuDebugOn(bindex >= 0);
7530 + AuDebugOn(destr.len < NAME_MAX);
7532 +#ifdef CONFIG_4KSTACKS
7533 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7538 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7539 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7540 +++ linux/fs/aufs/debug.h 2017-07-29 12:14:25.899708630 +0200
7543 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7545 + * This program, aufs is free software; you can redistribute it and/or modify
7546 + * it under the terms of the GNU General Public License as published by
7547 + * the Free Software Foundation; either version 2 of the License, or
7548 + * (at your option) any later version.
7550 + * This program is distributed in the hope that it will be useful,
7551 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7552 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7553 + * GNU General Public License for more details.
7555 + * You should have received a copy of the GNU General Public License
7556 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7560 + * debug print functions
7563 +#ifndef __AUFS_DEBUG_H__
7564 +#define __AUFS_DEBUG_H__
7568 +#include <linux/atomic.h>
7569 +#include <linux/module.h>
7570 +#include <linux/kallsyms.h>
7571 +#include <linux/sysrq.h>
7573 +#ifdef CONFIG_AUFS_DEBUG
7574 +#define AuDebugOn(a) BUG_ON(a)
7576 +/* module parameter */
7577 +extern atomic_t aufs_debug;
7578 +static inline void au_debug_on(void)
7580 + atomic_inc(&aufs_debug);
7582 +static inline void au_debug_off(void)
7584 + atomic_dec_if_positive(&aufs_debug);
7587 +static inline int au_debug_test(void)
7589 + return atomic_read(&aufs_debug) > 0;
7592 +#define AuDebugOn(a) do {} while (0)
7593 +AuStubVoid(au_debug_on, void)
7594 +AuStubVoid(au_debug_off, void)
7595 +AuStubInt0(au_debug_test, void)
7596 +#endif /* CONFIG_AUFS_DEBUG */
7598 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7600 +/* ---------------------------------------------------------------------- */
7604 +#define AuDbg(fmt, ...) do { \
7605 + if (au_debug_test()) \
7606 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7608 +#define AuLabel(l) AuDbg(#l "\n")
7609 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7610 +#define AuWarn1(fmt, ...) do { \
7611 + static unsigned char _c; \
7613 + pr_warn(fmt, ##__VA_ARGS__); \
7616 +#define AuErr1(fmt, ...) do { \
7617 + static unsigned char _c; \
7619 + pr_err(fmt, ##__VA_ARGS__); \
7622 +#define AuIOErr1(fmt, ...) do { \
7623 + static unsigned char _c; \
7625 + AuIOErr(fmt, ##__VA_ARGS__); \
7628 +#define AuUnsupportMsg "This operation is not supported." \
7629 + " Please report this application to aufs-users ML."
7630 +#define AuUnsupport(fmt, ...) do { \
7631 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7635 +#define AuTraceErr(e) do { \
7636 + if (unlikely((e) < 0)) \
7637 + AuDbg("err %d\n", (int)(e)); \
7640 +#define AuTraceErrPtr(p) do { \
7642 + AuDbg("err %ld\n", PTR_ERR(p)); \
7645 +/* dirty macros for debug print, use with "%.*s" and caution */
7646 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7648 +/* ---------------------------------------------------------------------- */
7651 +#ifdef CONFIG_AUFS_DEBUG
7652 +extern struct mutex au_dbg_mtx;
7653 +extern char *au_plevel;
7655 +void au_dpri_whlist(struct au_nhash *whlist);
7657 +void au_dpri_vdir(struct au_vdir *vdir);
7659 +void au_dpri_inode(struct inode *inode);
7660 +void au_dpri_dalias(struct inode *inode);
7661 +void au_dpri_dentry(struct dentry *dentry);
7663 +void au_dpri_file(struct file *filp);
7664 +struct super_block;
7665 +void au_dpri_sb(struct super_block *sb);
7667 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7668 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7669 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7670 +void au_dbg_verify_kthread(void);
7672 +int __init au_debug_init(void);
7674 +#define AuDbgWhlist(w) do { \
7675 + mutex_lock(&au_dbg_mtx); \
7677 + au_dpri_whlist(w); \
7678 + mutex_unlock(&au_dbg_mtx); \
7681 +#define AuDbgVdir(v) do { \
7682 + mutex_lock(&au_dbg_mtx); \
7684 + au_dpri_vdir(v); \
7685 + mutex_unlock(&au_dbg_mtx); \
7688 +#define AuDbgInode(i) do { \
7689 + mutex_lock(&au_dbg_mtx); \
7691 + au_dpri_inode(i); \
7692 + mutex_unlock(&au_dbg_mtx); \
7695 +#define AuDbgDAlias(i) do { \
7696 + mutex_lock(&au_dbg_mtx); \
7698 + au_dpri_dalias(i); \
7699 + mutex_unlock(&au_dbg_mtx); \
7702 +#define AuDbgDentry(d) do { \
7703 + mutex_lock(&au_dbg_mtx); \
7705 + au_dpri_dentry(d); \
7706 + mutex_unlock(&au_dbg_mtx); \
7709 +#define AuDbgFile(f) do { \
7710 + mutex_lock(&au_dbg_mtx); \
7712 + au_dpri_file(f); \
7713 + mutex_unlock(&au_dbg_mtx); \
7716 +#define AuDbgSb(sb) do { \
7717 + mutex_lock(&au_dbg_mtx); \
7718 + AuDbg(#sb "\n"); \
7720 + mutex_unlock(&au_dbg_mtx); \
7723 +#define AuDbgSym(addr) do { \
7724 + char sym[KSYM_SYMBOL_LEN]; \
7725 + sprint_symbol(sym, (unsigned long)addr); \
7726 + AuDbg("%s\n", sym); \
7729 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7730 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7731 +AuStubVoid(au_dbg_verify_kthread, void)
7732 +AuStubInt0(__init au_debug_init, void)
7734 +#define AuDbgWhlist(w) do {} while (0)
7735 +#define AuDbgVdir(v) do {} while (0)
7736 +#define AuDbgInode(i) do {} while (0)
7737 +#define AuDbgDAlias(i) do {} while (0)
7738 +#define AuDbgDentry(d) do {} while (0)
7739 +#define AuDbgFile(f) do {} while (0)
7740 +#define AuDbgSb(sb) do {} while (0)
7741 +#define AuDbgSym(addr) do {} while (0)
7742 +#endif /* CONFIG_AUFS_DEBUG */
7744 +/* ---------------------------------------------------------------------- */
7746 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7747 +int __init au_sysrq_init(void);
7748 +void au_sysrq_fin(void);
7750 +#ifdef CONFIG_HW_CONSOLE
7751 +#define au_dbg_blocked() do { \
7753 + handle_sysrq('w'); \
7756 +AuStubVoid(au_dbg_blocked, void)
7760 +AuStubInt0(__init au_sysrq_init, void)
7761 +AuStubVoid(au_sysrq_fin, void)
7762 +AuStubVoid(au_dbg_blocked, void)
7763 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7765 +#endif /* __KERNEL__ */
7766 +#endif /* __AUFS_DEBUG_H__ */
7767 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7768 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7769 +++ linux/fs/aufs/dentry.c 2017-07-29 12:14:25.899708630 +0200
7772 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7774 + * This program, aufs is free software; you can redistribute it and/or modify
7775 + * it under the terms of the GNU General Public License as published by
7776 + * the Free Software Foundation; either version 2 of the License, or
7777 + * (at your option) any later version.
7779 + * This program is distributed in the hope that it will be useful,
7780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7782 + * GNU General Public License for more details.
7784 + * You should have received a copy of the GNU General Public License
7785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7789 + * lookup and dentry operations
7792 +#include <linux/namei.h>
7795 +struct au_do_lookup_args {
7796 + unsigned int flags;
7801 + * returns positive/negative dentry, NULL or an error.
7802 + * NULL means whiteout-ed or not-found.
7804 +static struct dentry*
7805 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7806 + aufs_bindex_t bindex, struct qstr *wh_name,
7807 + struct au_do_lookup_args *args)
7809 + struct dentry *h_dentry;
7810 + struct inode *h_inode;
7811 + struct au_branch *br;
7812 + int wh_found, opq;
7813 + unsigned char wh_able;
7814 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7815 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7819 + br = au_sbr(dentry->d_sb, bindex);
7820 + wh_able = !!au_br_whable(br->br_perm);
7822 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7823 + h_dentry = ERR_PTR(wh_found);
7826 + if (unlikely(wh_found < 0))
7829 + /* We found a whiteout */
7830 + /* au_set_dbbot(dentry, bindex); */
7831 + au_set_dbwh(dentry, bindex);
7833 + return NULL; /* success */
7837 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7839 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7840 + if (IS_ERR(h_dentry)) {
7841 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7847 + h_inode = d_inode(h_dentry);
7848 + if (d_is_negative(h_dentry)) {
7851 + } else if (wh_found
7852 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7855 + if (au_dbbot(dentry) <= bindex)
7856 + au_set_dbbot(dentry, bindex);
7857 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7858 + au_set_dbtop(dentry, bindex);
7859 + au_set_h_dptr(dentry, bindex, h_dentry);
7861 + if (!d_is_dir(h_dentry)
7863 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7864 + goto out; /* success */
7866 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7867 + opq = au_diropq_test(h_dentry);
7868 + inode_unlock(h_inode);
7870 + au_set_dbdiropq(dentry, bindex);
7871 + else if (unlikely(opq < 0)) {
7872 + au_set_h_dptr(dentry, bindex, NULL);
7873 + h_dentry = ERR_PTR(opq);
7884 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7886 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7887 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7893 + * returns the number of lower positive dentries,
7894 + * otherwise an error.
7895 + * can be called at unlinking with @type is zero.
7897 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7898 + unsigned int flags)
7900 + int npositive, err;
7901 + aufs_bindex_t bindex, btail, bdiropq;
7902 + unsigned char isdir, dirperm1;
7903 + struct qstr whname;
7904 + struct au_do_lookup_args args = {
7907 + const struct qstr *name = &dentry->d_name;
7908 + struct dentry *parent;
7909 + struct super_block *sb;
7911 + sb = dentry->d_sb;
7912 + err = au_test_shwh(sb, name);
7913 + if (unlikely(err))
7916 + err = au_wh_name_alloc(&whname, name);
7917 + if (unlikely(err))
7920 + isdir = !!d_is_dir(dentry);
7921 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7924 + parent = dget_parent(dentry);
7925 + btail = au_dbtaildir(parent);
7926 + for (bindex = btop; bindex <= btail; bindex++) {
7927 + struct dentry *h_parent, *h_dentry;
7928 + struct inode *h_inode, *h_dir;
7930 + h_dentry = au_h_dptr(dentry, bindex);
7932 + if (d_is_positive(h_dentry))
7936 + h_parent = au_h_dptr(parent, bindex);
7937 + if (!h_parent || !d_is_dir(h_parent))
7940 + h_dir = d_inode(h_parent);
7941 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7942 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7944 + inode_unlock(h_dir);
7945 + err = PTR_ERR(h_dentry);
7946 + if (IS_ERR(h_dentry))
7949 + au_fclr_lkup(args.flags, ALLOW_NEG);
7951 + au_fset_lkup(args.flags, IGNORE_PERM);
7953 + if (au_dbwh(dentry) == bindex)
7957 + if (d_is_negative(h_dentry))
7959 + h_inode = d_inode(h_dentry);
7962 + args.type = h_inode->i_mode & S_IFMT;
7963 + if (args.type != S_IFDIR)
7966 + /* the type of lower may be different */
7967 + bdiropq = au_dbdiropq(dentry);
7968 + if (bdiropq >= 0 && bdiropq <= bindex)
7974 + AuLabel(positive);
7975 + au_update_dbtop(dentry);
7978 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7979 + && au_dbtop(dentry) < 0)) {
7981 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7987 + kfree(whname.name);
7992 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7994 + struct dentry *dentry;
7997 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7998 + dentry = vfsub_lkup_one(name, parent);
8000 + struct vfsub_lkup_one_args args = {
8006 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8007 + if (unlikely(wkq_err))
8008 + dentry = ERR_PTR(wkq_err);
8015 + * lookup @dentry on @bindex which should be negative.
8017 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8020 + struct dentry *parent, *h_parent, *h_dentry;
8021 + struct au_branch *br;
8023 + parent = dget_parent(dentry);
8024 + h_parent = au_h_dptr(parent, bindex);
8025 + br = au_sbr(dentry->d_sb, bindex);
8027 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8029 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8030 + err = PTR_ERR(h_dentry);
8031 + if (IS_ERR(h_dentry))
8033 + if (unlikely(d_is_positive(h_dentry))) {
8035 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8041 + if (bindex < au_dbtop(dentry))
8042 + au_set_dbtop(dentry, bindex);
8043 + if (au_dbbot(dentry) < bindex)
8044 + au_set_dbbot(dentry, bindex);
8045 + au_set_h_dptr(dentry, bindex, h_dentry);
8052 +/* ---------------------------------------------------------------------- */
8054 +/* subset of struct inode */
8056 + unsigned long i_ino;
8057 + /* unsigned int i_nlink; */
8063 + blkcnt_t i_blocks;
8068 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8070 + ia->i_ino = h_inode->i_ino;
8071 + /* ia->i_nlink = h_inode->i_nlink; */
8072 + ia->i_uid = h_inode->i_uid;
8073 + ia->i_gid = h_inode->i_gid;
8074 + ia->i_version = h_inode->i_version;
8076 + ia->i_size = h_inode->i_size;
8077 + ia->i_blocks = h_inode->i_blocks;
8079 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8082 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8084 + return ia->i_ino != h_inode->i_ino
8085 + /* || ia->i_nlink != h_inode->i_nlink */
8086 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8087 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8088 + || ia->i_version != h_inode->i_version
8090 + || ia->i_size != h_inode->i_size
8091 + || ia->i_blocks != h_inode->i_blocks
8093 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8096 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8097 + struct au_branch *br)
8100 + struct au_iattr ia;
8101 + struct inode *h_inode;
8102 + struct dentry *h_d;
8103 + struct super_block *h_sb;
8106 + memset(&ia, -1, sizeof(ia));
8107 + h_sb = h_dentry->d_sb;
8109 + if (d_is_positive(h_dentry)) {
8110 + h_inode = d_inode(h_dentry);
8111 + au_iattr_save(&ia, h_inode);
8112 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8113 + /* nfs d_revalidate may return 0 for negative dentry */
8114 + /* fuse d_revalidate always return 0 for negative dentry */
8117 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8118 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8119 + err = PTR_ERR(h_d);
8124 + if (unlikely(h_d != h_dentry
8125 + || d_inode(h_d) != h_inode
8126 + || (h_inode && au_iattr_test(&ia, h_inode))))
8127 + err = au_busy_or_stale();
8135 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8136 + struct dentry *h_parent, struct au_branch *br)
8141 + if (udba == AuOpt_UDBA_REVAL
8142 + && !au_test_fs_remote(h_dentry->d_sb)) {
8144 + err = (d_inode(h_dentry->d_parent) != h_dir);
8145 + } else if (udba != AuOpt_UDBA_NONE)
8146 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8151 +/* ---------------------------------------------------------------------- */
8153 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8156 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8157 + struct au_hdentry tmp, *p, *q;
8158 + struct au_dinfo *dinfo;
8159 + struct super_block *sb;
8161 + DiMustWriteLock(dentry);
8163 + sb = dentry->d_sb;
8164 + dinfo = au_di(dentry);
8165 + bbot = dinfo->di_bbot;
8166 + bwh = dinfo->di_bwh;
8167 + bdiropq = dinfo->di_bdiropq;
8168 + bindex = dinfo->di_btop;
8169 + p = au_hdentry(dinfo, bindex);
8170 + for (; bindex <= bbot; bindex++, p++) {
8171 + if (!p->hd_dentry)
8174 + new_bindex = au_br_index(sb, p->hd_id);
8175 + if (new_bindex == bindex)
8178 + if (dinfo->di_bwh == bindex)
8180 + if (dinfo->di_bdiropq == bindex)
8181 + bdiropq = new_bindex;
8182 + if (new_bindex < 0) {
8184 + p->hd_dentry = NULL;
8188 + /* swap two lower dentries, and loop again */
8189 + q = au_hdentry(dinfo, new_bindex);
8193 + if (tmp.hd_dentry) {
8199 + dinfo->di_bwh = -1;
8200 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8201 + dinfo->di_bwh = bwh;
8203 + dinfo->di_bdiropq = -1;
8205 + && bdiropq <= au_sbbot(sb)
8206 + && au_sbr_whable(sb, bdiropq))
8207 + dinfo->di_bdiropq = bdiropq;
8210 + dinfo->di_btop = -1;
8211 + dinfo->di_bbot = -1;
8212 + bbot = au_dbbot(parent);
8214 + p = au_hdentry(dinfo, bindex);
8215 + for (; bindex <= bbot; bindex++, p++)
8216 + if (p->hd_dentry) {
8217 + dinfo->di_btop = bindex;
8221 + if (dinfo->di_btop >= 0) {
8223 + p = au_hdentry(dinfo, bindex);
8224 + for (; bindex >= 0; bindex--, p--)
8225 + if (p->hd_dentry) {
8226 + dinfo->di_bbot = bindex;
8235 +static void au_do_hide(struct dentry *dentry)
8237 + struct inode *inode;
8239 + if (d_really_is_positive(dentry)) {
8240 + inode = d_inode(dentry);
8241 + if (!d_is_dir(dentry)) {
8242 + if (inode->i_nlink && !d_unhashed(dentry))
8243 + drop_nlink(inode);
8245 + clear_nlink(inode);
8246 + /* stop next lookup */
8247 + inode->i_flags |= S_DEAD;
8249 + smp_mb(); /* necessary? */
8254 +static int au_hide_children(struct dentry *parent)
8256 + int err, i, j, ndentry;
8257 + struct au_dcsub_pages dpages;
8258 + struct au_dpage *dpage;
8259 + struct dentry *dentry;
8261 + err = au_dpages_init(&dpages, GFP_NOFS);
8262 + if (unlikely(err))
8264 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8265 + if (unlikely(err))
8268 + /* in reverse order */
8269 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8270 + dpage = dpages.dpages + i;
8271 + ndentry = dpage->ndentry;
8272 + for (j = ndentry - 1; j >= 0; j--) {
8273 + dentry = dpage->dentries[j];
8274 + if (dentry != parent)
8275 + au_do_hide(dentry);
8280 + au_dpages_free(&dpages);
8285 +static void au_hide(struct dentry *dentry)
8289 + AuDbgDentry(dentry);
8290 + if (d_is_dir(dentry)) {
8291 + /* shrink_dcache_parent(dentry); */
8292 + err = au_hide_children(dentry);
8293 + if (unlikely(err))
8294 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8297 + au_do_hide(dentry);
8301 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8303 + * a dirty branch is added
8304 + * - on the top of layers
8305 + * - in the middle of layers
8306 + * - to the bottom of layers
8308 + * on the added branch there exists
8311 + * - a same named entry
8313 + * * negative --> positive
8314 + * * positive --> positive
8315 + * - type is unchanged
8316 + * - type is changed
8318 + * * negative --> negative
8319 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8322 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8323 + struct au_dinfo *tmp)
8326 + aufs_bindex_t bindex, bbot;
8328 + struct dentry *dentry;
8329 + struct inode *inode;
8331 + } orig_h, tmp_h = {
8334 + struct au_hdentry *hd;
8335 + struct inode *inode, *h_inode;
8336 + struct dentry *h_dentry;
8339 + AuDebugOn(dinfo->di_btop < 0);
8341 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8342 + orig_h.inode = NULL;
8343 + if (d_is_positive(orig_h.dentry)) {
8344 + orig_h.inode = d_inode(orig_h.dentry);
8345 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8347 + if (tmp->di_btop >= 0) {
8348 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8349 + if (d_is_positive(tmp_h.dentry)) {
8350 + tmp_h.inode = d_inode(tmp_h.dentry);
8351 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8356 + if (d_really_is_positive(dentry))
8357 + inode = d_inode(dentry);
8358 + if (!orig_h.inode) {
8359 + AuDbg("nagative originally\n");
8365 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8366 + AuDebugOn(dinfo->di_bdiropq != -1);
8368 + if (!tmp_h.inode) {
8369 + AuDbg("negative --> negative\n");
8370 + /* should have only one negative lower */
8371 + if (tmp->di_btop >= 0
8372 + && tmp->di_btop < dinfo->di_btop) {
8373 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8374 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8375 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8376 + au_di_cp(dinfo, tmp);
8377 + hd = au_hdentry(tmp, tmp->di_btop);
8378 + au_set_h_dptr(dentry, tmp->di_btop,
8379 + dget(hd->hd_dentry));
8381 + au_dbg_verify_dinode(dentry);
8383 + AuDbg("negative --> positive\n");
8385 + * similar to the behaviour of creating with bypassing
8387 + * unhash it in order to force an error in the
8388 + * succeeding create operation.
8389 + * we should not set S_DEAD here.
8392 + /* au_di_swap(tmp, dinfo); */
8393 + au_dbg_verify_dinode(dentry);
8396 + AuDbg("positive originally\n");
8397 + /* inode may be NULL */
8398 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8399 + if (!tmp_h.inode) {
8400 + AuDbg("positive --> negative\n");
8401 + /* or bypassing aufs */
8403 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8404 + dinfo->di_bwh = tmp->di_bwh;
8406 + err = au_refresh_hinode_self(inode);
8407 + au_dbg_verify_dinode(dentry);
8408 + } else if (orig_h.mode == tmp_h.mode) {
8409 + AuDbg("positive --> positive, same type\n");
8410 + if (!S_ISDIR(orig_h.mode)
8411 + && dinfo->di_btop > tmp->di_btop) {
8413 + * similar to the behaviour of removing and
8418 + err = au_refresh_hinode_self(inode);
8419 + au_dbg_verify_dinode(dentry);
8421 + /* fill empty slots */
8422 + if (dinfo->di_btop > tmp->di_btop)
8423 + dinfo->di_btop = tmp->di_btop;
8424 + if (dinfo->di_bbot < tmp->di_bbot)
8425 + dinfo->di_bbot = tmp->di_bbot;
8426 + dinfo->di_bwh = tmp->di_bwh;
8427 + dinfo->di_bdiropq = tmp->di_bdiropq;
8428 + bbot = dinfo->di_bbot;
8429 + bindex = tmp->di_btop;
8430 + hd = au_hdentry(tmp, bindex);
8431 + for (; bindex <= bbot; bindex++, hd++) {
8432 + if (au_h_dptr(dentry, bindex))
8434 + h_dentry = hd->hd_dentry;
8437 + AuDebugOn(d_is_negative(h_dentry));
8438 + h_inode = d_inode(h_dentry);
8439 + AuDebugOn(orig_h.mode
8440 + != (h_inode->i_mode
8442 + au_set_h_dptr(dentry, bindex,
8446 + err = au_refresh_hinode(inode, dentry);
8447 + au_dbg_verify_dinode(dentry);
8450 + AuDbg("positive --> positive, different type\n");
8451 + /* similar to the behaviour of removing and creating */
8454 + err = au_refresh_hinode_self(inode);
8455 + au_dbg_verify_dinode(dentry);
8463 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8465 + const struct dentry_operations *dop
8466 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8467 + static const unsigned int mask
8468 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8470 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8472 + if (dentry->d_op == dop)
8475 + AuDbg("%pd\n", dentry);
8476 + spin_lock(&dentry->d_lock);
8477 + if (dop == &aufs_dop)
8478 + dentry->d_flags |= mask;
8480 + dentry->d_flags &= ~mask;
8481 + dentry->d_op = dop;
8482 + spin_unlock(&dentry->d_lock);
8485 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8487 + int err, ebrange, nbr;
8488 + unsigned int sigen;
8489 + struct au_dinfo *dinfo, *tmp;
8490 + struct super_block *sb;
8491 + struct inode *inode;
8493 + DiMustWriteLock(dentry);
8494 + AuDebugOn(IS_ROOT(dentry));
8495 + AuDebugOn(d_really_is_negative(parent));
8497 + sb = dentry->d_sb;
8498 + sigen = au_sigen(sb);
8499 + err = au_digen_test(parent, sigen);
8500 + if (unlikely(err))
8503 + nbr = au_sbbot(sb) + 1;
8504 + dinfo = au_di(dentry);
8505 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8506 + if (unlikely(err))
8508 + ebrange = au_dbrange_test(dentry);
8510 + ebrange = au_do_refresh_hdentry(dentry, parent);
8512 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8513 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8514 + if (d_really_is_positive(dentry)) {
8515 + inode = d_inode(dentry);
8516 + err = au_refresh_hinode_self(inode);
8518 + au_dbg_verify_dinode(dentry);
8520 + goto out_dgen; /* success */
8524 + /* temporary dinfo */
8525 + AuDbgDentry(dentry);
8527 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8528 + if (unlikely(!tmp))
8530 + au_di_swap(tmp, dinfo);
8531 + /* returns the number of positive dentries */
8533 + * if current working dir is removed, it returns an error.
8534 + * but the dentry is legal.
8536 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8537 + AuDbgDentry(dentry);
8538 + au_di_swap(tmp, dinfo);
8539 + if (err == -ENOENT)
8542 + /* compare/refresh by dinfo */
8543 + AuDbgDentry(dentry);
8544 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8545 + au_dbg_verify_dinode(dentry);
8548 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8549 + au_rw_write_unlock(&tmp->di_rwsem);
8551 + if (unlikely(err))
8555 + au_update_digen(dentry);
8557 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8558 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8559 + AuDbgDentry(dentry);
8565 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8566 + struct dentry *dentry, aufs_bindex_t bindex)
8571 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8574 + AuDbg("b%d\n", bindex);
8576 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8577 + * due to whiteout and branch permission.
8579 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8580 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8581 + /* it may return tri-state */
8582 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8584 + if (unlikely(valid < 0))
8594 +/* todo: remove this */
8595 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8596 + unsigned int flags, int do_udba)
8599 + umode_t mode, h_mode;
8600 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8601 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8602 + struct inode *h_inode, *h_cached_inode;
8603 + struct dentry *h_dentry;
8604 + struct qstr *name, *h_name;
8611 + unhashed = !!d_unhashed(dentry);
8612 + is_root = !!IS_ROOT(dentry);
8613 + name = &dentry->d_name;
8614 + tmpfile = au_di(dentry)->di_tmpfile;
8617 + * Theoretically, REVAL test should be unnecessary in case of
8619 + * But {fs,i}notify doesn't fire some necessary events,
8620 + * IN_ATTRIB for atime/nlink/pageio
8621 + * Let's do REVAL test too.
8623 + if (do_udba && inode) {
8624 + mode = (inode->i_mode & S_IFMT);
8625 + plus = (inode->i_nlink > 0);
8626 + ibs = au_ibtop(inode);
8627 + ibe = au_ibbot(inode);
8630 + btop = au_dbtop(dentry);
8632 + if (inode && S_ISDIR(inode->i_mode))
8633 + btail = au_dbtaildir(dentry);
8634 + for (bindex = btop; bindex <= btail; bindex++) {
8635 + h_dentry = au_h_dptr(dentry, bindex);
8639 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8640 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8641 + spin_lock(&h_dentry->d_lock);
8642 + h_name = &h_dentry->d_name;
8643 + if (unlikely(do_udba
8646 + && (unhashed != !!d_unhashed(h_dentry)
8648 + && !au_qstreq(name, h_name))
8651 + && !(flags & LOOKUP_OPEN)
8652 + && (h_dentry->d_flags
8653 + & DCACHE_NFSFS_RENAMED)))
8657 + h_unhashed = d_unhashed(h_dentry);
8658 + spin_unlock(&h_dentry->d_lock);
8659 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8660 + unhashed, h_unhashed, dentry, h_dentry);
8663 + spin_unlock(&h_dentry->d_lock);
8665 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8666 + if (unlikely(err))
8667 + /* do not goto err, to keep the errno */
8670 + /* todo: plink too? */
8675 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8679 + if (d_is_positive(h_dentry))
8680 + h_inode = d_inode(h_dentry);
8683 + h_cached_inode = h_inode;
8685 + h_mode = (h_inode->i_mode & S_IFMT);
8686 + h_plus = (h_inode->i_nlink > 0);
8688 + if (inode && ibs <= bindex && bindex <= ibe)
8689 + h_cached_inode = au_h_iptr(inode, bindex);
8692 + if (unlikely(plus != h_plus && !tmpfile))
8695 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8697 + && !IS_ROOT(h_dentry)
8698 + && unhashed != d_unhashed(h_dentry)))
8701 + if (unlikely(mode != h_mode
8702 + || h_cached_inode != h_inode))
8715 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8716 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8719 + struct dentry *parent;
8721 + if (!au_digen_test(dentry, sigen))
8724 + parent = dget_parent(dentry);
8725 + di_read_lock_parent(parent, AuLock_IR);
8726 + AuDebugOn(au_digen_test(parent, sigen));
8727 + au_dbg_verify_gen(parent, sigen);
8728 + err = au_refresh_dentry(dentry, parent);
8729 + di_read_unlock(parent, AuLock_IR);
8735 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8738 + struct dentry *d, *parent;
8740 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8741 + return simple_reval_dpath(dentry, sigen);
8743 + /* slow loop, keep it simple and stupid */
8744 + /* cf: au_cpup_dirs() */
8747 + while (au_digen_test(dentry, sigen)) {
8751 + parent = dget_parent(d);
8752 + if (!au_digen_test(parent, sigen))
8758 + di_write_lock_child2(d);
8760 + /* someone might update our dentry while we were sleeping */
8761 + if (au_digen_test(d, sigen)) {
8763 + * todo: consolidate with simple_reval_dpath(),
8764 + * do_refresh() and au_reval_for_attr().
8766 + di_read_lock_parent(parent, AuLock_IR);
8767 + err = au_refresh_dentry(d, parent);
8768 + di_read_unlock(parent, AuLock_IR);
8772 + di_write_unlock(d);
8774 + if (unlikely(err))
8782 + * if valid returns 1, otherwise 0.
8784 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8787 + unsigned int sigen;
8788 + unsigned char do_udba;
8789 + struct super_block *sb;
8790 + struct inode *inode;
8792 + /* todo: support rcu-walk? */
8793 + if (flags & LOOKUP_RCU)
8797 + if (unlikely(!au_di(dentry)))
8801 + sb = dentry->d_sb;
8804 + * i_mutex of parent dir may be held,
8805 + * but we should not return 'invalid' due to busy.
8807 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8808 + if (unlikely(err)) {
8814 + if (d_really_is_positive(dentry))
8815 + inode = d_inode(dentry);
8816 + if (unlikely(inode && au_is_bad_inode(inode))) {
8821 + if (unlikely(au_dbrange_test(dentry))) {
8827 + sigen = au_sigen(sb);
8828 + if (au_digen_test(dentry, sigen)) {
8829 + AuDebugOn(IS_ROOT(dentry));
8830 + err = au_reval_dpath(dentry, sigen);
8831 + if (unlikely(err)) {
8836 + di_downgrade_lock(dentry, AuLock_IR);
8839 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8841 + && !(inode->i_state && I_LINKABLE)
8842 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8847 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8848 + if (do_udba && inode) {
8849 + aufs_bindex_t btop = au_ibtop(inode);
8850 + struct inode *h_inode;
8853 + h_inode = au_h_iptr(inode, btop);
8854 + if (h_inode && au_test_higen(inode, h_inode)) {
8861 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8862 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8864 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8870 + di_downgrade_lock(dentry, AuLock_IR);
8872 + aufs_read_unlock(dentry, AuLock_IR);
8877 + AuDbg("%pd invalid, %d\n", dentry, valid);
8883 +static void aufs_d_release(struct dentry *dentry)
8885 + if (au_di(dentry)) {
8886 + au_di_fin(dentry);
8887 + au_hn_di_reinit(dentry);
8891 +const struct dentry_operations aufs_dop = {
8892 + .d_revalidate = aufs_d_revalidate,
8893 + .d_weak_revalidate = aufs_d_revalidate,
8894 + .d_release = aufs_d_release
8897 +/* aufs_dop without d_revalidate */
8898 +const struct dentry_operations aufs_dop_noreval = {
8899 + .d_release = aufs_d_release
8901 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8902 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8903 +++ linux/fs/aufs/dentry.h 2017-07-29 12:14:25.899708630 +0200
8906 + * Copyright (C) 2005-2017 Junjiro R. Okajima
8908 + * This program, aufs is free software; you can redistribute it and/or modify
8909 + * it under the terms of the GNU General Public License as published by
8910 + * the Free Software Foundation; either version 2 of the License, or
8911 + * (at your option) any later version.
8913 + * This program is distributed in the hope that it will be useful,
8914 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8915 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8916 + * GNU General Public License for more details.
8918 + * You should have received a copy of the GNU General Public License
8919 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8923 + * lookup and dentry operations
8926 +#ifndef __AUFS_DENTRY_H__
8927 +#define __AUFS_DENTRY_H__
8931 +#include <linux/dcache.h>
8934 +struct au_hdentry {
8935 + struct dentry *hd_dentry;
8936 + aufs_bindex_t hd_id;
8940 + atomic_t di_generation;
8942 + struct au_rwsem di_rwsem;
8943 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8944 + unsigned char di_tmpfile; /* to allow the different name */
8945 + struct au_hdentry *di_hdentry;
8946 +} ____cacheline_aligned_in_smp;
8948 +/* ---------------------------------------------------------------------- */
8950 +/* flags for au_lkup_dentry() */
8951 +#define AuLkup_ALLOW_NEG 1
8952 +#define AuLkup_IGNORE_PERM (1 << 1)
8953 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8954 +#define au_fset_lkup(flags, name) \
8955 + do { (flags) |= AuLkup_##name; } while (0)
8956 +#define au_fclr_lkup(flags, name) \
8957 + do { (flags) &= ~AuLkup_##name; } while (0)
8959 +/* ---------------------------------------------------------------------- */
8962 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8964 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8965 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8966 + struct dentry *h_parent, struct au_branch *br);
8968 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8969 + unsigned int flags);
8970 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8971 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8972 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8973 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8976 +void au_di_init_once(void *_di);
8977 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8978 +void au_di_free(struct au_dinfo *dinfo);
8979 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8980 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8981 +int au_di_init(struct dentry *dentry);
8982 +void au_di_fin(struct dentry *dentry);
8983 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8985 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8986 +void di_read_unlock(struct dentry *d, int flags);
8987 +void di_downgrade_lock(struct dentry *d, int flags);
8988 +void di_write_lock(struct dentry *d, unsigned int lsc);
8989 +void di_write_unlock(struct dentry *d);
8990 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8991 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8992 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8994 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8995 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8996 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8997 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8999 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9000 + struct dentry *h_dentry);
9001 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9002 +int au_dbrange_test(struct dentry *dentry);
9003 +void au_update_digen(struct dentry *dentry);
9004 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9005 +void au_update_dbtop(struct dentry *dentry);
9006 +void au_update_dbbot(struct dentry *dentry);
9007 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9009 +/* ---------------------------------------------------------------------- */
9011 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9013 + return dentry->d_fsdata;
9016 +/* ---------------------------------------------------------------------- */
9018 +/* lock subclass for dinfo */
9020 + AuLsc_DI_CHILD, /* child first */
9021 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9022 + AuLsc_DI_CHILD3, /* copyup dirs */
9026 + AuLsc_DI_TMP /* temp for replacing dinfo */
9030 + * di_read_lock_child, di_write_lock_child,
9031 + * di_read_lock_child2, di_write_lock_child2,
9032 + * di_read_lock_child3, di_write_lock_child3,
9033 + * di_read_lock_parent, di_write_lock_parent,
9034 + * di_read_lock_parent2, di_write_lock_parent2,
9035 + * di_read_lock_parent3, di_write_lock_parent3,
9037 +#define AuReadLockFunc(name, lsc) \
9038 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9039 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9041 +#define AuWriteLockFunc(name, lsc) \
9042 +static inline void di_write_lock_##name(struct dentry *d) \
9043 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9045 +#define AuRWLockFuncs(name, lsc) \
9046 + AuReadLockFunc(name, lsc) \
9047 + AuWriteLockFunc(name, lsc)
9049 +AuRWLockFuncs(child, CHILD);
9050 +AuRWLockFuncs(child2, CHILD2);
9051 +AuRWLockFuncs(child3, CHILD3);
9052 +AuRWLockFuncs(parent, PARENT);
9053 +AuRWLockFuncs(parent2, PARENT2);
9054 +AuRWLockFuncs(parent3, PARENT3);
9056 +#undef AuReadLockFunc
9057 +#undef AuWriteLockFunc
9058 +#undef AuRWLockFuncs
9060 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9061 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9062 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9064 +/* ---------------------------------------------------------------------- */
9066 +/* todo: memory barrier? */
9067 +static inline unsigned int au_digen(struct dentry *d)
9069 + return atomic_read(&au_di(d)->di_generation);
9072 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9074 + hdentry->hd_dentry = NULL;
9077 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9078 + aufs_bindex_t bindex)
9080 + return di->di_hdentry + bindex;
9083 +static inline void au_hdput(struct au_hdentry *hd)
9086 + dput(hd->hd_dentry);
9089 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9091 + DiMustAnyLock(dentry);
9092 + return au_di(dentry)->di_btop;
9095 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9097 + DiMustAnyLock(dentry);
9098 + return au_di(dentry)->di_bbot;
9101 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9103 + DiMustAnyLock(dentry);
9104 + return au_di(dentry)->di_bwh;
9107 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9109 + DiMustAnyLock(dentry);
9110 + return au_di(dentry)->di_bdiropq;
9113 +/* todo: hard/soft set? */
9114 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9116 + DiMustWriteLock(dentry);
9117 + au_di(dentry)->di_btop = bindex;
9120 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9122 + DiMustWriteLock(dentry);
9123 + au_di(dentry)->di_bbot = bindex;
9126 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9128 + DiMustWriteLock(dentry);
9129 + /* dbwh can be outside of btop - bbot range */
9130 + au_di(dentry)->di_bwh = bindex;
9133 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9135 + DiMustWriteLock(dentry);
9136 + au_di(dentry)->di_bdiropq = bindex;
9139 +/* ---------------------------------------------------------------------- */
9141 +#ifdef CONFIG_AUFS_HNOTIFY
9142 +static inline void au_digen_dec(struct dentry *d)
9144 + atomic_dec(&au_di(d)->di_generation);
9147 +static inline void au_hn_di_reinit(struct dentry *dentry)
9149 + dentry->d_fsdata = NULL;
9152 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9153 +#endif /* CONFIG_AUFS_HNOTIFY */
9155 +#endif /* __KERNEL__ */
9156 +#endif /* __AUFS_DENTRY_H__ */
9157 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9158 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9159 +++ linux/fs/aufs/dinfo.c 2017-07-29 12:14:25.899708630 +0200
9162 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9164 + * This program, aufs is free software; you can redistribute it and/or modify
9165 + * it under the terms of the GNU General Public License as published by
9166 + * the Free Software Foundation; either version 2 of the License, or
9167 + * (at your option) any later version.
9169 + * This program is distributed in the hope that it will be useful,
9170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9172 + * GNU General Public License for more details.
9174 + * You should have received a copy of the GNU General Public License
9175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9179 + * dentry private data
9184 +void au_di_init_once(void *_dinfo)
9186 + struct au_dinfo *dinfo = _dinfo;
9188 + au_rw_init(&dinfo->di_rwsem);
9191 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9193 + struct au_dinfo *dinfo;
9196 + dinfo = au_cache_alloc_dinfo();
9197 + if (unlikely(!dinfo))
9200 + nbr = au_sbbot(sb) + 1;
9203 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9204 + if (dinfo->di_hdentry) {
9205 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9206 + dinfo->di_btop = -1;
9207 + dinfo->di_bbot = -1;
9208 + dinfo->di_bwh = -1;
9209 + dinfo->di_bdiropq = -1;
9210 + dinfo->di_tmpfile = 0;
9211 + for (i = 0; i < nbr; i++)
9212 + dinfo->di_hdentry[i].hd_id = -1;
9216 + au_cache_free_dinfo(dinfo);
9223 +void au_di_free(struct au_dinfo *dinfo)
9225 + struct au_hdentry *p;
9226 + aufs_bindex_t bbot, bindex;
9228 + /* dentry may not be revalidated */
9229 + bindex = dinfo->di_btop;
9230 + if (bindex >= 0) {
9231 + bbot = dinfo->di_bbot;
9232 + p = au_hdentry(dinfo, bindex);
9233 + while (bindex++ <= bbot)
9236 + kfree(dinfo->di_hdentry);
9237 + au_cache_free_dinfo(dinfo);
9240 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9242 + struct au_hdentry *p;
9245 + AuRwMustWriteLock(&a->di_rwsem);
9246 + AuRwMustWriteLock(&b->di_rwsem);
9248 +#define DiSwap(v, name) \
9250 + v = a->di_##name; \
9251 + a->di_##name = b->di_##name; \
9252 + b->di_##name = v; \
9255 + DiSwap(p, hdentry);
9259 + DiSwap(bi, bdiropq);
9265 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9267 + AuRwMustWriteLock(&dst->di_rwsem);
9268 + AuRwMustWriteLock(&src->di_rwsem);
9270 + dst->di_btop = src->di_btop;
9271 + dst->di_bbot = src->di_bbot;
9272 + dst->di_bwh = src->di_bwh;
9273 + dst->di_bdiropq = src->di_bdiropq;
9277 +int au_di_init(struct dentry *dentry)
9280 + struct super_block *sb;
9281 + struct au_dinfo *dinfo;
9284 + sb = dentry->d_sb;
9285 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9287 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9288 + /* smp_mb(); */ /* atomic_set */
9289 + dentry->d_fsdata = dinfo;
9296 +void au_di_fin(struct dentry *dentry)
9298 + struct au_dinfo *dinfo;
9300 + dinfo = au_di(dentry);
9301 + AuRwDestroy(&dinfo->di_rwsem);
9302 + au_di_free(dinfo);
9305 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9308 + struct au_hdentry *hdp;
9310 + AuRwMustWriteLock(&dinfo->di_rwsem);
9313 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9315 + sz = sizeof(*hdp);
9316 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9319 + dinfo->di_hdentry = hdp;
9326 +/* ---------------------------------------------------------------------- */
9328 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9331 + case AuLsc_DI_CHILD:
9332 + ii_write_lock_child(inode);
9334 + case AuLsc_DI_CHILD2:
9335 + ii_write_lock_child2(inode);
9337 + case AuLsc_DI_CHILD3:
9338 + ii_write_lock_child3(inode);
9340 + case AuLsc_DI_PARENT:
9341 + ii_write_lock_parent(inode);
9343 + case AuLsc_DI_PARENT2:
9344 + ii_write_lock_parent2(inode);
9346 + case AuLsc_DI_PARENT3:
9347 + ii_write_lock_parent3(inode);
9354 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9357 + case AuLsc_DI_CHILD:
9358 + ii_read_lock_child(inode);
9360 + case AuLsc_DI_CHILD2:
9361 + ii_read_lock_child2(inode);
9363 + case AuLsc_DI_CHILD3:
9364 + ii_read_lock_child3(inode);
9366 + case AuLsc_DI_PARENT:
9367 + ii_read_lock_parent(inode);
9369 + case AuLsc_DI_PARENT2:
9370 + ii_read_lock_parent2(inode);
9372 + case AuLsc_DI_PARENT3:
9373 + ii_read_lock_parent3(inode);
9380 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9382 + struct inode *inode;
9384 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9385 + if (d_really_is_positive(d)) {
9386 + inode = d_inode(d);
9387 + if (au_ftest_lock(flags, IW))
9388 + do_ii_write_lock(inode, lsc);
9389 + else if (au_ftest_lock(flags, IR))
9390 + do_ii_read_lock(inode, lsc);
9394 +void di_read_unlock(struct dentry *d, int flags)
9396 + struct inode *inode;
9398 + if (d_really_is_positive(d)) {
9399 + inode = d_inode(d);
9400 + if (au_ftest_lock(flags, IW)) {
9401 + au_dbg_verify_dinode(d);
9402 + ii_write_unlock(inode);
9403 + } else if (au_ftest_lock(flags, IR)) {
9404 + au_dbg_verify_dinode(d);
9405 + ii_read_unlock(inode);
9408 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9411 +void di_downgrade_lock(struct dentry *d, int flags)
9413 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9414 + ii_downgrade_lock(d_inode(d));
9415 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9418 +void di_write_lock(struct dentry *d, unsigned int lsc)
9420 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9421 + if (d_really_is_positive(d))
9422 + do_ii_write_lock(d_inode(d), lsc);
9425 +void di_write_unlock(struct dentry *d)
9427 + au_dbg_verify_dinode(d);
9428 + if (d_really_is_positive(d))
9429 + ii_write_unlock(d_inode(d));
9430 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9433 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9435 + AuDebugOn(d1 == d2
9436 + || d_inode(d1) == d_inode(d2)
9437 + || d1->d_sb != d2->d_sb);
9439 + if ((isdir && au_test_subdir(d1, d2))
9441 + di_write_lock_child(d1);
9442 + di_write_lock_child2(d2);
9444 + di_write_lock_child(d2);
9445 + di_write_lock_child2(d1);
9449 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9451 + AuDebugOn(d1 == d2
9452 + || d_inode(d1) == d_inode(d2)
9453 + || d1->d_sb != d2->d_sb);
9455 + if ((isdir && au_test_subdir(d1, d2))
9457 + di_write_lock_parent(d1);
9458 + di_write_lock_parent2(d2);
9460 + di_write_lock_parent(d2);
9461 + di_write_lock_parent2(d1);
9465 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9467 + di_write_unlock(d1);
9468 + if (d_inode(d1) == d_inode(d2))
9469 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9471 + di_write_unlock(d2);
9474 +/* ---------------------------------------------------------------------- */
9476 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9480 + DiMustAnyLock(dentry);
9482 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9484 + AuDebugOn(bindex < 0);
9485 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9486 + AuDebugOn(d && au_dcount(d) <= 0);
9491 + * extended version of au_h_dptr().
9492 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9495 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9497 + struct dentry *h_dentry;
9498 + struct inode *inode, *h_inode;
9500 + AuDebugOn(d_really_is_negative(dentry));
9503 + if (au_dbtop(dentry) <= bindex
9504 + && bindex <= au_dbbot(dentry))
9505 + h_dentry = au_h_dptr(dentry, bindex);
9506 + if (h_dentry && !au_d_linkable(h_dentry)) {
9508 + goto out; /* success */
9511 + inode = d_inode(dentry);
9512 + AuDebugOn(bindex < au_ibtop(inode));
9513 + AuDebugOn(au_ibbot(inode) < bindex);
9514 + h_inode = au_h_iptr(inode, bindex);
9515 + h_dentry = d_find_alias(h_inode);
9517 + if (!IS_ERR(h_dentry)) {
9518 + if (!au_d_linkable(h_dentry))
9519 + goto out; /* success */
9525 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9526 + h_dentry = au_plink_lkup(inode, bindex);
9527 + AuDebugOn(!h_dentry);
9528 + if (!IS_ERR(h_dentry)) {
9529 + if (!au_d_hashed_positive(h_dentry))
9530 + goto out; /* success */
9537 + AuDbgDentry(h_dentry);
9541 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9543 + aufs_bindex_t bbot, bwh;
9545 + bbot = au_dbbot(dentry);
9547 + bwh = au_dbwh(dentry);
9550 + if (0 < bwh && bwh < bbot)
9556 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9558 + aufs_bindex_t bbot, bopq;
9560 + bbot = au_dbtail(dentry);
9562 + bopq = au_dbdiropq(dentry);
9563 + if (0 <= bopq && bopq < bbot)
9569 +/* ---------------------------------------------------------------------- */
9571 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9572 + struct dentry *h_dentry)
9574 + struct au_dinfo *dinfo;
9575 + struct au_hdentry *hd;
9576 + struct au_branch *br;
9578 + DiMustWriteLock(dentry);
9580 + dinfo = au_di(dentry);
9581 + hd = au_hdentry(dinfo, bindex);
9583 + hd->hd_dentry = h_dentry;
9585 + br = au_sbr(dentry->d_sb, bindex);
9586 + hd->hd_id = br->br_id;
9590 +int au_dbrange_test(struct dentry *dentry)
9593 + aufs_bindex_t btop, bbot;
9596 + btop = au_dbtop(dentry);
9597 + bbot = au_dbbot(dentry);
9599 + AuDebugOn(bbot < 0 && btop > bbot);
9602 + AuDebugOn(bbot >= 0);
9608 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9613 + if (unlikely(au_digen(dentry) != sigen
9614 + || au_iigen_test(d_inode(dentry), sigen)))
9620 +void au_update_digen(struct dentry *dentry)
9622 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9623 + /* smp_mb(); */ /* atomic_set */
9626 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9628 + struct au_dinfo *dinfo;
9629 + struct dentry *h_d;
9630 + struct au_hdentry *hdp;
9631 + aufs_bindex_t bindex, bbot;
9633 + DiMustWriteLock(dentry);
9635 + dinfo = au_di(dentry);
9636 + if (!dinfo || dinfo->di_btop < 0)
9639 + if (do_put_zero) {
9640 + bbot = dinfo->di_bbot;
9641 + bindex = dinfo->di_btop;
9642 + hdp = au_hdentry(dinfo, bindex);
9643 + for (; bindex <= bbot; bindex++, hdp++) {
9644 + h_d = hdp->hd_dentry;
9645 + if (h_d && d_is_negative(h_d))
9646 + au_set_h_dptr(dentry, bindex, NULL);
9650 + dinfo->di_btop = 0;
9651 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9652 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9653 + if (hdp->hd_dentry)
9655 + if (dinfo->di_btop > dinfo->di_bbot) {
9656 + dinfo->di_btop = -1;
9657 + dinfo->di_bbot = -1;
9661 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9662 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9663 + if (hdp->hd_dentry)
9665 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9668 +void au_update_dbtop(struct dentry *dentry)
9670 + aufs_bindex_t bindex, bbot;
9671 + struct dentry *h_dentry;
9673 + bbot = au_dbbot(dentry);
9674 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9675 + h_dentry = au_h_dptr(dentry, bindex);
9678 + if (d_is_positive(h_dentry)) {
9679 + au_set_dbtop(dentry, bindex);
9682 + au_set_h_dptr(dentry, bindex, NULL);
9686 +void au_update_dbbot(struct dentry *dentry)
9688 + aufs_bindex_t bindex, btop;
9689 + struct dentry *h_dentry;
9691 + btop = au_dbtop(dentry);
9692 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9693 + h_dentry = au_h_dptr(dentry, bindex);
9696 + if (d_is_positive(h_dentry)) {
9697 + au_set_dbbot(dentry, bindex);
9700 + au_set_h_dptr(dentry, bindex, NULL);
9704 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9706 + aufs_bindex_t bindex, bbot;
9708 + bbot = au_dbbot(dentry);
9709 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9710 + if (au_h_dptr(dentry, bindex) == h_dentry)
9714 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9715 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9716 +++ linux/fs/aufs/dir.c 2017-07-29 12:14:25.899708630 +0200
9719 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9721 + * This program, aufs is free software; you can redistribute it and/or modify
9722 + * it under the terms of the GNU General Public License as published by
9723 + * the Free Software Foundation; either version 2 of the License, or
9724 + * (at your option) any later version.
9726 + * This program is distributed in the hope that it will be useful,
9727 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9729 + * GNU General Public License for more details.
9731 + * You should have received a copy of the GNU General Public License
9732 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9736 + * directory operations
9739 +#include <linux/fs_stack.h>
9742 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9744 + unsigned int nlink;
9746 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9748 + nlink = dir->i_nlink;
9749 + nlink += h_dir->i_nlink - 2;
9750 + if (h_dir->i_nlink < 2)
9752 + smp_mb(); /* for i_nlink */
9753 + /* 0 can happen in revaliding */
9754 + set_nlink(dir, nlink);
9757 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9759 + unsigned int nlink;
9761 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9763 + nlink = dir->i_nlink;
9764 + nlink -= h_dir->i_nlink - 2;
9765 + if (h_dir->i_nlink < 2)
9767 + smp_mb(); /* for i_nlink */
9768 + /* nlink == 0 means the branch-fs is broken */
9769 + set_nlink(dir, nlink);
9772 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9775 + aufs_bindex_t bindex, bbot;
9776 + struct file *h_file;
9777 + struct dentry *h_dentry;
9781 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9783 + bbot = au_fbbot_dir(file);
9784 + for (bindex = au_fbtop(file);
9785 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9787 + h_file = au_hf_dir(file, bindex);
9788 + if (h_file && file_inode(h_file))
9789 + sz += vfsub_f_size_read(h_file);
9792 + AuDebugOn(!dentry);
9793 + AuDebugOn(!d_is_dir(dentry));
9795 + bbot = au_dbtaildir(dentry);
9796 + for (bindex = au_dbtop(dentry);
9797 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9799 + h_dentry = au_h_dptr(dentry, bindex);
9800 + if (h_dentry && d_is_positive(h_dentry))
9801 + sz += i_size_read(d_inode(h_dentry));
9804 + if (sz < KMALLOC_MAX_SIZE)
9805 + sz = roundup_pow_of_two(sz);
9806 + if (sz > KMALLOC_MAX_SIZE)
9807 + sz = KMALLOC_MAX_SIZE;
9808 + else if (sz < NAME_MAX) {
9809 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9810 + sz = AUFS_RDBLK_DEF;
9815 +struct au_dir_ts_arg {
9816 + struct dentry *dentry;
9817 + aufs_bindex_t brid;
9820 +static void au_do_dir_ts(void *arg)
9822 + struct au_dir_ts_arg *a = arg;
9823 + struct au_dtime dt;
9824 + struct path h_path;
9825 + struct inode *dir, *h_dir;
9826 + struct super_block *sb;
9827 + struct au_branch *br;
9828 + struct au_hinode *hdir;
9830 + aufs_bindex_t btop, bindex;
9832 + sb = a->dentry->d_sb;
9833 + if (d_really_is_negative(a->dentry))
9835 + /* no dir->i_mutex lock */
9836 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9838 + dir = d_inode(a->dentry);
9839 + btop = au_ibtop(dir);
9840 + bindex = au_br_index(sb, a->brid);
9841 + if (bindex < btop)
9844 + br = au_sbr(sb, bindex);
9845 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9846 + if (!h_path.dentry)
9848 + h_path.mnt = au_br_mnt(br);
9849 + au_dtime_store(&dt, a->dentry, &h_path);
9851 + br = au_sbr(sb, btop);
9852 + if (!au_br_writable(br->br_perm))
9854 + h_path.dentry = au_h_dptr(a->dentry, btop);
9855 + h_path.mnt = au_br_mnt(br);
9856 + err = vfsub_mnt_want_write(h_path.mnt);
9859 + hdir = au_hi(dir, btop);
9860 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9861 + h_dir = au_h_iptr(dir, btop);
9862 + if (h_dir->i_nlink
9863 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9864 + dt.dt_h_path = h_path;
9865 + au_dtime_revert(&dt);
9867 + au_hn_inode_unlock(hdir);
9868 + vfsub_mnt_drop_write(h_path.mnt);
9869 + au_cpup_attr_timesizes(dir);
9872 + aufs_read_unlock(a->dentry, AuLock_DW);
9875 + au_nwt_done(&au_sbi(sb)->si_nowait);
9879 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9881 + int perm, wkq_err;
9882 + aufs_bindex_t btop;
9883 + struct au_dir_ts_arg *arg;
9884 + struct dentry *dentry;
9885 + struct super_block *sb;
9889 + dentry = d_find_any_alias(dir);
9890 + AuDebugOn(!dentry);
9891 + sb = dentry->d_sb;
9892 + btop = au_ibtop(dir);
9893 + if (btop == bindex) {
9894 + au_cpup_attr_timesizes(dir);
9898 + perm = au_sbr_perm(sb, btop);
9899 + if (!au_br_writable(perm))
9902 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9906 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9907 + arg->brid = au_sbr_id(sb, bindex);
9908 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9909 + if (unlikely(wkq_err)) {
9910 + pr_err("wkq %d\n", wkq_err);
9919 +/* ---------------------------------------------------------------------- */
9921 +static int reopen_dir(struct file *file)
9924 + unsigned int flags;
9925 + aufs_bindex_t bindex, btail, btop;
9926 + struct dentry *dentry, *h_dentry;
9927 + struct file *h_file;
9929 + /* open all lower dirs */
9930 + dentry = file->f_path.dentry;
9931 + btop = au_dbtop(dentry);
9932 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9933 + au_set_h_fptr(file, bindex, NULL);
9934 + au_set_fbtop(file, btop);
9936 + btail = au_dbtaildir(dentry);
9937 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9938 + au_set_h_fptr(file, bindex, NULL);
9939 + au_set_fbbot_dir(file, btail);
9941 + flags = vfsub_file_flags(file);
9942 + for (bindex = btop; bindex <= btail; bindex++) {
9943 + h_dentry = au_h_dptr(dentry, bindex);
9946 + h_file = au_hf_dir(file, bindex);
9950 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9951 + err = PTR_ERR(h_file);
9952 + if (IS_ERR(h_file))
9953 + goto out; /* close all? */
9954 + au_set_h_fptr(file, bindex, h_file);
9956 + au_update_figen(file);
9957 + /* todo: necessary? */
9958 + /* file->f_ra = h_file->f_ra; */
9965 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9968 + aufs_bindex_t bindex, btail;
9969 + struct dentry *dentry, *h_dentry;
9970 + struct vfsmount *mnt;
9972 + FiMustWriteLock(file);
9973 + AuDebugOn(h_file);
9976 + mnt = file->f_path.mnt;
9977 + dentry = file->f_path.dentry;
9978 + file->f_version = d_inode(dentry)->i_version;
9979 + bindex = au_dbtop(dentry);
9980 + au_set_fbtop(file, bindex);
9981 + btail = au_dbtaildir(dentry);
9982 + au_set_fbbot_dir(file, btail);
9983 + for (; !err && bindex <= btail; bindex++) {
9984 + h_dentry = au_h_dptr(dentry, bindex);
9988 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9989 + if (unlikely(err))
9991 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9992 + if (IS_ERR(h_file)) {
9993 + err = PTR_ERR(h_file);
9996 + au_set_h_fptr(file, bindex, h_file);
9998 + au_update_figen(file);
9999 + /* todo: necessary? */
10000 + /* file->f_ra = h_file->f_ra; */
10002 + return 0; /* success */
10005 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10006 + au_set_h_fptr(file, bindex, NULL);
10007 + au_set_fbtop(file, -1);
10008 + au_set_fbbot_dir(file, -1);
10013 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10014 + struct file *file)
10017 + struct super_block *sb;
10018 + struct au_fidir *fidir;
10021 + sb = file->f_path.dentry->d_sb;
10022 + si_read_lock(sb, AuLock_FLUSH);
10023 + fidir = au_fidir_alloc(sb);
10025 + struct au_do_open_args args = {
10026 + .open = do_open_dir,
10029 + err = au_do_open(file, &args);
10030 + if (unlikely(err))
10033 + si_read_unlock(sb);
10037 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10038 + struct file *file)
10040 + struct au_vdir *vdir_cache;
10041 + struct au_finfo *finfo;
10042 + struct au_fidir *fidir;
10043 + struct au_hfile *hf;
10044 + aufs_bindex_t bindex, bbot;
10046 + finfo = au_fi(file);
10047 + fidir = finfo->fi_hdir;
10049 + au_sphl_del(&finfo->fi_hlist,
10050 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10051 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10053 + au_vdir_free(vdir_cache);
10055 + bindex = finfo->fi_btop;
10056 + if (bindex >= 0) {
10057 + hf = fidir->fd_hfile + bindex;
10059 + * calls fput() instead of filp_close(),
10060 + * since no dnotify or lock for the lower file.
10062 + bbot = fidir->fd_bbot;
10063 + for (; bindex <= bbot; bindex++, hf++)
10065 + au_hfput(hf, /*execed*/0);
10068 + finfo->fi_hdir = NULL;
10070 + au_finfo_fin(file);
10074 +/* ---------------------------------------------------------------------- */
10076 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10079 + aufs_bindex_t bindex, bbot;
10080 + struct file *h_file;
10083 + bbot = au_fbbot_dir(file);
10084 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10085 + h_file = au_hf_dir(file, bindex);
10087 + err = vfsub_flush(h_file, id);
10092 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10094 + return au_do_flush(file, id, au_do_flush_dir);
10097 +/* ---------------------------------------------------------------------- */
10099 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10102 + aufs_bindex_t bbot, bindex;
10103 + struct inode *inode;
10104 + struct super_block *sb;
10107 + sb = dentry->d_sb;
10108 + inode = d_inode(dentry);
10109 + IMustLock(inode);
10110 + bbot = au_dbbot(dentry);
10111 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10112 + struct path h_path;
10114 + if (au_test_ro(sb, bindex, inode))
10116 + h_path.dentry = au_h_dptr(dentry, bindex);
10117 + if (!h_path.dentry)
10120 + h_path.mnt = au_sbr_mnt(sb, bindex);
10121 + err = vfsub_fsync(NULL, &h_path, datasync);
10127 +static int au_do_fsync_dir(struct file *file, int datasync)
10130 + aufs_bindex_t bbot, bindex;
10131 + struct file *h_file;
10132 + struct super_block *sb;
10133 + struct inode *inode;
10135 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10136 + if (unlikely(err))
10139 + inode = file_inode(file);
10140 + sb = inode->i_sb;
10141 + bbot = au_fbbot_dir(file);
10142 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10143 + h_file = au_hf_dir(file, bindex);
10144 + if (!h_file || au_test_ro(sb, bindex, inode))
10147 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10155 + * @file may be NULL
10157 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10161 + struct dentry *dentry;
10162 + struct inode *inode;
10163 + struct super_block *sb;
10166 + dentry = file->f_path.dentry;
10167 + inode = d_inode(dentry);
10168 + inode_lock(inode);
10169 + sb = dentry->d_sb;
10170 + si_noflush_read_lock(sb);
10172 + err = au_do_fsync_dir(file, datasync);
10174 + di_write_lock_child(dentry);
10175 + err = au_do_fsync_dir_no_file(dentry, datasync);
10177 + au_cpup_attr_timesizes(inode);
10178 + di_write_unlock(dentry);
10180 + fi_write_unlock(file);
10182 + si_read_unlock(sb);
10183 + inode_unlock(inode);
10187 +/* ---------------------------------------------------------------------- */
10189 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10192 + struct dentry *dentry;
10193 + struct inode *inode, *h_inode;
10194 + struct super_block *sb;
10196 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10198 + dentry = file->f_path.dentry;
10199 + inode = d_inode(dentry);
10200 + IMustLock(inode);
10202 + sb = dentry->d_sb;
10203 + si_read_lock(sb, AuLock_FLUSH);
10204 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10205 + if (unlikely(err))
10207 + err = au_alive_dir(dentry);
10209 + err = au_vdir_init(file);
10210 + di_downgrade_lock(dentry, AuLock_IR);
10211 + if (unlikely(err))
10214 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10215 + if (!au_test_nfsd()) {
10216 + err = au_vdir_fill_de(file, ctx);
10217 + fsstack_copy_attr_atime(inode, h_inode);
10220 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10221 + * encode_fh() and others.
10223 + atomic_inc(&h_inode->i_count);
10224 + di_read_unlock(dentry, AuLock_IR);
10225 + si_read_unlock(sb);
10226 + err = au_vdir_fill_de(file, ctx);
10227 + fsstack_copy_attr_atime(inode, h_inode);
10228 + fi_write_unlock(file);
10236 + di_read_unlock(dentry, AuLock_IR);
10237 + fi_write_unlock(file);
10239 + si_read_unlock(sb);
10243 +/* ---------------------------------------------------------------------- */
10245 +#define AuTestEmpty_WHONLY 1
10246 +#define AuTestEmpty_CALLED (1 << 1)
10247 +#define AuTestEmpty_SHWH (1 << 2)
10248 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10249 +#define au_fset_testempty(flags, name) \
10250 + do { (flags) |= AuTestEmpty_##name; } while (0)
10251 +#define au_fclr_testempty(flags, name) \
10252 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10254 +#ifndef CONFIG_AUFS_SHWH
10255 +#undef AuTestEmpty_SHWH
10256 +#define AuTestEmpty_SHWH 0
10259 +struct test_empty_arg {
10260 + struct dir_context ctx;
10261 + struct au_nhash *whlist;
10262 + unsigned int flags;
10264 + aufs_bindex_t bindex;
10267 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10268 + int namelen, loff_t offset __maybe_unused, u64 ino,
10269 + unsigned int d_type)
10271 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10273 + char *name = (void *)__name;
10276 + au_fset_testempty(arg->flags, CALLED);
10278 + if (name[0] == '.'
10279 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10280 + goto out; /* success */
10282 + if (namelen <= AUFS_WH_PFX_LEN
10283 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10284 + if (au_ftest_testempty(arg->flags, WHONLY)
10285 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10286 + arg->err = -ENOTEMPTY;
10290 + name += AUFS_WH_PFX_LEN;
10291 + namelen -= AUFS_WH_PFX_LEN;
10292 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10293 + arg->err = au_nhash_append_wh
10294 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10295 + au_ftest_testempty(arg->flags, SHWH));
10299 + AuTraceErr(arg->err);
10303 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10306 + struct file *h_file;
10308 + h_file = au_h_open(dentry, arg->bindex,
10309 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10310 + /*file*/NULL, /*force_wr*/0);
10311 + err = PTR_ERR(h_file);
10312 + if (IS_ERR(h_file))
10316 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10317 + && !file_inode(h_file)->i_nlink)
10322 + au_fclr_testempty(arg->flags, CALLED);
10324 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10327 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10331 + au_sbr_put(dentry->d_sb, arg->bindex);
10336 +struct do_test_empty_args {
10338 + struct dentry *dentry;
10339 + struct test_empty_arg *arg;
10342 +static void call_do_test_empty(void *args)
10344 + struct do_test_empty_args *a = args;
10345 + *a->errp = do_test_empty(a->dentry, a->arg);
10348 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10350 + int err, wkq_err;
10351 + struct dentry *h_dentry;
10352 + struct inode *h_inode;
10354 + h_dentry = au_h_dptr(dentry, arg->bindex);
10355 + h_inode = d_inode(h_dentry);
10356 + /* todo: i_mode changes anytime? */
10357 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10358 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10359 + inode_unlock(h_inode);
10361 + err = do_test_empty(dentry, arg);
10363 + struct do_test_empty_args args = {
10365 + .dentry = dentry,
10368 + unsigned int flags = arg->flags;
10370 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10371 + if (unlikely(wkq_err))
10373 + arg->flags = flags;
10379 +int au_test_empty_lower(struct dentry *dentry)
10382 + unsigned int rdhash;
10383 + aufs_bindex_t bindex, btop, btail;
10384 + struct au_nhash whlist;
10385 + struct test_empty_arg arg = {
10387 + .actor = test_empty_cb
10390 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10392 + SiMustAnyLock(dentry->d_sb);
10394 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10396 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10397 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10398 + if (unlikely(err))
10402 + arg.whlist = &whlist;
10403 + btop = au_dbtop(dentry);
10404 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10405 + au_fset_testempty(arg.flags, SHWH);
10406 + test_empty = do_test_empty;
10407 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10408 + test_empty = sio_test_empty;
10409 + arg.bindex = btop;
10410 + err = test_empty(dentry, &arg);
10411 + if (unlikely(err))
10414 + au_fset_testempty(arg.flags, WHONLY);
10415 + btail = au_dbtaildir(dentry);
10416 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10417 + struct dentry *h_dentry;
10419 + h_dentry = au_h_dptr(dentry, bindex);
10420 + if (h_dentry && d_is_positive(h_dentry)) {
10421 + arg.bindex = bindex;
10422 + err = test_empty(dentry, &arg);
10427 + au_nhash_wh_free(&whlist);
10432 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10435 + struct test_empty_arg arg = {
10437 + .actor = test_empty_cb
10440 + aufs_bindex_t bindex, btail;
10443 + arg.whlist = whlist;
10444 + arg.flags = AuTestEmpty_WHONLY;
10445 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10446 + au_fset_testempty(arg.flags, SHWH);
10447 + btail = au_dbtaildir(dentry);
10448 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10449 + struct dentry *h_dentry;
10451 + h_dentry = au_h_dptr(dentry, bindex);
10452 + if (h_dentry && d_is_positive(h_dentry)) {
10453 + arg.bindex = bindex;
10454 + err = sio_test_empty(dentry, &arg);
10461 +/* ---------------------------------------------------------------------- */
10463 +const struct file_operations aufs_dir_fop = {
10464 + .owner = THIS_MODULE,
10465 + .llseek = default_llseek,
10466 + .read = generic_read_dir,
10467 + .iterate_shared = aufs_iterate_shared,
10468 + .unlocked_ioctl = aufs_ioctl_dir,
10469 +#ifdef CONFIG_COMPAT
10470 + .compat_ioctl = aufs_compat_ioctl_dir,
10472 + .open = aufs_open_dir,
10473 + .release = aufs_release_dir,
10474 + .flush = aufs_flush_dir,
10475 + .fsync = aufs_fsync_dir
10477 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10478 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10479 +++ linux/fs/aufs/dir.h 2017-07-29 12:14:25.899708630 +0200
10482 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10484 + * This program, aufs is free software; you can redistribute it and/or modify
10485 + * it under the terms of the GNU General Public License as published by
10486 + * the Free Software Foundation; either version 2 of the License, or
10487 + * (at your option) any later version.
10489 + * This program is distributed in the hope that it will be useful,
10490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10492 + * GNU General Public License for more details.
10494 + * You should have received a copy of the GNU General Public License
10495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10499 + * directory operations
10502 +#ifndef __AUFS_DIR_H__
10503 +#define __AUFS_DIR_H__
10507 +#include <linux/fs.h>
10509 +/* ---------------------------------------------------------------------- */
10511 +/* need to be faster and smaller */
10514 + unsigned int nh_num;
10515 + struct hlist_head *nh_head;
10518 +struct au_vdir_destr {
10519 + unsigned char len;
10520 + unsigned char name[0];
10523 +struct au_vdir_dehstr {
10524 + struct hlist_node hash;
10525 + struct au_vdir_destr *str;
10526 +} ____cacheline_aligned_in_smp;
10528 +struct au_vdir_de {
10530 + unsigned char de_type;
10531 + /* caution: packed */
10532 + struct au_vdir_destr de_str;
10535 +struct au_vdir_wh {
10536 + struct hlist_node wh_hash;
10537 +#ifdef CONFIG_AUFS_SHWH
10539 + aufs_bindex_t wh_bindex;
10540 + unsigned char wh_type;
10542 + aufs_bindex_t wh_bindex;
10544 + /* caution: packed */
10545 + struct au_vdir_destr wh_str;
10548 +union au_vdir_deblk_p {
10549 + unsigned char *deblk;
10550 + struct au_vdir_de *de;
10554 + unsigned char **vd_deblk;
10555 + unsigned long vd_nblk;
10557 + unsigned long ul;
10558 + union au_vdir_deblk_p p;
10561 + unsigned long vd_version;
10562 + unsigned int vd_deblk_sz;
10563 + unsigned long vd_jiffy;
10564 +} ____cacheline_aligned_in_smp;
10566 +/* ---------------------------------------------------------------------- */
10569 +extern const struct file_operations aufs_dir_fop;
10570 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10571 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10572 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10573 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10574 +int au_test_empty_lower(struct dentry *dentry);
10575 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10578 +unsigned int au_rdhash_est(loff_t sz);
10579 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10580 +void au_nhash_wh_free(struct au_nhash *whlist);
10581 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10583 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10584 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10585 + unsigned int d_type, aufs_bindex_t bindex,
10586 + unsigned char shwh);
10587 +void au_vdir_free(struct au_vdir *vdir);
10588 +int au_vdir_init(struct file *file);
10589 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10592 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10594 +#ifdef CONFIG_AUFS_RDU
10596 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10597 +#ifdef CONFIG_COMPAT
10598 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10599 + unsigned long arg);
10602 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10603 + unsigned int cmd, unsigned long arg)
10604 +#ifdef CONFIG_COMPAT
10605 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10606 + unsigned int cmd, unsigned long arg)
10610 +#endif /* __KERNEL__ */
10611 +#endif /* __AUFS_DIR_H__ */
10612 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10613 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10614 +++ linux/fs/aufs/dynop.c 2017-07-29 12:14:25.899708630 +0200
10617 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10619 + * This program, aufs is free software; you can redistribute it and/or modify
10620 + * it under the terms of the GNU General Public License as published by
10621 + * the Free Software Foundation; either version 2 of the License, or
10622 + * (at your option) any later version.
10624 + * This program is distributed in the hope that it will be useful,
10625 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10626 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10627 + * GNU General Public License for more details.
10629 + * You should have received a copy of the GNU General Public License
10630 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10634 + * dynamically customizable operations for regular files
10639 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10642 + * How large will these lists be?
10643 + * Usually just a few elements, 20-30 at most for each, I guess.
10645 +static struct au_sphlhead dynop[AuDyLast];
10647 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10649 + struct au_dykey *key, *tmp;
10650 + struct hlist_head *head;
10653 + head = &sphl->head;
10655 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10656 + if (tmp->dk_op.dy_hop == h_op) {
10658 + kref_get(&key->dk_kref);
10661 + rcu_read_unlock();
10666 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10668 + struct au_dykey **k, *found;
10669 + const void *h_op = key->dk_op.dy_hop;
10673 + k = br->br_dykey;
10674 + for (i = 0; i < AuBrDynOp; i++)
10676 + if (k[i]->dk_op.dy_hop == h_op) {
10683 + spin_lock(&br->br_dykey_lock);
10684 + for (; i < AuBrDynOp; i++)
10686 + if (k[i]->dk_op.dy_hop == h_op) {
10694 + spin_unlock(&br->br_dykey_lock);
10695 + BUG_ON(i == AuBrDynOp); /* expand the array */
10701 +/* kref_get() if @key is already added */
10702 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10704 + struct au_dykey *tmp, *found;
10705 + struct hlist_head *head;
10706 + const void *h_op = key->dk_op.dy_hop;
10709 + head = &sphl->head;
10710 + spin_lock(&sphl->spin);
10711 + hlist_for_each_entry(tmp, head, dk_hnode)
10712 + if (tmp->dk_op.dy_hop == h_op) {
10713 + kref_get(&tmp->dk_kref);
10718 + hlist_add_head_rcu(&key->dk_hnode, head);
10719 + spin_unlock(&sphl->spin);
10726 +static void dy_free_rcu(struct rcu_head *rcu)
10728 + struct au_dykey *key;
10730 + key = container_of(rcu, struct au_dykey, dk_rcu);
10735 +static void dy_free(struct kref *kref)
10737 + struct au_dykey *key;
10738 + struct au_sphlhead *sphl;
10740 + key = container_of(kref, struct au_dykey, dk_kref);
10741 + sphl = dynop + key->dk_op.dy_type;
10742 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10743 + call_rcu(&key->dk_rcu, dy_free_rcu);
10746 +void au_dy_put(struct au_dykey *key)
10748 + kref_put(&key->dk_kref, dy_free);
10751 +/* ---------------------------------------------------------------------- */
10753 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10755 +#ifdef CONFIG_AUFS_DEBUG
10756 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10757 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10759 +#define DyDbgDeclare(cnt) do {} while (0)
10760 +#define DyDbgInc(cnt) do {} while (0)
10763 +#define DySet(func, dst, src, h_op, h_sb) do { \
10765 + if (h_op->func) { \
10767 + dst.func = src.func; \
10769 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10773 +#define DySetForce(func, dst, src) do { \
10774 + AuDebugOn(!src.func); \
10776 + dst.func = src.func; \
10779 +#define DySetAop(func) \
10780 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10781 +#define DySetAopForce(func) \
10782 + DySetForce(func, dyaop->da_op, aufs_aop)
10784 +static void dy_aop(struct au_dykey *key, const void *h_op,
10785 + struct super_block *h_sb __maybe_unused)
10787 + struct au_dyaop *dyaop = (void *)key;
10788 + const struct address_space_operations *h_aop = h_op;
10789 + DyDbgDeclare(cnt);
10791 + AuDbg("%s\n", au_sbtype(h_sb));
10793 + DySetAop(writepage);
10794 + DySetAopForce(readpage); /* force */
10795 + DySetAop(writepages);
10796 + DySetAop(set_page_dirty);
10797 + DySetAop(readpages);
10798 + DySetAop(write_begin);
10799 + DySetAop(write_end);
10801 + DySetAop(invalidatepage);
10802 + DySetAop(releasepage);
10803 + DySetAop(freepage);
10804 + /* this one will be changed according to an aufs mount option */
10805 + DySetAop(direct_IO);
10806 + DySetAop(migratepage);
10807 + DySetAop(isolate_page);
10808 + DySetAop(putback_page);
10809 + DySetAop(launder_page);
10810 + DySetAop(is_partially_uptodate);
10811 + DySetAop(is_dirty_writeback);
10812 + DySetAop(error_remove_page);
10813 + DySetAop(swap_activate);
10814 + DySetAop(swap_deactivate);
10816 + DyDbgSize(cnt, *h_aop);
10819 +/* ---------------------------------------------------------------------- */
10821 +static void dy_bug(struct kref *kref)
10826 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10828 + struct au_dykey *key, *old;
10829 + struct au_sphlhead *sphl;
10832 + void (*set)(struct au_dykey *key, const void *h_op,
10833 + struct super_block *h_sb __maybe_unused);
10835 + static const struct op a[] = {
10837 + .sz = sizeof(struct au_dyaop),
10841 + const struct op *p;
10843 + sphl = dynop + op->dy_type;
10844 + key = dy_gfind_get(sphl, op->dy_hop);
10846 + goto out_add; /* success */
10848 + p = a + op->dy_type;
10849 + key = kzalloc(p->sz, GFP_NOFS);
10850 + if (unlikely(!key)) {
10851 + key = ERR_PTR(-ENOMEM);
10855 + key->dk_op.dy_hop = op->dy_hop;
10856 + kref_init(&key->dk_kref);
10857 + p->set(key, op->dy_hop, au_br_sb(br));
10858 + old = dy_gadd(sphl, key);
10865 + old = dy_bradd(br, key);
10867 + /* its ref-count should never be zero here */
10868 + kref_put(&key->dk_kref, dy_bug);
10873 +/* ---------------------------------------------------------------------- */
10875 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10876 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10877 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10878 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10879 + * See the aufs manual in detail.
10881 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10884 + dyaop->da_op.direct_IO = NULL;
10886 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10889 +static struct au_dyaop *dy_aget(struct au_branch *br,
10890 + const struct address_space_operations *h_aop,
10893 + struct au_dyaop *dyaop;
10894 + struct au_dynop op;
10896 + op.dy_type = AuDy_AOP;
10897 + op.dy_haop = h_aop;
10898 + dyaop = (void *)dy_get(&op, br);
10899 + if (IS_ERR(dyaop))
10901 + dy_adx(dyaop, do_dx);
10907 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10908 + struct inode *h_inode)
10911 + struct super_block *sb;
10912 + struct au_branch *br;
10913 + struct au_dyaop *dyaop;
10915 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10916 + IiMustWriteLock(inode);
10918 + sb = inode->i_sb;
10919 + br = au_sbr(sb, bindex);
10920 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10921 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10922 + err = PTR_ERR(dyaop);
10923 + if (IS_ERR(dyaop))
10924 + /* unnecessary to call dy_fput() */
10928 + inode->i_mapping->a_ops = &dyaop->da_op;
10935 + * Is it safe to replace a_ops during the inode/file is in operation?
10936 + * Yes, I hope so.
10938 +int au_dy_irefresh(struct inode *inode)
10941 + aufs_bindex_t btop;
10942 + struct inode *h_inode;
10945 + if (S_ISREG(inode->i_mode)) {
10946 + btop = au_ibtop(inode);
10947 + h_inode = au_h_iptr(inode, btop);
10948 + err = au_dy_iaop(inode, btop, h_inode);
10953 +void au_dy_arefresh(int do_dx)
10955 + struct au_sphlhead *sphl;
10956 + struct hlist_head *head;
10957 + struct au_dykey *key;
10959 + sphl = dynop + AuDy_AOP;
10960 + head = &sphl->head;
10961 + spin_lock(&sphl->spin);
10962 + hlist_for_each_entry(key, head, dk_hnode)
10963 + dy_adx((void *)key, do_dx);
10964 + spin_unlock(&sphl->spin);
10967 +/* ---------------------------------------------------------------------- */
10969 +void __init au_dy_init(void)
10973 + /* make sure that 'struct au_dykey *' can be any type */
10974 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10976 + for (i = 0; i < AuDyLast; i++)
10977 + au_sphl_init(dynop + i);
10980 +void au_dy_fin(void)
10984 + for (i = 0; i < AuDyLast; i++)
10985 + WARN_ON(!hlist_empty(&dynop[i].head));
10987 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10988 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10989 +++ linux/fs/aufs/dynop.h 2017-07-29 12:14:25.899708630 +0200
10992 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10994 + * This program, aufs is free software; you can redistribute it and/or modify
10995 + * it under the terms of the GNU General Public License as published by
10996 + * the Free Software Foundation; either version 2 of the License, or
10997 + * (at your option) any later version.
10999 + * This program is distributed in the hope that it will be useful,
11000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11002 + * GNU General Public License for more details.
11004 + * You should have received a copy of the GNU General Public License
11005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11009 + * dynamically customizable operations (for regular files only)
11012 +#ifndef __AUFS_DYNOP_H__
11013 +#define __AUFS_DYNOP_H__
11017 +#include <linux/fs.h>
11018 +#include <linux/kref.h>
11020 +enum {AuDy_AOP, AuDyLast};
11025 + const void *dy_hop;
11026 + const struct address_space_operations *dy_haop;
11032 + struct hlist_node dk_hnode;
11033 + struct rcu_head dk_rcu;
11035 + struct au_dynop dk_op;
11038 + * during I am in the branch local array, kref is gotten. when the
11039 + * branch is removed, kref is put.
11041 + struct kref dk_kref;
11044 +/* stop unioning since their sizes are very different from each other */
11046 + struct au_dykey da_key;
11047 + struct address_space_operations da_op; /* not const */
11050 +/* ---------------------------------------------------------------------- */
11054 +void au_dy_put(struct au_dykey *key);
11055 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
11056 + struct inode *h_inode);
11057 +int au_dy_irefresh(struct inode *inode);
11058 +void au_dy_arefresh(int do_dio);
11060 +void __init au_dy_init(void);
11061 +void au_dy_fin(void);
11063 +#endif /* __KERNEL__ */
11064 +#endif /* __AUFS_DYNOP_H__ */
11065 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
11066 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
11067 +++ linux/fs/aufs/export.c 2017-07-29 12:14:25.903042072 +0200
11070 + * Copyright (C) 2005-2017 Junjiro R. Okajima
11072 + * This program, aufs is free software; you can redistribute it and/or modify
11073 + * it under the terms of the GNU General Public License as published by
11074 + * the Free Software Foundation; either version 2 of the License, or
11075 + * (at your option) any later version.
11077 + * This program is distributed in the hope that it will be useful,
11078 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11079 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11080 + * GNU General Public License for more details.
11082 + * You should have received a copy of the GNU General Public License
11083 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11090 +#include <linux/exportfs.h>
11091 +#include <linux/fs_struct.h>
11092 +#include <linux/namei.h>
11093 +#include <linux/nsproxy.h>
11094 +#include <linux/random.h>
11095 +#include <linux/writeback.h>
11099 +#ifdef CONFIG_AUFS_INO_T_64
11107 +static ino_t decode_ino(__u32 *a)
11111 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11113 +#ifdef CONFIG_AUFS_INO_T_64
11119 +static void encode_ino(__u32 *a, ino_t ino)
11125 +#ifdef CONFIG_AUFS_INO_T_64
11130 +/* NFS file handle */
11134 +#ifdef CONFIG_AUFS_INO_T_64
11135 + /* support 64bit inode number */
11148 + Fh_ino = Fh_ino1,
11149 + Fh_dir_ino = Fh_dir_ino1
11152 +static int au_test_anon(struct dentry *dentry)
11154 + /* note: read d_flags without d_lock */
11155 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11158 +int au_test_nfsd(void)
11161 + struct task_struct *tsk = current;
11162 + char comm[sizeof(tsk->comm)];
11165 + if (tsk->flags & PF_KTHREAD) {
11166 + get_task_comm(comm, tsk);
11167 + ret = !strcmp(comm, "nfsd");
11173 +/* ---------------------------------------------------------------------- */
11174 +/* inode generation external table */
11176 +void au_xigen_inc(struct inode *inode)
11181 + struct super_block *sb;
11182 + struct au_sbinfo *sbinfo;
11184 + sb = inode->i_sb;
11185 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11187 + sbinfo = au_sbi(sb);
11188 + pos = inode->i_ino;
11189 + pos *= sizeof(igen);
11190 + igen = inode->i_generation + 1;
11191 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11192 + sizeof(igen), &pos);
11193 + if (sz == sizeof(igen))
11194 + return; /* success */
11196 + if (unlikely(sz >= 0))
11197 + AuIOErr("xigen error (%zd)\n", sz);
11200 +int au_xigen_new(struct inode *inode)
11205 + struct super_block *sb;
11206 + struct au_sbinfo *sbinfo;
11207 + struct file *file;
11210 + /* todo: dirty, at mount time */
11211 + if (inode->i_ino == AUFS_ROOT_INO)
11213 + sb = inode->i_sb;
11214 + SiMustAnyLock(sb);
11215 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11219 + pos = inode->i_ino;
11220 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11221 + AuIOErr1("too large i%lld\n", pos);
11224 + pos *= sizeof(inode->i_generation);
11227 + sbinfo = au_sbi(sb);
11228 + file = sbinfo->si_xigen;
11231 + if (vfsub_f_size_read(file)
11232 + < pos + sizeof(inode->i_generation)) {
11233 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11234 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11235 + sizeof(inode->i_generation), &pos);
11237 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11238 + sizeof(inode->i_generation), &pos);
11239 + if (sz == sizeof(inode->i_generation))
11240 + goto out; /* success */
11243 + if (unlikely(sz >= 0)) {
11245 + AuIOErr("xigen error (%zd)\n", sz);
11252 +int au_xigen_set(struct super_block *sb, struct file *base)
11255 + struct au_sbinfo *sbinfo;
11256 + struct file *file;
11258 + SiMustWriteLock(sb);
11260 + sbinfo = au_sbi(sb);
11261 + file = au_xino_create2(base, sbinfo->si_xigen);
11262 + err = PTR_ERR(file);
11263 + if (IS_ERR(file))
11266 + if (sbinfo->si_xigen)
11267 + fput(sbinfo->si_xigen);
11268 + sbinfo->si_xigen = file;
11274 +void au_xigen_clr(struct super_block *sb)
11276 + struct au_sbinfo *sbinfo;
11278 + SiMustWriteLock(sb);
11280 + sbinfo = au_sbi(sb);
11281 + if (sbinfo->si_xigen) {
11282 + fput(sbinfo->si_xigen);
11283 + sbinfo->si_xigen = NULL;
11287 +/* ---------------------------------------------------------------------- */
11289 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11292 + struct dentry *dentry, *d;
11293 + struct inode *inode;
11294 + unsigned int sigen;
11297 + inode = ilookup(sb, ino);
11301 + dentry = ERR_PTR(-ESTALE);
11302 + sigen = au_sigen(sb);
11303 + if (unlikely(au_is_bad_inode(inode)
11304 + || IS_DEADDIR(inode)
11305 + || sigen != au_iigen(inode, NULL)))
11309 + if (!dir_ino || S_ISDIR(inode->i_mode))
11310 + dentry = d_find_alias(inode);
11312 + spin_lock(&inode->i_lock);
11313 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11314 + spin_lock(&d->d_lock);
11315 + if (!au_test_anon(d)
11316 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11317 + dentry = dget_dlock(d);
11318 + spin_unlock(&d->d_lock);
11321 + spin_unlock(&d->d_lock);
11323 + spin_unlock(&inode->i_lock);
11325 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11326 + /* need to refresh */
11334 + AuTraceErrPtr(dentry);
11338 +/* ---------------------------------------------------------------------- */
11340 +/* todo: dirty? */
11341 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11343 +struct au_compare_mnt_args {
11345 + struct super_block *sb;
11348 + struct vfsmount *mnt;
11351 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11353 + struct au_compare_mnt_args *a = arg;
11355 + if (mnt->mnt_sb != a->sb)
11357 + a->mnt = mntget(mnt);
11361 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11364 + struct path root;
11365 + struct au_compare_mnt_args args = {
11369 + get_fs_root(current->fs, &root);
11371 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11372 + rcu_read_unlock();
11375 + AuDebugOn(!args.mnt);
11379 +struct au_nfsd_si_lock {
11380 + unsigned int sigen;
11381 + aufs_bindex_t bindex, br_id;
11382 + unsigned char force_lock;
11385 +static int si_nfsd_read_lock(struct super_block *sb,
11386 + struct au_nfsd_si_lock *nsi_lock)
11389 + aufs_bindex_t bindex;
11391 + si_read_lock(sb, AuLock_FLUSH);
11393 + /* branch id may be wrapped around */
11395 + bindex = au_br_index(sb, nsi_lock->br_id);
11396 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11397 + goto out; /* success */
11401 + if (!nsi_lock->force_lock)
11402 + si_read_unlock(sb);
11405 + nsi_lock->bindex = bindex;
11409 +struct find_name_by_ino {
11410 + struct dir_context ctx;
11411 + int called, found;
11418 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11419 + loff_t offset, u64 ino, unsigned int d_type)
11421 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11425 + if (a->ino != ino)
11428 + memcpy(a->name, name, namelen);
11429 + a->namelen = namelen;
11434 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11435 + struct au_nfsd_si_lock *nsi_lock)
11437 + struct dentry *dentry, *parent;
11438 + struct file *file;
11439 + struct inode *dir;
11440 + struct find_name_by_ino arg = {
11442 + .actor = find_name_by_ino
11447 + parent = path->dentry;
11449 + si_read_unlock(parent->d_sb);
11450 + file = vfsub_dentry_open(path, au_dir_roflags);
11451 + dentry = (void *)file;
11452 + if (IS_ERR(file))
11455 + dentry = ERR_PTR(-ENOMEM);
11456 + arg.name = (void *)__get_free_page(GFP_NOFS);
11457 + if (unlikely(!arg.name))
11464 + err = vfsub_iterate_dir(file, &arg.ctx);
11465 + } while (!err && !arg.found && arg.called);
11466 + dentry = ERR_PTR(err);
11467 + if (unlikely(err))
11469 + /* instead of ENOENT */
11470 + dentry = ERR_PTR(-ESTALE);
11474 + /* do not call vfsub_lkup_one() */
11475 + dir = d_inode(parent);
11476 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11477 + AuTraceErrPtr(dentry);
11478 + if (IS_ERR(dentry))
11480 + AuDebugOn(au_test_anon(dentry));
11481 + if (unlikely(d_really_is_negative(dentry))) {
11483 + dentry = ERR_PTR(-ENOENT);
11487 + free_page((unsigned long)arg.name);
11491 + if (unlikely(nsi_lock
11492 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11493 + if (!IS_ERR(dentry)) {
11495 + dentry = ERR_PTR(-ESTALE);
11497 + AuTraceErrPtr(dentry);
11501 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11503 + struct au_nfsd_si_lock *nsi_lock)
11505 + struct dentry *dentry;
11506 + struct path path;
11508 + if (dir_ino != AUFS_ROOT_INO) {
11509 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11510 + dentry = path.dentry;
11511 + if (!path.dentry || IS_ERR(path.dentry))
11513 + AuDebugOn(au_test_anon(path.dentry));
11515 + path.dentry = dget(sb->s_root);
11517 + path.mnt = au_mnt_get(sb);
11518 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11522 + AuTraceErrPtr(dentry);
11526 +/* ---------------------------------------------------------------------- */
11528 +static int h_acceptable(void *expv, struct dentry *dentry)
11533 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11534 + char *buf, int len, struct super_block *sb)
11538 + struct path path;
11540 + p = d_path(h_rootpath, buf, len);
11545 + path.mnt = h_rootpath->mnt;
11546 + path.dentry = h_parent;
11547 + p = d_path(&path, buf, len);
11553 + path.mnt = au_mnt_get(sb);
11554 + path.dentry = sb->s_root;
11555 + p = d_path(&path, buf, len - strlen(p));
11556 + mntput(path.mnt);
11560 + p[strlen(p)] = '/';
11563 + AuTraceErrPtr(p);
11568 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11569 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11571 + struct dentry *dentry, *h_parent, *root;
11572 + struct super_block *h_sb;
11573 + char *pathname, *p;
11574 + struct vfsmount *h_mnt;
11575 + struct au_branch *br;
11577 + struct path path;
11579 + br = au_sbr(sb, nsi_lock->bindex);
11580 + h_mnt = au_br_mnt(br);
11581 + h_sb = h_mnt->mnt_sb;
11582 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11584 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11585 + fh_len - Fh_tail, fh[Fh_h_type],
11586 + h_acceptable, /*context*/NULL);
11588 + dentry = h_parent;
11589 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11590 + AuWarn1("%s decode_fh failed, %ld\n",
11591 + au_sbtype(h_sb), PTR_ERR(h_parent));
11595 + if (unlikely(au_test_anon(h_parent))) {
11596 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11597 + au_sbtype(h_sb));
11598 + goto out_h_parent;
11601 + dentry = ERR_PTR(-ENOMEM);
11602 + pathname = (void *)__get_free_page(GFP_NOFS);
11603 + if (unlikely(!pathname))
11604 + goto out_h_parent;
11606 + root = sb->s_root;
11607 + path.mnt = h_mnt;
11608 + di_read_lock_parent(root, !AuLock_IR);
11609 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11610 + di_read_unlock(root, !AuLock_IR);
11611 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11612 + dentry = (void *)p;
11614 + goto out_pathname;
11616 + si_read_unlock(sb);
11617 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11618 + dentry = ERR_PTR(err);
11619 + if (unlikely(err))
11622 + dentry = ERR_PTR(-ENOENT);
11623 + AuDebugOn(au_test_anon(path.dentry));
11624 + if (unlikely(d_really_is_negative(path.dentry)))
11627 + if (ino != d_inode(path.dentry)->i_ino)
11628 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11630 + dentry = dget(path.dentry);
11635 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11636 + if (!IS_ERR(dentry)) {
11638 + dentry = ERR_PTR(-ESTALE);
11641 + free_page((unsigned long)pathname);
11645 + AuTraceErrPtr(dentry);
11649 +/* ---------------------------------------------------------------------- */
11651 +static struct dentry *
11652 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11655 + struct dentry *dentry;
11656 + __u32 *fh = fid->raw;
11657 + struct au_branch *br;
11658 + ino_t ino, dir_ino;
11659 + struct au_nfsd_si_lock nsi_lock = {
11663 + dentry = ERR_PTR(-ESTALE);
11664 + /* it should never happen, but the file handle is unreliable */
11665 + if (unlikely(fh_len < Fh_tail))
11667 + nsi_lock.sigen = fh[Fh_sigen];
11668 + nsi_lock.br_id = fh[Fh_br_id];
11670 + /* branch id may be wrapped around */
11672 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11674 + nsi_lock.force_lock = 1;
11676 + /* is this inode still cached? */
11677 + ino = decode_ino(fh + Fh_ino);
11678 + /* it should never happen */
11679 + if (unlikely(ino == AUFS_ROOT_INO))
11682 + dir_ino = decode_ino(fh + Fh_dir_ino);
11683 + dentry = decode_by_ino(sb, ino, dir_ino);
11684 + if (IS_ERR(dentry))
11689 + /* is the parent dir cached? */
11690 + br = au_sbr(sb, nsi_lock.bindex);
11692 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11693 + if (IS_ERR(dentry))
11698 + /* lookup path */
11699 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11700 + if (IS_ERR(dentry))
11702 + if (unlikely(!dentry))
11703 + /* todo?: make it ESTALE */
11707 + if (!au_digen_test(dentry, au_sigen(sb))
11708 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11709 + goto out_unlock; /* success */
11712 + dentry = ERR_PTR(-ESTALE);
11716 + si_read_unlock(sb);
11718 + AuTraceErrPtr(dentry);
11722 +#if 0 /* reserved for future use */
11723 +/* support subtreecheck option */
11724 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11725 + int fh_len, int fh_type)
11727 + struct dentry *parent;
11728 + __u32 *fh = fid->raw;
11731 + dir_ino = decode_ino(fh + Fh_dir_ino);
11732 + parent = decode_by_ino(sb, dir_ino, 0);
11733 + if (IS_ERR(parent))
11736 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11737 + dir_ino, fh, fh_len);
11740 + AuTraceErrPtr(parent);
11745 +/* ---------------------------------------------------------------------- */
11747 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11748 + struct inode *dir)
11751 + aufs_bindex_t bindex;
11752 + struct super_block *sb, *h_sb;
11753 + struct dentry *dentry, *parent, *h_parent;
11754 + struct inode *h_dir;
11755 + struct au_branch *br;
11758 + if (unlikely(*max_len <= Fh_tail)) {
11759 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11763 + err = FILEID_ROOT;
11764 + if (inode->i_ino == AUFS_ROOT_INO) {
11765 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11770 + sb = inode->i_sb;
11771 + err = si_read_lock(sb, AuLock_FLUSH);
11772 + if (unlikely(err))
11775 +#ifdef CONFIG_AUFS_DEBUG
11776 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11777 + AuWarn1("NFS-exporting requires xino\n");
11781 + ii_read_lock_child(inode);
11782 + bindex = au_ibtop(inode);
11784 + dentry = d_find_any_alias(inode);
11785 + if (unlikely(!dentry))
11787 + AuDebugOn(au_test_anon(dentry));
11788 + parent = dget_parent(dentry);
11790 + if (unlikely(!parent))
11792 + if (d_really_is_positive(parent))
11793 + dir = d_inode(parent);
11796 + ii_read_lock_parent(dir);
11797 + h_dir = au_h_iptr(dir, bindex);
11798 + ii_read_unlock(dir);
11799 + if (unlikely(!h_dir))
11801 + h_parent = d_find_any_alias(h_dir);
11802 + if (unlikely(!h_parent))
11803 + goto out_hparent;
11806 + br = au_sbr(sb, bindex);
11807 + h_sb = au_br_sb(br);
11808 + if (unlikely(!h_sb->s_export_op)) {
11809 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11810 + goto out_hparent;
11813 + fh[Fh_br_id] = br->br_id;
11814 + fh[Fh_sigen] = au_sigen(sb);
11815 + encode_ino(fh + Fh_ino, inode->i_ino);
11816 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11817 + fh[Fh_igen] = inode->i_generation;
11819 + *max_len -= Fh_tail;
11820 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11822 + /*connectable or subtreecheck*/0);
11823 + err = fh[Fh_h_type];
11824 + *max_len += Fh_tail;
11825 + /* todo: macros? */
11826 + if (err != FILEID_INVALID)
11829 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11836 + ii_read_unlock(inode);
11837 + si_read_unlock(sb);
11839 + if (unlikely(err < 0))
11840 + err = FILEID_INVALID;
11844 +/* ---------------------------------------------------------------------- */
11846 +static int aufs_commit_metadata(struct inode *inode)
11849 + aufs_bindex_t bindex;
11850 + struct super_block *sb;
11851 + struct inode *h_inode;
11852 + int (*f)(struct inode *inode);
11854 + sb = inode->i_sb;
11855 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11856 + ii_write_lock_child(inode);
11857 + bindex = au_ibtop(inode);
11858 + AuDebugOn(bindex < 0);
11859 + h_inode = au_h_iptr(inode, bindex);
11861 + f = h_inode->i_sb->s_export_op->commit_metadata;
11863 + err = f(h_inode);
11865 + struct writeback_control wbc = {
11866 + .sync_mode = WB_SYNC_ALL,
11867 + .nr_to_write = 0 /* metadata only */
11870 + err = sync_inode(h_inode, &wbc);
11873 + au_cpup_attr_timesizes(inode);
11874 + ii_write_unlock(inode);
11875 + si_read_unlock(sb);
11879 +/* ---------------------------------------------------------------------- */
11881 +static struct export_operations aufs_export_op = {
11882 + .fh_to_dentry = aufs_fh_to_dentry,
11883 + /* .fh_to_parent = aufs_fh_to_parent, */
11884 + .encode_fh = aufs_encode_fh,
11885 + .commit_metadata = aufs_commit_metadata
11888 +void au_export_init(struct super_block *sb)
11890 + struct au_sbinfo *sbinfo;
11893 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11894 + && IS_MODULE(CONFIG_EXPORTFS),
11895 + AUFS_NAME ": unsupported configuration "
11896 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11898 + sb->s_export_op = &aufs_export_op;
11899 + sbinfo = au_sbi(sb);
11900 + sbinfo->si_xigen = NULL;
11901 + get_random_bytes(&u, sizeof(u));
11902 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11903 + atomic_set(&sbinfo->si_xigen_next, u);
11905 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11906 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11907 +++ linux/fs/aufs/fhsm.c 2017-07-29 12:14:25.903042072 +0200
11910 + * Copyright (C) 2011-2017 Junjiro R. Okajima
11912 + * This program, aufs is free software; you can redistribute it and/or modify
11913 + * it under the terms of the GNU General Public License as published by
11914 + * the Free Software Foundation; either version 2 of the License, or
11915 + * (at your option) any later version.
11917 + * This program is distributed in the hope that it will be useful,
11918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11920 + * GNU General Public License for more details.
11922 + * You should have received a copy of the GNU General Public License
11923 + * along with this program; if not, write to the Free Software
11924 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11928 + * File-based Hierarchy Storage Management
11931 +#include <linux/anon_inodes.h>
11932 +#include <linux/poll.h>
11933 +#include <linux/seq_file.h>
11934 +#include <linux/statfs.h>
11937 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11939 + struct au_sbinfo *sbinfo;
11940 + struct au_fhsm *fhsm;
11942 + SiMustAnyLock(sb);
11944 + sbinfo = au_sbi(sb);
11945 + fhsm = &sbinfo->si_fhsm;
11946 + AuDebugOn(!fhsm);
11947 + return fhsm->fhsm_bottom;
11950 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11952 + struct au_sbinfo *sbinfo;
11953 + struct au_fhsm *fhsm;
11955 + SiMustWriteLock(sb);
11957 + sbinfo = au_sbi(sb);
11958 + fhsm = &sbinfo->si_fhsm;
11959 + AuDebugOn(!fhsm);
11960 + fhsm->fhsm_bottom = bindex;
11963 +/* ---------------------------------------------------------------------- */
11965 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11967 + struct au_br_fhsm *bf;
11969 + bf = br->br_fhsm;
11970 + MtxMustLock(&bf->bf_lock);
11972 + return !bf->bf_readable
11973 + || time_after(jiffies,
11974 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11977 +/* ---------------------------------------------------------------------- */
11979 +static void au_fhsm_notify(struct super_block *sb, int val)
11981 + struct au_sbinfo *sbinfo;
11982 + struct au_fhsm *fhsm;
11984 + SiMustAnyLock(sb);
11986 + sbinfo = au_sbi(sb);
11987 + fhsm = &sbinfo->si_fhsm;
11988 + if (au_fhsm_pid(fhsm)
11989 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11990 + atomic_set(&fhsm->fhsm_readable, val);
11992 + wake_up(&fhsm->fhsm_wqh);
11996 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11997 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
12000 + struct au_branch *br;
12001 + struct au_br_fhsm *bf;
12003 + br = au_sbr(sb, bindex);
12004 + AuDebugOn(au_br_rdonly(br));
12005 + bf = br->br_fhsm;
12009 + mutex_lock(&bf->bf_lock);
12011 + MtxMustLock(&bf->bf_lock);
12013 + /* sb->s_root for NFS is unreliable */
12014 + err = au_br_stfs(br, &bf->bf_stfs);
12015 + if (unlikely(err)) {
12016 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
12020 + bf->bf_jiffy = jiffies;
12021 + bf->bf_readable = 1;
12023 + au_fhsm_notify(sb, /*val*/1);
12025 + *rstfs = bf->bf_stfs;
12029 + mutex_unlock(&bf->bf_lock);
12030 + au_fhsm_notify(sb, /*val*/1);
12035 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
12038 + struct au_sbinfo *sbinfo;
12039 + struct au_fhsm *fhsm;
12040 + struct au_branch *br;
12041 + struct au_br_fhsm *bf;
12043 + AuDbg("b%d, force %d\n", bindex, force);
12044 + SiMustAnyLock(sb);
12046 + sbinfo = au_sbi(sb);
12047 + fhsm = &sbinfo->si_fhsm;
12048 + if (!au_ftest_si(sbinfo, FHSM)
12049 + || fhsm->fhsm_bottom == bindex)
12052 + br = au_sbr(sb, bindex);
12053 + bf = br->br_fhsm;
12055 + mutex_lock(&bf->bf_lock);
12057 + || au_fhsm_pid(fhsm)
12058 + || au_fhsm_test_jiffy(sbinfo, br))
12059 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
12061 + mutex_unlock(&bf->bf_lock);
12064 +void au_fhsm_wrote_all(struct super_block *sb, int force)
12066 + aufs_bindex_t bindex, bbot;
12067 + struct au_branch *br;
12069 + /* exclude the bottom */
12070 + bbot = au_fhsm_bottom(sb);
12071 + for (bindex = 0; bindex < bbot; bindex++) {
12072 + br = au_sbr(sb, bindex);
12073 + if (au_br_fhsm(br->br_perm))
12074 + au_fhsm_wrote(sb, bindex, force);
12078 +/* ---------------------------------------------------------------------- */
12080 +static unsigned int au_fhsm_poll(struct file *file,
12081 + struct poll_table_struct *wait)
12083 + unsigned int mask;
12084 + struct au_sbinfo *sbinfo;
12085 + struct au_fhsm *fhsm;
12088 + sbinfo = file->private_data;
12089 + fhsm = &sbinfo->si_fhsm;
12090 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12091 + if (atomic_read(&fhsm->fhsm_readable))
12092 + mask = POLLIN /* | POLLRDNORM */;
12094 + AuTraceErr((int)mask);
12098 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12099 + struct aufs_stfs *stfs, __s16 brid)
12103 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12105 + err = __put_user(brid, &stbr->brid);
12106 + if (unlikely(err))
12112 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12113 + struct aufs_stbr __user *stbr, size_t count)
12117 + aufs_bindex_t bindex, bbot;
12118 + struct au_branch *br;
12119 + struct au_br_fhsm *bf;
12121 + /* except the bottom branch */
12124 + bbot = au_fhsm_bottom(sb);
12125 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12126 + br = au_sbr(sb, bindex);
12127 + if (!au_br_fhsm(br->br_perm))
12130 + bf = br->br_fhsm;
12131 + mutex_lock(&bf->bf_lock);
12132 + if (bf->bf_readable) {
12134 + if (count >= sizeof(*stbr))
12135 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12138 + bf->bf_readable = 0;
12139 + count -= sizeof(*stbr);
12143 + mutex_unlock(&bf->bf_lock);
12146 + err = sizeof(*stbr) * nstbr;
12151 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12156 + aufs_bindex_t nfhsm, bindex, bbot;
12157 + struct au_sbinfo *sbinfo;
12158 + struct au_fhsm *fhsm;
12159 + struct au_branch *br;
12160 + struct super_block *sb;
12163 + sbinfo = file->private_data;
12164 + fhsm = &sbinfo->si_fhsm;
12166 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12167 + if (!atomic_read(&fhsm->fhsm_readable)) {
12168 + if (vfsub_file_flags(file) & O_NONBLOCK)
12171 + err = wait_event_interruptible_locked_irq
12173 + atomic_read(&fhsm->fhsm_readable));
12175 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12176 + if (unlikely(err))
12179 + /* sb may already be dead */
12180 + au_rw_read_lock(&sbinfo->si_rwsem);
12181 + readable = atomic_read(&fhsm->fhsm_readable);
12182 + if (readable > 0) {
12183 + sb = sbinfo->si_sb;
12185 + /* exclude the bottom branch */
12187 + bbot = au_fhsm_bottom(sb);
12188 + for (bindex = 0; bindex < bbot; bindex++) {
12189 + br = au_sbr(sb, bindex);
12190 + if (au_br_fhsm(br->br_perm))
12194 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12195 + atomic_set(&fhsm->fhsm_readable, 0);
12196 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12200 + au_rw_read_unlock(&sbinfo->si_rwsem);
12208 +static int au_fhsm_release(struct inode *inode, struct file *file)
12210 + struct au_sbinfo *sbinfo;
12211 + struct au_fhsm *fhsm;
12213 + /* sb may already be dead */
12214 + sbinfo = file->private_data;
12215 + fhsm = &sbinfo->si_fhsm;
12216 + spin_lock(&fhsm->fhsm_spin);
12217 + fhsm->fhsm_pid = 0;
12218 + spin_unlock(&fhsm->fhsm_spin);
12219 + kobject_put(&sbinfo->si_kobj);
12224 +static const struct file_operations au_fhsm_fops = {
12225 + .owner = THIS_MODULE,
12226 + .llseek = noop_llseek,
12227 + .read = au_fhsm_read,
12228 + .poll = au_fhsm_poll,
12229 + .release = au_fhsm_release
12232 +int au_fhsm_fd(struct super_block *sb, int oflags)
12235 + struct au_sbinfo *sbinfo;
12236 + struct au_fhsm *fhsm;
12239 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12243 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12247 + sbinfo = au_sbi(sb);
12248 + fhsm = &sbinfo->si_fhsm;
12249 + spin_lock(&fhsm->fhsm_spin);
12250 + if (!fhsm->fhsm_pid)
12251 + fhsm->fhsm_pid = current->pid;
12254 + spin_unlock(&fhsm->fhsm_spin);
12255 + if (unlikely(err))
12258 + oflags |= O_RDONLY;
12259 + /* oflags |= FMODE_NONOTIFY; */
12260 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12262 + if (unlikely(fd < 0))
12265 + /* succeed reglardless 'fhsm' status */
12266 + kobject_get(&sbinfo->si_kobj);
12267 + si_noflush_read_lock(sb);
12268 + if (au_ftest_si(sbinfo, FHSM))
12269 + au_fhsm_wrote_all(sb, /*force*/0);
12270 + si_read_unlock(sb);
12271 + goto out; /* success */
12274 + spin_lock(&fhsm->fhsm_spin);
12275 + fhsm->fhsm_pid = 0;
12276 + spin_unlock(&fhsm->fhsm_spin);
12282 +/* ---------------------------------------------------------------------- */
12284 +int au_fhsm_br_alloc(struct au_branch *br)
12289 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12291 + au_br_fhsm_init(br->br_fhsm);
12298 +/* ---------------------------------------------------------------------- */
12300 +void au_fhsm_fin(struct super_block *sb)
12302 + au_fhsm_notify(sb, /*val*/-1);
12305 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12307 + struct au_fhsm *fhsm;
12309 + fhsm = &sbinfo->si_fhsm;
12310 + spin_lock_init(&fhsm->fhsm_spin);
12311 + init_waitqueue_head(&fhsm->fhsm_wqh);
12312 + atomic_set(&fhsm->fhsm_readable, 0);
12313 + fhsm->fhsm_expire
12314 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12315 + fhsm->fhsm_bottom = -1;
12318 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12320 + sbinfo->si_fhsm.fhsm_expire
12321 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12324 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12328 + if (!au_ftest_si(sbinfo, FHSM))
12331 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12332 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12333 + seq_printf(seq, ",fhsm_sec=%u", u);
12335 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12336 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12337 +++ linux/fs/aufs/file.c 2017-07-29 12:14:25.903042072 +0200
12340 + * Copyright (C) 2005-2017 Junjiro R. Okajima
12342 + * This program, aufs is free software; you can redistribute it and/or modify
12343 + * it under the terms of the GNU General Public License as published by
12344 + * the Free Software Foundation; either version 2 of the License, or
12345 + * (at your option) any later version.
12347 + * This program is distributed in the hope that it will be useful,
12348 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12349 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12350 + * GNU General Public License for more details.
12352 + * You should have received a copy of the GNU General Public License
12353 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12357 + * handling file/dir, and address_space operation
12360 +#ifdef CONFIG_AUFS_DEBUG
12361 +#include <linux/migrate.h>
12363 +#include <linux/pagemap.h>
12366 +/* drop flags for writing */
12367 +unsigned int au_file_roflags(unsigned int flags)
12369 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12370 + flags |= O_RDONLY | O_NOATIME;
12374 +/* common functions to regular file and dir */
12375 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12376 + struct file *file, int force_wr)
12378 + struct file *h_file;
12379 + struct dentry *h_dentry;
12380 + struct inode *h_inode;
12381 + struct super_block *sb;
12382 + struct au_branch *br;
12383 + struct path h_path;
12386 + /* a race condition can happen between open and unlink/rmdir */
12387 + h_file = ERR_PTR(-ENOENT);
12388 + h_dentry = au_h_dptr(dentry, bindex);
12389 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12391 + h_inode = d_inode(h_dentry);
12392 + spin_lock(&h_dentry->d_lock);
12393 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12394 + /* || !d_inode(dentry)->i_nlink */
12396 + spin_unlock(&h_dentry->d_lock);
12397 + if (unlikely(err))
12400 + sb = dentry->d_sb;
12401 + br = au_sbr(sb, bindex);
12402 + err = au_br_test_oflag(flags, br);
12403 + h_file = ERR_PTR(err);
12404 + if (unlikely(err))
12407 + /* drop flags for writing */
12408 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12409 + if (force_wr && !(flags & O_WRONLY))
12411 + flags = au_file_roflags(flags);
12413 + h_file = ERR_PTR(-EROFS);
12414 + flags = au_file_roflags(flags);
12415 + if (unlikely(vfsub_native_ro(h_inode)
12416 + || IS_APPEND(h_inode)))
12418 + flags &= ~O_ACCMODE;
12419 + flags |= O_WRONLY;
12422 + flags &= ~O_CREAT;
12424 + h_path.dentry = h_dentry;
12425 + h_path.mnt = au_br_mnt(br);
12426 + h_file = vfsub_dentry_open(&h_path, flags);
12427 + if (IS_ERR(h_file))
12430 + if (flags & __FMODE_EXEC) {
12431 + err = deny_write_access(h_file);
12432 + if (unlikely(err)) {
12434 + h_file = ERR_PTR(err);
12438 + fsnotify_open(h_file);
12439 + goto out; /* success */
12447 +static int au_cmoo(struct dentry *dentry)
12450 + unsigned int udba;
12451 + struct path h_path;
12452 + struct au_pin pin;
12453 + struct au_cp_generic cpg = {
12454 + .dentry = dentry,
12459 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12461 + struct inode *delegated;
12462 + struct super_block *sb;
12463 + struct au_sbinfo *sbinfo;
12464 + struct au_fhsm *fhsm;
12466 + struct au_branch *br;
12467 + struct dentry *parent;
12468 + struct au_hinode *hdir;
12470 + DiMustWriteLock(dentry);
12471 + IiMustWriteLock(d_inode(dentry));
12474 + if (IS_ROOT(dentry))
12476 + cpg.bsrc = au_dbtop(dentry);
12480 + sb = dentry->d_sb;
12481 + sbinfo = au_sbi(sb);
12482 + fhsm = &sbinfo->si_fhsm;
12483 + pid = au_fhsm_pid(fhsm);
12485 + && (current->pid == pid
12486 + || current->real_parent->pid == pid))
12489 + br = au_sbr(sb, cpg.bsrc);
12490 + cmoo = au_br_cmoo(br->br_perm);
12493 + if (!d_is_reg(dentry))
12494 + cmoo &= AuBrAttr_COO_ALL;
12498 + parent = dget_parent(dentry);
12499 + di_write_lock_parent(parent);
12500 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12502 + if (unlikely(err < 0)) {
12503 + err = 0; /* there is no upper writable branch */
12506 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12508 + /* do not respect the coo attrib for the target branch */
12509 + err = au_cpup_dirs(dentry, cpg.bdst);
12510 + if (unlikely(err))
12513 + di_downgrade_lock(parent, AuLock_IR);
12514 + udba = au_opt_udba(sb);
12515 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12516 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12517 + if (unlikely(err))
12520 + err = au_sio_cpup_simple(&cpg);
12522 + if (unlikely(err))
12524 + if (!(cmoo & AuBrWAttr_MOO))
12525 + goto out_parent; /* success */
12527 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12528 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12529 + if (unlikely(err))
12532 + h_path.mnt = au_br_mnt(br);
12533 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12534 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12535 + delegated = NULL;
12536 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12538 + /* todo: keep h_dentry or not? */
12539 + if (unlikely(err == -EWOULDBLOCK)) {
12540 + pr_warn("cannot retry for NFSv4 delegation"
12541 + " for an internal unlink\n");
12544 + if (unlikely(err)) {
12545 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12549 + goto out_parent; /* success */
12552 + di_downgrade_lock(parent, AuLock_IR);
12554 + di_read_unlock(parent, AuLock_IR);
12561 +int au_do_open(struct file *file, struct au_do_open_args *args)
12563 + int err, no_lock = args->no_lock;
12564 + struct dentry *dentry;
12565 + struct au_finfo *finfo;
12568 + err = au_finfo_init(file, args->fidir);
12571 + err = au_finfo_init(file, args->fidir);
12574 + if (unlikely(err))
12577 + dentry = file->f_path.dentry;
12578 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12580 + di_write_lock_child(dentry);
12581 + err = au_cmoo(dentry);
12582 + di_downgrade_lock(dentry, AuLock_IR);
12584 + err = args->open(file, vfsub_file_flags(file), NULL);
12585 + di_read_unlock(dentry, AuLock_IR);
12587 + err = au_cmoo(dentry);
12589 + err = args->open(file, vfsub_file_flags(file),
12591 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12593 + * cmoo happens after h_file was opened.
12594 + * need to refresh file later.
12596 + atomic_dec(&au_fi(file)->fi_generation);
12599 + finfo = au_fi(file);
12601 + finfo->fi_file = file;
12602 + au_sphl_add(&finfo->fi_hlist,
12603 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12606 + fi_write_unlock(file);
12609 + fi_write_unlock(file);
12612 + if (unlikely(err)) {
12613 + finfo->fi_hdir = NULL;
12614 + au_finfo_fin(file);
12621 +int au_reopen_nondir(struct file *file)
12624 + aufs_bindex_t btop;
12625 + struct dentry *dentry;
12626 + struct file *h_file, *h_file_tmp;
12628 + dentry = file->f_path.dentry;
12629 + btop = au_dbtop(dentry);
12630 + h_file_tmp = NULL;
12631 + if (au_fbtop(file) == btop) {
12632 + h_file = au_hf_top(file);
12633 + if (file->f_mode == h_file->f_mode)
12634 + return 0; /* success */
12635 + h_file_tmp = h_file;
12636 + get_file(h_file_tmp);
12637 + au_set_h_fptr(file, btop, NULL);
12639 + AuDebugOn(au_fi(file)->fi_hdir);
12642 + * file exists on both of rw and ro
12643 + * open --> dbtop and fbtop are both 0
12644 + * prepend a branch as rw, "rw" become ro
12646 + * delete the top branch, "rw" becomes rw again
12647 + * --> dbtop is 1, fbtop is still 0
12648 + * write --> fbtop is 0 but dbtop is 1
12650 + /* AuDebugOn(au_fbtop(file) < btop); */
12652 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12653 + file, /*force_wr*/0);
12654 + err = PTR_ERR(h_file);
12655 + if (IS_ERR(h_file)) {
12656 + if (h_file_tmp) {
12657 + au_sbr_get(dentry->d_sb, btop);
12658 + au_set_h_fptr(file, btop, h_file_tmp);
12659 + h_file_tmp = NULL;
12661 + goto out; /* todo: close all? */
12665 + au_set_fbtop(file, btop);
12666 + au_set_h_fptr(file, btop, h_file);
12667 + au_update_figen(file);
12668 + /* todo: necessary? */
12669 + /* file->f_ra = h_file->f_ra; */
12673 + fput(h_file_tmp);
12677 +/* ---------------------------------------------------------------------- */
12679 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12680 + struct dentry *hi_wh)
12683 + aufs_bindex_t btop;
12684 + struct au_dinfo *dinfo;
12685 + struct dentry *h_dentry;
12686 + struct au_hdentry *hdp;
12688 + dinfo = au_di(file->f_path.dentry);
12689 + AuRwMustWriteLock(&dinfo->di_rwsem);
12691 + btop = dinfo->di_btop;
12692 + dinfo->di_btop = btgt;
12693 + hdp = au_hdentry(dinfo, btgt);
12694 + h_dentry = hdp->hd_dentry;
12695 + hdp->hd_dentry = hi_wh;
12696 + err = au_reopen_nondir(file);
12697 + hdp->hd_dentry = h_dentry;
12698 + dinfo->di_btop = btop;
12703 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12704 + aufs_bindex_t bcpup, struct au_pin *pin)
12707 + struct inode *inode, *h_inode;
12708 + struct dentry *h_dentry, *hi_wh;
12709 + struct au_cp_generic cpg = {
12710 + .dentry = file->f_path.dentry,
12717 + au_update_dbtop(cpg.dentry);
12718 + inode = d_inode(cpg.dentry);
12720 + if (au_dbtop(cpg.dentry) <= bcpup
12721 + && au_dbbot(cpg.dentry) >= bcpup) {
12722 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12723 + if (h_dentry && d_is_positive(h_dentry))
12724 + h_inode = d_inode(h_dentry);
12726 + hi_wh = au_hi_wh(inode, bcpup);
12727 + if (!hi_wh && !h_inode)
12728 + err = au_sio_cpup_wh(&cpg, file);
12730 + /* already copied-up after unlink */
12731 + err = au_reopen_wh(file, bcpup, hi_wh);
12734 + && (inode->i_nlink > 1
12735 + || (inode->i_state & I_LINKABLE))
12736 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12737 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12743 + * prepare the @file for writing.
12745 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12748 + aufs_bindex_t dbtop;
12749 + struct dentry *parent;
12750 + struct inode *inode;
12751 + struct super_block *sb;
12752 + struct file *h_file;
12753 + struct au_cp_generic cpg = {
12754 + .dentry = file->f_path.dentry,
12759 + .flags = AuCpup_DTIME
12762 + sb = cpg.dentry->d_sb;
12763 + inode = d_inode(cpg.dentry);
12764 + cpg.bsrc = au_fbtop(file);
12765 + err = au_test_ro(sb, cpg.bsrc, inode);
12766 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12767 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12772 + /* need to cpup or reopen */
12773 + parent = dget_parent(cpg.dentry);
12774 + di_write_lock_parent(parent);
12775 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12777 + if (unlikely(err < 0))
12781 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12782 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12783 + if (unlikely(err))
12787 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12788 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12789 + if (unlikely(err))
12792 + dbtop = au_dbtop(cpg.dentry);
12793 + if (dbtop <= cpg.bdst)
12794 + cpg.bsrc = cpg.bdst;
12796 + if (dbtop <= cpg.bdst /* just reopen */
12797 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12799 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12800 + if (IS_ERR(h_file))
12801 + err = PTR_ERR(h_file);
12803 + di_downgrade_lock(parent, AuLock_IR);
12804 + if (dbtop > cpg.bdst)
12805 + err = au_sio_cpup_simple(&cpg);
12807 + err = au_reopen_nondir(file);
12808 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12810 + } else { /* copyup as wh and reopen */
12812 + * since writable hfsplus branch is not supported,
12813 + * h_open_pre/post() are unnecessary.
12815 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12816 + di_downgrade_lock(parent, AuLock_IR);
12820 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12821 + goto out_dput; /* success */
12827 + di_downgrade_lock(parent, AuLock_IR);
12829 + di_read_unlock(parent, AuLock_IR);
12836 +/* ---------------------------------------------------------------------- */
12838 +int au_do_flush(struct file *file, fl_owner_t id,
12839 + int (*flush)(struct file *file, fl_owner_t id))
12842 + struct super_block *sb;
12843 + struct inode *inode;
12845 + inode = file_inode(file);
12846 + sb = inode->i_sb;
12847 + si_noflush_read_lock(sb);
12848 + fi_read_lock(file);
12849 + ii_read_lock_child(inode);
12851 + err = flush(file, id);
12852 + au_cpup_attr_timesizes(inode);
12854 + ii_read_unlock(inode);
12855 + fi_read_unlock(file);
12856 + si_read_unlock(sb);
12860 +/* ---------------------------------------------------------------------- */
12862 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12865 + struct au_pin pin;
12866 + struct au_finfo *finfo;
12867 + struct dentry *parent, *hi_wh;
12868 + struct inode *inode;
12869 + struct super_block *sb;
12870 + struct au_cp_generic cpg = {
12871 + .dentry = file->f_path.dentry,
12876 + .flags = AuCpup_DTIME
12879 + FiMustWriteLock(file);
12882 + finfo = au_fi(file);
12883 + sb = cpg.dentry->d_sb;
12884 + inode = d_inode(cpg.dentry);
12885 + cpg.bdst = au_ibtop(inode);
12886 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12889 + parent = dget_parent(cpg.dentry);
12890 + if (au_test_ro(sb, cpg.bdst, inode)) {
12891 + di_read_lock_parent(parent, !AuLock_IR);
12892 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12894 + di_read_unlock(parent, !AuLock_IR);
12895 + if (unlikely(err < 0))
12900 + di_read_lock_parent(parent, AuLock_IR);
12901 + hi_wh = au_hi_wh(inode, cpg.bdst);
12902 + if (!S_ISDIR(inode->i_mode)
12903 + && au_opt_test(au_mntflags(sb), PLINK)
12904 + && au_plink_test(inode)
12905 + && !d_unhashed(cpg.dentry)
12906 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12907 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12908 + if (unlikely(err))
12911 + /* always superio. */
12912 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12913 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12915 + err = au_sio_cpup_simple(&cpg);
12918 + } else if (hi_wh) {
12919 + /* already copied-up after unlink */
12920 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12921 + *need_reopen = 0;
12925 + di_read_unlock(parent, AuLock_IR);
12932 +static void au_do_refresh_dir(struct file *file)
12934 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12935 + struct au_hfile *p, tmp, *q;
12936 + struct au_finfo *finfo;
12937 + struct super_block *sb;
12938 + struct au_fidir *fidir;
12940 + FiMustWriteLock(file);
12942 + sb = file->f_path.dentry->d_sb;
12943 + finfo = au_fi(file);
12944 + fidir = finfo->fi_hdir;
12945 + AuDebugOn(!fidir);
12946 + p = fidir->fd_hfile + finfo->fi_btop;
12947 + brid = p->hf_br->br_id;
12948 + bbot = fidir->fd_bbot;
12949 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12953 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12954 + if (new_bindex == bindex)
12956 + if (new_bindex < 0) {
12957 + au_set_h_fptr(file, bindex, NULL);
12961 + /* swap two lower inode, and loop again */
12962 + q = fidir->fd_hfile + new_bindex;
12966 + if (tmp.hf_file) {
12972 + p = fidir->fd_hfile;
12973 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12974 + bbot = au_sbbot(sb);
12975 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12976 + finfo->fi_btop++, p++)
12977 + if (p->hf_file) {
12978 + if (file_inode(p->hf_file))
12980 + au_hfput(p, /*execed*/0);
12983 + bbot = au_br_index(sb, brid);
12984 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12985 + finfo->fi_btop++, p++)
12987 + au_hfput(p, /*execed*/0);
12988 + bbot = au_sbbot(sb);
12991 + p = fidir->fd_hfile + bbot;
12992 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12993 + fidir->fd_bbot--, p--)
12994 + if (p->hf_file) {
12995 + if (file_inode(p->hf_file))
12997 + au_hfput(p, /*execed*/0);
12999 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
13003 + * after branch manipulating, refresh the file.
13005 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
13007 + int err, need_reopen, nbr;
13008 + aufs_bindex_t bbot, bindex;
13009 + struct dentry *dentry;
13010 + struct super_block *sb;
13011 + struct au_finfo *finfo;
13012 + struct au_hfile *hfile;
13014 + dentry = file->f_path.dentry;
13015 + sb = dentry->d_sb;
13016 + nbr = au_sbbot(sb) + 1;
13017 + finfo = au_fi(file);
13018 + if (!finfo->fi_hdir) {
13019 + hfile = &finfo->fi_htop;
13020 + AuDebugOn(!hfile->hf_file);
13021 + bindex = au_br_index(sb, hfile->hf_br->br_id);
13022 + AuDebugOn(bindex < 0);
13023 + if (bindex != finfo->fi_btop)
13024 + au_set_fbtop(file, bindex);
13026 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
13027 + if (unlikely(err))
13029 + au_do_refresh_dir(file);
13034 + if (!au_test_mmapped(file))
13035 + err = au_file_refresh_by_inode(file, &need_reopen);
13036 + if (finfo->fi_hdir)
13037 + /* harmless if err */
13038 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
13039 + if (!err && need_reopen && !d_unlinked(dentry))
13040 + err = reopen(file);
13042 + au_update_figen(file);
13043 + goto out; /* success */
13046 + /* error, close all lower files */
13047 + if (finfo->fi_hdir) {
13048 + bbot = au_fbbot_dir(file);
13049 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
13050 + au_set_h_fptr(file, bindex, NULL);
13057 +/* common function to regular file and dir */
13058 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13059 + int wlock, unsigned int fi_lsc)
13062 + unsigned int sigen, figen;
13063 + aufs_bindex_t btop;
13064 + unsigned char pseudo_link;
13065 + struct dentry *dentry;
13066 + struct inode *inode;
13069 + dentry = file->f_path.dentry;
13070 + inode = d_inode(dentry);
13071 + sigen = au_sigen(dentry->d_sb);
13072 + fi_write_lock_nested(file, fi_lsc);
13073 + figen = au_figen(file);
13075 + di_write_lock_child(dentry);
13077 + di_write_lock_child2(dentry);
13078 + btop = au_dbtop(dentry);
13079 + pseudo_link = (btop != au_ibtop(inode));
13080 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
13082 + di_downgrade_lock(dentry, AuLock_IR);
13083 + fi_downgrade_lock(file);
13085 + goto out; /* success */
13088 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13089 + if (au_digen_test(dentry, sigen)) {
13090 + err = au_reval_dpath(dentry, sigen);
13091 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13095 + err = refresh_file(file, reopen);
13098 + di_downgrade_lock(dentry, AuLock_IR);
13099 + fi_downgrade_lock(file);
13102 + di_write_unlock(dentry);
13103 + fi_write_unlock(file);
13110 +/* ---------------------------------------------------------------------- */
13112 +/* cf. aufs_nopage() */
13113 +/* for madvise(2) */
13114 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13116 + unlock_page(page);
13120 +/* it will never be called, but necessary to support O_DIRECT */
13121 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13122 +{ BUG(); return 0; }
13124 +/* they will never be called. */
13125 +#ifdef CONFIG_AUFS_DEBUG
13126 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13127 + loff_t pos, unsigned len, unsigned flags,
13128 + struct page **pagep, void **fsdata)
13129 +{ AuUnsupport(); return 0; }
13130 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13131 + loff_t pos, unsigned len, unsigned copied,
13132 + struct page *page, void *fsdata)
13133 +{ AuUnsupport(); return 0; }
13134 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13135 +{ AuUnsupport(); return 0; }
13137 +static int aufs_set_page_dirty(struct page *page)
13138 +{ AuUnsupport(); return 0; }
13139 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13140 + unsigned int length)
13141 +{ AuUnsupport(); }
13142 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13143 +{ AuUnsupport(); return 0; }
13144 +#if 0 /* called by memory compaction regardless file */
13145 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13146 + struct page *page, enum migrate_mode mode)
13147 +{ AuUnsupport(); return 0; }
13149 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13150 +{ AuUnsupport(); return true; }
13151 +static void aufs_putback_page(struct page *page)
13152 +{ AuUnsupport(); }
13153 +static int aufs_launder_page(struct page *page)
13154 +{ AuUnsupport(); return 0; }
13155 +static int aufs_is_partially_uptodate(struct page *page,
13156 + unsigned long from,
13157 + unsigned long count)
13158 +{ AuUnsupport(); return 0; }
13159 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13161 +{ AuUnsupport(); }
13162 +static int aufs_error_remove_page(struct address_space *mapping,
13163 + struct page *page)
13164 +{ AuUnsupport(); return 0; }
13165 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13167 +{ AuUnsupport(); return 0; }
13168 +static void aufs_swap_deactivate(struct file *file)
13169 +{ AuUnsupport(); }
13170 +#endif /* CONFIG_AUFS_DEBUG */
13172 +const struct address_space_operations aufs_aop = {
13173 + .readpage = aufs_readpage,
13174 + .direct_IO = aufs_direct_IO,
13175 +#ifdef CONFIG_AUFS_DEBUG
13176 + .writepage = aufs_writepage,
13177 + /* no writepages, because of writepage */
13178 + .set_page_dirty = aufs_set_page_dirty,
13179 + /* no readpages, because of readpage */
13180 + .write_begin = aufs_write_begin,
13181 + .write_end = aufs_write_end,
13182 + /* no bmap, no block device */
13183 + .invalidatepage = aufs_invalidatepage,
13184 + .releasepage = aufs_releasepage,
13185 + /* is fallback_migrate_page ok? */
13186 + /* .migratepage = aufs_migratepage, */
13187 + .isolate_page = aufs_isolate_page,
13188 + .putback_page = aufs_putback_page,
13189 + .launder_page = aufs_launder_page,
13190 + .is_partially_uptodate = aufs_is_partially_uptodate,
13191 + .is_dirty_writeback = aufs_is_dirty_writeback,
13192 + .error_remove_page = aufs_error_remove_page,
13193 + .swap_activate = aufs_swap_activate,
13194 + .swap_deactivate = aufs_swap_deactivate
13195 +#endif /* CONFIG_AUFS_DEBUG */
13197 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13198 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13199 +++ linux/fs/aufs/file.h 2017-07-29 12:14:25.903042072 +0200
13202 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13204 + * This program, aufs is free software; you can redistribute it and/or modify
13205 + * it under the terms of the GNU General Public License as published by
13206 + * the Free Software Foundation; either version 2 of the License, or
13207 + * (at your option) any later version.
13209 + * This program is distributed in the hope that it will be useful,
13210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13212 + * GNU General Public License for more details.
13214 + * You should have received a copy of the GNU General Public License
13215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13219 + * file operations
13222 +#ifndef __AUFS_FILE_H__
13223 +#define __AUFS_FILE_H__
13227 +#include <linux/file.h>
13228 +#include <linux/fs.h>
13229 +#include <linux/poll.h>
13230 +#include "rwsem.h"
13234 + struct file *hf_file;
13235 + struct au_branch *hf_br;
13240 + aufs_bindex_t fd_bbot;
13241 + aufs_bindex_t fd_nent;
13242 + struct au_vdir *fd_vdir_cache;
13243 + struct au_hfile fd_hfile[];
13246 +static inline int au_fidir_sz(int nent)
13248 + AuDebugOn(nent < 0);
13249 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13253 + atomic_t fi_generation;
13255 + struct au_rwsem fi_rwsem;
13256 + aufs_bindex_t fi_btop;
13258 + /* do not union them */
13259 + struct { /* for non-dir */
13260 + struct au_hfile fi_htop;
13261 + atomic_t fi_mmapped;
13263 + struct au_fidir *fi_hdir; /* for dir only */
13265 + struct hlist_node fi_hlist;
13266 + struct file *fi_file; /* very ugly */
13267 +} ____cacheline_aligned_in_smp;
13269 +/* ---------------------------------------------------------------------- */
13272 +extern const struct address_space_operations aufs_aop;
13273 +unsigned int au_file_roflags(unsigned int flags);
13274 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13275 + struct file *file, int force_wr);
13276 +struct au_do_open_args {
13278 + int (*open)(struct file *file, int flags,
13279 + struct file *h_file);
13280 + struct au_fidir *fidir;
13281 + struct file *h_file;
13283 +int au_do_open(struct file *file, struct au_do_open_args *args);
13284 +int au_reopen_nondir(struct file *file);
13286 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13287 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13288 + int wlock, unsigned int fi_lsc);
13289 +int au_do_flush(struct file *file, fl_owner_t id,
13290 + int (*flush)(struct file *file, fl_owner_t id));
13293 +#ifdef CONFIG_AUFS_POLL
13294 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13297 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13299 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13301 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13302 + struct file *h_file);
13304 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13305 + aufs_bindex_t bindex, int force_wr)
13306 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13307 + struct file *h_file);
13311 +extern const struct file_operations aufs_file_fop;
13312 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13313 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13314 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
13317 +void au_hfput(struct au_hfile *hf, int execed);
13318 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13319 + struct file *h_file);
13321 +void au_update_figen(struct file *file);
13322 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13323 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13325 +void au_fi_init_once(void *_fi);
13326 +void au_finfo_fin(struct file *file);
13327 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13330 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13331 +#ifdef CONFIG_COMPAT
13332 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13333 + unsigned long arg);
13334 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13335 + unsigned long arg);
13338 +/* ---------------------------------------------------------------------- */
13340 +static inline struct au_finfo *au_fi(struct file *file)
13342 + return file->private_data;
13345 +/* ---------------------------------------------------------------------- */
13348 + * fi_read_lock, fi_write_lock,
13349 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13351 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13353 +/* lock subclass for finfo */
13359 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
13361 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13364 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
13366 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13370 + * fi_read_lock_1, fi_write_lock_1,
13371 + * fi_read_lock_2, fi_write_lock_2
13373 +#define AuReadLockFunc(name) \
13374 +static inline void fi_read_lock_##name(struct file *f) \
13375 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
13377 +#define AuWriteLockFunc(name) \
13378 +static inline void fi_write_lock_##name(struct file *f) \
13379 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
13381 +#define AuRWLockFuncs(name) \
13382 + AuReadLockFunc(name) \
13383 + AuWriteLockFunc(name)
13388 +#undef AuReadLockFunc
13389 +#undef AuWriteLockFunc
13390 +#undef AuRWLockFuncs
13392 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13393 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13394 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13396 +/* ---------------------------------------------------------------------- */
13398 +/* todo: hard/soft set? */
13399 +static inline aufs_bindex_t au_fbtop(struct file *file)
13401 + FiMustAnyLock(file);
13402 + return au_fi(file)->fi_btop;
13405 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13407 + FiMustAnyLock(file);
13408 + AuDebugOn(!au_fi(file)->fi_hdir);
13409 + return au_fi(file)->fi_hdir->fd_bbot;
13412 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13414 + FiMustAnyLock(file);
13415 + AuDebugOn(!au_fi(file)->fi_hdir);
13416 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13419 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13421 + FiMustWriteLock(file);
13422 + au_fi(file)->fi_btop = bindex;
13425 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13427 + FiMustWriteLock(file);
13428 + AuDebugOn(!au_fi(file)->fi_hdir);
13429 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13432 +static inline void au_set_fvdir_cache(struct file *file,
13433 + struct au_vdir *vdir_cache)
13435 + FiMustWriteLock(file);
13436 + AuDebugOn(!au_fi(file)->fi_hdir);
13437 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13440 +static inline struct file *au_hf_top(struct file *file)
13442 + FiMustAnyLock(file);
13443 + AuDebugOn(au_fi(file)->fi_hdir);
13444 + return au_fi(file)->fi_htop.hf_file;
13447 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13449 + FiMustAnyLock(file);
13450 + AuDebugOn(!au_fi(file)->fi_hdir);
13451 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13454 +/* todo: memory barrier? */
13455 +static inline unsigned int au_figen(struct file *f)
13457 + return atomic_read(&au_fi(f)->fi_generation);
13460 +static inline void au_set_mmapped(struct file *f)
13462 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13464 + pr_warn("fi_mmapped wrapped around\n");
13465 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13469 +static inline void au_unset_mmapped(struct file *f)
13471 + atomic_dec(&au_fi(f)->fi_mmapped);
13474 +static inline int au_test_mmapped(struct file *f)
13476 + return atomic_read(&au_fi(f)->fi_mmapped);
13479 +/* customize vma->vm_file */
13481 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13482 + struct file *file)
13486 + f = vma->vm_file;
13488 + vma->vm_file = file;
13493 +#define AuDbgVmRegion(file, vma) do {} while (0)
13495 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13496 + struct file *file)
13498 + au_do_vm_file_reset(vma, file);
13501 +#define AuDbgVmRegion(file, vma) \
13502 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13504 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13505 + struct file *file)
13509 + au_do_vm_file_reset(vma, file);
13510 + f = vma->vm_region->vm_file;
13512 + vma->vm_region->vm_file = file;
13515 +#endif /* CONFIG_MMU */
13517 +/* handle vma->vm_prfile */
13518 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13519 + struct file *file)
13522 + vma->vm_prfile = file;
13523 +#ifndef CONFIG_MMU
13525 + vma->vm_region->vm_prfile = file;
13529 +#endif /* __KERNEL__ */
13530 +#endif /* __AUFS_FILE_H__ */
13531 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13532 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13533 +++ linux/fs/aufs/finfo.c 2017-07-29 12:14:25.903042072 +0200
13536 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13538 + * This program, aufs is free software; you can redistribute it and/or modify
13539 + * it under the terms of the GNU General Public License as published by
13540 + * the Free Software Foundation; either version 2 of the License, or
13541 + * (at your option) any later version.
13543 + * This program is distributed in the hope that it will be useful,
13544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13546 + * GNU General Public License for more details.
13548 + * You should have received a copy of the GNU General Public License
13549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13553 + * file private data
13558 +void au_hfput(struct au_hfile *hf, int execed)
13561 + allow_write_access(hf->hf_file);
13562 + fput(hf->hf_file);
13563 + hf->hf_file = NULL;
13564 + au_br_put(hf->hf_br);
13565 + hf->hf_br = NULL;
13568 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13570 + struct au_finfo *finfo = au_fi(file);
13571 + struct au_hfile *hf;
13572 + struct au_fidir *fidir;
13574 + fidir = finfo->fi_hdir;
13576 + AuDebugOn(finfo->fi_btop != bindex);
13577 + hf = &finfo->fi_htop;
13579 + hf = fidir->fd_hfile + bindex;
13581 + if (hf && hf->hf_file)
13582 + au_hfput(hf, vfsub_file_execed(file));
13584 + FiMustWriteLock(file);
13585 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13586 + hf->hf_file = val;
13587 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13591 +void au_update_figen(struct file *file)
13593 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13594 + /* smp_mb(); */ /* atomic_set */
13597 +/* ---------------------------------------------------------------------- */
13599 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13601 + struct au_fidir *fidir;
13604 + nbr = au_sbbot(sb) + 1;
13606 + nbr = 2; /* initial allocate for 2 branches */
13607 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13609 + fidir->fd_bbot = -1;
13610 + fidir->fd_nent = nbr;
13616 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13619 + struct au_fidir *fidir, *p;
13621 + AuRwMustWriteLock(&finfo->fi_rwsem);
13622 + fidir = finfo->fi_hdir;
13623 + AuDebugOn(!fidir);
13626 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13627 + GFP_NOFS, may_shrink);
13629 + p->fd_nent = nbr;
13630 + finfo->fi_hdir = p;
13637 +/* ---------------------------------------------------------------------- */
13639 +void au_finfo_fin(struct file *file)
13641 + struct au_finfo *finfo;
13643 + au_nfiles_dec(file->f_path.dentry->d_sb);
13645 + finfo = au_fi(file);
13646 + AuDebugOn(finfo->fi_hdir);
13647 + AuRwDestroy(&finfo->fi_rwsem);
13648 + au_cache_free_finfo(finfo);
13651 +void au_fi_init_once(void *_finfo)
13653 + struct au_finfo *finfo = _finfo;
13655 + au_rw_init(&finfo->fi_rwsem);
13658 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13661 + struct au_finfo *finfo;
13662 + struct dentry *dentry;
13665 + dentry = file->f_path.dentry;
13666 + finfo = au_cache_alloc_finfo();
13667 + if (unlikely(!finfo))
13671 + au_nfiles_inc(dentry->d_sb);
13672 + au_rw_write_lock(&finfo->fi_rwsem);
13673 + finfo->fi_btop = -1;
13674 + finfo->fi_hdir = fidir;
13675 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13676 + /* smp_mb(); */ /* atomic_set */
13678 + file->private_data = finfo;
13683 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13684 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13685 +++ linux/fs/aufs/f_op.c 2017-07-29 12:14:25.903042072 +0200
13688 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13690 + * This program, aufs is free software; you can redistribute it and/or modify
13691 + * it under the terms of the GNU General Public License as published by
13692 + * the Free Software Foundation; either version 2 of the License, or
13693 + * (at your option) any later version.
13695 + * This program is distributed in the hope that it will be useful,
13696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13698 + * GNU General Public License for more details.
13700 + * You should have received a copy of the GNU General Public License
13701 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13705 + * file and vm operations
13708 +#include <linux/aio.h>
13709 +#include <linux/fs_stack.h>
13710 +#include <linux/mman.h>
13711 +#include <linux/security.h>
13714 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13717 + aufs_bindex_t bindex;
13718 + struct dentry *dentry, *h_dentry;
13719 + struct au_finfo *finfo;
13720 + struct inode *h_inode;
13722 + FiMustWriteLock(file);
13725 + dentry = file->f_path.dentry;
13726 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13727 + finfo = au_fi(file);
13728 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13729 + atomic_set(&finfo->fi_mmapped, 0);
13730 + bindex = au_dbtop(dentry);
13732 + h_dentry = au_h_dptr(dentry, bindex);
13733 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13734 + if (unlikely(err))
13736 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13738 + h_dentry = h_file->f_path.dentry;
13739 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13740 + if (unlikely(err))
13742 + get_file(h_file);
13744 + if (IS_ERR(h_file))
13745 + err = PTR_ERR(h_file);
13747 + if ((flags & __O_TMPFILE)
13748 + && !(flags & O_EXCL)) {
13749 + h_inode = file_inode(h_file);
13750 + spin_lock(&h_inode->i_lock);
13751 + h_inode->i_state |= I_LINKABLE;
13752 + spin_unlock(&h_inode->i_lock);
13754 + au_set_fbtop(file, bindex);
13755 + au_set_h_fptr(file, bindex, h_file);
13756 + au_update_figen(file);
13757 + /* todo: necessary? */
13758 + /* file->f_ra = h_file->f_ra; */
13765 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13766 + struct file *file)
13769 + struct super_block *sb;
13770 + struct au_do_open_args args = {
13771 + .open = au_do_open_nondir
13774 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13775 + file, vfsub_file_flags(file), file->f_mode);
13777 + sb = file->f_path.dentry->d_sb;
13778 + si_read_lock(sb, AuLock_FLUSH);
13779 + err = au_do_open(file, &args);
13780 + si_read_unlock(sb);
13784 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13786 + struct au_finfo *finfo;
13787 + aufs_bindex_t bindex;
13789 + finfo = au_fi(file);
13790 + au_sphl_del(&finfo->fi_hlist,
13791 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13792 + bindex = finfo->fi_btop;
13794 + au_set_h_fptr(file, bindex, NULL);
13796 + au_finfo_fin(file);
13800 +/* ---------------------------------------------------------------------- */
13802 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13805 + struct file *h_file;
13808 + h_file = au_hf_top(file);
13810 + err = vfsub_flush(h_file, id);
13814 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13816 + return au_do_flush(file, id, au_do_flush_nondir);
13819 +/* ---------------------------------------------------------------------- */
13821 + * read and write functions acquire [fdi]_rwsem once, but release before
13822 + * mmap_sem. This is because to stop a race condition between mmap(2).
13823 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13824 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13825 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13828 +/* Callers should call au_read_post() or fput() in the end */
13829 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
13831 + struct file *h_file;
13834 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
13836 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13837 + h_file = au_hf_top(file);
13838 + get_file(h_file);
13840 + fi_read_unlock(file);
13842 + h_file = ERR_PTR(err);
13847 +static void au_read_post(struct inode *inode, struct file *h_file)
13849 + /* update without lock, I don't think it a problem */
13850 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13854 +struct au_write_pre {
13856 + unsigned int lsc;
13860 + aufs_bindex_t btop;
13864 + * return with iinfo is write-locked
13865 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13868 +static struct file *au_write_pre(struct file *file, int do_ready,
13869 + struct au_write_pre *wpre)
13871 + struct file *h_file;
13872 + struct dentry *dentry;
13874 + unsigned int lsc;
13875 + struct au_pin pin;
13880 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
13881 + h_file = ERR_PTR(err);
13882 + if (unlikely(err))
13885 + dentry = file->f_path.dentry;
13887 + err = au_ready_to_write(file, -1, &pin);
13888 + if (unlikely(err)) {
13889 + h_file = ERR_PTR(err);
13890 + di_write_unlock(dentry);
13895 + di_downgrade_lock(dentry, /*flags*/0);
13897 + wpre->btop = au_fbtop(file);
13898 + h_file = au_hf_top(file);
13899 + get_file(h_file);
13901 + wpre->blks = file_inode(h_file)->i_blocks;
13904 + di_read_unlock(dentry, /*flags*/0);
13907 + fi_write_unlock(file);
13912 +static void au_write_post(struct inode *inode, struct file *h_file,
13913 + struct au_write_pre *wpre, ssize_t written)
13915 + struct inode *h_inode;
13917 + au_cpup_attr_timesizes(inode);
13918 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13919 + h_inode = file_inode(h_file);
13920 + inode->i_mode = h_inode->i_mode;
13921 + ii_write_unlock(inode);
13922 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13924 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13925 + /*force*/h_inode->i_blocks > wpre->blks);
13929 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13933 + struct inode *inode;
13934 + struct file *h_file;
13935 + struct super_block *sb;
13937 + inode = file_inode(file);
13938 + sb = inode->i_sb;
13939 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13941 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
13942 + err = PTR_ERR(h_file);
13943 + if (IS_ERR(h_file))
13946 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13947 + err = vfsub_read_u(h_file, buf, count, ppos);
13948 + /* todo: necessary? */
13949 + /* file->f_ra = h_file->f_ra; */
13950 + au_read_post(inode, h_file);
13953 + si_read_unlock(sb);
13958 + * todo: very ugly
13959 + * it locks both of i_mutex and si_rwsem for read in safe.
13960 + * if the plink maintenance mode continues forever (that is the problem),
13961 + * may loop forever.
13963 +static void au_mtx_and_read_lock(struct inode *inode)
13966 + struct super_block *sb = inode->i_sb;
13969 + inode_lock(inode);
13970 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13973 + inode_unlock(inode);
13974 + si_read_lock(sb, AuLock_NOPLMW);
13975 + si_read_unlock(sb);
13979 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13980 + size_t count, loff_t *ppos)
13983 + struct au_write_pre wpre;
13984 + struct inode *inode;
13985 + struct file *h_file;
13986 + char __user *buf = (char __user *)ubuf;
13988 + inode = file_inode(file);
13989 + au_mtx_and_read_lock(inode);
13992 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13993 + err = PTR_ERR(h_file);
13994 + if (IS_ERR(h_file))
13997 + err = vfsub_write_u(h_file, buf, count, ppos);
13998 + au_write_post(inode, h_file, &wpre, err);
14001 + si_read_unlock(inode->i_sb);
14002 + inode_unlock(inode);
14006 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
14007 + struct iov_iter *iov_iter)
14010 + struct file *file;
14011 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
14013 + err = security_file_permission(h_file, rw);
14014 + if (unlikely(err))
14019 + if (rw == MAY_READ)
14020 + iter = h_file->f_op->read_iter;
14021 + else if (rw == MAY_WRITE)
14022 + iter = h_file->f_op->write_iter;
14024 + file = kio->ki_filp;
14025 + kio->ki_filp = h_file;
14028 + err = iter(kio, iov_iter);
14031 + /* currently there is no such fs */
14033 + kio->ki_filp = file;
14039 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14042 + struct file *file, *h_file;
14043 + struct inode *inode;
14044 + struct super_block *sb;
14046 + file = kio->ki_filp;
14047 + inode = file_inode(file);
14048 + sb = inode->i_sb;
14049 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14051 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
14052 + err = PTR_ERR(h_file);
14053 + if (IS_ERR(h_file))
14056 + if (au_test_loopback_kthread()) {
14057 + au_warn_loopback(h_file->f_path.dentry->d_sb);
14058 + if (file->f_mapping != h_file->f_mapping) {
14059 + file->f_mapping = h_file->f_mapping;
14060 + smp_mb(); /* unnecessary? */
14063 + fi_read_unlock(file);
14065 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
14066 + /* todo: necessary? */
14067 + /* file->f_ra = h_file->f_ra; */
14068 + au_read_post(inode, h_file);
14071 + si_read_unlock(sb);
14075 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14078 + struct au_write_pre wpre;
14079 + struct inode *inode;
14080 + struct file *file, *h_file;
14082 + file = kio->ki_filp;
14083 + inode = file_inode(file);
14084 + au_mtx_and_read_lock(inode);
14087 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14088 + err = PTR_ERR(h_file);
14089 + if (IS_ERR(h_file))
14092 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
14093 + au_write_post(inode, h_file, &wpre, err);
14096 + si_read_unlock(inode->i_sb);
14097 + inode_unlock(inode);
14101 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
14102 + struct pipe_inode_info *pipe, size_t len,
14103 + unsigned int flags)
14106 + struct file *h_file;
14107 + struct inode *inode;
14108 + struct super_block *sb;
14110 + inode = file_inode(file);
14111 + sb = inode->i_sb;
14112 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14114 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14115 + err = PTR_ERR(h_file);
14116 + if (IS_ERR(h_file))
14119 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14120 + /* todo: necessasry? */
14121 + /* file->f_ra = h_file->f_ra; */
14122 + au_read_post(inode, h_file);
14125 + si_read_unlock(sb);
14130 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14131 + size_t len, unsigned int flags)
14134 + struct au_write_pre wpre;
14135 + struct inode *inode;
14136 + struct file *h_file;
14138 + inode = file_inode(file);
14139 + au_mtx_and_read_lock(inode);
14142 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14143 + err = PTR_ERR(h_file);
14144 + if (IS_ERR(h_file))
14147 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14148 + au_write_post(inode, h_file, &wpre, err);
14151 + si_read_unlock(inode->i_sb);
14152 + inode_unlock(inode);
14156 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14160 + struct au_write_pre wpre;
14161 + struct inode *inode;
14162 + struct file *h_file;
14164 + inode = file_inode(file);
14165 + au_mtx_and_read_lock(inode);
14168 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14169 + err = PTR_ERR(h_file);
14170 + if (IS_ERR(h_file))
14174 + err = vfs_fallocate(h_file, mode, offset, len);
14176 + au_write_post(inode, h_file, &wpre, /*written*/1);
14179 + si_read_unlock(inode->i_sb);
14180 + inode_unlock(inode);
14184 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
14185 + struct file *dst, loff_t dst_pos,
14186 + size_t len, unsigned int flags)
14189 + struct au_write_pre wpre;
14190 + enum { SRC, DST };
14192 + struct inode *inode;
14193 + struct file *h_file;
14194 + struct super_block *h_sb;
14196 +#define a_src a[SRC]
14197 +#define a_dst a[DST]
14200 + a_src.inode = file_inode(src);
14201 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
14203 + a_dst.inode = file_inode(dst);
14204 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
14207 + au_mtx_and_read_lock(a_dst.inode);
14209 + * in order to match the order in di_write_lock2_{child,parent}(),
14210 + * use f_path.dentry for this comparision.
14212 + if (src->f_path.dentry < dst->f_path.dentry) {
14213 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
14214 + err = PTR_ERR(a_src.h_file);
14215 + if (IS_ERR(a_src.h_file))
14218 + wpre.lsc = AuLsc_FI_2;
14219 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14220 + err = PTR_ERR(a_dst.h_file);
14221 + if (IS_ERR(a_dst.h_file)) {
14222 + au_read_post(a_src.inode, a_src.h_file);
14226 + wpre.lsc = AuLsc_FI_1;
14227 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14228 + err = PTR_ERR(a_dst.h_file);
14229 + if (IS_ERR(a_dst.h_file))
14232 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
14233 + err = PTR_ERR(a_src.h_file);
14234 + if (IS_ERR(a_src.h_file)) {
14235 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
14242 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
14243 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
14244 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
14250 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
14251 + dst_pos, len, flags);
14254 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
14255 + fi_read_unlock(src);
14256 + au_read_post(a_src.inode, a_src.h_file);
14258 + si_read_unlock(a_dst.inode->i_sb);
14259 + inode_unlock(a_dst.inode);
14266 +/* ---------------------------------------------------------------------- */
14269 + * The locking order around current->mmap_sem.
14270 + * - in most and regular cases
14271 + * file I/O syscall -- aufs_read() or something
14272 + * -- si_rwsem for read -- mmap_sem
14273 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14275 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14276 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14277 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14278 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14279 + * It means that when aufs acquires si_rwsem for write, the process should never
14280 + * acquire mmap_sem.
14282 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14283 + * problem either since any directory is not able to be mmap-ed.
14284 + * The similar scenario is applied to aufs_readlink() too.
14287 +#if 0 /* stop calling security_file_mmap() */
14288 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14289 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14291 +static unsigned long au_arch_prot_conv(unsigned long flags)
14293 + /* currently ppc64 only */
14294 +#ifdef CONFIG_PPC64
14295 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14296 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14297 + return AuConv_VM_PROT(flags, SAO);
14299 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14304 +static unsigned long au_prot_conv(unsigned long flags)
14306 + return AuConv_VM_PROT(flags, READ)
14307 + | AuConv_VM_PROT(flags, WRITE)
14308 + | AuConv_VM_PROT(flags, EXEC)
14309 + | au_arch_prot_conv(flags);
14312 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14313 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14315 +static unsigned long au_flag_conv(unsigned long flags)
14317 + return AuConv_VM_MAP(flags, GROWSDOWN)
14318 + | AuConv_VM_MAP(flags, DENYWRITE)
14319 + | AuConv_VM_MAP(flags, LOCKED);
14323 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14326 + const unsigned char wlock
14327 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14328 + struct super_block *sb;
14329 + struct file *h_file;
14330 + struct inode *inode;
14332 + AuDbgVmRegion(file, vma);
14334 + inode = file_inode(file);
14335 + sb = inode->i_sb;
14337 + si_read_lock(sb, AuLock_NOPLMW);
14339 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14341 + err = PTR_ERR(h_file);
14342 + if (IS_ERR(h_file))
14346 + au_set_mmapped(file);
14347 + au_vm_file_reset(vma, h_file);
14349 + * we cannot call security_mmap_file() here since it may acquire
14350 + * mmap_sem or i_mutex.
14352 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14353 + * au_flag_conv(vma->vm_flags));
14356 + err = call_mmap(h_file, vma);
14358 + au_vm_prfile_set(vma, file);
14359 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14360 + goto out_fput; /* success */
14362 + au_unset_mmapped(file);
14363 + au_vm_file_reset(vma, file);
14367 + ii_write_unlock(inode);
14372 + si_read_unlock(sb);
14378 +/* ---------------------------------------------------------------------- */
14380 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14384 + struct au_write_pre wpre;
14385 + struct inode *inode;
14386 + struct file *h_file;
14388 + err = 0; /* -EBADF; */ /* posix? */
14389 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14392 + inode = file_inode(file);
14393 + au_mtx_and_read_lock(inode);
14396 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14397 + err = PTR_ERR(h_file);
14398 + if (IS_ERR(h_file))
14401 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14402 + au_write_post(inode, h_file, &wpre, /*written*/0);
14405 + si_read_unlock(inode->i_sb);
14406 + inode_unlock(inode);
14411 +static int aufs_fasync(int fd, struct file *file, int flag)
14414 + struct file *h_file;
14415 + struct super_block *sb;
14417 + sb = file->f_path.dentry->d_sb;
14418 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14420 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14421 + err = PTR_ERR(h_file);
14422 + if (IS_ERR(h_file))
14425 + if (h_file->f_op->fasync)
14426 + err = h_file->f_op->fasync(fd, h_file, flag);
14427 + fput(h_file); /* instead of au_read_post() */
14430 + si_read_unlock(sb);
14434 +static int aufs_setfl(struct file *file, unsigned long arg)
14437 + struct file *h_file;
14438 + struct super_block *sb;
14440 + sb = file->f_path.dentry->d_sb;
14441 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14443 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14444 + err = PTR_ERR(h_file);
14445 + if (IS_ERR(h_file))
14448 + /* stop calling h_file->fasync */
14449 + arg |= vfsub_file_flags(file) & FASYNC;
14450 + err = setfl(/*unused fd*/-1, h_file, arg);
14451 + fput(h_file); /* instead of au_read_post() */
14454 + si_read_unlock(sb);
14458 +/* ---------------------------------------------------------------------- */
14460 +/* no one supports this operation, currently */
14462 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14463 + size_t len, loff_t *pos, int more)
14468 +/* ---------------------------------------------------------------------- */
14470 +const struct file_operations aufs_file_fop = {
14471 + .owner = THIS_MODULE,
14473 + .llseek = default_llseek,
14475 + .read = aufs_read,
14476 + .write = aufs_write,
14477 + .read_iter = aufs_read_iter,
14478 + .write_iter = aufs_write_iter,
14480 +#ifdef CONFIG_AUFS_POLL
14481 + .poll = aufs_poll,
14483 + .unlocked_ioctl = aufs_ioctl_nondir,
14484 +#ifdef CONFIG_COMPAT
14485 + .compat_ioctl = aufs_compat_ioctl_nondir,
14487 + .mmap = aufs_mmap,
14488 + .open = aufs_open_nondir,
14489 + .flush = aufs_flush_nondir,
14490 + .release = aufs_release_nondir,
14491 + .fsync = aufs_fsync_nondir,
14492 + .fasync = aufs_fasync,
14493 + /* .sendpage = aufs_sendpage, */
14494 + .setfl = aufs_setfl,
14495 + .splice_write = aufs_splice_write,
14496 + .splice_read = aufs_splice_read,
14498 + .aio_splice_write = aufs_aio_splice_write,
14499 + .aio_splice_read = aufs_aio_splice_read,
14501 + .fallocate = aufs_fallocate,
14502 + .copy_file_range = aufs_copy_file_range
14504 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14505 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14506 +++ linux/fs/aufs/fstype.h 2017-07-29 12:14:25.903042072 +0200
14509 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14511 + * This program, aufs is free software; you can redistribute it and/or modify
14512 + * it under the terms of the GNU General Public License as published by
14513 + * the Free Software Foundation; either version 2 of the License, or
14514 + * (at your option) any later version.
14516 + * This program is distributed in the hope that it will be useful,
14517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14519 + * GNU General Public License for more details.
14521 + * You should have received a copy of the GNU General Public License
14522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14526 + * judging filesystem type
14529 +#ifndef __AUFS_FSTYPE_H__
14530 +#define __AUFS_FSTYPE_H__
14534 +#include <linux/fs.h>
14535 +#include <linux/magic.h>
14536 +#include <linux/nfs_fs.h>
14537 +#include <linux/romfs_fs.h>
14539 +static inline int au_test_aufs(struct super_block *sb)
14541 + return sb->s_magic == AUFS_SUPER_MAGIC;
14544 +static inline const char *au_sbtype(struct super_block *sb)
14546 + return sb->s_type->name;
14549 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14551 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14552 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14558 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14560 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14561 + return sb->s_magic == ROMFS_MAGIC;
14567 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14569 +#if IS_ENABLED(CONFIG_CRAMFS)
14570 + return sb->s_magic == CRAMFS_MAGIC;
14575 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14577 +#if IS_ENABLED(CONFIG_NFS_FS)
14578 + return sb->s_magic == NFS_SUPER_MAGIC;
14584 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14586 +#if IS_ENABLED(CONFIG_FUSE_FS)
14587 + return sb->s_magic == FUSE_SUPER_MAGIC;
14593 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14595 +#if IS_ENABLED(CONFIG_XFS_FS)
14596 + return sb->s_magic == XFS_SB_MAGIC;
14602 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14604 +#ifdef CONFIG_TMPFS
14605 + return sb->s_magic == TMPFS_MAGIC;
14611 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14613 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14614 + return !strcmp(au_sbtype(sb), "ecryptfs");
14620 +static inline int au_test_ramfs(struct super_block *sb)
14622 + return sb->s_magic == RAMFS_MAGIC;
14625 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14627 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14628 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14634 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14636 +#ifdef CONFIG_PROC_FS
14637 + return sb->s_magic == PROC_SUPER_MAGIC;
14643 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14645 +#ifdef CONFIG_SYSFS
14646 + return sb->s_magic == SYSFS_MAGIC;
14652 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14654 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14655 + return sb->s_magic == CONFIGFS_MAGIC;
14661 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14663 +#if IS_ENABLED(CONFIG_MINIX_FS)
14664 + return sb->s_magic == MINIX3_SUPER_MAGIC
14665 + || sb->s_magic == MINIX2_SUPER_MAGIC
14666 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14667 + || sb->s_magic == MINIX_SUPER_MAGIC
14668 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14674 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14676 +#if IS_ENABLED(CONFIG_FAT_FS)
14677 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14683 +static inline int au_test_msdos(struct super_block *sb)
14685 + return au_test_fat(sb);
14688 +static inline int au_test_vfat(struct super_block *sb)
14690 + return au_test_fat(sb);
14693 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14695 +#ifdef CONFIG_SECURITYFS
14696 + return sb->s_magic == SECURITYFS_MAGIC;
14702 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14704 +#if IS_ENABLED(CONFIG_SQUASHFS)
14705 + return sb->s_magic == SQUASHFS_MAGIC;
14711 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14713 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14714 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14720 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14722 +#if IS_ENABLED(CONFIG_XENFS)
14723 + return sb->s_magic == XENFS_SUPER_MAGIC;
14729 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14731 +#ifdef CONFIG_DEBUG_FS
14732 + return sb->s_magic == DEBUGFS_MAGIC;
14738 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14740 +#if IS_ENABLED(CONFIG_NILFS)
14741 + return sb->s_magic == NILFS_SUPER_MAGIC;
14747 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14749 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14750 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14756 +/* ---------------------------------------------------------------------- */
14758 + * they can't be an aufs branch.
14760 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14763 +#ifndef CONFIG_AUFS_BR_RAMFS
14764 + au_test_ramfs(sb) ||
14766 + au_test_procfs(sb)
14767 + || au_test_sysfs(sb)
14768 + || au_test_configfs(sb)
14769 + || au_test_debugfs(sb)
14770 + || au_test_securityfs(sb)
14771 + || au_test_xenfs(sb)
14772 + || au_test_ecryptfs(sb)
14773 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14774 + || au_test_aufs(sb); /* will be supported in next version */
14777 +static inline int au_test_fs_remote(struct super_block *sb)
14779 + return !au_test_tmpfs(sb)
14780 +#ifdef CONFIG_AUFS_BR_RAMFS
14781 + && !au_test_ramfs(sb)
14783 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14786 +/* ---------------------------------------------------------------------- */
14789 + * Note: these functions (below) are created after reading ->getattr() in all
14790 + * filesystems under linux/fs. it means we have to do so in every update...
14794 + * some filesystems require getattr to refresh the inode attributes before
14796 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14797 + * and leave the work for d_revalidate()
14799 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14801 + return au_test_nfs(sb)
14802 + || au_test_fuse(sb)
14803 + /* || au_test_btrfs(sb) */ /* untested */
14808 + * filesystems which don't maintain i_size or i_blocks.
14810 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14812 + return au_test_xfs(sb)
14813 + || au_test_btrfs(sb)
14814 + || au_test_ubifs(sb)
14815 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14816 + /* || au_test_minix(sb) */ /* untested */
14821 + * filesystems which don't store the correct value in some of their inode
14824 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14826 + return au_test_fs_bad_iattr_size(sb)
14827 + || au_test_fat(sb)
14828 + || au_test_msdos(sb)
14829 + || au_test_vfat(sb);
14832 +/* they don't check i_nlink in link(2) */
14833 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14835 + return au_test_tmpfs(sb)
14836 +#ifdef CONFIG_AUFS_BR_RAMFS
14837 + || au_test_ramfs(sb)
14839 + || au_test_ubifs(sb)
14840 + || au_test_hfsplus(sb);
14844 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14846 +static inline int au_test_fs_notime(struct super_block *sb)
14848 + return au_test_nfs(sb)
14849 + || au_test_fuse(sb)
14850 + || au_test_ubifs(sb)
14854 +/* temporary support for i#1 in cramfs */
14855 +static inline int au_test_fs_unique_ino(struct inode *inode)
14857 + if (au_test_cramfs(inode->i_sb))
14858 + return inode->i_ino != 1;
14862 +/* ---------------------------------------------------------------------- */
14865 + * the filesystem where the xino files placed must support i/o after unlink and
14866 + * maintain i_size and i_blocks.
14868 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14870 + return au_test_fs_remote(sb)
14871 + || au_test_fs_bad_iattr_size(sb)
14872 + /* don't want unnecessary work for xino */
14873 + || au_test_aufs(sb)
14874 + || au_test_ecryptfs(sb)
14875 + || au_test_nilfs(sb);
14878 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14880 + return au_test_tmpfs(sb)
14881 + || au_test_ramfs(sb);
14885 + * test if the @sb is real-readonly.
14887 +static inline int au_test_fs_rr(struct super_block *sb)
14889 + return au_test_squashfs(sb)
14890 + || au_test_iso9660(sb)
14891 + || au_test_cramfs(sb)
14892 + || au_test_romfs(sb);
14896 + * test if the @inode is nfs with 'noacl' option
14897 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14899 +static inline int au_test_nfs_noacl(struct inode *inode)
14901 + return au_test_nfs(inode->i_sb)
14902 + /* && IS_POSIXACL(inode) */
14903 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14906 +#endif /* __KERNEL__ */
14907 +#endif /* __AUFS_FSTYPE_H__ */
14908 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14909 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14910 +++ linux/fs/aufs/hfsnotify.c 2017-07-31 10:12:14.139177930 +0200
14913 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14915 + * This program, aufs is free software; you can redistribute it and/or modify
14916 + * it under the terms of the GNU General Public License as published by
14917 + * the Free Software Foundation; either version 2 of the License, or
14918 + * (at your option) any later version.
14920 + * This program is distributed in the hope that it will be useful,
14921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14923 + * GNU General Public License for more details.
14925 + * You should have received a copy of the GNU General Public License
14926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14930 + * fsnotify for the lower directories
14935 +/* FS_IN_IGNORED is unnecessary */
14936 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14937 + | FS_CREATE | FS_EVENT_ON_CHILD);
14938 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14939 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14941 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14943 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14945 + /* AuDbg("here\n"); */
14946 + au_cache_free_hnotify(hn);
14947 + smp_mb__before_atomic();
14948 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14949 + wake_up(&au_hfsn_wq);
14952 +static int au_hfsn_alloc(struct au_hinode *hinode)
14955 + struct au_hnotify *hn;
14956 + struct super_block *sb;
14957 + struct au_branch *br;
14958 + struct fsnotify_mark *mark;
14959 + aufs_bindex_t bindex;
14961 + hn = hinode->hi_notify;
14962 + sb = hn->hn_aufs_inode->i_sb;
14963 + bindex = au_br_index(sb, hinode->hi_id);
14964 + br = au_sbr(sb, bindex);
14965 + AuDebugOn(!br->br_hfsn);
14967 + mark = &hn->hn_mark;
14968 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14969 + mark->mask = AuHfsnMask;
14971 + * by udba rename or rmdir, aufs assign a new inode to the known
14972 + * h_inode, so specify 1 to allow dups.
14975 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14976 + /*mnt*/NULL, /*allow_dups*/1);
14982 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14984 + struct fsnotify_mark *mark;
14985 + unsigned long long ull;
14986 + struct fsnotify_group *group;
14988 + ull = atomic64_inc_return(&au_hfsn_ifree);
14991 + mark = &hn->hn_mark;
14992 + spin_lock(&mark->lock);
14993 + group = mark->group;
14994 + fsnotify_get_group(group);
14995 + spin_unlock(&mark->lock);
14997 + fsnotify_destroy_mark(mark, group);
14998 + fsnotify_put_mark(mark);
14999 + fsnotify_put_group(group);
15002 + /* free hn by myself */
15006 +/* ---------------------------------------------------------------------- */
15008 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
15010 + struct fsnotify_mark *mark;
15012 + mark = &hinode->hi_notify->hn_mark;
15013 + spin_lock(&mark->lock);
15015 + AuDebugOn(mark->mask & AuHfsnMask);
15016 + mark->mask |= AuHfsnMask;
15018 + AuDebugOn(!(mark->mask & AuHfsnMask));
15019 + mark->mask &= ~AuHfsnMask;
15021 + spin_unlock(&mark->lock);
15022 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
15025 +/* ---------------------------------------------------------------------- */
15027 +/* #define AuDbgHnotify */
15028 +#ifdef AuDbgHnotify
15029 +static char *au_hfsn_name(u32 mask)
15031 +#ifdef CONFIG_AUFS_DEBUG
15032 +#define test_ret(flag) \
15034 + if (mask & flag) \
15037 + test_ret(FS_ACCESS);
15038 + test_ret(FS_MODIFY);
15039 + test_ret(FS_ATTRIB);
15040 + test_ret(FS_CLOSE_WRITE);
15041 + test_ret(FS_CLOSE_NOWRITE);
15042 + test_ret(FS_OPEN);
15043 + test_ret(FS_MOVED_FROM);
15044 + test_ret(FS_MOVED_TO);
15045 + test_ret(FS_CREATE);
15046 + test_ret(FS_DELETE);
15047 + test_ret(FS_DELETE_SELF);
15048 + test_ret(FS_MOVE_SELF);
15049 + test_ret(FS_UNMOUNT);
15050 + test_ret(FS_Q_OVERFLOW);
15051 + test_ret(FS_IN_IGNORED);
15052 + test_ret(FS_ISDIR);
15053 + test_ret(FS_IN_ONESHOT);
15054 + test_ret(FS_EVENT_ON_CHILD);
15063 +/* ---------------------------------------------------------------------- */
15065 +static void au_hfsn_free_group(struct fsnotify_group *group)
15067 + struct au_br_hfsnotify *hfsn = group->private;
15069 + /* AuDbg("here\n"); */
15073 +static int au_hfsn_handle_event(struct fsnotify_group *group,
15074 + struct inode *inode,
15075 + struct fsnotify_mark *inode_mark,
15076 + struct fsnotify_mark *vfsmount_mark,
15077 + u32 mask, const void *data, int data_type,
15078 + const unsigned char *file_name, u32 cookie)
15081 + struct au_hnotify *hnotify;
15082 + struct inode *h_dir, *h_inode;
15083 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
15085 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
15088 + /* if FS_UNMOUNT happens, there must be another bug */
15089 + AuDebugOn(mask & FS_UNMOUNT);
15090 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
15095 +#ifdef AuDbgHnotify
15097 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
15098 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
15099 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
15100 + h_dir->i_ino, mask, au_hfsn_name(mask),
15101 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
15102 + /* WARN_ON(1); */
15107 + AuDebugOn(!inode_mark);
15108 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
15109 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
15115 +static struct fsnotify_ops au_hfsn_ops = {
15116 + .handle_event = au_hfsn_handle_event,
15117 + .free_group_priv = au_hfsn_free_group
15120 +/* ---------------------------------------------------------------------- */
15122 +static void au_hfsn_fin_br(struct au_branch *br)
15124 + struct au_br_hfsnotify *hfsn;
15126 + hfsn = br->br_hfsn;
15129 + fsnotify_put_group(hfsn->hfsn_group);
15134 +static int au_hfsn_init_br(struct au_branch *br, int perm)
15137 + struct fsnotify_group *group;
15138 + struct au_br_hfsnotify *hfsn;
15141 + br->br_hfsn = NULL;
15142 + if (!au_br_hnotifyable(perm))
15146 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
15147 + if (unlikely(!hfsn))
15151 + group = fsnotify_alloc_group(&au_hfsn_ops);
15152 + if (IS_ERR(group)) {
15153 + err = PTR_ERR(group);
15154 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
15158 + group->private = hfsn;
15159 + hfsn->hfsn_group = group;
15160 + br->br_hfsn = hfsn;
15161 + goto out; /* success */
15169 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
15174 + if (!br->br_hfsn)
15175 + err = au_hfsn_init_br(br, perm);
15180 +/* ---------------------------------------------------------------------- */
15182 +static void au_hfsn_fin(void)
15184 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
15185 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
15188 +const struct au_hnotify_op au_hnotify_op = {
15189 + .ctl = au_hfsn_ctl,
15190 + .alloc = au_hfsn_alloc,
15191 + .free = au_hfsn_free,
15193 + .fin = au_hfsn_fin,
15195 + .reset_br = au_hfsn_reset_br,
15196 + .fin_br = au_hfsn_fin_br,
15197 + .init_br = au_hfsn_init_br
15199 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15200 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15201 +++ linux/fs/aufs/hfsplus.c 2017-07-29 12:14:25.903042072 +0200
15204 + * Copyright (C) 2010-2017 Junjiro R. Okajima
15206 + * This program, aufs is free software; you can redistribute it and/or modify
15207 + * it under the terms of the GNU General Public License as published by
15208 + * the Free Software Foundation; either version 2 of the License, or
15209 + * (at your option) any later version.
15211 + * This program is distributed in the hope that it will be useful,
15212 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15213 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15214 + * GNU General Public License for more details.
15216 + * You should have received a copy of the GNU General Public License
15217 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15221 + * special support for filesystems which aqucires an inode mutex
15222 + * at final closing a file, eg, hfsplus.
15224 + * This trick is very simple and stupid, just to open the file before really
15225 + * neceeary open to tell hfsplus that this is not the final closing.
15226 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15227 + * and au_h_open_post() after releasing it.
15232 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15235 + struct file *h_file;
15236 + struct dentry *h_dentry;
15238 + h_dentry = au_h_dptr(dentry, bindex);
15239 + AuDebugOn(!h_dentry);
15240 + AuDebugOn(d_is_negative(h_dentry));
15243 + if (au_test_hfsplus(h_dentry->d_sb)
15244 + && d_is_reg(h_dentry))
15245 + h_file = au_h_open(dentry, bindex,
15246 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15247 + /*file*/NULL, force_wr);
15251 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15252 + struct file *h_file)
15256 + au_sbr_put(dentry->d_sb, bindex);
15259 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15260 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15261 +++ linux/fs/aufs/hnotify.c 2017-07-29 12:14:25.903042072 +0200
15264 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15266 + * This program, aufs is free software; you can redistribute it and/or modify
15267 + * it under the terms of the GNU General Public License as published by
15268 + * the Free Software Foundation; either version 2 of the License, or
15269 + * (at your option) any later version.
15271 + * This program is distributed in the hope that it will be useful,
15272 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15273 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15274 + * GNU General Public License for more details.
15276 + * You should have received a copy of the GNU General Public License
15277 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15281 + * abstraction to notify the direct changes on lower directories
15286 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15289 + struct au_hnotify *hn;
15292 + hn = au_cache_alloc_hnotify();
15294 + hn->hn_aufs_inode = inode;
15295 + hinode->hi_notify = hn;
15296 + err = au_hnotify_op.alloc(hinode);
15298 + if (unlikely(err)) {
15299 + hinode->hi_notify = NULL;
15300 + au_cache_free_hnotify(hn);
15302 + * The upper dir was removed by udba, but the same named
15303 + * dir left. In this case, aufs assignes a new inode
15304 + * number and set the monitor again.
15305 + * For the lower dir, the old monitnor is still left.
15307 + if (err == -EEXIST)
15316 +void au_hn_free(struct au_hinode *hinode)
15318 + struct au_hnotify *hn;
15320 + hn = hinode->hi_notify;
15322 + hinode->hi_notify = NULL;
15323 + if (au_hnotify_op.free(hinode, hn))
15324 + au_cache_free_hnotify(hn);
15328 +/* ---------------------------------------------------------------------- */
15330 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15332 + if (hinode->hi_notify)
15333 + au_hnotify_op.ctl(hinode, do_set);
15336 +void au_hn_reset(struct inode *inode, unsigned int flags)
15338 + aufs_bindex_t bindex, bbot;
15339 + struct inode *hi;
15340 + struct dentry *iwhdentry;
15342 + bbot = au_ibbot(inode);
15343 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15344 + hi = au_h_iptr(inode, bindex);
15348 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15349 + iwhdentry = au_hi_wh(inode, bindex);
15353 + au_set_h_iptr(inode, bindex, NULL, 0);
15354 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15355 + flags & ~AuHi_XINO);
15358 + /* inode_unlock(hi); */
15362 +/* ---------------------------------------------------------------------- */
15364 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15367 + aufs_bindex_t bindex, bbot, bfound, btop;
15368 + struct inode *h_i;
15371 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15372 + pr_warn("branch root dir was changed\n");
15377 + bbot = au_ibbot(inode);
15378 + btop = au_ibtop(inode);
15379 +#if 0 /* reserved for future use */
15380 + if (bindex == bbot) {
15381 + /* keep this ino in rename case */
15385 + for (bindex = btop; bindex <= bbot; bindex++)
15386 + if (au_h_iptr(inode, bindex) == h_inode) {
15393 + for (bindex = btop; bindex <= bbot; bindex++) {
15394 + h_i = au_h_iptr(inode, bindex);
15398 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15399 + /* ignore this error */
15400 + /* bad action? */
15403 + /* children inode number will be broken */
15410 +static int hn_gen_tree(struct dentry *dentry)
15412 + int err, i, j, ndentry;
15413 + struct au_dcsub_pages dpages;
15414 + struct au_dpage *dpage;
15415 + struct dentry **dentries;
15417 + err = au_dpages_init(&dpages, GFP_NOFS);
15418 + if (unlikely(err))
15420 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15421 + if (unlikely(err))
15424 + for (i = 0; i < dpages.ndpage; i++) {
15425 + dpage = dpages.dpages + i;
15426 + dentries = dpage->dentries;
15427 + ndentry = dpage->ndentry;
15428 + for (j = 0; j < ndentry; j++) {
15429 + struct dentry *d;
15436 + if (d_really_is_positive(d))
15437 + /* todo: reset children xino?
15438 + cached children only? */
15439 + au_iigen_dec(d_inode(d));
15444 + au_dpages_free(&dpages);
15447 + /* discard children */
15448 + dentry_unhash(dentry);
15456 + * return 0 if processed.
15458 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15459 + const unsigned int isdir)
15462 + struct dentry *d;
15463 + struct qstr *dname;
15466 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15467 + pr_warn("branch root dir was changed\n");
15473 + AuDebugOn(!name);
15474 + au_iigen_dec(inode);
15475 + spin_lock(&inode->i_lock);
15476 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15477 + spin_lock(&d->d_lock);
15478 + dname = &d->d_name;
15479 + if (dname->len != nlen
15480 + && memcmp(dname->name, name, nlen)) {
15481 + spin_unlock(&d->d_lock);
15486 + spin_unlock(&d->d_lock);
15489 + spin_unlock(&inode->i_lock);
15491 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15492 + d = d_find_any_alias(inode);
15494 + au_iigen_dec(inode);
15498 + spin_lock(&d->d_lock);
15499 + dname = &d->d_name;
15500 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15501 + spin_unlock(&d->d_lock);
15502 + err = hn_gen_tree(d);
15503 + spin_lock(&d->d_lock);
15505 + spin_unlock(&d->d_lock);
15514 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15518 + if (IS_ROOT(dentry)) {
15519 + pr_warn("branch root dir was changed\n");
15525 + au_digen_dec(dentry);
15526 + if (d_really_is_positive(dentry))
15527 + au_iigen_dec(d_inode(dentry));
15529 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15530 + if (d_really_is_positive(dentry))
15531 + err = hn_gen_tree(dentry);
15538 +/* ---------------------------------------------------------------------- */
15540 +/* hnotify job flags */
15541 +#define AuHnJob_XINO0 1
15542 +#define AuHnJob_GEN (1 << 1)
15543 +#define AuHnJob_DIRENT (1 << 2)
15544 +#define AuHnJob_ISDIR (1 << 3)
15545 +#define AuHnJob_TRYXINO0 (1 << 4)
15546 +#define AuHnJob_MNTPNT (1 << 5)
15547 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15548 +#define au_fset_hnjob(flags, name) \
15549 + do { (flags) |= AuHnJob_##name; } while (0)
15550 +#define au_fclr_hnjob(flags, name) \
15551 + do { (flags) &= ~AuHnJob_##name; } while (0)
15559 +struct au_hnotify_args {
15560 + struct inode *h_dir, *dir, *h_child_inode;
15562 + unsigned int flags[AuHnLast];
15563 + unsigned int h_child_nlen;
15564 + char h_child_name[];
15567 +struct hn_job_args {
15568 + unsigned int flags;
15569 + struct inode *inode, *h_inode, *dir, *h_dir;
15570 + struct dentry *dentry;
15575 +static int hn_job(struct hn_job_args *a)
15577 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15581 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15582 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15584 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15587 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15588 + if (!a->h_inode->i_nlink
15589 + && !(a->h_inode->i_state & I_LINKABLE))
15590 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15591 + inode_unlock(a->h_inode);
15594 + /* make the generation obsolete */
15595 + if (au_ftest_hnjob(a->flags, GEN)) {
15598 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15600 + if (e && a->dentry)
15601 + hn_gen_by_name(a->dentry, isdir);
15602 + /* ignore this error */
15605 + /* make dir entries obsolete */
15606 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15607 + struct au_vdir *vdir;
15609 + vdir = au_ivdir(a->inode);
15611 + vdir->vd_jiffy = 0;
15612 + /* IMustLock(a->inode); */
15613 + /* a->inode->i_version++; */
15616 + /* can do nothing but warn */
15617 + if (au_ftest_hnjob(a->flags, MNTPNT)
15619 + && d_mountpoint(a->dentry))
15620 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15625 +/* ---------------------------------------------------------------------- */
15627 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15628 + struct inode *dir)
15630 + struct dentry *dentry, *d, *parent;
15631 + struct qstr *dname;
15633 + parent = d_find_any_alias(dir);
15638 + spin_lock(&parent->d_lock);
15639 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15640 + /* AuDbg("%pd\n", d); */
15641 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15642 + dname = &d->d_name;
15643 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15644 + goto cont_unlock;
15648 + goto cont_unlock;
15649 + if (au_dcount(d) > 0) {
15650 + dentry = dget_dlock(d);
15651 + spin_unlock(&d->d_lock);
15656 + spin_unlock(&d->d_lock);
15658 + spin_unlock(&parent->d_lock);
15662 + di_write_lock_child(dentry);
15667 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15668 + aufs_bindex_t bindex, ino_t h_ino)
15670 + struct inode *inode;
15675 + err = au_xino_read(sb, bindex, h_ino, &ino);
15677 + inode = ilookup(sb, ino);
15681 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15682 + pr_warn("wrong root branch\n");
15688 + ii_write_lock_child(inode);
15694 +static void au_hn_bh(void *_args)
15696 + struct au_hnotify_args *a = _args;
15697 + struct super_block *sb;
15698 + aufs_bindex_t bindex, bbot, bfound;
15699 + unsigned char xino, try_iput;
15701 + struct inode *inode;
15703 + struct hn_job_args args;
15704 + struct dentry *dentry;
15705 + struct au_sbinfo *sbinfo;
15707 + AuDebugOn(!_args);
15708 + AuDebugOn(!a->h_dir);
15709 + AuDebugOn(!a->dir);
15710 + AuDebugOn(!a->mask);
15711 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15712 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15713 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15718 + * do not lock a->dir->i_mutex here
15719 + * because of d_revalidate() may cause a deadlock.
15721 + sb = a->dir->i_sb;
15723 + sbinfo = au_sbi(sb);
15724 + AuDebugOn(!sbinfo);
15725 + si_write_lock(sb, AuLock_NOPLMW);
15727 + ii_read_lock_parent(a->dir);
15729 + bbot = au_ibbot(a->dir);
15730 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15731 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15735 + ii_read_unlock(a->dir);
15736 + if (unlikely(bfound < 0))
15739 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15741 + if (a->h_child_inode)
15742 + h_ino = a->h_child_inode->i_ino;
15744 + if (a->h_child_nlen
15745 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15746 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15747 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15750 + if (dentry && d_really_is_positive(dentry))
15751 + inode = d_inode(dentry);
15752 + if (xino && !inode && h_ino
15753 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15754 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15755 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15756 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15760 + args.flags = a->flags[AuHn_CHILD];
15761 + args.dentry = dentry;
15762 + args.inode = inode;
15763 + args.h_inode = a->h_child_inode;
15764 + args.dir = a->dir;
15765 + args.h_dir = a->h_dir;
15766 + args.h_name = a->h_child_name;
15767 + args.h_nlen = a->h_child_nlen;
15768 + err = hn_job(&args);
15770 + if (au_di(dentry))
15771 + di_write_unlock(dentry);
15774 + if (inode && try_iput) {
15775 + ii_write_unlock(inode);
15779 + ii_write_lock_parent(a->dir);
15780 + args.flags = a->flags[AuHn_PARENT];
15781 + args.dentry = NULL;
15782 + args.inode = a->dir;
15783 + args.h_inode = a->h_dir;
15785 + args.h_dir = NULL;
15786 + args.h_name = NULL;
15788 + err = hn_job(&args);
15789 + ii_write_unlock(a->dir);
15792 + iput(a->h_child_inode);
15795 + si_write_unlock(sb);
15796 + au_nwt_done(&sbinfo->si_nowait);
15800 +/* ---------------------------------------------------------------------- */
15802 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15803 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15806 + unsigned int flags[AuHnLast], f;
15807 + unsigned char isdir, isroot, wh;
15808 + struct inode *dir;
15809 + struct au_hnotify_args *args;
15810 + char *p, *h_child_name;
15813 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15814 + dir = igrab(hnotify->hn_aufs_inode);
15818 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15820 + h_child_name = (void *)h_child_qstr->name;
15821 + len = h_child_qstr->len;
15822 + if (h_child_name) {
15823 + if (len > AUFS_WH_PFX_LEN
15824 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15825 + h_child_name += AUFS_WH_PFX_LEN;
15826 + len -= AUFS_WH_PFX_LEN;
15832 + if (h_child_inode)
15833 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15834 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15835 + flags[AuHn_CHILD] = 0;
15837 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15838 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15839 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15840 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15841 + case FS_MOVED_FROM:
15842 + case FS_MOVED_TO:
15843 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15844 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15847 + AuDebugOn(!h_child_name);
15852 + * aufs never be able to get this child inode.
15853 + * revalidation should be in d_revalidate()
15854 + * by checking i_nlink, i_generation or d_unhashed().
15856 + AuDebugOn(!h_child_name);
15857 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15858 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15866 + h_child_inode = NULL;
15869 + /* iput() and kfree() will be called in au_hnotify() */
15870 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15871 + if (unlikely(!args)) {
15872 + AuErr1("no memory\n");
15876 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15877 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15878 + args->mask = mask;
15880 + args->h_dir = igrab(h_dir);
15881 + if (h_child_inode)
15882 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15883 + args->h_child_inode = h_child_inode;
15884 + args->h_child_nlen = len;
15886 + p = (void *)args;
15887 + p += sizeof(*args);
15888 + memcpy(p, h_child_name, len);
15892 + /* NFS fires the event for silly-renamed one from kworker */
15894 + if (!dir->i_nlink
15895 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15897 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15898 + if (unlikely(err)) {
15899 + pr_err("wkq %d\n", err);
15900 + iput(args->h_child_inode);
15901 + iput(args->h_dir);
15910 +/* ---------------------------------------------------------------------- */
15912 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15916 + AuDebugOn(!(udba & AuOptMask_UDBA));
15919 + if (au_hnotify_op.reset_br)
15920 + err = au_hnotify_op.reset_br(udba, br, perm);
15925 +int au_hnotify_init_br(struct au_branch *br, int perm)
15930 + if (au_hnotify_op.init_br)
15931 + err = au_hnotify_op.init_br(br, perm);
15936 +void au_hnotify_fin_br(struct au_branch *br)
15938 + if (au_hnotify_op.fin_br)
15939 + au_hnotify_op.fin_br(br);
15942 +static void au_hn_destroy_cache(void)
15944 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
15945 + au_cache[AuCache_HNOTIFY] = NULL;
15948 +int __init au_hnotify_init(void)
15953 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
15954 + if (au_cache[AuCache_HNOTIFY]) {
15956 + if (au_hnotify_op.init)
15957 + err = au_hnotify_op.init();
15958 + if (unlikely(err))
15959 + au_hn_destroy_cache();
15965 +void au_hnotify_fin(void)
15967 + if (au_hnotify_op.fin)
15968 + au_hnotify_op.fin();
15970 + /* cf. au_cache_fin() */
15971 + if (au_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-07-29 12:14:25.903042072 +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);
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 + 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-07-29 12:14:25.903042072 +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-07-29 12:14:25.903042072 +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;
16835 + struct inode *hn_aufs_inode; /* no get/put */
16837 +} ____cacheline_aligned_in_smp;
16839 +struct au_hinode {
16840 + struct inode *hi_inode;
16841 + aufs_bindex_t hi_id;
16842 +#ifdef CONFIG_AUFS_HNOTIFY
16843 + struct au_hnotify *hi_notify;
16846 + /* reference to the copied-up whiteout with get/put */
16847 + struct dentry *hi_whdentry;
16851 +#define AuIG_HALF_REFRESHED 1
16852 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16853 +#define au_ig_fset(flags, name) \
16854 + do { (flags) |= AuIG_##name; } while (0)
16855 +#define au_ig_fclr(flags, name) \
16856 + do { (flags) &= ~AuIG_##name; } while (0)
16859 + spinlock_t ig_spin;
16860 + __u32 ig_generation, ig_flags;
16865 + struct au_iigen ii_generation;
16866 + struct super_block *ii_hsb1; /* no get/put */
16868 + struct au_rwsem ii_rwsem;
16869 + aufs_bindex_t ii_btop, ii_bbot;
16871 + struct au_hinode *ii_hinode;
16872 + struct au_vdir *ii_vdir;
16875 +struct au_icntnr {
16876 + struct au_iinfo iinfo;
16877 + struct inode vfs_inode;
16878 + struct hlist_node plink;
16879 +} ____cacheline_aligned_in_smp;
16881 +/* au_pin flags */
16882 +#define AuPin_DI_LOCKED 1
16883 +#define AuPin_MNT_WRITE (1 << 1)
16884 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16885 +#define au_fset_pin(flags, name) \
16886 + do { (flags) |= AuPin_##name; } while (0)
16887 +#define au_fclr_pin(flags, name) \
16888 + do { (flags) &= ~AuPin_##name; } while (0)
16892 + struct dentry *dentry;
16893 + unsigned int udba;
16894 + unsigned char lsc_di, lsc_hi, flags;
16895 + aufs_bindex_t bindex;
16898 + struct dentry *parent;
16899 + struct au_hinode *hdir;
16900 + struct vfsmount *h_mnt;
16902 + /* temporary unlock/relock for copyup */
16903 + struct dentry *h_dentry, *h_parent;
16904 + struct au_branch *br;
16905 + struct task_struct *task;
16908 +void au_pin_hdir_unlock(struct au_pin *p);
16909 +int au_pin_hdir_lock(struct au_pin *p);
16910 +int au_pin_hdir_relock(struct au_pin *p);
16911 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16912 +void au_pin_hdir_release(struct au_pin *p);
16914 +/* ---------------------------------------------------------------------- */
16916 +static inline struct au_iinfo *au_ii(struct inode *inode)
16918 + BUG_ON(is_bad_inode(inode));
16919 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16922 +/* ---------------------------------------------------------------------- */
16925 +struct inode *au_igrab(struct inode *inode);
16926 +void au_refresh_iop(struct inode *inode, int force_getattr);
16927 +int au_refresh_hinode_self(struct inode *inode);
16928 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16929 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16930 + unsigned int d_type, ino_t *ino);
16931 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16932 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16933 + struct inode *inode);
16934 +int au_test_h_perm(struct inode *h_inode, int mask);
16935 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16937 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16938 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16940 +#ifdef CONFIG_AUFS_SHWH
16941 + return au_ino(sb, bindex, h_ino, d_type, ino);
16954 +extern struct inode_operations aufs_iop[AuIop_Last],
16955 + aufs_iop_nogetattr[AuIop_Last];
16957 +/* au_wr_dir flags */
16958 +#define AuWrDir_ADD_ENTRY 1
16959 +#define AuWrDir_ISDIR (1 << 1)
16960 +#define AuWrDir_TMPFILE (1 << 2)
16961 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16962 +#define au_fset_wrdir(flags, name) \
16963 + do { (flags) |= AuWrDir_##name; } while (0)
16964 +#define au_fclr_wrdir(flags, name) \
16965 + do { (flags) &= ~AuWrDir_##name; } while (0)
16967 +struct au_wr_dir_args {
16968 + aufs_bindex_t force_btgt;
16969 + unsigned char flags;
16971 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16972 + struct au_wr_dir_args *args);
16974 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16975 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16976 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16977 + unsigned int udba, unsigned char flags);
16978 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16979 + unsigned int udba, unsigned char flags) __must_check;
16980 +int au_do_pin(struct au_pin *pin) __must_check;
16981 +void au_unpin(struct au_pin *pin);
16982 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16984 +#define AuIcpup_DID_CPUP 1
16985 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16986 +#define au_fset_icpup(flags, name) \
16987 + do { (flags) |= AuIcpup_##name; } while (0)
16988 +#define au_fclr_icpup(flags, name) \
16989 + do { (flags) &= ~AuIcpup_##name; } while (0)
16991 +struct au_icpup_args {
16992 + unsigned char flags;
16993 + unsigned char pin_flags;
16994 + aufs_bindex_t btgt;
16995 + unsigned int udba;
16996 + struct au_pin pin;
16997 + struct path h_path;
16998 + struct inode *h_inode;
17001 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17002 + struct au_icpup_args *a);
17004 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
17008 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17009 + struct dentry *h_parent, int isdir);
17010 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17012 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
17013 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17015 +struct vfsub_aopen_args;
17016 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17017 + struct vfsub_aopen_args *args);
17018 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
17019 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17020 + struct dentry *dentry);
17021 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
17024 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
17025 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17026 + struct dentry *h_parent, int isdir);
17027 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
17028 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
17031 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
17032 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
17033 + struct inode *dir, struct dentry *dentry,
17034 + unsigned int flags);
17037 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
17038 +void au_hiput(struct au_hinode *hinode);
17039 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17040 + struct dentry *h_wh);
17041 +unsigned int au_hi_flags(struct inode *inode, int isdir);
17043 +/* hinode flags */
17044 +#define AuHi_XINO 1
17045 +#define AuHi_HNOTIFY (1 << 1)
17046 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
17047 +#define au_fset_hi(flags, name) \
17048 + do { (flags) |= AuHi_##name; } while (0)
17049 +#define au_fclr_hi(flags, name) \
17050 + do { (flags) &= ~AuHi_##name; } while (0)
17052 +#ifndef CONFIG_AUFS_HNOTIFY
17053 +#undef AuHi_HNOTIFY
17054 +#define AuHi_HNOTIFY 0
17057 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17058 + struct inode *h_inode, unsigned int flags);
17060 +void au_update_iigen(struct inode *inode, int half);
17061 +void au_update_ibrange(struct inode *inode, int do_put_zero);
17063 +void au_icntnr_init_once(void *_c);
17064 +void au_hinode_init(struct au_hinode *hinode);
17065 +int au_iinfo_init(struct inode *inode);
17066 +void au_iinfo_fin(struct inode *inode);
17067 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
17069 +#ifdef CONFIG_PROC_FS
17071 +int au_plink_maint(struct super_block *sb, int flags);
17073 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
17074 +int au_plink_maint_enter(struct super_block *sb);
17075 +#ifdef CONFIG_AUFS_DEBUG
17076 +void au_plink_list(struct super_block *sb);
17078 +AuStubVoid(au_plink_list, struct super_block *sb)
17080 +int au_plink_test(struct inode *inode);
17081 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
17082 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
17083 + struct dentry *h_dentry);
17084 +void au_plink_put(struct super_block *sb, int verbose);
17085 +void au_plink_clean(struct super_block *sb, int verbose);
17086 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
17088 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
17089 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
17090 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
17091 +AuStubVoid(au_plink_list, struct super_block *sb);
17092 +AuStubInt0(au_plink_test, struct inode *inode);
17093 +AuStub(struct dentry *, au_plink_lkup, return NULL,
17094 + struct inode *inode, aufs_bindex_t bindex);
17095 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
17096 + struct dentry *h_dentry);
17097 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
17098 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
17099 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
17100 +#endif /* CONFIG_PROC_FS */
17102 +#ifdef CONFIG_AUFS_XATTR
17104 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
17105 + unsigned int verbose);
17106 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
17107 +void au_xattr_init(struct super_block *sb);
17109 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
17110 + int ignore_flags, unsigned int verbose);
17111 +AuStubVoid(au_xattr_init, struct super_block *sb);
17114 +#ifdef CONFIG_FS_POSIX_ACL
17115 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
17116 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
17119 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
17125 +struct au_sxattr {
17129 + const char *name;
17130 + const void *value;
17135 + struct posix_acl *acl;
17140 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
17141 + struct au_sxattr *arg);
17144 +/* ---------------------------------------------------------------------- */
17146 +/* lock subclass for iinfo */
17148 + AuLsc_II_CHILD, /* child first */
17149 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
17150 + AuLsc_II_CHILD3, /* copyup dirs */
17151 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
17152 + AuLsc_II_PARENT2,
17153 + AuLsc_II_PARENT3, /* copyup dirs */
17154 + AuLsc_II_NEW_CHILD
17158 + * ii_read_lock_child, ii_write_lock_child,
17159 + * ii_read_lock_child2, ii_write_lock_child2,
17160 + * ii_read_lock_child3, ii_write_lock_child3,
17161 + * ii_read_lock_parent, ii_write_lock_parent,
17162 + * ii_read_lock_parent2, ii_write_lock_parent2,
17163 + * ii_read_lock_parent3, ii_write_lock_parent3,
17164 + * ii_read_lock_new_child, ii_write_lock_new_child,
17166 +#define AuReadLockFunc(name, lsc) \
17167 +static inline void ii_read_lock_##name(struct inode *i) \
17169 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17172 +#define AuWriteLockFunc(name, lsc) \
17173 +static inline void ii_write_lock_##name(struct inode *i) \
17175 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17178 +#define AuRWLockFuncs(name, lsc) \
17179 + AuReadLockFunc(name, lsc) \
17180 + AuWriteLockFunc(name, lsc)
17182 +AuRWLockFuncs(child, CHILD);
17183 +AuRWLockFuncs(child2, CHILD2);
17184 +AuRWLockFuncs(child3, CHILD3);
17185 +AuRWLockFuncs(parent, PARENT);
17186 +AuRWLockFuncs(parent2, PARENT2);
17187 +AuRWLockFuncs(parent3, PARENT3);
17188 +AuRWLockFuncs(new_child, NEW_CHILD);
17190 +#undef AuReadLockFunc
17191 +#undef AuWriteLockFunc
17192 +#undef AuRWLockFuncs
17195 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17197 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17199 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17200 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17201 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17203 +/* ---------------------------------------------------------------------- */
17205 +static inline void au_icntnr_init(struct au_icntnr *c)
17207 +#ifdef CONFIG_AUFS_DEBUG
17208 + c->vfs_inode.i_mode = 0;
17212 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17214 + unsigned int gen;
17215 + struct au_iinfo *iinfo;
17216 + struct au_iigen *iigen;
17218 + iinfo = au_ii(inode);
17219 + iigen = &iinfo->ii_generation;
17220 + spin_lock(&iigen->ig_spin);
17222 + *igflags = iigen->ig_flags;
17223 + gen = iigen->ig_generation;
17224 + spin_unlock(&iigen->ig_spin);
17229 +/* tiny test for inode number */
17230 +/* tmpfs generation is too rough */
17231 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17233 + struct au_iinfo *iinfo;
17235 + iinfo = au_ii(inode);
17236 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17237 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17238 + && iinfo->ii_higen == h_inode->i_generation);
17241 +static inline void au_iigen_dec(struct inode *inode)
17243 + struct au_iinfo *iinfo;
17244 + struct au_iigen *iigen;
17246 + iinfo = au_ii(inode);
17247 + iigen = &iinfo->ii_generation;
17248 + spin_lock(&iigen->ig_spin);
17249 + iigen->ig_generation--;
17250 + spin_unlock(&iigen->ig_spin);
17253 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17258 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17264 +/* ---------------------------------------------------------------------- */
17266 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17267 + aufs_bindex_t bindex)
17269 + return iinfo->ii_hinode + bindex;
17272 +static inline int au_is_bad_inode(struct inode *inode)
17274 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17277 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17278 + aufs_bindex_t bindex)
17280 + IiMustAnyLock(inode);
17281 + return au_hinode(au_ii(inode), bindex)->hi_id;
17284 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17286 + IiMustAnyLock(inode);
17287 + return au_ii(inode)->ii_btop;
17290 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17292 + IiMustAnyLock(inode);
17293 + return au_ii(inode)->ii_bbot;
17296 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17298 + IiMustAnyLock(inode);
17299 + return au_ii(inode)->ii_vdir;
17302 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17304 + IiMustAnyLock(inode);
17305 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17308 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17310 + IiMustWriteLock(inode);
17311 + au_ii(inode)->ii_btop = bindex;
17314 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17316 + IiMustWriteLock(inode);
17317 + au_ii(inode)->ii_bbot = bindex;
17320 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17322 + IiMustWriteLock(inode);
17323 + au_ii(inode)->ii_vdir = vdir;
17326 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17328 + IiMustAnyLock(inode);
17329 + return au_hinode(au_ii(inode), bindex);
17332 +/* ---------------------------------------------------------------------- */
17334 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17337 + return pin->parent;
17341 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17343 + if (pin && pin->hdir)
17344 + return pin->hdir->hi_inode;
17348 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17351 + return pin->hdir;
17355 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17358 + pin->dentry = dentry;
17361 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17362 + unsigned char lflag)
17366 + au_fset_pin(pin->flags, DI_LOCKED);
17368 + au_fclr_pin(pin->flags, DI_LOCKED);
17372 +#if 0 /* reserved */
17373 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17376 + dput(pin->parent);
17377 + pin->parent = dget(parent);
17382 +/* ---------------------------------------------------------------------- */
17385 +#ifdef CONFIG_AUFS_HNOTIFY
17386 +struct au_hnotify_op {
17387 + void (*ctl)(struct au_hinode *hinode, int do_set);
17388 + int (*alloc)(struct au_hinode *hinode);
17391 + * if it returns true, the the caller should free hinode->hi_notify,
17392 + * otherwise ->free() frees it.
17394 + int (*free)(struct au_hinode *hinode,
17395 + struct au_hnotify *hn) __must_check;
17397 + void (*fin)(void);
17398 + int (*init)(void);
17400 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17401 + void (*fin_br)(struct au_branch *br);
17402 + int (*init_br)(struct au_branch *br, int perm);
17406 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17407 +void au_hn_free(struct au_hinode *hinode);
17408 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17409 +void au_hn_reset(struct inode *inode, unsigned int flags);
17410 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17411 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17412 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17413 +int au_hnotify_init_br(struct au_branch *br, int perm);
17414 +void au_hnotify_fin_br(struct au_branch *br);
17415 +int __init au_hnotify_init(void);
17416 +void au_hnotify_fin(void);
17419 +extern const struct au_hnotify_op au_hnotify_op;
17422 +void au_hn_init(struct au_hinode *hinode)
17424 + hinode->hi_notify = NULL;
17427 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17429 + return hinode->hi_notify;
17433 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17434 + struct au_hinode *hinode __maybe_unused,
17435 + struct inode *inode __maybe_unused)
17436 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17437 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17438 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17439 + int do_set __maybe_unused)
17440 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17441 + unsigned int flags __maybe_unused)
17442 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17443 + struct au_branch *br __maybe_unused,
17444 + int perm __maybe_unused)
17445 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17446 + int perm __maybe_unused)
17447 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17448 +AuStubInt0(__init au_hnotify_init, void)
17449 +AuStubVoid(au_hnotify_fin, void)
17450 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17451 +#endif /* CONFIG_AUFS_HNOTIFY */
17453 +static inline void au_hn_suspend(struct au_hinode *hdir)
17455 + au_hn_ctl(hdir, /*do_set*/0);
17458 +static inline void au_hn_resume(struct au_hinode *hdir)
17460 + au_hn_ctl(hdir, /*do_set*/1);
17463 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17465 + inode_lock(hdir->hi_inode);
17466 + au_hn_suspend(hdir);
17469 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17470 + unsigned int sc __maybe_unused)
17472 + inode_lock_nested(hdir->hi_inode, sc);
17473 + au_hn_suspend(hdir);
17476 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17478 + au_hn_resume(hdir);
17479 + inode_unlock(hdir->hi_inode);
17482 +#endif /* __KERNEL__ */
17483 +#endif /* __AUFS_INODE_H__ */
17484 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17485 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17486 +++ linux/fs/aufs/ioctl.c 2017-07-29 12:14:25.903042072 +0200
17489 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17491 + * This program, aufs is free software; you can redistribute it and/or modify
17492 + * it under the terms of the GNU General Public License as published by
17493 + * the Free Software Foundation; either version 2 of the License, or
17494 + * (at your option) any later version.
17496 + * This program is distributed in the hope that it will be useful,
17497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17499 + * GNU General Public License for more details.
17501 + * You should have received a copy of the GNU General Public License
17502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17507 + * plink-management and readdir in userspace.
17508 + * assist the pathconf(3) wrapper library.
17510 + * File-based Hierarchical Storage Management.
17513 +#include <linux/compat.h>
17514 +#include <linux/file.h>
17517 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17520 + aufs_bindex_t wbi, bindex, bbot;
17521 + struct file *h_file;
17522 + struct super_block *sb;
17523 + struct dentry *root;
17524 + struct au_branch *br;
17525 + struct aufs_wbr_fd wbrfd = {
17526 + .oflags = au_dir_roflags,
17529 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17530 + | O_NOATIME | O_CLOEXEC;
17532 + AuDebugOn(wbrfd.oflags & ~valid);
17535 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17536 + if (unlikely(err)) {
17542 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17543 + wbrfd.oflags |= au_dir_roflags;
17544 + AuDbg("0%o\n", wbrfd.oflags);
17545 + if (unlikely(wbrfd.oflags & ~valid))
17549 + fd = get_unused_fd_flags(0);
17551 + if (unlikely(fd < 0))
17554 + h_file = ERR_PTR(-EINVAL);
17557 + sb = path->dentry->d_sb;
17558 + root = sb->s_root;
17559 + aufs_read_lock(root, AuLock_IR);
17560 + bbot = au_sbbot(sb);
17561 + if (wbrfd.brid >= 0) {
17562 + wbi = au_br_index(sb, wbrfd.brid);
17563 + if (unlikely(wbi < 0 || wbi > bbot))
17567 + h_file = ERR_PTR(-ENOENT);
17568 + br = au_sbr(sb, wbi);
17569 + if (!au_br_writable(br->br_perm)) {
17573 + bindex = wbi + 1;
17575 + for (; bindex <= bbot; bindex++) {
17576 + br = au_sbr(sb, bindex);
17577 + if (au_br_writable(br->br_perm)) {
17579 + br = au_sbr(sb, wbi);
17584 + AuDbg("wbi %d\n", wbi);
17586 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17590 + aufs_read_unlock(root, AuLock_IR);
17591 + err = PTR_ERR(h_file);
17592 + if (IS_ERR(h_file))
17595 + au_br_put(br); /* cf. au_h_open() */
17596 + fd_install(fd, h_file);
17598 + goto out; /* success */
17601 + put_unused_fd(fd);
17607 +/* ---------------------------------------------------------------------- */
17609 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17612 + struct dentry *dentry;
17615 + case AUFS_CTL_RDU:
17616 + case AUFS_CTL_RDU_INO:
17617 + err = au_rdu_ioctl(file, cmd, arg);
17620 + case AUFS_CTL_WBR_FD:
17621 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17624 + case AUFS_CTL_IBUSY:
17625 + err = au_ibusy_ioctl(file, arg);
17628 + case AUFS_CTL_BRINFO:
17629 + err = au_brinfo_ioctl(file, arg);
17632 + case AUFS_CTL_FHSM_FD:
17633 + dentry = file->f_path.dentry;
17634 + if (IS_ROOT(dentry))
17635 + err = au_fhsm_fd(dentry->d_sb, arg);
17641 + /* do not call the lower */
17642 + AuDbg("0x%x\n", cmd);
17650 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17655 + case AUFS_CTL_MVDOWN:
17656 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17659 + case AUFS_CTL_WBR_FD:
17660 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17664 + /* do not call the lower */
17665 + AuDbg("0x%x\n", cmd);
17673 +#ifdef CONFIG_COMPAT
17674 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17675 + unsigned long arg)
17680 + case AUFS_CTL_RDU:
17681 + case AUFS_CTL_RDU_INO:
17682 + err = au_rdu_compat_ioctl(file, cmd, arg);
17685 + case AUFS_CTL_IBUSY:
17686 + err = au_ibusy_compat_ioctl(file, arg);
17689 + case AUFS_CTL_BRINFO:
17690 + err = au_brinfo_compat_ioctl(file, arg);
17694 + err = aufs_ioctl_dir(file, cmd, arg);
17701 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17702 + unsigned long arg)
17704 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17707 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17708 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17709 +++ linux/fs/aufs/i_op_add.c 2017-07-29 12:14:25.903042072 +0200
17712 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17714 + * This program, aufs is free software; you can redistribute it and/or modify
17715 + * it under the terms of the GNU General Public License as published by
17716 + * the Free Software Foundation; either version 2 of the License, or
17717 + * (at your option) any later version.
17719 + * This program is distributed in the hope that it will be useful,
17720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17722 + * GNU General Public License for more details.
17724 + * You should have received a copy of the GNU General Public License
17725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17729 + * inode operations (add entry)
17735 + * final procedure of adding a new entry, except link(2).
17736 + * remove whiteout, instantiate, copyup the parent dir's times and size
17737 + * and update version.
17738 + * if it failed, re-create the removed whiteout.
17740 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17741 + struct dentry *wh_dentry, struct dentry *dentry)
17744 + aufs_bindex_t bwh;
17745 + struct path h_path;
17746 + struct super_block *sb;
17747 + struct inode *inode, *h_dir;
17748 + struct dentry *wh;
17753 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17754 + IMustLock(h_dir);
17755 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17756 + bwh = au_dbwh(dentry);
17757 + h_path.dentry = wh_dentry;
17758 + h_path.mnt = au_sbr_mnt(sb, bindex);
17759 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17761 + if (unlikely(err))
17765 + inode = au_new_inode(dentry, /*must_new*/1);
17766 + if (!IS_ERR(inode)) {
17767 + d_instantiate(dentry, inode);
17768 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17770 + au_dir_ts(dir, bindex);
17771 + dir->i_version++;
17772 + au_fhsm_wrote(sb, bindex, /*force*/0);
17773 + return 0; /* success */
17776 + err = PTR_ERR(inode);
17781 + /* dir inode is locked */
17782 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17783 + rerr = PTR_ERR(wh);
17784 + if (IS_ERR(wh)) {
17785 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17786 + dentry, err, rerr);
17795 +static int au_d_may_add(struct dentry *dentry)
17800 + if (unlikely(d_unhashed(dentry)))
17802 + if (unlikely(d_really_is_positive(dentry)))
17808 + * simple tests for the adding inode operations.
17809 + * following the checks in vfs, plus the parent-child relationship.
17811 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17812 + struct dentry *h_parent, int isdir)
17816 + struct dentry *h_dentry;
17817 + struct inode *h_inode;
17819 + err = -ENAMETOOLONG;
17820 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17823 + h_dentry = au_h_dptr(dentry, bindex);
17824 + if (d_really_is_negative(dentry)) {
17826 + if (unlikely(d_is_positive(h_dentry)))
17829 + /* rename(2) case */
17831 + if (unlikely(d_is_negative(h_dentry)))
17833 + h_inode = d_inode(h_dentry);
17834 + if (unlikely(!h_inode->i_nlink))
17837 + h_mode = h_inode->i_mode;
17840 + if (unlikely(S_ISDIR(h_mode)))
17842 + } else if (unlikely(!S_ISDIR(h_mode))) {
17849 + /* expected parent dir is locked */
17850 + if (unlikely(h_parent != h_dentry->d_parent))
17859 + * initial procedure of adding a new entry.
17860 + * prepare writable branch and the parent dir, lock it,
17861 + * and lookup whiteout for the new entry.
17863 +static struct dentry*
17864 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17865 + struct dentry *src_dentry, struct au_pin *pin,
17866 + struct au_wr_dir_args *wr_dir_args)
17868 + struct dentry *wh_dentry, *h_parent;
17869 + struct super_block *sb;
17870 + struct au_branch *br;
17872 + unsigned int udba;
17873 + aufs_bindex_t bcpup;
17875 + AuDbg("%pd\n", dentry);
17877 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17879 + wh_dentry = ERR_PTR(err);
17880 + if (unlikely(err < 0))
17883 + sb = dentry->d_sb;
17884 + udba = au_opt_udba(sb);
17885 + err = au_pin(pin, dentry, bcpup, udba,
17886 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17887 + wh_dentry = ERR_PTR(err);
17888 + if (unlikely(err))
17891 + h_parent = au_pinned_h_parent(pin);
17892 + if (udba != AuOpt_UDBA_NONE
17893 + && au_dbtop(dentry) == bcpup)
17894 + err = au_may_add(dentry, bcpup, h_parent,
17895 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17896 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17897 + err = -ENAMETOOLONG;
17898 + wh_dentry = ERR_PTR(err);
17899 + if (unlikely(err))
17902 + br = au_sbr(sb, bcpup);
17904 + struct path tmp = {
17905 + .dentry = h_parent,
17906 + .mnt = au_br_mnt(br)
17908 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17911 + wh_dentry = NULL;
17912 + if (bcpup != au_dbwh(dentry))
17913 + goto out; /* success */
17916 + * ENAMETOOLONG here means that if we allowed create such name, then it
17917 + * would not be able to removed in the future. So we don't allow such
17918 + * name here and we don't handle ENAMETOOLONG differently here.
17920 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17923 + if (IS_ERR(wh_dentry))
17926 + return wh_dentry;
17929 +/* ---------------------------------------------------------------------- */
17931 +enum { Mknod, Symlink, Creat };
17932 +struct simple_arg {
17939 + struct vfsub_aopen_args *aopen;
17942 + const char *symname;
17951 +static int add_simple(struct inode *dir, struct dentry *dentry,
17952 + struct simple_arg *arg)
17955 + aufs_bindex_t btop;
17956 + unsigned char created;
17957 + const unsigned char try_aopen
17958 + = (arg->type == Creat && arg->u.c.try_aopen);
17959 + struct dentry *wh_dentry, *parent;
17960 + struct inode *h_dir;
17961 + struct super_block *sb;
17962 + struct au_branch *br;
17963 + /* to reuduce stack size */
17965 + struct au_dtime dt;
17966 + struct au_pin pin;
17967 + struct path h_path;
17968 + struct au_wr_dir_args wr_dir_args;
17971 + AuDbg("%pd\n", dentry);
17975 + a = kmalloc(sizeof(*a), GFP_NOFS);
17976 + if (unlikely(!a))
17978 + a->wr_dir_args.force_btgt = -1;
17979 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17981 + parent = dentry->d_parent; /* dir inode is locked */
17982 + if (!try_aopen) {
17983 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17984 + if (unlikely(err))
17987 + err = au_d_may_add(dentry);
17988 + if (unlikely(err))
17991 + di_write_lock_parent(parent);
17992 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17993 + &a->pin, &a->wr_dir_args);
17994 + err = PTR_ERR(wh_dentry);
17995 + if (IS_ERR(wh_dentry))
17998 + btop = au_dbtop(dentry);
17999 + sb = dentry->d_sb;
18000 + br = au_sbr(sb, btop);
18001 + a->h_path.dentry = au_h_dptr(dentry, btop);
18002 + a->h_path.mnt = au_br_mnt(br);
18003 + h_dir = au_pinned_h_dir(&a->pin);
18004 + switch (arg->type) {
18007 + if (!try_aopen || !h_dir->i_op->atomic_open)
18008 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
18009 + arg->u.c.want_excl);
18011 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
18012 + arg->u.c.aopen, br);
18015 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
18018 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
18026 + err = epilog(dir, btop, wh_dentry, dentry);
18029 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
18030 + /* no delegation since it is just created */
18031 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
18034 + AuIOErr("%pd revert failure(%d, %d)\n",
18035 + dentry, err, rerr);
18038 + au_dtime_revert(&a->dt);
18041 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
18042 + *arg->u.c.aopen->opened |= FILE_CREATED;
18044 + au_unpin(&a->pin);
18049 + di_write_unlock(parent);
18051 + if (unlikely(err)) {
18052 + au_update_dbtop(dentry);
18056 + aufs_read_unlock(dentry, AuLock_DW);
18063 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18066 + struct simple_arg arg = {
18073 + return add_simple(dir, dentry, &arg);
18076 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
18078 + struct simple_arg arg = {
18080 + .u.s.symname = symname
18082 + return add_simple(dir, dentry, &arg);
18085 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18088 + struct simple_arg arg = {
18092 + .want_excl = want_excl
18095 + return add_simple(dir, dentry, &arg);
18098 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18099 + struct vfsub_aopen_args *aopen_args)
18101 + struct simple_arg arg = {
18104 + .mode = aopen_args->create_mode,
18105 + .want_excl = aopen_args->open_flag & O_EXCL,
18106 + .try_aopen = true,
18107 + .aopen = aopen_args
18110 + return add_simple(dir, dentry, &arg);
18113 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
18116 + aufs_bindex_t bindex;
18117 + struct super_block *sb;
18118 + struct dentry *parent, *h_parent, *h_dentry;
18119 + struct inode *h_dir, *inode;
18120 + struct vfsmount *h_mnt;
18121 + struct au_wr_dir_args wr_dir_args = {
18122 + .force_btgt = -1,
18123 + .flags = AuWrDir_TMPFILE
18126 + /* copy-up may happen */
18130 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18131 + if (unlikely(err))
18134 + err = au_di_init(dentry);
18135 + if (unlikely(err))
18139 + parent = d_find_any_alias(dir);
18140 + AuDebugOn(!parent);
18141 + di_write_lock_parent(parent);
18142 + if (unlikely(d_inode(parent) != dir))
18145 + err = au_digen_test(parent, au_sigen(sb));
18146 + if (unlikely(err))
18149 + bindex = au_dbtop(parent);
18150 + au_set_dbtop(dentry, bindex);
18151 + au_set_dbbot(dentry, bindex);
18152 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18154 + if (unlikely(err < 0))
18157 + err = -EOPNOTSUPP;
18158 + h_dir = au_h_iptr(dir, bindex);
18159 + if (unlikely(!h_dir->i_op->tmpfile))
18162 + h_mnt = au_sbr_mnt(sb, bindex);
18163 + err = vfsub_mnt_want_write(h_mnt);
18164 + if (unlikely(err))
18167 + h_parent = au_h_dptr(parent, bindex);
18168 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
18169 + if (IS_ERR(h_dentry)) {
18170 + err = PTR_ERR(h_dentry);
18174 + au_set_dbtop(dentry, bindex);
18175 + au_set_dbbot(dentry, bindex);
18176 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18177 + inode = au_new_inode(dentry, /*must_new*/1);
18178 + if (IS_ERR(inode)) {
18179 + err = PTR_ERR(inode);
18180 + au_set_h_dptr(dentry, bindex, NULL);
18181 + au_set_dbtop(dentry, -1);
18182 + au_set_dbbot(dentry, -1);
18184 + if (!inode->i_nlink)
18185 + set_nlink(inode, 1);
18186 + d_tmpfile(dentry, inode);
18187 + au_di(dentry)->di_tmpfile = 1;
18189 + /* update without i_mutex */
18190 + if (au_ibtop(dir) == au_dbtop(dentry))
18191 + au_cpup_attr_timesizes(dir);
18196 + vfsub_mnt_drop_write(h_mnt);
18198 + di_write_unlock(parent);
18200 + di_write_unlock(dentry);
18201 + if (unlikely(err)) {
18202 + au_di_fin(dentry);
18203 + dentry->d_fsdata = NULL;
18206 + si_read_unlock(sb);
18208 + inode_unlock(dir);
18212 +/* ---------------------------------------------------------------------- */
18214 +struct au_link_args {
18215 + aufs_bindex_t bdst, bsrc;
18216 + struct au_pin pin;
18217 + struct path h_path;
18218 + struct dentry *src_parent, *parent;
18221 +static int au_cpup_before_link(struct dentry *src_dentry,
18222 + struct au_link_args *a)
18225 + struct dentry *h_src_dentry;
18226 + struct au_cp_generic cpg = {
18227 + .dentry = src_dentry,
18232 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18235 + di_read_lock_parent(a->src_parent, AuLock_IR);
18236 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18237 + if (unlikely(err))
18240 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18241 + err = au_pin(&a->pin, src_dentry, a->bdst,
18242 + au_opt_udba(src_dentry->d_sb),
18243 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18244 + if (unlikely(err))
18247 + err = au_sio_cpup_simple(&cpg);
18248 + au_unpin(&a->pin);
18251 + di_read_unlock(a->src_parent, AuLock_IR);
18255 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18256 + struct au_link_args *a)
18259 + unsigned char plink;
18260 + aufs_bindex_t bbot;
18261 + struct dentry *h_src_dentry;
18262 + struct inode *h_inode, *inode, *delegated;
18263 + struct super_block *sb;
18264 + struct file *h_file;
18268 + sb = src_dentry->d_sb;
18269 + inode = d_inode(src_dentry);
18270 + if (au_ibtop(inode) <= a->bdst)
18271 + h_inode = au_h_iptr(inode, a->bdst);
18272 + if (!h_inode || !h_inode->i_nlink) {
18273 + /* copyup src_dentry as the name of dentry. */
18274 + bbot = au_dbbot(dentry);
18275 + if (bbot < a->bsrc)
18276 + au_set_dbbot(dentry, a->bsrc);
18277 + au_set_h_dptr(dentry, a->bsrc,
18278 + dget(au_h_dptr(src_dentry, a->bsrc)));
18279 + dget(a->h_path.dentry);
18280 + au_set_h_dptr(dentry, a->bdst, NULL);
18281 + AuDbg("temporary d_inode...\n");
18282 + spin_lock(&dentry->d_lock);
18283 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18284 + spin_unlock(&dentry->d_lock);
18285 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18286 + if (IS_ERR(h_file))
18287 + err = PTR_ERR(h_file);
18289 + struct au_cp_generic cpg = {
18290 + .dentry = dentry,
18295 + .flags = AuCpup_KEEPLINO
18297 + err = au_sio_cpup_simple(&cpg);
18298 + au_h_open_post(dentry, a->bsrc, h_file);
18300 + dput(a->h_path.dentry);
18301 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18303 + au_set_h_dptr(dentry, a->bdst,
18304 + a->h_path.dentry);
18306 + spin_lock(&dentry->d_lock);
18307 + dentry->d_inode = NULL; /* restore */
18308 + spin_unlock(&dentry->d_lock);
18309 + AuDbg("temporary d_inode...done\n");
18310 + au_set_h_dptr(dentry, a->bsrc, NULL);
18311 + au_set_dbbot(dentry, bbot);
18313 + /* the inode of src_dentry already exists on a.bdst branch */
18314 + h_src_dentry = d_find_alias(h_inode);
18315 + if (!h_src_dentry && au_plink_test(inode)) {
18317 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18318 + err = PTR_ERR(h_src_dentry);
18319 + if (IS_ERR(h_src_dentry))
18322 + if (unlikely(d_is_negative(h_src_dentry))) {
18323 + dput(h_src_dentry);
18324 + h_src_dentry = NULL;
18328 + if (h_src_dentry) {
18329 + delegated = NULL;
18330 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18331 + &a->h_path, &delegated);
18332 + if (unlikely(err == -EWOULDBLOCK)) {
18333 + pr_warn("cannot retry for NFSv4 delegation"
18334 + " for an internal link\n");
18337 + dput(h_src_dentry);
18339 + AuIOErr("no dentry found for hi%lu on b%d\n",
18340 + h_inode->i_ino, a->bdst);
18345 + if (!err && !plink)
18346 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18353 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18354 + struct dentry *dentry)
18357 + struct au_dtime dt;
18358 + struct au_link_args *a;
18359 + struct dentry *wh_dentry, *h_src_dentry;
18360 + struct inode *inode, *delegated;
18361 + struct super_block *sb;
18362 + struct au_wr_dir_args wr_dir_args = {
18363 + /* .force_btgt = -1, */
18364 + .flags = AuWrDir_ADD_ENTRY
18368 + inode = d_inode(src_dentry);
18369 + IMustLock(inode);
18372 + a = kzalloc(sizeof(*a), GFP_NOFS);
18373 + if (unlikely(!a))
18376 + a->parent = dentry->d_parent; /* dir inode is locked */
18377 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18378 + AuLock_NOPLM | AuLock_GEN);
18379 + if (unlikely(err))
18381 + err = au_d_linkable(src_dentry);
18382 + if (unlikely(err))
18384 + err = au_d_may_add(dentry);
18385 + if (unlikely(err))
18388 + a->src_parent = dget_parent(src_dentry);
18389 + wr_dir_args.force_btgt = au_ibtop(inode);
18391 + di_write_lock_parent(a->parent);
18392 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18393 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18395 + err = PTR_ERR(wh_dentry);
18396 + if (IS_ERR(wh_dentry))
18400 + sb = dentry->d_sb;
18401 + a->bdst = au_dbtop(dentry);
18402 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18403 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18404 + a->bsrc = au_ibtop(inode);
18405 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18406 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18407 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18408 + if (!h_src_dentry) {
18409 + a->bsrc = au_dbtop(src_dentry);
18410 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18411 + AuDebugOn(!h_src_dentry);
18412 + } else if (IS_ERR(h_src_dentry)) {
18413 + err = PTR_ERR(h_src_dentry);
18418 + * aufs doesn't touch the credential so
18419 + * security_dentry_create_files_as() is unnecrssary.
18421 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18422 + if (a->bdst < a->bsrc
18423 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18424 + err = au_cpup_or_link(src_dentry, dentry, a);
18426 + delegated = NULL;
18427 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18428 + &a->h_path, &delegated);
18429 + if (unlikely(err == -EWOULDBLOCK)) {
18430 + pr_warn("cannot retry for NFSv4 delegation"
18431 + " for an internal link\n");
18435 + dput(h_src_dentry);
18438 + * copyup src_dentry to the branch we process,
18439 + * and then link(2) to it.
18441 + dput(h_src_dentry);
18442 + if (a->bdst < a->bsrc
18443 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18444 + au_unpin(&a->pin);
18445 + di_write_unlock(a->parent);
18446 + err = au_cpup_before_link(src_dentry, a);
18447 + di_write_lock_parent(a->parent);
18449 + err = au_pin(&a->pin, dentry, a->bdst,
18451 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18452 + if (unlikely(err))
18456 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18458 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18459 + delegated = NULL;
18460 + err = vfsub_link(h_src_dentry,
18461 + au_pinned_h_dir(&a->pin),
18462 + &a->h_path, &delegated);
18463 + if (unlikely(err == -EWOULDBLOCK)) {
18464 + pr_warn("cannot retry"
18465 + " for NFSv4 delegation"
18466 + " for an internal link\n");
18472 + if (unlikely(err))
18476 + a->h_path.dentry = wh_dentry;
18477 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18479 + if (unlikely(err))
18483 + au_dir_ts(dir, a->bdst);
18484 + dir->i_version++;
18485 + inc_nlink(inode);
18486 + inode->i_ctime = dir->i_ctime;
18487 + d_instantiate(dentry, au_igrab(inode));
18488 + if (d_unhashed(a->h_path.dentry))
18489 + /* some filesystem calls d_drop() */
18491 + /* some filesystems consume an inode even hardlink */
18492 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18493 + goto out_unpin; /* success */
18496 + /* no delegation since it is just created */
18497 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18498 + /*delegated*/NULL, /*force*/0);
18499 + if (unlikely(rerr)) {
18500 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18503 + au_dtime_revert(&dt);
18505 + au_unpin(&a->pin);
18509 + di_write_unlock(a->parent);
18510 + dput(a->src_parent);
18512 + if (unlikely(err)) {
18513 + au_update_dbtop(dentry);
18516 + aufs_read_and_write_unlock2(dentry, src_dentry);
18524 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18527 + aufs_bindex_t bindex;
18528 + unsigned char diropq;
18529 + struct path h_path;
18530 + struct dentry *wh_dentry, *parent, *opq_dentry;
18531 + struct inode *h_inode;
18532 + struct super_block *sb;
18534 + struct au_pin pin;
18535 + struct au_dtime dt;
18536 + } *a; /* reduce the stack usage */
18537 + struct au_wr_dir_args wr_dir_args = {
18538 + .force_btgt = -1,
18539 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18545 + a = kmalloc(sizeof(*a), GFP_NOFS);
18546 + if (unlikely(!a))
18549 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18550 + if (unlikely(err))
18552 + err = au_d_may_add(dentry);
18553 + if (unlikely(err))
18556 + parent = dentry->d_parent; /* dir inode is locked */
18557 + di_write_lock_parent(parent);
18558 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18559 + &a->pin, &wr_dir_args);
18560 + err = PTR_ERR(wh_dentry);
18561 + if (IS_ERR(wh_dentry))
18564 + sb = dentry->d_sb;
18565 + bindex = au_dbtop(dentry);
18566 + h_path.dentry = au_h_dptr(dentry, bindex);
18567 + h_path.mnt = au_sbr_mnt(sb, bindex);
18568 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18569 + if (unlikely(err))
18572 + /* make the dir opaque */
18574 + h_inode = d_inode(h_path.dentry);
18576 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18577 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18578 + opq_dentry = au_diropq_create(dentry, bindex);
18579 + inode_unlock(h_inode);
18580 + err = PTR_ERR(opq_dentry);
18581 + if (IS_ERR(opq_dentry))
18583 + dput(opq_dentry);
18587 + err = epilog(dir, bindex, wh_dentry, dentry);
18590 + goto out_unpin; /* success */
18595 + AuLabel(revert opq);
18596 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18597 + rerr = au_diropq_remove(dentry, bindex);
18598 + inode_unlock(h_inode);
18600 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18601 + dentry, err, rerr);
18607 + AuLabel(revert dir);
18608 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18610 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18611 + dentry, err, rerr);
18614 + au_dtime_revert(&a->dt);
18616 + au_unpin(&a->pin);
18619 + di_write_unlock(parent);
18621 + if (unlikely(err)) {
18622 + au_update_dbtop(dentry);
18625 + aufs_read_unlock(dentry, AuLock_DW);
18631 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18632 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18633 +++ linux/fs/aufs/i_op.c 2017-07-29 12:14:25.903042072 +0200
18636 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18638 + * This program, aufs is free software; you can redistribute it and/or modify
18639 + * it under the terms of the GNU General Public License as published by
18640 + * the Free Software Foundation; either version 2 of the License, or
18641 + * (at your option) any later version.
18643 + * This program is distributed in the hope that it will be useful,
18644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18646 + * GNU General Public License for more details.
18648 + * You should have received a copy of the GNU General Public License
18649 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18653 + * inode operations (except add/del/rename)
18656 +#include <linux/device_cgroup.h>
18657 +#include <linux/fs_stack.h>
18658 +#include <linux/namei.h>
18659 +#include <linux/security.h>
18662 +static int h_permission(struct inode *h_inode, int mask,
18663 + struct path *h_path, int brperm)
18666 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18669 + if (write_mask && IS_IMMUTABLE(h_inode))
18673 + if (((mask & MAY_EXEC)
18674 + && S_ISREG(h_inode->i_mode)
18675 + && (path_noexec(h_path)
18676 + || !(h_inode->i_mode & S_IXUGO))))
18680 + * - skip the lower fs test in the case of write to ro branch.
18681 + * - nfs dir permission write check is optimized, but a policy for
18682 + * link/rename requires a real check.
18683 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18684 + * in this case, generic_permission() returns -EOPNOTSUPP.
18686 + if ((write_mask && !au_br_writable(brperm))
18687 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18688 + && write_mask && !(mask & MAY_READ))
18689 + || !h_inode->i_op->permission) {
18690 + /* AuLabel(generic_permission); */
18691 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18692 + err = generic_permission(h_inode, mask);
18693 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18694 + err = h_inode->i_op->permission(h_inode, mask);
18697 + /* AuLabel(h_inode->permission); */
18698 + err = h_inode->i_op->permission(h_inode, mask);
18703 + err = devcgroup_inode_permission(h_inode, mask);
18705 + err = security_inode_permission(h_inode, mask);
18709 + /* todo: do we need to call ima_path_check()? */
18710 + struct path h_path = {
18714 + err = ima_path_check(&h_path,
18715 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18716 + IMA_COUNT_LEAVE);
18724 +static int aufs_permission(struct inode *inode, int mask)
18727 + aufs_bindex_t bindex, bbot;
18728 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18729 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18730 + struct inode *h_inode;
18731 + struct super_block *sb;
18732 + struct au_branch *br;
18734 + /* todo: support rcu-walk? */
18735 + if (mask & MAY_NOT_BLOCK)
18738 + sb = inode->i_sb;
18739 + si_read_lock(sb, AuLock_FLUSH);
18740 + ii_read_lock_child(inode);
18742 + err = au_iigen_test(inode, au_sigen(sb));
18743 + if (unlikely(err))
18749 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18750 + err = au_busy_or_stale();
18751 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18752 + if (unlikely(!h_inode
18753 + || (h_inode->i_mode & S_IFMT)
18754 + != (inode->i_mode & S_IFMT)))
18758 + bindex = au_ibtop(inode);
18759 + br = au_sbr(sb, bindex);
18760 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18763 + && !special_file(h_inode->i_mode)) {
18764 + /* test whether the upper writable branch exists */
18766 + for (; bindex >= 0; bindex--)
18767 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18775 + /* non-write to dir */
18777 + bbot = au_ibbot(inode);
18778 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18779 + h_inode = au_h_iptr(inode, bindex);
18781 + err = au_busy_or_stale();
18782 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18785 + br = au_sbr(sb, bindex);
18786 + err = h_permission(h_inode, mask, &br->br_path,
18792 + ii_read_unlock(inode);
18793 + si_read_unlock(sb);
18797 +/* ---------------------------------------------------------------------- */
18799 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18800 + unsigned int flags)
18802 + struct dentry *ret, *parent;
18803 + struct inode *inode;
18804 + struct super_block *sb;
18805 + int err, npositive;
18809 + /* todo: support rcu-walk? */
18810 + ret = ERR_PTR(-ECHILD);
18811 + if (flags & LOOKUP_RCU)
18814 + ret = ERR_PTR(-ENAMETOOLONG);
18815 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18819 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18820 + ret = ERR_PTR(err);
18821 + if (unlikely(err))
18824 + err = au_di_init(dentry);
18825 + ret = ERR_PTR(err);
18826 + if (unlikely(err))
18830 + npositive = 0; /* suppress a warning */
18831 + parent = dentry->d_parent; /* dir inode is locked */
18832 + di_read_lock_parent(parent, AuLock_IR);
18833 + err = au_alive_dir(parent);
18835 + err = au_digen_test(parent, au_sigen(sb));
18837 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18838 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18839 + AuLkup_ALLOW_NEG);
18842 + di_read_unlock(parent, AuLock_IR);
18843 + ret = ERR_PTR(err);
18844 + if (unlikely(err < 0))
18848 + inode = au_new_inode(dentry, /*must_new*/0);
18849 + if (IS_ERR(inode)) {
18850 + ret = (void *)inode;
18857 + atomic_inc(&inode->i_count);
18858 + ret = d_splice_alias(inode, dentry);
18860 + if (unlikely(d_need_lookup(dentry))) {
18861 + spin_lock(&dentry->d_lock);
18862 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18863 + spin_unlock(&dentry->d_lock);
18867 + if (!IS_ERR(ret)) {
18869 + if (ret && ret != dentry)
18870 + ii_write_unlock(inode);
18872 + ii_write_unlock(inode);
18879 + di_write_unlock(dentry);
18881 + si_read_unlock(sb);
18886 +/* ---------------------------------------------------------------------- */
18888 +struct aopen_node {
18889 + struct hlist_node hlist;
18890 + struct file *file, *h_file;
18893 +static int au_do_aopen(struct inode *inode, struct file *file)
18895 + struct au_sphlhead *aopen;
18896 + struct aopen_node *node;
18897 + struct au_do_open_args args = {
18899 + .open = au_do_open_nondir
18902 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18903 + spin_lock(&aopen->spin);
18904 + hlist_for_each_entry(node, &aopen->head, hlist)
18905 + if (node->file == file) {
18906 + args.h_file = node->h_file;
18909 + spin_unlock(&aopen->spin);
18910 + /* AuDebugOn(!args.h_file); */
18912 + return au_do_open(file, &args);
18915 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18916 + struct file *file, unsigned int open_flag,
18917 + umode_t create_mode, int *opened)
18919 + int err, h_opened = *opened;
18920 + unsigned int lkup_flags;
18921 + struct dentry *parent, *d;
18922 + struct au_sphlhead *aopen;
18923 + struct vfsub_aopen_args args = {
18924 + .open_flag = open_flag,
18925 + .create_mode = create_mode,
18926 + .opened = &h_opened
18928 + struct aopen_node aopen_node = {
18933 + AuDbg("open_flag 0%o\n", open_flag);
18934 + AuDbgDentry(dentry);
18937 + if (!au_di(dentry)) {
18938 + lkup_flags = LOOKUP_OPEN;
18939 + if (open_flag & O_CREAT)
18940 + lkup_flags |= LOOKUP_CREATE;
18941 + d = aufs_lookup(dir, dentry, lkup_flags);
18943 + err = PTR_ERR(d);
18948 + * obsoleted dentry found.
18949 + * another error will be returned later.
18955 + AuDbgDentry(dentry);
18958 + if (d_is_positive(dentry)
18959 + || d_unhashed(dentry)
18960 + || d_unlinked(dentry)
18961 + || !(open_flag & O_CREAT))
18962 + goto out_no_open;
18964 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18965 + if (unlikely(err))
18968 + parent = dentry->d_parent; /* dir is locked */
18969 + di_write_lock_parent(parent);
18970 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18971 + if (unlikely(err))
18974 + AuDbgDentry(dentry);
18975 + if (d_is_positive(dentry))
18978 + args.file = get_empty_filp();
18979 + err = PTR_ERR(args.file);
18980 + if (IS_ERR(args.file))
18983 + args.file->f_flags = file->f_flags;
18984 + err = au_aopen_or_create(dir, dentry, &args);
18986 + AuDbgFile(args.file);
18987 + if (unlikely(err < 0)) {
18988 + if (h_opened & FILE_OPENED)
18991 + put_filp(args.file);
18995 + /* some filesystems don't set FILE_CREATED while succeeded? */
18996 + *opened |= FILE_CREATED;
18997 + if (h_opened & FILE_OPENED)
18998 + aopen_node.h_file = args.file;
19000 + put_filp(args.file);
19001 + args.file = NULL;
19003 + aopen = &au_sbi(dir->i_sb)->si_aopen;
19004 + au_sphl_add(&aopen_node.hlist, aopen);
19005 + err = finish_open(file, dentry, au_do_aopen, opened);
19006 + au_sphl_del(&aopen_node.hlist, aopen);
19009 + if (aopen_node.h_file)
19010 + fput(aopen_node.h_file);
19013 + di_write_unlock(parent);
19014 + aufs_read_unlock(dentry, AuLock_DW);
19015 + AuDbgDentry(dentry);
19016 + if (unlikely(err < 0))
19019 + if (err >= 0 && !(*opened & FILE_CREATED)) {
19020 + AuLabel(out_no_open);
19022 + err = finish_no_open(file, dentry);
19025 + AuDbg("%pd%s%s\n", dentry,
19026 + (*opened & FILE_CREATED) ? " created" : "",
19027 + (*opened & FILE_OPENED) ? " opened" : "");
19033 +/* ---------------------------------------------------------------------- */
19035 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
19036 + const unsigned char add_entry, aufs_bindex_t bcpup,
19037 + aufs_bindex_t btop)
19040 + struct dentry *h_parent;
19041 + struct inode *h_dir;
19044 + IMustLock(d_inode(parent));
19046 + di_write_lock_parent(parent);
19049 + if (!au_h_dptr(parent, bcpup)) {
19050 + if (btop > bcpup)
19051 + err = au_cpup_dirs(dentry, bcpup);
19052 + else if (btop < bcpup)
19053 + err = au_cpdown_dirs(dentry, bcpup);
19057 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
19058 + h_parent = au_h_dptr(parent, bcpup);
19059 + h_dir = d_inode(h_parent);
19060 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
19061 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
19062 + /* todo: no unlock here */
19063 + inode_unlock(h_dir);
19065 + AuDbg("bcpup %d\n", bcpup);
19067 + if (d_really_is_negative(dentry))
19068 + au_set_h_dptr(dentry, btop, NULL);
19069 + au_update_dbrange(dentry, /*do_put_zero*/0);
19074 + di_write_unlock(parent);
19076 + err = bcpup; /* success */
19083 + * decide the branch and the parent dir where we will create a new entry.
19084 + * returns new bindex or an error.
19085 + * copyup the parent dir if needed.
19087 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19088 + struct au_wr_dir_args *args)
19091 + unsigned int flags;
19092 + aufs_bindex_t bcpup, btop, src_btop;
19093 + const unsigned char add_entry
19094 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
19095 + | au_ftest_wrdir(args->flags, TMPFILE);
19096 + struct super_block *sb;
19097 + struct dentry *parent;
19098 + struct au_sbinfo *sbinfo;
19100 + sb = dentry->d_sb;
19101 + sbinfo = au_sbi(sb);
19102 + parent = dget_parent(dentry);
19103 + btop = au_dbtop(dentry);
19105 + if (args->force_btgt < 0) {
19106 + if (src_dentry) {
19107 + src_btop = au_dbtop(src_dentry);
19108 + if (src_btop < btop)
19109 + bcpup = src_btop;
19110 + } else if (add_entry) {
19112 + if (au_ftest_wrdir(args->flags, ISDIR))
19113 + au_fset_wbr(flags, DIR);
19114 + err = AuWbrCreate(sbinfo, dentry, flags);
19118 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
19120 + err = AuWbrCopyup(sbinfo, dentry);
19122 + if (!IS_ROOT(dentry)) {
19123 + di_read_lock_parent(parent, !AuLock_IR);
19124 + err = AuWbrCopyup(sbinfo, dentry);
19125 + di_read_unlock(parent, !AuLock_IR);
19127 + err = AuWbrCopyup(sbinfo, dentry);
19130 + if (unlikely(err < 0))
19134 + bcpup = args->force_btgt;
19135 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
19138 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
19140 + if (bcpup == btop)
19141 + goto out; /* success */
19143 + /* copyup the new parent into the branch we process */
19144 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
19146 + if (d_really_is_negative(dentry)) {
19147 + au_set_h_dptr(dentry, btop, NULL);
19148 + au_set_dbtop(dentry, bcpup);
19149 + au_set_dbbot(dentry, bcpup);
19151 + AuDebugOn(add_entry
19152 + && !au_ftest_wrdir(args->flags, TMPFILE)
19153 + && !au_h_dptr(dentry, bcpup));
19161 +/* ---------------------------------------------------------------------- */
19163 +void au_pin_hdir_unlock(struct au_pin *p)
19166 + au_hn_inode_unlock(p->hdir);
19169 +int au_pin_hdir_lock(struct au_pin *p)
19177 + /* even if an error happens later, keep this lock */
19178 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19181 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19186 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19187 + p->h_parent, p->br);
19193 +int au_pin_hdir_relock(struct au_pin *p)
19196 + struct inode *h_i;
19197 + struct dentry *h_d[] = {
19202 + err = au_pin_hdir_lock(p);
19203 + if (unlikely(err))
19206 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19209 + if (d_is_positive(h_d[i])) {
19210 + h_i = d_inode(h_d[i]);
19211 + err = !h_i->i_nlink;
19219 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19221 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19222 + p->hdir->hi_inode->i_rwsem.owner = task;
19226 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19229 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19230 + p->lsc_hi, 0, NULL, _RET_IP_);
19231 + au_pin_hdir_set_owner(p, current);
19235 +void au_pin_hdir_release(struct au_pin *p)
19238 + au_pin_hdir_set_owner(p, p->task);
19239 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19243 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19245 + if (pin && pin->parent)
19246 + return au_h_dptr(pin->parent, pin->bindex);
19250 +void au_unpin(struct au_pin *p)
19253 + au_pin_hdir_unlock(p);
19254 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19255 + vfsub_mnt_drop_write(p->h_mnt);
19259 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19260 + di_read_unlock(p->parent, AuLock_IR);
19261 + iput(p->hdir->hi_inode);
19263 + p->parent = NULL;
19266 + /* do not clear p->task */
19269 +int au_do_pin(struct au_pin *p)
19272 + struct super_block *sb;
19273 + struct inode *h_dir;
19276 + sb = p->dentry->d_sb;
19277 + p->br = au_sbr(sb, p->bindex);
19278 + if (IS_ROOT(p->dentry)) {
19279 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19280 + p->h_mnt = au_br_mnt(p->br);
19281 + err = vfsub_mnt_want_write(p->h_mnt);
19282 + if (unlikely(err)) {
19283 + au_fclr_pin(p->flags, MNT_WRITE);
19290 + p->h_dentry = NULL;
19291 + if (p->bindex <= au_dbbot(p->dentry))
19292 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19294 + p->parent = dget_parent(p->dentry);
19295 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19296 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19299 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19300 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19302 + h_dir = p->hdir->hi_inode;
19306 + * if DI_LOCKED is not set, then p->parent may be different
19307 + * and h_parent can be NULL.
19309 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19311 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19312 + di_read_unlock(p->parent, AuLock_IR);
19314 + p->parent = NULL;
19318 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19319 + p->h_mnt = au_br_mnt(p->br);
19320 + err = vfsub_mnt_want_write(p->h_mnt);
19321 + if (unlikely(err)) {
19322 + au_fclr_pin(p->flags, MNT_WRITE);
19323 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19324 + di_read_unlock(p->parent, AuLock_IR);
19326 + p->parent = NULL;
19332 + err = au_pin_hdir_lock(p);
19334 + goto out; /* success */
19339 + pr_err("err %d\n", err);
19340 + err = au_busy_or_stale();
19345 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19346 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19347 + unsigned int udba, unsigned char flags)
19349 + p->dentry = dentry;
19351 + p->lsc_di = lsc_di;
19352 + p->lsc_hi = lsc_hi;
19353 + p->flags = flags;
19354 + p->bindex = bindex;
19356 + p->parent = NULL;
19360 + p->h_dentry = NULL;
19361 + p->h_parent = NULL;
19363 + p->task = current;
19366 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19367 + unsigned int udba, unsigned char flags)
19369 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19371 + return au_do_pin(pin);
19374 +/* ---------------------------------------------------------------------- */
19377 + * ->setattr() and ->getattr() are called in various cases.
19378 + * chmod, stat: dentry is revalidated.
19379 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19381 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19383 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19384 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19387 + struct dentry *parent;
19390 + if (au_digen_test(dentry, sigen)) {
19391 + parent = dget_parent(dentry);
19392 + di_read_lock_parent(parent, AuLock_IR);
19393 + err = au_refresh_dentry(dentry, parent);
19394 + di_read_unlock(parent, AuLock_IR);
19402 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19403 + struct au_icpup_args *a)
19407 + aufs_bindex_t btop, ibtop;
19408 + struct dentry *hi_wh, *parent;
19409 + struct inode *inode;
19410 + struct au_wr_dir_args wr_dir_args = {
19411 + .force_btgt = -1,
19415 + if (d_is_dir(dentry))
19416 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19417 + /* plink or hi_wh() case */
19418 + btop = au_dbtop(dentry);
19419 + inode = d_inode(dentry);
19420 + ibtop = au_ibtop(inode);
19421 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19422 + wr_dir_args.force_btgt = ibtop;
19423 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19424 + if (unlikely(err < 0))
19428 + au_fset_icpup(a->flags, DID_CPUP);
19431 + a->pin_flags = AuPin_MNT_WRITE;
19433 + if (!IS_ROOT(dentry)) {
19434 + au_fset_pin(a->pin_flags, DI_LOCKED);
19435 + parent = dget_parent(dentry);
19436 + di_write_lock_parent(parent);
19439 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19440 + if (unlikely(err))
19444 + a->h_path.dentry = au_h_dptr(dentry, btop);
19445 + a->h_inode = d_inode(a->h_path.dentry);
19446 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19447 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19448 + if (ia->ia_size < i_size_read(a->h_inode))
19449 + sz = ia->ia_size;
19450 + inode_unlock(a->h_inode);
19454 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19455 + hi_wh = au_hi_wh(inode, a->btgt);
19457 + struct au_cp_generic cpg = {
19458 + .dentry = dentry,
19464 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19465 + if (unlikely(err))
19467 + hi_wh = au_hi_wh(inode, a->btgt);
19468 + /* todo: revalidate hi_wh? */
19473 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19474 + di_downgrade_lock(parent, AuLock_IR);
19478 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19479 + goto out; /* success */
19481 + if (!d_unhashed(dentry)) {
19482 + struct au_cp_generic cpg = {
19483 + .dentry = dentry,
19488 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19490 + err = au_sio_cpup_simple(&cpg);
19492 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19493 + } else if (!hi_wh)
19494 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19496 + a->h_path.dentry = hi_wh; /* do not dget here */
19499 + a->h_inode = d_inode(a->h_path.dentry);
19501 + goto out; /* success */
19502 + au_unpin(&a->pin);
19505 + di_write_unlock(parent);
19510 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19514 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19517 + struct inode *inode, *delegated;
19518 + struct super_block *sb;
19519 + struct file *file;
19520 + struct au_icpup_args *a;
19522 + inode = d_inode(dentry);
19523 + IMustLock(inode);
19525 + err = setattr_prepare(dentry, ia);
19526 + if (unlikely(err))
19530 + a = kzalloc(sizeof(*a), GFP_NOFS);
19531 + if (unlikely(!a))
19534 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19535 + ia->ia_valid &= ~ATTR_MODE;
19538 + sb = dentry->d_sb;
19539 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19540 + if (unlikely(err))
19543 + if (ia->ia_valid & ATTR_FILE) {
19544 + /* currently ftruncate(2) only */
19545 + AuDebugOn(!d_is_reg(dentry));
19546 + file = ia->ia_file;
19547 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
19549 + if (unlikely(err))
19551 + ia->ia_file = au_hf_top(file);
19552 + a->udba = AuOpt_UDBA_NONE;
19554 + /* fchmod() doesn't pass ia_file */
19555 + a->udba = au_opt_udba(sb);
19556 + di_write_lock_child(dentry);
19557 + /* no d_unlinked(), to set UDBA_NONE for root */
19558 + if (d_unhashed(dentry))
19559 + a->udba = AuOpt_UDBA_NONE;
19560 + if (a->udba != AuOpt_UDBA_NONE) {
19561 + AuDebugOn(IS_ROOT(dentry));
19562 + err = au_reval_for_attr(dentry, au_sigen(sb));
19563 + if (unlikely(err))
19568 + err = au_pin_and_icpup(dentry, ia, a);
19569 + if (unlikely(err < 0))
19571 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19572 + ia->ia_file = NULL;
19573 + ia->ia_valid &= ~ATTR_FILE;
19576 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19577 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19578 + == (ATTR_MODE | ATTR_CTIME)) {
19579 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19580 + if (unlikely(err))
19582 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19583 + && (ia->ia_valid & ATTR_CTIME)) {
19584 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19585 + if (unlikely(err))
19589 + if (ia->ia_valid & ATTR_SIZE) {
19592 + if (ia->ia_size < i_size_read(inode))
19594 + truncate_setsize(inode, ia->ia_size);
19597 + if (ia->ia_valid & ATTR_FILE)
19599 + inode_unlock(a->h_inode);
19600 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19601 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19603 + delegated = NULL;
19605 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19607 + err = break_deleg_wait(&delegated);
19615 + * regardless aufs 'acl' option setting.
19616 + * why don't all acl-aware fs call this func from their ->setattr()?
19618 + if (!err && (ia->ia_valid & ATTR_MODE))
19619 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19621 + au_cpup_attr_changeable(inode);
19624 + inode_unlock(a->h_inode);
19625 + au_unpin(&a->pin);
19626 + if (unlikely(err))
19627 + au_update_dbtop(dentry);
19629 + di_write_unlock(dentry);
19631 + fi_write_unlock(file);
19632 + ia->ia_file = file;
19633 + ia->ia_valid |= ATTR_FILE;
19636 + si_read_unlock(sb);
19644 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19645 +static int au_h_path_to_set_attr(struct dentry *dentry,
19646 + struct au_icpup_args *a, struct path *h_path)
19649 + struct super_block *sb;
19651 + sb = dentry->d_sb;
19652 + a->udba = au_opt_udba(sb);
19653 + /* no d_unlinked(), to set UDBA_NONE for root */
19654 + if (d_unhashed(dentry))
19655 + a->udba = AuOpt_UDBA_NONE;
19656 + if (a->udba != AuOpt_UDBA_NONE) {
19657 + AuDebugOn(IS_ROOT(dentry));
19658 + err = au_reval_for_attr(dentry, au_sigen(sb));
19659 + if (unlikely(err))
19662 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19663 + if (unlikely(err < 0))
19666 + h_path->dentry = a->h_path.dentry;
19667 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19673 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19674 + struct au_sxattr *arg)
19677 + struct path h_path;
19678 + struct super_block *sb;
19679 + struct au_icpup_args *a;
19680 + struct inode *h_inode;
19682 + IMustLock(inode);
19685 + a = kzalloc(sizeof(*a), GFP_NOFS);
19686 + if (unlikely(!a))
19689 + sb = dentry->d_sb;
19690 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19691 + if (unlikely(err))
19694 + h_path.dentry = NULL; /* silence gcc */
19695 + di_write_lock_child(dentry);
19696 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19697 + if (unlikely(err))
19700 + inode_unlock(a->h_inode);
19701 + switch (arg->type) {
19702 + case AU_XATTR_SET:
19703 + AuDebugOn(d_is_negative(h_path.dentry));
19704 + err = vfsub_setxattr(h_path.dentry,
19705 + arg->u.set.name, arg->u.set.value,
19706 + arg->u.set.size, arg->u.set.flags);
19709 + err = -EOPNOTSUPP;
19710 + h_inode = d_inode(h_path.dentry);
19711 + if (h_inode->i_op->set_acl)
19712 + /* this will call posix_acl_update_mode */
19713 + err = h_inode->i_op->set_acl(h_inode,
19714 + arg->u.acl_set.acl,
19715 + arg->u.acl_set.type);
19719 + au_cpup_attr_timesizes(inode);
19721 + au_unpin(&a->pin);
19722 + if (unlikely(err))
19723 + au_update_dbtop(dentry);
19726 + di_write_unlock(dentry);
19727 + si_read_unlock(sb);
19736 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19737 + unsigned int nlink)
19741 + inode->i_mode = st->mode;
19742 + /* don't i_[ug]id_write() here */
19743 + inode->i_uid = st->uid;
19744 + inode->i_gid = st->gid;
19745 + inode->i_atime = st->atime;
19746 + inode->i_mtime = st->mtime;
19747 + inode->i_ctime = st->ctime;
19749 + au_cpup_attr_nlink(inode, /*force*/0);
19750 + if (S_ISDIR(inode->i_mode)) {
19751 + n = inode->i_nlink;
19754 + smp_mb(); /* for i_nlink */
19755 + /* 0 can happen */
19756 + set_nlink(inode, n);
19759 + spin_lock(&inode->i_lock);
19760 + inode->i_blocks = st->blocks;
19761 + i_size_write(inode, st->size);
19762 + spin_unlock(&inode->i_lock);
19766 + * common routine for aufs_getattr() and au_getxattr().
19767 + * returns zero or negative (an error).
19768 + * @dentry will be read-locked in success.
19770 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19774 + unsigned int mnt_flags, sigen;
19775 + unsigned char udba_none;
19776 + aufs_bindex_t bindex;
19777 + struct super_block *sb, *h_sb;
19778 + struct inode *inode;
19780 + h_path->mnt = NULL;
19781 + h_path->dentry = NULL;
19784 + sb = dentry->d_sb;
19785 + mnt_flags = au_mntflags(sb);
19786 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19788 + if (unlikely(locked))
19789 + goto body; /* skip locking dinfo */
19791 + /* support fstat(2) */
19792 + if (!d_unlinked(dentry) && !udba_none) {
19793 + sigen = au_sigen(sb);
19794 + err = au_digen_test(dentry, sigen);
19796 + di_read_lock_child(dentry, AuLock_IR);
19797 + err = au_dbrange_test(dentry);
19798 + if (unlikely(err)) {
19799 + di_read_unlock(dentry, AuLock_IR);
19803 + AuDebugOn(IS_ROOT(dentry));
19804 + di_write_lock_child(dentry);
19805 + err = au_dbrange_test(dentry);
19807 + err = au_reval_for_attr(dentry, sigen);
19809 + di_downgrade_lock(dentry, AuLock_IR);
19811 + di_write_unlock(dentry);
19816 + di_read_lock_child(dentry, AuLock_IR);
19819 + inode = d_inode(dentry);
19820 + bindex = au_ibtop(inode);
19821 + h_path->mnt = au_sbr_mnt(sb, bindex);
19822 + h_sb = h_path->mnt->mnt_sb;
19824 + && !au_test_fs_bad_iattr(h_sb)
19826 + goto out; /* success */
19828 + if (au_dbtop(dentry) == bindex)
19829 + h_path->dentry = au_h_dptr(dentry, bindex);
19830 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19831 + h_path->dentry = au_plink_lkup(inode, bindex);
19832 + if (IS_ERR(h_path->dentry))
19833 + /* pretending success */
19834 + h_path->dentry = NULL;
19836 + dput(h_path->dentry);
19843 +static int aufs_getattr(const struct path *path, struct kstat *st,
19844 + u32 request, unsigned int query)
19847 + unsigned char positive;
19848 + struct path h_path;
19849 + struct dentry *dentry;
19850 + struct inode *inode;
19851 + struct super_block *sb;
19853 + dentry = path->dentry;
19854 + inode = d_inode(dentry);
19855 + sb = dentry->d_sb;
19856 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19857 + if (unlikely(err))
19859 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
19860 + if (unlikely(err))
19862 + if (unlikely(!h_path.dentry))
19863 + /* illegally overlapped or something */
19864 + goto out_fill; /* pretending success */
19866 + positive = d_is_positive(h_path.dentry);
19868 + /* no vfsub version */
19869 + err = vfs_getattr(&h_path, st, request, query);
19872 + au_refresh_iattr(inode, st,
19873 + d_inode(h_path.dentry)->i_nlink);
19874 + goto out_fill; /* success */
19880 + generic_fillattr(inode, st);
19882 + di_read_unlock(dentry, AuLock_IR);
19884 + si_read_unlock(sb);
19890 +/* ---------------------------------------------------------------------- */
19892 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19893 + struct delayed_call *done)
19896 + struct dentry *h_dentry;
19897 + struct inode *h_inode;
19899 + aufs_bindex_t bindex;
19901 + ret = NULL; /* suppress a warning */
19906 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19907 + if (unlikely(err))
19910 + err = au_d_hashed_positive(dentry);
19911 + if (unlikely(err))
19915 + inode = d_inode(dentry);
19916 + bindex = au_ibtop(inode);
19917 + h_inode = au_h_iptr(inode, bindex);
19918 + if (unlikely(!h_inode->i_op->get_link))
19923 + if (au_dbtop(dentry) <= bindex) {
19924 + h_dentry = au_h_dptr(dentry, bindex);
19929 + h_dentry = d_find_any_alias(h_inode);
19930 + if (IS_ERR(h_dentry)) {
19931 + err = PTR_ERR(h_dentry);
19935 + if (unlikely(!h_dentry))
19939 + AuDbg("%pf\n", h_inode->i_op->get_link);
19940 + AuDbgDentry(h_dentry);
19941 + ret = vfs_get_link(h_dentry, done);
19944 + err = PTR_ERR(ret);
19947 + aufs_read_unlock(dentry, AuLock_IR);
19949 + if (unlikely(err))
19950 + ret = ERR_PTR(err);
19951 + AuTraceErrPtr(ret);
19955 +/* ---------------------------------------------------------------------- */
19957 +static int au_is_special(struct inode *inode)
19959 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19962 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19965 + aufs_bindex_t bindex;
19966 + struct super_block *sb;
19967 + struct inode *h_inode;
19968 + struct vfsmount *h_mnt;
19970 + sb = inode->i_sb;
19971 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19972 + "unexpected s_flags 0x%lx", sb->s_flags);
19974 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19976 + si_read_lock(sb, AuLock_FLUSH);
19977 + ii_write_lock_child(inode);
19981 + bindex = au_ibtop(inode);
19982 + h_inode = au_h_iptr(inode, bindex);
19983 + if (!au_test_ro(sb, bindex, inode)) {
19984 + h_mnt = au_sbr_mnt(sb, bindex);
19985 + err = vfsub_mnt_want_write(h_mnt);
19987 + err = vfsub_update_time(h_inode, ts, flags);
19988 + vfsub_mnt_drop_write(h_mnt);
19990 + } else if (au_is_special(h_inode)) {
19992 + * Never copy-up here.
19993 + * These special files may already be opened and used for
19994 + * communicating. If we copied it up, then the communication
19995 + * would be corrupted.
19997 + AuWarn1("timestamps for i%lu are ignored "
19998 + "since it is on readonly branch (hi%lu).\n",
19999 + inode->i_ino, h_inode->i_ino);
20000 + } else if (flags & ~S_ATIME) {
20002 + AuIOErr1("unexpected flags 0x%x\n", flags);
20008 + au_cpup_attr_timesizes(inode);
20009 + ii_write_unlock(inode);
20010 + si_read_unlock(sb);
20013 + if (!err && (flags & S_VERSION))
20014 + inode_inc_iversion(inode);
20019 +/* ---------------------------------------------------------------------- */
20021 +/* no getattr version will be set by module.c:aufs_init() */
20022 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
20024 + [AuIop_SYMLINK] = {
20025 + .permission = aufs_permission,
20026 +#ifdef CONFIG_FS_POSIX_ACL
20027 + .get_acl = aufs_get_acl,
20028 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
20031 + .setattr = aufs_setattr,
20032 + .getattr = aufs_getattr,
20034 +#ifdef CONFIG_AUFS_XATTR
20035 + .listxattr = aufs_listxattr,
20038 + .get_link = aufs_get_link,
20040 + /* .update_time = aufs_update_time */
20043 + .create = aufs_create,
20044 + .lookup = aufs_lookup,
20045 + .link = aufs_link,
20046 + .unlink = aufs_unlink,
20047 + .symlink = aufs_symlink,
20048 + .mkdir = aufs_mkdir,
20049 + .rmdir = aufs_rmdir,
20050 + .mknod = aufs_mknod,
20051 + .rename = aufs_rename,
20053 + .permission = aufs_permission,
20054 +#ifdef CONFIG_FS_POSIX_ACL
20055 + .get_acl = aufs_get_acl,
20056 + .set_acl = aufs_set_acl,
20059 + .setattr = aufs_setattr,
20060 + .getattr = aufs_getattr,
20062 +#ifdef CONFIG_AUFS_XATTR
20063 + .listxattr = aufs_listxattr,
20066 + .update_time = aufs_update_time,
20067 + .atomic_open = aufs_atomic_open,
20068 + .tmpfile = aufs_tmpfile
20070 + [AuIop_OTHER] = {
20071 + .permission = aufs_permission,
20072 +#ifdef CONFIG_FS_POSIX_ACL
20073 + .get_acl = aufs_get_acl,
20074 + .set_acl = aufs_set_acl,
20077 + .setattr = aufs_setattr,
20078 + .getattr = aufs_getattr,
20080 +#ifdef CONFIG_AUFS_XATTR
20081 + .listxattr = aufs_listxattr,
20084 + .update_time = aufs_update_time
20087 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
20088 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
20089 +++ linux/fs/aufs/i_op_del.c 2017-07-29 12:14:25.903042072 +0200
20092 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20094 + * This program, aufs is free software; you can redistribute it and/or modify
20095 + * it under the terms of the GNU General Public License as published by
20096 + * the Free Software Foundation; either version 2 of the License, or
20097 + * (at your option) any later version.
20099 + * This program is distributed in the hope that it will be useful,
20100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20102 + * GNU General Public License for more details.
20104 + * You should have received a copy of the GNU General Public License
20105 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20109 + * inode operations (del entry)
20115 + * decide if a new whiteout for @dentry is necessary or not.
20116 + * when it is necessary, prepare the parent dir for the upper branch whose
20117 + * branch index is @bcpup for creation. the actual creation of the whiteout will
20118 + * be done by caller.
20120 + * 0: wh is unnecessary
20121 + * plus: wh is necessary
20124 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
20126 + int need_wh, err;
20127 + aufs_bindex_t btop;
20128 + struct super_block *sb;
20130 + sb = dentry->d_sb;
20131 + btop = au_dbtop(dentry);
20132 + if (*bcpup < 0) {
20134 + if (au_test_ro(sb, btop, d_inode(dentry))) {
20135 + err = AuWbrCopyup(au_sbi(sb), dentry);
20137 + if (unlikely(err < 0))
20141 + AuDebugOn(btop < *bcpup
20142 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
20143 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
20145 + if (*bcpup != btop) {
20146 + err = au_cpup_dirs(dentry, *bcpup);
20147 + if (unlikely(err))
20151 + struct au_dinfo *dinfo, *tmp;
20153 + need_wh = -ENOMEM;
20154 + dinfo = au_di(dentry);
20155 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
20157 + au_di_cp(tmp, dinfo);
20158 + au_di_swap(tmp, dinfo);
20159 + /* returns the number of positive dentries */
20160 + need_wh = au_lkup_dentry(dentry, btop + 1,
20161 + /* AuLkup_IGNORE_PERM */ 0);
20162 + au_di_swap(tmp, dinfo);
20163 + au_rw_write_unlock(&tmp->di_rwsem);
20167 + AuDbg("need_wh %d\n", need_wh);
20175 + * simple tests for the del-entry operations.
20176 + * following the checks in vfs, plus the parent-child relationship.
20178 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20179 + struct dentry *h_parent, int isdir)
20183 + struct dentry *h_dentry, *h_latest;
20184 + struct inode *h_inode;
20186 + h_dentry = au_h_dptr(dentry, bindex);
20187 + if (d_really_is_positive(dentry)) {
20189 + if (unlikely(d_is_negative(h_dentry)))
20191 + h_inode = d_inode(h_dentry);
20192 + if (unlikely(!h_inode->i_nlink))
20195 + h_mode = h_inode->i_mode;
20198 + if (unlikely(S_ISDIR(h_mode)))
20200 + } else if (unlikely(!S_ISDIR(h_mode))) {
20205 + /* rename(2) case */
20207 + if (unlikely(d_is_positive(h_dentry)))
20212 + /* expected parent dir is locked */
20213 + if (unlikely(h_parent != h_dentry->d_parent))
20218 + * rmdir a dir may break the consistency on some filesystem.
20219 + * let's try heavy test.
20222 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20223 + && au_test_h_perm(d_inode(h_parent),
20224 + MAY_EXEC | MAY_WRITE)))
20227 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20229 + if (IS_ERR(h_latest))
20231 + if (h_latest == h_dentry)
20240 + * decide the branch where we operate for @dentry. the branch index will be set
20241 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20242 + * dir for reverting.
20243 + * when a new whiteout is necessary, create it.
20245 +static struct dentry*
20246 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20247 + struct au_dtime *dt, struct au_pin *pin)
20249 + struct dentry *wh_dentry;
20250 + struct super_block *sb;
20251 + struct path h_path;
20252 + int err, need_wh;
20253 + unsigned int udba;
20254 + aufs_bindex_t bcpup;
20256 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20257 + wh_dentry = ERR_PTR(need_wh);
20258 + if (unlikely(need_wh < 0))
20261 + sb = dentry->d_sb;
20262 + udba = au_opt_udba(sb);
20264 + err = au_pin(pin, dentry, bcpup, udba,
20265 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20266 + wh_dentry = ERR_PTR(err);
20267 + if (unlikely(err))
20270 + h_path.dentry = au_pinned_h_parent(pin);
20271 + if (udba != AuOpt_UDBA_NONE
20272 + && au_dbtop(dentry) == bcpup) {
20273 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20274 + wh_dentry = ERR_PTR(err);
20275 + if (unlikely(err))
20279 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20280 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20281 + wh_dentry = NULL;
20283 + goto out; /* success, no need to create whiteout */
20285 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20286 + if (IS_ERR(wh_dentry))
20289 + /* returns with the parent is locked and wh_dentry is dget-ed */
20290 + goto out; /* success */
20295 + return wh_dentry;
20299 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20300 + * in order to be revertible and save time for removing many child whiteouts
20302 + * returns 1 when there are too many child whiteout and caller should remove
20303 + * them asynchronously. returns 0 when the number of children is enough small to
20304 + * remove now or the branch fs is a remote fs.
20305 + * otherwise return an error.
20307 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20308 + struct au_nhash *whlist, struct inode *dir)
20310 + int rmdir_later, err, dirwh;
20311 + struct dentry *h_dentry;
20312 + struct super_block *sb;
20313 + struct inode *inode;
20315 + sb = dentry->d_sb;
20316 + SiMustAnyLock(sb);
20317 + h_dentry = au_h_dptr(dentry, bindex);
20318 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20319 + if (unlikely(err))
20322 + /* stop monitoring */
20323 + inode = d_inode(dentry);
20324 + au_hn_free(au_hi(inode, bindex));
20326 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20327 + dirwh = au_sbi(sb)->si_dirwh;
20328 + rmdir_later = (dirwh <= 1);
20329 + if (!rmdir_later)
20330 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20333 + return rmdir_later;
20336 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20337 + if (unlikely(err)) {
20338 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20339 + h_dentry, bindex, err);
20349 + * final procedure for deleting a entry.
20350 + * maintain dentry and iattr.
20352 +static void epilog(struct inode *dir, struct dentry *dentry,
20353 + aufs_bindex_t bindex)
20355 + struct inode *inode;
20357 + inode = d_inode(dentry);
20359 + inode->i_ctime = dir->i_ctime;
20361 + au_dir_ts(dir, bindex);
20362 + dir->i_version++;
20366 + * when an error happened, remove the created whiteout and revert everything.
20368 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20369 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20370 + struct dentry *dentry, struct au_dtime *dt)
20373 + struct path h_path = {
20374 + .dentry = wh_dentry,
20375 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20378 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20380 + au_set_dbwh(dentry, bwh);
20381 + au_dtime_revert(dt);
20385 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20389 +/* ---------------------------------------------------------------------- */
20391 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20394 + aufs_bindex_t bwh, bindex, btop;
20395 + struct inode *inode, *h_dir, *delegated;
20396 + struct dentry *parent, *wh_dentry;
20397 + /* to reuduce stack size */
20399 + struct au_dtime dt;
20400 + struct au_pin pin;
20401 + struct path h_path;
20407 + a = kmalloc(sizeof(*a), GFP_NOFS);
20408 + if (unlikely(!a))
20411 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20412 + if (unlikely(err))
20414 + err = au_d_hashed_positive(dentry);
20415 + if (unlikely(err))
20417 + inode = d_inode(dentry);
20418 + IMustLock(inode);
20420 + if (unlikely(d_is_dir(dentry)))
20421 + goto out_unlock; /* possible? */
20423 + btop = au_dbtop(dentry);
20424 + bwh = au_dbwh(dentry);
20426 + parent = dentry->d_parent; /* dir inode is locked */
20427 + di_write_lock_parent(parent);
20428 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20430 + err = PTR_ERR(wh_dentry);
20431 + if (IS_ERR(wh_dentry))
20434 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20435 + a->h_path.dentry = au_h_dptr(dentry, btop);
20436 + dget(a->h_path.dentry);
20437 + if (bindex == btop) {
20438 + h_dir = au_pinned_h_dir(&a->pin);
20439 + delegated = NULL;
20440 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20441 + if (unlikely(err == -EWOULDBLOCK)) {
20442 + pr_warn("cannot retry for NFSv4 delegation"
20443 + " for an internal unlink\n");
20447 + /* dir inode is locked */
20448 + h_dir = d_inode(wh_dentry->d_parent);
20449 + IMustLock(h_dir);
20454 + vfsub_drop_nlink(inode);
20455 + epilog(dir, dentry, bindex);
20457 + /* update target timestamps */
20458 + if (bindex == btop) {
20459 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20461 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20463 + /* todo: this timestamp may be reverted later */
20464 + inode->i_ctime = h_dir->i_ctime;
20465 + goto out_unpin; /* success */
20472 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20479 + au_unpin(&a->pin);
20481 + dput(a->h_path.dentry);
20483 + di_write_unlock(parent);
20485 + aufs_read_unlock(dentry, AuLock_DW);
20492 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20494 + int err, rmdir_later;
20495 + aufs_bindex_t bwh, bindex, btop;
20496 + struct inode *inode;
20497 + struct dentry *parent, *wh_dentry, *h_dentry;
20498 + struct au_whtmp_rmdir *args;
20499 + /* to reuduce stack size */
20501 + struct au_dtime dt;
20502 + struct au_pin pin;
20508 + a = kmalloc(sizeof(*a), GFP_NOFS);
20509 + if (unlikely(!a))
20512 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20513 + if (unlikely(err))
20515 + err = au_alive_dir(dentry);
20516 + if (unlikely(err))
20518 + inode = d_inode(dentry);
20519 + IMustLock(inode);
20521 + if (unlikely(!d_is_dir(dentry)))
20522 + goto out_unlock; /* possible? */
20525 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20526 + if (unlikely(!args))
20529 + parent = dentry->d_parent; /* dir inode is locked */
20530 + di_write_lock_parent(parent);
20531 + err = au_test_empty(dentry, &args->whlist);
20532 + if (unlikely(err))
20535 + btop = au_dbtop(dentry);
20536 + bwh = au_dbwh(dentry);
20538 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20540 + err = PTR_ERR(wh_dentry);
20541 + if (IS_ERR(wh_dentry))
20544 + h_dentry = au_h_dptr(dentry, btop);
20547 + if (bindex == btop) {
20548 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20550 + rmdir_later = err;
20554 + /* stop monitoring */
20555 + au_hn_free(au_hi(inode, btop));
20557 + /* dir inode is locked */
20558 + IMustLock(d_inode(wh_dentry->d_parent));
20563 + vfsub_dead_dir(inode);
20564 + au_set_dbdiropq(dentry, -1);
20565 + epilog(dir, dentry, bindex);
20567 + if (rmdir_later) {
20568 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20572 + goto out_unpin; /* success */
20580 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20587 + au_unpin(&a->pin);
20591 + di_write_unlock(parent);
20593 + au_whtmp_rmdir_free(args);
20595 + aufs_read_unlock(dentry, AuLock_DW);
20602 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20603 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20604 +++ linux/fs/aufs/i_op_ren.c 2017-07-29 12:14:25.903042072 +0200
20607 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20609 + * This program, aufs is free software; you can redistribute it and/or modify
20610 + * it under the terms of the GNU General Public License as published by
20611 + * the Free Software Foundation; either version 2 of the License, or
20612 + * (at your option) any later version.
20614 + * This program is distributed in the hope that it will be useful,
20615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20617 + * GNU General Public License for more details.
20619 + * You should have received a copy of the GNU General Public License
20620 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20624 + * inode operation (rename entry)
20625 + * todo: this is crazy monster
20630 +enum { AuSRC, AuDST, AuSrcDst };
20631 +enum { AuPARENT, AuCHILD, AuParentChild };
20633 +#define AuRen_ISDIR_SRC 1
20634 +#define AuRen_ISDIR_DST (1 << 1)
20635 +#define AuRen_ISSAMEDIR (1 << 2)
20636 +#define AuRen_WHSRC (1 << 3)
20637 +#define AuRen_WHDST (1 << 4)
20638 +#define AuRen_MNT_WRITE (1 << 5)
20639 +#define AuRen_DT_DSTDIR (1 << 6)
20640 +#define AuRen_DIROPQ_SRC (1 << 7)
20641 +#define AuRen_DIROPQ_DST (1 << 8)
20642 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20643 +#define au_fset_ren(flags, name) \
20644 + do { (flags) |= AuRen_##name; } while (0)
20645 +#define au_fclr_ren(flags, name) \
20646 + do { (flags) &= ~AuRen_##name; } while (0)
20648 +struct au_ren_args {
20650 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20652 + struct inode *dir, *inode;
20653 + struct au_hinode *hdir, *hinode;
20654 + struct au_dtime dt[AuParentChild];
20655 + aufs_bindex_t btop, bdiropq;
20658 +#define src_dentry sd[AuSRC].dentry
20659 +#define src_dir sd[AuSRC].dir
20660 +#define src_inode sd[AuSRC].inode
20661 +#define src_h_dentry sd[AuSRC].h_dentry
20662 +#define src_parent sd[AuSRC].parent
20663 +#define src_h_parent sd[AuSRC].h_parent
20664 +#define src_wh_dentry sd[AuSRC].wh_dentry
20665 +#define src_hdir sd[AuSRC].hdir
20666 +#define src_hinode sd[AuSRC].hinode
20667 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20668 +#define src_dt sd[AuSRC].dt
20669 +#define src_btop sd[AuSRC].btop
20670 +#define src_bdiropq sd[AuSRC].bdiropq
20672 +#define dst_dentry sd[AuDST].dentry
20673 +#define dst_dir sd[AuDST].dir
20674 +#define dst_inode sd[AuDST].inode
20675 +#define dst_h_dentry sd[AuDST].h_dentry
20676 +#define dst_parent sd[AuDST].parent
20677 +#define dst_h_parent sd[AuDST].h_parent
20678 +#define dst_wh_dentry sd[AuDST].wh_dentry
20679 +#define dst_hdir sd[AuDST].hdir
20680 +#define dst_hinode sd[AuDST].hinode
20681 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20682 +#define dst_dt sd[AuDST].dt
20683 +#define dst_btop sd[AuDST].btop
20684 +#define dst_bdiropq sd[AuDST].bdiropq
20686 + struct dentry *h_trap;
20687 + struct au_branch *br;
20688 + struct path h_path;
20689 + struct au_nhash whlist;
20690 + aufs_bindex_t btgt, src_bwh;
20693 + unsigned short auren_flags;
20694 + unsigned char flags; /* syscall parameter */
20695 + unsigned char exchange;
20698 + struct au_whtmp_rmdir *thargs;
20699 + struct dentry *h_dst;
20702 +/* ---------------------------------------------------------------------- */
20705 + * functions for reverting.
20706 + * when an error happened in a single rename systemcall, we should revert
20707 + * everything as if nothing happened.
20708 + * we don't need to revert the copied-up/down the parent dir since they are
20712 +#define RevertFailure(fmt, ...) do { \
20713 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20714 + ##__VA_ARGS__, err, rerr); \
20718 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20721 + struct dentry *d;
20722 +#define src_or_dst(member) a->sd[idx].member
20724 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20725 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20726 + rerr = au_diropq_remove(d, a->btgt);
20727 + au_hn_inode_unlock(src_or_dst(hinode));
20728 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20730 + RevertFailure("remove diropq %pd", d);
20732 +#undef src_or_dst_
20735 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20737 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20738 + au_ren_do_rev_diropq(err, a, AuSRC);
20739 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20740 + au_ren_do_rev_diropq(err, a, AuDST);
20743 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20746 + struct inode *delegated;
20748 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20749 + a->src_h_parent);
20750 + rerr = PTR_ERR(a->h_path.dentry);
20751 + if (IS_ERR(a->h_path.dentry)) {
20752 + RevertFailure("lkup one %pd", a->src_dentry);
20756 + delegated = NULL;
20757 + rerr = vfsub_rename(a->dst_h_dir,
20758 + au_h_dptr(a->src_dentry, a->btgt),
20759 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20760 + if (unlikely(rerr == -EWOULDBLOCK)) {
20761 + pr_warn("cannot retry for NFSv4 delegation"
20762 + " for an internal rename\n");
20765 + d_drop(a->h_path.dentry);
20766 + dput(a->h_path.dentry);
20767 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20769 + RevertFailure("rename %pd", a->src_dentry);
20772 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20775 + struct inode *delegated;
20777 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20778 + a->dst_h_parent);
20779 + rerr = PTR_ERR(a->h_path.dentry);
20780 + if (IS_ERR(a->h_path.dentry)) {
20781 + RevertFailure("lkup one %pd", a->dst_dentry);
20784 + if (d_is_positive(a->h_path.dentry)) {
20785 + d_drop(a->h_path.dentry);
20786 + dput(a->h_path.dentry);
20790 + delegated = NULL;
20791 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20792 + &delegated, a->flags);
20793 + if (unlikely(rerr == -EWOULDBLOCK)) {
20794 + pr_warn("cannot retry for NFSv4 delegation"
20795 + " for an internal rename\n");
20798 + d_drop(a->h_path.dentry);
20799 + dput(a->h_path.dentry);
20801 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20803 + RevertFailure("rename %pd", a->h_dst);
20806 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20810 + a->h_path.dentry = a->src_wh_dentry;
20811 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20812 + au_set_dbwh(a->src_dentry, a->src_bwh);
20814 + RevertFailure("unlink %pd", a->src_wh_dentry);
20816 +#undef RevertFailure
20818 +/* ---------------------------------------------------------------------- */
20821 + * when we have to copyup the renaming entry, do it with the rename-target name
20822 + * in order to minimize the cost (the later actual rename is unnecessary).
20823 + * otherwise rename it on the target branch.
20825 +static int au_ren_or_cpup(struct au_ren_args *a)
20828 + struct dentry *d;
20829 + struct inode *delegated;
20831 + d = a->src_dentry;
20832 + if (au_dbtop(d) == a->btgt) {
20833 + a->h_path.dentry = a->dst_h_dentry;
20834 + AuDebugOn(au_dbtop(d) != a->btgt);
20835 + delegated = NULL;
20836 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20837 + a->dst_h_dir, &a->h_path, &delegated,
20839 + if (unlikely(err == -EWOULDBLOCK)) {
20840 + pr_warn("cannot retry for NFSv4 delegation"
20841 + " for an internal rename\n");
20847 + if (!err && a->h_dst)
20848 + /* it will be set to dinfo later */
20854 +/* cf. aufs_rmdir() */
20855 +static int au_ren_del_whtmp(struct au_ren_args *a)
20858 + struct inode *dir;
20860 + dir = a->dst_dir;
20861 + SiMustAnyLock(dir->i_sb);
20862 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20863 + au_sbi(dir->i_sb)->si_dirwh)
20864 + || au_test_fs_remote(a->h_dst->d_sb)) {
20865 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20866 + if (unlikely(err))
20867 + pr_warn("failed removing whtmp dir %pd (%d), "
20868 + "ignored.\n", a->h_dst, err);
20870 + au_nhash_wh_free(&a->thargs->whlist);
20871 + a->thargs->whlist = a->whlist;
20872 + a->whlist.nh_num = 0;
20873 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20875 + a->thargs = NULL;
20881 +/* make it 'opaque' dir. */
20882 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20885 + struct dentry *d, *diropq;
20886 +#define src_or_dst(member) a->sd[idx].member
20889 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20890 + src_or_dst(bdiropq) = au_dbdiropq(d);
20891 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20892 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20893 + diropq = au_diropq_create(d, a->btgt);
20894 + au_hn_inode_unlock(src_or_dst(hinode));
20895 + if (IS_ERR(diropq))
20896 + err = PTR_ERR(diropq);
20900 +#undef src_or_dst_
20904 +static int au_ren_diropq(struct au_ren_args *a)
20907 + unsigned char always;
20908 + struct dentry *d;
20911 + d = a->dst_dentry; /* already renamed on the branch */
20912 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20913 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20914 + && a->btgt != au_dbdiropq(a->src_dentry)
20915 + && (a->dst_wh_dentry
20916 + || a->btgt <= au_dbdiropq(d)
20917 + /* hide the lower to keep xino */
20918 + /* the lowers may not be a dir, but we hide them anyway */
20919 + || a->btgt < au_dbbot(d)
20922 + err = au_ren_do_diropq(a, AuSRC);
20923 + if (unlikely(err))
20925 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20927 + if (!a->exchange)
20928 + goto out; /* success */
20930 + d = a->src_dentry; /* already renamed on the branch */
20931 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20932 + && a->btgt != au_dbdiropq(a->dst_dentry)
20933 + && (a->btgt < au_dbdiropq(d)
20934 + || a->btgt < au_dbbot(d)
20936 + AuDbgDentry(a->src_dentry);
20937 + AuDbgDentry(a->dst_dentry);
20938 + err = au_ren_do_diropq(a, AuDST);
20939 + if (unlikely(err))
20940 + goto out_rev_src;
20941 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20943 + goto out; /* success */
20946 + AuDbg("err %d, reverting src\n", err);
20947 + au_ren_rev_diropq(err, a);
20952 +static int do_rename(struct au_ren_args *a)
20955 + struct dentry *d, *h_d;
20957 + if (!a->exchange) {
20958 + /* prepare workqueue args for asynchronous rmdir */
20959 + h_d = a->dst_h_dentry;
20960 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20961 + && d_is_positive(h_d)) {
20963 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20965 + if (unlikely(!a->thargs))
20967 + a->h_dst = dget(h_d);
20970 + /* create whiteout for src_dentry */
20971 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20972 + a->src_bwh = au_dbwh(a->src_dentry);
20973 + AuDebugOn(a->src_bwh >= 0);
20974 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20975 + a->src_h_parent);
20976 + err = PTR_ERR(a->src_wh_dentry);
20977 + if (IS_ERR(a->src_wh_dentry))
20981 + /* lookup whiteout for dentry */
20982 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20983 + h_d = au_wh_lkup(a->dst_h_parent,
20984 + &a->dst_dentry->d_name, a->br);
20985 + err = PTR_ERR(h_d);
20988 + if (d_is_negative(h_d))
20991 + a->dst_wh_dentry = h_d;
20994 + /* rename dentry to tmpwh */
20996 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20997 + if (unlikely(err))
21000 + d = a->dst_dentry;
21001 + au_set_h_dptr(d, a->btgt, NULL);
21002 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
21003 + if (unlikely(err))
21005 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
21009 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
21011 + /* rename by vfs_rename or cpup */
21012 + err = au_ren_or_cpup(a);
21013 + if (unlikely(err))
21014 + /* leave the copied-up one */
21017 + /* make dir opaque */
21018 + err = au_ren_diropq(a);
21019 + if (unlikely(err))
21022 + /* update target timestamps */
21023 + if (a->exchange) {
21024 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
21025 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
21026 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21027 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21029 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
21030 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
21031 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21032 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21034 + if (!a->exchange) {
21035 + /* remove whiteout for dentry */
21036 + if (a->dst_wh_dentry) {
21037 + a->h_path.dentry = a->dst_wh_dentry;
21038 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
21040 + if (unlikely(err))
21044 + /* remove whtmp */
21046 + au_ren_del_whtmp(a); /* ignore this error */
21048 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
21051 + goto out_success;
21054 + au_ren_rev_diropq(err, a);
21056 + au_ren_rev_rename(err, a);
21060 + au_ren_rev_whtmp(err, a);
21062 + dput(a->dst_wh_dentry);
21063 + a->dst_wh_dentry = NULL;
21065 + if (a->src_wh_dentry)
21066 + au_ren_rev_whsrc(err, a);
21068 + dput(a->src_wh_dentry);
21069 + dput(a->dst_wh_dentry);
21073 + au_whtmp_rmdir_free(a->thargs);
21074 + a->thargs = NULL;
21080 +/* ---------------------------------------------------------------------- */
21083 + * test if @dentry dir can be rename destination or not.
21084 + * success means, it is a logically empty dir.
21086 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
21088 + return au_test_empty(dentry, whlist);
21092 + * test if @dentry dir can be rename source or not.
21093 + * if it can, return 0 and @children is filled.
21095 + * - it is a logically empty dir.
21096 + * - or, it exists on writable branch and has no children including whiteouts
21097 + * on the lower branch.
21099 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
21102 + unsigned int rdhash;
21103 + aufs_bindex_t btop;
21105 + btop = au_dbtop(dentry);
21106 + if (btop != btgt) {
21107 + struct au_nhash whlist;
21109 + SiMustAnyLock(dentry->d_sb);
21110 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
21112 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
21114 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
21115 + if (unlikely(err))
21117 + err = au_test_empty(dentry, &whlist);
21118 + au_nhash_wh_free(&whlist);
21122 + if (btop == au_dbtaildir(dentry))
21123 + return 0; /* success */
21125 + err = au_test_empty_lower(dentry);
21128 + if (err == -ENOTEMPTY) {
21129 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
21130 + " is not supported\n");
21136 +/* side effect: sets whlist and h_dentry */
21137 +static int au_ren_may_dir(struct au_ren_args *a)
21140 + unsigned int rdhash;
21141 + struct dentry *d;
21143 + d = a->dst_dentry;
21144 + SiMustAnyLock(d->d_sb);
21147 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
21148 + rdhash = au_sbi(d->d_sb)->si_rdhash;
21150 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
21151 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
21152 + if (unlikely(err))
21155 + if (!a->exchange) {
21156 + au_set_dbtop(d, a->dst_btop);
21157 + err = may_rename_dstdir(d, &a->whlist);
21158 + au_set_dbtop(d, a->btgt);
21160 + err = may_rename_srcdir(d, a->btgt);
21162 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
21163 + if (unlikely(err))
21166 + d = a->src_dentry;
21167 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
21168 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21169 + err = may_rename_srcdir(d, a->btgt);
21170 + if (unlikely(err)) {
21171 + au_nhash_wh_free(&a->whlist);
21172 + a->whlist.nh_num = 0;
21179 +/* ---------------------------------------------------------------------- */
21182 + * simple tests for rename.
21183 + * following the checks in vfs, plus the parent-child relationship.
21185 +static int au_may_ren(struct au_ren_args *a)
21188 + struct inode *h_inode;
21190 + if (a->src_btop == a->btgt) {
21191 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
21192 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
21193 + if (unlikely(err))
21196 + if (unlikely(a->src_h_dentry == a->h_trap))
21201 + if (a->dst_btop != a->btgt)
21204 + err = -ENOTEMPTY;
21205 + if (unlikely(a->dst_h_dentry == a->h_trap))
21209 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21210 + if (d_really_is_negative(a->dst_dentry)) {
21211 + if (d_is_negative(a->dst_h_dentry))
21212 + err = au_may_add(a->dst_dentry, a->btgt,
21213 + a->dst_h_parent, isdir);
21215 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21217 + h_inode = d_inode(a->dst_h_dentry);
21218 + if (h_inode->i_nlink)
21219 + err = au_may_del(a->dst_dentry, a->btgt,
21220 + a->dst_h_parent, isdir);
21224 + if (unlikely(err == -ENOENT || err == -EEXIST))
21230 +/* ---------------------------------------------------------------------- */
21235 + * - src_dir and dir by lock_rename()
21236 + * - inode if exitsts
21239 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21241 + * + di_write_lock2_child()
21242 + * + di_write_lock_child()
21243 + * + ii_write_lock_child()
21244 + * + di_write_lock_child2()
21245 + * + ii_write_lock_child2()
21246 + * + src_parent and parent
21247 + * + di_write_lock_parent()
21248 + * + ii_write_lock_parent()
21249 + * + di_write_lock_parent2()
21250 + * + ii_write_lock_parent2()
21251 + * + lower src_dir and dir by vfsub_lock_rename()
21252 + * + verify the every relationships between child and parent. if any
21253 + * of them failed, unlock all and return -EBUSY.
21255 +static void au_ren_unlock(struct au_ren_args *a)
21257 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21258 + a->dst_h_parent, a->dst_hdir);
21259 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21260 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21263 +static int au_ren_lock(struct au_ren_args *a)
21266 + unsigned int udba;
21269 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21270 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21271 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21272 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21274 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21275 + if (unlikely(err))
21277 + au_fset_ren(a->auren_flags, MNT_WRITE);
21278 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21279 + a->dst_h_parent, a->dst_hdir);
21280 + udba = au_opt_udba(a->src_dentry->d_sb);
21281 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21282 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21283 + err = au_busy_or_stale();
21284 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21285 + err = au_h_verify(a->src_h_dentry, udba,
21286 + d_inode(a->src_h_parent), a->src_h_parent,
21288 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21289 + err = au_h_verify(a->dst_h_dentry, udba,
21290 + d_inode(a->dst_h_parent), a->dst_h_parent,
21293 + goto out; /* success */
21295 + err = au_busy_or_stale();
21296 + au_ren_unlock(a);
21302 +/* ---------------------------------------------------------------------- */
21304 +static void au_ren_refresh_dir(struct au_ren_args *a)
21306 + struct inode *dir;
21308 + dir = a->dst_dir;
21309 + dir->i_version++;
21310 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21311 + /* is this updating defined in POSIX? */
21312 + au_cpup_attr_timesizes(a->src_inode);
21313 + au_cpup_attr_nlink(dir, /*force*/1);
21315 + au_dir_ts(dir, a->btgt);
21317 + if (a->exchange) {
21318 + dir = a->src_dir;
21319 + dir->i_version++;
21320 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21321 + /* is this updating defined in POSIX? */
21322 + au_cpup_attr_timesizes(a->dst_inode);
21323 + au_cpup_attr_nlink(dir, /*force*/1);
21325 + au_dir_ts(dir, a->btgt);
21328 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21331 + dir = a->src_dir;
21332 + dir->i_version++;
21333 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21334 + au_cpup_attr_nlink(dir, /*force*/1);
21335 + au_dir_ts(dir, a->btgt);
21338 +static void au_ren_refresh(struct au_ren_args *a)
21340 + aufs_bindex_t bbot, bindex;
21341 + struct dentry *d, *h_d;
21342 + struct inode *i, *h_i;
21343 + struct super_block *sb;
21345 + d = a->dst_dentry;
21348 + /* already dget-ed by au_ren_or_cpup() */
21349 + au_set_h_dptr(d, a->btgt, a->h_dst);
21351 + i = a->dst_inode;
21353 + if (!a->exchange) {
21354 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21355 + vfsub_drop_nlink(i);
21357 + vfsub_dead_dir(i);
21358 + au_cpup_attr_timesizes(i);
21360 + au_update_dbrange(d, /*do_put_zero*/1);
21362 + au_cpup_attr_nlink(i, /*force*/1);
21365 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21366 + au_set_h_dptr(d, bindex, NULL);
21367 + bbot = au_dbbot(d);
21368 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21369 + au_set_h_dptr(d, bindex, NULL);
21370 + au_update_dbrange(d, /*do_put_zero*/0);
21373 + d = a->src_dentry;
21374 + if (!a->exchange) {
21375 + au_set_dbwh(d, -1);
21376 + bbot = au_dbbot(d);
21377 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21378 + h_d = au_h_dptr(d, bindex);
21380 + au_set_h_dptr(d, bindex, NULL);
21382 + au_set_dbbot(d, a->btgt);
21385 + i = a->src_inode;
21386 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21387 + return; /* success */
21389 + bbot = au_ibbot(i);
21390 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21391 + h_i = au_h_iptr(i, bindex);
21393 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21394 + /* ignore this error */
21395 + au_set_h_iptr(i, bindex, NULL, 0);
21398 + au_set_ibbot(i, a->btgt);
21400 + d_drop(a->src_dentry);
21403 +/* ---------------------------------------------------------------------- */
21405 +/* mainly for link(2) and rename(2) */
21406 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21408 + aufs_bindex_t bdiropq, bwh;
21409 + struct dentry *parent;
21410 + struct au_branch *br;
21412 + parent = dentry->d_parent;
21413 + IMustLock(d_inode(parent)); /* dir is locked */
21415 + bdiropq = au_dbdiropq(parent);
21416 + bwh = au_dbwh(dentry);
21417 + br = au_sbr(dentry->d_sb, btgt);
21418 + if (au_br_rdonly(br)
21419 + || (0 <= bdiropq && bdiropq < btgt)
21420 + || (0 <= bwh && bwh < btgt))
21423 + AuDbg("btgt %d\n", btgt);
21427 +/* sets src_btop, dst_btop and btgt */
21428 +static int au_ren_wbr(struct au_ren_args *a)
21431 + struct au_wr_dir_args wr_dir_args = {
21432 + /* .force_btgt = -1, */
21433 + .flags = AuWrDir_ADD_ENTRY
21436 + a->src_btop = au_dbtop(a->src_dentry);
21437 + a->dst_btop = au_dbtop(a->dst_dentry);
21438 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21439 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21440 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21441 + wr_dir_args.force_btgt = a->src_btop;
21442 + if (a->dst_inode && a->dst_btop < a->src_btop)
21443 + wr_dir_args.force_btgt = a->dst_btop;
21444 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21445 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21448 + au_update_dbtop(a->dst_dentry);
21453 +static void au_ren_dt(struct au_ren_args *a)
21455 + a->h_path.dentry = a->src_h_parent;
21456 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21457 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21458 + a->h_path.dentry = a->dst_h_parent;
21459 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21462 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21463 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21467 + a->h_path.dentry = a->src_h_dentry;
21468 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21469 + if (d_is_positive(a->dst_h_dentry)) {
21470 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21471 + a->h_path.dentry = a->dst_h_dentry;
21472 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21476 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21478 + struct dentry *h_d;
21479 + struct inode *h_inode;
21481 + au_dtime_revert(a->src_dt + AuPARENT);
21482 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21483 + au_dtime_revert(a->dst_dt + AuPARENT);
21485 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21486 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21487 + h_inode = d_inode(h_d);
21488 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21489 + au_dtime_revert(a->src_dt + AuCHILD);
21490 + inode_unlock(h_inode);
21492 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21493 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21494 + h_inode = d_inode(h_d);
21495 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21496 + au_dtime_revert(a->dst_dt + AuCHILD);
21497 + inode_unlock(h_inode);
21502 +/* ---------------------------------------------------------------------- */
21504 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21505 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21506 + unsigned int _flags)
21508 + int err, lock_flags;
21509 + /* reduce stack space */
21510 + struct au_ren_args *a;
21511 + struct au_pin pin;
21513 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21514 + IMustLock(_src_dir);
21515 + IMustLock(_dst_dir);
21518 + if (unlikely(_flags & RENAME_WHITEOUT))
21522 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21523 + a = kzalloc(sizeof(*a), GFP_NOFS);
21524 + if (unlikely(!a))
21527 + a->flags = _flags;
21528 + a->exchange = _flags & RENAME_EXCHANGE;
21529 + a->src_dir = _src_dir;
21530 + a->src_dentry = _src_dentry;
21531 + a->src_inode = NULL;
21532 + if (d_really_is_positive(a->src_dentry))
21533 + a->src_inode = d_inode(a->src_dentry);
21534 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21535 + a->dst_dir = _dst_dir;
21536 + a->dst_dentry = _dst_dentry;
21537 + a->dst_inode = NULL;
21538 + if (d_really_is_positive(a->dst_dentry))
21539 + a->dst_inode = d_inode(a->dst_dentry);
21540 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21541 + if (a->dst_inode) {
21543 + * if EXCHANGE && src is non-dir && dst is dir,
21544 + * dst is not locked.
21546 + /* IMustLock(a->dst_inode); */
21547 + au_igrab(a->dst_inode);
21551 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21552 + if (d_is_dir(a->src_dentry)) {
21553 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21554 + if (unlikely(!a->exchange
21555 + && d_really_is_positive(a->dst_dentry)
21556 + && !d_is_dir(a->dst_dentry)))
21558 + lock_flags |= AuLock_DIRS;
21560 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21561 + au_fset_ren(a->auren_flags, ISDIR_DST);
21562 + if (unlikely(!a->exchange
21563 + && d_really_is_positive(a->src_dentry)
21564 + && !d_is_dir(a->src_dentry)))
21566 + lock_flags |= AuLock_DIRS;
21568 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21569 + if (unlikely(err))
21572 + err = au_d_hashed_positive(a->src_dentry);
21573 + if (unlikely(err))
21576 + if (a->dst_inode) {
21578 + * If it is a dir, VFS unhash it before this
21579 + * function. It means we cannot rely upon d_unhashed().
21581 + if (unlikely(!a->dst_inode->i_nlink))
21583 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21584 + err = au_d_hashed_positive(a->dst_dentry);
21585 + if (unlikely(err && !a->exchange))
21587 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21589 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21593 + * is it possible?
21594 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21595 + * there may exist a problem somewhere else.
21598 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21601 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21602 + di_write_lock_parent(a->dst_parent);
21604 + /* which branch we process */
21605 + err = au_ren_wbr(a);
21606 + if (unlikely(err < 0))
21608 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21609 + a->h_path.mnt = au_br_mnt(a->br);
21611 + /* are they available to be renamed */
21612 + err = au_ren_may_dir(a);
21613 + if (unlikely(err))
21614 + goto out_children;
21616 + /* prepare the writable parent dir on the same branch */
21617 + if (a->dst_btop == a->btgt) {
21618 + au_fset_ren(a->auren_flags, WHDST);
21620 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21621 + if (unlikely(err))
21622 + goto out_children;
21626 + if (!a->exchange) {
21627 + if (a->src_dir != a->dst_dir) {
21629 + * this temporary unlock is safe,
21630 + * because both dir->i_mutex are locked.
21632 + di_write_unlock(a->dst_parent);
21633 + di_write_lock_parent(a->src_parent);
21634 + err = au_wr_dir_need_wh(a->src_dentry,
21635 + au_ftest_ren(a->auren_flags,
21638 + di_write_unlock(a->src_parent);
21639 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21641 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21643 + err = au_wr_dir_need_wh(a->src_dentry,
21644 + au_ftest_ren(a->auren_flags,
21648 + if (unlikely(err < 0))
21649 + goto out_children;
21651 + au_fset_ren(a->auren_flags, WHSRC);
21654 + if (a->src_btop != a->btgt) {
21655 + err = au_pin(&pin, a->src_dentry, a->btgt,
21656 + au_opt_udba(a->src_dentry->d_sb),
21657 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21659 + struct au_cp_generic cpg = {
21660 + .dentry = a->src_dentry,
21662 + .bsrc = a->src_btop,
21665 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21667 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21668 + err = au_sio_cpup_simple(&cpg);
21671 + if (unlikely(err))
21672 + goto out_children;
21673 + a->src_btop = a->btgt;
21674 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21675 + if (!a->exchange)
21676 + au_fset_ren(a->auren_flags, WHSRC);
21680 + if (a->exchange && a->dst_inode
21681 + && a->dst_btop != a->btgt) {
21682 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21683 + au_opt_udba(a->dst_dentry->d_sb),
21684 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21686 + struct au_cp_generic cpg = {
21687 + .dentry = a->dst_dentry,
21689 + .bsrc = a->dst_btop,
21692 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21694 + err = au_sio_cpup_simple(&cpg);
21697 + if (unlikely(err))
21698 + goto out_children;
21699 + a->dst_btop = a->btgt;
21700 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21703 + /* lock them all */
21704 + err = au_ren_lock(a);
21705 + if (unlikely(err))
21706 + /* leave the copied-up one */
21707 + goto out_children;
21709 + if (!a->exchange) {
21710 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21711 + err = au_may_ren(a);
21712 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21713 + err = -ENAMETOOLONG;
21714 + if (unlikely(err))
21718 + /* store timestamps to be revertible */
21722 + err = do_rename(a);
21723 + if (unlikely(err))
21726 + /* update dir attributes */
21727 + au_ren_refresh_dir(a);
21729 + /* dput/iput all lower dentries */
21730 + au_ren_refresh(a);
21732 + goto out_hdir; /* success */
21735 + au_ren_rev_dt(err, a);
21737 + au_ren_unlock(a);
21739 + au_nhash_wh_free(&a->whlist);
21740 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21741 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21742 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21743 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21747 + if (!a->exchange)
21748 + d_move(a->src_dentry, a->dst_dentry);
21750 + d_exchange(a->src_dentry, a->dst_dentry);
21752 + au_update_dbtop(a->dst_dentry);
21753 + if (!a->dst_inode)
21754 + d_drop(a->dst_dentry);
21756 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21757 + di_write_unlock(a->dst_parent);
21759 + di_write_unlock2(a->src_parent, a->dst_parent);
21761 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21763 + iput(a->dst_inode);
21765 + au_whtmp_rmdir_free(a->thargs);
21771 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21772 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21773 +++ linux/fs/aufs/Kconfig 2017-07-29 12:14:25.896375188 +0200
21776 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21778 + Aufs is a stackable unification filesystem such as Unionfs,
21779 + which unifies several directories and provides a merged single
21781 + In the early days, aufs was entirely re-designed and
21782 + re-implemented Unionfs Version 1.x series. Introducing many
21783 + original ideas, approaches and improvements, it becomes totally
21784 + different from Unionfs while keeping the basic features.
21788 + prompt "Maximum number of branches"
21789 + default AUFS_BRANCH_MAX_127
21791 + Specifies the maximum number of branches (or member directories)
21792 + in a single aufs. The larger value consumes more system
21793 + resources and has a minor impact to performance.
21794 +config 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_511
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_1023
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_32767
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.
21820 +config AUFS_SBILIST
21822 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21825 + Automatic configuration for internal use.
21826 + When aufs supports Magic SysRq or /proc, enabled automatically.
21828 +config AUFS_HNOTIFY
21829 + bool "Detect direct branch access (bypassing aufs)"
21831 + If you want to modify files on branches directly, eg. bypassing aufs,
21832 + and want aufs to detect the changes of them fully, then enable this
21833 + option and use 'udba=notify' mount option.
21834 + Currently there is only one available configuration, "fsnotify".
21835 + It will have a negative impact to the performance.
21836 + See detail in aufs.5.
21839 + prompt "method" if AUFS_HNOTIFY
21840 + default AUFS_HFSNOTIFY
21841 +config AUFS_HFSNOTIFY
21846 +config AUFS_EXPORT
21847 + bool "NFS-exportable aufs"
21848 + depends on EXPORTFS
21850 + If you want to export your mounted aufs via NFS, then enable this
21851 + option. There are several requirements for this configuration.
21852 + See detail in aufs.5.
21854 +config AUFS_INO_T_64
21856 + depends on AUFS_EXPORT
21857 + depends on 64BIT && !(ALPHA || S390)
21860 + Automatic configuration for internal use.
21861 + /* typedef unsigned long/int __kernel_ino_t */
21862 + /* alpha and s390x are int */
21865 + bool "support for XATTR/EA (including Security Labels)"
21867 + If your branch fs supports XATTR/EA and you want to make them
21868 + available in aufs too, then enable this opsion and specify the
21869 + branch attributes for EA.
21870 + See detail in aufs.5.
21873 + bool "File-based Hierarchical Storage Management"
21875 + Hierarchical Storage Management (or HSM) is a well-known feature
21876 + in the storage world. Aufs provides this feature as file-based.
21877 + with multiple branches.
21878 + These multiple branches are prioritized, ie. the topmost one
21879 + should be the fastest drive and be used heavily.
21882 + bool "Readdir in userspace"
21884 + Aufs has two methods to provide a merged view for a directory,
21885 + by a user-space library and by kernel-space natively. The latter
21886 + is always enabled but sometimes large and slow.
21887 + If you enable this option, install the library in aufs2-util
21888 + package, and set some environment variables for your readdir(3),
21889 + then the work will be handled in user-space which generally
21890 + shows better performance in most cases.
21891 + See detail in aufs.5.
21894 + bool "Show whiteouts"
21896 + If you want to make the whiteouts in aufs visible, then enable
21897 + this option and specify 'shwh' mount option. Although it may
21898 + sounds like philosophy or something, but in technically it
21899 + simply shows the name of whiteout with keeping its behaviour.
21901 +config AUFS_BR_RAMFS
21902 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21904 + If you want to use ramfs as an aufs branch fs, then enable this
21905 + option. Generally tmpfs is recommended.
21906 + Aufs prohibited them to be a branch fs by default, because
21907 + initramfs becomes unusable after switch_root or something
21908 + generally. If you sets initramfs as an aufs branch and boot your
21909 + system by switch_root, you will meet a problem easily since the
21910 + files in initramfs may be inaccessible.
21911 + Unless you are going to use ramfs as an aufs branch fs without
21912 + switch_root or something, leave it N.
21914 +config AUFS_BR_FUSE
21915 + bool "Fuse fs as an aufs branch"
21916 + depends on FUSE_FS
21919 + If you want to use fuse-based userspace filesystem as an aufs
21920 + branch fs, then enable this option.
21921 + It implements the internal poll(2) operation which is
21922 + implemented by fuse only (curretnly).
21927 + Automatic configuration for internal use.
21929 +config AUFS_BR_HFSPLUS
21930 + bool "Hfsplus as an aufs branch"
21931 + depends on HFSPLUS_FS
21934 + If you want to use hfsplus fs as an aufs branch fs, then enable
21935 + this option. This option introduces a small overhead at
21936 + copying-up a file on hfsplus.
21938 +config AUFS_BDEV_LOOP
21940 + depends on BLK_DEV_LOOP
21943 + Automatic configuration for internal use.
21944 + Convert =[ym] into =y.
21947 + bool "Debug aufs"
21949 + Enable this to compile aufs internal debug code.
21950 + It will have a negative impact to the performance.
21952 +config AUFS_MAGIC_SYSRQ
21954 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21957 + Automatic configuration for internal use.
21958 + When aufs supports Magic SysRq, enabled automatically.
21960 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21961 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21962 +++ linux/fs/aufs/loop.c 2017-07-29 12:14:25.903042072 +0200
21965 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21967 + * This program, aufs is free software; you can redistribute it and/or modify
21968 + * it under the terms of the GNU General Public License as published by
21969 + * the Free Software Foundation; either version 2 of the License, or
21970 + * (at your option) any later version.
21972 + * This program is distributed in the hope that it will be useful,
21973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21975 + * GNU General Public License for more details.
21977 + * You should have received a copy of the GNU General Public License
21978 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21982 + * support for loopback block device as a branch
21987 +/* added into drivers/block/loop.c */
21988 +static struct file *(*backing_file_func)(struct super_block *sb);
21991 + * test if two lower dentries have overlapping branches.
21993 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21995 + struct super_block *h_sb;
21996 + struct file *backing_file;
21998 + if (unlikely(!backing_file_func)) {
21999 + /* don't load "loop" module here */
22000 + backing_file_func = symbol_get(loop_backing_file);
22001 + if (unlikely(!backing_file_func))
22002 + /* "loop" module is not loaded */
22006 + h_sb = h_adding->d_sb;
22007 + backing_file = backing_file_func(h_sb);
22008 + if (!backing_file)
22011 + h_adding = backing_file->f_path.dentry;
22013 + * h_adding can be local NFS.
22014 + * in this case aufs cannot detect the loop.
22016 + if (unlikely(h_adding->d_sb == sb))
22018 + return !!au_test_subdir(h_adding, sb->s_root);
22021 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
22022 +int au_test_loopback_kthread(void)
22025 + struct task_struct *tsk = current;
22026 + char c, comm[sizeof(tsk->comm)];
22029 + if (tsk->flags & PF_KTHREAD) {
22030 + get_task_comm(comm, tsk);
22032 + ret = ('0' <= c && c <= '9'
22033 + && !strncmp(comm, "loop", 4));
22039 +/* ---------------------------------------------------------------------- */
22041 +#define au_warn_loopback_step 16
22042 +static int au_warn_loopback_nelem = au_warn_loopback_step;
22043 +static unsigned long *au_warn_loopback_array;
22045 +void au_warn_loopback(struct super_block *h_sb)
22047 + int i, new_nelem;
22048 + unsigned long *a, magic;
22049 + static DEFINE_SPINLOCK(spin);
22051 + magic = h_sb->s_magic;
22052 + spin_lock(&spin);
22053 + a = au_warn_loopback_array;
22054 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
22055 + if (a[i] == magic) {
22056 + spin_unlock(&spin);
22060 + /* h_sb is new to us, print it */
22061 + if (i < au_warn_loopback_nelem) {
22066 + /* expand the array */
22067 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
22068 + a = au_kzrealloc(au_warn_loopback_array,
22069 + au_warn_loopback_nelem * sizeof(unsigned long),
22070 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
22071 + /*may_shrink*/0);
22073 + au_warn_loopback_nelem = new_nelem;
22074 + au_warn_loopback_array = a;
22079 + spin_unlock(&spin);
22080 + AuWarn1("realloc failed, ignored\n");
22084 + spin_unlock(&spin);
22085 + pr_warn("you may want to try another patch for loopback file "
22086 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
22089 +int au_loopback_init(void)
22092 + struct super_block *sb __maybe_unused;
22094 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
22097 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
22098 + sizeof(unsigned long), GFP_NOFS);
22099 + if (unlikely(!au_warn_loopback_array))
22105 +void au_loopback_fin(void)
22107 + if (backing_file_func)
22108 + symbol_put(loop_backing_file);
22109 + kfree(au_warn_loopback_array);
22111 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
22112 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
22113 +++ linux/fs/aufs/loop.h 2017-07-29 12:14:25.903042072 +0200
22116 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22118 + * This program, aufs is free software; you can redistribute it and/or modify
22119 + * it under the terms of the GNU General Public License as published by
22120 + * the Free Software Foundation; either version 2 of the License, or
22121 + * (at your option) any later version.
22123 + * This program is distributed in the hope that it will be useful,
22124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22126 + * GNU General Public License for more details.
22128 + * You should have received a copy of the GNU General Public License
22129 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22133 + * support for loopback mount as a branch
22136 +#ifndef __AUFS_LOOP_H__
22137 +#define __AUFS_LOOP_H__
22142 +struct super_block;
22144 +#ifdef CONFIG_AUFS_BDEV_LOOP
22145 +/* drivers/block/loop.c */
22146 +struct file *loop_backing_file(struct super_block *sb);
22149 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
22150 +int au_test_loopback_kthread(void);
22151 +void au_warn_loopback(struct super_block *h_sb);
22153 +int au_loopback_init(void);
22154 +void au_loopback_fin(void);
22156 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
22157 + struct dentry *h_adding)
22158 +AuStubInt0(au_test_loopback_kthread, void)
22159 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
22161 +AuStubInt0(au_loopback_init, void)
22162 +AuStubVoid(au_loopback_fin, void)
22163 +#endif /* BLK_DEV_LOOP */
22165 +#endif /* __KERNEL__ */
22166 +#endif /* __AUFS_LOOP_H__ */
22167 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
22168 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
22169 +++ linux/fs/aufs/magic.mk 2017-07-29 12:14:25.903042072 +0200
22172 +# defined in ${srctree}/fs/fuse/inode.c
22174 +ifdef CONFIG_FUSE_FS
22175 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
22178 +# defined in ${srctree}/fs/xfs/xfs_sb.h
22180 +ifdef CONFIG_XFS_FS
22181 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
22184 +# defined in ${srctree}/fs/configfs/mount.c
22186 +ifdef CONFIG_CONFIGFS_FS
22187 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
22190 +# defined in ${srctree}/fs/ubifs/ubifs.h
22192 +ifdef CONFIG_UBIFS_FS
22193 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
22196 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22198 +ifdef CONFIG_HFSPLUS_FS
22199 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22201 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22202 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22203 +++ linux/fs/aufs/Makefile 2017-07-29 12:14:25.896375188 +0200
22206 +include ${src}/magic.mk
22207 +ifeq (${CONFIG_AUFS_FS},m)
22208 +include ${src}/conf.mk
22210 +-include ${src}/priv_def.mk
22212 +# cf. include/linux/kernel.h
22214 +ccflags-y += -DDEBUG
22215 +# sparse requires the full pathname
22217 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22219 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22222 +obj-$(CONFIG_AUFS_FS) += aufs.o
22223 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22224 + wkq.o vfsub.o dcsub.o \
22225 + cpup.o whout.o wbr_policy.o \
22226 + dinfo.o dentry.o \
22228 + finfo.o file.o f_op.o \
22230 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22234 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22235 +aufs-$(CONFIG_SYSFS) += sysfs.o
22236 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22237 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22238 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22239 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22240 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22241 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22242 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22243 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22244 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22245 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22246 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22247 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22248 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22249 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22250 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22251 +++ linux/fs/aufs/module.c 2017-07-29 12:14:25.903042072 +0200
22254 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22256 + * This program, aufs is free software; you can redistribute it and/or modify
22257 + * it under the terms of the GNU General Public License as published by
22258 + * the Free Software Foundation; either version 2 of the License, or
22259 + * (at your option) any later version.
22261 + * This program is distributed in the hope that it will be useful,
22262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22264 + * GNU General Public License for more details.
22266 + * You should have received a copy of the GNU General Public License
22267 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22271 + * module global variables and operations
22274 +#include <linux/module.h>
22275 +#include <linux/seq_file.h>
22278 +/* shrinkable realloc */
22279 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22287 +#if 0 /* unused */
22294 + AuDebugOn(!new_sz);
22297 + diff = au_kmidx_sub(sz, new_sz);
22303 + /* expand or SLOB */
22304 + p = krealloc(p, new_sz, gfp);
22305 + else if (new_sz < sz && may_shrink) {
22309 + q = kmalloc(new_sz, gfp);
22312 + memcpy(q, p, new_sz);
22324 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22327 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22328 + if (p && new_sz > nused)
22329 + memset(p + nused, 0, new_sz - nused);
22333 +/* ---------------------------------------------------------------------- */
22337 +struct kmem_cache *au_cache[AuCache_Last];
22339 +static void au_cache_fin(void)
22344 + * Make sure all delayed rcu free inodes are flushed before we
22349 + /* excluding AuCache_HNOTIFY */
22350 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22351 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22352 + kmem_cache_destroy(au_cache[i]);
22353 + au_cache[i] = NULL;
22357 +static int __init au_cache_init(void)
22359 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
22360 + if (au_cache[AuCache_DINFO])
22361 + /* SLAB_DESTROY_BY_RCU */
22362 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
22363 + au_icntnr_init_once);
22364 + if (au_cache[AuCache_ICNTNR])
22365 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
22366 + au_fi_init_once);
22367 + if (au_cache[AuCache_FINFO])
22368 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
22369 + if (au_cache[AuCache_VDIR])
22370 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
22371 + if (au_cache[AuCache_DEHSTR])
22378 +/* ---------------------------------------------------------------------- */
22380 +int au_dir_roflags;
22382 +#ifdef CONFIG_AUFS_SBILIST
22384 + * iterate_supers_type() doesn't protect us from
22385 + * remounting (branch management)
22387 +struct au_sphlhead au_sbilist;
22391 + * functions for module interface.
22393 +MODULE_LICENSE("GPL");
22394 +/* MODULE_LICENSE("GPL v2"); */
22395 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22396 +MODULE_DESCRIPTION(AUFS_NAME
22397 + " -- Advanced multi layered unification filesystem");
22398 +MODULE_VERSION(AUFS_VERSION);
22399 +MODULE_ALIAS_FS(AUFS_NAME);
22401 +/* this module parameter has no meaning when SYSFS is disabled */
22402 +int sysaufs_brs = 1;
22403 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22404 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22406 +/* this module parameter has no meaning when USER_NS is disabled */
22408 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22409 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22411 +/* ---------------------------------------------------------------------- */
22413 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22415 +int au_seq_path(struct seq_file *seq, struct path *path)
22419 + err = seq_path(seq, path, au_esc_chars);
22428 +/* ---------------------------------------------------------------------- */
22430 +static int __init aufs_init(void)
22435 + p = au_esc_chars;
22436 + for (i = 1; i <= ' '; i++)
22442 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22444 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22445 + for (i = 0; i < AuIop_Last; i++)
22446 + aufs_iop_nogetattr[i].getattr = NULL;
22448 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
22450 + au_sbilist_init();
22451 + sysaufs_brs_init();
22454 + err = sysaufs_init();
22455 + if (unlikely(err))
22457 + err = au_procfs_init();
22458 + if (unlikely(err))
22459 + goto out_sysaufs;
22460 + err = au_wkq_init();
22461 + if (unlikely(err))
22463 + err = au_loopback_init();
22464 + if (unlikely(err))
22466 + err = au_hnotify_init();
22467 + if (unlikely(err))
22468 + goto out_loopback;
22469 + err = au_sysrq_init();
22470 + if (unlikely(err))
22472 + err = au_cache_init();
22473 + if (unlikely(err))
22476 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22477 + err = register_filesystem(&aufs_fs_type);
22478 + if (unlikely(err))
22481 + /* since we define pr_fmt, call printk directly */
22482 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22483 + goto out; /* success */
22490 + au_hnotify_fin();
22492 + au_loopback_fin();
22504 +static void __exit aufs_exit(void)
22506 + unregister_filesystem(&aufs_fs_type);
22509 + au_hnotify_fin();
22510 + au_loopback_fin();
22517 +module_init(aufs_init);
22518 +module_exit(aufs_exit);
22519 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22520 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22521 +++ linux/fs/aufs/module.h 2017-07-29 12:14:25.903042072 +0200
22524 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22526 + * This program, aufs is free software; you can redistribute it and/or modify
22527 + * it under the terms of the GNU General Public License as published by
22528 + * the Free Software Foundation; either version 2 of the License, or
22529 + * (at your option) any later version.
22531 + * This program is distributed in the hope that it will be useful,
22532 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22533 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22534 + * GNU General Public License for more details.
22536 + * You should have received a copy of the GNU General Public License
22537 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22541 + * module initialization and module-global
22544 +#ifndef __AUFS_MODULE_H__
22545 +#define __AUFS_MODULE_H__
22549 +#include <linux/slab.h>
22554 +/* module parameters */
22555 +extern int sysaufs_brs;
22556 +extern bool au_userns;
22558 +/* ---------------------------------------------------------------------- */
22560 +extern int au_dir_roflags;
22562 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22563 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22566 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22568 +#ifndef CONFIG_SLOB
22569 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22571 + return -1; /* SLOB is untested */
22575 +int au_seq_path(struct seq_file *seq, struct path *path);
22577 +#ifdef CONFIG_PROC_FS
22579 +int __init au_procfs_init(void);
22580 +void au_procfs_fin(void);
22582 +AuStubInt0(au_procfs_init, void);
22583 +AuStubVoid(au_procfs_fin, void);
22586 +/* ---------------------------------------------------------------------- */
22595 + AuCache_HNOTIFY, /* must be last */
22599 +extern struct kmem_cache *au_cache[AuCache_Last];
22601 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22602 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22603 +#define AuCacheCtor(type, ctor) \
22604 + kmem_cache_create(#type, sizeof(struct type), \
22605 + __alignof__(struct type), AuCacheFlags, ctor)
22607 +#define AuCacheFuncs(name, index) \
22608 +static inline struct au_##name *au_cache_alloc_##name(void) \
22609 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
22610 +static inline void au_cache_free_##name(struct au_##name *p) \
22611 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
22613 +AuCacheFuncs(dinfo, DINFO);
22614 +AuCacheFuncs(icntnr, ICNTNR);
22615 +AuCacheFuncs(finfo, FINFO);
22616 +AuCacheFuncs(vdir, VDIR);
22617 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22618 +#ifdef CONFIG_AUFS_HNOTIFY
22619 +AuCacheFuncs(hnotify, HNOTIFY);
22622 +#endif /* __KERNEL__ */
22623 +#endif /* __AUFS_MODULE_H__ */
22624 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22625 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22626 +++ linux/fs/aufs/mvdown.c 2017-07-29 12:14:25.903042072 +0200
22629 + * Copyright (C) 2011-2017 Junjiro R. Okajima
22631 + * This program, aufs is free software; you can redistribute it and/or modify
22632 + * it under the terms of the GNU General Public License as published by
22633 + * the Free Software Foundation; either version 2 of the License, or
22634 + * (at your option) any later version.
22636 + * This program is distributed in the hope that it will be useful,
22637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22639 + * GNU General Public License for more details.
22641 + * You should have received a copy of the GNU General Public License
22642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22646 + * move-down, opposite of copy-up
22651 +struct au_mvd_args {
22653 + struct super_block *h_sb;
22654 + struct dentry *h_parent;
22655 + struct au_hinode *hdir;
22656 + struct inode *h_dir, *h_inode;
22657 + struct au_pin pin;
22658 + } info[AUFS_MVDOWN_NARRAY];
22660 + struct aufs_mvdown mvdown;
22661 + struct dentry *dentry, *parent;
22662 + struct inode *inode, *dir;
22663 + struct super_block *sb;
22664 + aufs_bindex_t bopq, bwh, bfound;
22665 + unsigned char rename_lock;
22668 +#define mvd_errno mvdown.au_errno
22669 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22670 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22671 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22672 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22674 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22675 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22676 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22677 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22678 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22679 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22681 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22682 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22683 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22684 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22685 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22686 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22688 +#define AU_MVD_PR(flag, ...) do { \
22690 + pr_err(__VA_ARGS__); \
22693 +static int find_lower_writable(struct au_mvd_args *a)
22695 + struct super_block *sb;
22696 + aufs_bindex_t bindex, bbot;
22697 + struct au_branch *br;
22700 + bindex = a->mvd_bsrc;
22701 + bbot = au_sbbot(sb);
22702 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22703 + for (bindex++; bindex <= bbot; bindex++) {
22704 + br = au_sbr(sb, bindex);
22705 + if (au_br_fhsm(br->br_perm)
22706 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22709 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22710 + for (bindex++; bindex <= bbot; bindex++) {
22711 + br = au_sbr(sb, bindex);
22712 + if (!au_br_rdonly(br))
22716 + for (bindex++; bindex <= bbot; bindex++) {
22717 + br = au_sbr(sb, bindex);
22718 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22719 + if (au_br_rdonly(br))
22721 + |= AUFS_MVDOWN_ROLOWER_R;
22729 +/* make the parent dir on bdst */
22730 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22735 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22736 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22737 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22738 + a->mvd_h_dst_parent = NULL;
22739 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22740 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22741 + if (!a->mvd_h_dst_parent) {
22742 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22743 + if (unlikely(err)) {
22744 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22747 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22755 +/* lock them all */
22756 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22759 + struct dentry *h_trap;
22761 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22762 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22763 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22764 + au_opt_udba(a->sb),
22765 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22767 + if (unlikely(err)) {
22768 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22772 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22773 + a->rename_lock = 0;
22774 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22775 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22776 + au_opt_udba(a->sb),
22777 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22778 + err = au_do_pin(&a->mvd_pin_src);
22780 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22781 + if (unlikely(err)) {
22782 + AU_MVD_PR(dmsg, "pin_src failed\n");
22785 + goto out; /* success */
22788 + a->rename_lock = 1;
22789 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22790 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22791 + au_opt_udba(a->sb),
22792 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22794 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22795 + if (unlikely(err)) {
22796 + AU_MVD_PR(dmsg, "pin_src failed\n");
22797 + au_pin_hdir_lock(&a->mvd_pin_dst);
22800 + au_pin_hdir_unlock(&a->mvd_pin_src);
22801 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22802 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22804 + err = (h_trap != a->mvd_h_src_parent);
22806 + err = (h_trap != a->mvd_h_dst_parent);
22808 + BUG_ON(err); /* it should never happen */
22809 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22812 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22813 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22814 + au_pin_hdir_lock(&a->mvd_pin_src);
22815 + au_unpin(&a->mvd_pin_src);
22816 + au_pin_hdir_lock(&a->mvd_pin_dst);
22819 + goto out; /* success */
22822 + au_unpin(&a->mvd_pin_dst);
22828 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22830 + if (!a->rename_lock)
22831 + au_unpin(&a->mvd_pin_src);
22833 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22834 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22835 + au_pin_hdir_lock(&a->mvd_pin_src);
22836 + au_unpin(&a->mvd_pin_src);
22837 + au_pin_hdir_lock(&a->mvd_pin_dst);
22839 + au_unpin(&a->mvd_pin_dst);
22842 +/* copy-down the file */
22843 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22846 + struct au_cp_generic cpg = {
22847 + .dentry = a->dentry,
22848 + .bdst = a->mvd_bdst,
22849 + .bsrc = a->mvd_bsrc,
22851 + .pin = &a->mvd_pin_dst,
22852 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22855 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22856 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22857 + au_fset_cpup(cpg.flags, OVERWRITE);
22858 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22859 + au_fset_cpup(cpg.flags, RWDST);
22860 + err = au_sio_cpdown_simple(&cpg);
22861 + if (unlikely(err))
22862 + AU_MVD_PR(dmsg, "cpdown failed\n");
22869 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22872 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22875 + struct path h_path;
22876 + struct au_branch *br;
22877 + struct inode *delegated;
22879 + br = au_sbr(a->sb, a->mvd_bdst);
22880 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22881 + err = PTR_ERR(h_path.dentry);
22882 + if (IS_ERR(h_path.dentry)) {
22883 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22888 + if (d_is_positive(h_path.dentry)) {
22889 + h_path.mnt = au_br_mnt(br);
22890 + delegated = NULL;
22891 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22892 + &delegated, /*force*/0);
22893 + if (unlikely(err == -EWOULDBLOCK)) {
22894 + pr_warn("cannot retry for NFSv4 delegation"
22895 + " for an internal unlink\n");
22898 + if (unlikely(err))
22899 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22901 + dput(h_path.dentry);
22909 + * unlink the topmost h_dentry
22911 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22914 + struct path h_path;
22915 + struct inode *delegated;
22917 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22918 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22919 + delegated = NULL;
22920 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22921 + if (unlikely(err == -EWOULDBLOCK)) {
22922 + pr_warn("cannot retry for NFSv4 delegation"
22923 + " for an internal unlink\n");
22926 + if (unlikely(err))
22927 + AU_MVD_PR(dmsg, "unlink failed\n");
22933 +/* Since mvdown succeeded, we ignore an error of this function */
22934 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22937 + struct au_branch *br;
22939 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22940 + br = au_sbr(a->sb, a->mvd_bsrc);
22941 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22943 + br = au_sbr(a->sb, a->mvd_bdst);
22944 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22945 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22948 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22950 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22954 + * copy-down the file and unlink the bsrc file.
22955 + * - unlink the bdst whout if exist
22956 + * - copy-down the file (with whtmp name and rename)
22957 + * - unlink the bsrc file
22959 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22963 + err = au_do_mkdir(dmsg, a);
22965 + err = au_do_lock(dmsg, a);
22966 + if (unlikely(err))
22970 + * do not revert the activities we made on bdst since they should be
22971 + * harmless in aufs.
22974 + err = au_do_cpdown(dmsg, a);
22976 + err = au_do_unlink_wh(dmsg, a);
22977 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22978 + err = au_do_unlink(dmsg, a);
22979 + if (unlikely(err))
22982 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22983 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22984 + if (find_lower_writable(a) < 0)
22985 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22987 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22988 + au_do_stfs(dmsg, a);
22990 + /* maintain internal array */
22991 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22992 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22993 + au_set_dbtop(a->dentry, a->mvd_bdst);
22994 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22995 + au_set_ibtop(a->inode, a->mvd_bdst);
22997 + /* hide the lower */
22998 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22999 + au_set_dbbot(a->dentry, a->mvd_bsrc);
23000 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
23001 + au_set_ibbot(a->inode, a->mvd_bsrc);
23003 + if (au_dbbot(a->dentry) < a->mvd_bdst)
23004 + au_set_dbbot(a->dentry, a->mvd_bdst);
23005 + if (au_ibbot(a->inode) < a->mvd_bdst)
23006 + au_set_ibbot(a->inode, a->mvd_bdst);
23009 + au_do_unlock(dmsg, a);
23015 +/* ---------------------------------------------------------------------- */
23017 +/* make sure the file is idle */
23018 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
23020 + int err, plinked;
23023 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
23024 + if (au_dbtop(a->dentry) == a->mvd_bsrc
23025 + && au_dcount(a->dentry) == 1
23026 + && atomic_read(&a->inode->i_count) == 1
23027 + /* && a->mvd_h_src_inode->i_nlink == 1 */
23028 + && (!plinked || !au_plink_test(a->inode))
23029 + && a->inode->i_nlink == 1)
23034 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
23035 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
23036 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
23037 + a->mvd_h_src_inode->i_nlink,
23038 + plinked, plinked ? au_plink_test(a->inode) : 0);
23045 +/* make sure the parent dir is fine */
23046 +static int au_mvd_args_parent(const unsigned char dmsg,
23047 + struct au_mvd_args *a)
23050 + aufs_bindex_t bindex;
23053 + if (unlikely(au_alive_dir(a->parent))) {
23055 + AU_MVD_PR(dmsg, "parent dir is dead\n");
23059 + a->bopq = au_dbdiropq(a->parent);
23060 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
23061 + AuDbg("b%d\n", bindex);
23062 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
23063 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
23065 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
23066 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
23067 + a->bopq, a->mvd_bdst);
23075 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23076 + struct au_mvd_args *a)
23079 + struct au_dinfo *dinfo, *tmp;
23081 + /* lookup the next lower positive entry */
23083 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23084 + if (unlikely(!tmp))
23089 + dinfo = au_di(a->dentry);
23090 + au_di_cp(tmp, dinfo);
23091 + au_di_swap(tmp, dinfo);
23093 + /* returns the number of positive dentries */
23094 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23095 + /* AuLkup_IGNORE_PERM */ 0);
23097 + a->bwh = au_dbwh(a->dentry);
23098 + else if (err > 0)
23099 + a->bfound = au_dbtop(a->dentry);
23101 + au_di_swap(tmp, dinfo);
23102 + au_rw_write_unlock(&tmp->di_rwsem);
23104 + if (unlikely(err < 0))
23105 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23108 + * here, we have these cases.
23110 + * no positive dentry under bsrc. there are more sub-cases.
23112 + * there no whiteout, we can safely move-down.
23115 + * bsrc < bwh && bwh < bdst
23116 + * there is a whiteout on RO branch. cannot proceed.
23118 + * there is a whiteout on the RW target branch. it should
23121 + * there is a whiteout somewhere unrelated branch.
23122 + * -1 < bfound && bfound <= bsrc
23125 + * found, but it is on RO branch between bsrc and bdst. cannot
23128 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23131 + * found, after we create the file on bdst, it will be hidden.
23134 + AuDebugOn(a->bfound == -1
23136 + && a->bwh <= a->mvd_bsrc);
23137 + AuDebugOn(-1 < a->bfound
23138 + && a->bfound <= a->mvd_bsrc);
23141 + if (a->bfound == -1
23142 + && a->mvd_bsrc < a->bwh
23144 + && a->bwh < a->mvd_bdst) {
23145 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23146 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23147 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23149 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23150 + a->mvd_errno = EAU_MVDOWN_UPPER;
23151 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23152 + a->mvd_bdst, a->bfound);
23156 + err = 0; /* success */
23163 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23168 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23169 + && a->bfound == a->mvd_bdst)
23175 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23178 + struct au_branch *br;
23181 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23185 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23186 + a->mvd_bsrc = au_ibtop(a->inode);
23188 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23189 + if (unlikely(a->mvd_bsrc < 0
23190 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23191 + || au_dbbot(a->dentry) < a->mvd_bsrc
23192 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23193 + || (a->mvd_bsrc < au_ibtop(a->inode)
23194 + || au_ibbot(a->inode) < a->mvd_bsrc
23195 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23196 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23197 + AU_MVD_PR(dmsg, "no upper\n");
23201 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23202 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23203 + AU_MVD_PR(dmsg, "on the bottom\n");
23206 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23207 + br = au_sbr(a->sb, a->mvd_bsrc);
23208 + err = au_br_rdonly(br);
23209 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23210 + if (unlikely(err))
23212 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23213 + || IS_APPEND(a->mvd_h_src_inode))) {
23215 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23221 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23222 + a->mvd_bdst = find_lower_writable(a);
23223 + if (unlikely(a->mvd_bdst < 0)) {
23224 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23225 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23229 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23230 + if (unlikely(a->mvd_bdst < 0
23231 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23232 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23233 + AU_MVD_PR(dmsg, "no lower brid\n");
23238 + err = au_mvd_args_busy(dmsg, a);
23240 + err = au_mvd_args_parent(dmsg, a);
23242 + err = au_mvd_args_intermediate(dmsg, a);
23244 + err = au_mvd_args_exist(dmsg, a);
23246 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23253 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23256 + unsigned char dmsg;
23257 + struct au_mvd_args *args;
23258 + struct inode *inode;
23260 + inode = d_inode(dentry);
23262 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23266 + args = kmalloc(sizeof(*args), GFP_NOFS);
23267 + if (unlikely(!args))
23270 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23272 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23273 + if (unlikely(err)) {
23278 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23279 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23280 + args->mvdown.au_errno = 0;
23281 + args->dentry = dentry;
23282 + args->inode = inode;
23283 + args->sb = dentry->d_sb;
23286 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23287 + args->parent = dget_parent(dentry);
23288 + args->dir = d_inode(args->parent);
23289 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23290 + dput(args->parent);
23291 + if (unlikely(args->parent != dentry->d_parent)) {
23292 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23296 + inode_lock_nested(inode, I_MUTEX_CHILD);
23297 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23298 + if (unlikely(err))
23301 + di_write_lock_parent(args->parent);
23302 + err = au_mvd_args(dmsg, args);
23303 + if (unlikely(err))
23306 + err = au_do_mvdown(dmsg, args);
23307 + if (unlikely(err))
23310 + au_cpup_attr_timesizes(args->dir);
23311 + au_cpup_attr_timesizes(inode);
23312 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23313 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23314 + /* au_digen_dec(dentry); */
23317 + di_write_unlock(args->parent);
23318 + aufs_read_unlock(dentry, AuLock_DW);
23320 + inode_unlock(inode);
23322 + inode_unlock(args->dir);
23324 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23332 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23333 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23334 +++ linux/fs/aufs/opts.c 2017-07-29 12:14:25.903042072 +0200
23337 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23339 + * This program, aufs is free software; you can redistribute it and/or modify
23340 + * it under the terms of the GNU General Public License as published by
23341 + * the Free Software Foundation; either version 2 of the License, or
23342 + * (at your option) any later version.
23344 + * This program is distributed in the hope that it will be useful,
23345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23347 + * GNU General Public License for more details.
23349 + * You should have received a copy of the GNU General Public License
23350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23354 + * mount options/flags
23357 +#include <linux/namei.h>
23358 +#include <linux/types.h> /* a distribution requires */
23359 +#include <linux/parser.h>
23362 +/* ---------------------------------------------------------------------- */
23366 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23367 + Opt_idel, Opt_imod,
23368 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23369 + Opt_rdblk_def, Opt_rdhash_def,
23370 + Opt_xino, Opt_noxino,
23371 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23372 + Opt_trunc_xino_path, Opt_itrunc_xino,
23373 + Opt_trunc_xib, Opt_notrunc_xib,
23374 + Opt_shwh, Opt_noshwh,
23375 + Opt_plink, Opt_noplink, Opt_list_plink,
23377 + Opt_dio, Opt_nodio,
23378 + Opt_diropq_a, Opt_diropq_w,
23379 + Opt_warn_perm, Opt_nowarn_perm,
23380 + Opt_wbr_copyup, Opt_wbr_create,
23382 + Opt_verbose, Opt_noverbose,
23383 + Opt_sum, Opt_nosum, Opt_wsum,
23384 + Opt_dirperm1, Opt_nodirperm1,
23385 + Opt_acl, Opt_noacl,
23386 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23389 +static match_table_t options = {
23390 + {Opt_br, "br=%s"},
23391 + {Opt_br, "br:%s"},
23393 + {Opt_add, "add=%d:%s"},
23394 + {Opt_add, "add:%d:%s"},
23395 + {Opt_add, "ins=%d:%s"},
23396 + {Opt_add, "ins:%d:%s"},
23397 + {Opt_append, "append=%s"},
23398 + {Opt_append, "append:%s"},
23399 + {Opt_prepend, "prepend=%s"},
23400 + {Opt_prepend, "prepend:%s"},
23402 + {Opt_del, "del=%s"},
23403 + {Opt_del, "del:%s"},
23404 + /* {Opt_idel, "idel:%d"}, */
23405 + {Opt_mod, "mod=%s"},
23406 + {Opt_mod, "mod:%s"},
23407 + /* {Opt_imod, "imod:%d:%s"}, */
23409 + {Opt_dirwh, "dirwh=%d"},
23411 + {Opt_xino, "xino=%s"},
23412 + {Opt_noxino, "noxino"},
23413 + {Opt_trunc_xino, "trunc_xino"},
23414 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23415 + {Opt_notrunc_xino, "notrunc_xino"},
23416 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23417 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23418 + /* {Opt_zxino, "zxino=%s"}, */
23419 + {Opt_trunc_xib, "trunc_xib"},
23420 + {Opt_notrunc_xib, "notrunc_xib"},
23422 +#ifdef CONFIG_PROC_FS
23423 + {Opt_plink, "plink"},
23425 + {Opt_ignore_silent, "plink"},
23428 + {Opt_noplink, "noplink"},
23430 +#ifdef CONFIG_AUFS_DEBUG
23431 + {Opt_list_plink, "list_plink"},
23434 + {Opt_udba, "udba=%s"},
23436 + {Opt_dio, "dio"},
23437 + {Opt_nodio, "nodio"},
23439 +#ifdef CONFIG_AUFS_FHSM
23440 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23442 + {Opt_ignore_silent, "fhsm_sec=%d"},
23445 + {Opt_diropq_a, "diropq=always"},
23446 + {Opt_diropq_a, "diropq=a"},
23447 + {Opt_diropq_w, "diropq=whiteouted"},
23448 + {Opt_diropq_w, "diropq=w"},
23450 + {Opt_warn_perm, "warn_perm"},
23451 + {Opt_nowarn_perm, "nowarn_perm"},
23453 + /* keep them temporary */
23454 + {Opt_ignore_silent, "nodlgt"},
23455 + {Opt_ignore_silent, "clean_plink"},
23457 +#ifdef CONFIG_AUFS_SHWH
23458 + {Opt_shwh, "shwh"},
23460 + {Opt_noshwh, "noshwh"},
23462 + {Opt_dirperm1, "dirperm1"},
23463 + {Opt_nodirperm1, "nodirperm1"},
23465 + {Opt_verbose, "verbose"},
23466 + {Opt_verbose, "v"},
23467 + {Opt_noverbose, "noverbose"},
23468 + {Opt_noverbose, "quiet"},
23469 + {Opt_noverbose, "q"},
23470 + {Opt_noverbose, "silent"},
23472 + {Opt_sum, "sum"},
23473 + {Opt_nosum, "nosum"},
23474 + {Opt_wsum, "wsum"},
23476 + {Opt_rdcache, "rdcache=%d"},
23477 + {Opt_rdblk, "rdblk=%d"},
23478 + {Opt_rdblk_def, "rdblk=def"},
23479 + {Opt_rdhash, "rdhash=%d"},
23480 + {Opt_rdhash_def, "rdhash=def"},
23482 + {Opt_wbr_create, "create=%s"},
23483 + {Opt_wbr_create, "create_policy=%s"},
23484 + {Opt_wbr_copyup, "cpup=%s"},
23485 + {Opt_wbr_copyup, "copyup=%s"},
23486 + {Opt_wbr_copyup, "copyup_policy=%s"},
23488 + /* generic VFS flag */
23489 +#ifdef CONFIG_FS_POSIX_ACL
23490 + {Opt_acl, "acl"},
23491 + {Opt_noacl, "noacl"},
23493 + {Opt_ignore_silent, "acl"},
23494 + {Opt_ignore_silent, "noacl"},
23497 + /* internal use for the scripts */
23498 + {Opt_ignore_silent, "si=%s"},
23500 + {Opt_br, "dirs=%s"},
23501 + {Opt_ignore, "debug=%d"},
23502 + {Opt_ignore, "delete=whiteout"},
23503 + {Opt_ignore, "delete=all"},
23504 + {Opt_ignore, "imap=%s"},
23506 + /* temporary workaround, due to old mount(8)? */
23507 + {Opt_ignore_silent, "relatime"},
23512 +/* ---------------------------------------------------------------------- */
23514 +static const char *au_parser_pattern(int val, match_table_t tbl)
23516 + struct match_token *p;
23519 + while (p->pattern) {
23520 + if (p->token == val)
23521 + return p->pattern;
23528 +static const char *au_optstr(int *val, match_table_t tbl)
23530 + struct match_token *p;
23537 + while (p->pattern) {
23539 + && (v & p->token) == p->token) {
23540 + *val &= ~p->token;
23541 + return p->pattern;
23550 +/* ---------------------------------------------------------------------- */
23552 +static match_table_t brperm = {
23553 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23554 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23555 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23559 +static match_table_t brattr = {
23561 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23562 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23563 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23564 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23565 +#ifdef CONFIG_AUFS_FHSM
23566 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23568 +#ifdef CONFIG_AUFS_XATTR
23569 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23570 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23571 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23572 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23573 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23574 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23577 + /* ro/rr branch */
23578 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23581 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23582 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23587 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23594 + p = strchr(str, '+');
23597 + v = match_token(str, table, args);
23599 + if (v & AuBrAttr_CMOO_Mask)
23600 + attr &= ~AuBrAttr_CMOO_Mask;
23605 + pr_warn("ignored branch attribute %s\n", str);
23615 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23623 + p = au_optstr(&perm, brattr);
23626 + memcpy(q, p, sz + 1);
23632 + p = au_optstr(&perm, brattr);
23636 + memcpy(q, p, sz + 1);
23642 + return q - str->a;
23645 +static int noinline_for_stack br_perm_val(char *perm)
23647 + int val, bad, sz;
23649 + substring_t args[MAX_OPT_ARGS];
23650 + au_br_perm_str_t attr;
23652 + p = strchr(perm, '+');
23655 + val = match_token(perm, brperm, args);
23659 + pr_warn("ignored branch permission %s\n", perm);
23660 + val = AuBrPerm_RO;
23666 + val |= br_attr_val(p + 1, brattr, args);
23669 + switch (val & AuBrPerm_Mask) {
23670 + case AuBrPerm_RO:
23671 + case AuBrPerm_RR:
23672 + bad = val & AuBrWAttr_Mask;
23673 + val &= ~AuBrWAttr_Mask;
23675 + case AuBrPerm_RW:
23676 + bad = val & AuBrRAttr_Mask;
23677 + val &= ~AuBrRAttr_Mask;
23682 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23683 + * does not treat it as an error, just warning.
23684 + * this is a tiny guard for the user operation.
23686 + if (val & AuBrAttr_UNPIN) {
23687 + bad |= AuBrAttr_UNPIN;
23688 + val &= ~AuBrAttr_UNPIN;
23691 + if (unlikely(bad)) {
23692 + sz = au_do_optstr_br_attr(&attr, bad);
23694 + pr_warn("ignored branch attribute %s\n", attr.a);
23701 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23703 + au_br_perm_str_t attr;
23709 + p = au_optstr(&perm, brperm);
23710 + AuDebugOn(!p || !*p);
23712 + memcpy(q, p, sz + 1);
23715 + sz = au_do_optstr_br_attr(&attr, perm);
23718 + memcpy(q, attr.a, sz + 1);
23721 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23724 +/* ---------------------------------------------------------------------- */
23726 +static match_table_t udbalevel = {
23727 + {AuOpt_UDBA_REVAL, "reval"},
23728 + {AuOpt_UDBA_NONE, "none"},
23729 +#ifdef CONFIG_AUFS_HNOTIFY
23730 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23731 +#ifdef CONFIG_AUFS_HFSNOTIFY
23732 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23738 +static int noinline_for_stack udba_val(char *str)
23740 + substring_t args[MAX_OPT_ARGS];
23742 + return match_token(str, udbalevel, args);
23745 +const char *au_optstr_udba(int udba)
23747 + return au_parser_pattern(udba, udbalevel);
23750 +/* ---------------------------------------------------------------------- */
23752 +static match_table_t au_wbr_create_policy = {
23753 + {AuWbrCreate_TDP, "tdp"},
23754 + {AuWbrCreate_TDP, "top-down-parent"},
23755 + {AuWbrCreate_RR, "rr"},
23756 + {AuWbrCreate_RR, "round-robin"},
23757 + {AuWbrCreate_MFS, "mfs"},
23758 + {AuWbrCreate_MFS, "most-free-space"},
23759 + {AuWbrCreate_MFSV, "mfs:%d"},
23760 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23762 + /* top-down regardless the parent, and then mfs */
23763 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23764 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23766 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23767 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23768 + {AuWbrCreate_PMFS, "pmfs"},
23769 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23770 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23771 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23776 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23777 + struct au_opt_wbr_create *create)
23780 + unsigned long long ull;
23783 + if (!match_u64(arg, &ull))
23784 + create->mfsrr_watermark = ull;
23786 + pr_err("bad integer in %s\n", str);
23793 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23794 + struct au_opt_wbr_create *create)
23799 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23800 + create->mfs_second = n;
23802 + pr_err("bad integer in %s\n", str);
23809 +static int noinline_for_stack
23810 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23813 + substring_t args[MAX_OPT_ARGS];
23815 + err = match_token(str, au_wbr_create_policy, args);
23816 + create->wbr_create = err;
23818 + case AuWbrCreate_MFSRRV:
23819 + case AuWbrCreate_TDMFSV:
23820 + case AuWbrCreate_PMFSRRV:
23821 + e = au_wbr_mfs_wmark(&args[0], str, create);
23823 + e = au_wbr_mfs_sec(&args[1], str, create);
23827 + case AuWbrCreate_MFSRR:
23828 + case AuWbrCreate_TDMFS:
23829 + case AuWbrCreate_PMFSRR:
23830 + e = au_wbr_mfs_wmark(&args[0], str, create);
23831 + if (unlikely(e)) {
23836 + case AuWbrCreate_MFS:
23837 + case AuWbrCreate_PMFS:
23838 + create->mfs_second = AUFS_MFS_DEF_SEC;
23840 + case AuWbrCreate_MFSV:
23841 + case AuWbrCreate_PMFSV:
23842 + e = au_wbr_mfs_sec(&args[0], str, create);
23851 +const char *au_optstr_wbr_create(int wbr_create)
23853 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23856 +static match_table_t au_wbr_copyup_policy = {
23857 + {AuWbrCopyup_TDP, "tdp"},
23858 + {AuWbrCopyup_TDP, "top-down-parent"},
23859 + {AuWbrCopyup_BUP, "bup"},
23860 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23861 + {AuWbrCopyup_BU, "bu"},
23862 + {AuWbrCopyup_BU, "bottom-up"},
23866 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23868 + substring_t args[MAX_OPT_ARGS];
23870 + return match_token(str, au_wbr_copyup_policy, args);
23873 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23875 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23878 +/* ---------------------------------------------------------------------- */
23880 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23882 +static void dump_opts(struct au_opts *opts)
23884 +#ifdef CONFIG_AUFS_DEBUG
23885 + /* reduce stack space */
23887 + struct au_opt_add *add;
23888 + struct au_opt_del *del;
23889 + struct au_opt_mod *mod;
23890 + struct au_opt_xino *xino;
23891 + struct au_opt_xino_itrunc *xino_itrunc;
23892 + struct au_opt_wbr_create *create;
23894 + struct au_opt *opt;
23897 + while (opt->type != Opt_tail) {
23898 + switch (opt->type) {
23900 + u.add = &opt->add;
23901 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23902 + u.add->bindex, u.add->pathname, u.add->perm,
23903 + u.add->path.dentry);
23907 + u.del = &opt->del;
23908 + AuDbg("del {%s, %p}\n",
23909 + u.del->pathname, u.del->h_path.dentry);
23913 + u.mod = &opt->mod;
23914 + AuDbg("mod {%s, 0x%x, %p}\n",
23915 + u.mod->path, u.mod->perm, u.mod->h_root);
23918 + u.add = &opt->add;
23919 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23920 + u.add->bindex, u.add->pathname, u.add->perm,
23921 + u.add->path.dentry);
23923 + case Opt_prepend:
23924 + u.add = &opt->add;
23925 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23926 + u.add->bindex, u.add->pathname, u.add->perm,
23927 + u.add->path.dentry);
23930 + AuDbg("dirwh %d\n", opt->dirwh);
23932 + case Opt_rdcache:
23933 + AuDbg("rdcache %d\n", opt->rdcache);
23936 + AuDbg("rdblk %u\n", opt->rdblk);
23938 + case Opt_rdblk_def:
23939 + AuDbg("rdblk_def\n");
23942 + AuDbg("rdhash %u\n", opt->rdhash);
23944 + case Opt_rdhash_def:
23945 + AuDbg("rdhash_def\n");
23948 + u.xino = &opt->xino;
23949 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23951 + case Opt_trunc_xino:
23952 + AuLabel(trunc_xino);
23954 + case Opt_notrunc_xino:
23955 + AuLabel(notrunc_xino);
23957 + case Opt_trunc_xino_path:
23958 + case Opt_itrunc_xino:
23959 + u.xino_itrunc = &opt->xino_itrunc;
23960 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23965 + case Opt_trunc_xib:
23966 + AuLabel(trunc_xib);
23968 + case Opt_notrunc_xib:
23969 + AuLabel(notrunc_xib);
23977 + case Opt_dirperm1:
23978 + AuLabel(dirperm1);
23980 + case Opt_nodirperm1:
23981 + AuLabel(nodirperm1);
23986 + case Opt_noplink:
23987 + AuLabel(noplink);
23989 + case Opt_list_plink:
23990 + AuLabel(list_plink);
23993 + AuDbg("udba %d, %s\n",
23994 + opt->udba, au_optstr_udba(opt->udba));
24002 + case Opt_diropq_a:
24003 + AuLabel(diropq_a);
24005 + case Opt_diropq_w:
24006 + AuLabel(diropq_w);
24008 + case Opt_warn_perm:
24009 + AuLabel(warn_perm);
24011 + case Opt_nowarn_perm:
24012 + AuLabel(nowarn_perm);
24014 + case Opt_verbose:
24015 + AuLabel(verbose);
24017 + case Opt_noverbose:
24018 + AuLabel(noverbose);
24029 + case Opt_wbr_create:
24030 + u.create = &opt->wbr_create;
24031 + AuDbg("create %d, %s\n", u.create->wbr_create,
24032 + au_optstr_wbr_create(u.create->wbr_create));
24033 + switch (u.create->wbr_create) {
24034 + case AuWbrCreate_MFSV:
24035 + case AuWbrCreate_PMFSV:
24036 + AuDbg("%d sec\n", u.create->mfs_second);
24038 + case AuWbrCreate_MFSRR:
24039 + case AuWbrCreate_TDMFS:
24040 + AuDbg("%llu watermark\n",
24041 + u.create->mfsrr_watermark);
24043 + case AuWbrCreate_MFSRRV:
24044 + case AuWbrCreate_TDMFSV:
24045 + case AuWbrCreate_PMFSRRV:
24046 + AuDbg("%llu watermark, %d sec\n",
24047 + u.create->mfsrr_watermark,
24048 + u.create->mfs_second);
24052 + case Opt_wbr_copyup:
24053 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
24054 + au_optstr_wbr_copyup(opt->wbr_copyup));
24056 + case Opt_fhsm_sec:
24057 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24073 +void au_opts_free(struct au_opts *opts)
24075 + struct au_opt *opt;
24078 + while (opt->type != Opt_tail) {
24079 + switch (opt->type) {
24082 + case Opt_prepend:
24083 + path_put(&opt->add.path);
24087 + path_put(&opt->del.h_path);
24091 + dput(opt->mod.h_root);
24094 + fput(opt->xino.file);
24101 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24102 + aufs_bindex_t bindex)
24105 + struct au_opt_add *add = &opt->add;
24108 + add->bindex = bindex;
24109 + add->perm = AuBrPerm_RO;
24110 + add->pathname = opt_str;
24111 + p = strchr(opt_str, '=');
24115 + add->perm = br_perm_val(p);
24118 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24121 + add->perm = AuBrPerm_RO;
24122 + if (au_test_fs_rr(add->path.dentry->d_sb))
24123 + add->perm = AuBrPerm_RR;
24124 + else if (!bindex && !(sb_flags & MS_RDONLY))
24125 + add->perm = AuBrPerm_RW;
24127 + opt->type = Opt_add;
24130 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24137 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24141 + del->pathname = args[0].from;
24142 + AuDbg("del path %s\n", del->pathname);
24144 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24145 + if (unlikely(err))
24146 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24151 +#if 0 /* reserved for future use */
24152 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24153 + struct au_opt_del *del, substring_t args[])
24156 + struct dentry *root;
24159 + root = sb->s_root;
24160 + aufs_read_lock(root, AuLock_FLUSH);
24161 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24162 + pr_err("out of bounds, %d\n", bindex);
24167 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24168 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24171 + aufs_read_unlock(root, !AuLock_IR);
24176 +static int noinline_for_stack
24177 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24180 + struct path path;
24184 + mod->path = args[0].from;
24185 + p = strchr(mod->path, '=');
24186 + if (unlikely(!p)) {
24187 + pr_err("no permssion %s\n", args[0].from);
24192 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24193 + if (unlikely(err)) {
24194 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24198 + mod->perm = br_perm_val(p);
24199 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24200 + mod->h_root = dget(path.dentry);
24207 +#if 0 /* reserved for future use */
24208 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24209 + struct au_opt_mod *mod, substring_t args[])
24212 + struct dentry *root;
24215 + root = sb->s_root;
24216 + aufs_read_lock(root, AuLock_FLUSH);
24217 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24218 + pr_err("out of bounds, %d\n", bindex);
24223 + mod->perm = br_perm_val(args[1].from);
24224 + AuDbg("mod path %s, perm 0x%x, %s\n",
24225 + mod->path, mod->perm, args[1].from);
24226 + mod->h_root = dget(au_h_dptr(root, bindex));
24229 + aufs_read_unlock(root, !AuLock_IR);
24234 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24235 + substring_t args[])
24238 + struct file *file;
24240 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24241 + err = PTR_ERR(file);
24242 + if (IS_ERR(file))
24246 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24248 + pr_err("%s must be outside\n", args[0].from);
24253 + xino->file = file;
24254 + xino->path = args[0].from;
24260 +static int noinline_for_stack
24261 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24262 + struct au_opt_xino_itrunc *xino_itrunc,
24263 + substring_t args[])
24266 + aufs_bindex_t bbot, bindex;
24267 + struct path path;
24268 + struct dentry *root;
24270 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24271 + if (unlikely(err)) {
24272 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24276 + xino_itrunc->bindex = -1;
24277 + root = sb->s_root;
24278 + aufs_read_lock(root, AuLock_FLUSH);
24279 + bbot = au_sbbot(sb);
24280 + for (bindex = 0; bindex <= bbot; bindex++) {
24281 + if (au_h_dptr(root, bindex) == path.dentry) {
24282 + xino_itrunc->bindex = bindex;
24286 + aufs_read_unlock(root, !AuLock_IR);
24289 + if (unlikely(xino_itrunc->bindex < 0)) {
24290 + pr_err("no such branch %s\n", args[0].from);
24298 +/* called without aufs lock */
24299 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24301 + int err, n, token;
24302 + aufs_bindex_t bindex;
24303 + unsigned char skipped;
24304 + struct dentry *root;
24305 + struct au_opt *opt, *opt_tail;
24307 + /* reduce the stack space */
24309 + struct au_opt_xino_itrunc *xino_itrunc;
24310 + struct au_opt_wbr_create *create;
24313 + substring_t args[MAX_OPT_ARGS];
24317 + a = kmalloc(sizeof(*a), GFP_NOFS);
24318 + if (unlikely(!a))
24321 + root = sb->s_root;
24325 + opt_tail = opt + opts->max_opt - 1;
24326 + opt->type = Opt_tail;
24327 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24330 + token = match_token(opt_str, options, a->args);
24334 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24336 + err = opt_add(opt, opt_str, opts->sb_flags,
24338 + if (unlikely(!err && ++opt > opt_tail)) {
24342 + opt->type = Opt_tail;
24347 + if (unlikely(match_int(&a->args[0], &n))) {
24348 + pr_err("bad integer in %s\n", opt_str);
24352 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24355 + opt->type = token;
24358 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24359 + /*dummy bindex*/1);
24361 + opt->type = token;
24363 + case Opt_prepend:
24364 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24367 + opt->type = token;
24370 + err = au_opts_parse_del(&opt->del, a->args);
24372 + opt->type = token;
24374 +#if 0 /* reserved for future use */
24376 + del->pathname = "(indexed)";
24377 + if (unlikely(match_int(&args[0], &n))) {
24378 + pr_err("bad integer in %s\n", opt_str);
24381 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24383 + opt->type = token;
24387 + err = au_opts_parse_mod(&opt->mod, a->args);
24389 + opt->type = token;
24391 +#ifdef IMOD /* reserved for future use */
24393 + u.mod->path = "(indexed)";
24394 + if (unlikely(match_int(&a->args[0], &n))) {
24395 + pr_err("bad integer in %s\n", opt_str);
24398 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24400 + opt->type = token;
24404 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24406 + opt->type = token;
24409 + case Opt_trunc_xino_path:
24410 + err = au_opts_parse_xino_itrunc_path
24411 + (sb, &opt->xino_itrunc, a->args);
24413 + opt->type = token;
24416 + case Opt_itrunc_xino:
24417 + u.xino_itrunc = &opt->xino_itrunc;
24418 + if (unlikely(match_int(&a->args[0], &n))) {
24419 + pr_err("bad integer in %s\n", opt_str);
24422 + u.xino_itrunc->bindex = n;
24423 + aufs_read_lock(root, AuLock_FLUSH);
24424 + if (n < 0 || au_sbbot(sb) < n) {
24425 + pr_err("out of bounds, %d\n", n);
24426 + aufs_read_unlock(root, !AuLock_IR);
24429 + aufs_read_unlock(root, !AuLock_IR);
24431 + opt->type = token;
24435 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24438 + opt->type = token;
24441 + case Opt_rdcache:
24442 + if (unlikely(match_int(&a->args[0], &n))) {
24443 + pr_err("bad integer in %s\n", opt_str);
24446 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24447 + pr_err("rdcache must be smaller than %d\n",
24448 + AUFS_RDCACHE_MAX);
24451 + opt->rdcache = n;
24453 + opt->type = token;
24456 + if (unlikely(match_int(&a->args[0], &n)
24458 + || n > KMALLOC_MAX_SIZE)) {
24459 + pr_err("bad integer in %s\n", opt_str);
24462 + if (unlikely(n && n < NAME_MAX)) {
24463 + pr_err("rdblk must be larger than %d\n",
24469 + opt->type = token;
24472 + if (unlikely(match_int(&a->args[0], &n)
24474 + || n * sizeof(struct hlist_head)
24475 + > KMALLOC_MAX_SIZE)) {
24476 + pr_err("bad integer in %s\n", opt_str);
24481 + opt->type = token;
24484 + case Opt_trunc_xino:
24485 + case Opt_notrunc_xino:
24487 + case Opt_trunc_xib:
24488 + case Opt_notrunc_xib:
24491 + case Opt_dirperm1:
24492 + case Opt_nodirperm1:
24494 + case Opt_noplink:
24495 + case Opt_list_plink:
24498 + case Opt_diropq_a:
24499 + case Opt_diropq_w:
24500 + case Opt_warn_perm:
24501 + case Opt_nowarn_perm:
24502 + case Opt_verbose:
24503 + case Opt_noverbose:
24507 + case Opt_rdblk_def:
24508 + case Opt_rdhash_def:
24512 + opt->type = token;
24516 + opt->udba = udba_val(a->args[0].from);
24517 + if (opt->udba >= 0) {
24519 + opt->type = token;
24521 + pr_err("wrong value, %s\n", opt_str);
24524 + case Opt_wbr_create:
24525 + u.create = &opt->wbr_create;
24526 + u.create->wbr_create
24527 + = au_wbr_create_val(a->args[0].from, u.create);
24528 + if (u.create->wbr_create >= 0) {
24530 + opt->type = token;
24532 + pr_err("wrong value, %s\n", opt_str);
24534 + case Opt_wbr_copyup:
24535 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24536 + if (opt->wbr_copyup >= 0) {
24538 + opt->type = token;
24540 + pr_err("wrong value, %s\n", opt_str);
24543 + case Opt_fhsm_sec:
24544 + if (unlikely(match_int(&a->args[0], &n)
24546 + pr_err("bad integer in %s\n", opt_str);
24549 + if (sysaufs_brs) {
24550 + opt->fhsm_second = n;
24551 + opt->type = token;
24553 + pr_warn("ignored %s\n", opt_str);
24558 + pr_warn("ignored %s\n", opt_str);
24560 + case Opt_ignore_silent:
24565 + pr_err("unknown option %s\n", opt_str);
24569 + if (!err && !skipped) {
24570 + if (unlikely(++opt > opt_tail)) {
24573 + opt->type = Opt_tail;
24576 + opt->type = Opt_tail;
24582 + if (unlikely(err))
24583 + au_opts_free(opts);
24589 +static int au_opt_wbr_create(struct super_block *sb,
24590 + struct au_opt_wbr_create *create)
24593 + struct au_sbinfo *sbinfo;
24595 + SiMustWriteLock(sb);
24597 + err = 1; /* handled */
24598 + sbinfo = au_sbi(sb);
24599 + if (sbinfo->si_wbr_create_ops->fin) {
24600 + err = sbinfo->si_wbr_create_ops->fin(sb);
24605 + sbinfo->si_wbr_create = create->wbr_create;
24606 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24607 + switch (create->wbr_create) {
24608 + case AuWbrCreate_MFSRRV:
24609 + case AuWbrCreate_MFSRR:
24610 + case AuWbrCreate_TDMFS:
24611 + case AuWbrCreate_TDMFSV:
24612 + case AuWbrCreate_PMFSRR:
24613 + case AuWbrCreate_PMFSRRV:
24614 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24616 + case AuWbrCreate_MFS:
24617 + case AuWbrCreate_MFSV:
24618 + case AuWbrCreate_PMFS:
24619 + case AuWbrCreate_PMFSV:
24620 + sbinfo->si_wbr_mfs.mfs_expire
24621 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24625 + if (sbinfo->si_wbr_create_ops->init)
24626 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24633 + * plus: processed without an error
24634 + * zero: unprocessed
24636 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24637 + struct au_opts *opts)
24640 + struct au_sbinfo *sbinfo;
24642 + SiMustWriteLock(sb);
24644 + err = 1; /* handled */
24645 + sbinfo = au_sbi(sb);
24646 + switch (opt->type) {
24648 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24649 + sbinfo->si_mntflags |= opt->udba;
24650 + opts->given_udba |= opt->udba;
24654 + au_opt_set(sbinfo->si_mntflags, PLINK);
24656 + case Opt_noplink:
24657 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24658 + au_plink_put(sb, /*verbose*/1);
24659 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24661 + case Opt_list_plink:
24662 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24663 + au_plink_list(sb);
24667 + au_opt_set(sbinfo->si_mntflags, DIO);
24668 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24671 + au_opt_clr(sbinfo->si_mntflags, DIO);
24672 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24675 + case Opt_fhsm_sec:
24676 + au_fhsm_set(sbinfo, opt->fhsm_second);
24679 + case Opt_diropq_a:
24680 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24682 + case Opt_diropq_w:
24683 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24686 + case Opt_warn_perm:
24687 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24689 + case Opt_nowarn_perm:
24690 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24693 + case Opt_verbose:
24694 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24696 + case Opt_noverbose:
24697 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24701 + au_opt_set(sbinfo->si_mntflags, SUM);
24704 + au_opt_clr(sbinfo->si_mntflags, SUM);
24705 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24707 + au_opt_clr(sbinfo->si_mntflags, SUM);
24708 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24711 + case Opt_wbr_create:
24712 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24714 + case Opt_wbr_copyup:
24715 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24716 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24720 + sbinfo->si_dirwh = opt->dirwh;
24723 + case Opt_rdcache:
24724 + sbinfo->si_rdcache
24725 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24728 + sbinfo->si_rdblk = opt->rdblk;
24730 + case Opt_rdblk_def:
24731 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24734 + sbinfo->si_rdhash = opt->rdhash;
24736 + case Opt_rdhash_def:
24737 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24741 + au_opt_set(sbinfo->si_mntflags, SHWH);
24744 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24747 + case Opt_dirperm1:
24748 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24750 + case Opt_nodirperm1:
24751 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24754 + case Opt_trunc_xino:
24755 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24757 + case Opt_notrunc_xino:
24758 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24761 + case Opt_trunc_xino_path:
24762 + case Opt_itrunc_xino:
24763 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24768 + case Opt_trunc_xib:
24769 + au_fset_opts(opts->flags, TRUNC_XIB);
24771 + case Opt_notrunc_xib:
24772 + au_fclr_opts(opts->flags, TRUNC_XIB);
24776 + sb->s_flags |= MS_POSIXACL;
24779 + sb->s_flags &= ~MS_POSIXACL;
24791 + * returns tri-state.
24792 + * plus: processed without an error
24793 + * zero: unprocessed
24796 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24797 + struct au_opts *opts)
24799 + int err, do_refresh;
24802 + switch (opt->type) {
24804 + opt->add.bindex = au_sbbot(sb) + 1;
24805 + if (opt->add.bindex < 0)
24806 + opt->add.bindex = 0;
24808 + case Opt_prepend:
24809 + opt->add.bindex = 0;
24810 + add: /* indented label */
24812 + err = au_br_add(sb, &opt->add,
24813 + au_ftest_opts(opts->flags, REMOUNT));
24816 + au_fset_opts(opts->flags, REFRESH);
24822 + err = au_br_del(sb, &opt->del,
24823 + au_ftest_opts(opts->flags, REMOUNT));
24826 + au_fset_opts(opts->flags, TRUNC_XIB);
24827 + au_fset_opts(opts->flags, REFRESH);
24833 + err = au_br_mod(sb, &opt->mod,
24834 + au_ftest_opts(opts->flags, REMOUNT),
24839 + au_fset_opts(opts->flags, REFRESH);
24846 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24847 + struct au_opt_xino **opt_xino,
24848 + struct au_opts *opts)
24851 + aufs_bindex_t bbot, bindex;
24852 + struct dentry *root, *parent, *h_root;
24855 + switch (opt->type) {
24857 + err = au_xino_set(sb, &opt->xino,
24858 + !!au_ftest_opts(opts->flags, REMOUNT));
24859 + if (unlikely(err))
24862 + *opt_xino = &opt->xino;
24863 + au_xino_brid_set(sb, -1);
24865 + /* safe d_parent access */
24866 + parent = opt->xino.file->f_path.dentry->d_parent;
24867 + root = sb->s_root;
24868 + bbot = au_sbbot(sb);
24869 + for (bindex = 0; bindex <= bbot; bindex++) {
24870 + h_root = au_h_dptr(root, bindex);
24871 + if (h_root == parent) {
24872 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24880 + au_xino_brid_set(sb, -1);
24881 + *opt_xino = (void *)-1;
24888 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24889 + unsigned int pending)
24892 + aufs_bindex_t bindex, bbot;
24893 + unsigned char do_plink, skip, do_free, can_no_dreval;
24894 + struct au_branch *br;
24895 + struct au_wbr *wbr;
24896 + struct dentry *root, *dentry;
24897 + struct inode *dir, *h_dir;
24898 + struct au_sbinfo *sbinfo;
24899 + struct au_hinode *hdir;
24901 + SiMustAnyLock(sb);
24903 + sbinfo = au_sbi(sb);
24904 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24906 + if (!(sb_flags & MS_RDONLY)) {
24907 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24908 + pr_warn("first branch should be rw\n");
24909 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24910 + pr_warn_once("shwh should be used with ro\n");
24913 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24914 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24915 + pr_warn_once("udba=*notify requires xino\n");
24917 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24918 + pr_warn_once("dirperm1 breaks the protection"
24919 + " by the permission bits on the lower branch\n");
24923 + root = sb->s_root;
24924 + dir = d_inode(root);
24925 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24926 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24928 + bbot = au_sbbot(sb);
24929 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24931 + h_dir = au_h_iptr(dir, bindex);
24932 + br = au_sbr(sb, bindex);
24934 + if ((br->br_perm & AuBrAttr_ICEX)
24935 + && !h_dir->i_op->listxattr)
24936 + br->br_perm &= ~AuBrAttr_ICEX;
24938 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24939 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24940 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24944 + wbr = br->br_wbr;
24946 + wbr_wh_read_lock(wbr);
24948 + if (!au_br_writable(br->br_perm)) {
24951 + || (!wbr->wbr_whbase
24952 + && !wbr->wbr_plink
24953 + && !wbr->wbr_orph));
24954 + } else if (!au_br_wh_linkable(br->br_perm)) {
24955 + /* skip = (!br->br_whbase && !br->br_orph); */
24956 + skip = (!wbr || !wbr->wbr_whbase);
24957 + if (skip && wbr) {
24959 + skip = !!wbr->wbr_plink;
24961 + skip = !wbr->wbr_plink;
24964 + /* skip = (br->br_whbase && br->br_ohph); */
24965 + skip = (wbr && wbr->wbr_whbase);
24968 + skip = !!wbr->wbr_plink;
24970 + skip = !wbr->wbr_plink;
24974 + wbr_wh_read_unlock(wbr);
24976 + if (can_no_dreval) {
24977 + dentry = br->br_path.dentry;
24978 + spin_lock(&dentry->d_lock);
24979 + if (dentry->d_flags &
24980 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24981 + can_no_dreval = 0;
24982 + spin_unlock(&dentry->d_lock);
24985 + if (au_br_fhsm(br->br_perm)) {
24987 + AuDebugOn(!br->br_fhsm);
24993 + hdir = au_hi(dir, bindex);
24994 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24996 + wbr_wh_write_lock(wbr);
24997 + err = au_wh_init(br, sb);
24999 + wbr_wh_write_unlock(wbr);
25000 + au_hn_inode_unlock(hdir);
25002 + if (!err && do_free) {
25004 + br->br_wbr = NULL;
25008 + if (can_no_dreval)
25009 + au_fset_si(sbinfo, NO_DREVAL);
25011 + au_fclr_si(sbinfo, NO_DREVAL);
25014 + au_fset_si(sbinfo, FHSM);
25015 + for (bindex = bbot; bindex >= 0; bindex--) {
25016 + br = au_sbr(sb, bindex);
25017 + if (au_br_fhsm(br->br_perm)) {
25018 + au_fhsm_set_bottom(sb, bindex);
25023 + au_fclr_si(sbinfo, FHSM);
25024 + au_fhsm_set_bottom(sb, -1);
25030 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
25033 + unsigned int tmp;
25034 + aufs_bindex_t bindex, bbot;
25035 + struct au_opt *opt;
25036 + struct au_opt_xino *opt_xino, xino;
25037 + struct au_sbinfo *sbinfo;
25038 + struct au_branch *br;
25039 + struct inode *dir;
25041 + SiMustWriteLock(sb);
25046 + while (err >= 0 && opt->type != Opt_tail)
25047 + err = au_opt_simple(sb, opt++, opts);
25050 + else if (unlikely(err < 0))
25053 + /* disable xino and udba temporary */
25054 + sbinfo = au_sbi(sb);
25055 + tmp = sbinfo->si_mntflags;
25056 + au_opt_clr(sbinfo->si_mntflags, XINO);
25057 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25060 + while (err >= 0 && opt->type != Opt_tail)
25061 + err = au_opt_br(sb, opt++, opts);
25064 + else if (unlikely(err < 0))
25067 + bbot = au_sbbot(sb);
25068 + if (unlikely(bbot < 0)) {
25070 + pr_err("no branches\n");
25074 + if (au_opt_test(tmp, XINO))
25075 + au_opt_set(sbinfo->si_mntflags, XINO);
25077 + while (!err && opt->type != Opt_tail)
25078 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25079 + if (unlikely(err))
25082 + err = au_opts_verify(sb, sb->s_flags, tmp);
25083 + if (unlikely(err))
25086 + /* restore xino */
25087 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25088 + xino.file = au_xino_def(sb);
25089 + err = PTR_ERR(xino.file);
25090 + if (IS_ERR(xino.file))
25093 + err = au_xino_set(sb, &xino, /*remount*/0);
25095 + if (unlikely(err))
25099 + /* restore udba */
25100 + tmp &= AuOptMask_UDBA;
25101 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25102 + sbinfo->si_mntflags |= tmp;
25103 + bbot = au_sbbot(sb);
25104 + for (bindex = 0; bindex <= bbot; bindex++) {
25105 + br = au_sbr(sb, bindex);
25106 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25107 + if (unlikely(err))
25108 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25110 + /* go on even if err */
25112 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25113 + dir = d_inode(sb->s_root);
25114 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25121 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25124 + unsigned char no_dreval;
25125 + struct inode *dir;
25126 + struct au_opt_xino *opt_xino;
25127 + struct au_opt *opt;
25128 + struct au_sbinfo *sbinfo;
25130 + SiMustWriteLock(sb);
25133 + dir = d_inode(sb->s_root);
25134 + sbinfo = au_sbi(sb);
25137 + while (err >= 0 && opt->type != Opt_tail) {
25138 + err = au_opt_simple(sb, opt, opts);
25140 + err = au_opt_br(sb, opt, opts);
25142 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25148 + /* go on even err */
25150 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25151 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25152 + if (unlikely(rerr && !err))
25155 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25156 + au_fset_opts(opts->flags, REFRESH_IDOP);
25158 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25159 + rerr = au_xib_trunc(sb);
25160 + if (unlikely(rerr && !err))
25164 + /* will be handled by the caller */
25165 + if (!au_ftest_opts(opts->flags, REFRESH)
25166 + && (opts->given_udba
25167 + || au_opt_test(sbinfo->si_mntflags, XINO)
25168 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25170 + au_fset_opts(opts->flags, REFRESH);
25172 + AuDbg("status 0x%x\n", opts->flags);
25176 +/* ---------------------------------------------------------------------- */
25178 +unsigned int au_opt_udba(struct super_block *sb)
25180 + return au_mntflags(sb) & AuOptMask_UDBA;
25182 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25183 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25184 +++ linux/fs/aufs/opts.h 2017-07-29 12:14:25.903042072 +0200
25187 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25189 + * This program, aufs is free software; you can redistribute it and/or modify
25190 + * it under the terms of the GNU General Public License as published by
25191 + * the Free Software Foundation; either version 2 of the License, or
25192 + * (at your option) any later version.
25194 + * This program is distributed in the hope that it will be useful,
25195 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25196 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25197 + * GNU General Public License for more details.
25199 + * You should have received a copy of the GNU General Public License
25200 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25204 + * mount options/flags
25207 +#ifndef __AUFS_OPTS_H__
25208 +#define __AUFS_OPTS_H__
25212 +#include <linux/path.h>
25216 +/* ---------------------------------------------------------------------- */
25219 +#define AuOpt_XINO 1 /* external inode number bitmap
25220 + and translation table */
25221 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25222 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25223 +#define AuOpt_UDBA_REVAL (1 << 3)
25224 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25225 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25226 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25227 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25229 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25230 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25231 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25232 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25233 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25234 +#define AuOpt_DIO (1 << 14) /* direct io */
25236 +#ifndef CONFIG_AUFS_HNOTIFY
25237 +#undef AuOpt_UDBA_HNOTIFY
25238 +#define AuOpt_UDBA_HNOTIFY 0
25240 +#ifndef CONFIG_AUFS_SHWH
25242 +#define AuOpt_SHWH 0
25245 +#define AuOpt_Def (AuOpt_XINO \
25246 + | AuOpt_UDBA_REVAL \
25248 + /* | AuOpt_DIRPERM1 */ \
25249 + | AuOpt_WARN_PERM)
25250 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25251 + | AuOpt_UDBA_REVAL \
25252 + | AuOpt_UDBA_HNOTIFY)
25254 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25255 +#define au_opt_set(flags, name) do { \
25256 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25257 + ((flags) |= AuOpt_##name); \
25259 +#define au_opt_set_udba(flags, name) do { \
25260 + (flags) &= ~AuOptMask_UDBA; \
25261 + ((flags) |= AuOpt_##name); \
25263 +#define au_opt_clr(flags, name) do { \
25264 + ((flags) &= ~AuOpt_##name); \
25267 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25269 +#ifdef CONFIG_PROC_FS
25272 + return mntflags & ~AuOpt_PLINK;
25276 +/* ---------------------------------------------------------------------- */
25278 +/* policies to select one among multiple writable branches */
25280 + AuWbrCreate_TDP, /* top down parent */
25281 + AuWbrCreate_RR, /* round robin */
25282 + AuWbrCreate_MFS, /* most free space */
25283 + AuWbrCreate_MFSV, /* mfs with seconds */
25284 + AuWbrCreate_MFSRR, /* mfs then rr */
25285 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25286 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25287 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25288 + AuWbrCreate_PMFS, /* parent and mfs */
25289 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25290 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25291 + AuWbrCreate_PMFSRRV, /* plus seconds */
25293 + AuWbrCreate_Def = AuWbrCreate_TDP
25297 + AuWbrCopyup_TDP, /* top down parent */
25298 + AuWbrCopyup_BUP, /* bottom up parent */
25299 + AuWbrCopyup_BU, /* bottom up */
25301 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25304 +/* ---------------------------------------------------------------------- */
25306 +struct au_opt_add {
25307 + aufs_bindex_t bindex;
25310 + struct path path;
25313 +struct au_opt_del {
25315 + struct path h_path;
25318 +struct au_opt_mod {
25321 + struct dentry *h_root;
25324 +struct au_opt_xino {
25326 + struct file *file;
25329 +struct au_opt_xino_itrunc {
25330 + aufs_bindex_t bindex;
25333 +struct au_opt_wbr_create {
25336 + unsigned long long mfsrr_watermark;
25342 + struct au_opt_xino xino;
25343 + struct au_opt_xino_itrunc xino_itrunc;
25344 + struct au_opt_add add;
25345 + struct au_opt_del del;
25346 + struct au_opt_mod mod;
25349 + unsigned int rdblk;
25350 + unsigned int rdhash;
25352 + struct au_opt_wbr_create wbr_create;
25354 + unsigned int fhsm_second;
25359 +#define AuOpts_REMOUNT 1
25360 +#define AuOpts_REFRESH (1 << 1)
25361 +#define AuOpts_TRUNC_XIB (1 << 2)
25362 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25363 +#define AuOpts_REFRESH_IDOP (1 << 4)
25364 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25365 +#define au_fset_opts(flags, name) \
25366 + do { (flags) |= AuOpts_##name; } while (0)
25367 +#define au_fclr_opts(flags, name) \
25368 + do { (flags) &= ~AuOpts_##name; } while (0)
25371 + struct au_opt *opt;
25374 + unsigned int given_udba;
25375 + unsigned int flags;
25376 + unsigned long sb_flags;
25379 +/* ---------------------------------------------------------------------- */
25382 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25383 +const char *au_optstr_udba(int udba);
25384 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25385 +const char *au_optstr_wbr_create(int wbr_create);
25387 +void au_opts_free(struct au_opts *opts);
25388 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25389 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25390 + unsigned int pending);
25391 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25392 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25394 +unsigned int au_opt_udba(struct super_block *sb);
25396 +#endif /* __KERNEL__ */
25397 +#endif /* __AUFS_OPTS_H__ */
25398 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25399 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25400 +++ linux/fs/aufs/plink.c 2017-07-29 12:14:25.903042072 +0200
25403 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25405 + * This program, aufs is free software; you can redistribute it and/or modify
25406 + * it under the terms of the GNU General Public License as published by
25407 + * the Free Software Foundation; either version 2 of the License, or
25408 + * (at your option) any later version.
25410 + * This program is distributed in the hope that it will be useful,
25411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25413 + * GNU General Public License for more details.
25415 + * You should have received a copy of the GNU General Public License
25416 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25426 + * the pseudo-link maintenance mode.
25427 + * during a user process maintains the pseudo-links,
25428 + * prohibit adding a new plink and branch manipulation.
25432 + * For entry functions which will handle plink, and i_mutex is already held
25434 + * They cannot wait and should return an error at once.
25435 + * Callers has to check the error.
25437 + * For entry functions which will handle plink, but i_mutex is not held
25439 + * They can wait the plink maintenance mode to finish.
25441 + * They behave like F_SETLK and F_SETLKW.
25442 + * If the caller never handle plink, then both flags are unnecessary.
25445 +int au_plink_maint(struct super_block *sb, int flags)
25449 + struct task_struct *parent, *prev;
25450 + struct au_sbinfo *sbi;
25452 + SiMustAnyLock(sb);
25455 + if (!au_opt_test(au_mntflags(sb), PLINK))
25458 + sbi = au_sbi(sb);
25459 + pid = sbi->si_plink_maint_pid;
25460 + if (!pid || pid == current->pid)
25463 + /* todo: it highly depends upon /sbin/mount.aufs */
25465 + parent = current;
25469 + parent = rcu_dereference(parent->real_parent);
25470 + if (parent == prev)
25472 + ppid = task_pid_vnr(parent);
25473 + if (pid == ppid) {
25474 + rcu_read_unlock();
25479 + rcu_read_unlock();
25481 + if (au_ftest_lock(flags, NOPLMW)) {
25482 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25483 + /* AuDebugOn(!lockdep_depth(current)); */
25484 + while (sbi->si_plink_maint_pid) {
25485 + si_read_unlock(sb);
25486 + /* gave up wake_up_bit() */
25487 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25489 + if (au_ftest_lock(flags, FLUSH))
25490 + au_nwt_flush(&sbi->si_nowait);
25491 + si_noflush_read_lock(sb);
25493 + } else if (au_ftest_lock(flags, NOPLM)) {
25494 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25502 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25504 + spin_lock(&sbinfo->si_plink_maint_lock);
25505 + sbinfo->si_plink_maint_pid = 0;
25506 + spin_unlock(&sbinfo->si_plink_maint_lock);
25507 + wake_up_all(&sbinfo->si_plink_wq);
25510 +int au_plink_maint_enter(struct super_block *sb)
25513 + struct au_sbinfo *sbinfo;
25516 + sbinfo = au_sbi(sb);
25517 + /* make sure i am the only one in this fs */
25518 + si_write_lock(sb, AuLock_FLUSH);
25519 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25520 + spin_lock(&sbinfo->si_plink_maint_lock);
25521 + if (!sbinfo->si_plink_maint_pid)
25522 + sbinfo->si_plink_maint_pid = current->pid;
25525 + spin_unlock(&sbinfo->si_plink_maint_lock);
25527 + si_write_unlock(sb);
25532 +/* ---------------------------------------------------------------------- */
25534 +#ifdef CONFIG_AUFS_DEBUG
25535 +void au_plink_list(struct super_block *sb)
25538 + struct au_sbinfo *sbinfo;
25539 + struct hlist_head *plink_hlist;
25540 + struct au_icntnr *icntnr;
25542 + SiMustAnyLock(sb);
25544 + sbinfo = au_sbi(sb);
25545 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25546 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25548 + for (i = 0; i < AuPlink_NHASH; i++) {
25549 + plink_hlist = &sbinfo->si_plink[i].head;
25551 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25552 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25553 + rcu_read_unlock();
25558 +/* is the inode pseudo-linked? */
25559 +int au_plink_test(struct inode *inode)
25562 + struct au_sbinfo *sbinfo;
25563 + struct hlist_head *plink_hlist;
25564 + struct au_icntnr *icntnr;
25566 + sbinfo = au_sbi(inode->i_sb);
25567 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25568 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25569 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25572 + i = au_plink_hash(inode->i_ino);
25573 + plink_hlist = &sbinfo->si_plink[i].head;
25575 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25576 + if (&icntnr->vfs_inode == inode) {
25580 + rcu_read_unlock();
25584 +/* ---------------------------------------------------------------------- */
25587 + * generate a name for plink.
25588 + * the file will be stored under AUFS_WH_PLINKDIR.
25590 +/* 20 is max digits length of ulong 64 */
25591 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25593 +static int plink_name(char *name, int len, struct inode *inode,
25594 + aufs_bindex_t bindex)
25597 + struct inode *h_inode;
25599 + h_inode = au_h_iptr(inode, bindex);
25600 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25604 +struct au_do_plink_lkup_args {
25605 + struct dentry **errp;
25606 + struct qstr *tgtname;
25607 + struct dentry *h_parent;
25608 + struct au_branch *br;
25611 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25612 + struct dentry *h_parent,
25613 + struct au_branch *br)
25615 + struct dentry *h_dentry;
25616 + struct inode *h_inode;
25618 + h_inode = d_inode(h_parent);
25619 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25620 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25621 + inode_unlock(h_inode);
25625 +static void au_call_do_plink_lkup(void *args)
25627 + struct au_do_plink_lkup_args *a = args;
25628 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25631 +/* lookup the plink-ed @inode under the branch at @bindex */
25632 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25634 + struct dentry *h_dentry, *h_parent;
25635 + struct au_branch *br;
25637 + char a[PLINK_NAME_LEN];
25638 + struct qstr tgtname = QSTR_INIT(a, 0);
25640 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25642 + br = au_sbr(inode->i_sb, bindex);
25643 + h_parent = br->br_wbr->wbr_plink;
25644 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25646 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25647 + struct au_do_plink_lkup_args args = {
25648 + .errp = &h_dentry,
25649 + .tgtname = &tgtname,
25650 + .h_parent = h_parent,
25654 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25655 + if (unlikely(wkq_err))
25656 + h_dentry = ERR_PTR(wkq_err);
25658 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25663 +/* create a pseudo-link */
25664 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25665 + struct dentry *h_dentry, struct au_branch *br)
25668 + struct path h_path = {
25669 + .mnt = au_br_mnt(br)
25671 + struct inode *h_dir, *delegated;
25673 + h_dir = d_inode(h_parent);
25674 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25676 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25677 + err = PTR_ERR(h_path.dentry);
25678 + if (IS_ERR(h_path.dentry))
25682 + /* wh.plink dir is not monitored */
25683 + /* todo: is it really safe? */
25684 + if (d_is_positive(h_path.dentry)
25685 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25686 + delegated = NULL;
25687 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25688 + if (unlikely(err == -EWOULDBLOCK)) {
25689 + pr_warn("cannot retry for NFSv4 delegation"
25690 + " for an internal unlink\n");
25693 + dput(h_path.dentry);
25694 + h_path.dentry = NULL;
25698 + if (!err && d_is_negative(h_path.dentry)) {
25699 + delegated = NULL;
25700 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25701 + if (unlikely(err == -EWOULDBLOCK)) {
25702 + pr_warn("cannot retry for NFSv4 delegation"
25703 + " for an internal link\n");
25707 + dput(h_path.dentry);
25710 + inode_unlock(h_dir);
25714 +struct do_whplink_args {
25716 + struct qstr *tgt;
25717 + struct dentry *h_parent;
25718 + struct dentry *h_dentry;
25719 + struct au_branch *br;
25722 +static void call_do_whplink(void *args)
25724 + struct do_whplink_args *a = args;
25725 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25728 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25729 + aufs_bindex_t bindex, struct au_branch *br)
25731 + int err, wkq_err;
25732 + struct au_wbr *wbr;
25733 + struct dentry *h_parent;
25734 + char a[PLINK_NAME_LEN];
25735 + struct qstr tgtname = QSTR_INIT(a, 0);
25737 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25738 + h_parent = wbr->wbr_plink;
25739 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25741 + /* always superio. */
25742 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25743 + struct do_whplink_args args = {
25746 + .h_parent = h_parent,
25747 + .h_dentry = h_dentry,
25750 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25751 + if (unlikely(wkq_err))
25754 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25760 + * create a new pseudo-link for @h_dentry on @bindex.
25761 + * the linked inode is held in aufs @inode.
25763 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25764 + struct dentry *h_dentry)
25766 + struct super_block *sb;
25767 + struct au_sbinfo *sbinfo;
25768 + struct hlist_head *plink_hlist;
25769 + struct au_icntnr *icntnr;
25770 + struct au_sphlhead *sphl;
25771 + int found, err, cnt, i;
25773 + sb = inode->i_sb;
25774 + sbinfo = au_sbi(sb);
25775 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25776 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25778 + found = au_plink_test(inode);
25782 + i = au_plink_hash(inode->i_ino);
25783 + sphl = sbinfo->si_plink + i;
25784 + plink_hlist = &sphl->head;
25787 + spin_lock(&sphl->spin);
25788 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25789 + if (&icntnr->vfs_inode == inode) {
25795 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25796 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25798 + spin_unlock(&sphl->spin);
25800 + cnt = au_sphl_count(sphl);
25801 +#define msg "unexpectedly unblanced or too many pseudo-links"
25802 + if (cnt > AUFS_PLINK_WARN)
25803 + AuWarn1(msg ", %d\n", cnt);
25805 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25806 + if (unlikely(err)) {
25807 + pr_warn("err %d, damaged pseudo link.\n", err);
25808 + au_sphl_del_rcu(&icntnr->plink, sphl);
25809 + iput(&icntnr->vfs_inode);
25812 + iput(&icntnr->vfs_inode);
25815 +/* free all plinks */
25816 +void au_plink_put(struct super_block *sb, int verbose)
25819 + struct au_sbinfo *sbinfo;
25820 + struct hlist_head *plink_hlist;
25821 + struct hlist_node *tmp;
25822 + struct au_icntnr *icntnr;
25824 + SiMustWriteLock(sb);
25826 + sbinfo = au_sbi(sb);
25827 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25828 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25830 + /* no spin_lock since sbinfo is write-locked */
25832 + for (i = 0; i < AuPlink_NHASH; i++) {
25833 + plink_hlist = &sbinfo->si_plink[i].head;
25834 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25835 + pr_warn("pseudo-link is not flushed");
25838 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25839 + iput(&icntnr->vfs_inode);
25840 + INIT_HLIST_HEAD(plink_hlist);
25844 +void au_plink_clean(struct super_block *sb, int verbose)
25846 + struct dentry *root;
25848 + root = sb->s_root;
25849 + aufs_write_lock(root);
25850 + if (au_opt_test(au_mntflags(sb), PLINK))
25851 + au_plink_put(sb, verbose);
25852 + aufs_write_unlock(root);
25855 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25858 + aufs_bindex_t btop, bbot, bindex;
25861 + btop = au_ibtop(inode);
25862 + bbot = au_ibbot(inode);
25864 + for (bindex = btop; bindex <= bbot; bindex++) {
25865 + if (!au_h_iptr(inode, bindex)
25866 + || au_ii_br_id(inode, bindex) != br_id)
25868 + au_set_h_iptr(inode, bindex, NULL, 0);
25873 + for (bindex = btop; bindex <= bbot; bindex++)
25874 + if (au_h_iptr(inode, bindex)) {
25884 +/* free the plinks on a branch specified by @br_id */
25885 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25887 + struct au_sbinfo *sbinfo;
25888 + struct hlist_head *plink_hlist;
25889 + struct hlist_node *tmp;
25890 + struct au_icntnr *icntnr;
25891 + struct inode *inode;
25894 + SiMustWriteLock(sb);
25896 + sbinfo = au_sbi(sb);
25897 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25898 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25900 + /* no spin_lock since sbinfo is write-locked */
25901 + for (i = 0; i < AuPlink_NHASH; i++) {
25902 + plink_hlist = &sbinfo->si_plink[i].head;
25903 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25904 + inode = au_igrab(&icntnr->vfs_inode);
25905 + ii_write_lock_child(inode);
25906 + do_put = au_plink_do_half_refresh(inode, br_id);
25908 + hlist_del(&icntnr->plink);
25911 + ii_write_unlock(inode);
25916 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25917 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25918 +++ linux/fs/aufs/poll.c 2017-07-29 12:14:25.906375514 +0200
25921 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25923 + * This program, aufs is free software; you can redistribute it and/or modify
25924 + * it under the terms of the GNU General Public License as published by
25925 + * the Free Software Foundation; either version 2 of the License, or
25926 + * (at your option) any later version.
25928 + * This program is distributed in the hope that it will be useful,
25929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25931 + * GNU General Public License for more details.
25933 + * You should have received a copy of the GNU General Public License
25934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25939 + * There is only one filesystem which implements ->poll operation, currently.
25944 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25946 + unsigned int mask;
25948 + struct file *h_file;
25949 + struct super_block *sb;
25951 + /* We should pretend an error happened. */
25952 + mask = POLLERR /* | POLLIN | POLLOUT */;
25953 + sb = file->f_path.dentry->d_sb;
25954 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25956 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
25957 + err = PTR_ERR(h_file);
25958 + if (IS_ERR(h_file))
25961 + /* it is not an error if h_file has no operation */
25962 + mask = DEFAULT_POLLMASK;
25963 + if (h_file->f_op->poll)
25964 + mask = h_file->f_op->poll(h_file, wait);
25965 + fput(h_file); /* instead of au_read_post() */
25968 + si_read_unlock(sb);
25969 + AuTraceErr((int)mask);
25972 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25973 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25974 +++ linux/fs/aufs/posix_acl.c 2017-07-29 12:14:25.906375514 +0200
25977 + * Copyright (C) 2014-2017 Junjiro R. Okajima
25979 + * This program, aufs is free software; you can redistribute it and/or modify
25980 + * it under the terms of the GNU General Public License as published by
25981 + * the Free Software Foundation; either version 2 of the License, or
25982 + * (at your option) any later version.
25984 + * This program is distributed in the hope that it will be useful,
25985 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25986 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25987 + * GNU General Public License for more details.
25989 + * You should have received a copy of the GNU General Public License
25990 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25994 + * posix acl operations
25997 +#include <linux/fs.h>
26000 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
26002 + struct posix_acl *acl;
26004 + aufs_bindex_t bindex;
26005 + struct inode *h_inode;
26006 + struct super_block *sb;
26009 + sb = inode->i_sb;
26010 + si_read_lock(sb, AuLock_FLUSH);
26011 + ii_read_lock_child(inode);
26012 + if (!(sb->s_flags & MS_POSIXACL))
26015 + bindex = au_ibtop(inode);
26016 + h_inode = au_h_iptr(inode, bindex);
26017 + if (unlikely(!h_inode
26018 + || ((h_inode->i_mode & S_IFMT)
26019 + != (inode->i_mode & S_IFMT)))) {
26020 + err = au_busy_or_stale();
26021 + acl = ERR_PTR(err);
26025 + /* always topmost only */
26026 + acl = get_acl(h_inode, type);
26027 + if (!IS_ERR_OR_NULL(acl))
26028 + set_cached_acl(inode, type, acl);
26031 + ii_read_unlock(inode);
26032 + si_read_unlock(sb);
26034 + AuTraceErrPtr(acl);
26038 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
26042 + struct dentry *dentry;
26043 + struct au_sxattr arg = {
26044 + .type = AU_ACL_SET,
26051 + IMustLock(inode);
26053 + if (inode->i_ino == AUFS_ROOT_INO)
26054 + dentry = dget(inode->i_sb->s_root);
26056 + dentry = d_find_alias(inode);
26058 + dentry = d_find_any_alias(inode);
26060 + pr_warn("cannot handle this inode, "
26061 + "please report to aufs-users ML\n");
26067 + ssz = au_sxattr(dentry, inode, &arg);
26072 + set_cached_acl(inode, type, acl);
26078 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
26079 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
26080 +++ linux/fs/aufs/procfs.c 2017-07-29 12:14:25.906375514 +0200
26083 + * Copyright (C) 2010-2017 Junjiro R. Okajima
26085 + * This program, aufs is free software; you can redistribute it and/or modify
26086 + * it under the terms of the GNU General Public License as published by
26087 + * the Free Software Foundation; either version 2 of the License, or
26088 + * (at your option) any later version.
26090 + * This program is distributed in the hope that it will be useful,
26091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26093 + * GNU General Public License for more details.
26095 + * You should have received a copy of the GNU General Public License
26096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26100 + * procfs interfaces
26103 +#include <linux/proc_fs.h>
26106 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
26108 + struct au_sbinfo *sbinfo;
26110 + sbinfo = file->private_data;
26112 + au_plink_maint_leave(sbinfo);
26113 + kobject_put(&sbinfo->si_kobj);
26119 +static void au_procfs_plm_write_clean(struct file *file)
26121 + struct au_sbinfo *sbinfo;
26123 + sbinfo = file->private_data;
26125 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
26128 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
26131 + struct super_block *sb;
26132 + struct au_sbinfo *sbinfo;
26135 + if (unlikely(file->private_data))
26139 + /* don't use au_sbilist_lock() here */
26140 + spin_lock(&au_sbilist.spin);
26141 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26142 + if (id == sysaufs_si_id(sbinfo)) {
26143 + kobject_get(&sbinfo->si_kobj);
26144 + sb = sbinfo->si_sb;
26147 + spin_unlock(&au_sbilist.spin);
26150 + if (unlikely(!sb))
26153 + err = au_plink_maint_enter(sb);
26155 + /* keep kobject_get() */
26156 + file->private_data = sbinfo;
26158 + kobject_put(&sbinfo->si_kobj);
26164 + * Accept a valid "si=xxxx" only.
26165 + * Once it is accepted successfully, accept "clean" too.
26167 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26168 + size_t count, loff_t *ppos)
26171 + unsigned long id;
26172 + /* last newline is allowed */
26173 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26176 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26180 + if (unlikely(count > sizeof(buf)))
26183 + err = copy_from_user(buf, ubuf, count);
26184 + if (unlikely(err)) {
26191 + if (!strcmp("clean", buf)) {
26192 + au_procfs_plm_write_clean(file);
26193 + goto out_success;
26194 + } else if (unlikely(strncmp("si=", buf, 3)))
26197 + err = kstrtoul(buf + 3, 16, &id);
26198 + if (unlikely(err))
26201 + err = au_procfs_plm_write_si(file, id);
26202 + if (unlikely(err))
26206 + err = count; /* success */
26211 +static const struct file_operations au_procfs_plm_fop = {
26212 + .write = au_procfs_plm_write,
26213 + .release = au_procfs_plm_release,
26214 + .owner = THIS_MODULE
26217 +/* ---------------------------------------------------------------------- */
26219 +static struct proc_dir_entry *au_procfs_dir;
26221 +void au_procfs_fin(void)
26223 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26224 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26227 +int __init au_procfs_init(void)
26230 + struct proc_dir_entry *entry;
26233 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26234 + if (unlikely(!au_procfs_dir))
26237 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26238 + au_procfs_dir, &au_procfs_plm_fop);
26239 + if (unlikely(!entry))
26243 + goto out; /* success */
26247 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26251 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26252 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26253 +++ linux/fs/aufs/rdu.c 2017-07-29 12:14:25.906375514 +0200
26256 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26258 + * This program, aufs is free software; you can redistribute it and/or modify
26259 + * it under the terms of the GNU General Public License as published by
26260 + * the Free Software Foundation; either version 2 of the License, or
26261 + * (at your option) any later version.
26263 + * This program is distributed in the hope that it will be useful,
26264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26266 + * GNU General Public License for more details.
26268 + * You should have received a copy of the GNU General Public License
26269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26273 + * readdir in userspace.
26276 +#include <linux/compat.h>
26277 +#include <linux/fs_stack.h>
26278 +#include <linux/security.h>
26281 +/* bits for struct aufs_rdu.flags */
26282 +#define AuRdu_CALLED 1
26283 +#define AuRdu_CONT (1 << 1)
26284 +#define AuRdu_FULL (1 << 2)
26285 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26286 +#define au_fset_rdu(flags, name) \
26287 + do { (flags) |= AuRdu_##name; } while (0)
26288 +#define au_fclr_rdu(flags, name) \
26289 + do { (flags) &= ~AuRdu_##name; } while (0)
26291 +struct au_rdu_arg {
26292 + struct dir_context ctx;
26293 + struct aufs_rdu *rdu;
26294 + union au_rdu_ent_ul ent;
26295 + unsigned long end;
26297 + struct super_block *sb;
26301 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26302 + loff_t offset, u64 h_ino, unsigned int d_type)
26305 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26306 + struct aufs_rdu *rdu = arg->rdu;
26307 + struct au_rdu_ent ent;
26311 + au_fset_rdu(rdu->cookie.flags, CALLED);
26312 + len = au_rdu_len(nlen);
26313 + if (arg->ent.ul + len < arg->end) {
26315 + ent.bindex = rdu->cookie.bindex;
26316 + ent.type = d_type;
26318 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26319 + ent.type = DT_UNKNOWN;
26321 + /* unnecessary to support mmap_sem since this is a dir */
26323 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26325 + if (copy_to_user(arg->ent.e->name, name, nlen))
26327 + /* the terminating NULL */
26328 + if (__put_user(0, arg->ent.e->name + nlen))
26331 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26332 + arg->ent.ul += len;
26336 + au_fset_rdu(rdu->cookie.flags, FULL);
26338 + rdu->tail = arg->ent;
26342 + /* AuTraceErr(err); */
26346 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26350 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26352 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26353 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26355 + if (unlikely(offset != cookie->h_pos))
26361 + au_fclr_rdu(cookie->flags, CALLED);
26363 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26367 + && au_ftest_rdu(cookie->flags, CALLED)
26368 + && !au_ftest_rdu(cookie->flags, FULL));
26369 + cookie->h_pos = h_file->f_pos;
26376 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26379 + aufs_bindex_t bbot;
26380 + struct au_rdu_arg arg = {
26382 + .actor = au_rdu_fill
26385 + struct dentry *dentry;
26386 + struct inode *inode;
26387 + struct file *h_file;
26388 + struct au_rdu_cookie *cookie = &rdu->cookie;
26390 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26391 + if (unlikely(err)) {
26397 + rdu->tail = rdu->ent;
26400 + arg.ent = rdu->ent;
26401 + arg.end = arg.ent.ul;
26402 + arg.end += rdu->sz;
26405 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26408 + err = security_file_permission(file, MAY_READ);
26410 + if (unlikely(err))
26413 + dentry = file->f_path.dentry;
26414 + inode = d_inode(dentry);
26415 + inode_lock_shared(inode);
26417 + arg.sb = inode->i_sb;
26418 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26419 + if (unlikely(err))
26421 + err = au_alive_dir(dentry);
26422 + if (unlikely(err))
26424 + /* todo: reval? */
26425 + fi_read_lock(file);
26428 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26429 + && cookie->generation != au_figen(file)))
26434 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26436 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26438 + bbot = au_fbtop(file);
26439 + if (cookie->bindex < bbot)
26440 + cookie->bindex = bbot;
26441 + bbot = au_fbbot_dir(file);
26442 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26443 + for (; !err && cookie->bindex <= bbot;
26444 + cookie->bindex++, cookie->h_pos = 0) {
26445 + h_file = au_hf_dir(file, cookie->bindex);
26449 + au_fclr_rdu(cookie->flags, FULL);
26450 + err = au_rdu_do(h_file, &arg);
26452 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26455 + AuDbg("rent %llu\n", rdu->rent);
26457 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26458 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26459 + au_fset_rdu(cookie->flags, CONT);
26460 + cookie->generation = au_figen(file);
26463 + ii_read_lock_child(inode);
26464 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26465 + ii_read_unlock(inode);
26468 + fi_read_unlock(file);
26470 + si_read_unlock(arg.sb);
26472 + inode_unlock_shared(inode);
26478 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26482 + unsigned long long nent;
26483 + union au_rdu_ent_ul *u;
26484 + struct au_rdu_ent ent;
26485 + struct super_block *sb;
26488 + nent = rdu->nent;
26490 + sb = file->f_path.dentry->d_sb;
26491 + si_read_lock(sb, AuLock_FLUSH);
26492 + while (nent-- > 0) {
26493 + /* unnecessary to support mmap_sem since this is a dir */
26494 + err = copy_from_user(&ent, u->e, sizeof(ent));
26496 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26497 + if (unlikely(err)) {
26503 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26505 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26507 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26509 + if (unlikely(err)) {
26514 + err = __put_user(ino, &u->e->ino);
26515 + if (unlikely(err)) {
26520 + u->ul += au_rdu_len(ent.nlen);
26522 + si_read_unlock(sb);
26527 +/* ---------------------------------------------------------------------- */
26529 +static int au_rdu_verify(struct aufs_rdu *rdu)
26531 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26532 + "%llu, b%d, 0x%x, g%u}\n",
26533 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26535 + rdu->rent, rdu->shwh, rdu->full,
26536 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26537 + rdu->cookie.generation);
26539 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26543 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26547 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26550 + struct aufs_rdu rdu;
26551 + void __user *p = (void __user *)arg;
26553 + err = copy_from_user(&rdu, p, sizeof(rdu));
26554 + if (unlikely(err)) {
26559 + err = au_rdu_verify(&rdu);
26560 + if (unlikely(err))
26564 + case AUFS_CTL_RDU:
26565 + err = au_rdu(file, &rdu);
26566 + if (unlikely(err))
26569 + e = copy_to_user(p, &rdu, sizeof(rdu));
26570 + if (unlikely(e)) {
26575 + case AUFS_CTL_RDU_INO:
26576 + err = au_rdu_ino(file, &rdu);
26580 + /* err = -ENOTTY; */
26589 +#ifdef CONFIG_COMPAT
26590 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26593 + struct aufs_rdu rdu;
26594 + void __user *p = compat_ptr(arg);
26596 + /* todo: get_user()? */
26597 + err = copy_from_user(&rdu, p, sizeof(rdu));
26598 + if (unlikely(err)) {
26603 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26604 + err = au_rdu_verify(&rdu);
26605 + if (unlikely(err))
26609 + case AUFS_CTL_RDU:
26610 + err = au_rdu(file, &rdu);
26611 + if (unlikely(err))
26614 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26615 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26616 + e = copy_to_user(p, &rdu, sizeof(rdu));
26617 + if (unlikely(e)) {
26622 + case AUFS_CTL_RDU_INO:
26623 + err = au_rdu_ino(file, &rdu);
26627 + /* err = -ENOTTY; */
26636 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26637 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26638 +++ linux/fs/aufs/rwsem.h 2017-07-29 12:14:25.906375514 +0200
26641 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26643 + * This program, aufs is free software; you can redistribute it and/or modify
26644 + * it under the terms of the GNU General Public License as published by
26645 + * the Free Software Foundation; either version 2 of the License, or
26646 + * (at your option) any later version.
26648 + * This program is distributed in the hope that it will be useful,
26649 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26650 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26651 + * GNU General Public License for more details.
26653 + * You should have received a copy of the GNU General Public License
26654 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26658 + * simple read-write semaphore wrappers
26661 +#ifndef __AUFS_RWSEM_H__
26662 +#define __AUFS_RWSEM_H__
26666 +#include "debug.h"
26669 + struct rw_semaphore rwsem;
26670 +#ifdef CONFIG_AUFS_DEBUG
26671 + /* just for debugging, not almighty counter */
26672 + atomic_t rcnt, wcnt;
26676 +#ifdef CONFIG_LOCKDEP
26677 +#define au_lockdep_set_name(rw) \
26678 + lockdep_set_class_and_name(&(rw)->rwsem, \
26679 + /*original key*/(rw)->rwsem.dep_map.key, \
26682 +#define au_lockdep_set_name(rw) do {} while (0)
26685 +#ifdef CONFIG_AUFS_DEBUG
26686 +#define AuDbgCntInit(rw) do { \
26687 + atomic_set(&(rw)->rcnt, 0); \
26688 + atomic_set(&(rw)->wcnt, 0); \
26689 + smp_mb(); /* atomic set */ \
26692 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26693 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26694 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26695 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26696 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26697 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26698 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26700 +#define AuDbgCnt(rw, cnt) 0
26701 +#define AuDbgCntInit(rw) do {} while (0)
26702 +#define AuDbgRcntInc(rw) do {} while (0)
26703 +#define AuDbgRcntDec(rw) do {} while (0)
26704 +#define AuDbgWcntInc(rw) do {} while (0)
26705 +#define AuDbgWcntDec(rw) do {} while (0)
26706 +#endif /* CONFIG_AUFS_DEBUG */
26708 +/* to debug easier, do not make them inlined functions */
26709 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26710 +/* rwsem_is_locked() is unusable */
26711 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26712 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26713 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26714 + && AuDbgCnt(rw, wcnt) <= 0)
26715 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26716 + || AuDbgCnt(rw, wcnt))
26718 +#define au_rw_init(rw) do { \
26719 + AuDbgCntInit(rw); \
26720 + init_rwsem(&(rw)->rwsem); \
26721 + au_lockdep_set_name(rw); \
26724 +#define au_rw_init_wlock(rw) do { \
26725 + au_rw_init(rw); \
26726 + down_write(&(rw)->rwsem); \
26727 + AuDbgWcntInc(rw); \
26730 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26731 + au_rw_init(rw); \
26732 + down_write_nested(&(rw)->rwsem, lsc); \
26733 + AuDbgWcntInc(rw); \
26736 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26738 + down_read(&rw->rwsem);
26739 + AuDbgRcntInc(rw);
26742 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26744 + down_read_nested(&rw->rwsem, lsc);
26745 + AuDbgRcntInc(rw);
26748 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26750 + AuRwMustReadLock(rw);
26751 + AuDbgRcntDec(rw);
26752 + up_read(&rw->rwsem);
26755 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26757 + AuRwMustWriteLock(rw);
26758 + AuDbgRcntInc(rw);
26759 + AuDbgWcntDec(rw);
26760 + downgrade_write(&rw->rwsem);
26763 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26765 + down_write(&rw->rwsem);
26766 + AuDbgWcntInc(rw);
26769 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26770 + unsigned int lsc)
26772 + down_write_nested(&rw->rwsem, lsc);
26773 + AuDbgWcntInc(rw);
26776 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26778 + AuRwMustWriteLock(rw);
26779 + AuDbgWcntDec(rw);
26780 + up_write(&rw->rwsem);
26783 +/* why is not _nested version defined */
26784 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26788 + ret = down_read_trylock(&rw->rwsem);
26790 + AuDbgRcntInc(rw);
26794 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26798 + ret = down_write_trylock(&rw->rwsem);
26800 + AuDbgWcntInc(rw);
26804 +#undef AuDbgCntDec
26805 +#undef AuDbgRcntInc
26806 +#undef AuDbgRcntDec
26807 +#undef AuDbgWcntDec
26809 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26810 +static inline void prefix##_read_lock(param) \
26811 +{ au_rw_read_lock(rwsem); } \
26812 +static inline void prefix##_write_lock(param) \
26813 +{ au_rw_write_lock(rwsem); } \
26814 +static inline int prefix##_read_trylock(param) \
26815 +{ return au_rw_read_trylock(rwsem); } \
26816 +static inline int prefix##_write_trylock(param) \
26817 +{ return au_rw_write_trylock(rwsem); }
26818 +/* why is not _nested version defined */
26819 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26820 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26821 +static inline void prefix##_write_trylock_nestd(param, lsc)
26822 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26824 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26825 +static inline void prefix##_read_unlock(param) \
26826 +{ au_rw_read_unlock(rwsem); } \
26827 +static inline void prefix##_write_unlock(param) \
26828 +{ au_rw_write_unlock(rwsem); } \
26829 +static inline void prefix##_downgrade_lock(param) \
26830 +{ au_rw_dgrade_lock(rwsem); }
26832 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26833 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26834 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26836 +#endif /* __KERNEL__ */
26837 +#endif /* __AUFS_RWSEM_H__ */
26838 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26839 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26840 +++ linux/fs/aufs/sbinfo.c 2017-07-29 12:14:25.906375514 +0200
26843 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26845 + * This program, aufs is free software; you can redistribute it and/or modify
26846 + * it under the terms of the GNU General Public License as published by
26847 + * the Free Software Foundation; either version 2 of the License, or
26848 + * (at your option) any later version.
26850 + * This program is distributed in the hope that it will be useful,
26851 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26852 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26853 + * GNU General Public License for more details.
26855 + * You should have received a copy of the GNU General Public License
26856 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26860 + * superblock private data
26866 + * they are necessary regardless sysfs is disabled.
26868 +void au_si_free(struct kobject *kobj)
26871 + struct au_sbinfo *sbinfo;
26872 + char *locked __maybe_unused; /* debug only */
26874 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26875 + for (i = 0; i < AuPlink_NHASH; i++)
26876 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26877 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26879 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26880 + percpu_counter_destroy(&sbinfo->si_ninodes);
26881 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26882 + percpu_counter_destroy(&sbinfo->si_nfiles);
26884 + au_rw_write_lock(&sbinfo->si_rwsem);
26885 + au_br_free(sbinfo);
26886 + au_rw_write_unlock(&sbinfo->si_rwsem);
26888 + kfree(sbinfo->si_branch);
26889 + mutex_destroy(&sbinfo->si_xib_mtx);
26890 + AuRwDestroy(&sbinfo->si_rwsem);
26895 +int au_si_alloc(struct super_block *sb)
26898 + struct au_sbinfo *sbinfo;
26901 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26902 + if (unlikely(!sbinfo))
26905 + /* will be reallocated separately */
26906 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26907 + if (unlikely(!sbinfo->si_branch))
26910 + err = sysaufs_si_init(sbinfo);
26911 + if (unlikely(err))
26914 + au_nwt_init(&sbinfo->si_nowait);
26915 + au_rw_init_wlock(&sbinfo->si_rwsem);
26917 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26918 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26920 + sbinfo->si_bbot = -1;
26921 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26923 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26924 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26925 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26926 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26928 + au_fhsm_init(sbinfo);
26930 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26932 + sbinfo->si_xino_jiffy = jiffies;
26933 + sbinfo->si_xino_expire
26934 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26935 + mutex_init(&sbinfo->si_xib_mtx);
26936 + sbinfo->si_xino_brid = -1;
26937 + /* leave si_xib_last_pindex and si_xib_next_bit */
26939 + au_sphl_init(&sbinfo->si_aopen);
26941 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26942 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26943 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26944 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26946 + for (i = 0; i < AuPlink_NHASH; i++)
26947 + au_sphl_init(sbinfo->si_plink + i);
26948 + init_waitqueue_head(&sbinfo->si_plink_wq);
26949 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26951 + au_sphl_init(&sbinfo->si_files);
26953 + /* with getattr by default */
26954 + sbinfo->si_iop_array = aufs_iop;
26956 + /* leave other members for sysaufs and si_mnt. */
26957 + sbinfo->si_sb = sb;
26958 + sb->s_fs_info = sbinfo;
26960 + return 0; /* success */
26963 + kfree(sbinfo->si_branch);
26970 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
26973 + struct au_branch **brp;
26975 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26978 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26979 + if (unlikely(!sz))
26980 + sz = sizeof(*brp);
26981 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
26984 + sbinfo->si_branch = brp;
26991 +/* ---------------------------------------------------------------------- */
26993 +unsigned int au_sigen_inc(struct super_block *sb)
26995 + unsigned int gen;
26996 + struct inode *inode;
26998 + SiMustWriteLock(sb);
27000 + gen = ++au_sbi(sb)->si_generation;
27001 + au_update_digen(sb->s_root);
27002 + inode = d_inode(sb->s_root);
27003 + au_update_iigen(inode, /*half*/0);
27004 + inode->i_version++;
27008 +aufs_bindex_t au_new_br_id(struct super_block *sb)
27010 + aufs_bindex_t br_id;
27012 + struct au_sbinfo *sbinfo;
27014 + SiMustWriteLock(sb);
27016 + sbinfo = au_sbi(sb);
27017 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
27018 + br_id = ++sbinfo->si_last_br_id;
27019 + AuDebugOn(br_id < 0);
27020 + if (br_id && au_br_index(sb, br_id) < 0)
27027 +/* ---------------------------------------------------------------------- */
27029 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
27030 +int si_read_lock(struct super_block *sb, int flags)
27035 + if (au_ftest_lock(flags, FLUSH))
27036 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27038 + si_noflush_read_lock(sb);
27039 + err = au_plink_maint(sb, flags);
27040 + if (unlikely(err))
27041 + si_read_unlock(sb);
27046 +int si_write_lock(struct super_block *sb, int flags)
27050 + if (au_ftest_lock(flags, FLUSH))
27051 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27053 + si_noflush_write_lock(sb);
27054 + err = au_plink_maint(sb, flags);
27055 + if (unlikely(err))
27056 + si_write_unlock(sb);
27061 +/* dentry and super_block lock. call at entry point */
27062 +int aufs_read_lock(struct dentry *dentry, int flags)
27065 + struct super_block *sb;
27067 + sb = dentry->d_sb;
27068 + err = si_read_lock(sb, flags);
27069 + if (unlikely(err))
27072 + if (au_ftest_lock(flags, DW))
27073 + di_write_lock_child(dentry);
27075 + di_read_lock_child(dentry, flags);
27077 + if (au_ftest_lock(flags, GEN)) {
27078 + err = au_digen_test(dentry, au_sigen(sb));
27079 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
27080 + AuDebugOn(!err && au_dbrange_test(dentry));
27082 + err = au_dbrange_test(dentry);
27083 + if (unlikely(err))
27084 + aufs_read_unlock(dentry, flags);
27091 +void aufs_read_unlock(struct dentry *dentry, int flags)
27093 + if (au_ftest_lock(flags, DW))
27094 + di_write_unlock(dentry);
27096 + di_read_unlock(dentry, flags);
27097 + si_read_unlock(dentry->d_sb);
27100 +void aufs_write_lock(struct dentry *dentry)
27102 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
27103 + di_write_lock_child(dentry);
27106 +void aufs_write_unlock(struct dentry *dentry)
27108 + di_write_unlock(dentry);
27109 + si_write_unlock(dentry->d_sb);
27112 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
27115 + unsigned int sigen;
27116 + struct super_block *sb;
27119 + err = si_read_lock(sb, flags);
27120 + if (unlikely(err))
27123 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
27125 + if (au_ftest_lock(flags, GEN)) {
27126 + sigen = au_sigen(sb);
27127 + err = au_digen_test(d1, sigen);
27128 + AuDebugOn(!err && au_dbrange_test(d1));
27130 + err = au_digen_test(d2, sigen);
27131 + AuDebugOn(!err && au_dbrange_test(d2));
27133 + if (unlikely(err))
27134 + aufs_read_and_write_unlock2(d1, d2);
27141 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
27143 + di_write_unlock2(d1, d2);
27144 + si_read_unlock(d1->d_sb);
27146 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27147 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27148 +++ linux/fs/aufs/spl.h 2017-07-29 12:14:25.906375514 +0200
27151 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27153 + * This program, aufs is free software; you can redistribute it and/or modify
27154 + * it under the terms of the GNU General Public License as published by
27155 + * the Free Software Foundation; either version 2 of the License, or
27156 + * (at your option) any later version.
27158 + * This program is distributed in the hope that it will be useful,
27159 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27160 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27161 + * GNU General Public License for more details.
27163 + * You should have received a copy of the GNU General Public License
27164 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27168 + * simple list protected by a spinlock
27171 +#ifndef __AUFS_SPL_H__
27172 +#define __AUFS_SPL_H__
27177 +struct au_splhead {
27179 + struct list_head head;
27182 +static inline void au_spl_init(struct au_splhead *spl)
27184 + spin_lock_init(&spl->spin);
27185 + INIT_LIST_HEAD(&spl->head);
27188 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27190 + spin_lock(&spl->spin);
27191 + list_add(list, &spl->head);
27192 + spin_unlock(&spl->spin);
27195 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27197 + spin_lock(&spl->spin);
27199 + spin_unlock(&spl->spin);
27202 +static inline void au_spl_del_rcu(struct list_head *list,
27203 + struct au_splhead *spl)
27205 + spin_lock(&spl->spin);
27206 + list_del_rcu(list);
27207 + spin_unlock(&spl->spin);
27211 +/* ---------------------------------------------------------------------- */
27213 +struct au_sphlhead {
27215 + struct hlist_head head;
27218 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27220 + spin_lock_init(&sphl->spin);
27221 + INIT_HLIST_HEAD(&sphl->head);
27224 +static inline void au_sphl_add(struct hlist_node *hlist,
27225 + struct au_sphlhead *sphl)
27227 + spin_lock(&sphl->spin);
27228 + hlist_add_head(hlist, &sphl->head);
27229 + spin_unlock(&sphl->spin);
27232 +static inline void au_sphl_del(struct hlist_node *hlist,
27233 + struct au_sphlhead *sphl)
27235 + spin_lock(&sphl->spin);
27236 + hlist_del(hlist);
27237 + spin_unlock(&sphl->spin);
27240 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27241 + struct au_sphlhead *sphl)
27243 + spin_lock(&sphl->spin);
27244 + hlist_del_rcu(hlist);
27245 + spin_unlock(&sphl->spin);
27248 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27250 + unsigned long cnt;
27251 + struct hlist_node *pos;
27254 + spin_lock(&sphl->spin);
27255 + hlist_for_each(pos, &sphl->head)
27257 + spin_unlock(&sphl->spin);
27261 +#endif /* __KERNEL__ */
27262 +#endif /* __AUFS_SPL_H__ */
27263 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27264 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27265 +++ linux/fs/aufs/super.c 2017-07-29 12:14:25.906375514 +0200
27268 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27270 + * This program, aufs is free software; you can redistribute it and/or modify
27271 + * it under the terms of the GNU General Public License as published by
27272 + * the Free Software Foundation; either version 2 of the License, or
27273 + * (at your option) any later version.
27275 + * This program is distributed in the hope that it will be useful,
27276 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27277 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27278 + * GNU General Public License for more details.
27280 + * You should have received a copy of the GNU General Public License
27281 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27285 + * mount and super_block operations
27288 +#include <linux/mm.h>
27289 +#include <linux/seq_file.h>
27290 +#include <linux/statfs.h>
27291 +#include <linux/vmalloc.h>
27295 + * super_operations
27297 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27299 + struct au_icntnr *c;
27301 + c = au_cache_alloc_icntnr();
27303 + au_icntnr_init(c);
27304 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27305 + c->iinfo.ii_hinode = NULL;
27306 + return &c->vfs_inode;
27311 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27313 + struct inode *inode = container_of(head, struct inode, i_rcu);
27315 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27318 +static void aufs_destroy_inode(struct inode *inode)
27320 + if (!au_is_bad_inode(inode))
27321 + au_iinfo_fin(inode);
27322 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27325 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27327 + struct inode *inode;
27330 + inode = iget_locked(sb, ino);
27331 + if (unlikely(!inode)) {
27332 + inode = ERR_PTR(-ENOMEM);
27335 + if (!(inode->i_state & I_NEW))
27338 + err = au_xigen_new(inode);
27340 + err = au_iinfo_init(inode);
27342 + inode->i_version++;
27344 + iget_failed(inode);
27345 + inode = ERR_PTR(err);
27349 + /* never return NULL */
27350 + AuDebugOn(!inode);
27351 + AuTraceErrPtr(inode);
27355 +/* lock free root dinfo */
27356 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27359 + aufs_bindex_t bindex, bbot;
27360 + struct path path;
27361 + struct au_hdentry *hdp;
27362 + struct au_branch *br;
27363 + au_br_perm_str_t perm;
27366 + bbot = au_sbbot(sb);
27368 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27369 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27370 + br = au_sbr(sb, bindex);
27371 + path.mnt = au_br_mnt(br);
27372 + path.dentry = hdp->hd_dentry;
27373 + err = au_seq_path(seq, &path);
27375 + au_optstr_br_perm(&perm, br->br_perm);
27376 + seq_printf(seq, "=%s", perm.a);
27377 + if (bindex != bbot)
27378 + seq_putc(seq, ':');
27381 + if (unlikely(err || seq_has_overflowed(seq)))
27387 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
27388 + const char *append)
27393 + while (*pat != ':')
27396 + strcpy(p, append);
27397 + AuDebugOn(strlen(fmt) >= len);
27400 +static void au_show_wbr_create(struct seq_file *m, int v,
27401 + struct au_sbinfo *sbinfo)
27405 + struct au_wbr_mfs *mfs;
27407 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27409 + seq_puts(m, ",create=");
27410 + pat = au_optstr_wbr_create(v);
27411 + mfs = &sbinfo->si_wbr_mfs;
27413 + case AuWbrCreate_TDP:
27414 + case AuWbrCreate_RR:
27415 + case AuWbrCreate_MFS:
27416 + case AuWbrCreate_PMFS:
27417 + seq_puts(m, pat);
27419 + case AuWbrCreate_MFSRR:
27420 + case AuWbrCreate_TDMFS:
27421 + case AuWbrCreate_PMFSRR:
27422 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
27423 + seq_printf(m, fmt, mfs->mfsrr_watermark);
27425 + case AuWbrCreate_MFSV:
27426 + case AuWbrCreate_PMFSV:
27427 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
27428 + seq_printf(m, fmt,
27429 + jiffies_to_msecs(mfs->mfs_expire)
27432 + case AuWbrCreate_MFSRRV:
27433 + case AuWbrCreate_TDMFSV:
27434 + case AuWbrCreate_PMFSRRV:
27435 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
27436 + seq_printf(m, fmt, mfs->mfsrr_watermark,
27437 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
27444 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27446 +#ifdef CONFIG_SYSFS
27450 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27451 + aufs_bindex_t bindex, brid;
27452 + struct qstr *name;
27454 + struct dentry *d, *h_root;
27456 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27459 + f = au_sbi(sb)->si_xib;
27463 + /* stop printing the default xino path on the first writable branch */
27465 + brid = au_xino_brid(sb);
27467 + bindex = au_br_index(sb, brid);
27468 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27470 + d = f->f_path.dentry;
27471 + name = &d->d_name;
27472 + /* safe ->d_parent because the file is unlinked */
27473 + if (d->d_parent == h_root
27474 + && name->len == len
27475 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27478 + seq_puts(seq, ",xino=");
27479 + err = au_xino_path(seq, f);
27486 +/* seq_file will re-call me in case of too long string */
27487 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27490 + unsigned int mnt_flags, v;
27491 + struct super_block *sb;
27492 + struct au_sbinfo *sbinfo;
27494 +#define AuBool(name, str) do { \
27495 + v = au_opt_test(mnt_flags, name); \
27496 + if (v != au_opt_test(AuOpt_Def, name)) \
27497 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27500 +#define AuStr(name, str) do { \
27501 + v = mnt_flags & AuOptMask_##name; \
27502 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27503 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27506 +#define AuUInt(name, str, val) do { \
27507 + if (val != AUFS_##name##_DEF) \
27508 + seq_printf(m, "," #str "=%u", val); \
27511 + sb = dentry->d_sb;
27512 + if (sb->s_flags & MS_POSIXACL)
27513 + seq_puts(m, ",acl");
27515 + /* lock free root dinfo */
27516 + si_noflush_read_lock(sb);
27517 + sbinfo = au_sbi(sb);
27518 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27520 + mnt_flags = au_mntflags(sb);
27521 + if (au_opt_test(mnt_flags, XINO)) {
27522 + err = au_show_xino(m, sb);
27523 + if (unlikely(err))
27526 + seq_puts(m, ",noxino");
27528 + AuBool(TRUNC_XINO, trunc_xino);
27529 + AuStr(UDBA, udba);
27530 + AuBool(SHWH, shwh);
27531 + AuBool(PLINK, plink);
27532 + AuBool(DIO, dio);
27533 + AuBool(DIRPERM1, dirperm1);
27535 + v = sbinfo->si_wbr_create;
27536 + if (v != AuWbrCreate_Def)
27537 + au_show_wbr_create(m, v, sbinfo);
27539 + v = sbinfo->si_wbr_copyup;
27540 + if (v != AuWbrCopyup_Def)
27541 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27543 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27544 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27545 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27547 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27549 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27550 + AuUInt(RDCACHE, rdcache, v);
27552 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27553 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27555 + au_fhsm_show(m, sbinfo);
27557 + AuBool(SUM, sum);
27558 + /* AuBool(SUM_W, wsum); */
27559 + AuBool(WARN_PERM, warn_perm);
27560 + AuBool(VERBOSE, verbose);
27563 + /* be sure to print "br:" last */
27564 + if (!sysaufs_brs) {
27565 + seq_puts(m, ",br:");
27566 + au_show_brs(m, sb);
27568 + si_read_unlock(sb);
27576 +/* ---------------------------------------------------------------------- */
27578 +/* sum mode which returns the summation for statfs(2) */
27580 +static u64 au_add_till_max(u64 a, u64 b)
27588 + return ULLONG_MAX;
27591 +static u64 au_mul_till_max(u64 a, long mul)
27599 + return ULLONG_MAX;
27602 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27605 + long bsize, factor;
27606 + u64 blocks, bfree, bavail, files, ffree;
27607 + aufs_bindex_t bbot, bindex, i;
27608 + unsigned char shared;
27609 + struct path h_path;
27610 + struct super_block *h_sb;
27613 + bsize = LONG_MAX;
27619 + bbot = au_sbbot(sb);
27620 + for (bindex = 0; bindex <= bbot; bindex++) {
27621 + h_path.mnt = au_sbr_mnt(sb, bindex);
27622 + h_sb = h_path.mnt->mnt_sb;
27624 + for (i = 0; !shared && i < bindex; i++)
27625 + shared = (au_sbr_sb(sb, i) == h_sb);
27629 + /* sb->s_root for NFS is unreliable */
27630 + h_path.dentry = h_path.mnt->mnt_root;
27631 + err = vfs_statfs(&h_path, buf);
27632 + if (unlikely(err))
27635 + if (bsize > buf->f_bsize) {
27637 + * we will reduce bsize, so we have to expand blocks
27638 + * etc. to match them again
27640 + factor = (bsize / buf->f_bsize);
27641 + blocks = au_mul_till_max(blocks, factor);
27642 + bfree = au_mul_till_max(bfree, factor);
27643 + bavail = au_mul_till_max(bavail, factor);
27644 + bsize = buf->f_bsize;
27647 + factor = (buf->f_bsize / bsize);
27648 + blocks = au_add_till_max(blocks,
27649 + au_mul_till_max(buf->f_blocks, factor));
27650 + bfree = au_add_till_max(bfree,
27651 + au_mul_till_max(buf->f_bfree, factor));
27652 + bavail = au_add_till_max(bavail,
27653 + au_mul_till_max(buf->f_bavail, factor));
27654 + files = au_add_till_max(files, buf->f_files);
27655 + ffree = au_add_till_max(ffree, buf->f_ffree);
27658 + buf->f_bsize = bsize;
27659 + buf->f_blocks = blocks;
27660 + buf->f_bfree = bfree;
27661 + buf->f_bavail = bavail;
27662 + buf->f_files = files;
27663 + buf->f_ffree = ffree;
27664 + buf->f_frsize = 0;
27670 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27673 + struct path h_path;
27674 + struct super_block *sb;
27676 + /* lock free root dinfo */
27677 + sb = dentry->d_sb;
27678 + si_noflush_read_lock(sb);
27679 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27680 + /* sb->s_root for NFS is unreliable */
27681 + h_path.mnt = au_sbr_mnt(sb, 0);
27682 + h_path.dentry = h_path.mnt->mnt_root;
27683 + err = vfs_statfs(&h_path, buf);
27685 + err = au_statfs_sum(sb, buf);
27686 + si_read_unlock(sb);
27689 + buf->f_type = AUFS_SUPER_MAGIC;
27690 + buf->f_namelen = AUFS_MAX_NAMELEN;
27691 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27693 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27698 +/* ---------------------------------------------------------------------- */
27700 +static int aufs_sync_fs(struct super_block *sb, int wait)
27703 + aufs_bindex_t bbot, bindex;
27704 + struct au_branch *br;
27705 + struct super_block *h_sb;
27708 + si_noflush_read_lock(sb);
27709 + bbot = au_sbbot(sb);
27710 + for (bindex = 0; bindex <= bbot; bindex++) {
27711 + br = au_sbr(sb, bindex);
27712 + if (!au_br_writable(br->br_perm))
27715 + h_sb = au_sbr_sb(sb, bindex);
27716 + e = vfsub_sync_filesystem(h_sb, wait);
27717 + if (unlikely(e && !err))
27719 + /* go on even if an error happens */
27721 + si_read_unlock(sb);
27726 +/* ---------------------------------------------------------------------- */
27728 +/* final actions when unmounting a file system */
27729 +static void aufs_put_super(struct super_block *sb)
27731 + struct au_sbinfo *sbinfo;
27733 + sbinfo = au_sbi(sb);
27737 + dbgaufs_si_fin(sbinfo);
27738 + kobject_put(&sbinfo->si_kobj);
27741 +/* ---------------------------------------------------------------------- */
27743 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27744 + struct super_block *sb, void *arg)
27747 + unsigned long long n, sz;
27754 + if (*hint > ULLONG_MAX / sizeof(array)) {
27755 + array = ERR_PTR(-EMFILE);
27756 + pr_err("hint %llu\n", *hint);
27760 + sz = sizeof(array) * *hint;
27761 + array = kzalloc(sz, GFP_NOFS);
27762 + if (unlikely(!array))
27763 + array = vzalloc(sz);
27764 + if (unlikely(!array)) {
27765 + array = ERR_PTR(-ENOMEM);
27769 + n = cb(sb, array, *hint, arg);
27770 + AuDebugOn(n > *hint);
27777 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27778 + unsigned long long max __maybe_unused,
27781 + unsigned long long n;
27782 + struct inode **p, *inode;
27783 + struct list_head *head;
27788 + spin_lock(&sb->s_inode_list_lock);
27789 + list_for_each_entry(inode, head, i_sb_list) {
27790 + if (!au_is_bad_inode(inode)
27791 + && au_ii(inode)->ii_btop >= 0) {
27792 + spin_lock(&inode->i_lock);
27793 + if (atomic_read(&inode->i_count)) {
27797 + AuDebugOn(n > max);
27799 + spin_unlock(&inode->i_lock);
27802 + spin_unlock(&sb->s_inode_list_lock);
27807 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27809 + *max = au_ninodes(sb);
27810 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27813 +void au_iarray_free(struct inode **a, unsigned long long max)
27815 + unsigned long long ull;
27817 + for (ull = 0; ull < max; ull++)
27822 +/* ---------------------------------------------------------------------- */
27825 + * refresh dentry and inode at remount time.
27827 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27828 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27829 + struct dentry *parent)
27833 + di_write_lock_child(dentry);
27834 + di_read_lock_parent(parent, AuLock_IR);
27835 + err = au_refresh_dentry(dentry, parent);
27836 + if (!err && dir_flags)
27837 + au_hn_reset(d_inode(dentry), dir_flags);
27838 + di_read_unlock(parent, AuLock_IR);
27839 + di_write_unlock(dentry);
27844 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27845 + struct au_sbinfo *sbinfo,
27846 + const unsigned int dir_flags, unsigned int do_idop)
27849 + struct dentry *parent;
27852 + parent = dget_parent(dentry);
27853 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27854 + if (d_really_is_positive(dentry)) {
27855 + if (!d_is_dir(dentry))
27856 + err = au_do_refresh(dentry, /*dir_flags*/0,
27859 + err = au_do_refresh(dentry, dir_flags, parent);
27860 + if (unlikely(err))
27861 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27864 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27865 + AuDbgDentry(dentry);
27871 + au_refresh_dop(dentry, /*force_reval*/0);
27873 + au_refresh_dop(dentry, /*force_reval*/1);
27879 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27881 + int err, i, j, ndentry, e;
27882 + unsigned int sigen;
27883 + struct au_dcsub_pages dpages;
27884 + struct au_dpage *dpage;
27885 + struct dentry **dentries, *d;
27886 + struct au_sbinfo *sbinfo;
27887 + struct dentry *root = sb->s_root;
27888 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27891 + au_refresh_dop(root, /*force_reval*/0);
27893 + err = au_dpages_init(&dpages, GFP_NOFS);
27894 + if (unlikely(err))
27896 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27897 + if (unlikely(err))
27900 + sigen = au_sigen(sb);
27901 + sbinfo = au_sbi(sb);
27902 + for (i = 0; i < dpages.ndpage; i++) {
27903 + dpage = dpages.dpages + i;
27904 + dentries = dpage->dentries;
27905 + ndentry = dpage->ndentry;
27906 + for (j = 0; j < ndentry; j++) {
27908 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27910 + if (unlikely(e && !err))
27912 + /* go on even err */
27917 + au_dpages_free(&dpages);
27922 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27925 + unsigned int sigen;
27926 + unsigned long long max, ull;
27927 + struct inode *inode, **array;
27929 + array = au_iarray_alloc(sb, &max);
27930 + err = PTR_ERR(array);
27931 + if (IS_ERR(array))
27935 + sigen = au_sigen(sb);
27936 + for (ull = 0; ull < max; ull++) {
27937 + inode = array[ull];
27938 + if (unlikely(!inode))
27942 + ii_write_lock_child(inode);
27943 + if (au_iigen(inode, NULL) != sigen) {
27944 + e = au_refresh_hinode_self(inode);
27945 + if (unlikely(e)) {
27946 + au_refresh_iop(inode, /*force_getattr*/1);
27947 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27950 + /* go on even if err */
27953 + if (!e && do_idop)
27954 + au_refresh_iop(inode, /*force_getattr*/0);
27955 + ii_write_unlock(inode);
27958 + au_iarray_free(array, max);
27964 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27967 + unsigned int udba;
27968 + aufs_bindex_t bindex, bbot;
27969 + struct dentry *root;
27970 + struct inode *inode;
27971 + struct au_branch *br;
27972 + struct au_sbinfo *sbi;
27974 + au_sigen_inc(sb);
27975 + sbi = au_sbi(sb);
27976 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27978 + root = sb->s_root;
27979 + DiMustNoWaiters(root);
27980 + inode = d_inode(root);
27981 + IiMustNoWaiters(inode);
27983 + udba = au_opt_udba(sb);
27984 + bbot = au_sbbot(sb);
27985 + for (bindex = 0; bindex <= bbot; bindex++) {
27986 + br = au_sbr(sb, bindex);
27987 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27988 + if (unlikely(err))
27989 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27991 + /* go on even if err */
27993 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27996 + if (au_ftest_si(sbi, NO_DREVAL)) {
27997 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27998 + sb->s_d_op = &aufs_dop_noreval;
27999 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
28000 + sbi->si_iop_array = aufs_iop_nogetattr;
28002 + AuDebugOn(sb->s_d_op == &aufs_dop);
28003 + sb->s_d_op = &aufs_dop;
28004 + AuDebugOn(sbi->si_iop_array == aufs_iop);
28005 + sbi->si_iop_array = aufs_iop;
28007 + pr_info("reset to %pf and %pf\n",
28008 + sb->s_d_op, sbi->si_iop_array);
28011 + di_write_unlock(root);
28012 + err = au_refresh_d(sb, do_idop);
28013 + e = au_refresh_i(sb, do_idop);
28014 + if (unlikely(e && !err))
28016 + /* aufs_write_lock() calls ..._child() */
28017 + di_write_lock_child(root);
28019 + au_cpup_attr_all(inode, /*force*/1);
28021 + if (unlikely(err))
28022 + AuIOErr("refresh failed, ignored, %d\n", err);
28025 +/* stop extra interpretation of errno in mount(8), and strange error messages */
28026 +static int cvt_err(int err)
28040 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
28043 + unsigned int mntflags;
28044 + struct au_opts opts = {
28047 + struct dentry *root;
28048 + struct inode *inode;
28049 + struct au_sbinfo *sbinfo;
28052 + root = sb->s_root;
28053 + if (!data || !*data) {
28054 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28056 + di_write_lock_child(root);
28057 + err = au_opts_verify(sb, *flags, /*pending*/0);
28058 + aufs_write_unlock(root);
28064 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28065 + if (unlikely(!opts.opt))
28067 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28068 + opts.flags = AuOpts_REMOUNT;
28069 + opts.sb_flags = *flags;
28071 + /* parse it before aufs lock */
28072 + err = au_opts_parse(sb, data, &opts);
28073 + if (unlikely(err))
28076 + sbinfo = au_sbi(sb);
28077 + inode = d_inode(root);
28078 + inode_lock(inode);
28079 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28080 + if (unlikely(err))
28082 + di_write_lock_child(root);
28084 + /* au_opts_remount() may return an error */
28085 + err = au_opts_remount(sb, &opts);
28086 + au_opts_free(&opts);
28088 + if (au_ftest_opts(opts.flags, REFRESH))
28089 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
28091 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
28092 + mntflags = au_mntflags(sb);
28093 + do_dx = !!au_opt_test(mntflags, DIO);
28094 + au_dy_arefresh(do_dx);
28097 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
28098 + aufs_write_unlock(root);
28101 + inode_unlock(inode);
28103 + free_page((unsigned long)opts.opt);
28105 + err = cvt_err(err);
28110 +static const struct super_operations aufs_sop = {
28111 + .alloc_inode = aufs_alloc_inode,
28112 + .destroy_inode = aufs_destroy_inode,
28113 + /* always deleting, no clearing */
28114 + .drop_inode = generic_delete_inode,
28115 + .show_options = aufs_show_options,
28116 + .statfs = aufs_statfs,
28117 + .put_super = aufs_put_super,
28118 + .sync_fs = aufs_sync_fs,
28119 + .remount_fs = aufs_remount_fs
28122 +/* ---------------------------------------------------------------------- */
28124 +static int alloc_root(struct super_block *sb)
28127 + struct inode *inode;
28128 + struct dentry *root;
28131 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28132 + err = PTR_ERR(inode);
28133 + if (IS_ERR(inode))
28136 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28137 + inode->i_fop = &aufs_dir_fop;
28138 + inode->i_mode = S_IFDIR;
28139 + set_nlink(inode, 2);
28140 + unlock_new_inode(inode);
28142 + root = d_make_root(inode);
28143 + if (unlikely(!root))
28145 + err = PTR_ERR(root);
28146 + if (IS_ERR(root))
28149 + err = au_di_init(root);
28151 + sb->s_root = root;
28152 + return 0; /* success */
28160 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28161 + int silent __maybe_unused)
28164 + struct au_opts opts = {
28167 + struct au_sbinfo *sbinfo;
28168 + struct dentry *root;
28169 + struct inode *inode;
28170 + char *arg = raw_data;
28172 + if (unlikely(!arg || !*arg)) {
28174 + pr_err("no arg\n");
28179 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28180 + if (unlikely(!opts.opt))
28182 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28183 + opts.sb_flags = sb->s_flags;
28185 + err = au_si_alloc(sb);
28186 + if (unlikely(err))
28188 + sbinfo = au_sbi(sb);
28190 + /* all timestamps always follow the ones on the branch */
28191 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28192 + sb->s_op = &aufs_sop;
28193 + sb->s_d_op = &aufs_dop;
28194 + sb->s_magic = AUFS_SUPER_MAGIC;
28195 + sb->s_maxbytes = 0;
28196 + sb->s_stack_depth = 1;
28197 + au_export_init(sb);
28198 + au_xattr_init(sb);
28200 + err = alloc_root(sb);
28201 + if (unlikely(err)) {
28202 + si_write_unlock(sb);
28205 + root = sb->s_root;
28206 + inode = d_inode(root);
28209 + * actually we can parse options regardless aufs lock here.
28210 + * but at remount time, parsing must be done before aufs lock.
28211 + * so we follow the same rule.
28213 + ii_write_lock_parent(inode);
28214 + aufs_write_unlock(root);
28215 + err = au_opts_parse(sb, arg, &opts);
28216 + if (unlikely(err))
28219 + /* lock vfs_inode first, then aufs. */
28220 + inode_lock(inode);
28221 + aufs_write_lock(root);
28222 + err = au_opts_mount(sb, &opts);
28223 + au_opts_free(&opts);
28224 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28225 + sb->s_d_op = &aufs_dop_noreval;
28226 + pr_info("%pf\n", sb->s_d_op);
28227 + au_refresh_dop(root, /*force_reval*/0);
28228 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28229 + au_refresh_iop(inode, /*force_getattr*/0);
28231 + aufs_write_unlock(root);
28232 + inode_unlock(inode);
28234 + goto out_opts; /* success */
28238 + sb->s_root = NULL;
28240 + dbgaufs_si_fin(sbinfo);
28241 + kobject_put(&sbinfo->si_kobj);
28242 + sb->s_fs_info = NULL;
28244 + free_page((unsigned long)opts.opt);
28247 + err = cvt_err(err);
28252 +/* ---------------------------------------------------------------------- */
28254 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28255 + const char *dev_name __maybe_unused,
28258 + struct dentry *root;
28259 + struct super_block *sb;
28261 + /* all timestamps always follow the ones on the branch */
28262 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28263 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28264 + if (IS_ERR(root))
28268 + si_write_lock(sb, !AuLock_FLUSH);
28269 + sysaufs_brs_add(sb, 0);
28270 + si_write_unlock(sb);
28271 + au_sbilist_add(sb);
28277 +static void aufs_kill_sb(struct super_block *sb)
28279 + struct au_sbinfo *sbinfo;
28281 + sbinfo = au_sbi(sb);
28283 + au_sbilist_del(sb);
28284 + aufs_write_lock(sb->s_root);
28286 + if (sbinfo->si_wbr_create_ops->fin)
28287 + sbinfo->si_wbr_create_ops->fin(sb);
28288 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28289 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28290 + au_remount_refresh(sb, /*do_idop*/0);
28292 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28293 + au_plink_put(sb, /*verbose*/1);
28295 + sbinfo->si_sb = NULL;
28296 + aufs_write_unlock(sb->s_root);
28297 + au_nwt_flush(&sbinfo->si_nowait);
28299 + kill_anon_super(sb);
28302 +struct file_system_type aufs_fs_type = {
28303 + .name = AUFS_FSTYPE,
28304 + /* a race between rename and others */
28305 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28306 + .mount = aufs_mount,
28307 + .kill_sb = aufs_kill_sb,
28308 + /* no need to __module_get() and module_put(). */
28309 + .owner = THIS_MODULE,
28311 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28312 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28313 +++ linux/fs/aufs/super.h 2017-07-29 12:14:25.906375514 +0200
28316 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28318 + * This program, aufs is free software; you can redistribute it and/or modify
28319 + * it under the terms of the GNU General Public License as published by
28320 + * the Free Software Foundation; either version 2 of the License, or
28321 + * (at your option) any later version.
28323 + * This program is distributed in the hope that it will be useful,
28324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28326 + * GNU General Public License for more details.
28328 + * You should have received a copy of the GNU General Public License
28329 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28333 + * super_block operations
28336 +#ifndef __AUFS_SUPER_H__
28337 +#define __AUFS_SUPER_H__
28341 +#include <linux/fs.h>
28342 +#include <linux/kobject.h>
28343 +#include "rwsem.h"
28347 +/* policies to select one among multiple writable branches */
28348 +struct au_wbr_copyup_operations {
28349 + int (*copyup)(struct dentry *dentry);
28352 +#define AuWbr_DIR 1 /* target is a dir */
28353 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28355 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28356 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28357 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28359 +struct au_wbr_create_operations {
28360 + int (*create)(struct dentry *dentry, unsigned int flags);
28361 + int (*init)(struct super_block *sb);
28362 + int (*fin)(struct super_block *sb);
28365 +struct au_wbr_mfs {
28366 + struct mutex mfs_lock; /* protect this structure */
28367 + unsigned long mfs_jiffy;
28368 + unsigned long mfs_expire;
28369 + aufs_bindex_t mfs_bindex;
28371 + unsigned long long mfsrr_bytes;
28372 + unsigned long long mfsrr_watermark;
28375 +#define AuPlink_NHASH 100
28376 +static inline int au_plink_hash(ino_t ino)
28378 + return ino % AuPlink_NHASH;
28381 +/* File-based Hierarchical Storage Management */
28383 +#ifdef CONFIG_AUFS_FHSM
28384 + /* allow only one process who can receive the notification */
28385 + spinlock_t fhsm_spin;
28387 + wait_queue_head_t fhsm_wqh;
28388 + atomic_t fhsm_readable;
28390 + /* these are protected by si_rwsem */
28391 + unsigned long fhsm_expire;
28392 + aufs_bindex_t fhsm_bottom;
28397 +struct au_sbinfo {
28398 + /* nowait tasks in the system-wide workqueue */
28399 + struct au_nowait_tasks si_nowait;
28402 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28403 + * rwsem for au_sbinfo is necessary.
28405 + struct au_rwsem si_rwsem;
28408 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28411 + struct percpu_counter si_ninodes, si_nfiles;
28413 + /* branch management */
28414 + unsigned int si_generation;
28416 + /* see AuSi_ flags */
28417 + unsigned char au_si_status;
28419 + aufs_bindex_t si_bbot;
28421 + /* dirty trick to keep br_id plus */
28422 + unsigned int si_last_br_id :
28423 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28424 + struct au_branch **si_branch;
28426 + /* policy to select a writable branch */
28427 + unsigned char si_wbr_copyup;
28428 + unsigned char si_wbr_create;
28429 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28430 + struct au_wbr_create_operations *si_wbr_create_ops;
28432 + /* round robin */
28433 + atomic_t si_wbr_rr_next;
28435 + /* most free space */
28436 + struct au_wbr_mfs si_wbr_mfs;
28438 + /* File-based Hierarchical Storage Management */
28439 + struct au_fhsm si_fhsm;
28441 + /* mount flags */
28442 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28443 + unsigned int si_mntflags;
28445 + /* external inode number (bitmap and translation table) */
28446 + vfs_readf_t si_xread;
28447 + vfs_writef_t si_xwrite;
28448 + struct file *si_xib;
28449 + struct mutex si_xib_mtx; /* protect xib members */
28450 + unsigned long *si_xib_buf;
28451 + unsigned long si_xib_last_pindex;
28452 + int si_xib_next_bit;
28453 + aufs_bindex_t si_xino_brid;
28454 + unsigned long si_xino_jiffy;
28455 + unsigned long si_xino_expire;
28456 + /* reserved for future use */
28457 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28459 +#ifdef CONFIG_AUFS_EXPORT
28460 + /* i_generation */
28461 + struct file *si_xigen;
28462 + atomic_t si_xigen_next;
28465 + /* dirty trick to suppoer atomic_open */
28466 + struct au_sphlhead si_aopen;
28468 + /* vdir parameters */
28469 + unsigned long si_rdcache; /* max cache time in jiffies */
28470 + unsigned int si_rdblk; /* deblk size */
28471 + unsigned int si_rdhash; /* hash size */
28474 + * If the number of whiteouts are larger than si_dirwh, leave all of
28475 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28476 + * future fsck.aufs or kernel thread will remove them later.
28477 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28479 + unsigned int si_dirwh;
28481 + /* pseudo_link list */
28482 + struct au_sphlhead si_plink[AuPlink_NHASH];
28483 + wait_queue_head_t si_plink_wq;
28484 + spinlock_t si_plink_maint_lock;
28485 + pid_t si_plink_maint_pid;
28488 + struct au_sphlhead si_files;
28490 + /* with/without getattr, brother of sb->s_d_op */
28491 + struct inode_operations *si_iop_array;
28494 + * sysfs and lifetime management.
28495 + * this is not a small structure and it may be a waste of memory in case
28496 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28497 + * but using sysfs is majority.
28499 + struct kobject si_kobj;
28500 +#ifdef CONFIG_DEBUG_FS
28501 + struct dentry *si_dbgaufs;
28502 + struct dentry *si_dbgaufs_plink;
28503 + struct dentry *si_dbgaufs_xib;
28504 +#ifdef CONFIG_AUFS_EXPORT
28505 + struct dentry *si_dbgaufs_xigen;
28509 +#ifdef CONFIG_AUFS_SBILIST
28510 + struct hlist_node si_list;
28513 + /* dirty, necessary for unmounting, sysfs and sysrq */
28514 + struct super_block *si_sb;
28517 +/* sbinfo status flags */
28519 + * set true when refresh_dirs() failed at remount time.
28520 + * then try refreshing dirs at access time again.
28521 + * if it is false, refreshing dirs at access time is unnecesary
28523 +#define AuSi_FAILED_REFRESH_DIR 1
28524 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28525 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28527 +#ifndef CONFIG_AUFS_FHSM
28529 +#define AuSi_FHSM 0
28532 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28533 + unsigned int flag)
28535 + AuRwMustAnyLock(&sbi->si_rwsem);
28536 + return sbi->au_si_status & flag;
28538 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28539 +#define au_fset_si(sbinfo, name) do { \
28540 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28541 + (sbinfo)->au_si_status |= AuSi_##name; \
28543 +#define au_fclr_si(sbinfo, name) do { \
28544 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28545 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28548 +/* ---------------------------------------------------------------------- */
28550 +/* policy to select one among writable branches */
28551 +#define AuWbrCopyup(sbinfo, ...) \
28552 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28553 +#define AuWbrCreate(sbinfo, ...) \
28554 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28556 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28557 +#define AuLock_DW 1 /* write-lock dentry */
28558 +#define AuLock_IR (1 << 1) /* read-lock inode */
28559 +#define AuLock_IW (1 << 2) /* write-lock inode */
28560 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28561 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28562 + /* except RENAME_EXCHANGE */
28563 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28564 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28565 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28566 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28567 +#define au_fset_lock(flags, name) \
28568 + do { (flags) |= AuLock_##name; } while (0)
28569 +#define au_fclr_lock(flags, name) \
28570 + do { (flags) &= ~AuLock_##name; } while (0)
28572 +/* ---------------------------------------------------------------------- */
28575 +extern struct file_system_type aufs_fs_type;
28576 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28577 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28578 + unsigned long long max, void *arg);
28579 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28580 + struct super_block *sb, void *arg);
28581 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28582 +void au_iarray_free(struct inode **a, unsigned long long max);
28585 +void au_si_free(struct kobject *kobj);
28586 +int au_si_alloc(struct super_block *sb);
28587 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28589 +unsigned int au_sigen_inc(struct super_block *sb);
28590 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28592 +int si_read_lock(struct super_block *sb, int flags);
28593 +int si_write_lock(struct super_block *sb, int flags);
28594 +int aufs_read_lock(struct dentry *dentry, int flags);
28595 +void aufs_read_unlock(struct dentry *dentry, int flags);
28596 +void aufs_write_lock(struct dentry *dentry);
28597 +void aufs_write_unlock(struct dentry *dentry);
28598 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28599 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28601 +/* wbr_policy.c */
28602 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28603 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28604 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28605 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28606 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28609 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28611 +#ifdef CONFIG_AUFS_FHSM
28614 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28618 + spin_lock(&fhsm->fhsm_spin);
28619 + pid = fhsm->fhsm_pid;
28620 + spin_unlock(&fhsm->fhsm_spin);
28625 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28626 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28627 +int au_fhsm_fd(struct super_block *sb, int oflags);
28628 +int au_fhsm_br_alloc(struct au_branch *br);
28629 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28630 +void au_fhsm_fin(struct super_block *sb);
28631 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28632 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28633 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28635 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28637 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28638 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28639 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28640 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28641 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28642 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28643 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28644 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28645 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28648 +/* ---------------------------------------------------------------------- */
28650 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28652 + return sb->s_fs_info;
28655 +/* ---------------------------------------------------------------------- */
28657 +#ifdef CONFIG_AUFS_EXPORT
28658 +int au_test_nfsd(void);
28659 +void au_export_init(struct super_block *sb);
28660 +void au_xigen_inc(struct inode *inode);
28661 +int au_xigen_new(struct inode *inode);
28662 +int au_xigen_set(struct super_block *sb, struct file *base);
28663 +void au_xigen_clr(struct super_block *sb);
28665 +static inline int au_busy_or_stale(void)
28667 + if (!au_test_nfsd())
28672 +AuStubInt0(au_test_nfsd, void)
28673 +AuStubVoid(au_export_init, struct super_block *sb)
28674 +AuStubVoid(au_xigen_inc, struct inode *inode)
28675 +AuStubInt0(au_xigen_new, struct inode *inode)
28676 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28677 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28678 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28679 +#endif /* CONFIG_AUFS_EXPORT */
28681 +/* ---------------------------------------------------------------------- */
28683 +#ifdef CONFIG_AUFS_SBILIST
28685 +extern struct au_sphlhead au_sbilist;
28687 +static inline void au_sbilist_init(void)
28689 + au_sphl_init(&au_sbilist);
28692 +static inline void au_sbilist_add(struct super_block *sb)
28694 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28697 +static inline void au_sbilist_del(struct super_block *sb)
28699 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28702 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28703 +static inline void au_sbilist_lock(void)
28705 + spin_lock(&au_sbilist.spin);
28708 +static inline void au_sbilist_unlock(void)
28710 + spin_unlock(&au_sbilist.spin);
28712 +#define AuGFP_SBILIST GFP_ATOMIC
28714 +AuStubVoid(au_sbilist_lock, void)
28715 +AuStubVoid(au_sbilist_unlock, void)
28716 +#define AuGFP_SBILIST GFP_NOFS
28717 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28719 +AuStubVoid(au_sbilist_init, void)
28720 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28721 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28722 +AuStubVoid(au_sbilist_lock, void)
28723 +AuStubVoid(au_sbilist_unlock, void)
28724 +#define AuGFP_SBILIST GFP_NOFS
28727 +/* ---------------------------------------------------------------------- */
28729 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28732 + * This function is a dynamic '__init' function actually,
28733 + * so the tiny check for si_rwsem is unnecessary.
28735 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28736 +#ifdef CONFIG_DEBUG_FS
28737 + sbinfo->si_dbgaufs = NULL;
28738 + sbinfo->si_dbgaufs_plink = NULL;
28739 + sbinfo->si_dbgaufs_xib = NULL;
28740 +#ifdef CONFIG_AUFS_EXPORT
28741 + sbinfo->si_dbgaufs_xigen = NULL;
28746 +/* ---------------------------------------------------------------------- */
28748 +/* current->atomic_flags */
28749 +/* this value should never corrupt the ones defined in linux/sched.h */
28750 +#define PFA_AUFS 7
28752 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
28753 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
28754 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
28756 +static inline int si_pid_test(struct super_block *sb)
28758 + return !!task_test_aufs(current);
28761 +static inline void si_pid_clr(struct super_block *sb)
28763 + AuDebugOn(!task_test_aufs(current));
28764 + task_clear_aufs(current);
28767 +static inline void si_pid_set(struct super_block *sb)
28769 + AuDebugOn(task_test_aufs(current));
28770 + task_set_aufs(current);
28773 +/* ---------------------------------------------------------------------- */
28775 +/* lock superblock. mainly for entry point functions */
28777 + * __si_read_lock, __si_write_lock,
28778 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28780 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28782 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28783 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28784 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28786 +static inline void si_noflush_read_lock(struct super_block *sb)
28788 + __si_read_lock(sb);
28792 +static inline int si_noflush_read_trylock(struct super_block *sb)
28796 + locked = __si_read_trylock(sb);
28802 +static inline void si_noflush_write_lock(struct super_block *sb)
28804 + __si_write_lock(sb);
28808 +static inline int si_noflush_write_trylock(struct super_block *sb)
28812 + locked = __si_write_trylock(sb);
28818 +#if 0 /* reserved */
28819 +static inline int si_read_trylock(struct super_block *sb, int flags)
28821 + if (au_ftest_lock(flags, FLUSH))
28822 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28823 + return si_noflush_read_trylock(sb);
28827 +static inline void si_read_unlock(struct super_block *sb)
28830 + __si_read_unlock(sb);
28833 +#if 0 /* reserved */
28834 +static inline int si_write_trylock(struct super_block *sb, int flags)
28836 + if (au_ftest_lock(flags, FLUSH))
28837 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28838 + return si_noflush_write_trylock(sb);
28842 +static inline void si_write_unlock(struct super_block *sb)
28845 + __si_write_unlock(sb);
28848 +#if 0 /* reserved */
28849 +static inline void si_downgrade_lock(struct super_block *sb)
28851 + __si_downgrade_lock(sb);
28855 +/* ---------------------------------------------------------------------- */
28857 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28859 + SiMustAnyLock(sb);
28860 + return au_sbi(sb)->si_bbot;
28863 +static inline unsigned int au_mntflags(struct super_block *sb)
28865 + SiMustAnyLock(sb);
28866 + return au_sbi(sb)->si_mntflags;
28869 +static inline unsigned int au_sigen(struct super_block *sb)
28871 + SiMustAnyLock(sb);
28872 + return au_sbi(sb)->si_generation;
28875 +static inline unsigned long long au_ninodes(struct super_block *sb)
28877 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28883 +static inline void au_ninodes_inc(struct super_block *sb)
28885 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28888 +static inline void au_ninodes_dec(struct super_block *sb)
28890 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28893 +static inline unsigned long long au_nfiles(struct super_block *sb)
28895 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28901 +static inline void au_nfiles_inc(struct super_block *sb)
28903 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28906 +static inline void au_nfiles_dec(struct super_block *sb)
28908 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28911 +static inline struct au_branch *au_sbr(struct super_block *sb,
28912 + aufs_bindex_t bindex)
28914 + SiMustAnyLock(sb);
28915 + return au_sbi(sb)->si_branch[0 + bindex];
28918 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28920 + SiMustWriteLock(sb);
28921 + au_sbi(sb)->si_xino_brid = brid;
28924 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28926 + SiMustAnyLock(sb);
28927 + return au_sbi(sb)->si_xino_brid;
28930 +#endif /* __KERNEL__ */
28931 +#endif /* __AUFS_SUPER_H__ */
28932 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28933 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28934 +++ linux/fs/aufs/sysaufs.c 2017-07-29 12:14:25.906375514 +0200
28937 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28939 + * This program, aufs is free software; you can redistribute it and/or modify
28940 + * it under the terms of the GNU General Public License as published by
28941 + * the Free Software Foundation; either version 2 of the License, or
28942 + * (at your option) any later version.
28944 + * This program is distributed in the hope that it will be useful,
28945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28947 + * GNU General Public License for more details.
28949 + * You should have received a copy of the GNU General Public License
28950 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28954 + * sysfs interface and lifetime management
28955 + * they are necessary regardless sysfs is disabled.
28958 +#include <linux/random.h>
28961 +unsigned long sysaufs_si_mask;
28962 +struct kset *sysaufs_kset;
28964 +#define AuSiAttr(_name) { \
28965 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28966 + .show = sysaufs_si_##_name, \
28969 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28970 +struct attribute *sysaufs_si_attrs[] = {
28971 + &sysaufs_si_attr_xi_path.attr,
28975 +static const struct sysfs_ops au_sbi_ops = {
28976 + .show = sysaufs_si_show
28979 +static struct kobj_type au_sbi_ktype = {
28980 + .release = au_si_free,
28981 + .sysfs_ops = &au_sbi_ops,
28982 + .default_attrs = sysaufs_si_attrs
28985 +/* ---------------------------------------------------------------------- */
28987 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28991 + sbinfo->si_kobj.kset = sysaufs_kset;
28992 + /* cf. sysaufs_name() */
28993 + err = kobject_init_and_add
28994 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28995 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28997 + dbgaufs_si_null(sbinfo);
28999 + err = dbgaufs_si_init(sbinfo);
29000 + if (unlikely(err))
29001 + kobject_put(&sbinfo->si_kobj);
29006 +void sysaufs_fin(void)
29009 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29010 + kset_unregister(sysaufs_kset);
29013 +int __init sysaufs_init(void)
29018 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
29019 + } while (!sysaufs_si_mask);
29022 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
29023 + if (unlikely(!sysaufs_kset))
29025 + err = PTR_ERR(sysaufs_kset);
29026 + if (IS_ERR(sysaufs_kset))
29028 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29029 + if (unlikely(err)) {
29030 + kset_unregister(sysaufs_kset);
29034 + err = dbgaufs_init();
29035 + if (unlikely(err))
29040 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
29041 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
29042 +++ linux/fs/aufs/sysaufs.h 2017-07-29 12:14:25.906375514 +0200
29045 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29047 + * This program, aufs is free software; you can redistribute it and/or modify
29048 + * it under the terms of the GNU General Public License as published by
29049 + * the Free Software Foundation; either version 2 of the License, or
29050 + * (at your option) any later version.
29052 + * This program is distributed in the hope that it will be useful,
29053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29055 + * GNU General Public License for more details.
29057 + * You should have received a copy of the GNU General Public License
29058 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29062 + * sysfs interface and mount lifetime management
29065 +#ifndef __SYSAUFS_H__
29066 +#define __SYSAUFS_H__
29070 +#include <linux/sysfs.h>
29071 +#include "module.h"
29073 +struct super_block;
29076 +struct sysaufs_si_attr {
29077 + struct attribute attr;
29078 + int (*show)(struct seq_file *seq, struct super_block *sb);
29081 +/* ---------------------------------------------------------------------- */
29084 +extern unsigned long sysaufs_si_mask;
29085 +extern struct kset *sysaufs_kset;
29086 +extern struct attribute *sysaufs_si_attrs[];
29087 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
29088 +int __init sysaufs_init(void);
29089 +void sysaufs_fin(void);
29091 +/* ---------------------------------------------------------------------- */
29093 +/* some people doesn't like to show a pointer in kernel */
29094 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
29096 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
29099 +#define SysaufsSiNamePrefix "si_"
29100 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29101 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29103 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29104 + sysaufs_si_id(sbinfo));
29108 +#ifdef CONFIG_SYSFS
29110 +extern struct attribute_group *sysaufs_attr_group;
29112 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29113 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29115 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29116 +#ifdef CONFIG_COMPAT
29117 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29120 +void sysaufs_br_init(struct au_branch *br);
29121 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29122 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29124 +#define sysaufs_brs_init() do {} while (0)
29127 +#define sysaufs_attr_group NULL
29129 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29130 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29131 + struct attribute *attr, char *buf)
29132 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29133 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29134 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29136 +static inline void sysaufs_brs_init(void)
29141 +#endif /* CONFIG_SYSFS */
29143 +#endif /* __KERNEL__ */
29144 +#endif /* __SYSAUFS_H__ */
29145 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29146 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29147 +++ linux/fs/aufs/sysfs.c 2017-07-29 12:14:25.906375514 +0200
29150 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29152 + * This program, aufs is free software; you can redistribute it and/or modify
29153 + * it under the terms of the GNU General Public License as published by
29154 + * the Free Software Foundation; either version 2 of the License, or
29155 + * (at your option) any later version.
29157 + * This program is distributed in the hope that it will be useful,
29158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29160 + * GNU General Public License for more details.
29162 + * You should have received a copy of the GNU General Public License
29163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29167 + * sysfs interface
29170 +#include <linux/compat.h>
29171 +#include <linux/seq_file.h>
29174 +#ifdef CONFIG_AUFS_FS_MODULE
29175 +/* this entry violates the "one line per file" policy of sysfs */
29176 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29180 + static char *conf =
29181 +/* this file is generated at compiling */
29182 +#include "conf.str"
29185 + err = snprintf(buf, PAGE_SIZE, conf);
29186 + if (unlikely(err >= PAGE_SIZE))
29191 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29194 +static struct attribute *au_attr[] = {
29195 +#ifdef CONFIG_AUFS_FS_MODULE
29196 + &au_config_attr.attr,
29198 + NULL, /* need to NULL terminate the list of attributes */
29201 +static struct attribute_group sysaufs_attr_group_body = {
29205 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29207 +/* ---------------------------------------------------------------------- */
29209 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29213 + SiMustAnyLock(sb);
29216 + if (au_opt_test(au_mntflags(sb), XINO)) {
29217 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29218 + seq_putc(seq, '\n');
29224 + * the lifetime of branch is independent from the entry under sysfs.
29225 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29228 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29229 + aufs_bindex_t bindex, int idx)
29232 + struct path path;
29233 + struct dentry *root;
29234 + struct au_branch *br;
29235 + au_br_perm_str_t perm;
29237 + AuDbg("b%d\n", bindex);
29240 + root = sb->s_root;
29241 + di_read_lock_parent(root, !AuLock_IR);
29242 + br = au_sbr(sb, bindex);
29245 + case AuBrSysfs_BR:
29246 + path.mnt = au_br_mnt(br);
29247 + path.dentry = au_h_dptr(root, bindex);
29248 + err = au_seq_path(seq, &path);
29250 + au_optstr_br_perm(&perm, br->br_perm);
29251 + seq_printf(seq, "=%s\n", perm.a);
29254 + case AuBrSysfs_BRID:
29255 + seq_printf(seq, "%d\n", br->br_id);
29258 + di_read_unlock(root, !AuLock_IR);
29259 + if (unlikely(err || seq_has_overflowed(seq)))
29265 +/* ---------------------------------------------------------------------- */
29267 +static struct seq_file *au_seq(char *p, ssize_t len)
29269 + struct seq_file *seq;
29271 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29273 + /* mutex_init(&seq.lock); */
29276 + return seq; /* success */
29279 + seq = ERR_PTR(-ENOMEM);
29283 +#define SysaufsBr_PREFIX "br"
29284 +#define SysaufsBrid_PREFIX "brid"
29286 +/* todo: file size may exceed PAGE_SIZE */
29287 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29293 + aufs_bindex_t bbot;
29294 + struct au_sbinfo *sbinfo;
29295 + struct super_block *sb;
29296 + struct seq_file *seq;
29298 + struct attribute **cattr;
29300 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29301 + sb = sbinfo->si_sb;
29304 + * prevent a race condition between sysfs and aufs.
29305 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29306 + * prohibits maintaining the sysfs entries.
29307 + * hew we acquire read lock after sysfs_get_active_two().
29308 + * on the other hand, the remount process may maintain the sysfs/aufs
29309 + * entries after acquiring write lock.
29310 + * it can cause a deadlock.
29311 + * simply we gave up processing read here.
29314 + if (unlikely(!si_noflush_read_trylock(sb)))
29317 + seq = au_seq(buf, PAGE_SIZE);
29318 + err = PTR_ERR(seq);
29322 + name = (void *)attr->name;
29323 + cattr = sysaufs_si_attrs;
29325 + if (!strcmp(name, (*cattr)->name)) {
29326 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29333 + if (!strncmp(name, SysaufsBrid_PREFIX,
29334 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29335 + idx = AuBrSysfs_BRID;
29336 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29337 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29338 + sizeof(SysaufsBr_PREFIX) - 1)) {
29339 + idx = AuBrSysfs_BR;
29340 + name += sizeof(SysaufsBr_PREFIX) - 1;
29344 + err = kstrtol(name, 10, &l);
29346 + bbot = au_sbbot(sb);
29348 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29355 + err = seq->count;
29356 + /* sysfs limit */
29357 + if (unlikely(err == PAGE_SIZE))
29362 + si_read_unlock(sb);
29367 +/* ---------------------------------------------------------------------- */
29369 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29373 + aufs_bindex_t bindex, bbot;
29376 + struct seq_file *seq;
29377 + struct au_branch *br;
29379 + si_read_lock(sb, AuLock_FLUSH);
29380 + bbot = au_sbbot(sb);
29386 + buf = (void *)__get_free_page(GFP_NOFS);
29387 + if (unlikely(!buf))
29390 + seq = au_seq(buf, PAGE_SIZE);
29391 + err = PTR_ERR(seq);
29395 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29396 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29397 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29398 + if (unlikely(err))
29401 + br = au_sbr(sb, bindex);
29402 + brid = br->br_id;
29403 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29404 + err = __put_user(brid, &arg->id);
29405 + if (unlikely(err))
29408 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29409 + err = __put_user(br->br_perm, &arg->perm);
29410 + if (unlikely(err))
29413 + err = au_seq_path(seq, &br->br_path);
29414 + if (unlikely(err))
29416 + seq_putc(seq, '\0');
29417 + if (!seq_has_overflowed(seq)) {
29418 + err = copy_to_user(arg->path, seq->buf, seq->count);
29420 + if (unlikely(err))
29427 + if (unlikely(err))
29433 + free_page((unsigned long)buf);
29435 + si_read_unlock(sb);
29439 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29441 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29444 +#ifdef CONFIG_COMPAT
29445 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29447 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29451 +/* ---------------------------------------------------------------------- */
29453 +void sysaufs_br_init(struct au_branch *br)
29456 + struct au_brsysfs *br_sysfs;
29457 + struct attribute *attr;
29459 + br_sysfs = br->br_sysfs;
29460 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29461 + attr = &br_sysfs->attr;
29462 + sysfs_attr_init(attr);
29463 + attr->name = br_sysfs->name;
29464 + attr->mode = S_IRUGO;
29469 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29471 + struct au_branch *br;
29472 + struct kobject *kobj;
29473 + struct au_brsysfs *br_sysfs;
29475 + aufs_bindex_t bbot;
29477 + dbgaufs_brs_del(sb, bindex);
29479 + if (!sysaufs_brs)
29482 + kobj = &au_sbi(sb)->si_kobj;
29483 + bbot = au_sbbot(sb);
29484 + for (; bindex <= bbot; bindex++) {
29485 + br = au_sbr(sb, bindex);
29486 + br_sysfs = br->br_sysfs;
29487 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29488 + sysfs_remove_file(kobj, &br_sysfs->attr);
29494 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29497 + aufs_bindex_t bbot;
29498 + struct kobject *kobj;
29499 + struct au_branch *br;
29500 + struct au_brsysfs *br_sysfs;
29502 + dbgaufs_brs_add(sb, bindex);
29504 + if (!sysaufs_brs)
29507 + kobj = &au_sbi(sb)->si_kobj;
29508 + bbot = au_sbbot(sb);
29509 + for (; bindex <= bbot; bindex++) {
29510 + br = au_sbr(sb, bindex);
29511 + br_sysfs = br->br_sysfs;
29512 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29513 + SysaufsBr_PREFIX "%d", bindex);
29514 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29515 + SysaufsBrid_PREFIX "%d", bindex);
29516 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29517 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29518 + if (unlikely(err))
29519 + pr_warn("failed %s under sysfs(%d)\n",
29520 + br_sysfs->name, err);
29525 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29526 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29527 +++ linux/fs/aufs/sysrq.c 2017-07-29 12:14:25.906375514 +0200
29530 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29532 + * This program, aufs is free software; you can redistribute it and/or modify
29533 + * it under the terms of the GNU General Public License as published by
29534 + * the Free Software Foundation; either version 2 of the License, or
29535 + * (at your option) any later version.
29537 + * This program is distributed in the hope that it will be useful,
29538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29540 + * GNU General Public License for more details.
29542 + * You should have received a copy of the GNU General Public License
29543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29547 + * magic sysrq hanlder
29550 +/* #include <linux/sysrq.h> */
29551 +#include <linux/writeback.h>
29554 +/* ---------------------------------------------------------------------- */
29556 +static void sysrq_sb(struct super_block *sb)
29559 + struct au_sbinfo *sbinfo;
29560 + struct file *file;
29561 + struct au_sphlhead *files;
29562 + struct au_finfo *finfo;
29564 + plevel = au_plevel;
29565 + au_plevel = KERN_WARNING;
29567 + /* since we define pr_fmt, call printk directly */
29568 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29570 + sbinfo = au_sbi(sb);
29571 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29572 + pr("superblock\n");
29576 + pr("root dentry\n");
29577 + au_dpri_dentry(sb->s_root);
29578 + pr("root inode\n");
29579 + au_dpri_inode(d_inode(sb->s_root));
29584 + int err, i, j, ndentry;
29585 + struct au_dcsub_pages dpages;
29586 + struct au_dpage *dpage;
29588 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29589 + if (unlikely(err))
29591 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29593 + for (i = 0; i < dpages.ndpage; i++) {
29594 + dpage = dpages.dpages + i;
29595 + ndentry = dpage->ndentry;
29596 + for (j = 0; j < ndentry; j++)
29597 + au_dpri_dentry(dpage->dentries[j]);
29599 + au_dpages_free(&dpages);
29607 + pr("isolated inode\n");
29608 + spin_lock(&sb->s_inode_list_lock);
29609 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29610 + spin_lock(&i->i_lock);
29611 + if (1 || hlist_empty(&i->i_dentry))
29612 + au_dpri_inode(i);
29613 + spin_unlock(&i->i_lock);
29615 + spin_unlock(&sb->s_inode_list_lock);
29619 + files = &au_sbi(sb)->si_files;
29620 + spin_lock(&files->spin);
29621 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29624 + file = finfo->fi_file;
29625 + mode = file_inode(file)->i_mode;
29626 + if (!special_file(mode))
29627 + au_dpri_file(file);
29629 + spin_unlock(&files->spin);
29633 + au_plevel = plevel;
29636 +/* ---------------------------------------------------------------------- */
29638 +/* module parameter */
29639 +static char *aufs_sysrq_key = "a";
29640 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29641 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29643 +static void au_sysrq(int key __maybe_unused)
29645 + struct au_sbinfo *sbinfo;
29648 + au_sbilist_lock();
29649 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29650 + sysrq_sb(sbinfo->si_sb);
29651 + au_sbilist_unlock();
29655 +static struct sysrq_key_op au_sysrq_op = {
29656 + .handler = au_sysrq,
29657 + .help_msg = "Aufs",
29658 + .action_msg = "Aufs",
29659 + .enable_mask = SYSRQ_ENABLE_DUMP
29662 +/* ---------------------------------------------------------------------- */
29664 +int __init au_sysrq_init(void)
29670 + key = *aufs_sysrq_key;
29671 + if ('a' <= key && key <= 'z')
29672 + err = register_sysrq_key(key, &au_sysrq_op);
29673 + if (unlikely(err))
29674 + pr_err("err %d, sysrq=%c\n", err, key);
29678 +void au_sysrq_fin(void)
29682 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29683 + if (unlikely(err))
29684 + pr_err("err %d (ignored)\n", err);
29686 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29687 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29688 +++ linux/fs/aufs/vdir.c 2017-07-29 12:14:25.906375514 +0200
29691 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29693 + * This program, aufs is free software; you can redistribute it and/or modify
29694 + * it under the terms of the GNU General Public License as published by
29695 + * the Free Software Foundation; either version 2 of the License, or
29696 + * (at your option) any later version.
29698 + * This program is distributed in the hope that it will be useful,
29699 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29700 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29701 + * GNU General Public License for more details.
29703 + * You should have received a copy of the GNU General Public License
29704 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29708 + * virtual or vertical directory
29713 +static unsigned int calc_size(int nlen)
29715 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29718 +static int set_deblk_end(union au_vdir_deblk_p *p,
29719 + union au_vdir_deblk_p *deblk_end)
29721 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29722 + p->de->de_str.len = 0;
29726 + return -1; /* error */
29729 +/* returns true or false */
29730 +static int is_deblk_end(union au_vdir_deblk_p *p,
29731 + union au_vdir_deblk_p *deblk_end)
29733 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29734 + return !p->de->de_str.len;
29738 +static unsigned char *last_deblk(struct au_vdir *vdir)
29740 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29743 +/* ---------------------------------------------------------------------- */
29745 +/* estimate the appropriate size for name hash table */
29746 +unsigned int au_rdhash_est(loff_t sz)
29754 + if (sz < AUFS_RDHASH_DEF)
29755 + n = AUFS_RDHASH_DEF;
29756 + /* pr_info("n %u\n", n); */
29761 + * the allocated memory has to be freed by
29762 + * au_nhash_wh_free() or au_nhash_de_free().
29764 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29766 + struct hlist_head *head;
29770 + sz = sizeof(*nhash->nh_head) * num_hash;
29771 + head = kmalloc(sz, gfp);
29773 + nhash->nh_num = num_hash;
29774 + nhash->nh_head = head;
29775 + for (u = 0; u < num_hash; u++)
29776 + INIT_HLIST_HEAD(head++);
29777 + return 0; /* success */
29783 +static void nhash_count(struct hlist_head *head)
29787 + struct hlist_node *pos;
29790 + hlist_for_each(pos, head)
29792 + pr_info("%lu\n", n);
29796 +static void au_nhash_wh_do_free(struct hlist_head *head)
29798 + struct au_vdir_wh *pos;
29799 + struct hlist_node *node;
29801 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29805 +static void au_nhash_de_do_free(struct hlist_head *head)
29807 + struct au_vdir_dehstr *pos;
29808 + struct hlist_node *node;
29810 + hlist_for_each_entry_safe(pos, node, head, hash)
29811 + au_cache_free_vdir_dehstr(pos);
29814 +static void au_nhash_do_free(struct au_nhash *nhash,
29815 + void (*free)(struct hlist_head *head))
29818 + struct hlist_head *head;
29820 + n = nhash->nh_num;
29824 + head = nhash->nh_head;
29825 + while (n-- > 0) {
29826 + nhash_count(head);
29829 + kfree(nhash->nh_head);
29832 +void au_nhash_wh_free(struct au_nhash *whlist)
29834 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29837 +static void au_nhash_de_free(struct au_nhash *delist)
29839 + au_nhash_do_free(delist, au_nhash_de_do_free);
29842 +/* ---------------------------------------------------------------------- */
29844 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29848 + unsigned int u, n;
29849 + struct hlist_head *head;
29850 + struct au_vdir_wh *pos;
29853 + n = whlist->nh_num;
29854 + head = whlist->nh_head;
29855 + for (u = 0; u < n; u++, head++)
29856 + hlist_for_each_entry(pos, head, wh_hash)
29857 + if (pos->wh_bindex == btgt && ++num > limit)
29862 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29863 + unsigned char *name,
29864 + unsigned int len)
29867 + /* const unsigned int magic_bit = 12; */
29869 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29876 + /* v = hash_long(v, magic_bit); */
29877 + v %= nhash->nh_num;
29878 + return nhash->nh_head + v;
29881 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29884 + return str->len == nlen && !memcmp(str->name, name, nlen);
29887 +/* returns found or not */
29888 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29890 + struct hlist_head *head;
29891 + struct au_vdir_wh *pos;
29892 + struct au_vdir_destr *str;
29894 + head = au_name_hash(whlist, name, nlen);
29895 + hlist_for_each_entry(pos, head, wh_hash) {
29896 + str = &pos->wh_str;
29897 + AuDbg("%.*s\n", str->len, str->name);
29898 + if (au_nhash_test_name(str, name, nlen))
29904 +/* returns found(true) or not */
29905 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29907 + struct hlist_head *head;
29908 + struct au_vdir_dehstr *pos;
29909 + struct au_vdir_destr *str;
29911 + head = au_name_hash(delist, name, nlen);
29912 + hlist_for_each_entry(pos, head, hash) {
29914 + AuDbg("%.*s\n", str->len, str->name);
29915 + if (au_nhash_test_name(str, name, nlen))
29921 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29922 + unsigned char d_type)
29924 +#ifdef CONFIG_AUFS_SHWH
29925 + wh->wh_ino = ino;
29926 + wh->wh_type = d_type;
29930 +/* ---------------------------------------------------------------------- */
29932 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29933 + unsigned int d_type, aufs_bindex_t bindex,
29934 + unsigned char shwh)
29937 + struct au_vdir_destr *str;
29938 + struct au_vdir_wh *wh;
29940 + AuDbg("%.*s\n", nlen, name);
29941 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29944 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29945 + if (unlikely(!wh))
29949 + wh->wh_bindex = bindex;
29951 + au_shwh_init_wh(wh, ino, d_type);
29952 + str = &wh->wh_str;
29954 + memcpy(str->name, name, nlen);
29955 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29962 +static int append_deblk(struct au_vdir *vdir)
29965 + unsigned long ul;
29966 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29967 + union au_vdir_deblk_p p, deblk_end;
29968 + unsigned char **o;
29971 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29972 + GFP_NOFS, /*may_shrink*/0);
29973 + if (unlikely(!o))
29976 + vdir->vd_deblk = o;
29977 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29979 + ul = vdir->vd_nblk++;
29980 + vdir->vd_deblk[ul] = p.deblk;
29981 + vdir->vd_last.ul = ul;
29982 + vdir->vd_last.p.deblk = p.deblk;
29983 + deblk_end.deblk = p.deblk + deblk_sz;
29984 + err = set_deblk_end(&p, &deblk_end);
29991 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29992 + unsigned int d_type, struct au_nhash *delist)
29996 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29997 + union au_vdir_deblk_p p, *room, deblk_end;
29998 + struct au_vdir_dehstr *dehstr;
30000 + p.deblk = last_deblk(vdir);
30001 + deblk_end.deblk = p.deblk + deblk_sz;
30002 + room = &vdir->vd_last.p;
30003 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
30004 + || !is_deblk_end(room, &deblk_end));
30006 + sz = calc_size(nlen);
30007 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
30008 + err = append_deblk(vdir);
30009 + if (unlikely(err))
30012 + p.deblk = last_deblk(vdir);
30013 + deblk_end.deblk = p.deblk + deblk_sz;
30015 + AuDebugOn(room->deblk != p.deblk);
30019 + dehstr = au_cache_alloc_vdir_dehstr();
30020 + if (unlikely(!dehstr))
30023 + dehstr->str = &room->de->de_str;
30024 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
30025 + room->de->de_ino = ino;
30026 + room->de->de_type = d_type;
30027 + room->de->de_str.len = nlen;
30028 + memcpy(room->de->de_str.name, name, nlen);
30031 + room->deblk += sz;
30032 + if (unlikely(set_deblk_end(room, &deblk_end)))
30033 + err = append_deblk(vdir);
30040 +/* ---------------------------------------------------------------------- */
30042 +void au_vdir_free(struct au_vdir *vdir)
30044 + unsigned char **deblk;
30046 + deblk = vdir->vd_deblk;
30047 + while (vdir->vd_nblk--)
30049 + kfree(vdir->vd_deblk);
30050 + au_cache_free_vdir(vdir);
30053 +static struct au_vdir *alloc_vdir(struct file *file)
30055 + struct au_vdir *vdir;
30056 + struct super_block *sb;
30059 + sb = file->f_path.dentry->d_sb;
30060 + SiMustAnyLock(sb);
30063 + vdir = au_cache_alloc_vdir();
30064 + if (unlikely(!vdir))
30067 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
30068 + if (unlikely(!vdir->vd_deblk))
30071 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
30072 + if (!vdir->vd_deblk_sz) {
30073 + /* estimate the appropriate size for deblk */
30074 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
30075 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
30077 + vdir->vd_nblk = 0;
30078 + vdir->vd_version = 0;
30079 + vdir->vd_jiffy = 0;
30080 + err = append_deblk(vdir);
30082 + return vdir; /* success */
30084 + kfree(vdir->vd_deblk);
30087 + au_cache_free_vdir(vdir);
30089 + vdir = ERR_PTR(err);
30093 +static int reinit_vdir(struct au_vdir *vdir)
30096 + union au_vdir_deblk_p p, deblk_end;
30098 + while (vdir->vd_nblk > 1) {
30099 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30100 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30103 + p.deblk = vdir->vd_deblk[0];
30104 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30105 + err = set_deblk_end(&p, &deblk_end);
30106 + /* keep vd_dblk_sz */
30107 + vdir->vd_last.ul = 0;
30108 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30109 + vdir->vd_version = 0;
30110 + vdir->vd_jiffy = 0;
30115 +/* ---------------------------------------------------------------------- */
30117 +#define AuFillVdir_CALLED 1
30118 +#define AuFillVdir_WHABLE (1 << 1)
30119 +#define AuFillVdir_SHWH (1 << 2)
30120 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30121 +#define au_fset_fillvdir(flags, name) \
30122 + do { (flags) |= AuFillVdir_##name; } while (0)
30123 +#define au_fclr_fillvdir(flags, name) \
30124 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30126 +#ifndef CONFIG_AUFS_SHWH
30127 +#undef AuFillVdir_SHWH
30128 +#define AuFillVdir_SHWH 0
30131 +struct fillvdir_arg {
30132 + struct dir_context ctx;
30133 + struct file *file;
30134 + struct au_vdir *vdir;
30135 + struct au_nhash delist;
30136 + struct au_nhash whlist;
30137 + aufs_bindex_t bindex;
30138 + unsigned int flags;
30142 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30143 + loff_t offset __maybe_unused, u64 h_ino,
30144 + unsigned int d_type)
30146 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30147 + char *name = (void *)__name;
30148 + struct super_block *sb;
30150 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30153 + sb = arg->file->f_path.dentry->d_sb;
30154 + au_fset_fillvdir(arg->flags, CALLED);
30156 + if (nlen <= AUFS_WH_PFX_LEN
30157 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30158 + if (test_known(&arg->delist, name, nlen)
30159 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30160 + goto out; /* already exists or whiteouted */
30162 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30164 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30165 + d_type = DT_UNKNOWN;
30166 + arg->err = append_de(arg->vdir, name, nlen, ino,
30167 + d_type, &arg->delist);
30169 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30170 + name += AUFS_WH_PFX_LEN;
30171 + nlen -= AUFS_WH_PFX_LEN;
30172 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30173 + goto out; /* already whiteouted */
30176 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30179 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30180 + d_type = DT_UNKNOWN;
30181 + arg->err = au_nhash_append_wh
30182 + (&arg->whlist, name, nlen, ino, d_type,
30183 + arg->bindex, shwh);
30189 + arg->vdir->vd_jiffy = jiffies;
30191 + AuTraceErr(arg->err);
30195 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30196 + struct au_nhash *whlist, struct au_nhash *delist)
30198 +#ifdef CONFIG_AUFS_SHWH
30200 + unsigned int nh, u;
30201 + struct hlist_head *head;
30202 + struct au_vdir_wh *pos;
30203 + struct hlist_node *n;
30205 + struct au_vdir_destr *destr;
30207 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30210 + o = p = (void *)__get_free_page(GFP_NOFS);
30211 + if (unlikely(!p))
30215 + nh = whlist->nh_num;
30216 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30217 + p += AUFS_WH_PFX_LEN;
30218 + for (u = 0; u < nh; u++) {
30219 + head = whlist->nh_head + u;
30220 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30221 + destr = &pos->wh_str;
30222 + memcpy(p, destr->name, destr->len);
30223 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30224 + pos->wh_ino, pos->wh_type, delist);
30225 + if (unlikely(err))
30230 + free_page((unsigned long)o);
30240 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30243 + unsigned int rdhash;
30245 + aufs_bindex_t bbot, bindex, btop;
30246 + unsigned char shwh;
30247 + struct file *hf, *file;
30248 + struct super_block *sb;
30250 + file = arg->file;
30251 + sb = file->f_path.dentry->d_sb;
30252 + SiMustAnyLock(sb);
30254 + rdhash = au_sbi(sb)->si_rdhash;
30256 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30257 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30258 + if (unlikely(err))
30260 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30261 + if (unlikely(err))
30267 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30269 + au_fset_fillvdir(arg->flags, SHWH);
30271 + btop = au_fbtop(file);
30272 + bbot = au_fbbot_dir(file);
30273 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30274 + hf = au_hf_dir(file, bindex);
30278 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30280 + if (unlikely(offset))
30283 + arg->bindex = bindex;
30284 + au_fclr_fillvdir(arg->flags, WHABLE);
30286 + || (bindex != bbot
30287 + && au_br_whable(au_sbr_perm(sb, bindex))))
30288 + au_fset_fillvdir(arg->flags, WHABLE);
30291 + au_fclr_fillvdir(arg->flags, CALLED);
30293 + err = vfsub_iterate_dir(hf, &arg->ctx);
30296 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30299 + * dir_relax() may be good for concurrency, but aufs should not
30300 + * use it since it will cause a lockdep problem.
30304 + if (!err && shwh)
30305 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30307 + au_nhash_wh_free(&arg->whlist);
30310 + au_nhash_de_free(&arg->delist);
30315 +static int read_vdir(struct file *file, int may_read)
30318 + unsigned long expire;
30319 + unsigned char do_read;
30320 + struct fillvdir_arg arg = {
30322 + .actor = fillvdir
30325 + struct inode *inode;
30326 + struct au_vdir *vdir, *allocated;
30329 + inode = file_inode(file);
30330 + IMustLock(inode);
30331 + IiMustWriteLock(inode);
30332 + SiMustAnyLock(inode->i_sb);
30334 + allocated = NULL;
30336 + expire = au_sbi(inode->i_sb)->si_rdcache;
30337 + vdir = au_ivdir(inode);
30340 + vdir = alloc_vdir(file);
30341 + err = PTR_ERR(vdir);
30342 + if (IS_ERR(vdir))
30345 + allocated = vdir;
30346 + } else if (may_read
30347 + && (inode->i_version != vdir->vd_version
30348 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30350 + err = reinit_vdir(vdir);
30351 + if (unlikely(err))
30356 + return 0; /* success */
30360 + err = au_do_read_vdir(&arg);
30362 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30363 + vdir->vd_version = inode->i_version;
30364 + vdir->vd_last.ul = 0;
30365 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30367 + au_set_ivdir(inode, allocated);
30368 + } else if (allocated)
30369 + au_vdir_free(allocated);
30375 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30378 + unsigned long ul, n;
30379 + const unsigned int deblk_sz = src->vd_deblk_sz;
30381 + AuDebugOn(tgt->vd_nblk != 1);
30384 + if (tgt->vd_nblk < src->vd_nblk) {
30385 + unsigned char **p;
30387 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30388 + GFP_NOFS, /*may_shrink*/0);
30389 + if (unlikely(!p))
30391 + tgt->vd_deblk = p;
30394 + if (tgt->vd_deblk_sz != deblk_sz) {
30395 + unsigned char *p;
30397 + tgt->vd_deblk_sz = deblk_sz;
30398 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30399 + /*may_shrink*/1);
30400 + if (unlikely(!p))
30402 + tgt->vd_deblk[0] = p;
30404 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30405 + tgt->vd_version = src->vd_version;
30406 + tgt->vd_jiffy = src->vd_jiffy;
30408 + n = src->vd_nblk;
30409 + for (ul = 1; ul < n; ul++) {
30410 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30412 + if (unlikely(!tgt->vd_deblk[ul]))
30416 + tgt->vd_nblk = n;
30417 + tgt->vd_last.ul = tgt->vd_last.ul;
30418 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30419 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30420 + - src->vd_deblk[src->vd_last.ul];
30422 + return 0; /* success */
30425 + rerr = reinit_vdir(tgt);
30430 +int au_vdir_init(struct file *file)
30433 + struct inode *inode;
30434 + struct au_vdir *vdir_cache, *allocated;
30436 + /* test file->f_pos here instead of ctx->pos */
30437 + err = read_vdir(file, !file->f_pos);
30438 + if (unlikely(err))
30441 + allocated = NULL;
30442 + vdir_cache = au_fvdir_cache(file);
30443 + if (!vdir_cache) {
30444 + vdir_cache = alloc_vdir(file);
30445 + err = PTR_ERR(vdir_cache);
30446 + if (IS_ERR(vdir_cache))
30448 + allocated = vdir_cache;
30449 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30450 + /* test file->f_pos here instead of ctx->pos */
30451 + err = reinit_vdir(vdir_cache);
30452 + if (unlikely(err))
30455 + return 0; /* success */
30457 + inode = file_inode(file);
30458 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30460 + file->f_version = inode->i_version;
30462 + au_set_fvdir_cache(file, allocated);
30463 + } else if (allocated)
30464 + au_vdir_free(allocated);
30470 +static loff_t calc_offset(struct au_vdir *vdir)
30473 + union au_vdir_deblk_p p;
30475 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30476 + offset = vdir->vd_last.p.deblk - p.deblk;
30477 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30481 +/* returns true or false */
30482 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30485 + unsigned int deblk_sz;
30486 + unsigned long ul, n;
30488 + union au_vdir_deblk_p p, deblk_end;
30489 + struct au_vdir *vdir_cache;
30492 + vdir_cache = au_fvdir_cache(file);
30493 + offset = calc_offset(vdir_cache);
30494 + AuDbg("offset %lld\n", offset);
30495 + if (ctx->pos == offset)
30498 + vdir_cache->vd_last.ul = 0;
30499 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30504 + deblk_sz = vdir_cache->vd_deblk_sz;
30505 + ul = div64_u64(ctx->pos, deblk_sz);
30506 + AuDbg("ul %lu\n", ul);
30507 + if (ul >= vdir_cache->vd_nblk)
30510 + n = vdir_cache->vd_nblk;
30511 + for (; ul < n; ul++) {
30512 + p.deblk = vdir_cache->vd_deblk[ul];
30513 + deblk_end.deblk = p.deblk + deblk_sz;
30515 + offset *= deblk_sz;
30516 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30519 + l = calc_size(p.de->de_str.len);
30523 + if (!is_deblk_end(&p, &deblk_end)) {
30525 + vdir_cache->vd_last.ul = ul;
30526 + vdir_cache->vd_last.p = p;
30533 + AuTraceErr(!valid);
30537 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30539 + unsigned int l, deblk_sz;
30540 + union au_vdir_deblk_p deblk_end;
30541 + struct au_vdir *vdir_cache;
30542 + struct au_vdir_de *de;
30544 + vdir_cache = au_fvdir_cache(file);
30545 + if (!seek_vdir(file, ctx))
30548 + deblk_sz = vdir_cache->vd_deblk_sz;
30550 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30551 + deblk_end.deblk += deblk_sz;
30552 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30553 + de = vdir_cache->vd_last.p.de;
30554 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30555 + de->de_str.len, de->de_str.name, ctx->pos,
30556 + (unsigned long)de->de_ino, de->de_type);
30557 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30558 + de->de_str.len, de->de_ino,
30560 + /* todo: ignore the error caused by udba? */
30561 + /* return err; */
30565 + l = calc_size(de->de_str.len);
30566 + vdir_cache->vd_last.p.deblk += l;
30569 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30570 + vdir_cache->vd_last.ul++;
30571 + vdir_cache->vd_last.p.deblk
30572 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30573 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30582 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30583 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30584 +++ linux/fs/aufs/vfsub.c 2017-07-29 12:14:25.906375514 +0200
30587 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30589 + * This program, aufs is free software; you can redistribute it and/or modify
30590 + * it under the terms of the GNU General Public License as published by
30591 + * the Free Software Foundation; either version 2 of the License, or
30592 + * (at your option) any later version.
30594 + * This program is distributed in the hope that it will be useful,
30595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30597 + * GNU General Public License for more details.
30599 + * You should have received a copy of the GNU General Public License
30600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30604 + * sub-routines for VFS
30607 +#include <linux/namei.h>
30608 +#include <linux/nsproxy.h>
30609 +#include <linux/security.h>
30610 +#include <linux/splice.h>
30611 +#ifdef CONFIG_AUFS_BR_FUSE
30612 +#include "../fs/mount.h"
30616 +#ifdef CONFIG_AUFS_BR_FUSE
30617 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30619 + struct nsproxy *ns;
30621 + if (!au_test_fuse(h_sb) || !au_userns)
30624 + ns = current->nsproxy;
30625 + /* no {get,put}_nsproxy(ns) */
30626 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30630 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
30635 + down_read(&h_sb->s_umount);
30636 + err = __sync_filesystem(h_sb, wait);
30637 + up_read(&h_sb->s_umount);
30643 +/* ---------------------------------------------------------------------- */
30645 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30649 + struct super_block *h_sb;
30651 + /* for remote fs, leave work for its getattr or d_revalidate */
30652 + /* for bad i_attr fs, handle them in aufs_getattr() */
30653 + /* still some fs may acquire i_mutex. we need to skip them */
30657 + h_sb = h_path->dentry->d_sb;
30658 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30660 + err = vfsub_getattr(h_path, &st);
30665 +/* ---------------------------------------------------------------------- */
30667 +struct file *vfsub_dentry_open(struct path *path, int flags)
30669 + struct file *file;
30671 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30673 + if (!IS_ERR_OR_NULL(file)
30674 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30675 + i_readcount_inc(d_inode(path->dentry));
30680 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30682 + struct file *file;
30685 + file = filp_open(path,
30686 + oflags /* | __FMODE_NONOTIFY */,
30689 + if (IS_ERR(file))
30691 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30698 + * Ideally this function should call VFS:do_last() in order to keep all its
30699 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30700 + * structure such as nameidata. This is a second (or third) best approach.
30701 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30703 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30704 + struct vfsub_aopen_args *args, struct au_branch *br)
30707 + struct file *file = args->file;
30708 + /* copied from linux/fs/namei.c:atomic_open() */
30709 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30712 + AuDebugOn(!dir->i_op->atomic_open);
30714 + err = au_br_test_oflag(args->open_flag, br);
30715 + if (unlikely(err))
30718 + args->file->f_path.dentry = DENTRY_NOT_SET;
30719 + args->file->f_path.mnt = au_br_mnt(br);
30720 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30721 + args->create_mode, args->opened);
30723 + /* some filesystems don't set FILE_CREATED while succeeded? */
30724 + if (*args->opened & FILE_CREATED)
30725 + fsnotify_create(dir, dentry);
30731 + /* todo: call VFS:may_open() here */
30732 + err = open_check_o_direct(file);
30733 + /* todo: ima_file_check() too? */
30734 + if (!err && (args->open_flag & __FMODE_EXEC))
30735 + err = deny_write_access(file);
30736 + if (unlikely(err))
30737 + /* note that the file is created and still opened */
30742 + fsnotify_open(file);
30748 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30752 + err = kern_path(name, flags, path);
30753 + if (!err && d_is_positive(path->dentry))
30754 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30758 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30759 + struct dentry *parent, int len)
30761 + struct path path = {
30765 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30766 + if (IS_ERR(path.dentry))
30768 + if (d_is_positive(path.dentry))
30769 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30772 + AuTraceErrPtr(path.dentry);
30773 + return path.dentry;
30776 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30779 + struct path path = {
30783 + /* VFS checks it too, but by WARN_ON_ONCE() */
30784 + IMustLock(d_inode(parent));
30786 + path.dentry = lookup_one_len(name, parent, len);
30787 + if (IS_ERR(path.dentry))
30789 + if (d_is_positive(path.dentry))
30790 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30793 + AuTraceErrPtr(path.dentry);
30794 + return path.dentry;
30797 +void vfsub_call_lkup_one(void *args)
30799 + struct vfsub_lkup_one_args *a = args;
30800 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30803 +/* ---------------------------------------------------------------------- */
30805 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30806 + struct dentry *d2, struct au_hinode *hdir2)
30808 + struct dentry *d;
30811 + d = lock_rename(d1, d2);
30813 + au_hn_suspend(hdir1);
30814 + if (hdir1 != hdir2)
30815 + au_hn_suspend(hdir2);
30820 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30821 + struct dentry *d2, struct au_hinode *hdir2)
30823 + au_hn_resume(hdir1);
30824 + if (hdir1 != hdir2)
30825 + au_hn_resume(hdir2);
30827 + unlock_rename(d1, d2);
30831 +/* ---------------------------------------------------------------------- */
30833 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30836 + struct dentry *d;
30840 + d = path->dentry;
30841 + path->dentry = d->d_parent;
30842 + err = security_path_mknod(path, d, mode, 0);
30843 + path->dentry = d;
30844 + if (unlikely(err))
30848 + err = vfs_create(dir, path->dentry, mode, want_excl);
30851 + struct path tmp = *path;
30854 + vfsub_update_h_iattr(&tmp, &did);
30856 + tmp.dentry = path->dentry->d_parent;
30857 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30866 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30869 + struct dentry *d;
30873 + d = path->dentry;
30874 + path->dentry = d->d_parent;
30875 + err = security_path_symlink(path, d, symname);
30876 + path->dentry = d;
30877 + if (unlikely(err))
30881 + err = vfs_symlink(dir, path->dentry, symname);
30884 + struct path tmp = *path;
30887 + vfsub_update_h_iattr(&tmp, &did);
30889 + tmp.dentry = path->dentry->d_parent;
30890 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30899 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30902 + struct dentry *d;
30906 + d = path->dentry;
30907 + path->dentry = d->d_parent;
30908 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30909 + path->dentry = d;
30910 + if (unlikely(err))
30914 + err = vfs_mknod(dir, path->dentry, mode, dev);
30917 + struct path tmp = *path;
30920 + vfsub_update_h_iattr(&tmp, &did);
30922 + tmp.dentry = path->dentry->d_parent;
30923 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30932 +static int au_test_nlink(struct inode *inode)
30934 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30936 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30937 + || inode->i_nlink < link_max)
30942 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30943 + struct inode **delegated_inode)
30946 + struct dentry *d;
30950 + err = au_test_nlink(d_inode(src_dentry));
30951 + if (unlikely(err))
30954 + /* we don't call may_linkat() */
30955 + d = path->dentry;
30956 + path->dentry = d->d_parent;
30957 + err = security_path_link(src_dentry, path, d);
30958 + path->dentry = d;
30959 + if (unlikely(err))
30963 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30966 + struct path tmp = *path;
30969 + /* fuse has different memory inode for the same inumber */
30970 + vfsub_update_h_iattr(&tmp, &did);
30972 + tmp.dentry = path->dentry->d_parent;
30973 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30974 + tmp.dentry = src_dentry;
30975 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30984 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30985 + struct inode *dir, struct path *path,
30986 + struct inode **delegated_inode, unsigned int flags)
30989 + struct path tmp = {
30992 + struct dentry *d;
30995 + IMustLock(src_dir);
30997 + d = path->dentry;
30998 + path->dentry = d->d_parent;
30999 + tmp.dentry = src_dentry->d_parent;
31000 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
31001 + path->dentry = d;
31002 + if (unlikely(err))
31006 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
31007 + delegated_inode, flags);
31012 + tmp.dentry = d->d_parent;
31013 + vfsub_update_h_iattr(&tmp, &did);
31015 + tmp.dentry = src_dentry;
31016 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31017 + tmp.dentry = src_dentry->d_parent;
31018 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31027 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
31030 + struct dentry *d;
31034 + d = path->dentry;
31035 + path->dentry = d->d_parent;
31036 + err = security_path_mkdir(path, d, mode);
31037 + path->dentry = d;
31038 + if (unlikely(err))
31042 + err = vfs_mkdir(dir, path->dentry, mode);
31045 + struct path tmp = *path;
31048 + vfsub_update_h_iattr(&tmp, &did);
31050 + tmp.dentry = path->dentry->d_parent;
31051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31060 +int vfsub_rmdir(struct inode *dir, struct path *path)
31063 + struct dentry *d;
31067 + d = path->dentry;
31068 + path->dentry = d->d_parent;
31069 + err = security_path_rmdir(path, d);
31070 + path->dentry = d;
31071 + if (unlikely(err))
31075 + err = vfs_rmdir(dir, path->dentry);
31078 + struct path tmp = {
31079 + .dentry = path->dentry->d_parent,
31083 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31090 +/* ---------------------------------------------------------------------- */
31092 +/* todo: support mmap_sem? */
31093 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31099 + err = vfs_read(file, ubuf, count, ppos);
31102 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31106 +/* todo: kernel_read()? */
31107 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31111 + mm_segment_t oldfs;
31118 + oldfs = get_fs();
31119 + set_fs(KERNEL_DS);
31120 + err = vfsub_read_u(file, buf.u, count, ppos);
31125 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31131 + err = vfs_write(file, ubuf, count, ppos);
31134 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31138 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31141 + mm_segment_t oldfs;
31144 + const char __user *u;
31148 + oldfs = get_fs();
31149 + set_fs(KERNEL_DS);
31150 + err = vfsub_write_u(file, buf.u, count, ppos);
31155 +int vfsub_flush(struct file *file, fl_owner_t id)
31160 + if (file->f_op->flush) {
31161 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31162 + err = file->f_op->flush(file, id);
31165 + err = file->f_op->flush(file, id);
31169 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31175 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31179 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31182 + err = iterate_dir(file, ctx);
31185 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31190 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31191 + struct pipe_inode_info *pipe, size_t len,
31192 + unsigned int flags)
31197 + err = do_splice_to(in, ppos, pipe, len, flags);
31199 + file_accessed(in);
31201 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31205 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31206 + loff_t *ppos, size_t len, unsigned int flags)
31211 + err = do_splice_from(pipe, out, ppos, len, flags);
31214 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31218 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31222 + /* file can be NULL */
31224 + err = vfs_fsync(file, datasync);
31228 + AuDebugOn(!file);
31229 + path = &file->f_path;
31231 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31236 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31237 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31238 + struct file *h_file)
31241 + struct inode *h_inode;
31242 + struct super_block *h_sb;
31245 + err = vfsub_truncate(h_path, length);
31249 + h_inode = d_inode(h_path->dentry);
31250 + h_sb = h_inode->i_sb;
31252 + sb_start_write(h_sb);
31254 + err = locks_verify_truncate(h_inode, h_file, length);
31256 + err = security_path_truncate(h_path);
31259 + err = do_truncate(h_path->dentry, length, attr, h_file);
31263 + sb_end_write(h_sb);
31270 +/* ---------------------------------------------------------------------- */
31272 +struct au_vfsub_mkdir_args {
31274 + struct inode *dir;
31275 + struct path *path;
31279 +static void au_call_vfsub_mkdir(void *args)
31281 + struct au_vfsub_mkdir_args *a = args;
31282 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31285 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31287 + int err, do_sio, wkq_err;
31289 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31292 + err = vfsub_mkdir(dir, path, mode);
31295 + struct au_vfsub_mkdir_args args = {
31301 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31302 + if (unlikely(wkq_err))
31309 +struct au_vfsub_rmdir_args {
31311 + struct inode *dir;
31312 + struct path *path;
31315 +static void au_call_vfsub_rmdir(void *args)
31317 + struct au_vfsub_rmdir_args *a = args;
31318 + *a->errp = vfsub_rmdir(a->dir, a->path);
31321 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31323 + int err, do_sio, wkq_err;
31325 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31328 + err = vfsub_rmdir(dir, path);
31331 + struct au_vfsub_rmdir_args args = {
31336 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31337 + if (unlikely(wkq_err))
31344 +/* ---------------------------------------------------------------------- */
31346 +struct notify_change_args {
31348 + struct path *path;
31349 + struct iattr *ia;
31350 + struct inode **delegated_inode;
31353 +static void call_notify_change(void *args)
31355 + struct notify_change_args *a = args;
31356 + struct inode *h_inode;
31358 + h_inode = d_inode(a->path->dentry);
31359 + IMustLock(h_inode);
31361 + *a->errp = -EPERM;
31362 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31364 + *a->errp = notify_change(a->path->dentry, a->ia,
31365 + a->delegated_inode);
31368 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31370 + AuTraceErr(*a->errp);
31373 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31374 + struct inode **delegated_inode)
31377 + struct notify_change_args args = {
31381 + .delegated_inode = delegated_inode
31384 + call_notify_change(&args);
31389 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31390 + struct inode **delegated_inode)
31392 + int err, wkq_err;
31393 + struct notify_change_args args = {
31397 + .delegated_inode = delegated_inode
31400 + wkq_err = au_wkq_wait(call_notify_change, &args);
31401 + if (unlikely(wkq_err))
31407 +/* ---------------------------------------------------------------------- */
31409 +struct unlink_args {
31411 + struct inode *dir;
31412 + struct path *path;
31413 + struct inode **delegated_inode;
31416 +static void call_unlink(void *args)
31418 + struct unlink_args *a = args;
31419 + struct dentry *d = a->path->dentry;
31420 + struct inode *h_inode;
31421 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31422 + && au_dcount(d) == 1);
31424 + IMustLock(a->dir);
31426 + a->path->dentry = d->d_parent;
31427 + *a->errp = security_path_unlink(a->path, d);
31428 + a->path->dentry = d;
31429 + if (unlikely(*a->errp))
31432 + if (!stop_sillyrename)
31435 + if (d_is_positive(d)) {
31436 + h_inode = d_inode(d);
31441 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31444 + struct path tmp = {
31445 + .dentry = d->d_parent,
31446 + .mnt = a->path->mnt
31448 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31451 + if (!stop_sillyrename)
31456 + AuTraceErr(*a->errp);
31460 + * @dir: must be locked.
31461 + * @dentry: target dentry.
31463 +int vfsub_unlink(struct inode *dir, struct path *path,
31464 + struct inode **delegated_inode, int force)
31467 + struct unlink_args args = {
31471 + .delegated_inode = delegated_inode
31475 + call_unlink(&args);
31479 + wkq_err = au_wkq_wait(call_unlink, &args);
31480 + if (unlikely(wkq_err))
31486 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31487 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31488 +++ linux/fs/aufs/vfsub.h 2017-07-29 12:14:25.906375514 +0200
31491 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31493 + * This program, aufs is free software; you can redistribute it and/or modify
31494 + * it under the terms of the GNU General Public License as published by
31495 + * the Free Software Foundation; either version 2 of the License, or
31496 + * (at your option) any later version.
31498 + * This program is distributed in the hope that it will be useful,
31499 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31500 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31501 + * GNU General Public License for more details.
31503 + * You should have received a copy of the GNU General Public License
31504 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31508 + * sub-routines for VFS
31511 +#ifndef __AUFS_VFSUB_H__
31512 +#define __AUFS_VFSUB_H__
31516 +#include <linux/fs.h>
31517 +#include <linux/mount.h>
31518 +#include <linux/posix_acl.h>
31519 +#include <linux/xattr.h>
31520 +#include "debug.h"
31522 +/* copied from linux/fs/internal.h */
31523 +/* todo: BAD approach!! */
31524 +extern void __mnt_drop_write(struct vfsmount *);
31525 +extern int open_check_o_direct(struct file *f);
31527 +/* ---------------------------------------------------------------------- */
31529 +/* lock subclass for lower inode */
31530 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31531 +/* reduce? gave up. */
31533 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31534 + AuLsc_I_PARENT, /* lower inode, parent first */
31535 + AuLsc_I_PARENT2, /* copyup dirs */
31536 + AuLsc_I_PARENT3, /* copyup wh */
31542 +/* to debug easier, do not make them inlined functions */
31543 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31544 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31546 +/* ---------------------------------------------------------------------- */
31548 +static inline void vfsub_drop_nlink(struct inode *inode)
31550 + AuDebugOn(!inode->i_nlink);
31551 + drop_nlink(inode);
31554 +static inline void vfsub_dead_dir(struct inode *inode)
31556 + AuDebugOn(!S_ISDIR(inode->i_mode));
31557 + inode->i_flags |= S_DEAD;
31558 + clear_nlink(inode);
31561 +static inline int vfsub_native_ro(struct inode *inode)
31563 + return (inode->i_sb->s_flags & MS_RDONLY)
31564 + || IS_RDONLY(inode)
31565 + /* || IS_APPEND(inode) */
31566 + || IS_IMMUTABLE(inode);
31569 +#ifdef CONFIG_AUFS_BR_FUSE
31570 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31572 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31575 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
31577 +/* ---------------------------------------------------------------------- */
31579 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31580 +struct file *vfsub_dentry_open(struct path *path, int flags);
31581 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31582 +struct vfsub_aopen_args {
31583 + struct file *file;
31584 + unsigned int open_flag;
31585 + umode_t create_mode;
31589 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31590 + struct vfsub_aopen_args *args, struct au_branch *br);
31591 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31593 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31594 + struct dentry *parent, int len);
31595 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31598 +struct vfsub_lkup_one_args {
31599 + struct dentry **errp;
31600 + struct qstr *name;
31601 + struct dentry *parent;
31604 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31605 + struct dentry *parent)
31607 + return vfsub_lookup_one_len(name->name, parent, name->len);
31610 +void vfsub_call_lkup_one(void *args);
31612 +/* ---------------------------------------------------------------------- */
31614 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31619 + err = mnt_want_write(mnt);
31624 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31627 + mnt_drop_write(mnt);
31631 +#if 0 /* reserved */
31632 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31635 + mnt_drop_write_file(file);
31640 +/* ---------------------------------------------------------------------- */
31643 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31644 + struct dentry *d2, struct au_hinode *hdir2);
31645 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31646 + struct dentry *d2, struct au_hinode *hdir2);
31648 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31650 +int vfsub_symlink(struct inode *dir, struct path *path,
31651 + const char *symname);
31652 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31653 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31654 + struct path *path, struct inode **delegated_inode);
31655 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31656 + struct inode *hdir, struct path *path,
31657 + struct inode **delegated_inode, unsigned int flags);
31658 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31659 +int vfsub_rmdir(struct inode *dir, struct path *path);
31661 +/* ---------------------------------------------------------------------- */
31663 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31665 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31667 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31669 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31671 +int vfsub_flush(struct file *file, fl_owner_t id);
31672 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31674 +static inline loff_t vfsub_f_size_read(struct file *file)
31676 + return i_size_read(file_inode(file));
31679 +static inline unsigned int vfsub_file_flags(struct file *file)
31681 + unsigned int flags;
31683 + spin_lock(&file->f_lock);
31684 + flags = file->f_flags;
31685 + spin_unlock(&file->f_lock);
31690 +static inline int vfsub_file_execed(struct file *file)
31692 + /* todo: direct access f_flags */
31693 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31696 +#if 0 /* reserved */
31697 +static inline void vfsub_file_accessed(struct file *h_file)
31699 + file_accessed(h_file);
31700 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31704 +#if 0 /* reserved */
31705 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31706 + struct dentry *h_dentry)
31708 + struct path h_path = {
31709 + .dentry = h_dentry,
31712 + touch_atime(&h_path);
31713 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31717 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31720 + return update_time(h_inode, ts, flags);
31721 + /* no vfsub_update_h_iattr() since we don't have struct path */
31724 +#ifdef CONFIG_FS_POSIX_ACL
31725 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31729 + err = posix_acl_chmod(h_inode, h_mode);
31730 + if (err == -EOPNOTSUPP)
31735 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31738 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31739 + struct pipe_inode_info *pipe, size_t len,
31740 + unsigned int flags);
31741 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31742 + loff_t *ppos, size_t len, unsigned int flags);
31744 +static inline long vfsub_truncate(struct path *path, loff_t length)
31749 + err = vfs_truncate(path, length);
31754 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31755 + struct file *h_file);
31756 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31759 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
31762 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
31768 + err = vfs_clone_file_range(src, 0, dst, 0, len);
31774 +/* copy_file_range(2) is a systemcall */
31775 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
31776 + struct file *dst, loff_t dst_pos,
31777 + size_t len, unsigned int flags)
31782 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
31788 +/* ---------------------------------------------------------------------- */
31790 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31795 + err = vfs_llseek(file, offset, origin);
31800 +/* ---------------------------------------------------------------------- */
31802 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31803 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31804 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31805 + struct inode **delegated_inode);
31806 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31807 + struct inode **delegated_inode);
31808 +int vfsub_unlink(struct inode *dir, struct path *path,
31809 + struct inode **delegated_inode, int force);
31811 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
31813 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
31816 +/* ---------------------------------------------------------------------- */
31818 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31819 + const void *value, size_t size, int flags)
31824 + err = vfs_setxattr(dentry, name, value, size, flags);
31830 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31835 + err = vfs_removexattr(dentry, name);
31841 +#endif /* __KERNEL__ */
31842 +#endif /* __AUFS_VFSUB_H__ */
31843 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31844 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31845 +++ linux/fs/aufs/wbr_policy.c 2017-07-29 12:14:25.906375514 +0200
31848 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31850 + * This program, aufs is free software; you can redistribute it and/or modify
31851 + * it under the terms of the GNU General Public License as published by
31852 + * the Free Software Foundation; either version 2 of the License, or
31853 + * (at your option) any later version.
31855 + * This program is distributed in the hope that it will be useful,
31856 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31857 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31858 + * GNU General Public License for more details.
31860 + * You should have received a copy of the GNU General Public License
31861 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31865 + * policies for selecting one among multiple writable branches
31868 +#include <linux/statfs.h>
31871 +/* subset of cpup_attr() */
31872 +static noinline_for_stack
31873 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31877 + struct inode *h_isrc;
31879 + h_isrc = d_inode(h_src);
31880 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31881 + ia.ia_mode = h_isrc->i_mode;
31882 + ia.ia_uid = h_isrc->i_uid;
31883 + ia.ia_gid = h_isrc->i_gid;
31884 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31885 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31886 + /* no delegation since it is just created */
31887 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31889 + /* is this nfs only? */
31890 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31891 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31892 + ia.ia_mode = h_isrc->i_mode;
31893 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31899 +#define AuCpdown_PARENT_OPQ 1
31900 +#define AuCpdown_WHED (1 << 1)
31901 +#define AuCpdown_MADE_DIR (1 << 2)
31902 +#define AuCpdown_DIROPQ (1 << 3)
31903 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31904 +#define au_fset_cpdown(flags, name) \
31905 + do { (flags) |= AuCpdown_##name; } while (0)
31906 +#define au_fclr_cpdown(flags, name) \
31907 + do { (flags) &= ~AuCpdown_##name; } while (0)
31909 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31910 + unsigned int *flags)
31913 + struct dentry *opq_dentry;
31915 + opq_dentry = au_diropq_create(dentry, bdst);
31916 + err = PTR_ERR(opq_dentry);
31917 + if (IS_ERR(opq_dentry))
31919 + dput(opq_dentry);
31920 + au_fset_cpdown(*flags, DIROPQ);
31926 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31927 + struct inode *dir, aufs_bindex_t bdst)
31930 + struct path h_path;
31931 + struct au_branch *br;
31933 + br = au_sbr(dentry->d_sb, bdst);
31934 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31935 + err = PTR_ERR(h_path.dentry);
31936 + if (IS_ERR(h_path.dentry))
31940 + if (d_is_positive(h_path.dentry)) {
31941 + h_path.mnt = au_br_mnt(br);
31942 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31945 + dput(h_path.dentry);
31951 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31952 + struct au_pin *pin,
31953 + struct dentry *h_parent, void *arg)
31956 + aufs_bindex_t bopq, btop;
31957 + struct path h_path;
31958 + struct dentry *parent;
31959 + struct inode *h_dir, *h_inode, *inode, *dir;
31960 + unsigned int *flags = arg;
31962 + btop = au_dbtop(dentry);
31963 + /* dentry is di-locked */
31964 + parent = dget_parent(dentry);
31965 + dir = d_inode(parent);
31966 + h_dir = d_inode(h_parent);
31967 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31968 + IMustLock(h_dir);
31970 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31971 + if (unlikely(err < 0))
31973 + h_path.dentry = au_h_dptr(dentry, bdst);
31974 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31975 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31976 + S_IRWXU | S_IRUGO | S_IXUGO);
31977 + if (unlikely(err))
31979 + au_fset_cpdown(*flags, MADE_DIR);
31981 + bopq = au_dbdiropq(dentry);
31982 + au_fclr_cpdown(*flags, WHED);
31983 + au_fclr_cpdown(*flags, DIROPQ);
31984 + if (au_dbwh(dentry) == bdst)
31985 + au_fset_cpdown(*flags, WHED);
31986 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31987 + au_fset_cpdown(*flags, PARENT_OPQ);
31988 + h_inode = d_inode(h_path.dentry);
31989 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31990 + if (au_ftest_cpdown(*flags, WHED)) {
31991 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31992 + if (unlikely(err)) {
31993 + inode_unlock(h_inode);
31998 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31999 + inode_unlock(h_inode);
32000 + if (unlikely(err))
32003 + if (au_ftest_cpdown(*flags, WHED)) {
32004 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
32005 + if (unlikely(err))
32009 + inode = d_inode(dentry);
32010 + if (au_ibbot(inode) < bdst)
32011 + au_set_ibbot(inode, bdst);
32012 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
32013 + au_hi_flags(inode, /*isdir*/1));
32014 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
32015 + goto out; /* success */
32019 + if (au_ftest_cpdown(*flags, DIROPQ)) {
32020 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
32021 + rerr = au_diropq_remove(dentry, bdst);
32022 + inode_unlock(h_inode);
32023 + if (unlikely(rerr)) {
32024 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
32025 + dentry, bdst, rerr);
32031 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
32032 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
32033 + if (unlikely(rerr)) {
32034 + AuIOErr("failed removing %pd b%d (%d)\n",
32035 + dentry, bdst, rerr);
32040 + au_set_h_dptr(dentry, bdst, NULL);
32041 + if (au_dbbot(dentry) == bdst)
32042 + au_update_dbbot(dentry);
32048 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
32051 + unsigned int flags;
32054 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
32059 +/* ---------------------------------------------------------------------- */
32061 +/* policies for create */
32063 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
32065 + int err, i, j, ndentry;
32066 + aufs_bindex_t bopq;
32067 + struct au_dcsub_pages dpages;
32068 + struct au_dpage *dpage;
32069 + struct dentry **dentries, *parent, *d;
32071 + err = au_dpages_init(&dpages, GFP_NOFS);
32072 + if (unlikely(err))
32074 + parent = dget_parent(dentry);
32075 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
32076 + if (unlikely(err))
32080 + for (i = 0; i < dpages.ndpage; i++) {
32081 + dpage = dpages.dpages + i;
32082 + dentries = dpage->dentries;
32083 + ndentry = dpage->ndentry;
32084 + for (j = 0; j < ndentry; j++) {
32086 + di_read_lock_parent2(d, !AuLock_IR);
32087 + bopq = au_dbdiropq(d);
32088 + di_read_unlock(d, !AuLock_IR);
32089 + if (bopq >= 0 && bopq < err)
32096 + au_dpages_free(&dpages);
32101 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32103 + for (; bindex >= 0; bindex--)
32104 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32109 +/* top down parent */
32110 +static int au_wbr_create_tdp(struct dentry *dentry,
32111 + unsigned int flags __maybe_unused)
32114 + aufs_bindex_t btop, bindex;
32115 + struct super_block *sb;
32116 + struct dentry *parent, *h_parent;
32118 + sb = dentry->d_sb;
32119 + btop = au_dbtop(dentry);
32121 + if (!au_br_rdonly(au_sbr(sb, btop)))
32125 + parent = dget_parent(dentry);
32126 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32127 + h_parent = au_h_dptr(parent, bindex);
32128 + if (!h_parent || d_is_negative(h_parent))
32131 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32138 + /* bottom up here */
32139 + if (unlikely(err < 0)) {
32140 + err = au_wbr_bu(sb, btop - 1);
32142 + err = au_wbr_nonopq(dentry, err);
32146 + AuDbg("b%d\n", err);
32150 +/* ---------------------------------------------------------------------- */
32152 +/* an exception for the policy other than tdp */
32153 +static int au_wbr_create_exp(struct dentry *dentry)
32156 + aufs_bindex_t bwh, bdiropq;
32157 + struct dentry *parent;
32160 + bwh = au_dbwh(dentry);
32161 + parent = dget_parent(dentry);
32162 + bdiropq = au_dbdiropq(parent);
32164 + if (bdiropq >= 0)
32165 + err = min(bdiropq, bwh);
32168 + AuDbg("%d\n", err);
32169 + } else if (bdiropq >= 0) {
32171 + AuDbg("%d\n", err);
32176 + err = au_wbr_nonopq(dentry, err);
32178 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32181 + AuDbg("%d\n", err);
32185 +/* ---------------------------------------------------------------------- */
32188 +static int au_wbr_create_init_rr(struct super_block *sb)
32192 + err = au_wbr_bu(sb, au_sbbot(sb));
32193 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32196 + AuDbg("b%d\n", err);
32200 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32204 + aufs_bindex_t bindex, bbot;
32205 + struct super_block *sb;
32208 + err = au_wbr_create_exp(dentry);
32212 + sb = dentry->d_sb;
32213 + next = &au_sbi(sb)->si_wbr_rr_next;
32214 + bbot = au_sbbot(sb);
32216 + for (bindex = 0; bindex <= bbot; bindex++) {
32217 + if (!au_ftest_wbr(flags, DIR)) {
32218 + err = atomic_dec_return(next) + 1;
32219 + /* modulo for 0 is meaningless */
32220 + if (unlikely(!err))
32221 + err = atomic_dec_return(next) + 1;
32223 + err = atomic_read(next);
32224 + AuDbg("%d\n", err);
32227 + AuDbg("%d\n", err);
32228 + if (!au_br_rdonly(au_sbr(sb, err)))
32234 + err = au_wbr_nonopq(dentry, err);
32237 + AuDbg("%d\n", err);
32241 +/* ---------------------------------------------------------------------- */
32243 +/* most free space */
32244 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32246 + struct super_block *sb;
32247 + struct au_branch *br;
32248 + struct au_wbr_mfs *mfs;
32249 + struct dentry *h_parent;
32250 + aufs_bindex_t bindex, bbot;
32252 + unsigned long long b, bavail;
32253 + struct path h_path;
32254 + /* reduce the stack usage */
32255 + struct kstatfs *st;
32257 + st = kmalloc(sizeof(*st), GFP_NOFS);
32258 + if (unlikely(!st)) {
32259 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32264 + sb = dentry->d_sb;
32265 + mfs = &au_sbi(sb)->si_wbr_mfs;
32266 + MtxMustLock(&mfs->mfs_lock);
32267 + mfs->mfs_bindex = -EROFS;
32268 + mfs->mfsrr_bytes = 0;
32271 + bbot = au_sbbot(sb);
32273 + bindex = au_dbtop(parent);
32274 + bbot = au_dbtaildir(parent);
32277 + for (; bindex <= bbot; bindex++) {
32279 + h_parent = au_h_dptr(parent, bindex);
32280 + if (!h_parent || d_is_negative(h_parent))
32283 + br = au_sbr(sb, bindex);
32284 + if (au_br_rdonly(br))
32287 + /* sb->s_root for NFS is unreliable */
32288 + h_path.mnt = au_br_mnt(br);
32289 + h_path.dentry = h_path.mnt->mnt_root;
32290 + err = vfs_statfs(&h_path, st);
32291 + if (unlikely(err)) {
32292 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32296 + /* when the available size is equal, select the lower one */
32297 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32298 + || sizeof(b) < sizeof(st->f_bsize));
32299 + b = st->f_bavail * st->f_bsize;
32300 + br->br_wbr->wbr_bytes = b;
32301 + if (b >= bavail) {
32303 + mfs->mfs_bindex = bindex;
32304 + mfs->mfs_jiffy = jiffies;
32308 + mfs->mfsrr_bytes = bavail;
32309 + AuDbg("b%d\n", mfs->mfs_bindex);
32313 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32316 + struct dentry *parent;
32317 + struct super_block *sb;
32318 + struct au_wbr_mfs *mfs;
32320 + err = au_wbr_create_exp(dentry);
32324 + sb = dentry->d_sb;
32326 + if (au_ftest_wbr(flags, PARENT))
32327 + parent = dget_parent(dentry);
32328 + mfs = &au_sbi(sb)->si_wbr_mfs;
32329 + mutex_lock(&mfs->mfs_lock);
32330 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32331 + || mfs->mfs_bindex < 0
32332 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32333 + au_mfs(dentry, parent);
32334 + mutex_unlock(&mfs->mfs_lock);
32335 + err = mfs->mfs_bindex;
32339 + err = au_wbr_nonopq(dentry, err);
32342 + AuDbg("b%d\n", err);
32346 +static int au_wbr_create_init_mfs(struct super_block *sb)
32348 + struct au_wbr_mfs *mfs;
32350 + mfs = &au_sbi(sb)->si_wbr_mfs;
32351 + mutex_init(&mfs->mfs_lock);
32352 + mfs->mfs_jiffy = 0;
32353 + mfs->mfs_bindex = -EROFS;
32358 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32360 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32364 +/* ---------------------------------------------------------------------- */
32366 +/* top down regardless parent, and then mfs */
32367 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32368 + unsigned int flags __maybe_unused)
32371 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32372 + unsigned long long watermark;
32373 + struct super_block *sb;
32374 + struct au_wbr_mfs *mfs;
32375 + struct au_branch *br;
32376 + struct dentry *parent;
32378 + sb = dentry->d_sb;
32379 + mfs = &au_sbi(sb)->si_wbr_mfs;
32380 + mutex_lock(&mfs->mfs_lock);
32381 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32382 + || mfs->mfs_bindex < 0)
32383 + au_mfs(dentry, /*parent*/NULL);
32384 + watermark = mfs->mfsrr_watermark;
32385 + bmfs = mfs->mfs_bindex;
32386 + mutex_unlock(&mfs->mfs_lock);
32388 + /* another style of au_wbr_create_exp() */
32389 + bwh = au_dbwh(dentry);
32390 + parent = dget_parent(dentry);
32391 + btail = au_dbtaildir(parent);
32392 + if (bwh >= 0 && bwh < btail)
32395 + err = au_wbr_nonopq(dentry, btail);
32396 + if (unlikely(err < 0))
32400 + for (bindex = 0; bindex <= btail; bindex++) {
32401 + br = au_sbr(sb, bindex);
32402 + if (au_br_rdonly(br))
32404 + if (br->br_wbr->wbr_bytes > watermark) {
32415 + AuDbg("b%d\n", err);
32419 +/* ---------------------------------------------------------------------- */
32421 +/* most free space and then round robin */
32422 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32425 + struct au_wbr_mfs *mfs;
32427 + err = au_wbr_create_mfs(dentry, flags);
32429 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32430 + mutex_lock(&mfs->mfs_lock);
32431 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32432 + err = au_wbr_create_rr(dentry, flags);
32433 + mutex_unlock(&mfs->mfs_lock);
32436 + AuDbg("b%d\n", err);
32440 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32444 + au_wbr_create_init_mfs(sb); /* ignore */
32445 + err = au_wbr_create_init_rr(sb);
32450 +/* ---------------------------------------------------------------------- */
32452 +/* top down parent and most free space */
32453 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32456 + unsigned long long b;
32457 + aufs_bindex_t bindex, btop, bbot;
32458 + struct super_block *sb;
32459 + struct dentry *parent, *h_parent;
32460 + struct au_branch *br;
32462 + err = au_wbr_create_tdp(dentry, flags);
32463 + if (unlikely(err < 0))
32465 + parent = dget_parent(dentry);
32466 + btop = au_dbtop(parent);
32467 + bbot = au_dbtaildir(parent);
32468 + if (btop == bbot)
32469 + goto out_parent; /* success */
32471 + e2 = au_wbr_create_mfs(dentry, flags);
32473 + goto out_parent; /* success */
32475 + /* when the available size is equal, select upper one */
32476 + sb = dentry->d_sb;
32477 + br = au_sbr(sb, err);
32478 + b = br->br_wbr->wbr_bytes;
32479 + AuDbg("b%d, %llu\n", err, b);
32481 + for (bindex = btop; bindex <= bbot; bindex++) {
32482 + h_parent = au_h_dptr(parent, bindex);
32483 + if (!h_parent || d_is_negative(h_parent))
32486 + br = au_sbr(sb, bindex);
32487 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32488 + b = br->br_wbr->wbr_bytes;
32490 + AuDbg("b%d, %llu\n", err, b);
32495 + err = au_wbr_nonopq(dentry, err);
32500 + AuDbg("b%d\n", err);
32504 +/* ---------------------------------------------------------------------- */
32507 + * - top down parent
32508 + * - most free space with parent
32509 + * - most free space round-robin regardless parent
32511 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32514 + unsigned long long watermark;
32515 + struct super_block *sb;
32516 + struct au_branch *br;
32517 + struct au_wbr_mfs *mfs;
32519 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32520 + if (unlikely(err < 0))
32523 + sb = dentry->d_sb;
32524 + br = au_sbr(sb, err);
32525 + mfs = &au_sbi(sb)->si_wbr_mfs;
32526 + mutex_lock(&mfs->mfs_lock);
32527 + watermark = mfs->mfsrr_watermark;
32528 + mutex_unlock(&mfs->mfs_lock);
32529 + if (br->br_wbr->wbr_bytes < watermark)
32530 + /* regardless the parent dir */
32531 + err = au_wbr_create_mfsrr(dentry, flags);
32534 + AuDbg("b%d\n", err);
32538 +/* ---------------------------------------------------------------------- */
32540 +/* policies for copyup */
32542 +/* top down parent */
32543 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32545 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32548 +/* bottom up parent */
32549 +static int au_wbr_copyup_bup(struct dentry *dentry)
32552 + aufs_bindex_t bindex, btop;
32553 + struct dentry *parent, *h_parent;
32554 + struct super_block *sb;
32557 + sb = dentry->d_sb;
32558 + parent = dget_parent(dentry);
32559 + btop = au_dbtop(parent);
32560 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32561 + h_parent = au_h_dptr(parent, bindex);
32562 + if (!h_parent || d_is_negative(h_parent))
32565 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32572 + /* bottom up here */
32573 + if (unlikely(err < 0))
32574 + err = au_wbr_bu(sb, btop - 1);
32576 + AuDbg("b%d\n", err);
32581 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32585 + err = au_wbr_bu(dentry->d_sb, btop);
32586 + AuDbg("b%d\n", err);
32588 + err = au_wbr_nonopq(dentry, err);
32590 + AuDbg("b%d\n", err);
32594 +static int au_wbr_copyup_bu(struct dentry *dentry)
32597 + aufs_bindex_t btop;
32599 + btop = au_dbtop(dentry);
32600 + err = au_wbr_do_copyup_bu(dentry, btop);
32604 +/* ---------------------------------------------------------------------- */
32606 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32607 + [AuWbrCopyup_TDP] = {
32608 + .copyup = au_wbr_copyup_tdp
32610 + [AuWbrCopyup_BUP] = {
32611 + .copyup = au_wbr_copyup_bup
32613 + [AuWbrCopyup_BU] = {
32614 + .copyup = au_wbr_copyup_bu
32618 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32619 + [AuWbrCreate_TDP] = {
32620 + .create = au_wbr_create_tdp
32622 + [AuWbrCreate_RR] = {
32623 + .create = au_wbr_create_rr,
32624 + .init = au_wbr_create_init_rr
32626 + [AuWbrCreate_MFS] = {
32627 + .create = au_wbr_create_mfs,
32628 + .init = au_wbr_create_init_mfs,
32629 + .fin = au_wbr_create_fin_mfs
32631 + [AuWbrCreate_MFSV] = {
32632 + .create = au_wbr_create_mfs,
32633 + .init = au_wbr_create_init_mfs,
32634 + .fin = au_wbr_create_fin_mfs
32636 + [AuWbrCreate_MFSRR] = {
32637 + .create = au_wbr_create_mfsrr,
32638 + .init = au_wbr_create_init_mfsrr,
32639 + .fin = au_wbr_create_fin_mfs
32641 + [AuWbrCreate_MFSRRV] = {
32642 + .create = au_wbr_create_mfsrr,
32643 + .init = au_wbr_create_init_mfsrr,
32644 + .fin = au_wbr_create_fin_mfs
32646 + [AuWbrCreate_TDMFS] = {
32647 + .create = au_wbr_create_tdmfs,
32648 + .init = au_wbr_create_init_mfs,
32649 + .fin = au_wbr_create_fin_mfs
32651 + [AuWbrCreate_TDMFSV] = {
32652 + .create = au_wbr_create_tdmfs,
32653 + .init = au_wbr_create_init_mfs,
32654 + .fin = au_wbr_create_fin_mfs
32656 + [AuWbrCreate_PMFS] = {
32657 + .create = au_wbr_create_pmfs,
32658 + .init = au_wbr_create_init_mfs,
32659 + .fin = au_wbr_create_fin_mfs
32661 + [AuWbrCreate_PMFSV] = {
32662 + .create = au_wbr_create_pmfs,
32663 + .init = au_wbr_create_init_mfs,
32664 + .fin = au_wbr_create_fin_mfs
32666 + [AuWbrCreate_PMFSRR] = {
32667 + .create = au_wbr_create_pmfsrr,
32668 + .init = au_wbr_create_init_mfsrr,
32669 + .fin = au_wbr_create_fin_mfs
32671 + [AuWbrCreate_PMFSRRV] = {
32672 + .create = au_wbr_create_pmfsrr,
32673 + .init = au_wbr_create_init_mfsrr,
32674 + .fin = au_wbr_create_fin_mfs
32677 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32678 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32679 +++ linux/fs/aufs/whout.c 2017-07-29 12:14:25.906375514 +0200
32682 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32684 + * This program, aufs is free software; you can redistribute it and/or modify
32685 + * it under the terms of the GNU General Public License as published by
32686 + * the Free Software Foundation; either version 2 of the License, or
32687 + * (at your option) any later version.
32689 + * This program is distributed in the hope that it will be useful,
32690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32692 + * GNU General Public License for more details.
32694 + * You should have received a copy of the GNU General Public License
32695 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32699 + * whiteout for logical deletion and opaque directory
32704 +#define WH_MASK S_IRUGO
32707 + * If a directory contains this file, then it is opaque. We start with the
32708 + * .wh. flag so that it is blocked by lookup.
32710 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32711 + sizeof(AUFS_WH_DIROPQ) - 1);
32714 + * generate whiteout name, which is NOT terminated by NULL.
32715 + * @name: original d_name.name
32716 + * @len: original d_name.len
32717 + * @wh: whiteout qstr
32718 + * returns zero when succeeds, otherwise error.
32719 + * succeeded value as wh->name should be freed by kfree().
32721 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32725 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32726 + return -ENAMETOOLONG;
32728 + wh->len = name->len + AUFS_WH_PFX_LEN;
32729 + p = kmalloc(wh->len, GFP_NOFS);
32732 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32733 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32740 +/* ---------------------------------------------------------------------- */
32743 + * test if the @wh_name exists under @h_parent.
32744 + * @try_sio specifies the necessary of super-io.
32746 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32749 + struct dentry *wh_dentry;
32752 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32754 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32755 + err = PTR_ERR(wh_dentry);
32756 + if (IS_ERR(wh_dentry)) {
32757 + if (err == -ENAMETOOLONG)
32763 + if (d_is_negative(wh_dentry))
32764 + goto out_wh; /* success */
32767 + if (d_is_reg(wh_dentry))
32768 + goto out_wh; /* success */
32771 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32772 + wh_dentry, d_inode(wh_dentry)->i_mode);
32781 + * test if the @h_dentry sets opaque or not.
32783 +int au_diropq_test(struct dentry *h_dentry)
32786 + struct inode *h_dir;
32788 + h_dir = d_inode(h_dentry);
32789 + err = au_wh_test(h_dentry, &diropq_name,
32790 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32795 + * returns a negative dentry whose name is unique and temporary.
32797 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32798 + struct qstr *prefix)
32800 + struct dentry *dentry;
32802 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32804 + /* strict atomic_t is unnecessary here */
32805 + static unsigned short cnt;
32808 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32811 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32812 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32813 + dentry = ERR_PTR(-ENAMETOOLONG);
32814 + if (unlikely(qs.len > NAME_MAX))
32816 + dentry = ERR_PTR(-ENOMEM);
32817 + name = kmalloc(qs.len + 1, GFP_NOFS);
32818 + if (unlikely(!name))
32822 + /* doubly whiteout-ed */
32823 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32824 + p = name + AUFS_WH_PFX_LEN * 2;
32825 + memcpy(p, prefix->name, prefix->len);
32826 + p += prefix->len;
32828 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32831 + for (i = 0; i < 3; i++) {
32832 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32833 + dentry = au_sio_lkup_one(&qs, h_parent);
32834 + if (IS_ERR(dentry) || d_is_negative(dentry))
32838 + /* pr_warn("could not get random name\n"); */
32839 + dentry = ERR_PTR(-EEXIST);
32840 + AuDbg("%.*s\n", AuLNPair(&qs));
32844 + if (name != defname)
32847 + AuTraceErrPtr(dentry);
32852 + * rename the @h_dentry on @br to the whiteouted temporary name.
32854 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32857 + struct path h_path = {
32858 + .mnt = au_br_mnt(br)
32860 + struct inode *h_dir, *delegated;
32861 + struct dentry *h_parent;
32863 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32864 + h_dir = d_inode(h_parent);
32865 + IMustLock(h_dir);
32867 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32868 + err = PTR_ERR(h_path.dentry);
32869 + if (IS_ERR(h_path.dentry))
32872 + /* under the same dir, no need to lock_rename() */
32873 + delegated = NULL;
32874 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
32877 + if (unlikely(err == -EWOULDBLOCK)) {
32878 + pr_warn("cannot retry for NFSv4 delegation"
32879 + " for an internal rename\n");
32882 + dput(h_path.dentry);
32889 +/* ---------------------------------------------------------------------- */
32891 + * functions for removing a whiteout
32894 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32897 + struct inode *delegated;
32900 + * forces superio when the dir has a sticky bit.
32901 + * this may be a violation of unix fs semantics.
32903 + force = (h_dir->i_mode & S_ISVTX)
32904 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32905 + delegated = NULL;
32906 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32907 + if (unlikely(err == -EWOULDBLOCK)) {
32908 + pr_warn("cannot retry for NFSv4 delegation"
32909 + " for an internal unlink\n");
32915 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32916 + struct dentry *dentry)
32920 + err = do_unlink_wh(h_dir, h_path);
32921 + if (!err && dentry)
32922 + au_set_dbwh(dentry, -1);
32927 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32928 + struct au_branch *br)
32931 + struct path h_path = {
32932 + .mnt = au_br_mnt(br)
32936 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32937 + if (IS_ERR(h_path.dentry))
32938 + err = PTR_ERR(h_path.dentry);
32940 + if (d_is_reg(h_path.dentry))
32941 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32942 + dput(h_path.dentry);
32948 +/* ---------------------------------------------------------------------- */
32950 + * initialize/clean whiteout for a branch
32953 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32957 + struct inode *delegated;
32959 + if (d_is_negative(whpath->dentry))
32963 + err = vfsub_rmdir(h_dir, whpath);
32965 + delegated = NULL;
32966 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32967 + if (unlikely(err == -EWOULDBLOCK)) {
32968 + pr_warn("cannot retry for NFSv4 delegation"
32969 + " for an internal unlink\n");
32973 + if (unlikely(err))
32974 + pr_warn("failed removing %pd (%d), ignored.\n",
32975 + whpath->dentry, err);
32978 +static int test_linkable(struct dentry *h_root)
32980 + struct inode *h_dir = d_inode(h_root);
32982 + if (h_dir->i_op->link)
32985 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32986 + h_root, au_sbtype(h_root->d_sb));
32990 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32991 +static int au_whdir(struct inode *h_dir, struct path *path)
32996 + if (d_is_negative(path->dentry)) {
32997 + int mode = S_IRWXU;
32999 + if (au_test_nfs(path->dentry->d_sb))
33001 + err = vfsub_mkdir(h_dir, path, mode);
33002 + } else if (d_is_dir(path->dentry))
33005 + pr_err("unknown %pd exists\n", path->dentry);
33010 +struct au_wh_base {
33011 + const struct qstr *name;
33012 + struct dentry *dentry;
33015 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
33016 + struct path *h_path)
33018 + h_path->dentry = base[AuBrWh_BASE].dentry;
33019 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33020 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33021 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33022 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33023 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33027 + * returns tri-state,
33028 + * minus: error, caller should print the message
33030 + * plus: error, caller should NOT print the message
33032 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
33033 + int do_plink, struct au_wh_base base[],
33034 + struct path *h_path)
33037 + struct inode *h_dir;
33039 + h_dir = d_inode(h_root);
33040 + h_path->dentry = base[AuBrWh_BASE].dentry;
33041 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33042 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33044 + err = test_linkable(h_root);
33045 + if (unlikely(err)) {
33050 + err = au_whdir(h_dir, h_path);
33051 + if (unlikely(err))
33053 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33055 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33056 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33057 + err = au_whdir(h_dir, h_path);
33058 + if (unlikely(err))
33060 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33067 + * for the moment, aufs supports the branch filesystem which does not support
33068 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
33069 + * copyup failed. finally, such filesystem will not be used as the writable
33072 + * returns tri-state, see above.
33074 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
33075 + int do_plink, struct au_wh_base base[],
33076 + struct path *h_path)
33079 + struct inode *h_dir;
33081 + WbrWhMustWriteLock(wbr);
33083 + err = test_linkable(h_root);
33084 + if (unlikely(err)) {
33090 + * todo: should this create be done in /sbin/mount.aufs helper?
33093 + h_dir = d_inode(h_root);
33094 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33095 + h_path->dentry = base[AuBrWh_BASE].dentry;
33096 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33097 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33100 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33101 + if (unlikely(err))
33104 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33106 + err = au_whdir(h_dir, h_path);
33107 + if (unlikely(err))
33109 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33111 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33112 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33114 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33115 + err = au_whdir(h_dir, h_path);
33116 + if (unlikely(err))
33118 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33125 + * initialize the whiteout base file/dir for @br.
33127 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33130 + const unsigned char do_plink
33131 + = !!au_opt_test(au_mntflags(sb), PLINK);
33132 + struct inode *h_dir;
33133 + struct path path = br->br_path;
33134 + struct dentry *h_root = path.dentry;
33135 + struct au_wbr *wbr = br->br_wbr;
33136 + static const struct qstr base_name[] = {
33137 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33138 + sizeof(AUFS_BASE_NAME) - 1),
33139 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33140 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33141 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33142 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33144 + struct au_wh_base base[] = {
33145 + [AuBrWh_BASE] = {
33146 + .name = base_name + AuBrWh_BASE,
33149 + [AuBrWh_PLINK] = {
33150 + .name = base_name + AuBrWh_PLINK,
33153 + [AuBrWh_ORPH] = {
33154 + .name = base_name + AuBrWh_ORPH,
33160 + WbrWhMustWriteLock(wbr);
33162 + for (i = 0; i < AuBrWh_Last; i++) {
33163 + /* doubly whiteouted */
33164 + struct dentry *d;
33166 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33167 + err = PTR_ERR(d);
33171 + base[i].dentry = d;
33173 + && wbr->wbr_wh[i]
33174 + && wbr->wbr_wh[i] != base[i].dentry);
33178 + for (i = 0; i < AuBrWh_Last; i++) {
33179 + dput(wbr->wbr_wh[i]);
33180 + wbr->wbr_wh[i] = NULL;
33184 + if (!au_br_writable(br->br_perm)) {
33185 + h_dir = d_inode(h_root);
33186 + au_wh_init_ro(h_dir, base, &path);
33187 + } else if (!au_br_wh_linkable(br->br_perm)) {
33188 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33194 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33200 + goto out; /* success */
33203 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33204 + err, h_root, au_sbtype(h_root->d_sb));
33206 + for (i = 0; i < AuBrWh_Last; i++)
33207 + dput(base[i].dentry);
33211 +/* ---------------------------------------------------------------------- */
33213 + * whiteouts are all hard-linked usually.
33214 + * when its link count reaches a ceiling, we create a new whiteout base
33215 + * asynchronously.
33218 +struct reinit_br_wh {
33219 + struct super_block *sb;
33220 + struct au_branch *br;
33223 +static void reinit_br_wh(void *arg)
33226 + aufs_bindex_t bindex;
33227 + struct path h_path;
33228 + struct reinit_br_wh *a = arg;
33229 + struct au_wbr *wbr;
33230 + struct inode *dir, *delegated;
33231 + struct dentry *h_root;
33232 + struct au_hinode *hdir;
33235 + wbr = a->br->br_wbr;
33236 + /* big aufs lock */
33237 + si_noflush_write_lock(a->sb);
33238 + if (!au_br_writable(a->br->br_perm))
33240 + bindex = au_br_index(a->sb, a->br->br_id);
33241 + if (unlikely(bindex < 0))
33244 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33245 + dir = d_inode(a->sb->s_root);
33246 + hdir = au_hi(dir, bindex);
33247 + h_root = au_h_dptr(a->sb->s_root, bindex);
33248 + AuDebugOn(h_root != au_br_dentry(a->br));
33250 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33251 + wbr_wh_write_lock(wbr);
33252 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33255 + h_path.dentry = wbr->wbr_whbase;
33256 + h_path.mnt = au_br_mnt(a->br);
33257 + delegated = NULL;
33258 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33260 + if (unlikely(err == -EWOULDBLOCK)) {
33261 + pr_warn("cannot retry for NFSv4 delegation"
33262 + " for an internal unlink\n");
33266 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33269 + dput(wbr->wbr_whbase);
33270 + wbr->wbr_whbase = NULL;
33272 + err = au_wh_init(a->br, a->sb);
33273 + wbr_wh_write_unlock(wbr);
33274 + au_hn_inode_unlock(hdir);
33275 + di_read_unlock(a->sb->s_root, AuLock_IR);
33277 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33281 + atomic_dec(&wbr->wbr_wh_running);
33282 + au_br_put(a->br);
33283 + si_write_unlock(a->sb);
33284 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33286 + if (unlikely(err))
33287 + AuIOErr("err %d\n", err);
33290 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33292 + int do_dec, wkq_err;
33293 + struct reinit_br_wh *arg;
33296 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33299 + /* ignore ENOMEM */
33300 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33303 + * dec(wh_running), kfree(arg) and dec(br_count)
33304 + * in reinit function
33309 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33310 + if (unlikely(wkq_err)) {
33311 + atomic_dec(&br->br_wbr->wbr_wh_running);
33320 + atomic_dec(&br->br_wbr->wbr_wh_running);
33323 +/* ---------------------------------------------------------------------- */
33326 + * create the whiteout @wh.
33328 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33329 + struct dentry *wh)
33332 + struct path h_path = {
33335 + struct au_branch *br;
33336 + struct au_wbr *wbr;
33337 + struct dentry *h_parent;
33338 + struct inode *h_dir, *delegated;
33340 + h_parent = wh->d_parent; /* dir inode is locked */
33341 + h_dir = d_inode(h_parent);
33342 + IMustLock(h_dir);
33344 + br = au_sbr(sb, bindex);
33345 + h_path.mnt = au_br_mnt(br);
33346 + wbr = br->br_wbr;
33347 + wbr_wh_read_lock(wbr);
33348 + if (wbr->wbr_whbase) {
33349 + delegated = NULL;
33350 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33351 + if (unlikely(err == -EWOULDBLOCK)) {
33352 + pr_warn("cannot retry for NFSv4 delegation"
33353 + " for an internal link\n");
33356 + if (!err || err != -EMLINK)
33359 + /* link count full. re-initialize br_whbase. */
33360 + kick_reinit_br_wh(sb, br);
33363 + /* return this error in this context */
33364 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33366 + au_fhsm_wrote(sb, bindex, /*force*/0);
33369 + wbr_wh_read_unlock(wbr);
33373 +/* ---------------------------------------------------------------------- */
33376 + * create or remove the diropq.
33378 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33379 + unsigned int flags)
33381 + struct dentry *opq_dentry, *h_dentry;
33382 + struct super_block *sb;
33383 + struct au_branch *br;
33386 + sb = dentry->d_sb;
33387 + br = au_sbr(sb, bindex);
33388 + h_dentry = au_h_dptr(dentry, bindex);
33389 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33390 + if (IS_ERR(opq_dentry))
33393 + if (au_ftest_diropq(flags, CREATE)) {
33394 + err = link_or_create_wh(sb, bindex, opq_dentry);
33396 + au_set_dbdiropq(dentry, bindex);
33397 + goto out; /* success */
33400 + struct path tmp = {
33401 + .dentry = opq_dentry,
33402 + .mnt = au_br_mnt(br)
33404 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33406 + au_set_dbdiropq(dentry, -1);
33408 + dput(opq_dentry);
33409 + opq_dentry = ERR_PTR(err);
33412 + return opq_dentry;
33415 +struct do_diropq_args {
33416 + struct dentry **errp;
33417 + struct dentry *dentry;
33418 + aufs_bindex_t bindex;
33419 + unsigned int flags;
33422 +static void call_do_diropq(void *args)
33424 + struct do_diropq_args *a = args;
33425 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33428 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33429 + unsigned int flags)
33431 + struct dentry *diropq, *h_dentry;
33433 + h_dentry = au_h_dptr(dentry, bindex);
33434 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33435 + diropq = do_diropq(dentry, bindex, flags);
33438 + struct do_diropq_args args = {
33440 + .dentry = dentry,
33441 + .bindex = bindex,
33445 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33446 + if (unlikely(wkq_err))
33447 + diropq = ERR_PTR(wkq_err);
33453 +/* ---------------------------------------------------------------------- */
33456 + * lookup whiteout dentry.
33457 + * @h_parent: lower parent dentry which must exist and be locked
33458 + * @base_name: name of dentry which will be whiteouted
33459 + * returns dentry for whiteout.
33461 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33462 + struct au_branch *br)
33465 + struct qstr wh_name;
33466 + struct dentry *wh_dentry;
33468 + err = au_wh_name_alloc(&wh_name, base_name);
33469 + wh_dentry = ERR_PTR(err);
33471 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33472 + kfree(wh_name.name);
33474 + return wh_dentry;
33478 + * link/create a whiteout for @dentry on @bindex.
33480 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33481 + struct dentry *h_parent)
33483 + struct dentry *wh_dentry;
33484 + struct super_block *sb;
33487 + sb = dentry->d_sb;
33488 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33489 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33490 + err = link_or_create_wh(sb, bindex, wh_dentry);
33492 + au_set_dbwh(dentry, bindex);
33493 + au_fhsm_wrote(sb, bindex, /*force*/0);
33496 + wh_dentry = ERR_PTR(err);
33500 + return wh_dentry;
33503 +/* ---------------------------------------------------------------------- */
33505 +/* Delete all whiteouts in this directory on branch bindex. */
33506 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33507 + aufs_bindex_t bindex, struct au_branch *br)
33510 + unsigned long ul, n;
33511 + struct qstr wh_name;
33513 + struct hlist_head *head;
33514 + struct au_vdir_wh *pos;
33515 + struct au_vdir_destr *str;
33518 + p = (void *)__get_free_page(GFP_NOFS);
33519 + wh_name.name = p;
33520 + if (unlikely(!wh_name.name))
33524 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33525 + p += AUFS_WH_PFX_LEN;
33526 + n = whlist->nh_num;
33527 + head = whlist->nh_head;
33528 + for (ul = 0; !err && ul < n; ul++, head++) {
33529 + hlist_for_each_entry(pos, head, wh_hash) {
33530 + if (pos->wh_bindex != bindex)
33533 + str = &pos->wh_str;
33534 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33535 + memcpy(p, str->name, str->len);
33536 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33537 + err = unlink_wh_name(h_dentry, &wh_name, br);
33542 + AuIOErr("whiteout name too long %.*s\n",
33543 + str->len, str->name);
33548 + free_page((unsigned long)wh_name.name);
33554 +struct del_wh_children_args {
33556 + struct dentry *h_dentry;
33557 + struct au_nhash *whlist;
33558 + aufs_bindex_t bindex;
33559 + struct au_branch *br;
33562 +static void call_del_wh_children(void *args)
33564 + struct del_wh_children_args *a = args;
33565 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33568 +/* ---------------------------------------------------------------------- */
33570 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33572 + struct au_whtmp_rmdir *whtmp;
33574 + unsigned int rdhash;
33576 + SiMustAnyLock(sb);
33578 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33579 + if (unlikely(!whtmp)) {
33580 + whtmp = ERR_PTR(-ENOMEM);
33584 + /* no estimation for dir size */
33585 + rdhash = au_sbi(sb)->si_rdhash;
33587 + rdhash = AUFS_RDHASH_DEF;
33588 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33589 + if (unlikely(err)) {
33591 + whtmp = ERR_PTR(err);
33598 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33601 + au_br_put(whtmp->br);
33602 + dput(whtmp->wh_dentry);
33603 + iput(whtmp->dir);
33604 + au_nhash_wh_free(&whtmp->whlist);
33609 + * rmdir the whiteouted temporary named dir @h_dentry.
33610 + * @whlist: whiteouted children.
33612 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33613 + struct dentry *wh_dentry, struct au_nhash *whlist)
33616 + unsigned int h_nlink;
33617 + struct path h_tmp;
33618 + struct inode *wh_inode, *h_dir;
33619 + struct au_branch *br;
33621 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33622 + IMustLock(h_dir);
33624 + br = au_sbr(dir->i_sb, bindex);
33625 + wh_inode = d_inode(wh_dentry);
33626 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33629 + * someone else might change some whiteouts while we were sleeping.
33630 + * it means this whlist may have an obsoleted entry.
33632 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33633 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33636 + struct del_wh_children_args args = {
33638 + .h_dentry = wh_dentry,
33639 + .whlist = whlist,
33640 + .bindex = bindex,
33644 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33645 + if (unlikely(wkq_err))
33648 + inode_unlock(wh_inode);
33651 + h_tmp.dentry = wh_dentry;
33652 + h_tmp.mnt = au_br_mnt(br);
33653 + h_nlink = h_dir->i_nlink;
33654 + err = vfsub_rmdir(h_dir, &h_tmp);
33655 + /* some fs doesn't change the parent nlink in some cases */
33656 + h_nlink -= h_dir->i_nlink;
33660 + if (au_ibtop(dir) == bindex) {
33661 + /* todo: dir->i_mutex is necessary */
33662 + au_cpup_attr_timesizes(dir);
33664 + vfsub_drop_nlink(dir);
33666 + return 0; /* success */
33669 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33673 +static void call_rmdir_whtmp(void *args)
33676 + aufs_bindex_t bindex;
33677 + struct au_whtmp_rmdir *a = args;
33678 + struct super_block *sb;
33679 + struct dentry *h_parent;
33680 + struct inode *h_dir;
33681 + struct au_hinode *hdir;
33683 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33684 + /* inode_lock(a->dir); */
33686 + sb = a->dir->i_sb;
33687 + si_read_lock(sb, !AuLock_FLUSH);
33688 + if (!au_br_writable(a->br->br_perm))
33690 + bindex = au_br_index(sb, a->br->br_id);
33691 + if (unlikely(bindex < 0))
33695 + ii_write_lock_parent(a->dir);
33696 + h_parent = dget_parent(a->wh_dentry);
33697 + h_dir = d_inode(h_parent);
33698 + hdir = au_hi(a->dir, bindex);
33699 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33700 + if (unlikely(err))
33702 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33703 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33706 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33707 + au_hn_inode_unlock(hdir);
33708 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33712 + ii_write_unlock(a->dir);
33714 + /* inode_unlock(a->dir); */
33715 + au_whtmp_rmdir_free(a);
33716 + si_read_unlock(sb);
33717 + au_nwt_done(&au_sbi(sb)->si_nowait);
33718 + if (unlikely(err))
33719 + AuIOErr("err %d\n", err);
33722 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33723 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33726 + struct super_block *sb;
33730 + /* all post-process will be done in do_rmdir_whtmp(). */
33732 + args->dir = au_igrab(dir);
33733 + args->br = au_sbr(sb, bindex);
33734 + au_br_get(args->br);
33735 + args->wh_dentry = dget(wh_dentry);
33736 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33737 + if (unlikely(wkq_err)) {
33738 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33739 + au_whtmp_rmdir_free(args);
33742 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33743 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33744 +++ linux/fs/aufs/whout.h 2017-07-29 12:14:25.906375514 +0200
33747 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33749 + * This program, aufs is free software; you can redistribute it and/or modify
33750 + * it under the terms of the GNU General Public License as published by
33751 + * the Free Software Foundation; either version 2 of the License, or
33752 + * (at your option) any later version.
33754 + * This program is distributed in the hope that it will be useful,
33755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33757 + * GNU General Public License for more details.
33759 + * You should have received a copy of the GNU General Public License
33760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33764 + * whiteout for logical deletion and opaque directory
33767 +#ifndef __AUFS_WHOUT_H__
33768 +#define __AUFS_WHOUT_H__
33775 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33776 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33777 +int au_diropq_test(struct dentry *h_dentry);
33778 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33779 + struct qstr *prefix);
33780 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33781 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33782 + struct dentry *dentry);
33783 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33785 +/* diropq flags */
33786 +#define AuDiropq_CREATE 1
33787 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33788 +#define au_fset_diropq(flags, name) \
33789 + do { (flags) |= AuDiropq_##name; } while (0)
33790 +#define au_fclr_diropq(flags, name) \
33791 + do { (flags) &= ~AuDiropq_##name; } while (0)
33793 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33794 + unsigned int flags);
33795 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33796 + struct au_branch *br);
33797 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33798 + struct dentry *h_parent);
33800 +/* real rmdir for the whiteout-ed dir */
33801 +struct au_whtmp_rmdir {
33802 + struct inode *dir;
33803 + struct au_branch *br;
33804 + struct dentry *wh_dentry;
33805 + struct au_nhash whlist;
33808 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33809 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33810 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33811 + struct dentry *wh_dentry, struct au_nhash *whlist);
33812 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33813 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33815 +/* ---------------------------------------------------------------------- */
33817 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33818 + aufs_bindex_t bindex)
33820 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33823 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33825 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33828 +#endif /* __KERNEL__ */
33829 +#endif /* __AUFS_WHOUT_H__ */
33830 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33831 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33832 +++ linux/fs/aufs/wkq.c 2017-07-29 12:14:25.906375514 +0200
33835 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33837 + * This program, aufs is free software; you can redistribute it and/or modify
33838 + * it under the terms of the GNU General Public License as published by
33839 + * the Free Software Foundation; either version 2 of the License, or
33840 + * (at your option) any later version.
33842 + * This program is distributed in the hope that it will be useful,
33843 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33844 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33845 + * GNU General Public License for more details.
33847 + * You should have received a copy of the GNU General Public License
33848 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33852 + * workqueue for asynchronous/super-io operations
33853 + * todo: try new dredential scheme
33856 +#include <linux/module.h>
33859 +/* internal workqueue named AUFS_WKQ_NAME */
33861 +static struct workqueue_struct *au_wkq;
33863 +struct au_wkinfo {
33864 + struct work_struct wk;
33865 + struct kobject *kobj;
33867 + unsigned int flags; /* see wkq.h */
33869 + au_wkq_func_t func;
33872 + struct completion *comp;
33875 +/* ---------------------------------------------------------------------- */
33877 +static void wkq_func(struct work_struct *wk)
33879 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33881 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33882 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33884 + wkinfo->func(wkinfo->args);
33885 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33886 + complete(wkinfo->comp);
33888 + kobject_put(wkinfo->kobj);
33889 + module_put(THIS_MODULE); /* todo: ?? */
33895 + * Since struct completion is large, try allocating it dynamically.
33897 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33898 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33900 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33902 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33904 + init_completion(*comp);
33905 + wkinfo->comp = *comp;
33911 +static void au_wkq_comp_free(struct completion *comp)
33919 +#define AuWkqCompDeclare(name) \
33920 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33921 + struct completion *comp = &_ ## name
33923 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33925 + wkinfo->comp = *comp;
33929 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33933 +#endif /* 4KSTACKS */
33935 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33937 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33938 + if (au_wkq_test()) {
33939 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33940 + " due to a dead dir by UDBA?\n");
33941 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33944 + au_dbg_verify_kthread();
33946 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33947 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33948 + queue_work(au_wkq, &wkinfo->wk);
33950 + INIT_WORK(&wkinfo->wk, wkq_func);
33951 + schedule_work(&wkinfo->wk);
33956 + * Be careful. It is easy to make deadlock happen.
33957 + * processA: lock, wkq and wait
33958 + * processB: wkq and wait, lock in wkq
33961 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33964 + AuWkqCompDeclare(comp);
33965 + struct au_wkinfo wkinfo = {
33971 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33973 + au_wkq_run(&wkinfo);
33974 + /* no timeout, no interrupt */
33975 + wait_for_completion(wkinfo.comp);
33976 + au_wkq_comp_free(comp);
33977 + destroy_work_on_stack(&wkinfo.wk);
33985 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33986 + * problem in a concurrent umounting.
33988 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33989 + unsigned int flags)
33992 + struct au_wkinfo *wkinfo;
33994 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33997 + * wkq_func() must free this wkinfo.
33998 + * it highly depends upon the implementation of workqueue.
34001 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
34003 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
34004 + wkinfo->flags = flags & ~AuWkq_WAIT;
34005 + wkinfo->func = func;
34006 + wkinfo->args = args;
34007 + wkinfo->comp = NULL;
34008 + kobject_get(wkinfo->kobj);
34009 + __module_get(THIS_MODULE); /* todo: ?? */
34011 + au_wkq_run(wkinfo);
34014 + au_nwt_done(&au_sbi(sb)->si_nowait);
34020 +/* ---------------------------------------------------------------------- */
34022 +void au_nwt_init(struct au_nowait_tasks *nwt)
34024 + atomic_set(&nwt->nw_len, 0);
34025 + /* smp_mb(); */ /* atomic_set */
34026 + init_waitqueue_head(&nwt->nw_wq);
34029 +void au_wkq_fin(void)
34031 + destroy_workqueue(au_wkq);
34034 +int __init au_wkq_init(void)
34039 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
34040 + if (IS_ERR(au_wkq))
34041 + err = PTR_ERR(au_wkq);
34042 + else if (!au_wkq)
34047 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
34048 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
34049 +++ linux/fs/aufs/wkq.h 2017-07-29 12:14:25.906375514 +0200
34052 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34054 + * This program, aufs is free software; you can redistribute it and/or modify
34055 + * it under the terms of the GNU General Public License as published by
34056 + * the Free Software Foundation; either version 2 of the License, or
34057 + * (at your option) any later version.
34059 + * This program is distributed in the hope that it will be useful,
34060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34062 + * GNU General Public License for more details.
34064 + * You should have received a copy of the GNU General Public License
34065 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34069 + * workqueue for asynchronous/super-io operations
34070 + * todo: try new credentials management scheme
34073 +#ifndef __AUFS_WKQ_H__
34074 +#define __AUFS_WKQ_H__
34078 +#include <linux/percpu_counter.h>
34080 +struct super_block;
34082 +/* ---------------------------------------------------------------------- */
34085 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34087 +struct au_nowait_tasks {
34089 + wait_queue_head_t nw_wq;
34092 +/* ---------------------------------------------------------------------- */
34094 +typedef void (*au_wkq_func_t)(void *args);
34097 +#define AuWkq_WAIT 1
34098 +#define AuWkq_NEST (1 << 1)
34099 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34100 +#define au_fset_wkq(flags, name) \
34101 + do { (flags) |= AuWkq_##name; } while (0)
34102 +#define au_fclr_wkq(flags, name) \
34103 + do { (flags) &= ~AuWkq_##name; } while (0)
34105 +#ifndef CONFIG_AUFS_HNOTIFY
34107 +#define AuWkq_NEST 0
34111 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34112 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34113 + unsigned int flags);
34114 +void au_nwt_init(struct au_nowait_tasks *nwt);
34115 +int __init au_wkq_init(void);
34116 +void au_wkq_fin(void);
34118 +/* ---------------------------------------------------------------------- */
34120 +static inline int au_wkq_test(void)
34122 + return current->flags & PF_WQ_WORKER;
34125 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34127 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34130 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34132 + if (atomic_dec_and_test(&nwt->nw_len))
34133 + wake_up_all(&nwt->nw_wq);
34136 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34138 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34142 +#endif /* __KERNEL__ */
34143 +#endif /* __AUFS_WKQ_H__ */
34144 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34145 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34146 +++ linux/fs/aufs/xattr.c 2017-07-29 12:14:25.906375514 +0200
34149 + * Copyright (C) 2014-2017 Junjiro R. Okajima
34151 + * This program, aufs is free software; you can redistribute it and/or modify
34152 + * it under the terms of the GNU General Public License as published by
34153 + * the Free Software Foundation; either version 2 of the License, or
34154 + * (at your option) any later version.
34156 + * This program is distributed in the hope that it will be useful,
34157 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34159 + * GNU General Public License for more details.
34161 + * You should have received a copy of the GNU General Public License
34162 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34166 + * handling xattr functions
34169 +#include <linux/fs.h>
34170 +#include <linux/posix_acl_xattr.h>
34171 +#include <linux/xattr.h>
34174 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34176 + if (!ignore_flags)
34184 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34189 +#define cmp(brattr, prefix) do { \
34190 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34191 + XATTR_##prefix##_PREFIX_LEN)) { \
34192 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34198 + cmp(SEC, SECURITY);
34199 + cmp(SYS, SYSTEM);
34200 + cmp(TR, TRUSTED);
34204 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34211 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34213 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34214 + char *name, char **buf, unsigned int ignore_flags,
34215 + unsigned int verbose)
34219 + struct inode *h_idst;
34221 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34223 + if (unlikely(err <= 0)) {
34224 + if (err == -ENODATA
34225 + || (err == -EOPNOTSUPP
34226 + && ((ignore_flags & au_xattr_out_of_list)
34227 + || (au_test_nfs_noacl(d_inode(h_src))
34228 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34230 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34233 + if (err && (verbose || au_debug_test()))
34234 + pr_err("%s, err %d\n", name, err);
34238 + /* unlock it temporary */
34239 + h_idst = d_inode(h_dst);
34240 + inode_unlock(h_idst);
34241 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34242 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34243 + if (unlikely(err)) {
34244 + if (verbose || au_debug_test())
34245 + pr_err("%s, err %d\n", name, err);
34246 + err = au_xattr_ignore(err, name, ignore_flags);
34253 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34254 + unsigned int verbose)
34256 + int err, unlocked, acl_access, acl_default;
34258 + struct inode *h_isrc, *h_idst;
34259 + char *value, *p, *o, *e;
34261 + /* try stopping to update the source inode while we are referencing */
34262 + /* there should not be the parent-child relationship between them */
34263 + h_isrc = d_inode(h_src);
34264 + h_idst = d_inode(h_dst);
34265 + inode_unlock(h_idst);
34266 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34267 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34270 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34271 + ssz = vfs_listxattr(h_src, NULL, 0);
34273 + if (unlikely(err < 0)) {
34275 + if (err == -ENODATA
34276 + || err == -EOPNOTSUPP)
34277 + err = 0; /* ignore */
34286 + p = kmalloc(ssz, GFP_NOFS);
34288 + if (unlikely(!p))
34290 + err = vfs_listxattr(h_src, p, ssz);
34292 + inode_unlock(h_isrc);
34294 + AuDbg("err %d, ssz %zd\n", err, ssz);
34295 + if (unlikely(err < 0))
34303 + while (!err && p < e) {
34304 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34305 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34306 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34307 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34309 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34311 + p += strlen(p) + 1;
34314 + ignore_flags |= au_xattr_out_of_list;
34315 + if (!err && !acl_access) {
34316 + err = au_do_cpup_xattr(h_dst, h_src,
34317 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34318 + ignore_flags, verbose);
34321 + if (!err && !acl_default) {
34322 + err = au_do_cpup_xattr(h_dst, h_src,
34323 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34324 + ignore_flags, verbose);
34336 + inode_unlock(h_isrc);
34341 +/* ---------------------------------------------------------------------- */
34343 +static int au_smack_reentering(struct super_block *sb)
34345 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
34347 + * as a part of lookup, smack_d_instantiate() is called, and it calls
34348 + * i_op->getxattr(). ouch.
34350 + return si_pid_test(sb);
34361 +struct au_lgxattr {
34369 + const char *name;
34376 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34380 + struct path h_path;
34381 + struct super_block *sb;
34383 + sb = dentry->d_sb;
34384 + reenter = au_smack_reentering(sb);
34386 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34387 + if (unlikely(err))
34390 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
34391 + if (unlikely(err))
34393 + if (unlikely(!h_path.dentry))
34394 + /* illegally overlapped or something */
34395 + goto out_di; /* pretending success */
34397 + /* always topmost entry only */
34398 + switch (arg->type) {
34399 + case AU_XATTR_LIST:
34400 + err = vfs_listxattr(h_path.dentry,
34401 + arg->u.list.list, arg->u.list.size);
34403 + case AU_XATTR_GET:
34404 + AuDebugOn(d_is_negative(h_path.dentry));
34405 + err = vfs_getxattr(h_path.dentry,
34406 + arg->u.get.name, arg->u.get.value,
34407 + arg->u.get.size);
34413 + di_read_unlock(dentry, AuLock_IR);
34416 + si_read_unlock(sb);
34422 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34424 + struct au_lgxattr arg = {
34425 + .type = AU_XATTR_LIST,
34432 + return au_lgxattr(dentry, &arg);
34435 +static ssize_t au_getxattr(struct dentry *dentry,
34436 + struct inode *inode __maybe_unused,
34437 + const char *name, void *value, size_t size)
34439 + struct au_lgxattr arg = {
34440 + .type = AU_XATTR_GET,
34448 + return au_lgxattr(dentry, &arg);
34451 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34452 + const char *name, const void *value, size_t size,
34455 + struct au_sxattr arg = {
34456 + .type = AU_XATTR_SET,
34465 + return au_sxattr(dentry, inode, &arg);
34468 +/* ---------------------------------------------------------------------- */
34470 +static int au_xattr_get(const struct xattr_handler *handler,
34471 + struct dentry *dentry, struct inode *inode,
34472 + const char *name, void *buffer, size_t size)
34474 + return au_getxattr(dentry, inode, name, buffer, size);
34477 +static int au_xattr_set(const struct xattr_handler *handler,
34478 + struct dentry *dentry, struct inode *inode,
34479 + const char *name, const void *value, size_t size,
34482 + return au_setxattr(dentry, inode, name, value, size, flags);
34485 +static const struct xattr_handler au_xattr_handler = {
34488 + .get = au_xattr_get,
34489 + .set = au_xattr_set
34492 +static const struct xattr_handler *au_xattr_handlers[] = {
34493 +#ifdef CONFIG_FS_POSIX_ACL
34494 + &posix_acl_access_xattr_handler,
34495 + &posix_acl_default_xattr_handler,
34497 + &au_xattr_handler, /* must be last */
34501 +void au_xattr_init(struct super_block *sb)
34503 + sb->s_xattr = au_xattr_handlers;
34505 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34506 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34507 +++ linux/fs/aufs/xino.c 2017-07-29 12:14:25.906375514 +0200
34510 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34512 + * This program, aufs is free software; you can redistribute it and/or modify
34513 + * it under the terms of the GNU General Public License as published by
34514 + * the Free Software Foundation; either version 2 of the License, or
34515 + * (at your option) any later version.
34517 + * This program is distributed in the hope that it will be useful,
34518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34520 + * GNU General Public License for more details.
34522 + * You should have received a copy of the GNU General Public License
34523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34527 + * external inode number translation table and bitmap
34530 +#include <linux/seq_file.h>
34531 +#include <linux/statfs.h>
34534 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34535 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34539 + mm_segment_t oldfs;
34546 + oldfs = get_fs();
34547 + set_fs(KERNEL_DS);
34549 + /* todo: signal_pending? */
34550 + err = func(file, buf.u, size, pos);
34551 + } while (err == -EAGAIN || err == -EINTR);
34554 +#if 0 /* reserved for future use */
34556 + fsnotify_access(file->f_path.dentry);
34562 +/* ---------------------------------------------------------------------- */
34564 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34565 + size_t size, loff_t *pos);
34567 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34568 + size_t size, loff_t *pos)
34571 + mm_segment_t oldfs;
34574 + const char __user *u;
34577 + const int prevent_endless = 10;
34581 + oldfs = get_fs();
34582 + set_fs(KERNEL_DS);
34584 + err = func(file, buf.u, size, pos);
34585 + if (err == -EINTR
34586 + && !au_wkq_test()
34587 + && fatal_signal_pending(current)) {
34589 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34590 + BUG_ON(err == -EINTR);
34591 + oldfs = get_fs();
34592 + set_fs(KERNEL_DS);
34594 + } while (i++ < prevent_endless
34595 + && (err == -EAGAIN || err == -EINTR));
34598 +#if 0 /* reserved for future use */
34600 + fsnotify_modify(file->f_path.dentry);
34606 +struct do_xino_fwrite_args {
34608 + vfs_writef_t func;
34609 + struct file *file;
34615 +static void call_do_xino_fwrite(void *args)
34617 + struct do_xino_fwrite_args *a = args;
34618 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34621 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34622 + size_t size, loff_t *pos)
34626 + struct do_xino_fwrite_args args = {
34636 + * it breaks RLIMIT_FSIZE and normal user's limit,
34637 + * users should care about quota and real 'filesystem full.'
34639 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34640 + if (unlikely(wkq_err))
34646 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34647 + size_t size, loff_t *pos)
34651 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34653 + err = do_xino_fwrite(func, file, buf, size, pos);
34656 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34661 +/* ---------------------------------------------------------------------- */
34664 + * create a new xinofile at the same place/path as @base_file.
34666 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34668 + struct file *file;
34669 + struct dentry *base, *parent;
34670 + struct inode *dir, *delegated;
34671 + struct qstr *name;
34672 + struct path path;
34675 + base = base_file->f_path.dentry;
34676 + parent = base->d_parent; /* dir inode is locked */
34677 + dir = d_inode(parent);
34680 + file = ERR_PTR(-EINVAL);
34681 + name = &base->d_name;
34682 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34683 + if (IS_ERR(path.dentry)) {
34684 + file = (void *)path.dentry;
34685 + pr_err("%pd lookup err %ld\n",
34686 + base, PTR_ERR(path.dentry));
34690 + /* no need to mnt_want_write() since we call dentry_open() later */
34691 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34692 + if (unlikely(err)) {
34693 + file = ERR_PTR(err);
34694 + pr_err("%pd create err %d\n", base, err);
34698 + path.mnt = base_file->f_path.mnt;
34699 + file = vfsub_dentry_open(&path,
34700 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34701 + /* | __FMODE_NONOTIFY */);
34702 + if (IS_ERR(file)) {
34703 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34707 + delegated = NULL;
34708 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34709 + if (unlikely(err == -EWOULDBLOCK)) {
34710 + pr_warn("cannot retry for NFSv4 delegation"
34711 + " for an internal unlink\n");
34714 + if (unlikely(err)) {
34715 + pr_err("%pd unlink err %d\n", base, err);
34720 + /* no one can touch copy_src xino */
34721 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34722 + if (unlikely(err)) {
34723 + pr_err("%pd copy err %d\n", base, err);
34727 + goto out_dput; /* success */
34731 + file = ERR_PTR(err);
34733 + dput(path.dentry);
34738 +struct au_xino_lock_dir {
34739 + struct au_hinode *hdir;
34740 + struct dentry *parent;
34741 + struct inode *dir;
34744 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34745 + struct au_xino_lock_dir *ldir)
34747 + aufs_bindex_t brid, bindex;
34749 + ldir->hdir = NULL;
34751 + brid = au_xino_brid(sb);
34753 + bindex = au_br_index(sb, brid);
34754 + if (bindex >= 0) {
34755 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34756 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34758 + ldir->parent = dget_parent(xino->f_path.dentry);
34759 + ldir->dir = d_inode(ldir->parent);
34760 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34764 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34767 + au_hn_inode_unlock(ldir->hdir);
34769 + inode_unlock(ldir->dir);
34770 + dput(ldir->parent);
34774 +/* ---------------------------------------------------------------------- */
34776 +/* trucate xino files asynchronously */
34778 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34781 + unsigned long jiffy;
34783 + aufs_bindex_t bi, bbot;
34784 + struct kstatfs *st;
34785 + struct au_branch *br;
34786 + struct file *new_xino, *file;
34787 + struct super_block *h_sb;
34788 + struct au_xino_lock_dir ldir;
34791 + st = kmalloc(sizeof(*st), GFP_NOFS);
34792 + if (unlikely(!st))
34796 + bbot = au_sbbot(sb);
34797 + if (unlikely(bindex < 0 || bbot < bindex))
34799 + br = au_sbr(sb, bindex);
34800 + file = br->br_xino.xi_file;
34804 + err = vfs_statfs(&file->f_path, st);
34805 + if (unlikely(err))
34806 + AuErr1("statfs err %d, ignored\n", err);
34808 + blocks = file_inode(file)->i_blocks;
34809 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34810 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34812 + au_xino_lock_dir(sb, file, &ldir);
34813 + /* mnt_want_write() is unnecessary here */
34814 + new_xino = au_xino_create2(file, file);
34815 + au_xino_unlock_dir(&ldir);
34816 + err = PTR_ERR(new_xino);
34817 + if (IS_ERR(new_xino)) {
34818 + pr_err("err %d, ignored\n", err);
34823 + br->br_xino.xi_file = new_xino;
34825 + h_sb = au_br_sb(br);
34826 + for (bi = 0; bi <= bbot; bi++) {
34827 + if (unlikely(bi == bindex))
34829 + br = au_sbr(sb, bi);
34830 + if (au_br_sb(br) != h_sb)
34833 + fput(br->br_xino.xi_file);
34834 + br->br_xino.xi_file = new_xino;
34835 + get_file(new_xino);
34838 + err = vfs_statfs(&new_xino->f_path, st);
34840 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34841 + bindex, (u64)file_inode(new_xino)->i_blocks,
34842 + st->f_bfree, st->f_blocks);
34843 + if (file_inode(new_xino)->i_blocks < blocks)
34844 + au_sbi(sb)->si_xino_jiffy = jiffy;
34846 + AuErr1("statfs err %d, ignored\n", err);
34854 +struct xino_do_trunc_args {
34855 + struct super_block *sb;
34856 + struct au_branch *br;
34859 +static void xino_do_trunc(void *_args)
34861 + struct xino_do_trunc_args *args = _args;
34862 + struct super_block *sb;
34863 + struct au_branch *br;
34864 + struct inode *dir;
34866 + aufs_bindex_t bindex;
34870 + dir = d_inode(sb->s_root);
34873 + si_noflush_write_lock(sb);
34874 + ii_read_lock_parent(dir);
34875 + bindex = au_br_index(sb, br->br_id);
34876 + err = au_xino_trunc(sb, bindex);
34877 + ii_read_unlock(dir);
34878 + if (unlikely(err))
34879 + pr_warn("err b%d, (%d)\n", bindex, err);
34880 + atomic_dec(&br->br_xino_running);
34882 + si_write_unlock(sb);
34883 + au_nwt_done(&au_sbi(sb)->si_nowait);
34887 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34890 + struct kstatfs st;
34891 + struct au_sbinfo *sbinfo;
34893 + /* todo: si_xino_expire and the ratio should be customizable */
34894 + sbinfo = au_sbi(sb);
34895 + if (time_before(jiffies,
34896 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34899 + /* truncation border */
34900 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34901 + if (unlikely(err)) {
34902 + AuErr1("statfs err %d, ignored\n", err);
34905 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34911 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34913 + struct xino_do_trunc_args *args;
34916 + if (!xino_trunc_test(sb, br))
34919 + if (atomic_inc_return(&br->br_xino_running) > 1)
34922 + /* lock and kfree() will be called in trunc_xino() */
34923 + args = kmalloc(sizeof(*args), GFP_NOFS);
34924 + if (unlikely(!args)) {
34925 + AuErr1("no memory\n");
34932 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34934 + return; /* success */
34936 + pr_err("wkq %d\n", wkq_err);
34941 + atomic_dec(&br->br_xino_running);
34944 +/* ---------------------------------------------------------------------- */
34946 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34947 + ino_t h_ino, ino_t ino)
34953 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34954 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34957 + pos *= sizeof(ino);
34958 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34959 + if (sz == sizeof(ino))
34960 + return 0; /* success */
34962 + AuIOErr("write failed (%zd)\n", sz);
34967 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34968 + * at the position of @h_ino.
34969 + * even if @ino is zero, it is written to the xinofile and means no entry.
34970 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34971 + * try truncating it.
34973 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34977 + unsigned int mnt_flags;
34978 + struct au_branch *br;
34980 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34981 + || ((loff_t)-1) > 0);
34982 + SiMustAnyLock(sb);
34984 + mnt_flags = au_mntflags(sb);
34985 + if (!au_opt_test(mnt_flags, XINO))
34988 + br = au_sbr(sb, bindex);
34989 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34992 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34993 + && au_test_fs_trunc_xino(au_br_sb(br)))
34994 + xino_try_trunc(sb, br);
34995 + return 0; /* success */
34998 + AuIOErr("write failed (%d)\n", err);
35002 +/* ---------------------------------------------------------------------- */
35004 +/* aufs inode number bitmap */
35006 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
35007 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
35011 + AuDebugOn(bit < 0 || page_bits <= bit);
35012 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
35016 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
35018 + AuDebugOn(ino < AUFS_FIRST_INO);
35019 + ino -= AUFS_FIRST_INO;
35020 + *pindex = ino / page_bits;
35021 + *bit = ino % page_bits;
35024 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
35029 + struct au_sbinfo *sbinfo;
35030 + struct file *xib;
35031 + unsigned long *p;
35033 + sbinfo = au_sbi(sb);
35034 + MtxMustLock(&sbinfo->si_xib_mtx);
35035 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
35036 + || !au_opt_test(sbinfo->si_mntflags, XINO));
35038 + if (pindex == sbinfo->si_xib_last_pindex)
35041 + xib = sbinfo->si_xib;
35042 + p = sbinfo->si_xib_buf;
35043 + pos = sbinfo->si_xib_last_pindex;
35044 + pos *= PAGE_SIZE;
35045 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35046 + if (unlikely(sz != PAGE_SIZE))
35050 + pos *= PAGE_SIZE;
35051 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
35052 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
35054 + memset(p, 0, PAGE_SIZE);
35055 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35057 + if (sz == PAGE_SIZE) {
35058 + sbinfo->si_xib_last_pindex = pindex;
35059 + return 0; /* success */
35063 + AuIOErr1("write failed (%zd)\n", sz);
35070 +/* ---------------------------------------------------------------------- */
35072 +static void au_xib_clear_bit(struct inode *inode)
35075 + unsigned long pindex;
35076 + struct super_block *sb;
35077 + struct au_sbinfo *sbinfo;
35079 + AuDebugOn(inode->i_nlink);
35081 + sb = inode->i_sb;
35082 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35083 + AuDebugOn(page_bits <= bit);
35084 + sbinfo = au_sbi(sb);
35085 + mutex_lock(&sbinfo->si_xib_mtx);
35086 + err = xib_pindex(sb, pindex);
35088 + clear_bit(bit, sbinfo->si_xib_buf);
35089 + sbinfo->si_xib_next_bit = bit;
35091 + mutex_unlock(&sbinfo->si_xib_mtx);
35094 +/* for s_op->delete_inode() */
35095 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35098 + unsigned int mnt_flags;
35099 + aufs_bindex_t bindex, bbot, bi;
35100 + unsigned char try_trunc;
35101 + struct au_iinfo *iinfo;
35102 + struct super_block *sb;
35103 + struct au_hinode *hi;
35104 + struct inode *h_inode;
35105 + struct au_branch *br;
35106 + vfs_writef_t xwrite;
35108 + AuDebugOn(au_is_bad_inode(inode));
35110 + sb = inode->i_sb;
35111 + mnt_flags = au_mntflags(sb);
35112 + if (!au_opt_test(mnt_flags, XINO)
35113 + || inode->i_ino == AUFS_ROOT_INO)
35117 + au_xigen_inc(inode);
35118 + au_xib_clear_bit(inode);
35121 + iinfo = au_ii(inode);
35122 + bindex = iinfo->ii_btop;
35126 + xwrite = au_sbi(sb)->si_xwrite;
35127 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35128 + hi = au_hinode(iinfo, bindex);
35129 + bbot = iinfo->ii_bbot;
35130 + for (; bindex <= bbot; bindex++, hi++) {
35131 + h_inode = hi->hi_inode;
35133 + || (!unlinked && h_inode->i_nlink))
35136 + /* inode may not be revalidated */
35137 + bi = au_br_index(sb, hi->hi_id);
35141 + br = au_sbr(sb, bi);
35142 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35143 + h_inode->i_ino, /*ino*/0);
35144 + if (!err && try_trunc
35145 + && au_test_fs_trunc_xino(au_br_sb(br)))
35146 + xino_try_trunc(sb, br);
35150 +/* get an unused inode number from bitmap */
35151 +ino_t au_xino_new_ino(struct super_block *sb)
35154 + unsigned long *p, pindex, ul, pend;
35155 + struct au_sbinfo *sbinfo;
35156 + struct file *file;
35157 + int free_bit, err;
35159 + if (!au_opt_test(au_mntflags(sb), XINO))
35160 + return iunique(sb, AUFS_FIRST_INO);
35162 + sbinfo = au_sbi(sb);
35163 + mutex_lock(&sbinfo->si_xib_mtx);
35164 + p = sbinfo->si_xib_buf;
35165 + free_bit = sbinfo->si_xib_next_bit;
35166 + if (free_bit < page_bits && !test_bit(free_bit, p))
35167 + goto out; /* success */
35168 + free_bit = find_first_zero_bit(p, page_bits);
35169 + if (free_bit < page_bits)
35170 + goto out; /* success */
35172 + pindex = sbinfo->si_xib_last_pindex;
35173 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35174 + err = xib_pindex(sb, ul);
35175 + if (unlikely(err))
35177 + free_bit = find_first_zero_bit(p, page_bits);
35178 + if (free_bit < page_bits)
35179 + goto out; /* success */
35182 + file = sbinfo->si_xib;
35183 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35184 + for (ul = pindex + 1; ul <= pend; ul++) {
35185 + err = xib_pindex(sb, ul);
35186 + if (unlikely(err))
35188 + free_bit = find_first_zero_bit(p, page_bits);
35189 + if (free_bit < page_bits)
35190 + goto out; /* success */
35195 + set_bit(free_bit, p);
35196 + sbinfo->si_xib_next_bit = free_bit + 1;
35197 + pindex = sbinfo->si_xib_last_pindex;
35198 + mutex_unlock(&sbinfo->si_xib_mtx);
35199 + ino = xib_calc_ino(pindex, free_bit);
35200 + AuDbg("i%lu\n", (unsigned long)ino);
35203 + mutex_unlock(&sbinfo->si_xib_mtx);
35209 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35210 + * at the position of @h_ino.
35211 + * if @ino does not exist and @do_new is true, get new one.
35213 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35219 + struct file *file;
35220 + struct au_sbinfo *sbinfo;
35223 + if (!au_opt_test(au_mntflags(sb), XINO))
35224 + return 0; /* no xino */
35227 + sbinfo = au_sbi(sb);
35229 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35230 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35233 + pos *= sizeof(*ino);
35235 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35236 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35237 + return 0; /* no ino */
35239 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35240 + if (sz == sizeof(*ino))
35241 + return 0; /* success */
35244 + if (unlikely(sz >= 0)) {
35246 + AuIOErr("xino read error (%zd)\n", sz);
35252 +/* ---------------------------------------------------------------------- */
35254 +/* create and set a new xino file */
35256 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35258 + struct file *file;
35259 + struct dentry *h_parent, *d;
35260 + struct inode *h_dir, *inode;
35264 + * at mount-time, and the xino file is the default path,
35265 + * hnotify is disabled so we have no notify events to ignore.
35266 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35268 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35269 + /* | __FMODE_NONOTIFY */,
35270 + S_IRUGO | S_IWUGO);
35271 + if (IS_ERR(file)) {
35273 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35277 + /* keep file count */
35279 + inode = file_inode(file);
35280 + h_parent = dget_parent(file->f_path.dentry);
35281 + h_dir = d_inode(h_parent);
35282 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35283 + /* mnt_want_write() is unnecessary here */
35284 + /* no delegation since it is just created */
35285 + if (inode->i_nlink)
35286 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35288 + inode_unlock(h_dir);
35290 + if (unlikely(err)) {
35292 + pr_err("unlink %s(%d)\n", fname, err);
35297 + d = file->f_path.dentry;
35298 + if (unlikely(sb == d->d_sb)) {
35300 + pr_err("%s must be outside\n", fname);
35303 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35305 + pr_err("xino doesn't support %s(%s)\n",
35306 + fname, au_sbtype(d->d_sb));
35309 + return file; /* success */
35313 + file = ERR_PTR(err);
35318 + * find another branch who is on the same filesystem of the specified
35319 + * branch{@btgt}. search until @bbot.
35321 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35322 + aufs_bindex_t bbot)
35324 + aufs_bindex_t bindex;
35325 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35327 + for (bindex = 0; bindex < btgt; bindex++)
35328 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35330 + for (bindex++; bindex <= bbot; bindex++)
35331 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35336 +/* ---------------------------------------------------------------------- */
35339 + * initialize the xinofile for the specified branch @br
35340 + * at the place/path where @base_file indicates.
35341 + * test whether another branch is on the same filesystem or not,
35342 + * if @do_test is true.
35344 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35345 + struct file *base_file, int do_test)
35349 + aufs_bindex_t bbot, bindex;
35350 + struct au_branch *shared_br, *b;
35351 + struct file *file;
35352 + struct super_block *tgt_sb;
35354 + shared_br = NULL;
35355 + bbot = au_sbbot(sb);
35357 + tgt_sb = au_br_sb(br);
35358 + for (bindex = 0; bindex <= bbot; bindex++) {
35359 + b = au_sbr(sb, bindex);
35360 + if (tgt_sb == au_br_sb(b)) {
35367 + if (!shared_br || !shared_br->br_xino.xi_file) {
35368 + struct au_xino_lock_dir ldir;
35370 + au_xino_lock_dir(sb, base_file, &ldir);
35371 + /* mnt_want_write() is unnecessary here */
35372 + file = au_xino_create2(base_file, NULL);
35373 + au_xino_unlock_dir(&ldir);
35374 + err = PTR_ERR(file);
35375 + if (IS_ERR(file))
35377 + br->br_xino.xi_file = file;
35379 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35380 + get_file(br->br_xino.xi_file);
35383 + ino = AUFS_ROOT_INO;
35384 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35386 + if (unlikely(err)) {
35387 + fput(br->br_xino.xi_file);
35388 + br->br_xino.xi_file = NULL;
35395 +/* ---------------------------------------------------------------------- */
35397 +/* trucate a xino bitmap file */
35400 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35404 + unsigned long pindex;
35405 + loff_t pos, pend;
35406 + struct au_sbinfo *sbinfo;
35407 + vfs_readf_t func;
35409 + unsigned long *p;
35412 + sbinfo = au_sbi(sb);
35413 + MtxMustLock(&sbinfo->si_xib_mtx);
35414 + p = sbinfo->si_xib_buf;
35415 + func = sbinfo->si_xread;
35416 + pend = vfsub_f_size_read(file);
35418 + while (pos < pend) {
35419 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35421 + if (unlikely(sz <= 0))
35425 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35426 + if (unlikely(*ino < AUFS_FIRST_INO))
35429 + xib_calc_bit(*ino, &pindex, &bit);
35430 + AuDebugOn(page_bits <= bit);
35431 + err = xib_pindex(sb, pindex);
35443 +static int xib_restore(struct super_block *sb)
35446 + aufs_bindex_t bindex, bbot;
35450 + page = (void *)__get_free_page(GFP_NOFS);
35451 + if (unlikely(!page))
35455 + bbot = au_sbbot(sb);
35456 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35457 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35458 + err = do_xib_restore
35459 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35461 + AuDbg("b%d\n", bindex);
35462 + free_page((unsigned long)page);
35468 +int au_xib_trunc(struct super_block *sb)
35473 + struct au_xino_lock_dir ldir;
35474 + struct au_sbinfo *sbinfo;
35475 + unsigned long *p;
35476 + struct file *file;
35478 + SiMustWriteLock(sb);
35481 + sbinfo = au_sbi(sb);
35482 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35485 + file = sbinfo->si_xib;
35486 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35489 + au_xino_lock_dir(sb, file, &ldir);
35490 + /* mnt_want_write() is unnecessary here */
35491 + file = au_xino_create2(sbinfo->si_xib, NULL);
35492 + au_xino_unlock_dir(&ldir);
35493 + err = PTR_ERR(file);
35494 + if (IS_ERR(file))
35496 + fput(sbinfo->si_xib);
35497 + sbinfo->si_xib = file;
35499 + p = sbinfo->si_xib_buf;
35500 + memset(p, 0, PAGE_SIZE);
35502 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35503 + if (unlikely(sz != PAGE_SIZE)) {
35505 + AuIOErr("err %d\n", err);
35511 + mutex_lock(&sbinfo->si_xib_mtx);
35512 + /* mnt_want_write() is unnecessary here */
35513 + err = xib_restore(sb);
35514 + mutex_unlock(&sbinfo->si_xib_mtx);
35520 +/* ---------------------------------------------------------------------- */
35523 + * xino mount option handlers
35527 +static void xino_clear_xib(struct super_block *sb)
35529 + struct au_sbinfo *sbinfo;
35531 + SiMustWriteLock(sb);
35533 + sbinfo = au_sbi(sb);
35534 + sbinfo->si_xread = NULL;
35535 + sbinfo->si_xwrite = NULL;
35536 + if (sbinfo->si_xib)
35537 + fput(sbinfo->si_xib);
35538 + sbinfo->si_xib = NULL;
35539 + if (sbinfo->si_xib_buf)
35540 + free_page((unsigned long)sbinfo->si_xib_buf);
35541 + sbinfo->si_xib_buf = NULL;
35544 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35548 + struct au_sbinfo *sbinfo;
35549 + struct file *file;
35551 + SiMustWriteLock(sb);
35553 + sbinfo = au_sbi(sb);
35554 + file = au_xino_create2(base, sbinfo->si_xib);
35555 + err = PTR_ERR(file);
35556 + if (IS_ERR(file))
35558 + if (sbinfo->si_xib)
35559 + fput(sbinfo->si_xib);
35560 + sbinfo->si_xib = file;
35561 + sbinfo->si_xread = vfs_readf(file);
35562 + sbinfo->si_xwrite = vfs_writef(file);
35565 + if (!sbinfo->si_xib_buf)
35566 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35567 + if (unlikely(!sbinfo->si_xib_buf))
35570 + sbinfo->si_xib_last_pindex = 0;
35571 + sbinfo->si_xib_next_bit = 0;
35572 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35574 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35575 + PAGE_SIZE, &pos);
35576 + if (unlikely(err != PAGE_SIZE))
35580 + goto out; /* success */
35583 + if (sbinfo->si_xib_buf)
35584 + free_page((unsigned long)sbinfo->si_xib_buf);
35585 + sbinfo->si_xib_buf = NULL;
35589 + fput(sbinfo->si_xib);
35590 + sbinfo->si_xib = NULL;
35591 + sbinfo->si_xread = NULL;
35592 + sbinfo->si_xwrite = NULL;
35597 +/* xino for each branch */
35598 +static void xino_clear_br(struct super_block *sb)
35600 + aufs_bindex_t bindex, bbot;
35601 + struct au_branch *br;
35603 + bbot = au_sbbot(sb);
35604 + for (bindex = 0; bindex <= bbot; bindex++) {
35605 + br = au_sbr(sb, bindex);
35606 + if (!br || !br->br_xino.xi_file)
35609 + fput(br->br_xino.xi_file);
35610 + br->br_xino.xi_file = NULL;
35614 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35618 + aufs_bindex_t bindex, bbot, bshared;
35620 + struct file *old, *new;
35622 + struct au_branch *br;
35623 + struct inode *inode;
35624 + vfs_writef_t writef;
35626 + SiMustWriteLock(sb);
35629 + bbot = au_sbbot(sb);
35630 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35631 + if (unlikely(!fpair))
35634 + inode = d_inode(sb->s_root);
35635 + ino = AUFS_ROOT_INO;
35636 + writef = au_sbi(sb)->si_xwrite;
35637 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35638 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35639 + if (bshared >= 0) {
35640 + /* shared xino */
35641 + *p = fpair[bshared];
35642 + get_file(p->new);
35647 + br = au_sbr(sb, bindex);
35648 + p->old = br->br_xino.xi_file;
35649 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35650 + err = PTR_ERR(p->new);
35651 + if (IS_ERR(p->new)) {
35657 + err = au_xino_do_write(writef, p->new,
35658 + au_h_iptr(inode, bindex)->i_ino, ino);
35659 + if (unlikely(err))
35663 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35664 + br = au_sbr(sb, bindex);
35665 + if (br->br_xino.xi_file)
35666 + fput(br->br_xino.xi_file);
35667 + get_file(p->new);
35668 + br->br_xino.xi_file = p->new;
35672 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35682 +void au_xino_clr(struct super_block *sb)
35684 + struct au_sbinfo *sbinfo;
35686 + au_xigen_clr(sb);
35687 + xino_clear_xib(sb);
35688 + xino_clear_br(sb);
35689 + sbinfo = au_sbi(sb);
35690 + /* lvalue, do not call au_mntflags() */
35691 + au_opt_clr(sbinfo->si_mntflags, XINO);
35694 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35697 + struct dentry *parent, *cur_parent;
35698 + struct qstr *dname, *cur_name;
35699 + struct file *cur_xino;
35700 + struct inode *dir;
35701 + struct au_sbinfo *sbinfo;
35703 + SiMustWriteLock(sb);
35706 + sbinfo = au_sbi(sb);
35707 + parent = dget_parent(xino->file->f_path.dentry);
35710 + dname = &xino->file->f_path.dentry->d_name;
35711 + cur_xino = sbinfo->si_xib;
35713 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35714 + cur_name = &cur_xino->f_path.dentry->d_name;
35715 + skip = (cur_parent == parent
35716 + && au_qstreq(dname, cur_name));
35717 + dput(cur_parent);
35723 + au_opt_set(sbinfo->si_mntflags, XINO);
35724 + dir = d_inode(parent);
35725 + inode_lock_nested(dir, AuLsc_I_PARENT);
35726 + /* mnt_want_write() is unnecessary here */
35727 + err = au_xino_set_xib(sb, xino->file);
35729 + err = au_xigen_set(sb, xino->file);
35731 + err = au_xino_set_br(sb, xino->file);
35732 + inode_unlock(dir);
35734 + goto out; /* success */
35737 + AuIOErr("failed creating xino(%d).\n", err);
35738 + au_xigen_clr(sb);
35739 + xino_clear_xib(sb);
35746 +/* ---------------------------------------------------------------------- */
35749 + * create a xinofile at the default place/path.
35751 +struct file *au_xino_def(struct super_block *sb)
35753 + struct file *file;
35755 + struct au_branch *br;
35756 + struct super_block *h_sb;
35757 + struct path path;
35758 + aufs_bindex_t bbot, bindex, bwr;
35761 + bbot = au_sbbot(sb);
35763 + for (bindex = 0; bindex <= bbot; bindex++) {
35764 + br = au_sbr(sb, bindex);
35765 + if (au_br_writable(br->br_perm)
35766 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35773 + file = ERR_PTR(-ENOMEM);
35774 + page = (void *)__get_free_page(GFP_NOFS);
35775 + if (unlikely(!page))
35777 + path.mnt = au_br_mnt(br);
35778 + path.dentry = au_h_dptr(sb->s_root, bwr);
35779 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35780 + file = (void *)p;
35781 + if (!IS_ERR(p)) {
35782 + strcat(p, "/" AUFS_XINO_FNAME);
35783 + AuDbg("%s\n", p);
35784 + file = au_xino_create(sb, p, /*silent*/0);
35785 + if (!IS_ERR(file))
35786 + au_xino_brid_set(sb, br->br_id);
35788 + free_page((unsigned long)page);
35790 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35791 + if (IS_ERR(file))
35793 + h_sb = file->f_path.dentry->d_sb;
35794 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35795 + pr_err("xino doesn't support %s(%s)\n",
35796 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35798 + file = ERR_PTR(-EINVAL);
35800 + if (!IS_ERR(file))
35801 + au_xino_brid_set(sb, -1);
35808 +/* ---------------------------------------------------------------------- */
35810 +int au_xino_path(struct seq_file *seq, struct file *file)
35814 + err = au_seq_path(seq, &file->f_path);
35815 + if (unlikely(err))
35818 +#define Deleted "\\040(deleted)"
35819 + seq->count -= sizeof(Deleted) - 1;
35820 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35821 + sizeof(Deleted) - 1));
35828 +/* ---------------------------------------------------------------------- */
35830 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
35831 + ino_t h_ino, int idx)
35833 + struct au_xino_file *xino;
35835 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
35836 + xino = &au_sbr(sb, bindex)->br_xino;
35837 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
35839 + spin_lock(&xino->xi_nondir.spin);
35840 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
35841 + xino->xi_nondir.array[idx] = 0;
35842 + spin_unlock(&xino->xi_nondir.spin);
35843 + wake_up_all(&xino->xi_nondir.wqh);
35846 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
35848 + int found, total, i;
35851 + total = xino->xi_nondir.total;
35852 + for (i = 0; i < total; i++) {
35853 + if (xino->xi_nondir.array[i] != h_ino)
35862 +static int au_xinondir_expand(struct au_xino_file *xino)
35867 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
35870 + sz = xino->xi_nondir.total * sizeof(ino_t);
35871 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
35873 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
35874 + /*may_shrink*/0);
35876 + xino->xi_nondir.array = p;
35877 + xino->xi_nondir.total <<= 1;
35878 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
35886 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35889 + int err, found, empty;
35890 + struct au_xino_file *xino;
35894 + if (!au_opt_test(au_mntflags(sb), XINO))
35895 + goto out; /* no xino */
35897 + xino = &au_sbr(sb, bindex)->br_xino;
35900 + spin_lock(&xino->xi_nondir.spin);
35901 + found = au_xinondir_find(xino, h_ino);
35902 + if (found == -1) {
35903 + empty = au_xinondir_find(xino, /*h_ino*/0);
35904 + if (empty == -1) {
35905 + empty = xino->xi_nondir.total;
35906 + err = au_xinondir_expand(xino);
35907 + if (unlikely(err))
35910 + xino->xi_nondir.array[empty] = h_ino;
35913 + spin_unlock(&xino->xi_nondir.spin);
35914 + wait_event(xino->xi_nondir.wqh,
35915 + xino->xi_nondir.array[found] != h_ino);
35920 + spin_unlock(&xino->xi_nondir.spin);
35924 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35925 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35926 +++ linux/include/uapi/linux/aufs_type.h 2017-07-31 10:12:14.139177930 +0200
35929 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35931 + * This program, aufs is free software; you can redistribute it and/or modify
35932 + * it under the terms of the GNU General Public License as published by
35933 + * the Free Software Foundation; either version 2 of the License, or
35934 + * (at your option) any later version.
35936 + * This program is distributed in the hope that it will be useful,
35937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35939 + * GNU General Public License for more details.
35941 + * You should have received a copy of the GNU General Public License
35942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35945 +#ifndef __AUFS_TYPE_H__
35946 +#define __AUFS_TYPE_H__
35948 +#define AUFS_NAME "aufs"
35952 + * define it before including all other headers.
35953 + * sched.h may use pr_* macros before defining "current", so define the
35954 + * no-current version first, and re-define later.
35956 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35957 +#include <linux/sched.h>
35959 +#define pr_fmt(fmt) \
35960 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35961 + (int)sizeof(current->comm), current->comm, current->pid
35963 +#include <stdint.h>
35964 +#include <sys/types.h>
35965 +#endif /* __KERNEL__ */
35967 +#include <linux/limits.h>
35969 +#define AUFS_VERSION "4.11.7+-20170703"
35971 +/* todo? move this to linux-2.6.19/include/magic.h */
35972 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35974 +/* ---------------------------------------------------------------------- */
35976 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35977 +typedef int8_t aufs_bindex_t;
35978 +#define AUFS_BRANCH_MAX 127
35980 +typedef int16_t aufs_bindex_t;
35981 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35982 +#define AUFS_BRANCH_MAX 511
35983 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35984 +#define AUFS_BRANCH_MAX 1023
35985 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35986 +#define AUFS_BRANCH_MAX 32767
35991 +#ifndef AUFS_BRANCH_MAX
35992 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35994 +#endif /* __KERNEL__ */
35996 +/* ---------------------------------------------------------------------- */
35998 +#define AUFS_FSTYPE AUFS_NAME
36000 +#define AUFS_ROOT_INO 2
36001 +#define AUFS_FIRST_INO 11
36003 +#define AUFS_WH_PFX ".wh."
36004 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
36005 +#define AUFS_WH_TMP_LEN 4
36006 +/* a limit for rmdir/rename a dir and copyup */
36007 +#define AUFS_MAX_NAMELEN (NAME_MAX \
36008 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
36010 + - AUFS_WH_TMP_LEN) /* hex */
36011 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
36012 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
36013 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
36014 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
36015 +#define AUFS_DIRWH_DEF 3
36016 +#define AUFS_RDCACHE_DEF 10 /* seconds */
36017 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
36018 +#define AUFS_RDBLK_DEF 512 /* bytes */
36019 +#define AUFS_RDHASH_DEF 32
36020 +#define AUFS_WKQ_NAME AUFS_NAME "d"
36021 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
36022 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
36023 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
36024 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
36026 +/* pseudo-link maintenace under /proc */
36027 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
36028 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
36029 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
36031 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
36032 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
36034 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
36035 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
36036 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
36038 +/* doubly whiteouted */
36039 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
36040 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
36041 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
36043 +/* branch permissions and attributes */
36044 +#define AUFS_BRPERM_RW "rw"
36045 +#define AUFS_BRPERM_RO "ro"
36046 +#define AUFS_BRPERM_RR "rr"
36047 +#define AUFS_BRATTR_COO_REG "coo_reg"
36048 +#define AUFS_BRATTR_COO_ALL "coo_all"
36049 +#define AUFS_BRATTR_FHSM "fhsm"
36050 +#define AUFS_BRATTR_UNPIN "unpin"
36051 +#define AUFS_BRATTR_ICEX "icex"
36052 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
36053 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
36054 +#define AUFS_BRATTR_ICEX_TR "icextr"
36055 +#define AUFS_BRATTR_ICEX_USR "icexusr"
36056 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
36057 +#define AUFS_BRRATTR_WH "wh"
36058 +#define AUFS_BRWATTR_NLWH "nolwh"
36059 +#define AUFS_BRWATTR_MOO "moo"
36061 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
36062 +#define AuBrPerm_RO (1 << 1) /* readonly */
36063 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
36064 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
36066 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
36067 +#define AuBrAttr_COO_ALL (1 << 4)
36068 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
36070 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
36071 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
36072 + branch. meaningless since
36073 + linux-3.18-rc1 */
36075 +/* ignore error in copying XATTR */
36076 +#define AuBrAttr_ICEX_SEC (1 << 7)
36077 +#define AuBrAttr_ICEX_SYS (1 << 8)
36078 +#define AuBrAttr_ICEX_TR (1 << 9)
36079 +#define AuBrAttr_ICEX_USR (1 << 10)
36080 +#define AuBrAttr_ICEX_OTH (1 << 11)
36081 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
36082 + | AuBrAttr_ICEX_SYS \
36083 + | AuBrAttr_ICEX_TR \
36084 + | AuBrAttr_ICEX_USR \
36085 + | AuBrAttr_ICEX_OTH)
36087 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
36088 +#define AuBrRAttr_Mask AuBrRAttr_WH
36090 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
36091 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
36092 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
36094 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
36096 +/* #warning test userspace */
36098 +#ifndef CONFIG_AUFS_FHSM
36099 +#undef AuBrAttr_FHSM
36100 +#define AuBrAttr_FHSM 0
36102 +#ifndef CONFIG_AUFS_XATTR
36103 +#undef AuBrAttr_ICEX
36104 +#define AuBrAttr_ICEX 0
36105 +#undef AuBrAttr_ICEX_SEC
36106 +#define AuBrAttr_ICEX_SEC 0
36107 +#undef AuBrAttr_ICEX_SYS
36108 +#define AuBrAttr_ICEX_SYS 0
36109 +#undef AuBrAttr_ICEX_TR
36110 +#define AuBrAttr_ICEX_TR 0
36111 +#undef AuBrAttr_ICEX_USR
36112 +#define AuBrAttr_ICEX_USR 0
36113 +#undef AuBrAttr_ICEX_OTH
36114 +#define AuBrAttr_ICEX_OTH 0
36118 +/* the longest combination */
36119 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
36120 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
36121 + "+" AUFS_BRATTR_COO_REG \
36122 + "+" AUFS_BRATTR_FHSM \
36123 + "+" AUFS_BRATTR_UNPIN \
36124 + "+" AUFS_BRATTR_ICEX_SEC \
36125 + "+" AUFS_BRATTR_ICEX_SYS \
36126 + "+" AUFS_BRATTR_ICEX_USR \
36127 + "+" AUFS_BRATTR_ICEX_OTH \
36128 + "+" AUFS_BRWATTR_NLWH)
36131 + char a[AuBrPermStrSz];
36132 +} au_br_perm_str_t;
36134 +static inline int au_br_writable(int brperm)
36136 + return brperm & AuBrPerm_RW;
36139 +static inline int au_br_whable(int brperm)
36141 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
36144 +static inline int au_br_wh_linkable(int brperm)
36146 + return !(brperm & AuBrWAttr_NoLinkWH);
36149 +static inline int au_br_cmoo(int brperm)
36151 + return brperm & AuBrAttr_CMOO_Mask;
36154 +static inline int au_br_fhsm(int brperm)
36156 + return brperm & AuBrAttr_FHSM;
36159 +/* ---------------------------------------------------------------------- */
36163 + /* readdir in userspace */
36167 + AuCtl_WBR_FD, /* pathconf wrapper */
36168 + AuCtl_IBUSY, /* busy inode */
36169 + AuCtl_MVDOWN, /* move-down */
36170 + AuCtl_BR, /* info about branches */
36171 + AuCtl_FHSM_FD /* connection for fhsm */
36174 +/* borrowed from linux/include/linux/kernel.h */
36176 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36177 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36180 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36182 +#define __aligned(x) __attribute__((aligned(x)))
36187 +#define __packed __attribute__((packed))
36191 +struct au_rdu_cookie {
36196 + uint32_t generation;
36199 +struct au_rdu_ent {
36208 +static inline int au_rdu_len(int nlen)
36210 + /* include the terminating NULL */
36211 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36212 + sizeof(uint64_t));
36215 +union au_rdu_ent_ul {
36216 + struct au_rdu_ent __user *e;
36228 + uint64_t sz; /* AuCtl_RDU */
36229 + uint64_t nent; /* AuCtl_RDU_INO */
36231 + union au_rdu_ent_ul ent;
36232 + uint16_t verify[AufsCtlRduV_End];
36234 + /* input/output */
36238 + union au_rdu_ent_ul tail;
36239 + /* number of entries which were added in a single call */
36244 + struct au_rdu_cookie cookie;
36247 +/* ---------------------------------------------------------------------- */
36249 +struct aufs_wbr_fd {
36254 +/* ---------------------------------------------------------------------- */
36256 +struct aufs_ibusy {
36257 + uint64_t ino, h_ino;
36261 +/* ---------------------------------------------------------------------- */
36263 +/* error code for move-down */
36264 +/* the actual message strings are implemented in aufs-util.git */
36266 + EAU_MVDOWN_OPAQUE = 1,
36267 + EAU_MVDOWN_WHITEOUT,
36268 + EAU_MVDOWN_UPPER,
36269 + EAU_MVDOWN_BOTTOM,
36270 + EAU_MVDOWN_NOUPPER,
36271 + EAU_MVDOWN_NOLOWERBR,
36275 +/* flags for move-down */
36276 +#define AUFS_MVDOWN_DMSG 1
36277 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36278 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36279 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36280 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36281 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36282 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36283 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36284 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36285 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36286 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36287 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36288 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36290 +/* index for move-down */
36292 + AUFS_MVDOWN_UPPER,
36293 + AUFS_MVDOWN_LOWER,
36294 + AUFS_MVDOWN_NARRAY
36298 + * additional info of move-down
36299 + * number of free blocks and inodes.
36300 + * subset of struct kstatfs, but smaller and always 64bit.
36302 +struct aufs_stfs {
36303 + uint64_t f_blocks;
36304 + uint64_t f_bavail;
36305 + uint64_t f_files;
36306 + uint64_t f_ffree;
36309 +struct aufs_stbr {
36310 + int16_t brid; /* optional input */
36311 + int16_t bindex; /* output */
36312 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36315 +struct aufs_mvdown {
36316 + uint32_t flags; /* input/output */
36317 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36318 + int8_t au_errno; /* output */
36321 +/* ---------------------------------------------------------------------- */
36323 +union aufs_brinfo {
36324 + /* PATH_MAX may differ between kernel-space and user-space */
36325 + char _spacer[4096];
36333 +/* ---------------------------------------------------------------------- */
36335 +#define AuCtlType 'A'
36336 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36337 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36338 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36339 + struct aufs_wbr_fd)
36340 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36341 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36342 + struct aufs_mvdown)
36343 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36344 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36346 +#endif /* __AUFS_TYPE_H__ */
36347 aufs4.11.7+ loopback patch
36349 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36350 index cf39138..29b33b2 100644
36351 --- a/drivers/block/loop.c
36352 +++ b/drivers/block/loop.c
36353 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36356 struct switch_request {
36357 - struct file *file;
36358 + struct file *file, *virt_file;
36359 struct completion wait;
36362 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36363 mapping = file->f_mapping;
36364 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36365 lo->lo_backing_file = file;
36366 + lo->lo_backing_virt_file = p->virt_file;
36367 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36368 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36369 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36370 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36371 * First it needs to flush existing IO, it does this by sending a magic
36372 * BIO down the pipe. The completion of this BIO does the actual switch.
36374 -static int loop_switch(struct loop_device *lo, struct file *file)
36375 +static int loop_switch(struct loop_device *lo, struct file *file,
36376 + struct file *virt_file)
36378 struct switch_request w;
36381 + w.virt_file = virt_file;
36383 /* freeze queue and wait for completion of scheduled requests */
36384 blk_mq_freeze_queue(lo->lo_queue);
36385 @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
36387 static int loop_flush(struct loop_device *lo)
36389 - return loop_switch(lo, NULL);
36390 + return loop_switch(lo, NULL, NULL);
36393 +static struct file *loop_real_file(struct file *file)
36395 + struct file *f = NULL;
36397 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36398 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36402 static void loop_reread_partitions(struct loop_device *lo,
36403 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36406 struct file *file, *old_file;
36407 + struct file *f, *virt_file = NULL, *old_virt_file;
36408 struct inode *inode;
36411 @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36415 + f = loop_real_file(file);
36417 + virt_file = file;
36422 inode = file->f_mapping->host;
36423 old_file = lo->lo_backing_file;
36424 + old_virt_file = lo->lo_backing_virt_file;
36428 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36431 /* and ... switch */
36432 - error = loop_switch(lo, file);
36433 + error = loop_switch(lo, file, virt_file);
36438 + if (old_virt_file)
36439 + fput(old_virt_file);
36440 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36441 loop_reread_partitions(lo, bdev);
36451 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36452 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36453 struct block_device *bdev, unsigned int arg)
36455 - struct file *file, *f;
36456 + struct file *file, *f, *virt_file = NULL;
36457 struct inode *inode;
36458 struct address_space *mapping;
36459 unsigned lo_blocksize;
36460 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36464 + f = loop_real_file(file);
36466 + virt_file = file;
36472 if (lo->lo_state != Lo_unbound)
36473 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36474 lo->lo_device = bdev;
36475 lo->lo_flags = lo_flags;
36476 lo->lo_backing_file = file;
36477 + lo->lo_backing_virt_file = virt_file;
36478 lo->transfer = NULL;
36480 lo->lo_sizelimit = 0;
36481 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36488 /* This is safe: open() is still holding a reference. */
36489 module_put(THIS_MODULE);
36490 @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36491 static int loop_clr_fd(struct loop_device *lo)
36493 struct file *filp = lo->lo_backing_file;
36494 + struct file *virt_filp = lo->lo_backing_virt_file;
36495 gfp_t gfp = lo->old_gfp_mask;
36496 struct block_device *bdev = lo->lo_device;
36498 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
36499 spin_lock_irq(&lo->lo_lock);
36500 lo->lo_state = Lo_rundown;
36501 lo->lo_backing_file = NULL;
36502 + lo->lo_backing_virt_file = NULL;
36503 spin_unlock_irq(&lo->lo_lock);
36505 loop_release_xfer(lo);
36506 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
36507 * bd_mutex which is usually taken before lo_ctl_mutex.
36515 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36516 index fb2237c..c3888c5 100644
36517 --- a/drivers/block/loop.h
36518 +++ b/drivers/block/loop.h
36519 @@ -46,7 +46,7 @@ struct loop_device {
36520 int (*ioctl)(struct loop_device *, int cmd,
36521 unsigned long arg);
36523 - struct file * lo_backing_file;
36524 + struct file * lo_backing_file, *lo_backing_virt_file;
36525 struct block_device *lo_device;
36526 unsigned lo_blocksize;
36528 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36529 index 870717e..ea7fee0 100644
36530 --- a/fs/aufs/f_op.c
36531 +++ b/fs/aufs/f_op.c
36532 @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36533 if (IS_ERR(h_file))
36536 - if (au_test_loopback_kthread()) {
36537 + if (0 && au_test_loopback_kthread()) {
36538 au_warn_loopback(h_file->f_path.dentry->d_sb);
36539 if (file->f_mapping != h_file->f_mapping) {
36540 file->f_mapping = h_file->f_mapping;
36541 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36542 index e35f015..b37f1ae 100644
36543 --- a/fs/aufs/loop.c
36544 +++ b/fs/aufs/loop.c
36545 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36546 symbol_put(loop_backing_file);
36547 kfree(au_warn_loopback_array);
36550 +/* ---------------------------------------------------------------------- */
36552 +/* support the loopback block device insude aufs */
36554 +struct file *aufs_real_loop(struct file *file)
36558 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36559 + fi_read_lock(file);
36560 + f = au_hf_top(file);
36561 + fi_read_unlock(file);
36565 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36566 index e2df495..36e5052 100644
36567 --- a/fs/aufs/loop.h
36568 +++ b/fs/aufs/loop.h
36569 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36571 int au_loopback_init(void);
36572 void au_loopback_fin(void);
36574 +struct file *aufs_real_loop(struct file *file);
36576 +AuStub(struct file *, loop_backing_file, return NULL)
36578 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36579 struct dentry *h_adding)
36580 AuStubInt0(au_test_loopback_kthread, void)
36581 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36583 AuStubInt0(au_loopback_init, void)
36584 AuStubVoid(au_loopback_fin, void)
36586 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36587 #endif /* BLK_DEV_LOOP */
36589 #endif /* __KERNEL__ */
36590 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36591 index 5455fb1..8b9df60 100644
36592 --- a/fs/aufs/super.c
36593 +++ b/fs/aufs/super.c
36594 @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = {
36595 .statfs = aufs_statfs,
36596 .put_super = aufs_put_super,
36597 .sync_fs = aufs_sync_fs,
36598 - .remount_fs = aufs_remount_fs
36599 + .remount_fs = aufs_remount_fs,
36600 +#ifdef CONFIG_AUFS_BDEV_LOOP
36601 + .real_loop = aufs_real_loop
36605 /* ---------------------------------------------------------------------- */
36606 diff --git a/include/linux/fs.h b/include/linux/fs.h
36607 index 433e314..b008398 100644
36608 --- a/include/linux/fs.h
36609 +++ b/include/linux/fs.h
36610 @@ -1810,6 +1810,10 @@ struct super_operations {
36611 struct shrink_control *);
36612 long (*free_cached_objects)(struct super_block *,
36613 struct shrink_control *);
36614 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36616 + struct file *(*real_loop)(struct file *);