1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 7aee6d6..ec92031 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 aufs4.x-rcN base patch
26 diff --git a/MAINTAINERS b/MAINTAINERS
27 index 1c3feff..1a12137 100644
30 @@ -2392,6 +2392,19 @@ F: include/linux/audit.h
31 F: include/uapi/linux/audit.h
34 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
35 +M: "J. R. Okajima" <hooanon05g@gmail.com>
36 +L: linux-unionfs@vger.kernel.org
37 +L: aufs-users@lists.sourceforge.net (members only)
38 +W: http://aufs.sourceforge.net
39 +T: git://github.com/sfjro/aufs4-linux.git
41 +F: Documentation/filesystems/aufs/
42 +F: Documentation/ABI/testing/debugfs-aufs
43 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: include/uapi/linux/aufs_type.h
47 AUXILIARY DISPLAY DRIVERS
48 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
49 W: http://miguelojeda.es/auxdisplay.htm
50 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
51 index f321b96..10707c3 100644
52 --- a/drivers/block/loop.c
53 +++ b/drivers/block/loop.c
54 @@ -700,6 +700,24 @@ static inline int is_loop_device(struct file *file)
55 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
60 + * no get/put for file.
62 +struct file *loop_backing_file(struct super_block *sb)
65 + struct loop_device *l;
68 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
69 + l = sb->s_bdev->bd_disk->private_data;
70 + ret = l->lo_backing_file;
74 +EXPORT_SYMBOL_GPL(loop_backing_file);
76 /* loop sysfs attributes */
78 static ssize_t loop_attr_show(struct device *dev, char *page,
79 diff --git a/fs/dcache.c b/fs/dcache.c
80 index f901413..e3719a5 100644
83 @@ -1197,7 +1197,7 @@ enum d_walk_ret {
85 * The @enter() and @finish() callbacks are called with d_lock held.
87 -static void d_walk(struct dentry *parent, void *data,
88 +void d_walk(struct dentry *parent, void *data,
89 enum d_walk_ret (*enter)(void *, struct dentry *),
90 void (*finish)(void *))
92 diff --git a/fs/fcntl.c b/fs/fcntl.c
93 index 3b01b64..659760e 100644
98 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
100 -static int setfl(int fd, struct file * filp, unsigned long arg)
101 +int setfl(int fd, struct file * filp, unsigned long arg)
103 struct inode * inode = file_inode(filp);
105 @@ -62,6 +62,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
107 if (filp->f_op->check_flags)
108 error = filp->f_op->check_flags(arg);
109 + if (!error && filp->f_op->setfl)
110 + error = filp->f_op->setfl(filp, arg);
114 diff --git a/fs/inode.c b/fs/inode.c
115 index 5037059..73820bf 100644
118 @@ -1641,7 +1641,7 @@ EXPORT_SYMBOL(generic_update_time);
119 * This does the actual work of updating an inodes time or version. Must have
120 * had called mnt_want_write() before calling this.
122 -static int update_time(struct inode *inode, struct timespec *time, int flags)
123 +int update_time(struct inode *inode, struct timespec *time, int flags)
125 int (*update_time)(struct inode *, struct timespec *, int);
127 diff --git a/fs/read_write.c b/fs/read_write.c
128 index 0cc7033..6e542f0 100644
129 --- a/fs/read_write.c
130 +++ b/fs/read_write.c
131 @@ -473,6 +473,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
133 EXPORT_SYMBOL(__vfs_write);
135 +vfs_readf_t vfs_readf(struct file *file)
137 + const struct file_operations *fop = file->f_op;
141 + if (fop->read_iter)
142 + return new_sync_read;
143 + return ERR_PTR(-ENOSYS);
146 +vfs_writef_t vfs_writef(struct file *file)
148 + const struct file_operations *fop = file->f_op;
152 + if (fop->write_iter)
153 + return new_sync_write;
154 + return ERR_PTR(-ENOSYS);
157 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
160 diff --git a/fs/splice.c b/fs/splice.c
161 index ae41201..9753304 100644
164 @@ -853,8 +853,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
166 * Attempt to initiate a splice from pipe to file.
168 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
169 - loff_t *ppos, size_t len, unsigned int flags)
170 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
171 + loff_t *ppos, size_t len, unsigned int flags)
173 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
174 loff_t *, size_t, unsigned int);
175 @@ -870,9 +870,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
177 * Attempt to initiate a splice from a file to a pipe.
179 -static long do_splice_to(struct file *in, loff_t *ppos,
180 - struct pipe_inode_info *pipe, size_t len,
181 - unsigned int flags)
182 +long do_splice_to(struct file *in, loff_t *ppos,
183 + struct pipe_inode_info *pipe, size_t len,
184 + unsigned int flags)
186 ssize_t (*splice_read)(struct file *, loff_t *,
187 struct pipe_inode_info *, size_t, unsigned int);
188 diff --git a/fs/sync.c b/fs/sync.c
189 index 2a54c1f..7a5fa3f 100644
193 * wait == 1 case since in that case write_inode() functions do
194 * sync_dirty_buffer() and thus effectively write one block at a time.
196 -static int __sync_filesystem(struct super_block *sb, int wait)
197 +int __sync_filesystem(struct super_block *sb, int wait)
201 diff --git a/include/linux/file.h b/include/linux/file.h
202 index 61eb82c..e700888 100644
203 --- a/include/linux/file.h
204 +++ b/include/linux/file.h
205 @@ -19,6 +19,7 @@ struct dentry;
207 extern struct file *alloc_file(const struct path *, fmode_t mode,
208 const struct file_operations *fop);
209 +extern struct file *get_empty_filp(void);
211 static inline void fput_light(struct file *file, int fput_needed)
213 diff --git a/include/linux/fs.h b/include/linux/fs.h
214 index cbfe127..9b21bb5 100644
215 --- a/include/linux/fs.h
216 +++ b/include/linux/fs.h
217 @@ -1262,6 +1262,7 @@ extern void fasync_free(struct fasync_struct *);
218 /* can be called from interrupts */
219 extern void kill_fasync(struct fasync_struct **, int, int);
221 +extern int setfl(int fd, struct file * filp, unsigned long arg);
222 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
223 extern int f_setown(struct file *filp, unsigned long arg, int force);
224 extern void f_delown(struct file *filp);
225 @@ -1683,6 +1684,7 @@ struct file_operations {
226 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
227 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
228 int (*check_flags)(int);
229 + int (*setfl)(struct file *, unsigned long);
230 int (*flock) (struct file *, int, struct file_lock *);
231 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
232 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
233 @@ -1753,6 +1755,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
234 struct iovec *fast_pointer,
235 struct iovec **ret_pointer);
237 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
238 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
240 +vfs_readf_t vfs_readf(struct file *file);
241 +vfs_writef_t vfs_writef(struct file *file);
243 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
244 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
245 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
246 @@ -2157,6 +2165,7 @@ extern int current_umask(void);
247 extern void ihold(struct inode * inode);
248 extern void iput(struct inode *);
249 extern int generic_update_time(struct inode *, struct timespec *, int);
250 +extern int update_time(struct inode *, struct timespec *, int);
253 extern struct kobject *fs_kobj;
254 @@ -2437,6 +2446,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
258 +extern int __sync_filesystem(struct super_block *, int);
259 extern int sync_filesystem(struct super_block *);
260 extern const struct file_operations def_blk_fops;
261 extern const struct file_operations def_chr_fops;
262 diff --git a/include/linux/splice.h b/include/linux/splice.h
263 index db42746..12f3a5a 100644
264 --- a/include/linux/splice.h
265 +++ b/include/linux/splice.h
266 @@ -86,4 +86,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
268 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
269 extern const struct pipe_buf_operations default_pipe_buf_ops;
271 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
272 + loff_t *ppos, size_t len, unsigned int flags);
273 +extern long do_splice_to(struct file *in, loff_t *ppos,
274 + struct pipe_inode_info *pipe, size_t len,
275 + unsigned int flags);
277 aufs4.x-rcN mmap patch
279 diff --git a/fs/proc/base.c b/fs/proc/base.c
280 index 719c2e9..a1b7968 100644
283 @@ -1986,7 +1986,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
284 down_read(&mm->mmap_sem);
285 vma = find_exact_vma(mm, vm_start, vm_end);
286 if (vma && vma->vm_file) {
287 - *path = vma->vm_file->f_path;
288 + *path = vma_pr_or_file(vma)->f_path;
292 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
293 index 7563437..7c0dc0f 100644
294 --- a/fs/proc/nommu.c
295 +++ b/fs/proc/nommu.c
296 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
297 file = region->vm_file;
300 - struct inode *inode = file_inode(region->vm_file);
301 + struct inode *inode;
303 + file = vmr_pr_or_file(region);
304 + inode = file_inode(file);
305 dev = inode->i_sb->s_dev;
308 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
309 index fe8f326..b2f7f1a 100644
310 --- a/fs/proc/task_mmu.c
311 +++ b/fs/proc/task_mmu.c
312 @@ -293,7 +293,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
313 const char *name = NULL;
316 - struct inode *inode = file_inode(vma->vm_file);
317 + struct inode *inode;
319 + file = vma_pr_or_file(vma);
320 + inode = file_inode(file);
321 dev = inode->i_sb->s_dev;
323 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
324 @@ -1640,7 +1643,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
325 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
326 struct vm_area_struct *vma = v;
327 struct numa_maps *md = &numa_priv->md;
328 - struct file *file = vma->vm_file;
329 + struct file *file = vma_pr_or_file(vma);
330 struct mm_struct *mm = vma->vm_mm;
331 struct mm_walk walk = {
332 .hugetlb_entry = gather_hugetlb_stats,
333 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
334 index 23266694..58e59b6 100644
335 --- a/fs/proc/task_nommu.c
336 +++ b/fs/proc/task_nommu.c
337 @@ -157,7 +157,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
341 - struct inode *inode = file_inode(vma->vm_file);
342 + struct inode *inode;
344 + file = vma_pr_or_file(vma);
345 + inode = file_inode(file);
346 dev = inode->i_sb->s_dev;
348 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
349 diff --git a/include/linux/mm.h b/include/linux/mm.h
350 index 46b9ac5..62ba1c3 100644
351 --- a/include/linux/mm.h
352 +++ b/include/linux/mm.h
353 @@ -1306,6 +1306,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
357 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
358 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
360 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
361 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
363 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
365 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
367 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
368 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
371 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
372 +extern void vmr_do_fput(struct vm_region *, const char[], int);
374 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
376 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
377 +#endif /* !CONFIG_MMU */
379 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
380 unsigned int gup_flags);
381 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
382 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
383 index 3cadee0..d0142c1 100644
384 --- a/include/linux/mm_types.h
385 +++ b/include/linux/mm_types.h
386 @@ -259,6 +259,7 @@ struct vm_region {
387 unsigned long vm_top; /* region allocated to here */
388 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
389 struct file *vm_file; /* the backing file or NULL */
390 + struct file *vm_prfile; /* the virtual backing file or NULL */
392 int vm_usage; /* region usage count (access under nommu_region_sem) */
393 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
394 @@ -333,6 +334,7 @@ struct vm_area_struct {
395 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
397 struct file * vm_file; /* File we map to (can be NULL). */
398 + struct file *vm_prfile; /* shadow of vm_file */
399 void * vm_private_data; /* was vm_pte (shared mem) */
402 diff --git a/kernel/fork.c b/kernel/fork.c
403 index cbbea27..f0fd8a1 100644
406 @@ -663,7 +663,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
407 struct inode *inode = file_inode(file);
408 struct address_space *mapping = file->f_mapping;
412 if (tmp->vm_flags & VM_DENYWRITE)
413 atomic_dec(&inode->i_writecount);
414 i_mmap_lock_write(mapping);
415 diff --git a/mm/Makefile b/mm/Makefile
416 index 411bd24..e7de927 100644
419 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
420 mm_init.o mmu_context.o percpu.o slab_common.o \
421 compaction.o vmacache.o swap_slots.o \
422 interval_tree.o list_lru.o workingset.o \
424 + prfile.o debug.o $(mmu-y)
428 diff --git a/mm/filemap.c b/mm/filemap.c
429 index 0b41c8c..c5262ff 100644
432 @@ -2543,7 +2543,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf)
433 int ret = VM_FAULT_LOCKED;
435 sb_start_pagefault(inode->i_sb);
436 - file_update_time(vmf->vma->vm_file);
437 + vma_file_update_time(vmf->vma);
439 if (page->mapping != inode->i_mapping) {
441 diff --git a/mm/mmap.c b/mm/mmap.c
442 index f19efcf..7fdd59e 100644
445 @@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
446 if (vma->vm_ops && vma->vm_ops->close)
447 vma->vm_ops->close(vma);
449 - fput(vma->vm_file);
451 mpol_put(vma_policy(vma));
452 kmem_cache_free(vm_area_cachep, vma);
454 @@ -895,7 +895,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
457 uprobe_munmap(next, next->vm_start, next->vm_end);
462 anon_vma_merge(vma, next);
463 @@ -1745,8 +1745,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
471 /* Undo any partial mapping done by a device driver. */
472 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
473 @@ -2568,7 +2568,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
477 - get_file(new->vm_file);
480 if (new->vm_ops && new->vm_ops->open)
481 new->vm_ops->open(new);
482 @@ -2587,7 +2587,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
483 if (new->vm_ops && new->vm_ops->close)
484 new->vm_ops->close(new);
486 - fput(new->vm_file);
488 unlink_anon_vmas(new);
490 mpol_put(vma_policy(new));
491 @@ -2741,7 +2741,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
492 struct vm_area_struct *vma;
493 unsigned long populate = 0;
494 unsigned long ret = -EINVAL;
496 + struct file *file, *prfile;
498 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
499 current->comm, current->pid);
500 @@ -2816,10 +2816,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
504 - file = get_file(vma->vm_file);
506 + file = vma->vm_file;
507 + prfile = vma->vm_prfile;
508 ret = do_mmap_pgoff(vma->vm_file, start, size,
509 prot, flags, pgoff, &populate, NULL);
510 + if (!IS_ERR_VALUE(ret) && file && prfile) {
511 + struct vm_area_struct *new_vma;
513 + new_vma = find_vma(mm, ret);
514 + if (!new_vma->vm_prfile)
515 + new_vma->vm_prfile = prfile;
516 + if (new_vma != vma)
520 + * two fput()s instead of vma_fput(vma),
521 + * coz vma may not be available anymore.
527 up_write(&mm->mmap_sem);
529 @@ -3110,7 +3127,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
530 if (anon_vma_clone(new_vma, vma))
531 goto out_free_mempol;
532 if (new_vma->vm_file)
533 - get_file(new_vma->vm_file);
534 + vma_get_file(new_vma);
535 if (new_vma->vm_ops && new_vma->vm_ops->open)
536 new_vma->vm_ops->open(new_vma);
537 vma_link(mm, new_vma, prev, rb_link, rb_parent);
538 diff --git a/mm/nommu.c b/mm/nommu.c
539 index fc184f5..637ea81 100644
542 @@ -641,7 +641,7 @@ static void __put_nommu_region(struct vm_region *region)
543 up_write(&nommu_region_sem);
546 - fput(region->vm_file);
549 /* IO memory and memory shared directly out of the pagecache
550 * from ramfs/tmpfs mustn't be released here */
551 @@ -799,7 +799,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
552 if (vma->vm_ops && vma->vm_ops->close)
553 vma->vm_ops->close(vma);
555 - fput(vma->vm_file);
557 put_nommu_region(vma->vm_region);
558 kmem_cache_free(vm_area_cachep, vma);
560 @@ -1326,7 +1326,7 @@ unsigned long do_mmap(struct file *file,
561 goto error_just_free;
564 - fput(region->vm_file);
566 kmem_cache_free(vm_region_jar, region);
569 @@ -1401,10 +1401,10 @@ unsigned long do_mmap(struct file *file,
570 up_write(&nommu_region_sem);
573 - fput(region->vm_file);
575 kmem_cache_free(vm_region_jar, region);
577 - fput(vma->vm_file);
579 kmem_cache_free(vm_area_cachep, vma);
582 diff --git a/mm/prfile.c b/mm/prfile.c
584 index 0000000..1ef053b
589 + * Mainly for aufs which mmap(2) different file and wants to print different
590 + * path in /proc/PID/maps.
591 + * Call these functions via macros defined in linux/mm.h.
593 + * See Documentation/filesystems/aufs/design/06mmap.txt
595 + * Copyright (c) 2014-2017 Junjro R. Okajima
596 + * Copyright (c) 2014 Ian Campbell
599 +#include <linux/mm.h>
600 +#include <linux/file.h>
601 +#include <linux/fs.h>
603 +/* #define PRFILE_TRACE */
604 +static inline void prfile_trace(struct file *f, struct file *pr,
605 + const char func[], int line, const char func2[])
609 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
613 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
616 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
618 + prfile_trace(f, pr, func, line, __func__);
619 + file_update_time(f);
621 + file_update_time(pr);
624 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
627 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
629 + prfile_trace(f, pr, func, line, __func__);
630 + return (f && pr) ? pr : f;
633 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
635 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
637 + prfile_trace(f, pr, func, line, __func__);
643 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
645 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
647 + prfile_trace(f, pr, func, line, __func__);
654 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
657 + struct file *f = region->vm_file, *pr = region->vm_prfile;
659 + prfile_trace(f, pr, func, line, __func__);
660 + return (f && pr) ? pr : f;
663 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
665 + struct file *f = region->vm_file, *pr = region->vm_prfile;
667 + prfile_trace(f, pr, func, line, __func__);
672 +#endif /* !CONFIG_MMU */
673 aufs4.x-rcN standalone patch
675 diff --git a/fs/dcache.c b/fs/dcache.c
676 index e3719a5..3203470 100644
679 @@ -1305,6 +1305,7 @@ void d_walk(struct dentry *parent, void *data,
683 +EXPORT_SYMBOL_GPL(d_walk);
686 struct vfsmount *mnt;
687 @@ -2894,6 +2895,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
689 write_sequnlock(&rename_lock);
691 +EXPORT_SYMBOL_GPL(d_exchange);
694 * d_ancestor - search for an ancestor
695 diff --git a/fs/exec.c b/fs/exec.c
696 index 62175cb..f0b6fdd 100644
699 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
700 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
701 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
703 +EXPORT_SYMBOL_GPL(path_noexec);
707 diff --git a/fs/fcntl.c b/fs/fcntl.c
708 index 659760e..5c37087 100644
711 @@ -84,6 +84,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
715 +EXPORT_SYMBOL_GPL(setfl);
717 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
719 diff --git a/fs/file_table.c b/fs/file_table.c
720 index 72e861a..01ae52f 100644
721 --- a/fs/file_table.c
722 +++ b/fs/file_table.c
723 @@ -148,6 +148,7 @@ struct file *get_empty_filp(void)
725 return ERR_PTR(-ENFILE);
727 +EXPORT_SYMBOL_GPL(get_empty_filp);
730 * alloc_file - allocate and initialize a 'struct file'
731 @@ -260,6 +261,7 @@ void flush_delayed_fput(void)
735 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
737 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
739 @@ -302,6 +304,7 @@ void __fput_sync(struct file *file)
743 +EXPORT_SYMBOL_GPL(__fput_sync);
745 void put_filp(struct file *file)
747 @@ -310,6 +313,7 @@ void put_filp(struct file *file)
751 +EXPORT_SYMBOL_GPL(put_filp);
753 void __init files_init(void)
755 diff --git a/fs/inode.c b/fs/inode.c
756 index 73820bf..7db829e 100644
759 @@ -1650,6 +1650,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
761 return update_time(inode, time, flags);
763 +EXPORT_SYMBOL_GPL(update_time);
766 * touch_atime - update the access time
767 diff --git a/fs/namespace.c b/fs/namespace.c
768 index f8893dc..c55d949 100644
771 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
772 mnt_dec_writers(real_mount(mnt));
775 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
778 * mnt_drop_write - give up write access to a mount
779 @@ -1823,6 +1824,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
783 +EXPORT_SYMBOL_GPL(iterate_mounts);
785 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
787 diff --git a/fs/notify/group.c b/fs/notify/group.c
788 index 3235753..14a2d48 100644
789 --- a/fs/notify/group.c
790 +++ b/fs/notify/group.c
792 #include <linux/srcu.h>
793 #include <linux/rculist.h>
794 #include <linux/wait.h>
795 +#include <linux/module.h>
797 #include <linux/fsnotify_backend.h>
798 #include "fsnotify.h"
799 @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
801 atomic_inc(&group->refcnt);
803 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
806 * Drop a reference to a group. Free it if it's through.
807 @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
808 if (atomic_dec_and_test(&group->refcnt))
809 fsnotify_final_destroy_group(group);
811 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
814 * Create a new fsnotify_group and hold a reference for the group returned.
815 @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
819 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
821 int fsnotify_fasync(int fd, struct file *file, int on)
823 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
824 index 9991f88..117042c 100644
825 --- a/fs/notify/mark.c
826 +++ b/fs/notify/mark.c
827 @@ -118,6 +118,7 @@ static bool fsnotify_get_mark_safe(struct fsnotify_mark *mark)
829 return atomic_inc_not_zero(&mark->refcnt);
831 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
833 static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
835 @@ -395,6 +396,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
836 mutex_unlock(&group->mark_mutex);
837 fsnotify_free_mark(mark);
839 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
842 * Sorting function for lists of fsnotify marks.
843 @@ -607,6 +609,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
844 fsnotify_put_mark(mark);
847 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
849 int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
850 struct vfsmount *mnt, int allow_dups)
851 @@ -742,6 +745,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
852 fsnotify_get_group(group);
855 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
858 * Destroy all marks in destroy_list, waits for SRCU period to finish before
859 diff --git a/fs/open.c b/fs/open.c
860 index 35bb784..92e08c5 100644
863 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
864 inode_unlock(dentry->d_inode);
867 +EXPORT_SYMBOL_GPL(do_truncate);
869 long vfs_truncate(const struct path *path, loff_t length)
871 @@ -691,6 +692,7 @@ int open_check_o_direct(struct file *f)
875 +EXPORT_SYMBOL_GPL(open_check_o_direct);
877 static int do_dentry_open(struct file *f,
879 diff --git a/fs/read_write.c b/fs/read_write.c
880 index 6e542f0..c6fa090 100644
881 --- a/fs/read_write.c
882 +++ b/fs/read_write.c
883 @@ -483,6 +483,7 @@ vfs_readf_t vfs_readf(struct file *file)
884 return new_sync_read;
885 return ERR_PTR(-ENOSYS);
887 +EXPORT_SYMBOL_GPL(vfs_readf);
889 vfs_writef_t vfs_writef(struct file *file)
891 @@ -494,6 +495,7 @@ vfs_writef_t vfs_writef(struct file *file)
892 return new_sync_write;
893 return ERR_PTR(-ENOSYS);
895 +EXPORT_SYMBOL_GPL(vfs_writef);
897 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
899 diff --git a/fs/splice.c b/fs/splice.c
900 index 9753304..b38e036 100644
903 @@ -866,6 +866,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
905 return splice_write(pipe, out, ppos, len, flags);
907 +EXPORT_SYMBOL_GPL(do_splice_from);
910 * Attempt to initiate a splice from a file to a pipe.
911 @@ -895,6 +896,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
913 return splice_read(in, ppos, pipe, len, flags);
915 +EXPORT_SYMBOL_GPL(do_splice_to);
918 * splice_direct_to_actor - splices data directly between two non-pipes
919 diff --git a/fs/sync.c b/fs/sync.c
920 index 7a5fa3f..c9b9d46 100644
923 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
924 sb->s_op->sync_fs(sb, wait);
925 return __sync_blockdev(sb->s_bdev, wait);
927 +EXPORT_SYMBOL_GPL(__sync_filesystem);
930 * Write out and wait upon all dirty data associated with this
931 diff --git a/fs/xattr.c b/fs/xattr.c
932 index 464c94b..0234d49 100644
935 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
936 *xattr_value = value;
939 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
942 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
943 diff --git a/kernel/task_work.c b/kernel/task_work.c
944 index d513051..e056d54 100644
945 --- a/kernel/task_work.c
946 +++ b/kernel/task_work.c
947 @@ -119,3 +119,4 @@ void task_work_run(void)
951 +EXPORT_SYMBOL_GPL(task_work_run);
952 diff --git a/security/commoncap.c b/security/commoncap.c
953 index 7abebd7..c079ce4 100644
954 --- a/security/commoncap.c
955 +++ b/security/commoncap.c
956 @@ -1062,12 +1062,14 @@ int cap_mmap_addr(unsigned long addr)
960 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
962 int cap_mmap_file(struct file *file, unsigned long reqprot,
963 unsigned long prot, unsigned long flags)
967 +EXPORT_SYMBOL_GPL(cap_mmap_file);
969 #ifdef CONFIG_SECURITY
971 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
972 index 03c1652..f88c84b 100644
973 --- a/security/device_cgroup.c
974 +++ b/security/device_cgroup.c
976 #include <linux/device_cgroup.h>
977 #include <linux/cgroup.h>
978 #include <linux/ctype.h>
979 +#include <linux/export.h>
980 #include <linux/list.h>
981 #include <linux/uaccess.h>
982 #include <linux/seq_file.h>
983 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
984 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
987 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
989 int devcgroup_inode_mknod(int mode, dev_t dev)
991 diff --git a/security/security.c b/security/security.c
992 index 3013237..342ce8b 100644
993 --- a/security/security.c
994 +++ b/security/security.c
995 @@ -535,6 +535,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
997 return call_int_hook(path_rmdir, 0, dir, dentry);
999 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1001 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1003 @@ -551,6 +552,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1005 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1007 +EXPORT_SYMBOL_GPL(security_path_symlink);
1009 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1010 struct dentry *new_dentry)
1011 @@ -559,6 +561,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1013 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1015 +EXPORT_SYMBOL_GPL(security_path_link);
1017 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1018 const struct path *new_dir, struct dentry *new_dentry,
1019 @@ -586,6 +589,7 @@ int security_path_truncate(const struct path *path)
1021 return call_int_hook(path_truncate, 0, path);
1023 +EXPORT_SYMBOL_GPL(security_path_truncate);
1025 int security_path_chmod(const struct path *path, umode_t mode)
1027 @@ -593,6 +597,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1029 return call_int_hook(path_chmod, 0, path, mode);
1031 +EXPORT_SYMBOL_GPL(security_path_chmod);
1033 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1035 @@ -600,6 +605,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1037 return call_int_hook(path_chown, 0, path, uid, gid);
1039 +EXPORT_SYMBOL_GPL(security_path_chown);
1041 int security_path_chroot(const struct path *path)
1043 @@ -685,6 +691,7 @@ int security_inode_readlink(struct dentry *dentry)
1045 return call_int_hook(inode_readlink, 0, dentry);
1047 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1049 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1051 @@ -700,6 +707,7 @@ int security_inode_permission(struct inode *inode, int mask)
1053 return call_int_hook(inode_permission, 0, inode, mask);
1055 +EXPORT_SYMBOL_GPL(security_inode_permission);
1057 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1059 @@ -871,6 +879,7 @@ int security_file_permission(struct file *file, int mask)
1061 return fsnotify_perm(file, mask);
1063 +EXPORT_SYMBOL_GPL(security_file_permission);
1065 int security_file_alloc(struct file *file)
1067 @@ -930,6 +939,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1069 return ima_file_mmap(file, prot);
1071 +EXPORT_SYMBOL_GPL(security_mmap_file);
1073 int security_mmap_addr(unsigned long addr)
1075 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1076 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1077 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-07-29 12:14:25.893041746 +0200
1079 +What: /debug/aufs/si_<id>/
1081 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1083 + Under /debug/aufs, a directory named si_<id> is created
1084 + per aufs mount, where <id> is a unique id generated
1087 +What: /debug/aufs/si_<id>/plink
1089 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1091 + It has three lines and shows the information about the
1092 + pseudo-link. The first line is a single number
1093 + representing a number of buckets. The second line is a
1094 + number of pseudo-links per buckets (separated by a
1095 + blank). The last line is a single number representing a
1096 + total number of psedo-links.
1097 + When the aufs mount option 'noplink' is specified, it
1098 + will show "1\n0\n0\n".
1100 +What: /debug/aufs/si_<id>/xib
1102 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1104 + It shows the consumed blocks by xib (External Inode Number
1105 + Bitmap), its block size and file size.
1106 + When the aufs mount option 'noxino' is specified, it
1107 + will be empty. About XINO files, see the aufs manual.
1109 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1111 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1113 + It shows the consumed blocks by xino (External Inode Number
1114 + Translation Table), its link count, block size and file
1116 + When the aufs mount option 'noxino' is specified, it
1117 + will be empty. About XINO files, see the aufs manual.
1119 +What: /debug/aufs/si_<id>/xigen
1121 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1123 + It shows the consumed blocks by xigen (External Inode
1124 + Generation Table), its block size and file size.
1125 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1127 + When the aufs mount option 'noxino' is specified, it
1128 + will be empty. About XINO files, see the aufs manual.
1129 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1130 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1131 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1133 +What: /sys/fs/aufs/si_<id>/
1135 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1137 + Under /sys/fs/aufs, a directory named si_<id> is created
1138 + per aufs mount, where <id> is a unique id generated
1141 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1143 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1145 + It shows the abolute path of a member directory (which
1146 + is called branch) in aufs, and its permission.
1148 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1150 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1152 + It shows the id of a member directory (which is called
1155 +What: /sys/fs/aufs/si_<id>/xi_path
1157 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1159 + It shows the abolute path of XINO (External Inode Number
1160 + Bitmap, Translation Table and Generation Table) file
1161 + even if it is the default path.
1162 + When the aufs mount option 'noxino' is specified, it
1163 + will be empty. About XINO files, see the aufs manual.
1164 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1165 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1166 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-09-05 10:42:11.038754821 +0200
1169 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1171 +# This program is free software; you can redistribute it and/or modify
1172 +# it under the terms of the GNU General Public License as published by
1173 +# the Free Software Foundation; either version 2 of the License, or
1174 +# (at your option) any later version.
1176 +# This program is distributed in the hope that it will be useful,
1177 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1178 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1179 +# GNU General Public License for more details.
1181 +# You should have received a copy of the GNU General Public License
1182 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1185 +----------------------------------------
1187 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1188 +1. abbrev. for "advanced multi-layered unification filesystem".
1189 +2. abbrev. for "another unionfs".
1190 +3. abbrev. for "auf das" in German which means "on the" in English.
1191 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1192 + But "Filesystem aufs Filesystem" is hard to understand.
1193 +4. abbrev. for "African Urban Fashion Show".
1195 +AUFS is a filesystem with features:
1196 +- multi layered stackable unification filesystem, the member directory
1197 + is called as a branch.
1198 +- branch permission and attribute, 'readonly', 'real-readonly',
1199 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1201 +- internal "file copy-on-write".
1202 +- logical deletion, whiteout.
1203 +- dynamic branch manipulation, adding, deleting and changing permission.
1204 +- allow bypassing aufs, user's direct branch access.
1205 +- external inode number translation table and bitmap which maintains the
1206 + persistent aufs inode number.
1207 +- seekable directory, including NFS readdir.
1208 +- file mapping, mmap and sharing pages.
1209 +- pseudo-link, hardlink over branches.
1210 +- loopback mounted filesystem as a branch.
1211 +- several policies to select one among multiple writable branches.
1212 +- revert a single systemcall when an error occurs in aufs.
1216 +Multi Layered Stackable Unification Filesystem
1217 +----------------------------------------------------------------------
1218 +Most people already knows what it is.
1219 +It is a filesystem which unifies several directories and provides a
1220 +merged single directory. When users access a file, the access will be
1221 +passed/re-directed/converted (sorry, I am not sure which English word is
1222 +correct) to the real file on the member filesystem. The member
1223 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1224 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1225 +readonly branch is handled by creating 'whiteout' on the upper writable
1228 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1229 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1230 +different approaches to implement the merged-view.
1231 +The former tries putting it into VFS, and the latter implements as a
1232 +separate filesystem.
1233 +(If I misunderstand about these implementations, please let me know and
1234 +I shall correct it. Because it is a long time ago when I read their
1235 +source files last time).
1237 +UnionMount's approach will be able to small, but may be hard to share
1238 +branches between several UnionMount since the whiteout in it is
1239 +implemented in the inode on branch filesystem and always
1240 +shared. According to Bharata's post, readdir does not seems to be
1242 +There are several missing features known in this implementations such as
1243 +- for users, the inode number may change silently. eg. copy-up.
1244 +- link(2) may break by copy-up.
1245 +- read(2) may get an obsoleted filedata (fstat(2) too).
1246 +- fcntl(F_SETLK) may be broken by copy-up.
1247 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1250 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1251 +merged into mainline. This is another implementation of UnionMount as a
1252 +separated filesystem. All the limitations and known problems which
1253 +UnionMount are equally inherited to "overlay" filesystem.
1255 +Unionfs has a longer history. When I started implementing a stackable
1256 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1257 +inode, dentry and file objects and they have an array pointing lower
1258 +same kind objects. After contributing many patches for Unionfs, I
1259 +re-started my project AUFS (Jun 2006).
1261 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1262 +implemented my own ideas, approaches and enhancements and it became
1263 +totally different one.
1265 +Comparing DM snapshot and fs based implementation
1266 +- the number of bytes to be copied between devices is much smaller.
1267 +- the type of filesystem must be one and only.
1268 +- the fs must be writable, no readonly fs, even for the lower original
1269 + device. so the compression fs will not be usable. but if we use
1270 + loopback mount, we may address this issue.
1272 + mount /cdrom/squashfs.img /sq
1273 + losetup /sq/ext2.img
1274 + losetup /somewhere/cow
1275 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1276 +- it will be difficult (or needs more operations) to extract the
1277 + difference between the original device and COW.
1278 +- DM snapshot-merge may help a lot when users try merging. in the
1279 + fs-layer union, users will use rsync(1).
1281 +You may want to read my old paper "Filesystems in LiveCD"
1282 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1285 +Several characters/aspects/persona of aufs
1286 +----------------------------------------------------------------------
1288 +Aufs has several characters, aspects or persona.
1289 +1. a filesystem, callee of VFS helper
1290 +2. sub-VFS, caller of VFS helper for branches
1291 +3. a virtual filesystem which maintains persistent inode number
1292 +4. reader/writer of files on branches such like an application
1294 +1. Callee of VFS Helper
1295 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1296 +unlink(2) from an application reaches sys_unlink() kernel function and
1297 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1298 +calls filesystem specific unlink operation. Actually aufs implements the
1299 +unlink operation but it behaves like a redirector.
1301 +2. Caller of VFS Helper for Branches
1302 +aufs_unlink() passes the unlink request to the branch filesystem as if
1303 +it were called from VFS. So the called unlink operation of the branch
1304 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1305 +every necessary pre/post operation for the branch filesystem.
1306 +- acquire the lock for the parent dir on a branch
1307 +- lookup in a branch
1308 +- revalidate dentry on a branch
1309 +- mnt_want_write() for a branch
1310 +- vfs_unlink() for a branch
1311 +- mnt_drop_write() for a branch
1312 +- release the lock on a branch
1314 +3. Persistent Inode Number
1315 +One of the most important issue for a filesystem is to maintain inode
1316 +numbers. This is particularly important to support exporting a
1317 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1318 +backend block device for its own. But some storage is necessary to
1319 +keep and maintain the inode numbers. It may be a large space and may not
1320 +suit to keep in memory. Aufs rents some space from its first writable
1321 +branch filesystem (by default) and creates file(s) on it. These files
1322 +are created by aufs internally and removed soon (currently) keeping
1324 +Note: Because these files are removed, they are totally gone after
1325 + unmounting aufs. It means the inode numbers are not persistent
1326 + across unmount or reboot. I have a plan to make them really
1327 + persistent which will be important for aufs on NFS server.
1329 +4. Read/Write Files Internally (copy-on-write)
1330 +Because a branch can be readonly, when you write a file on it, aufs will
1331 +"copy-up" it to the upper writable branch internally. And then write the
1332 +originally requested thing to the file. Generally kernel doesn't
1333 +open/read/write file actively. In aufs, even a single write may cause a
1334 +internal "file copy". This behaviour is very similar to cp(1) command.
1336 +Some people may think it is better to pass such work to user space
1337 +helper, instead of doing in kernel space. Actually I am still thinking
1338 +about it. But currently I have implemented it in kernel space.
1339 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1340 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1341 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2017-07-29 12:14:25.893041746 +0200
1344 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1346 +# This program is free software; you can redistribute it and/or modify
1347 +# it under the terms of the GNU General Public License as published by
1348 +# the Free Software Foundation; either version 2 of the License, or
1349 +# (at your option) any later version.
1351 +# This program is distributed in the hope that it will be useful,
1352 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1353 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1354 +# GNU General Public License for more details.
1356 +# You should have received a copy of the GNU General Public License
1357 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1359 +Basic Aufs Internal Structure
1361 +Superblock/Inode/Dentry/File Objects
1362 +----------------------------------------------------------------------
1363 +As like an ordinary filesystem, aufs has its own
1364 +superblock/inode/dentry/file objects. All these objects have a
1365 +dynamically allocated array and store the same kind of pointers to the
1366 +lower filesystem, branch.
1367 +For example, when you build a union with one readwrite branch and one
1368 +readonly, mounted /au, /rw and /ro respectively.
1370 +- /ro/fileA exists but /rw/fileA
1372 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1373 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1374 +- [0] = NULL (because /rw/fileA doesn't exist)
1377 +This style of an array is essentially same to the aufs
1378 +superblock/inode/dentry/file objects.
1380 +Because aufs supports manipulating branches, ie. add/delete/change
1381 +branches dynamically, these objects has its own generation. When
1382 +branches are changed, the generation in aufs superblock is
1383 +incremented. And a generation in other object are compared when it is
1384 +accessed. When a generation in other objects are obsoleted, aufs
1385 +refreshes the internal array.
1389 +----------------------------------------------------------------------
1390 +Additionally aufs superblock has some data for policies to select one
1391 +among multiple writable branches, XIB files, pseudo-links and kobject.
1392 +See below in detail.
1393 +About the policies which supports copy-down a directory, see
1394 +wbr_policy.txt too.
1397 +Branch and XINO(External Inode Number Translation Table)
1398 +----------------------------------------------------------------------
1399 +Every branch has its own xino (external inode number translation table)
1400 +file. The xino file is created and unlinked by aufs internally. When two
1401 +members of a union exist on the same filesystem, they share the single
1403 +The struct of a xino file is simple, just a sequence of aufs inode
1404 +numbers which is indexed by the lower inode number.
1405 +In the above sample, assume the inode number of /ro/fileA is i111 and
1406 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1407 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1409 +When the inode numbers are not contiguous, the xino file will be sparse
1410 +which has a hole in it and doesn't consume as much disk space as it
1411 +might appear. If your branch filesystem consumes disk space for such
1412 +holes, then you should specify 'xino=' option at mounting aufs.
1414 +Aufs has a mount option to free the disk blocks for such holes in XINO
1415 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1416 +meet a problem of disk shortage due to XINO files, then you should try
1417 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1418 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1419 +the holes in XINO files.
1421 +Also a writable branch has three kinds of "whiteout bases". All these
1422 +are existed when the branch is joined to aufs, and their names are
1423 +whiteout-ed doubly, so that users will never see their names in aufs
1425 +1. a regular file which will be hardlinked to all whiteouts.
1426 +2. a directory to store a pseudo-link.
1427 +3. a directory to store an "orphan"-ed file temporary.
1430 + When you remove a file on a readonly branch, aufs handles it as a
1431 + logical deletion and creates a whiteout on the upper writable branch
1432 + as a hardlink of this file in order not to consume inode on the
1435 + See below, Pseudo-link.
1437 + When "fileC" exists on the lower readonly branch only and it is
1438 + opened and removed with its parent dir, and then user writes
1439 + something into it, then aufs copies-up fileC to this
1440 + directory. Because there is no other dir to store fileC. After
1441 + creating a file under this dir, the file is unlinked.
1443 +Because aufs supports manipulating branches, ie. add/delete/change
1444 +dynamically, a branch has its own id. When the branch order changes,
1445 +aufs finds the new index by searching the branch id.
1449 +----------------------------------------------------------------------
1450 +Assume "fileA" exists on the lower readonly branch only and it is
1451 +hardlinked to "fileB" on the branch. When you write something to fileA,
1452 +aufs copies-up it to the upper writable branch. Additionally aufs
1453 +creates a hardlink under the Pseudo-link Directory of the writable
1454 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1455 +simple list. If fileB is read after unlinking fileA, aufs returns
1456 +filedata from the pseudo-link instead of the lower readonly
1457 +branch. Because the pseudo-link is based upon the inode, to keep the
1458 +inode number by xino (see above) is essentially necessary.
1460 +All the hardlinks under the Pseudo-link Directory of the writable branch
1461 +should be restored in a proper location later. Aufs provides a utility
1462 +to do this. The userspace helpers executed at remounting and unmounting
1464 +During this utility is running, it puts aufs into the pseudo-link
1465 +maintenance mode. In this mode, only the process which began the
1466 +maintenance mode (and its child processes) is allowed to operate in
1467 +aufs. Some other processes which are not related to the pseudo-link will
1468 +be allowed to run too, but the rest have to return an error or wait
1469 +until the maintenance mode ends. If a process already acquires an inode
1470 +mutex (in VFS), it has to return an error.
1473 +XIB(external inode number bitmap)
1474 +----------------------------------------------------------------------
1475 +Addition to the xino file per a branch, aufs has an external inode number
1476 +bitmap in a superblock object. It is also an internal file such like a
1478 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1480 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1482 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1483 +reduce the number of consumed disk blocks for these files.
1486 +Virtual or Vertical Dir, and Readdir in Userspace
1487 +----------------------------------------------------------------------
1488 +In order to support multiple layers (branches), aufs readdir operation
1489 +constructs a virtual dir block on memory. For readdir, aufs calls
1490 +vfs_readdir() internally for each dir on branches, merges their entries
1491 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1492 +object. So the file object has its entry list until it is closed. The
1493 +entry list will be updated when the file position is zero and becomes
1494 +obsoleted. This decision is made in aufs automatically.
1496 +The dynamically allocated memory block for the name of entries has a
1497 +unit of 512 bytes (by default) and stores the names contiguously (no
1498 +padding). Another block for each entry is handled by kmem_cache too.
1499 +During building dir blocks, aufs creates hash list and judging whether
1500 +the entry is whiteouted by its upper branch or already listed.
1501 +The merged result is cached in the corresponding inode object and
1502 +maintained by a customizable life-time option.
1504 +Some people may call it can be a security hole or invite DoS attack
1505 +since the opened and once readdir-ed dir (file object) holds its entry
1506 +list and becomes a pressure for system memory. But I'd say it is similar
1507 +to files under /proc or /sys. The virtual files in them also holds a
1508 +memory page (generally) while they are opened. When an idea to reduce
1509 +memory for them is introduced, it will be applied to aufs too.
1510 +For those who really hate this situation, I've developed readdir(3)
1511 +library which operates this merging in userspace. You just need to set
1512 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1513 +kernel space for readdir(3).
1517 +----------------------------------------------------------------------
1518 +Aufs sometimes requires privilege access to a branch. For instance,
1519 +in copy-up/down operation. When a user process is going to make changes
1520 +to a file which exists in the lower readonly branch only, and the mode
1521 +of one of ancestor directories may not be writable by a user
1522 +process. Here aufs copy-up the file with its ancestors and they may
1523 +require privilege to set its owner/group/mode/etc.
1524 +This is a typical case of a application character of aufs (see
1527 +Aufs uses workqueue synchronously for this case. It creates its own
1528 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1529 +passes the request to call mkdir or write (for example), and wait for
1530 +its completion. This approach solves a problem of a signal handler
1532 +If aufs didn't adopt the workqueue and changed the privilege of the
1533 +process, then the process may receive the unexpected SIGXFSZ or other
1536 +Also aufs uses the system global workqueue ("events" kernel thread) too
1537 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1538 +whiteout base and etc. This is unrelated to a privilege.
1539 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1540 +superblock at the beginning, at the same time waits for the completion
1541 +of all queued asynchronous tasks.
1545 +----------------------------------------------------------------------
1546 +The whiteout in aufs is very similar to Unionfs's. That is represented
1547 +by its filename. UnionMount takes an approach of a file mode, but I am
1548 +afraid several utilities (find(1) or something) will have to support it.
1550 +Basically the whiteout represents "logical deletion" which stops aufs to
1551 +lookup further, but also it represents "dir is opaque" which also stop
1554 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1555 +In order to make several functions in a single systemcall to be
1556 +revertible, aufs adopts an approach to rename a directory to a temporary
1557 +unique whiteouted name.
1558 +For example, in rename(2) dir where the target dir already existed, aufs
1559 +renames the target dir to a temporary unique whiteouted name before the
1560 +actual rename on a branch, and then handles other actions (make it opaque,
1561 +update the attributes, etc). If an error happens in these actions, aufs
1562 +simply renames the whiteouted name back and returns an error. If all are
1563 +succeeded, aufs registers a function to remove the whiteouted unique
1564 +temporary name completely and asynchronously to the system global
1569 +----------------------------------------------------------------------
1570 +It is a well-known feature or concept.
1571 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1572 +internally and makes change to the new file on the upper writable branch.
1573 +When the trigger systemcall does not update the timestamps of the parent
1574 +dir, aufs reverts it after copy-up.
1577 +Move-down (aufs3.9 and later)
1578 +----------------------------------------------------------------------
1579 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1580 +the lower readonly branch to the upper writable branch when a user
1581 +changes something about the file.
1582 +"Move-down" is an opposite action of copy-up. Basically this action is
1583 +ran manually instead of automatically and internally.
1584 +For desgin and implementation, aufs has to consider these issues.
1585 +- whiteout for the file may exist on the lower branch.
1586 +- ancestor directories may not exist on the lower branch.
1587 +- diropq for the ancestor directories may exist on the upper branch.
1588 +- free space on the lower branch will reduce.
1589 +- another access to the file may happen during moving-down, including
1590 + UDBA (see "Revalidate Dentry and UDBA").
1591 +- the file should not be hard-linked nor pseudo-linked. they should be
1592 + handled by auplink utility later.
1594 +Sometimes users want to move-down a file from the upper writable branch
1595 +to the lower readonly or writable branch. For instance,
1596 +- the free space of the upper writable branch is going to run out.
1597 +- create a new intermediate branch between the upper and lower branch.
1600 +For this purpose, use "aumvdown" command in aufs-util.git.
1601 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1602 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1603 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2017-07-29 12:14:25.893041746 +0200
1606 +# Copyright (C) 2015-2017 Junjiro R. Okajima
1608 +# This program is free software; you can redistribute it and/or modify
1609 +# it under the terms of the GNU General Public License as published by
1610 +# the Free Software Foundation; either version 2 of the License, or
1611 +# (at your option) any later version.
1613 +# This program is distributed in the hope that it will be useful,
1614 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1615 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616 +# GNU General Public License for more details.
1618 +# You should have received a copy of the GNU General Public License
1619 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1621 +Support for a branch who has its ->atomic_open()
1622 +----------------------------------------------------------------------
1623 +The filesystems who implement its ->atomic_open() are not majority. For
1624 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1625 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1626 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1627 +sure whether all filesystems who have ->atomic_open() behave like this,
1628 +but NFSv4 surely returns the error.
1630 +In order to support ->atomic_open() for aufs, there are a few
1633 +A. Introduce aufs_atomic_open()
1634 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1636 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1637 + an aufs user Pip Cet's approach
1638 + - calls aufs_create(), VFS finish_open() and notify_change().
1639 + - pass fake-mode to finish_open(), and then correct the mode by
1641 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1642 + - no aufs_atomic_open().
1643 + - aufs_lookup() registers the TID to an aufs internal object.
1644 + - aufs_create() does nothing when the matching TID is registered, but
1645 + registers the mode.
1646 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1647 + TID is registered.
1648 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1650 + - no aufs_atomic_open().
1651 + - aufs_create() registers the TID to an internal object. this info
1652 + represents "this process created this file just now."
1653 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1654 + registered TID and re-try open() with superuser's credential.
1656 +Pros and cons for each approach.
1659 + - straightforward but highly depends upon VFS internal.
1660 + - the atomic behavaiour is kept.
1661 + - some of parameters such as nameidata are hard to reproduce for
1665 + - easy to implement.
1666 + - the atomic behavaiour is lost.
1668 + - the atomic behavaiour is kept.
1669 + - dirty and tricky.
1670 + - VFS checks whether the file is created correctly after calling
1671 + ->create(), which means this approach doesn't work.
1673 + - easy to implement.
1674 + - the atomic behavaiour is lost.
1675 + - to open a file with superuser's credential and give it to a user
1676 + process is a bad idea, since the file object keeps the credential
1677 + in it. It may affect LSM or something. This approach doesn't work
1680 +The approach A is ideal, but it hard to implement. So here is a
1681 +variation of A, which is to be implemented.
1683 +A-1. Introduce aufs_atomic_open()
1684 + - calls branch fs ->atomic_open() if exists. otherwise calls
1685 + vfs_create() and finish_open().
1686 + - the demerit is that the several checks after branch fs
1687 + ->atomic_open() are lost. in the ordinary case, the checks are
1688 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1689 + be implemented in aufs, but not all I am afraid.
1690 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1691 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1692 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2017-07-29 12:14:25.893041746 +0200
1695 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1697 +# This program is free software; you can redistribute it and/or modify
1698 +# it under the terms of the GNU General Public License as published by
1699 +# the Free Software Foundation; either version 2 of the License, or
1700 +# (at your option) any later version.
1702 +# This program is distributed in the hope that it will be useful,
1703 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1704 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1705 +# GNU General Public License for more details.
1707 +# You should have received a copy of the GNU General Public License
1708 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1711 +----------------------------------------------------------------------
1712 +Since aufs has a character of sub-VFS (see Introduction), it operates
1713 +lookup for branches as VFS does. It may be a heavy work. But almost all
1714 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1715 +directly connected to its parent. Digging down the directory hierarchy
1716 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1719 +When a branch is a remote filesystem, aufs basically relies upon its
1720 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1722 +For d_revalidate, aufs implements three levels of revalidate tests. See
1723 +"Revalidate Dentry and UDBA" in detail.
1726 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1727 +----------------------------------------------------------------------
1728 +Let's try case study.
1729 +- aufs has two branches, upper readwrite and lower readonly.
1731 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1732 +- user invoked "chmod a+rx /au/dirA"
1733 +- the internal copy-up is activated and "/rw/dirA" is created and its
1734 + permission bits are set to world readable.
1735 +- then "/au/dirA" becomes world readable?
1737 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1738 +or it may be a natively readonly filesystem. If aufs respects the lower
1739 +branch, it should not respond readdir request from other users. But user
1740 +allowed it by chmod. Should really aufs rejects showing the entries
1743 +To be honest, I don't have a good solution for this case. So aufs
1744 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1746 +When dirperm1 is specified, aufs checks only the highest one for the
1747 +directory permission, and shows the entries. Otherwise, as usual, checks
1748 +every dir existing on all branches and rejects the request.
1750 +As a side effect, dirperm1 option improves the performance of aufs
1751 +because the number of permission check is reduced when the number of
1755 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1756 +----------------------------------------------------------------------
1757 +Generally VFS helpers re-validate a dentry as a part of lookup.
1758 +0. digging down the directory hierarchy.
1759 +1. lock the parent dir by its i_mutex.
1760 +2. lookup the final (child) entry.
1762 +4. call the actual operation (create, unlink, etc.)
1763 +5. unlock the parent dir
1765 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1766 +called. Actually aufs implements it and checks the dentry on a branch is
1768 +But it is not enough. Because aufs has to release the lock for the
1769 +parent dir on a branch at the end of ->lookup() (step 2) and
1770 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1772 +If the file on a branch is changed directly, eg. bypassing aufs, after
1773 +aufs released the lock, then the subsequent operation may cause
1774 +something unpleasant result.
1776 +This situation is a result of VFS architecture, ->lookup() and
1777 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1778 +design from VFS's point of view. It is just not suitable for sub-VFS
1781 +Aufs supports such case by three level of revalidation which is
1782 +selectable by user.
1783 +1. Simple Revalidate
1784 + Addition to the native flow in VFS's, confirm the child-parent
1785 + relationship on the branch just after locking the parent dir on the
1786 + branch in the "actual operation" (step 4). When this validation
1787 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1788 + checks the validation of the dentry on branches.
1789 +2. Monitor Changes Internally by Inotify/Fsnotify
1790 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1791 + the dentry on the branch, and returns EBUSY if it finds different
1793 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1794 + during it is in cache. When the event is notified, aufs registers a
1795 + function to kernel 'events' thread by schedule_work(). And the
1796 + function sets some special status to the cached aufs dentry and inode
1797 + private data. If they are not cached, then aufs has nothing to
1798 + do. When the same file is accessed through aufs (step 0-3) later,
1799 + aufs will detect the status and refresh all necessary data.
1800 + In this mode, aufs has to ignore the event which is fired by aufs
1802 +3. No Extra Validation
1803 + This is the simplest test and doesn't add any additional revalidation
1804 + test, and skip the revalidation in step 4. It is useful and improves
1805 + aufs performance when system surely hide the aufs branches from user,
1806 + by over-mounting something (or another method).
1807 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1808 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1809 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2017-07-29 12:14:25.893041746 +0200
1812 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1814 +# This program is free software; you can redistribute it and/or modify
1815 +# it under the terms of the GNU General Public License as published by
1816 +# the Free Software Foundation; either version 2 of the License, or
1817 +# (at your option) any later version.
1819 +# This program is distributed in the hope that it will be useful,
1820 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1821 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1822 +# GNU General Public License for more details.
1824 +# You should have received a copy of the GNU General Public License
1825 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1827 +Branch Manipulation
1829 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1830 +and changing its permission/attribute, there are a lot of works to do.
1834 +----------------------------------------------------------------------
1835 +o Confirm the adding dir exists outside of aufs, including loopback
1836 + mount, and its various attributes.
1837 +o Initialize the xino file and whiteout bases if necessary.
1840 +o Check the owner/group/mode of the directory
1841 + When the owner/group/mode of the adding directory differs from the
1842 + existing branch, aufs issues a warning because it may impose a
1844 + For example, when a upper writable branch has a world writable empty
1845 + top directory, a malicious user can create any files on the writable
1846 + branch directly, like copy-up and modify manually. If something like
1847 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1848 + writable branch, and the writable branch is world-writable, then a
1849 + malicious guy may create /etc/passwd on the writable branch directly
1850 + and the infected file will be valid in aufs.
1851 + I am afraid it can be a security issue, but aufs can do nothing except
1852 + producing a warning.
1856 +----------------------------------------------------------------------
1857 +o Confirm the deleting branch is not busy
1858 + To be general, there is one merit to adopt "remount" interface to
1859 + manipulate branches. It is to discard caches. At deleting a branch,
1860 + aufs checks the still cached (and connected) dentries and inodes. If
1861 + there are any, then they are all in-use. An inode without its
1862 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1864 + For the cached one, aufs checks whether the same named entry exists on
1866 + If the cached one is a directory, because aufs provides a merged view
1867 + to users, as long as one dir is left on any branch aufs can show the
1868 + dir to users. In this case, the branch can be removed from aufs.
1869 + Otherwise aufs rejects deleting the branch.
1871 + If any file on the deleting branch is opened by aufs, then aufs
1875 +Modify the Permission of a Branch
1876 +----------------------------------------------------------------------
1877 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1880 +o rw --> ro: Confirm the modifying branch is not busy
1881 + Aufs rejects the request if any of these conditions are true.
1882 + - a file on the branch is mmap-ed.
1883 + - a regular file on the branch is opened for write and there is no
1884 + same named entry on the upper branch.
1885 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1886 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1887 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2017-07-29 12:14:25.893041746 +0200
1890 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1892 +# This program is free software; you can redistribute it and/or modify
1893 +# it under the terms of the GNU General Public License as published by
1894 +# the Free Software Foundation; either version 2 of the License, or
1895 +# (at your option) any later version.
1897 +# This program is distributed in the hope that it will be useful,
1898 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1899 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1900 +# GNU General Public License for more details.
1902 +# You should have received a copy of the GNU General Public License
1903 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1905 +Policies to Select One among Multiple Writable Branches
1906 +----------------------------------------------------------------------
1907 +When the number of writable branch is more than one, aufs has to decide
1908 +the target branch for file creation or copy-up. By default, the highest
1909 +writable branch which has the parent (or ancestor) dir of the target
1910 +file is chosen (top-down-parent policy).
1911 +By user's request, aufs implements some other policies to select the
1912 +writable branch, for file creation several policies, round-robin,
1913 +most-free-space, and other policies. For copy-up, top-down-parent,
1914 +bottom-up-parent, bottom-up and others.
1916 +As expected, the round-robin policy selects the branch in circular. When
1917 +you have two writable branches and creates 10 new files, 5 files will be
1918 +created for each branch. mkdir(2) systemcall is an exception. When you
1919 +create 10 new directories, all will be created on the same branch.
1920 +And the most-free-space policy selects the one which has most free
1921 +space among the writable branches. The amount of free space will be
1922 +checked by aufs internally, and users can specify its time interval.
1924 +The policies for copy-up is more simple,
1925 +top-down-parent is equivalent to the same named on in create policy,
1926 +bottom-up-parent selects the writable branch where the parent dir
1927 +exists and the nearest upper one from the copyup-source,
1928 +bottom-up selects the nearest upper writable branch from the
1929 +copyup-source, regardless the existence of the parent dir.
1931 +There are some rules or exceptions to apply these policies.
1932 +- If there is a readonly branch above the policy-selected branch and
1933 + the parent dir is marked as opaque (a variation of whiteout), or the
1934 + target (creating) file is whiteout-ed on the upper readonly branch,
1935 + then the result of the policy is ignored and the target file will be
1936 + created on the nearest upper writable branch than the readonly branch.
1937 +- If there is a writable branch above the policy-selected branch and
1938 + the parent dir is marked as opaque or the target file is whiteouted
1939 + on the branch, then the result of the policy is ignored and the target
1940 + file will be created on the highest one among the upper writable
1941 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1943 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1944 + They try selecting the branch where the source exists as possible
1945 + since copyup a large file will take long time. If it can't be,
1946 + ie. the branch where the source exists is readonly, then they will
1947 + follow the copyup policy.
1948 +- There is an exception for rename(2) when the target exists.
1949 + If the rename target exists, aufs compares the index of the branches
1950 + where the source and the target exists and selects the higher
1951 + one. If the selected branch is readonly, then aufs follows the
1953 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1954 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1955 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2017-07-29 12:14:25.896375188 +0200
1958 +# Copyright (C) 2011-2017 Junjiro R. Okajima
1960 +# This program is free software; you can redistribute it and/or modify
1961 +# it under the terms of the GNU General Public License as published by
1962 +# the Free Software Foundation; either version 2 of the License, or
1963 +# (at your option) any later version.
1965 +# This program is distributed in the hope that it will be useful,
1966 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1967 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1968 +# GNU General Public License for more details.
1970 +# You should have received a copy of the GNU General Public License
1971 +# along with this program; if not, write to the Free Software
1972 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1975 +File-based Hierarchical Storage Management (FHSM)
1976 +----------------------------------------------------------------------
1977 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1978 +storage world. Aufs provides this feature as file-based with multiple
1979 +writable branches, based upon the principle of "Colder, the Lower".
1980 +Here the word "colder" means that the less used files, and "lower" means
1981 +that the position in the order of the stacked branches vertically.
1982 +These multiple writable branches are prioritized, ie. the topmost one
1983 +should be the fastest drive and be used heavily.
1985 +o Characters in aufs FHSM story
1986 +- aufs itself and a new branch attribute.
1987 +- a new ioctl interface to move-down and to establish a connection with
1988 + the daemon ("move-down" is a converse of "copy-up").
1989 +- userspace tool and daemon.
1991 +The userspace daemon establishes a connection with aufs and waits for
1992 +the notification. The notified information is very similar to struct
1993 +statfs containing the number of consumed blocks and inodes.
1994 +When the consumed blocks/inodes of a branch exceeds the user-specified
1995 +upper watermark, the daemon activates its move-down process until the
1996 +consumed blocks/inodes reaches the user-specified lower watermark.
1998 +The actual move-down is done by aufs based upon the request from
1999 +user-space since we need to maintain the inode number and the internal
2000 +pointer arrays in aufs.
2002 +Currently aufs FHSM handles the regular files only. Additionally they
2003 +must not be hard-linked nor pseudo-linked.
2006 +o Cowork of aufs and the user-space daemon
2007 + During the userspace daemon established the connection, aufs sends a
2008 + small notification to it whenever aufs writes something into the
2009 + writable branch. But it may cost high since aufs issues statfs(2)
2010 + internally. So user can specify a new option to cache the
2011 + info. Actually the notification is controlled by these factors.
2012 + + the specified cache time.
2013 + + classified as "force" by aufs internally.
2014 + Until the specified time expires, aufs doesn't send the info
2015 + except the forced cases. When aufs decide forcing, the info is always
2016 + notified to userspace.
2017 + For example, the number of free inodes is generally large enough and
2018 + the shortage of it happens rarely. So aufs doesn't force the
2019 + notification when creating a new file, directory and others. This is
2020 + the typical case which aufs doesn't force.
2021 + When aufs writes the actual filedata and the files consumes any of new
2022 + blocks, the aufs forces notifying.
2025 +o Interfaces in aufs
2026 +- New branch attribute.
2028 + Specifies that the branch is managed by FHSM feature. In other word,
2029 + participant in the FHSM.
2030 + When nofhsm is set to the branch, it will not be the source/target
2031 + branch of the move-down operation. This attribute is set
2032 + independently from coo and moo attributes, and if you want full
2033 + FHSM, you should specify them as well.
2034 +- New mount option.
2036 + Specifies a second to suppress many less important info to be
2039 + + AUFS_CTL_FHSM_FD
2040 + create a new file descriptor which userspace can read the notification
2041 + (a subset of struct statfs) from aufs.
2042 +- Module parameter 'brs'
2043 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2045 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2046 + When there are two or more branches with fhsm attributes,
2047 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2048 + terminates it. As a result of remounting and branch-manipulation, the
2049 + number of branches with fhsm attribute can be one. In this case,
2050 + /sbin/mount.aufs will terminate the user-space daemon.
2053 +Finally the operation is done as these steps in kernel-space.
2055 + + no one else is using the file.
2056 + + the file is not hard-linked.
2057 + + the file is not pseudo-linked.
2058 + + the file is a regular file.
2059 + + the parent dir is not opaqued.
2060 +- find the target writable branch.
2061 +- make sure the file is not whiteout-ed by the upper (than the target)
2063 +- make the parent dir on the target branch.
2064 +- mutex lock the inode on the branch.
2065 +- unlink the whiteout on the target branch (if exists).
2066 +- lookup and create the whiteout-ed temporary name on the target branch.
2067 +- copy the file as the whiteout-ed temporary name on the target branch.
2068 +- rename the whiteout-ed temporary name to the original name.
2069 +- unlink the file on the source branch.
2070 +- maintain the internal pointer array and the external inode number
2072 +- maintain the timestamps and other attributes of the parent dir and the
2075 +And of course, in every step, an error may happen. So the operation
2076 +should restore the original file state after an error happens.
2077 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2078 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2079 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2017-07-29 12:14:25.896375188 +0200
2082 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2084 +# This program is free software; you can redistribute it and/or modify
2085 +# it under the terms of the GNU General Public License as published by
2086 +# the Free Software Foundation; either version 2 of the License, or
2087 +# (at your option) any later version.
2089 +# This program is distributed in the hope that it will be useful,
2090 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2091 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2092 +# GNU General Public License for more details.
2094 +# You should have received a copy of the GNU General Public License
2095 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2097 +mmap(2) -- File Memory Mapping
2098 +----------------------------------------------------------------------
2099 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2100 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2102 +This approach is simple and good, but there is one problem.
2103 +Under /proc, several entries show the mmapped files by its path (with
2104 +device and inode number), and the printed path will be the path on the
2105 +branch fs's instead of virtual aufs's.
2106 +This is not a problem in most cases, but some utilities lsof(1) (and its
2107 +user) may expect the path on aufs.
2109 +To address this issue, aufs adds a new member called vm_prfile in struct
2110 +vm_area_struct (and struct vm_region). The original vm_file points to
2111 +the file on the branch fs in order to handle everything correctly as
2112 +usual. The new vm_prfile points to a virtual file in aufs, and the
2113 +show-functions in procfs refers to vm_prfile if it is set.
2114 +Also we need to maintain several other places where touching vm_file
2116 +- fork()/clone() copies vma and the reference count of vm_file is
2118 +- merging vma maintains the ref count too.
2120 +This is not a good approach. It just fakes the printed path. But it
2121 +leaves all behaviour around f_mapping unchanged. This is surely an
2123 +Actually aufs had adopted another complicated approach which calls
2124 +generic_file_mmap() and handles struct vm_operations_struct. In this
2125 +approach, aufs met a hard problem and I could not solve it without
2126 +switching the approach.
2128 +There may be one more another approach which is
2129 +- bind-mount the branch-root onto the aufs-root internally
2130 +- grab the new vfsmount (ie. struct mount)
2131 +- lazy-umount the branch-root internally
2132 +- in open(2) the aufs-file, open the branch-file with the hidden
2133 + vfsmount (instead of the original branch's vfsmount)
2134 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2135 + but it may be possible from userspace by the mount helper.
2137 +Adding the internal hidden vfsmount and using it in opening a file, the
2138 +file path under /proc will be printed correctly. This approach looks
2139 +smarter, but is not possible I am afraid.
2140 +- aufs-root may be bind-mount later. when it happens, another hidden
2141 + vfsmount will be required.
2142 +- it is hard to get the chance to bind-mount and lazy-umount
2143 + + in kernel-space, FS can have vfsmount in open(2) via
2144 + file->f_path, and aufs can know its vfsmount. But several locks are
2145 + already acquired, and if aufs tries to bind-mount and lazy-umount
2146 + here, then it may cause a deadlock.
2147 + + in user-space, bind-mount doesn't invoke the mount helper.
2148 +- since /proc shows dev and ino, aufs has to give vma these info. it
2149 + means a new member vm_prinode will be necessary. this is essentially
2150 + equivalent to vm_prfile described above.
2152 +I have to give up this "looks-smater" approach.
2153 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2154 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2155 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2017-07-29 12:14:25.896375188 +0200
2158 +# Copyright (C) 2014-2017 Junjiro R. Okajima
2160 +# This program is free software; you can redistribute it and/or modify
2161 +# it under the terms of the GNU General Public License as published by
2162 +# the Free Software Foundation; either version 2 of the License, or
2163 +# (at your option) any later version.
2165 +# This program is distributed in the hope that it will be useful,
2166 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2167 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2168 +# GNU General Public License for more details.
2170 +# You should have received a copy of the GNU General Public License
2171 +# along with this program; if not, write to the Free Software
2172 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2175 +Listing XATTR/EA and getting the value
2176 +----------------------------------------------------------------------
2177 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2178 +shows the values from the topmost existing file. This behaviour is good
2179 +for the non-dir entries since the bahaviour exactly matches the shown
2180 +information. But for the directories, aufs considers all the same named
2181 +entries on the lower branches. Which means, if one of the lower entry
2182 +rejects readdir call, then aufs returns an error even if the topmost
2183 +entry allows it. This behaviour is necessary to respect the branch fs's
2184 +security, but can make users confused since the user-visible standard
2185 +attributes don't match the behaviour.
2186 +To address this issue, aufs has a mount option called dirperm1 which
2187 +checks the permission for the topmost entry only, and ignores the lower
2188 +entry's permission.
2190 +A similar issue can happen around XATTR.
2191 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2192 +always set. Otherwise these very unpleasant situation would happen.
2193 +- listxattr(2) may return the duplicated entries.
2194 +- users may not be able to remove or reset the XATTR forever,
2197 +XATTR/EA support in the internal (copy,move)-(up,down)
2198 +----------------------------------------------------------------------
2199 +Generally the extended attributes of inode are categorized as these.
2200 +- "security" for LSM and capability.
2201 +- "system" for posix ACL, 'acl' mount option is required for the branch
2203 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2204 +- "user" for userspace, 'user_xattr' mount option is required for the
2205 + branch fs generally.
2207 +Moreover there are some other categories. Aufs handles these rather
2208 +unpopular categories as the ordinary ones, ie. there is no special
2209 +condition nor exception.
2211 +In copy-up, the support for XATTR on the dst branch may differ from the
2212 +src branch. In this case, the copy-up operation will get an error and
2213 +the original user operation which triggered the copy-up will fail. It
2214 +can happen that even all copy-up will fail.
2215 +When both of src and dst branches support XATTR and if an error occurs
2216 +during copying XATTR, then the copy-up should fail obviously. That is a
2217 +good reason and aufs should return an error to userspace. But when only
2218 +the src branch support that XATTR, aufs should not return an error.
2219 +For example, the src branch supports ACL but the dst branch doesn't
2220 +because the dst branch may natively un-support it or temporary
2221 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2222 +may NOT return an error even if the XATTR is not supported. It is
2223 +totally up to the branch fs.
2225 +Anyway when the aufs internal copy-up gets an error from the dst branch
2226 +fs, then aufs tries removing the just copied entry and returns the error
2227 +to the userspace. The worst case of this situation will be all copy-up
2230 +For the copy-up operation, there two basic approaches.
2231 +- copy the specified XATTR only (by category above), and return the
2232 + error unconditionally if it happens.
2233 +- copy all XATTR, and ignore the error on the specified category only.
2235 +In order to support XATTR and to implement the correct behaviour, aufs
2236 +chooses the latter approach and introduces some new branch attributes,
2237 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2238 +They correspond to the XATTR namespaces (see above). Additionally, to be
2239 +convenient, "icex" is also provided which means all "icex*" attributes
2240 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2242 +The meaning of these attributes is to ignore the error from setting
2243 +XATTR on that branch.
2244 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2245 +error from the dst branch according to the specified attributes.
2247 +Some XATTR may have its default value. The default value may come from
2248 +the parent dir or the environment. If the default value is set at the
2249 +file creating-time, it will be overwritten by copy-up.
2250 +Some contradiction may happen I am afraid.
2251 +Do we need another attribute to stop copying XATTR? I am unsure. For
2252 +now, aufs implements the branch attributes to ignore the error.
2253 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2254 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2255 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2017-07-29 12:14:25.896375188 +0200
2258 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2260 +# This program is free software; you can redistribute it and/or modify
2261 +# it under the terms of the GNU General Public License as published by
2262 +# the Free Software Foundation; either version 2 of the License, or
2263 +# (at your option) any later version.
2265 +# This program is distributed in the hope that it will be useful,
2266 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2267 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2268 +# GNU General Public License for more details.
2270 +# You should have received a copy of the GNU General Public License
2271 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2273 +Export Aufs via NFS
2274 +----------------------------------------------------------------------
2275 +Here is an approach.
2276 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2278 +- iget_locked(): initialize aufs inode generation for a new inode, and
2279 + store it in xigen file.
2280 +- destroy_inode(): increment aufs inode generation and store it in xigen
2281 + file. it is necessary even if it is not unlinked, because any data of
2282 + inode may be changed by UDBA.
2283 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2284 + build file handle by
2285 + + branch id (4 bytes)
2286 + + superblock generation (4 bytes)
2287 + + inode number (4 or 8 bytes)
2288 + + parent dir inode number (4 or 8 bytes)
2289 + + inode generation (4 bytes))
2290 + + return value of exportfs_encode_fh() for the parent on a branch (4
2292 + + file handle for a branch (by exportfs_encode_fh())
2294 + + find the index of a branch from its id in handle, and check it is
2295 + still exist in aufs.
2296 + + 1st level: get the inode number from handle and search it in cache.
2297 + + 2nd level: if not found in cache, get the parent inode number from
2298 + the handle and search it in cache. and then open the found parent
2299 + dir, find the matching inode number by vfs_readdir() and get its
2300 + name, and call lookup_one_len() for the target dentry.
2301 + + 3rd level: if the parent dir is not cached, call
2302 + exportfs_decode_fh() for a branch and get the parent on a branch,
2303 + build a pathname of it, convert it a pathname in aufs, call
2304 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2306 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2307 + for every branch, but not itself. to get this, (currently) aufs
2308 + searches in current->nsproxy->mnt_ns list. it may not be a good
2309 + idea, but I didn't get other approach.
2310 + + test the generation of the gotten inode.
2311 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2312 + convert it into ESTALE for NFSD.
2313 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2314 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2315 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2316 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2317 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2017-07-29 12:14:25.896375188 +0200
2320 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2322 +# This program is free software; you can redistribute it and/or modify
2323 +# it under the terms of the GNU General Public License as published by
2324 +# the Free Software Foundation; either version 2 of the License, or
2325 +# (at your option) any later version.
2327 +# This program is distributed in the hope that it will be useful,
2328 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2329 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2330 +# GNU General Public License for more details.
2332 +# You should have received a copy of the GNU General Public License
2333 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2335 +Show Whiteout Mode (shwh)
2336 +----------------------------------------------------------------------
2337 +Generally aufs hides the name of whiteouts. But in some cases, to show
2338 +them is very useful for users. For instance, creating a new middle layer
2339 +(branch) by merging existing layers.
2341 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2342 +When you have three branches,
2343 +- Bottom: 'system', squashfs (underlying base system), read-only
2344 +- Middle: 'mods', squashfs, read-only
2345 +- Top: 'overlay', ram (tmpfs), read-write
2347 +The top layer is loaded at boot time and saved at shutdown, to preserve
2348 +the changes made to the system during the session.
2349 +When larger changes have been made, or smaller changes have accumulated,
2350 +the size of the saved top layer data grows. At this point, it would be
2351 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2352 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2353 +restoring save and load speed.
2355 +This merging is simplified by the use of another aufs mount, of just the
2356 +two overlay branches using the 'shwh' option.
2357 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2358 + aufs /livesys/merge_union
2360 +A merged view of these two branches is then available at
2361 +/livesys/merge_union, and the new feature is that the whiteouts are
2363 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2364 +writing to all branches. Also the default mode for all branches is 'ro'.
2365 +It is now possible to save the combined contents of the two overlay
2366 +branches to a new squashfs, e.g.:
2367 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2369 +This new squashfs archive can be stored on the boot device and the
2370 +initramfs will use it to replace the old one at the next boot.
2371 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2372 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2373 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2017-07-29 12:14:25.896375188 +0200
2376 +# Copyright (C) 2010-2017 Junjiro R. Okajima
2378 +# This program is free software; you can redistribute it and/or modify
2379 +# it under the terms of the GNU General Public License as published by
2380 +# the Free Software Foundation; either version 2 of the License, or
2381 +# (at your option) any later version.
2383 +# This program is distributed in the hope that it will be useful,
2384 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2385 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2386 +# GNU General Public License for more details.
2388 +# You should have received a copy of the GNU General Public License
2389 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2391 +Dynamically customizable FS operations
2392 +----------------------------------------------------------------------
2393 +Generally FS operations (struct inode_operations, struct
2394 +address_space_operations, struct file_operations, etc.) are defined as
2395 +"static const", but it never means that FS have only one set of
2396 +operation. Some FS have multiple sets of them. For instance, ext2 has
2397 +three sets, one for XIP, for NOBH, and for normal.
2398 +Since aufs overrides and redirects these operations, sometimes aufs has
2399 +to change its behaviour according to the branch FS type. More importantly
2400 +VFS acts differently if a function (member in the struct) is set or
2401 +not. It means aufs should have several sets of operations and select one
2402 +among them according to the branch FS definition.
2404 +In order to solve this problem and not to affect the behaviour of VFS,
2405 +aufs defines these operations dynamically. For instance, aufs defines
2406 +dummy direct_IO function for struct address_space_operations, but it may
2407 +not be set to the address_space_operations actually. When the branch FS
2408 +doesn't have it, aufs doesn't set it to its address_space_operations
2409 +while the function definition itself is still alive. So the behaviour
2410 +itself will not change, and it will return an error when direct_IO is
2413 +The lifetime of these dynamically generated operation object is
2414 +maintained by aufs branch object. When the branch is removed from aufs,
2415 +the reference counter of the object is decremented. When it reaches
2416 +zero, the dynamically generated operation object will be freed.
2418 +This approach is designed to support AIO (io_submit), Direct I/O and
2420 +Currently this approach is applied to address_space_operations for
2421 +regular files only.
2422 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2423 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2424 +++ linux/Documentation/filesystems/aufs/README 2017-07-29 12:14:25.893041746 +0200
2427 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2433 +----------------------------------------
2434 +In the early days, aufs was entirely re-designed and re-implemented
2435 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2436 +improvements and implementations, it becomes totally different from
2437 +Unionfs while keeping the basic features.
2438 +Recently, Unionfs Version 2.x series begin taking some of the same
2439 +approaches to aufs1's.
2440 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2441 +University and his team.
2443 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2444 +If you want older kernel version support, try aufs2-2.6.git or
2445 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2447 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2448 + According to Christoph Hellwig, linux rejects all union-type
2449 + filesystems but UnionMount.
2450 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2452 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2453 + UnionMount, and he pointed out an issue around a directory mutex
2454 + lock and aufs addressed it. But it is still unsure whether aufs will
2455 + be merged (or any other union solution).
2456 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2460 +----------------------------------------
2461 +- unite several directories into a single virtual filesystem. The member
2462 + directory is called as a branch.
2463 +- you can specify the permission flags to the branch, which are 'readonly',
2464 + 'readwrite' and 'whiteout-able.'
2465 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2466 + readonly branch are modifiable logically.
2467 +- dynamic branch manipulation, add, del.
2470 +Also there are many enhancements in aufs, such as:
2471 +- test only the highest one for the directory permission (dirperm1)
2472 +- copyup on open (coo=)
2473 +- 'move' policy for copy-up between two writable branches, after
2474 + checking free space.
2476 +- readdir(3) in userspace.
2477 +- keep inode number by external inode number table
2478 +- keep the timestamps of file/dir in internal copyup operation
2479 +- seekable directory, supporting NFS readdir.
2480 +- whiteout is hardlinked in order to reduce the consumption of inodes
2482 +- do not copyup, nor create a whiteout when it is unnecessary
2483 +- revert a single systemcall when an error occurs in aufs
2484 +- remount interface instead of ioctl
2485 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2486 +- loopback mounted filesystem as a branch
2487 +- kernel thread for removing the dir who has a plenty of whiteouts
2488 +- support copyup sparse file (a file which has a 'hole' in it)
2489 +- default permission flags for branches
2490 +- selectable permission flags for ro branch, whether whiteout can
2493 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2494 +- support multiple writable branches, some policies to select one
2495 + among multiple writable branches.
2496 +- a new semantics for link(2) and rename(2) to support multiple
2497 + writable branches.
2498 +- no glibc changes are required.
2499 +- pseudo hardlink (hardlink over branches)
2500 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2501 + including NFS or remote filesystem branch.
2502 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2505 +Currently these features are dropped temporary from aufs4.
2506 +See design/08plan.txt in detail.
2507 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2509 +- statistics of aufs thread (/sys/fs/aufs/stat)
2511 +Features or just an idea in the future (see also design/*.txt),
2512 +- reorder the branch index without del/re-add.
2513 +- permanent xino files for NFSD
2514 +- an option for refreshing the opened files after add/del branches
2515 +- light version, without branch manipulation. (unnecessary?)
2516 +- copyup in userspace
2517 +- inotify in userspace
2522 +----------------------------------------
2523 +There are three GIT trees for aufs4, aufs4-linux.git,
2524 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2526 +While the aufs-util is always necessary, you need either of aufs4-linux
2527 +or aufs4-standalone.
2529 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2530 +git://git.kernel.org/.../torvalds/linux.git.
2531 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2532 +build aufs4 as an external kernel module.
2533 +Several extra patches are not included in this tree. Only
2534 +aufs4-standalone tree contains them. They are described in the later
2535 +section "Configuration and Compilation."
2537 +On the other hand, the aufs4-standalone tree has only aufs source files
2538 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2539 +But you need to apply all aufs patches manually.
2541 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2542 +represents the linux kernel version, "linux-4.x". For instance,
2543 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2544 +"aufs4.x-rcN" branch.
2547 +$ git clone --reference /your/linux/git/tree \
2548 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2549 +- if you don't have linux GIT tree, then remove "--reference ..."
2550 +$ cd aufs4-linux.git
2551 +$ git checkout origin/aufs4.0
2553 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2554 +leave the patch-work to GIT.
2555 +$ cd /your/linux/git/tree
2556 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2558 +$ git checkout -b my4.0 v4.0
2559 +$ (add your local change...)
2560 +$ git pull aufs4 aufs4.0
2561 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2562 +- you may need to solve some conflicts between your_changes and
2563 + aufs4.0. in this case, git-rerere is recommended so that you can
2564 + solve the similar conflicts automatically when you upgrade to 4.1 or
2565 + later in the future.
2567 +o aufs4-standalone tree
2568 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2569 +$ cd aufs4-standalone.git
2570 +$ git checkout origin/aufs4.0
2573 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2574 +- note that the public aufs-util.git is on SourceForge instead of
2577 +$ git checkout origin/aufs4.0
2579 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2580 +The minor version number, 'x' in '4.x', of aufs may not always
2581 +follow the minor version number of the kernel.
2582 +Because changes in the kernel that cause the use of a new
2583 +minor version number do not always require changes to aufs-util.
2585 +Since aufs-util has its own minor version number, you may not be
2586 +able to find a GIT branch in aufs-util for your kernel's
2587 +exact minor version number.
2588 +In this case, you should git-checkout the branch for the
2589 +nearest lower number.
2591 +For (an unreleased) example:
2592 +If you are using "linux-4.10" and the "aufs4.10" branch
2593 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2594 +or something numerically smaller is the branch for your kernel.
2596 +Also you can view all branches by
2600 +3. Configuration and Compilation
2601 +----------------------------------------
2602 +Make sure you have git-checkout'ed the correct branch.
2604 +For aufs4-linux tree,
2605 +- enable CONFIG_AUFS_FS.
2606 +- set other aufs configurations if necessary.
2608 +For aufs4-standalone tree,
2609 +There are several ways to build.
2612 +- apply ./aufs4-kbuild.patch to your kernel source files.
2613 +- apply ./aufs4-base.patch too.
2614 +- apply ./aufs4-mmap.patch too.
2615 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2616 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2617 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2618 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2619 +- enable CONFIG_AUFS_FS, you can select either
2621 +- and build your kernel as usual.
2622 +- install the built kernel.
2623 + Note: Since linux-3.9, every filesystem module requires an alias
2624 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2625 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2626 +- install the header files too by "make headers_install" to the
2627 + directory where you specify. By default, it is $PWD/usr.
2628 + "make help" shows a brief note for headers_install.
2629 +- and reboot your system.
2632 +- module only (CONFIG_AUFS_FS=m).
2633 +- apply ./aufs4-base.patch to your kernel source files.
2634 +- apply ./aufs4-mmap.patch too.
2635 +- apply ./aufs4-standalone.patch too.
2636 +- build your kernel, don't forget "make headers_install", and reboot.
2637 +- edit ./config.mk and set other aufs configurations if necessary.
2638 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2639 + every aufs configurations.
2640 +- build the module by simple "make".
2641 + Note: Since linux-3.9, every filesystem module requires an alias
2642 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2643 + modules.aliases file.
2644 +- you can specify ${KDIR} make variable which points to your kernel
2646 +- install the files
2647 + + run "make install" to install the aufs module, or copy the built
2648 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2649 + + run "make install_headers" (instead of headers_install) to install
2650 + the modified aufs header file (you can specify DESTDIR which is
2651 + available in aufs standalone version's Makefile only), or copy
2652 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2653 + you like manually. By default, the target directory is $PWD/usr.
2654 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2655 + kernel source tree.
2657 +Note: The header file aufs_type.h is necessary to build aufs-util
2658 + as well as "make headers_install" in the kernel source tree.
2659 + headers_install is subject to be forgotten, but it is essentially
2660 + necessary, not only for building aufs-util.
2661 + You may not meet problems without headers_install in some older
2665 +- read README in aufs-util, build and install it
2666 +- note that your distribution may contain an obsoleted version of
2667 + aufs_type.h in /usr/include/linux or something. When you build aufs
2668 + utilities, make sure that your compiler refers the correct aufs header
2669 + file which is built by "make headers_install."
2670 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2671 + then run "make install_ulib" too. And refer to the aufs manual in
2674 +There several other patches in aufs4-standalone.git. They are all
2675 +optional. When you meet some problems, they will help you.
2676 +- aufs4-loopback.patch
2677 + Supports a nested loopback mount in a branch-fs. This patch is
2678 + unnecessary until aufs produces a message like "you may want to try
2679 + another patch for loopback file".
2681 + Modifies a system global kernel internal function get_next_ino() in
2682 + order to stop assigning 0 for an inode-number. Not directly related to
2683 + aufs, but recommended generally.
2685 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2686 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2687 + duplication of inode number, which is important for backup tools and
2688 + other utilities. When you find aufs XINO files for tmpfs branch
2689 + growing too much, try this patch.
2690 +- lockdep-debug.patch
2691 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2692 + also a caller of VFS functions for branch filesystems, subclassing of
2693 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2694 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2695 + need to apply this debug patch to expand several constant values.
2696 + If don't know what LOCKDEP, then you don't have apply this patch.
2700 +----------------------------------------
2701 +At first, make sure aufs-util are installed, and please read the aufs
2702 +manual, aufs.5 in aufs-util.git tree.
2706 +$ mkdir /tmp/rw /tmp/aufs
2707 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2709 +Here is another example. The result is equivalent.
2710 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2712 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2713 +# mount -o remount,append:${HOME} /tmp/aufs
2715 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2716 +you modify a file under /tmp/aufs, the one on your home directory is
2717 +not affected, instead the same named file will be newly created under
2718 +/tmp/rw. And all of your modification to a file will be applied to
2719 +the one under /tmp/rw. This is called the file based Copy on Write
2721 +Aufs mount options are described in aufs.5.
2722 +If you run chroot or something and make your aufs as a root directory,
2723 +then you need to customize the shutdown script. See the aufs manual in
2726 +Additionally, there are some sample usages of aufs which are a
2727 +diskless system with network booting, and LiveCD over NFS.
2728 +See sample dir in CVS tree on SourceForge.
2732 +----------------------------------------
2733 +When you have any problems or strange behaviour in aufs, please let me
2735 +- /proc/mounts (instead of the output of mount(8))
2736 +- /sys/module/aufs/*
2737 +- /sys/fs/aufs/* (if you have them)
2738 +- /debug/aufs/* (if you have them)
2739 +- linux kernel version
2740 + if your kernel is not plain, for example modified by distributor,
2741 + the url where i can download its source is necessary too.
2742 +- aufs version which was printed at loading the module or booting the
2743 + system, instead of the date you downloaded.
2744 +- configuration (define/undefine CONFIG_AUFS_xxx)
2745 +- kernel configuration or /proc/config.gz (if you have it)
2746 +- behaviour which you think to be incorrect
2747 +- actual operation, reproducible one is better
2748 +- mailto: aufs-users at lists.sourceforge.net
2750 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2751 +and Feature Requests) on SourceForge. Please join and write to
2755 +6. Acknowledgements
2756 +----------------------------------------
2757 +Thanks to everyone who have tried and are using aufs, whoever
2758 +have reported a bug or any feedback.
2760 +Especially donators:
2761 +Tomas Matejicek(slax.org) made a donation (much more than once).
2762 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2763 + scripts) is making "doubling" donations.
2764 + Unfortunately I cannot list all of the donators, but I really
2766 + It ends Aug 2010, but the ordinary donation URL is still available.
2767 + <http://sourceforge.net/donate/index.php?group_id=167503>
2768 +Dai Itasaka made a donation (2007/8).
2769 +Chuck Smith made a donation (2008/4, 10 and 12).
2770 +Henk Schoneveld made a donation (2008/9).
2771 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2772 +Francois Dupoux made a donation (2008/11).
2773 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2774 + aufs2 GIT tree (2009/2).
2775 +William Grant made a donation (2009/3).
2776 +Patrick Lane made a donation (2009/4).
2777 +The Mail Archive (mail-archive.com) made donations (2009/5).
2778 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2779 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2780 +Pavel Pronskiy made a donation (2011/2).
2781 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2782 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2783 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2785 +Sam Liddicott made a donation (2011/9).
2786 +Era Scarecrow made a donation (2013/4).
2787 +Bor Ratajc made a donation (2013/4).
2788 +Alessandro Gorreta made a donation (2013/4).
2789 +POIRETTE Marc made a donation (2013/4).
2790 +Alessandro Gorreta made a donation (2013/4).
2791 +lauri kasvandik made a donation (2013/5).
2792 +"pemasu from Finland" made a donation (2013/7).
2793 +The Parted Magic Project made a donation (2013/9 and 11).
2794 +Pavel Barta made a donation (2013/10).
2795 +Nikolay Pertsev made a donation (2014/5).
2796 +James B made a donation (2014/7 and 2015/7).
2797 +Stefano Di Biase made a donation (2014/8).
2798 +Daniel Epellei made a donation (2015/1).
2799 +OmegaPhil made a donation (2016/1).
2800 +Tomasz Szewczyk made a donation (2016/4).
2801 +James Burry made a donation (2016/12).
2803 +Thank you very much.
2804 +Donations are always, including future donations, very important and
2805 +helpful for me to keep on developing aufs.
2809 +----------------------------------------
2810 +If you are an experienced user, no explanation is needed. Aufs is
2811 +just a linux filesystem.
2816 +# Local variables: ;
2819 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2820 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2821 +++ linux/fs/aufs/aufs.h 2017-07-29 12:14:25.896375188 +0200
2824 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2826 + * This program, aufs is free software; you can redistribute it and/or modify
2827 + * it under the terms of the GNU General Public License as published by
2828 + * the Free Software Foundation; either version 2 of the License, or
2829 + * (at your option) any later version.
2831 + * This program is distributed in the hope that it will be useful,
2832 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2833 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2834 + * GNU General Public License for more details.
2836 + * You should have received a copy of the GNU General Public License
2837 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2841 + * all header files
2849 +#define AuStub(type, name, body, ...) \
2850 + static inline type name(__VA_ARGS__) { body; }
2852 +#define AuStubVoid(name, ...) \
2853 + AuStub(void, name, , __VA_ARGS__)
2854 +#define AuStubInt0(name, ...) \
2855 + AuStub(int, name, return 0, __VA_ARGS__)
2859 +#include "branch.h"
2862 +#include "dbgaufs.h"
2863 +#include "dentry.h"
2867 +#include "fstype.h"
2870 +#include "module.h"
2875 +#include "sysaufs.h"
2880 +#endif /* __KERNEL__ */
2881 +#endif /* __AUFS_H__ */
2882 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2883 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2884 +++ linux/fs/aufs/branch.c 2017-07-29 12:14:25.896375188 +0200
2887 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2889 + * This program, aufs is free software; you can redistribute it and/or modify
2890 + * it under the terms of the GNU General Public License as published by
2891 + * the Free Software Foundation; either version 2 of the License, or
2892 + * (at your option) any later version.
2894 + * This program is distributed in the hope that it will be useful,
2895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2897 + * GNU General Public License for more details.
2899 + * You should have received a copy of the GNU General Public License
2900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2904 + * branch management
2907 +#include <linux/compat.h>
2908 +#include <linux/statfs.h>
2912 + * free a single branch
2914 +static void au_br_do_free(struct au_branch *br)
2917 + struct au_wbr *wbr;
2918 + struct au_dykey **key;
2920 + au_hnotify_fin_br(br);
2922 + if (br->br_xino.xi_file)
2923 + fput(br->br_xino.xi_file);
2924 + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--)
2925 + AuDebugOn(br->br_xino.xi_nondir.array[i]);
2926 + kfree(br->br_xino.xi_nondir.array);
2928 + AuDebugOn(au_br_count(br));
2929 + au_br_count_fin(br);
2933 + for (i = 0; i < AuBrWh_Last; i++)
2934 + dput(wbr->wbr_wh[i]);
2935 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2936 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2939 + if (br->br_fhsm) {
2940 + au_br_fhsm_fin(br->br_fhsm);
2941 + kfree(br->br_fhsm);
2944 + key = br->br_dykey;
2945 + for (i = 0; i < AuBrDynOp; i++, key++)
2951 + /* recursive lock, s_umount of branch's */
2953 + path_put(&br->br_path);
2960 + * frees all branches
2962 +void au_br_free(struct au_sbinfo *sbinfo)
2964 + aufs_bindex_t bmax;
2965 + struct au_branch **br;
2967 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2969 + bmax = sbinfo->si_bbot + 1;
2970 + br = sbinfo->si_branch;
2972 + au_br_do_free(*br++);
2976 + * find the index of a branch which is specified by @br_id.
2978 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2980 + aufs_bindex_t bindex, bbot;
2982 + bbot = au_sbbot(sb);
2983 + for (bindex = 0; bindex <= bbot; bindex++)
2984 + if (au_sbr_id(sb, bindex) == br_id)
2989 +/* ---------------------------------------------------------------------- */
2995 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2996 + struct dentry *h_root)
2998 + if (unlikely(h_adding == h_root
2999 + || au_test_loopback_overlap(sb, h_adding)))
3001 + if (h_adding->d_sb != h_root->d_sb)
3003 + return au_test_subdir(h_adding, h_root)
3004 + || au_test_subdir(h_root, h_adding);
3008 + * returns a newly allocated branch. @new_nbranch is a number of branches
3009 + * after adding a branch.
3011 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3014 + struct au_branch *add_branch;
3015 + struct dentry *root;
3016 + struct inode *inode;
3020 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3021 + if (unlikely(!add_branch))
3023 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3024 + add_branch->br_xino.xi_nondir.array
3025 + = kzalloc(sizeof(ino_t) * add_branch->br_xino.xi_nondir.total,
3027 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3030 + err = au_hnotify_init_br(add_branch, perm);
3031 + if (unlikely(err))
3032 + goto out_xinondir;
3034 + if (au_br_writable(perm)) {
3035 + /* may be freed separately at changing the branch permission */
3036 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3038 + if (unlikely(!add_branch->br_wbr))
3042 + if (au_br_fhsm(perm)) {
3043 + err = au_fhsm_br_alloc(add_branch);
3044 + if (unlikely(err))
3048 + root = sb->s_root;
3049 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3051 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3053 + inode = d_inode(root);
3054 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3058 + return add_branch; /* success */
3061 + kfree(add_branch->br_wbr);
3063 + au_hnotify_fin_br(add_branch);
3065 + kfree(add_branch->br_xino.xi_nondir.array);
3067 + kfree(add_branch);
3069 + return ERR_PTR(err);
3073 + * test if the branch permission is legal or not.
3075 +static int test_br(struct inode *inode, int brperm, char *path)
3079 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3084 + pr_err("write permission for readonly mount or inode, %s\n", path);
3092 + * 0: success, the caller will add it
3093 + * plus: success, it is already unified, the caller should ignore it
3096 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3099 + aufs_bindex_t bbot, bindex;
3100 + struct dentry *root, *h_dentry;
3101 + struct inode *inode, *h_inode;
3103 + root = sb->s_root;
3104 + bbot = au_sbbot(sb);
3105 + if (unlikely(bbot >= 0
3106 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3110 + pr_err("%s duplicated\n", add->pathname);
3115 + err = -ENOSPC; /* -E2BIG; */
3116 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3117 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3118 + pr_err("number of branches exceeded %s\n", add->pathname);
3123 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3124 + pr_err("bad index %d\n", add->bindex);
3128 + inode = d_inode(add->path.dentry);
3130 + if (unlikely(!inode->i_nlink)) {
3131 + pr_err("no existence %s\n", add->pathname);
3136 + if (unlikely(inode->i_sb == sb)) {
3137 + pr_err("%s must be outside\n", add->pathname);
3141 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3142 + pr_err("unsupported filesystem, %s (%s)\n",
3143 + add->pathname, au_sbtype(inode->i_sb));
3147 + if (unlikely(inode->i_sb->s_stack_depth)) {
3148 + pr_err("already stacked, %s (%s)\n",
3149 + add->pathname, au_sbtype(inode->i_sb));
3153 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3154 + if (unlikely(err))
3158 + return 0; /* success */
3161 + for (bindex = 0; bindex <= bbot; bindex++)
3162 + if (unlikely(test_overlap(sb, add->path.dentry,
3163 + au_h_dptr(root, bindex)))) {
3164 + pr_err("%s is overlapped\n", add->pathname);
3169 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3170 + h_dentry = au_h_dptr(root, 0);
3171 + h_inode = d_inode(h_dentry);
3172 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3173 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3174 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3175 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3177 + i_uid_read(inode), i_gid_read(inode),
3178 + (inode->i_mode & S_IALLUGO),
3179 + i_uid_read(h_inode), i_gid_read(h_inode),
3180 + (h_inode->i_mode & S_IALLUGO));
3188 + * initialize or clean the whiteouts for an adding branch
3190 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3193 + int err, old_perm;
3194 + aufs_bindex_t bindex;
3195 + struct inode *h_inode;
3196 + struct au_wbr *wbr;
3197 + struct au_hinode *hdir;
3198 + struct dentry *h_dentry;
3200 + err = vfsub_mnt_want_write(au_br_mnt(br));
3201 + if (unlikely(err))
3205 + old_perm = br->br_perm;
3206 + br->br_perm = new_perm;
3209 + bindex = au_br_index(sb, br->br_id);
3210 + if (0 <= bindex) {
3211 + hdir = au_hi(d_inode(sb->s_root), bindex);
3212 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3214 + h_dentry = au_br_dentry(br);
3215 + h_inode = d_inode(h_dentry);
3216 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3219 + err = au_wh_init(br, sb);
3221 + wbr_wh_write_lock(wbr);
3222 + err = au_wh_init(br, sb);
3223 + wbr_wh_write_unlock(wbr);
3226 + au_hn_inode_unlock(hdir);
3228 + inode_unlock(h_inode);
3229 + vfsub_mnt_drop_write(au_br_mnt(br));
3230 + br->br_perm = old_perm;
3232 + if (!err && wbr && !au_br_writable(new_perm)) {
3234 + br->br_wbr = NULL;
3241 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3245 + struct kstatfs kst;
3246 + struct au_wbr *wbr;
3249 + au_rw_init(&wbr->wbr_wh_rwsem);
3250 + atomic_set(&wbr->wbr_wh_running, 0);
3253 + * a limit for rmdir/rename a dir
3254 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3256 + err = vfs_statfs(&br->br_path, &kst);
3257 + if (unlikely(err))
3260 + if (kst.f_namelen >= NAME_MAX)
3261 + err = au_br_init_wh(sb, br, perm);
3263 + pr_err("%pd(%s), unsupported namelen %ld\n",
3265 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3271 +/* initialize a new branch */
3272 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3273 + struct au_opt_add *add)
3276 + struct inode *h_inode;
3279 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3280 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3281 + br->br_perm = add->perm;
3282 + br->br_path = add->path; /* set first, path_get() later */
3283 + spin_lock_init(&br->br_dykey_lock);
3284 + au_br_count_init(br);
3285 + atomic_set(&br->br_xino_running, 0);
3286 + br->br_id = au_new_br_id(sb);
3287 + AuDebugOn(br->br_id < 0);
3289 + if (au_br_writable(add->perm)) {
3290 + err = au_wbr_init(br, sb, add->perm);
3291 + if (unlikely(err))
3295 + if (au_opt_test(au_mntflags(sb), XINO)) {
3296 + h_inode = d_inode(add->path.dentry);
3297 + err = au_xino_br(sb, br, h_inode->i_ino,
3298 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3299 + if (unlikely(err)) {
3300 + AuDebugOn(br->br_xino.xi_file);
3305 + sysaufs_br_init(br);
3306 + path_get(&br->br_path);
3307 + goto out; /* success */
3310 + memset(&br->br_path, 0, sizeof(br->br_path));
3315 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3316 + struct au_branch *br, aufs_bindex_t bbot,
3317 + aufs_bindex_t amount)
3319 + struct au_branch **brp;
3321 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3323 + brp = sbinfo->si_branch + bindex;
3324 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3326 + sbinfo->si_bbot++;
3327 + if (unlikely(bbot < 0))
3328 + sbinfo->si_bbot = 0;
3331 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3332 + aufs_bindex_t bbot, aufs_bindex_t amount)
3334 + struct au_hdentry *hdp;
3336 + AuRwMustWriteLock(&dinfo->di_rwsem);
3338 + hdp = au_hdentry(dinfo, bindex);
3339 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3340 + au_h_dentry_init(hdp);
3342 + if (unlikely(bbot < 0))
3343 + dinfo->di_btop = 0;
3346 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3347 + aufs_bindex_t bbot, aufs_bindex_t amount)
3349 + struct au_hinode *hip;
3351 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3353 + hip = au_hinode(iinfo, bindex);
3354 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3355 + au_hinode_init(hip);
3357 + if (unlikely(bbot < 0))
3358 + iinfo->ii_btop = 0;
3361 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3362 + aufs_bindex_t bindex)
3364 + struct dentry *root, *h_dentry;
3365 + struct inode *root_inode, *h_inode;
3366 + aufs_bindex_t bbot, amount;
3368 + root = sb->s_root;
3369 + root_inode = d_inode(root);
3370 + bbot = au_sbbot(sb);
3371 + amount = bbot + 1 - bindex;
3372 + h_dentry = au_br_dentry(br);
3373 + au_sbilist_lock();
3374 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3375 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3376 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3377 + au_set_h_dptr(root, bindex, dget(h_dentry));
3378 + h_inode = d_inode(h_dentry);
3379 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3380 + au_sbilist_unlock();
3383 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3386 + aufs_bindex_t bbot, add_bindex;
3387 + struct dentry *root, *h_dentry;
3388 + struct inode *root_inode;
3389 + struct au_branch *add_branch;
3391 + root = sb->s_root;
3392 + root_inode = d_inode(root);
3393 + IMustLock(root_inode);
3394 + IiMustWriteLock(root_inode);
3395 + err = test_add(sb, add, remount);
3396 + if (unlikely(err < 0))
3400 + goto out; /* success */
3403 + bbot = au_sbbot(sb);
3404 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3405 + err = PTR_ERR(add_branch);
3406 + if (IS_ERR(add_branch))
3409 + err = au_br_init(add_branch, sb, add);
3410 + if (unlikely(err)) {
3411 + au_br_do_free(add_branch);
3415 + add_bindex = add->bindex;
3417 + au_br_do_add(sb, add_branch, add_bindex);
3419 + sysaufs_brs_del(sb, add_bindex);
3420 + au_br_do_add(sb, add_branch, add_bindex);
3421 + sysaufs_brs_add(sb, add_bindex);
3424 + h_dentry = add->path.dentry;
3425 + if (!add_bindex) {
3426 + au_cpup_attr_all(root_inode, /*force*/1);
3427 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3429 + au_add_nlink(root_inode, d_inode(h_dentry));
3432 + * this test/set prevents aufs from handling unnecesary notify events
3433 + * of xino files, in case of re-adding a writable branch which was
3434 + * once detached from aufs.
3436 + if (au_xino_brid(sb) < 0
3437 + && au_br_writable(add_branch->br_perm)
3438 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3439 + && add_branch->br_xino.xi_file
3440 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3441 + au_xino_brid_set(sb, add_branch->br_id);
3447 +/* ---------------------------------------------------------------------- */
3449 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3450 + unsigned long long max __maybe_unused,
3453 + unsigned long long n;
3454 + struct file **p, *f;
3455 + struct au_sphlhead *files;
3456 + struct au_finfo *finfo;
3460 + files = &au_sbi(sb)->si_files;
3461 + spin_lock(&files->spin);
3462 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3463 + f = finfo->fi_file;
3465 + && !special_file(file_inode(f)->i_mode)) {
3469 + AuDebugOn(n > max);
3472 + spin_unlock(&files->spin);
3477 +static struct file **au_farray_alloc(struct super_block *sb,
3478 + unsigned long long *max)
3480 + *max = au_nfiles(sb);
3481 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3484 +static void au_farray_free(struct file **a, unsigned long long max)
3486 + unsigned long long ull;
3488 + for (ull = 0; ull < max; ull++)
3494 +/* ---------------------------------------------------------------------- */
3500 +/* to show the line number, do not make it inlined function */
3501 +#define AuVerbose(do_info, fmt, ...) do { \
3503 + pr_info(fmt, ##__VA_ARGS__); \
3506 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3507 + aufs_bindex_t bbot)
3509 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3512 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3513 + aufs_bindex_t bbot)
3515 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3519 + * test if the branch is deletable or not.
3521 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3522 + unsigned int sigen, const unsigned int verbose)
3524 + int err, i, j, ndentry;
3525 + aufs_bindex_t btop, bbot;
3526 + struct au_dcsub_pages dpages;
3527 + struct au_dpage *dpage;
3530 + err = au_dpages_init(&dpages, GFP_NOFS);
3531 + if (unlikely(err))
3533 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3534 + if (unlikely(err))
3537 + for (i = 0; !err && i < dpages.ndpage; i++) {
3538 + dpage = dpages.dpages + i;
3539 + ndentry = dpage->ndentry;
3540 + for (j = 0; !err && j < ndentry; j++) {
3541 + d = dpage->dentries[j];
3542 + AuDebugOn(au_dcount(d) <= 0);
3543 + if (!au_digen_test(d, sigen)) {
3544 + di_read_lock_child(d, AuLock_IR);
3545 + if (unlikely(au_dbrange_test(d))) {
3546 + di_read_unlock(d, AuLock_IR);
3550 + di_write_lock_child(d);
3551 + if (unlikely(au_dbrange_test(d))) {
3552 + di_write_unlock(d);
3555 + err = au_reval_dpath(d, sigen);
3557 + di_downgrade_lock(d, AuLock_IR);
3559 + di_write_unlock(d);
3564 + /* AuDbgDentry(d); */
3565 + btop = au_dbtop(d);
3566 + bbot = au_dbbot(d);
3567 + if (btop <= bindex
3569 + && au_h_dptr(d, bindex)
3570 + && au_test_dbusy(d, btop, bbot)) {
3572 + AuVerbose(verbose, "busy %pd\n", d);
3575 + di_read_unlock(d, AuLock_IR);
3580 + au_dpages_free(&dpages);
3585 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3586 + unsigned int sigen, const unsigned int verbose)
3589 + unsigned long long max, ull;
3590 + struct inode *i, **array;
3591 + aufs_bindex_t btop, bbot;
3593 + array = au_iarray_alloc(sb, &max);
3594 + err = PTR_ERR(array);
3595 + if (IS_ERR(array))
3599 + AuDbg("b%d\n", bindex);
3600 + for (ull = 0; !err && ull < max; ull++) {
3604 + if (i->i_ino == AUFS_ROOT_INO)
3607 + /* AuDbgInode(i); */
3608 + if (au_iigen(i, NULL) == sigen)
3609 + ii_read_lock_child(i);
3611 + ii_write_lock_child(i);
3612 + err = au_refresh_hinode_self(i);
3615 + ii_downgrade_lock(i);
3617 + ii_write_unlock(i);
3622 + btop = au_ibtop(i);
3623 + bbot = au_ibbot(i);
3624 + if (btop <= bindex
3626 + && au_h_iptr(i, bindex)
3627 + && au_test_ibusy(i, btop, bbot)) {
3629 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3632 + ii_read_unlock(i);
3634 + au_iarray_free(array, max);
3640 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3641 + const unsigned int verbose)
3644 + unsigned int sigen;
3646 + sigen = au_sigen(root->d_sb);
3647 + DiMustNoWaiters(root);
3648 + IiMustNoWaiters(d_inode(root));
3649 + di_write_unlock(root);
3650 + err = test_dentry_busy(root, bindex, sigen, verbose);
3652 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3653 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3658 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3659 + struct file **to_free, int *idx)
3662 + unsigned char matched, root;
3663 + aufs_bindex_t bindex, bbot;
3664 + struct au_fidir *fidir;
3665 + struct au_hfile *hfile;
3668 + root = IS_ROOT(file->f_path.dentry);
3671 + to_free[*idx] = file;
3677 + fidir = au_fi(file)->fi_hdir;
3678 + AuDebugOn(!fidir);
3679 + bbot = au_fbbot_dir(file);
3680 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3681 + hfile = fidir->fd_hfile + bindex;
3682 + if (!hfile->hf_file)
3685 + if (hfile->hf_br->br_id == br_id) {
3697 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3698 + struct file **to_free, int opened)
3701 + unsigned long long ull, max;
3702 + aufs_bindex_t btop;
3703 + struct file *file, **array;
3704 + struct dentry *root;
3705 + struct au_hfile *hfile;
3707 + array = au_farray_alloc(sb, &max);
3708 + err = PTR_ERR(array);
3709 + if (IS_ERR(array))
3714 + root = sb->s_root;
3715 + di_write_unlock(root);
3716 + for (ull = 0; ull < max; ull++) {
3717 + file = array[ull];
3718 + if (unlikely(!file))
3721 + /* AuDbg("%pD\n", file); */
3722 + fi_read_lock(file);
3723 + btop = au_fbtop(file);
3724 + if (!d_is_dir(file->f_path.dentry)) {
3725 + hfile = &au_fi(file)->fi_htop;
3726 + if (hfile->hf_br->br_id == br_id)
3729 + err = test_dir_busy(file, br_id, to_free, &idx);
3730 + fi_read_unlock(file);
3731 + if (unlikely(err))
3734 + di_write_lock_child(root);
3735 + au_farray_free(array, max);
3736 + AuDebugOn(idx > opened);
3742 +static void br_del_file(struct file **to_free, unsigned long long opened,
3743 + aufs_bindex_t br_id)
3745 + unsigned long long ull;
3746 + aufs_bindex_t bindex, btop, bbot, bfound;
3747 + struct file *file;
3748 + struct au_fidir *fidir;
3749 + struct au_hfile *hfile;
3751 + for (ull = 0; ull < opened; ull++) {
3752 + file = to_free[ull];
3753 + if (unlikely(!file))
3756 + /* AuDbg("%pD\n", file); */
3757 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3759 + fidir = au_fi(file)->fi_hdir;
3760 + AuDebugOn(!fidir);
3761 + fi_write_lock(file);
3762 + btop = au_fbtop(file);
3763 + bbot = au_fbbot_dir(file);
3764 + for (bindex = btop; bindex <= bbot; bindex++) {
3765 + hfile = fidir->fd_hfile + bindex;
3766 + if (!hfile->hf_file)
3769 + if (hfile->hf_br->br_id == br_id) {
3774 + AuDebugOn(bfound < 0);
3775 + au_set_h_fptr(file, bfound, NULL);
3776 + if (bfound == btop) {
3777 + for (btop++; btop <= bbot; btop++)
3778 + if (au_hf_dir(file, btop)) {
3779 + au_set_fbtop(file, btop);
3783 + fi_write_unlock(file);
3787 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3788 + const aufs_bindex_t bindex,
3789 + const aufs_bindex_t bbot)
3791 + struct au_branch **brp, **p;
3793 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3795 + brp = sbinfo->si_branch + bindex;
3796 + if (bindex < bbot)
3797 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3798 + sbinfo->si_branch[0 + bbot] = NULL;
3799 + sbinfo->si_bbot--;
3801 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3804 + sbinfo->si_branch = p;
3805 + /* harmless error */
3808 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3809 + const aufs_bindex_t bbot)
3811 + struct au_hdentry *hdp, *p;
3813 + AuRwMustWriteLock(&dinfo->di_rwsem);
3815 + hdp = au_hdentry(dinfo, bindex);
3816 + if (bindex < bbot)
3817 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3818 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3821 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3824 + dinfo->di_hdentry = p;
3825 + /* harmless error */
3828 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3829 + const aufs_bindex_t bbot)
3831 + struct au_hinode *hip, *p;
3833 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3835 + hip = au_hinode(iinfo, bindex);
3836 + if (bindex < bbot)
3837 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3838 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3841 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3844 + iinfo->ii_hinode = p;
3845 + /* harmless error */
3848 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3849 + struct au_branch *br)
3851 + aufs_bindex_t bbot;
3852 + struct au_sbinfo *sbinfo;
3853 + struct dentry *root, *h_root;
3854 + struct inode *inode, *h_inode;
3855 + struct au_hinode *hinode;
3857 + SiMustWriteLock(sb);
3859 + root = sb->s_root;
3860 + inode = d_inode(root);
3861 + sbinfo = au_sbi(sb);
3862 + bbot = sbinfo->si_bbot;
3864 + h_root = au_h_dptr(root, bindex);
3865 + hinode = au_hi(inode, bindex);
3866 + h_inode = au_igrab(hinode->hi_inode);
3869 + au_sbilist_lock();
3870 + au_br_do_del_brp(sbinfo, bindex, bbot);
3871 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3872 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3873 + au_sbilist_unlock();
3877 + au_br_do_free(br);
3880 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3881 + unsigned long long max, void *arg)
3886 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3889 + unsigned long long opened;
3890 + unsigned int mnt_flags;
3891 + aufs_bindex_t bindex, bbot, br_id;
3892 + unsigned char do_wh, verbose;
3893 + struct au_branch *br;
3894 + struct au_wbr *wbr;
3895 + struct dentry *root;
3896 + struct file **to_free;
3901 + root = sb->s_root;
3902 + bindex = au_find_dbindex(root, del->h_path.dentry);
3905 + goto out; /* success */
3907 + pr_err("%s no such branch\n", del->pathname);
3910 + AuDbg("bindex b%d\n", bindex);
3913 + mnt_flags = au_mntflags(sb);
3914 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3915 + bbot = au_sbbot(sb);
3916 + if (unlikely(!bbot)) {
3917 + AuVerbose(verbose, "no more branches left\n");
3920 + br = au_sbr(sb, bindex);
3921 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3923 + br_id = br->br_id;
3924 + opened = au_br_count(br);
3925 + if (unlikely(opened)) {
3926 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3927 + err = PTR_ERR(to_free);
3928 + if (IS_ERR(to_free))
3931 + err = test_file_busy(sb, br_id, to_free, opened);
3932 + if (unlikely(err)) {
3933 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3939 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3941 + /* instead of WbrWhMustWriteLock(wbr) */
3942 + SiMustWriteLock(sb);
3943 + for (i = 0; i < AuBrWh_Last; i++) {
3944 + dput(wbr->wbr_wh[i]);
3945 + wbr->wbr_wh[i] = NULL;
3949 + err = test_children_busy(root, bindex, verbose);
3950 + if (unlikely(err)) {
3959 + * now we confirmed the branch is deletable.
3960 + * let's free the remaining opened dirs on the branch.
3962 + di_write_unlock(root);
3963 + br_del_file(to_free, opened, br_id);
3964 + di_write_lock_child(root);
3968 + au_br_do_del(sb, bindex, br);
3970 + sysaufs_brs_del(sb, bindex);
3971 + au_br_do_del(sb, bindex, br);
3972 + sysaufs_brs_add(sb, bindex);
3976 + au_cpup_attr_all(d_inode(root), /*force*/1);
3977 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3979 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3980 + if (au_opt_test(mnt_flags, PLINK))
3981 + au_plink_half_refresh(sb, br_id);
3983 + if (au_xino_brid(sb) == br_id)
3984 + au_xino_brid_set(sb, -1);
3985 + goto out; /* success */
3989 + rerr = au_br_init_wh(sb, br, br->br_perm);
3991 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3992 + del->pathname, rerr);
3995 + au_farray_free(to_free, opened);
3999 +/* ---------------------------------------------------------------------- */
4001 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4004 + aufs_bindex_t btop, bbot;
4005 + struct aufs_ibusy ibusy;
4006 + struct inode *inode, *h_inode;
4009 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4012 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4014 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4015 + if (unlikely(err)) {
4022 + si_read_lock(sb, AuLock_FLUSH);
4023 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4027 + ibusy.h_ino = 0; /* invalid */
4028 + inode = ilookup(sb, ibusy.ino);
4030 + || inode->i_ino == AUFS_ROOT_INO
4031 + || au_is_bad_inode(inode))
4034 + ii_read_lock_child(inode);
4035 + btop = au_ibtop(inode);
4036 + bbot = au_ibbot(inode);
4037 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4038 + h_inode = au_h_iptr(inode, ibusy.bindex);
4039 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4040 + ibusy.h_ino = h_inode->i_ino;
4042 + ii_read_unlock(inode);
4046 + si_read_unlock(sb);
4048 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4049 + if (unlikely(err)) {
4058 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4060 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4063 +#ifdef CONFIG_COMPAT
4064 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4066 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4070 +/* ---------------------------------------------------------------------- */
4073 + * change a branch permission
4076 +static void au_warn_ima(void)
4079 + /* since it doesn't support mark_files_ro() */
4080 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4084 +static int do_need_sigen_inc(int a, int b)
4086 + return au_br_whable(a) && !au_br_whable(b);
4089 +static int need_sigen_inc(int old, int new)
4091 + return do_need_sigen_inc(old, new)
4092 + || do_need_sigen_inc(new, old);
4095 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4098 + unsigned int mnt_flags;
4099 + unsigned long long ull, max;
4100 + aufs_bindex_t br_id;
4101 + unsigned char verbose, writer;
4102 + struct file *file, *hf, **array;
4103 + struct au_hfile *hfile;
4105 + mnt_flags = au_mntflags(sb);
4106 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4108 + array = au_farray_alloc(sb, &max);
4109 + err = PTR_ERR(array);
4110 + if (IS_ERR(array))
4114 + br_id = au_sbr_id(sb, bindex);
4115 + for (ull = 0; ull < max; ull++) {
4116 + file = array[ull];
4117 + if (unlikely(!file))
4120 + /* AuDbg("%pD\n", file); */
4121 + fi_read_lock(file);
4122 + if (unlikely(au_test_mmapped(file))) {
4124 + AuVerbose(verbose, "mmapped %pD\n", file);
4126 + FiMustNoWaiters(file);
4127 + fi_read_unlock(file);
4131 + hfile = &au_fi(file)->fi_htop;
4132 + hf = hfile->hf_file;
4133 + if (!d_is_reg(file->f_path.dentry)
4134 + || !(file->f_mode & FMODE_WRITE)
4135 + || hfile->hf_br->br_id != br_id
4136 + || !(hf->f_mode & FMODE_WRITE))
4137 + array[ull] = NULL;
4143 + FiMustNoWaiters(file);
4144 + fi_read_unlock(file);
4152 + for (ull = 0; ull < max; ull++) {
4153 + file = array[ull];
4157 + /* todo: already flushed? */
4159 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4160 + * approach which resets f_mode and calls mnt_drop_write() and
4161 + * file_release_write() for each file, because the branch
4162 + * attribute in aufs world is totally different from the native
4165 + /* fi_read_lock(file); */
4166 + hfile = &au_fi(file)->fi_htop;
4167 + hf = hfile->hf_file;
4168 + /* fi_read_unlock(file); */
4169 + spin_lock(&hf->f_lock);
4170 + writer = !!(hf->f_mode & FMODE_WRITER);
4171 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4172 + spin_unlock(&hf->f_lock);
4174 + put_write_access(file_inode(hf));
4175 + __mnt_drop_write(hf->f_path.mnt);
4180 + au_farray_free(array, max);
4186 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4190 + aufs_bindex_t bindex;
4191 + struct dentry *root;
4192 + struct au_branch *br;
4193 + struct au_br_fhsm *bf;
4195 + root = sb->s_root;
4196 + bindex = au_find_dbindex(root, mod->h_root);
4199 + return 0; /* success */
4201 + pr_err("%s no such branch\n", mod->path);
4204 + AuDbg("bindex b%d\n", bindex);
4206 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4207 + if (unlikely(err))
4210 + br = au_sbr(sb, bindex);
4211 + AuDebugOn(mod->h_root != au_br_dentry(br));
4212 + if (br->br_perm == mod->perm)
4213 + return 0; /* success */
4215 + /* pre-allocate for non-fhsm --> fhsm */
4217 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4218 + err = au_fhsm_br_alloc(br);
4219 + if (unlikely(err))
4222 + br->br_fhsm = NULL;
4225 + if (au_br_writable(br->br_perm)) {
4226 + /* remove whiteout base */
4227 + err = au_br_init_wh(sb, br, mod->perm);
4228 + if (unlikely(err))
4231 + if (!au_br_writable(mod->perm)) {
4232 + /* rw --> ro, file might be mmapped */
4233 + DiMustNoWaiters(root);
4234 + IiMustNoWaiters(d_inode(root));
4235 + di_write_unlock(root);
4236 + err = au_br_mod_files_ro(sb, bindex);
4237 + /* aufs_write_lock() calls ..._child() */
4238 + di_write_lock_child(root);
4240 + if (unlikely(err)) {
4242 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4245 + rerr = au_wbr_init(br, sb, br->br_perm);
4246 + if (unlikely(rerr)) {
4247 + AuIOErr("nested error %d (%d)\n",
4249 + br->br_perm = mod->perm;
4253 + } else if (au_br_writable(mod->perm)) {
4256 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4258 + err = au_wbr_init(br, sb, mod->perm);
4259 + if (unlikely(err)) {
4260 + kfree(br->br_wbr);
4261 + br->br_wbr = NULL;
4265 + if (unlikely(err))
4268 + if (au_br_fhsm(br->br_perm)) {
4269 + if (!au_br_fhsm(mod->perm)) {
4270 + /* fhsm --> non-fhsm */
4271 + au_br_fhsm_fin(br->br_fhsm);
4272 + kfree(br->br_fhsm);
4273 + br->br_fhsm = NULL;
4275 + } else if (au_br_fhsm(mod->perm))
4276 + /* non-fhsm --> fhsm */
4279 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4280 + br->br_perm = mod->perm;
4281 + goto out; /* success */
4291 +/* ---------------------------------------------------------------------- */
4293 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4296 + struct kstatfs kstfs;
4298 + err = vfs_statfs(&br->br_path, &kstfs);
4300 + stfs->f_blocks = kstfs.f_blocks;
4301 + stfs->f_bavail = kstfs.f_bavail;
4302 + stfs->f_files = kstfs.f_files;
4303 + stfs->f_ffree = kstfs.f_ffree;
4308 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4309 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4310 +++ linux/fs/aufs/branch.h 2017-07-29 12:14:25.896375188 +0200
4313 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4315 + * This program, aufs is free software; you can redistribute it and/or modify
4316 + * it under the terms of the GNU General Public License as published by
4317 + * the Free Software Foundation; either version 2 of the License, or
4318 + * (at your option) any later version.
4320 + * This program is distributed in the hope that it will be useful,
4321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4323 + * GNU General Public License for more details.
4325 + * You should have received a copy of the GNU General Public License
4326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4330 + * branch filesystems and xino for them
4333 +#ifndef __AUFS_BRANCH_H__
4334 +#define __AUFS_BRANCH_H__
4338 +#include <linux/mount.h>
4343 +/* ---------------------------------------------------------------------- */
4346 +struct au_xino_file {
4347 + struct file *xi_file;
4352 + /* reserved for future use */
4353 + /* unsigned long *bitmap; */
4354 + wait_queue_head_t wqh;
4357 + /* todo: make xino files an array to support huge inode number */
4359 +#ifdef CONFIG_DEBUG_FS
4360 + struct dentry *xi_dbgaufs;
4364 +/* File-based Hierarchical Storage Management */
4365 +struct au_br_fhsm {
4366 +#ifdef CONFIG_AUFS_FHSM
4367 + struct mutex bf_lock;
4368 + unsigned long bf_jiffy;
4369 + struct aufs_stfs bf_stfs;
4374 +/* members for writable branch only */
4375 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4377 + struct au_rwsem wbr_wh_rwsem;
4378 + struct dentry *wbr_wh[AuBrWh_Last];
4379 + atomic_t wbr_wh_running;
4380 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4381 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4382 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4385 + unsigned long long wbr_bytes;
4388 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4389 +#define AuBrDynOp (AuDyLast * 4)
4391 +#ifdef CONFIG_AUFS_HFSNOTIFY
4392 +/* support for asynchronous destruction */
4393 +struct au_br_hfsnotify {
4394 + struct fsnotify_group *hfsn_group;
4398 +/* sysfs entries */
4399 +struct au_brsysfs {
4401 + struct attribute attr;
4410 +/* protected by superblock rwsem */
4412 + struct au_xino_file br_xino;
4414 + aufs_bindex_t br_id;
4417 + struct path br_path;
4418 + spinlock_t br_dykey_lock;
4419 + struct au_dykey *br_dykey[AuBrDynOp];
4420 + struct percpu_counter br_count;
4422 + struct au_wbr *br_wbr;
4423 + struct au_br_fhsm *br_fhsm;
4425 + /* xino truncation */
4426 + atomic_t br_xino_running;
4428 +#ifdef CONFIG_AUFS_HFSNOTIFY
4429 + struct au_br_hfsnotify *br_hfsn;
4432 +#ifdef CONFIG_SYSFS
4433 + /* entries under sysfs per mount-point */
4434 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4438 +/* ---------------------------------------------------------------------- */
4440 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4442 + return br->br_path.mnt;
4445 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4447 + return br->br_path.dentry;
4450 +static inline struct super_block *au_br_sb(struct au_branch *br)
4452 + return au_br_mnt(br)->mnt_sb;
4455 +static inline void au_br_get(struct au_branch *br)
4457 + percpu_counter_inc(&br->br_count);
4460 +static inline void au_br_put(struct au_branch *br)
4462 + percpu_counter_dec(&br->br_count);
4465 +static inline s64 au_br_count(struct au_branch *br)
4467 + return percpu_counter_sum(&br->br_count);
4470 +static inline void au_br_count_init(struct au_branch *br)
4472 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4475 +static inline void au_br_count_fin(struct au_branch *br)
4477 + percpu_counter_destroy(&br->br_count);
4480 +static inline int au_br_rdonly(struct au_branch *br)
4482 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4483 + || !au_br_writable(br->br_perm))
4487 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4489 +#ifdef CONFIG_AUFS_HNOTIFY
4490 + return !(brperm & AuBrPerm_RR);
4496 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4498 + int err, exec_flag;
4501 + exec_flag = oflag & __FMODE_EXEC;
4502 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4508 +/* ---------------------------------------------------------------------- */
4512 +void au_br_free(struct au_sbinfo *sinfo);
4513 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4515 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4517 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4518 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4519 +#ifdef CONFIG_COMPAT
4520 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4523 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4526 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4529 +static const loff_t au_loff_max = LLONG_MAX;
4531 +int au_xib_trunc(struct super_block *sb);
4532 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4534 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4535 + size_t size, loff_t *pos);
4536 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4537 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4538 +ino_t au_xino_new_ino(struct super_block *sb);
4539 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4540 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4542 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4544 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4545 + struct file *base_file, int do_test);
4546 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4548 +struct au_opt_xino;
4549 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4550 +void au_xino_clr(struct super_block *sb);
4551 +struct file *au_xino_def(struct super_block *sb);
4552 +int au_xino_path(struct seq_file *seq, struct file *file);
4554 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4555 + ino_t h_ino, int idx);
4556 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4559 +/* ---------------------------------------------------------------------- */
4561 +/* Superblock to branch */
4563 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4565 + return au_sbr(sb, bindex)->br_id;
4569 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4571 + return au_br_mnt(au_sbr(sb, bindex));
4575 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4577 + return au_br_sb(au_sbr(sb, bindex));
4580 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4582 + au_br_get(au_sbr(sb, bindex));
4585 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4587 + au_br_put(au_sbr(sb, bindex));
4590 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4592 + return au_sbr(sb, bindex)->br_perm;
4595 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4597 + return au_br_whable(au_sbr_perm(sb, bindex));
4600 +/* ---------------------------------------------------------------------- */
4603 + * wbr_wh_read_lock, wbr_wh_write_lock
4604 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4606 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4608 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4609 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4610 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4612 +/* ---------------------------------------------------------------------- */
4614 +#ifdef CONFIG_AUFS_FHSM
4615 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4617 + mutex_init(&brfhsm->bf_lock);
4618 + brfhsm->bf_jiffy = 0;
4619 + brfhsm->bf_readable = 0;
4622 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4624 + mutex_destroy(&brfhsm->bf_lock);
4627 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4628 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4631 +#endif /* __KERNEL__ */
4632 +#endif /* __AUFS_BRANCH_H__ */
4633 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4634 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4635 +++ linux/fs/aufs/conf.mk 2017-07-29 12:14:25.899708630 +0200
4638 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4642 +AuConfStr += ${1}=${${1}}
4646 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4648 + HNOTIFY HFSNOTIFY \
4659 +$(foreach i, ${AuConfAll}, \
4660 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4662 +AuConfName = ${obj}/conf.str
4663 +${AuConfName}.tmp: FORCE
4664 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4665 +${AuConfName}: ${AuConfName}.tmp
4666 + @diff -q $< $@ > /dev/null 2>&1 || { \
4667 + echo ' GEN ' $@; \
4671 +clean-files += ${AuConfName} ${AuConfName}.tmp
4672 +${obj}/sysfs.o: ${AuConfName}
4674 +-include ${srctree}/${src}/conf_priv.mk
4675 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4676 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4677 +++ linux/fs/aufs/cpup.c 2017-09-05 10:42:11.055421928 +0200
4680 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4682 + * This program, aufs is free software; you can redistribute it and/or modify
4683 + * it under the terms of the GNU General Public License as published by
4684 + * the Free Software Foundation; either version 2 of the License, or
4685 + * (at your option) any later version.
4687 + * This program is distributed in the hope that it will be useful,
4688 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4689 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4690 + * GNU General Public License for more details.
4692 + * You should have received a copy of the GNU General Public License
4693 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4697 + * copy-up functions, see wbr_policy.c for copy-down
4700 +#include <linux/fs_stack.h>
4701 +#include <linux/mm.h>
4702 +#include <linux/task_work.h>
4705 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4707 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4708 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4710 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4712 + dst->i_flags |= iflags & ~mask;
4713 + if (au_test_fs_notime(dst->i_sb))
4714 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4717 +void au_cpup_attr_timesizes(struct inode *inode)
4719 + struct inode *h_inode;
4721 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4722 + fsstack_copy_attr_times(inode, h_inode);
4723 + fsstack_copy_inode_size(inode, h_inode);
4726 +void au_cpup_attr_nlink(struct inode *inode, int force)
4728 + struct inode *h_inode;
4729 + struct super_block *sb;
4730 + aufs_bindex_t bindex, bbot;
4733 + bindex = au_ibtop(inode);
4734 + h_inode = au_h_iptr(inode, bindex);
4736 + && !S_ISDIR(h_inode->i_mode)
4737 + && au_opt_test(au_mntflags(sb), PLINK)
4738 + && au_plink_test(inode))
4742 + * 0 can happen in revalidating.
4743 + * h_inode->i_mutex may not be held here, but it is harmless since once
4744 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4746 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4747 + * the incorrect link count.
4749 + set_nlink(inode, h_inode->i_nlink);
4752 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4753 + * it may includes whplink directory.
4755 + if (S_ISDIR(h_inode->i_mode)) {
4756 + bbot = au_ibbot(inode);
4757 + for (bindex++; bindex <= bbot; bindex++) {
4758 + h_inode = au_h_iptr(inode, bindex);
4760 + au_add_nlink(inode, h_inode);
4765 +void au_cpup_attr_changeable(struct inode *inode)
4767 + struct inode *h_inode;
4769 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4770 + inode->i_mode = h_inode->i_mode;
4771 + inode->i_uid = h_inode->i_uid;
4772 + inode->i_gid = h_inode->i_gid;
4773 + au_cpup_attr_timesizes(inode);
4774 + au_cpup_attr_flags(inode, h_inode->i_flags);
4777 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4779 + struct au_iinfo *iinfo = au_ii(inode);
4781 + IiMustWriteLock(inode);
4783 + iinfo->ii_higen = h_inode->i_generation;
4784 + iinfo->ii_hsb1 = h_inode->i_sb;
4787 +void au_cpup_attr_all(struct inode *inode, int force)
4789 + struct inode *h_inode;
4791 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4792 + au_cpup_attr_changeable(inode);
4793 + if (inode->i_nlink > 0)
4794 + au_cpup_attr_nlink(inode, force);
4795 + inode->i_rdev = h_inode->i_rdev;
4796 + inode->i_blkbits = h_inode->i_blkbits;
4797 + au_cpup_igen(inode, h_inode);
4800 +/* ---------------------------------------------------------------------- */
4802 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4804 +/* keep the timestamps of the parent dir when cpup */
4805 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4806 + struct path *h_path)
4808 + struct inode *h_inode;
4810 + dt->dt_dentry = dentry;
4811 + dt->dt_h_path = *h_path;
4812 + h_inode = d_inode(h_path->dentry);
4813 + dt->dt_atime = h_inode->i_atime;
4814 + dt->dt_mtime = h_inode->i_mtime;
4818 +void au_dtime_revert(struct au_dtime *dt)
4820 + struct iattr attr;
4823 + attr.ia_atime = dt->dt_atime;
4824 + attr.ia_mtime = dt->dt_mtime;
4825 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4826 + | ATTR_ATIME | ATTR_ATIME_SET;
4828 + /* no delegation since this is a directory */
4829 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4830 + if (unlikely(err))
4831 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4834 +/* ---------------------------------------------------------------------- */
4836 +/* internal use only */
4837 +struct au_cpup_reg_attr {
4840 + unsigned int iflags; /* inode->i_flags */
4843 +static noinline_for_stack
4844 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4845 + struct au_cpup_reg_attr *h_src_attr)
4847 + int err, sbits, icex;
4848 + unsigned int mnt_flags;
4849 + unsigned char verbose;
4851 + struct path h_path;
4852 + struct inode *h_isrc, *h_idst;
4853 + struct kstat *h_st;
4854 + struct au_branch *br;
4856 + h_path.dentry = au_h_dptr(dst, bindex);
4857 + h_idst = d_inode(h_path.dentry);
4858 + br = au_sbr(dst->d_sb, bindex);
4859 + h_path.mnt = au_br_mnt(br);
4860 + h_isrc = d_inode(h_src);
4861 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4862 + | ATTR_ATIME | ATTR_MTIME
4863 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4864 + if (h_src_attr && h_src_attr->valid) {
4865 + h_st = &h_src_attr->st;
4866 + ia.ia_uid = h_st->uid;
4867 + ia.ia_gid = h_st->gid;
4868 + ia.ia_atime = h_st->atime;
4869 + ia.ia_mtime = h_st->mtime;
4870 + if (h_idst->i_mode != h_st->mode
4871 + && !S_ISLNK(h_idst->i_mode)) {
4872 + ia.ia_valid |= ATTR_MODE;
4873 + ia.ia_mode = h_st->mode;
4875 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4876 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4878 + ia.ia_uid = h_isrc->i_uid;
4879 + ia.ia_gid = h_isrc->i_gid;
4880 + ia.ia_atime = h_isrc->i_atime;
4881 + ia.ia_mtime = h_isrc->i_mtime;
4882 + if (h_idst->i_mode != h_isrc->i_mode
4883 + && !S_ISLNK(h_idst->i_mode)) {
4884 + ia.ia_valid |= ATTR_MODE;
4885 + ia.ia_mode = h_isrc->i_mode;
4887 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4888 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4890 + /* no delegation since it is just created */
4891 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4893 + /* is this nfs only? */
4894 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4895 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4896 + ia.ia_mode = h_isrc->i_mode;
4897 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4900 + icex = br->br_perm & AuBrAttr_ICEX;
4902 + mnt_flags = au_mntflags(dst->d_sb);
4903 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4904 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4910 +/* ---------------------------------------------------------------------- */
4912 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4913 + char *buf, unsigned long blksize)
4916 + size_t sz, rbytes, wbytes;
4917 + unsigned char all_zero;
4919 + struct inode *h_inode;
4920 + /* reduce stack usage */
4923 + zp = page_address(ZERO_PAGE(0));
4924 + if (unlikely(!zp))
4925 + return -ENOMEM; /* possible? */
4930 + AuDbg("len %lld\n", len);
4932 + if (len < blksize)
4936 + /* todo: signal_pending? */
4937 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4938 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4941 + if (unlikely(err < 0))
4945 + if (len >= rbytes && rbytes == blksize)
4946 + all_zero = !memcmp(buf, zp, rbytes);
4953 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4955 + /* todo: signal_pending? */
4956 + if (unlikely(err == -EAGAIN || err == -EINTR))
4958 + if (unlikely(err < 0))
4963 + if (unlikely(err < 0))
4969 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4971 + if (unlikely(res < 0))
4978 + /* the last block may be a hole */
4979 + if (!err && all_zero) {
4980 + AuLabel(last hole);
4983 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4984 + /* nfs requires this step to make last hole */
4985 + /* is this only nfs? */
4987 + /* todo: signal_pending? */
4988 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4989 + } while (err == -EAGAIN || err == -EINTR);
4996 + ia->ia_size = dst->f_pos;
4997 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4998 + ia->ia_file = dst;
4999 + h_inode = file_inode(dst);
5000 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5001 + /* no delegation since it is just created */
5002 + err = vfsub_notify_change(&dst->f_path, ia,
5003 + /*delegated*/NULL);
5004 + inode_unlock(h_inode);
5011 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5014 + unsigned long blksize;
5015 + unsigned char do_kfree;
5019 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5020 + if (!blksize || PAGE_SIZE < blksize)
5021 + blksize = PAGE_SIZE;
5022 + AuDbg("blksize %lu\n", blksize);
5023 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5025 + buf = kmalloc(blksize, GFP_NOFS);
5027 + buf = (void *)__get_free_page(GFP_NOFS);
5028 + if (unlikely(!buf))
5031 + if (len > (1 << 22))
5032 + AuDbg("copying a large file %lld\n", (long long)len);
5036 + err = au_do_copy_file(dst, src, len, buf, blksize);
5040 + free_page((unsigned long)buf);
5046 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5049 + struct super_block *h_src_sb;
5050 + struct inode *h_src_inode;
5052 + h_src_inode = file_inode(src);
5053 + h_src_sb = h_src_inode->i_sb;
5055 + /* XFS acquires inode_lock */
5056 + if (!au_test_xfs(h_src_sb))
5057 + err = au_copy_file(dst, src, len);
5059 + inode_unlock_shared(h_src_inode);
5060 + err = au_copy_file(dst, src, len);
5061 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5067 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5070 + struct super_block *h_src_sb;
5071 + struct inode *h_src_inode;
5073 + h_src_inode = file_inode(src);
5074 + h_src_sb = h_src_inode->i_sb;
5075 + if (h_src_sb != file_inode(dst)->i_sb
5076 + || !dst->f_op->clone_file_range) {
5077 + err = au_do_copy(dst, src, len);
5081 + if (!au_test_nfs(h_src_sb)) {
5082 + inode_unlock_shared(h_src_inode);
5083 + err = vfsub_clone_file_range(src, dst, len);
5084 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5086 + err = vfsub_clone_file_range(src, dst, len);
5087 + /* older XFS has a condition in cloning */
5088 + if (unlikely(err != -EOPNOTSUPP))
5091 + /* the backend fs on NFS may not support cloning */
5092 + err = au_do_copy(dst, src, len);
5100 + * to support a sparse file which is opened with O_APPEND,
5101 + * we need to close the file.
5103 +static int au_cp_regular(struct au_cp_generic *cpg)
5106 + enum { SRC, DST };
5108 + aufs_bindex_t bindex;
5109 + unsigned int flags;
5110 + struct dentry *dentry;
5112 + struct file *file;
5116 + .bindex = cpg->bsrc,
5117 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5121 + .bindex = cpg->bdst,
5122 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5123 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5124 + .label = &&out_src
5127 + struct super_block *sb, *h_src_sb;
5128 + struct inode *h_src_inode;
5129 + struct task_struct *tsk = current;
5131 + /* bsrc branch can be ro/rw. */
5132 + sb = cpg->dentry->d_sb;
5134 + for (i = 0; i < 2; i++, f++) {
5135 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5136 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5137 + /*file*/NULL, f->force_wr);
5138 + err = PTR_ERR(f->file);
5139 + if (IS_ERR(f->file))
5143 + /* try stopping to update while we copyup */
5144 + h_src_inode = d_inode(file[SRC].dentry);
5145 + h_src_sb = h_src_inode->i_sb;
5146 + if (!au_test_nfs(h_src_sb))
5147 + IMustLock(h_src_inode);
5148 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5150 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5151 + if (tsk->flags & PF_KTHREAD)
5152 + __fput_sync(file[DST].file);
5154 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5156 + fput(file[DST].file);
5159 + * we have to call both since we don't know which place the file
5163 + flush_delayed_fput();
5165 + au_sbr_put(sb, file[DST].bindex);
5168 + fput(file[SRC].file);
5169 + au_sbr_put(sb, file[SRC].bindex);
5174 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5175 + struct au_cpup_reg_attr *h_src_attr)
5179 + struct path h_path;
5180 + struct inode *h_src_inode, *h_dst_inode;
5183 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5184 + l = i_size_read(h_src_inode);
5185 + if (cpg->len == -1 || l < cpg->len)
5188 + /* try stopping to update while we are referencing */
5189 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5190 + au_pin_hdir_unlock(cpg->pin);
5192 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5193 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5194 + h_src_attr->iflags = h_src_inode->i_flags;
5195 + if (!au_test_nfs(h_src_inode->i_sb))
5196 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5198 + inode_unlock_shared(h_src_inode);
5199 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5200 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5202 + if (unlikely(err)) {
5203 + inode_unlock_shared(h_src_inode);
5206 + h_src_attr->valid = 1;
5207 + if (!au_test_nfs(h_src_inode->i_sb)) {
5208 + err = au_cp_regular(cpg);
5209 + inode_unlock_shared(h_src_inode);
5211 + inode_unlock_shared(h_src_inode);
5212 + err = au_cp_regular(cpg);
5214 + rerr = au_pin_hdir_relock(cpg->pin);
5218 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5219 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5220 + h_dst_inode = d_inode(h_path.dentry);
5221 + spin_lock(&h_dst_inode->i_lock);
5222 + h_dst_inode->i_state |= I_LINKABLE;
5223 + spin_unlock(&h_dst_inode->i_lock);
5230 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5231 + struct inode *h_dir)
5234 + mm_segment_t old_fs;
5241 + sym.k = (void *)__get_free_page(GFP_NOFS);
5242 + if (unlikely(!sym.k))
5245 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5246 + old_fs = get_fs();
5247 + set_fs(KERNEL_DS);
5248 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5253 + sym.k[symlen] = 0;
5254 + err = vfsub_symlink(h_dir, h_path, sym.k);
5256 + free_page((unsigned long)sym.k);
5263 + * regardless 'acl' option, reset all ACL.
5264 + * All ACL will be copied up later from the original entry on the lower branch.
5266 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5269 + struct dentry *h_dentry;
5270 + struct inode *h_inode;
5272 + h_dentry = h_path->dentry;
5273 + h_inode = d_inode(h_dentry);
5274 + /* forget_all_cached_acls(h_inode)); */
5275 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5277 + if (err == -EOPNOTSUPP)
5280 + err = vfsub_acl_chmod(h_inode, mode);
5286 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5287 + struct inode *h_dir, struct path *h_path)
5290 + struct inode *dir, *inode;
5292 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5294 + if (err == -EOPNOTSUPP)
5296 + if (unlikely(err))
5300 + * strange behaviour from the users view,
5301 + * particularry setattr case
5303 + dir = d_inode(dst_parent);
5304 + if (au_ibtop(dir) == cpg->bdst)
5305 + au_cpup_attr_nlink(dir, /*force*/1);
5306 + inode = d_inode(cpg->dentry);
5307 + au_cpup_attr_nlink(inode, /*force*/1);
5313 +static noinline_for_stack
5314 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5315 + struct au_cpup_reg_attr *h_src_attr)
5319 + unsigned int mnt_flags;
5320 + unsigned char isdir, isreg, force;
5321 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5322 + struct au_dtime dt;
5323 + struct path h_path;
5324 + struct dentry *h_src, *h_dst, *h_parent;
5325 + struct inode *h_inode, *h_dir;
5326 + struct super_block *sb;
5328 + /* bsrc branch can be ro/rw. */
5329 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5330 + h_inode = d_inode(h_src);
5331 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5333 + /* try stopping to be referenced while we are creating */
5334 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5335 + if (au_ftest_cpup(cpg->flags, RENAME))
5336 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5337 + AUFS_WH_PFX_LEN));
5338 + h_parent = h_dst->d_parent; /* dir inode is locked */
5339 + h_dir = d_inode(h_parent);
5341 + AuDebugOn(h_parent != h_dst->d_parent);
5343 + sb = cpg->dentry->d_sb;
5344 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5346 + h_path.dentry = h_parent;
5347 + au_dtime_store(&dt, dst_parent, &h_path);
5349 + h_path.dentry = h_dst;
5353 + mode = h_inode->i_mode;
5354 + switch (mode & S_IFMT) {
5357 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5358 + /*want_excl*/true);
5360 + err = au_do_cpup_regular(cpg, h_src_attr);
5364 + err = vfsub_mkdir(h_dir, &h_path, mode);
5366 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5369 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5373 + AuDebugOn(!capable(CAP_MKNOD));
5377 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5380 + AuIOErr("Unknown inode type 0%o\n", mode);
5384 + err = au_reset_acl(h_dir, &h_path, mode);
5386 + mnt_flags = au_mntflags(sb);
5387 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5389 + && au_opt_test(mnt_flags, XINO)
5390 + && (h_inode->i_nlink == 1
5391 + || (h_inode->i_state & I_LINKABLE))
5392 + /* todo: unnecessary? */
5393 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5394 + && cpg->bdst < cpg->bsrc
5395 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5396 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5397 + /* ignore this error */
5402 + force = !!cpg->len;
5403 + if (cpg->len == -1)
5404 + force = !!i_size_read(h_inode);
5406 + au_fhsm_wrote(sb, cpg->bdst, force);
5410 + au_dtime_revert(&dt);
5414 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5417 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5418 + struct inode *h_dir;
5419 + aufs_bindex_t bdst;
5421 + dentry = cpg->dentry;
5423 + h_dentry = au_h_dptr(dentry, bdst);
5424 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5426 + au_set_h_dptr(dentry, bdst, NULL);
5427 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5429 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5430 + au_set_h_dptr(dentry, bdst, h_dentry);
5433 + parent = dget_parent(dentry);
5434 + h_parent = au_h_dptr(parent, bdst);
5436 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5437 + if (IS_ERR(h_path->dentry))
5438 + err = PTR_ERR(h_path->dentry);
5440 + if (unlikely(err))
5443 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5444 + h_dir = d_inode(h_parent);
5446 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5447 + /* no delegation since it is just created */
5448 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5450 + dput(h_path->dentry);
5457 + * copyup the @dentry from @bsrc to @bdst.
5458 + * the caller must set the both of lower dentries.
5459 + * @len is for truncating when it is -1 copyup the entire file.
5460 + * in link/rename cases, @dst_parent may be different from the real one.
5461 + * basic->bsrc can be larger than basic->bdst.
5462 + * aufs doesn't touch the credential so
5463 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5465 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5468 + aufs_bindex_t old_ibtop;
5469 + unsigned char isdir, plink;
5470 + struct dentry *h_src, *h_dst, *h_parent;
5471 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5472 + struct super_block *sb;
5473 + struct au_branch *br;
5474 + /* to reuduce stack size */
5476 + struct au_dtime dt;
5477 + struct path h_path;
5478 + struct au_cpup_reg_attr h_src_attr;
5482 + a = kmalloc(sizeof(*a), GFP_NOFS);
5485 + a->h_src_attr.valid = 0;
5487 + sb = cpg->dentry->d_sb;
5488 + br = au_sbr(sb, cpg->bdst);
5489 + a->h_path.mnt = au_br_mnt(br);
5490 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5491 + h_parent = h_dst->d_parent; /* dir inode is locked */
5492 + h_dir = d_inode(h_parent);
5495 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5496 + inode = d_inode(cpg->dentry);
5499 + dst_parent = dget_parent(cpg->dentry);
5503 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5504 + dst_inode = au_h_iptr(inode, cpg->bdst);
5506 + if (unlikely(!plink)) {
5508 + AuIOErr("hi%lu(i%lu) exists on b%d "
5509 + "but plink is disabled\n",
5510 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5514 + if (dst_inode->i_nlink) {
5515 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5517 + h_src = au_plink_lkup(inode, cpg->bdst);
5518 + err = PTR_ERR(h_src);
5519 + if (IS_ERR(h_src))
5521 + if (unlikely(d_is_negative(h_src))) {
5523 + AuIOErr("i%lu exists on b%d "
5524 + "but not pseudo-linked\n",
5525 + inode->i_ino, cpg->bdst);
5531 + a->h_path.dentry = h_parent;
5532 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5535 + a->h_path.dentry = h_dst;
5537 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5538 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5539 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5541 + au_dtime_revert(&a->dt);
5542 + if (unlikely(err == -EWOULDBLOCK)) {
5543 + pr_warn("cannot retry for NFSv4 delegation"
5544 + " for an internal link\n");
5550 + /* todo: cpup_wh_file? */
5552 + au_update_ibrange(inode, /*do_put_zero*/1);
5555 + isdir = S_ISDIR(inode->i_mode);
5556 + old_ibtop = au_ibtop(inode);
5557 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5558 + if (unlikely(err))
5560 + dst_inode = d_inode(h_dst);
5561 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5562 + /* todo: necessary? */
5563 + /* au_pin_hdir_unlock(cpg->pin); */
5565 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5566 + if (unlikely(err)) {
5567 + /* todo: necessary? */
5568 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5569 + inode_unlock(dst_inode);
5573 + if (cpg->bdst < old_ibtop) {
5574 + if (S_ISREG(inode->i_mode)) {
5575 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5576 + if (unlikely(err)) {
5577 + /* ignore an error */
5578 + /* au_pin_hdir_relock(cpg->pin); */
5579 + inode_unlock(dst_inode);
5583 + au_set_ibtop(inode, cpg->bdst);
5585 + au_set_ibbot(inode, cpg->bdst);
5586 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5587 + au_hi_flags(inode, isdir));
5589 + /* todo: necessary? */
5590 + /* err = au_pin_hdir_relock(cpg->pin); */
5591 + inode_unlock(dst_inode);
5592 + if (unlikely(err))
5595 + src_inode = d_inode(h_src);
5597 + && (src_inode->i_nlink > 1
5598 + || src_inode->i_state & I_LINKABLE)
5600 + au_plink_append(inode, cpg->bdst, h_dst);
5602 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5603 + a->h_path.dentry = h_dst;
5604 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5607 + goto out_parent; /* success */
5611 + a->h_path.dentry = h_parent;
5612 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5613 + a->h_path.dentry = h_dst;
5615 + if (d_is_positive(h_dst)) {
5617 + /* no delegation since it is just created */
5618 + rerr = vfsub_unlink(h_dir, &a->h_path,
5619 + /*delegated*/NULL, /*force*/0);
5621 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5623 + au_dtime_revert(&a->dt);
5625 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5635 +#if 0 /* reserved */
5636 +struct au_cpup_single_args {
5638 + struct au_cp_generic *cpg;
5639 + struct dentry *dst_parent;
5642 +static void au_call_cpup_single(void *args)
5644 + struct au_cpup_single_args *a = args;
5646 + au_pin_hdir_acquire_nest(a->cpg->pin);
5647 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5648 + au_pin_hdir_release(a->cpg->pin);
5653 + * prevent SIGXFSZ in copy-up.
5654 + * testing CAP_MKNOD is for generic fs,
5655 + * but CAP_FSETID is for xfs only, currently.
5657 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5660 + struct super_block *sb;
5661 + struct inode *h_dir;
5664 + sb = au_pinned_parent(pin)->d_sb;
5665 + if (!au_wkq_test()
5666 + && (!au_sbi(sb)->si_plink_maint_pid
5667 + || au_plink_maint(sb, AuLock_NOPLM))) {
5668 + switch (mode & S_IFMT) {
5670 + /* no condition about RLIMIT_FSIZE and the file size */
5675 + do_sio = !capable(CAP_MKNOD);
5679 + do_sio = ((mode & (S_ISUID | S_ISGID))
5680 + && !capable(CAP_FSETID));
5681 + /* this workaround may be removed in the future */
5683 + h_dir = au_pinned_h_dir(pin);
5684 + do_sio = h_dir->i_mode & S_ISVTX;
5691 +#if 0 /* reserved */
5692 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5695 + struct dentry *h_dentry;
5697 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5698 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5699 + err = au_cpup_single(cpg, dst_parent);
5701 + struct au_cpup_single_args args = {
5704 + .dst_parent = dst_parent
5706 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5707 + if (unlikely(wkq_err))
5716 + * copyup the @dentry from the first active lower branch to @bdst,
5717 + * using au_cpup_single().
5719 +static int au_cpup_simple(struct au_cp_generic *cpg)
5722 + unsigned int flags_orig;
5723 + struct dentry *dentry;
5725 + AuDebugOn(cpg->bsrc < 0);
5727 + dentry = cpg->dentry;
5728 + DiMustWriteLock(dentry);
5730 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5732 + flags_orig = cpg->flags;
5733 + au_fset_cpup(cpg->flags, RENAME);
5734 + err = au_cpup_single(cpg, NULL);
5735 + cpg->flags = flags_orig;
5737 + return 0; /* success */
5740 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5741 + au_set_dbtop(dentry, cpg->bsrc);
5747 +struct au_cpup_simple_args {
5749 + struct au_cp_generic *cpg;
5752 +static void au_call_cpup_simple(void *args)
5754 + struct au_cpup_simple_args *a = args;
5756 + au_pin_hdir_acquire_nest(a->cpg->pin);
5757 + *a->errp = au_cpup_simple(a->cpg);
5758 + au_pin_hdir_release(a->cpg->pin);
5761 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5764 + struct dentry *dentry, *parent;
5765 + struct file *h_file;
5766 + struct inode *h_dir;
5768 + dentry = cpg->dentry;
5770 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5771 + AuDebugOn(cpg->bsrc < 0);
5772 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5773 + err = PTR_ERR(h_file);
5774 + if (IS_ERR(h_file))
5778 + parent = dget_parent(dentry);
5779 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5780 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5781 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5782 + err = au_cpup_simple(cpg);
5784 + struct au_cpup_simple_args args = {
5788 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5789 + if (unlikely(wkq_err))
5795 + au_h_open_post(dentry, cpg->bsrc, h_file);
5801 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5803 + aufs_bindex_t bsrc, bbot;
5804 + struct dentry *dentry, *h_dentry;
5806 + if (cpg->bsrc < 0) {
5807 + dentry = cpg->dentry;
5808 + bbot = au_dbbot(dentry);
5809 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5810 + h_dentry = au_h_dptr(dentry, bsrc);
5812 + AuDebugOn(d_is_negative(h_dentry));
5816 + AuDebugOn(bsrc > bbot);
5819 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5820 + return au_do_sio_cpup_simple(cpg);
5823 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5825 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5826 + return au_do_sio_cpup_simple(cpg);
5829 +/* ---------------------------------------------------------------------- */
5832 + * copyup the deleted file for writing.
5834 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5835 + struct file *file)
5838 + unsigned int flags_orig;
5839 + aufs_bindex_t bsrc_orig;
5840 + struct au_dinfo *dinfo;
5842 + struct au_hdentry *hd;
5843 + struct dentry *h_dentry;
5846 + dinfo = au_di(cpg->dentry);
5847 + AuRwMustWriteLock(&dinfo->di_rwsem);
5849 + bsrc_orig = cpg->bsrc;
5850 + cpg->bsrc = dinfo->di_btop;
5851 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5852 + hdst.h_dentry = hdst.hd->hd_dentry;
5853 + hdst.hd->hd_dentry = wh_dentry;
5854 + dinfo->di_btop = cpg->bdst;
5856 + hsrc.h_dentry = NULL;
5858 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5859 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5860 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5862 + flags_orig = cpg->flags;
5863 + cpg->flags = !AuCpup_DTIME;
5864 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5865 + cpg->flags = flags_orig;
5868 + err = au_reopen_nondir(file);
5869 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5871 + hdst.hd->hd_dentry = hdst.h_dentry;
5872 + dinfo->di_btop = cpg->bsrc;
5873 + cpg->bsrc = bsrc_orig;
5878 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5881 + aufs_bindex_t bdst;
5882 + struct au_dtime dt;
5883 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5884 + struct au_branch *br;
5885 + struct path h_path;
5887 + dentry = cpg->dentry;
5889 + br = au_sbr(dentry->d_sb, bdst);
5890 + parent = dget_parent(dentry);
5891 + h_parent = au_h_dptr(parent, bdst);
5892 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5893 + err = PTR_ERR(wh_dentry);
5894 + if (IS_ERR(wh_dentry))
5897 + h_path.dentry = h_parent;
5898 + h_path.mnt = au_br_mnt(br);
5899 + au_dtime_store(&dt, parent, &h_path);
5900 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5901 + if (unlikely(err))
5905 + h_path.dentry = wh_dentry;
5906 + if (!d_is_dir(wh_dentry)) {
5907 + /* no delegation since it is just created */
5908 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5909 + /*delegated*/NULL, /*force*/0);
5911 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5912 + if (unlikely(err)) {
5913 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5917 + au_dtime_revert(&dt);
5918 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5927 +struct au_cpup_wh_args {
5929 + struct au_cp_generic *cpg;
5930 + struct file *file;
5933 +static void au_call_cpup_wh(void *args)
5935 + struct au_cpup_wh_args *a = args;
5937 + au_pin_hdir_acquire_nest(a->cpg->pin);
5938 + *a->errp = au_cpup_wh(a->cpg, a->file);
5939 + au_pin_hdir_release(a->cpg->pin);
5942 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5945 + aufs_bindex_t bdst;
5946 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5947 + struct inode *dir, *h_dir, *h_tmpdir;
5948 + struct au_wbr *wbr;
5949 + struct au_pin wh_pin, *pin_orig;
5951 + dentry = cpg->dentry;
5953 + parent = dget_parent(dentry);
5954 + dir = d_inode(parent);
5957 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5960 + if (!h_dir->i_nlink) {
5961 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5962 + h_orph = wbr->wbr_orph;
5964 + h_parent = dget(au_h_dptr(parent, bdst));
5965 + au_set_h_dptr(parent, bdst, dget(h_orph));
5966 + h_tmpdir = d_inode(h_orph);
5967 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5969 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5970 + /* todo: au_h_open_pre()? */
5972 + pin_orig = cpg->pin;
5973 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5974 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5975 + cpg->pin = &wh_pin;
5978 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5979 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5980 + err = au_cpup_wh(cpg, file);
5982 + struct au_cpup_wh_args args = {
5987 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5988 + if (unlikely(wkq_err))
5993 + inode_unlock(h_tmpdir);
5994 + /* todo: au_h_open_post()? */
5995 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5996 + au_set_h_dptr(parent, bdst, h_parent);
5997 + AuDebugOn(!pin_orig);
5998 + cpg->pin = pin_orig;
6006 +/* ---------------------------------------------------------------------- */
6009 + * generic routine for both of copy-up and copy-down.
6011 +/* cf. revalidate function in file.c */
6012 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6013 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6014 + struct au_pin *pin,
6015 + struct dentry *h_parent, void *arg),
6019 + struct au_pin pin;
6020 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6023 + parent = dget_parent(dentry);
6024 + if (IS_ROOT(parent))
6027 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6028 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6030 + /* do not use au_dpage */
6031 + real_parent = parent;
6034 + parent = dget_parent(dentry);
6035 + h_parent = au_h_dptr(parent, bdst);
6037 + goto out; /* success */
6039 + /* find top dir which is necessary to cpup */
6043 + parent = dget_parent(d);
6044 + di_read_lock_parent3(parent, !AuLock_IR);
6045 + h_parent = au_h_dptr(parent, bdst);
6046 + di_read_unlock(parent, !AuLock_IR);
6047 + } while (!h_parent);
6049 + if (d != real_parent)
6050 + di_write_lock_child3(d);
6052 + /* somebody else might create while we were sleeping */
6053 + h_dentry = au_h_dptr(d, bdst);
6054 + if (!h_dentry || d_is_negative(h_dentry)) {
6056 + au_update_dbtop(d);
6058 + au_pin_set_dentry(&pin, d);
6059 + err = au_do_pin(&pin);
6061 + err = cp(d, bdst, &pin, h_parent, arg);
6066 + if (d != real_parent)
6067 + di_write_unlock(d);
6068 + if (unlikely(err))
6077 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6078 + struct au_pin *pin,
6079 + struct dentry *h_parent __maybe_unused,
6080 + void *arg __maybe_unused)
6082 + struct au_cp_generic cpg = {
6088 + .flags = AuCpup_DTIME
6090 + return au_sio_cpup_simple(&cpg);
6093 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6095 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6098 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6101 + struct dentry *parent;
6102 + struct inode *dir;
6104 + parent = dget_parent(dentry);
6105 + dir = d_inode(parent);
6107 + if (au_h_iptr(dir, bdst))
6110 + di_read_unlock(parent, AuLock_IR);
6111 + di_write_lock_parent(parent);
6112 + /* someone else might change our inode while we were sleeping */
6113 + if (!au_h_iptr(dir, bdst))
6114 + err = au_cpup_dirs(dentry, bdst);
6115 + di_downgrade_lock(parent, AuLock_IR);
6121 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6122 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6123 +++ linux/fs/aufs/cpup.h 2017-07-29 12:14:25.899708630 +0200
6126 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6128 + * This program, aufs is free software; you can redistribute it and/or modify
6129 + * it under the terms of the GNU General Public License as published by
6130 + * the Free Software Foundation; either version 2 of the License, or
6131 + * (at your option) any later version.
6133 + * This program is distributed in the hope that it will be useful,
6134 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6135 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6136 + * GNU General Public License for more details.
6138 + * You should have received a copy of the GNU General Public License
6139 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6143 + * copy-up/down functions
6146 +#ifndef __AUFS_CPUP_H__
6147 +#define __AUFS_CPUP_H__
6151 +#include <linux/path.h>
6157 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6158 +void au_cpup_attr_timesizes(struct inode *inode);
6159 +void au_cpup_attr_nlink(struct inode *inode, int force);
6160 +void au_cpup_attr_changeable(struct inode *inode);
6161 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6162 +void au_cpup_attr_all(struct inode *inode, int force);
6164 +/* ---------------------------------------------------------------------- */
6166 +struct au_cp_generic {
6167 + struct dentry *dentry;
6168 + aufs_bindex_t bdst, bsrc;
6170 + struct au_pin *pin;
6171 + unsigned int flags;
6175 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6176 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6178 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6179 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6181 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6183 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6184 + the branch is marked as RO */
6186 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6187 +#define au_fset_cpup(flags, name) \
6188 + do { (flags) |= AuCpup_##name; } while (0)
6189 +#define au_fclr_cpup(flags, name) \
6190 + do { (flags) &= ~AuCpup_##name; } while (0)
6192 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6193 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6194 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6195 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6197 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6198 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6199 + struct au_pin *pin,
6200 + struct dentry *h_parent, void *arg),
6202 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6203 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6205 +/* ---------------------------------------------------------------------- */
6207 +/* keep timestamps when copyup */
6209 + struct dentry *dt_dentry;
6210 + struct path dt_h_path;
6211 + struct timespec dt_atime, dt_mtime;
6213 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6214 + struct path *h_path);
6215 +void au_dtime_revert(struct au_dtime *dt);
6217 +#endif /* __KERNEL__ */
6218 +#endif /* __AUFS_CPUP_H__ */
6219 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6220 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6221 +++ linux/fs/aufs/dbgaufs.c 2017-07-29 12:14:25.899708630 +0200
6224 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6226 + * This program, aufs is free software; you can redistribute it and/or modify
6227 + * it under the terms of the GNU General Public License as published by
6228 + * the Free Software Foundation; either version 2 of the License, or
6229 + * (at your option) any later version.
6231 + * This program is distributed in the hope that it will be useful,
6232 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6233 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6234 + * GNU General Public License for more details.
6236 + * You should have received a copy of the GNU General Public License
6237 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6241 + * debugfs interface
6244 +#include <linux/debugfs.h>
6247 +#ifndef CONFIG_SYSFS
6248 +#error DEBUG_FS depends upon SYSFS
6251 +static struct dentry *dbgaufs;
6252 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6254 +/* 20 is max digits length of ulong 64 */
6255 +struct dbgaufs_arg {
6261 + * common function for all XINO files
6263 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6264 + struct file *file)
6266 + kfree(file->private_data);
6270 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6274 + struct dbgaufs_arg *p;
6277 + p = kmalloc(sizeof(*p), GFP_NOFS);
6283 + file->private_data = p;
6287 + err = vfsub_getattr(&xf->f_path, &st);
6291 + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n",
6292 + (long)file_count(xf), st.blocks, st.blksize,
6293 + (long long)st.size);
6295 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6296 + st.blocks, st.blksize,
6297 + (long long)st.size);
6298 + AuDebugOn(p->n >= sizeof(p->a));
6300 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6309 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6310 + size_t count, loff_t *ppos)
6312 + struct dbgaufs_arg *p;
6314 + p = file->private_data;
6315 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6318 +/* ---------------------------------------------------------------------- */
6320 +struct dbgaufs_plink_arg {
6325 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6326 + struct file *file)
6328 + free_page((unsigned long)file->private_data);
6332 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6334 + int err, i, limit;
6335 + unsigned long n, sum;
6336 + struct dbgaufs_plink_arg *p;
6337 + struct au_sbinfo *sbinfo;
6338 + struct super_block *sb;
6339 + struct au_sphlhead *sphl;
6342 + p = (void *)get_zeroed_page(GFP_NOFS);
6347 + sbinfo = inode->i_private;
6348 + sb = sbinfo->si_sb;
6349 + si_noflush_read_lock(sb);
6350 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6351 + limit = PAGE_SIZE - sizeof(p->n);
6353 + /* the number of buckets */
6354 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6359 + for (i = 0, sphl = sbinfo->si_plink;
6360 + i < AuPlink_NHASH;
6362 + n = au_sphl_count(sphl);
6365 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6368 + if (unlikely(limit <= 0))
6371 + p->a[p->n - 1] = '\n';
6373 + /* the sum of plinks */
6374 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6377 + if (unlikely(limit <= 0))
6380 +#define str "1\n0\n0\n"
6381 + p->n = sizeof(str) - 1;
6382 + strcpy(p->a, str);
6385 + si_read_unlock(sb);
6388 + file->private_data = p;
6389 + goto out; /* success */
6392 + free_page((unsigned long)p);
6397 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6398 + size_t count, loff_t *ppos)
6400 + struct dbgaufs_plink_arg *p;
6402 + p = file->private_data;
6403 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6406 +static const struct file_operations dbgaufs_plink_fop = {
6407 + .owner = THIS_MODULE,
6408 + .open = dbgaufs_plink_open,
6409 + .release = dbgaufs_plink_release,
6410 + .read = dbgaufs_plink_read
6413 +/* ---------------------------------------------------------------------- */
6415 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6418 + struct au_sbinfo *sbinfo;
6419 + struct super_block *sb;
6421 + sbinfo = inode->i_private;
6422 + sb = sbinfo->si_sb;
6423 + si_noflush_read_lock(sb);
6424 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6425 + si_read_unlock(sb);
6429 +static const struct file_operations dbgaufs_xib_fop = {
6430 + .owner = THIS_MODULE,
6431 + .open = dbgaufs_xib_open,
6432 + .release = dbgaufs_xi_release,
6433 + .read = dbgaufs_xi_read
6436 +/* ---------------------------------------------------------------------- */
6438 +#define DbgaufsXi_PREFIX "xi"
6440 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6444 + struct au_sbinfo *sbinfo;
6445 + struct super_block *sb;
6447 + struct qstr *name;
6451 + name = &file->f_path.dentry->d_name;
6452 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6453 + || memcmp(name->name, DbgaufsXi_PREFIX,
6454 + sizeof(DbgaufsXi_PREFIX) - 1)))
6456 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6457 + if (unlikely(err))
6460 + sbinfo = inode->i_private;
6461 + sb = sbinfo->si_sb;
6462 + si_noflush_read_lock(sb);
6463 + if (l <= au_sbbot(sb)) {
6464 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6465 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6468 + si_read_unlock(sb);
6474 +static const struct file_operations dbgaufs_xino_fop = {
6475 + .owner = THIS_MODULE,
6476 + .open = dbgaufs_xino_open,
6477 + .release = dbgaufs_xi_release,
6478 + .read = dbgaufs_xi_read
6481 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6483 + aufs_bindex_t bbot;
6484 + struct au_branch *br;
6485 + struct au_xino_file *xi;
6487 + if (!au_sbi(sb)->si_dbgaufs)
6490 + bbot = au_sbbot(sb);
6491 + for (; bindex <= bbot; bindex++) {
6492 + br = au_sbr(sb, bindex);
6493 + xi = &br->br_xino;
6494 + /* debugfs acquires the parent i_mutex */
6496 + debugfs_remove(xi->xi_dbgaufs);
6498 + xi->xi_dbgaufs = NULL;
6502 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6504 + struct au_sbinfo *sbinfo;
6505 + struct dentry *parent;
6506 + struct au_branch *br;
6507 + struct au_xino_file *xi;
6508 + aufs_bindex_t bbot;
6509 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6511 + sbinfo = au_sbi(sb);
6512 + parent = sbinfo->si_dbgaufs;
6516 + bbot = au_sbbot(sb);
6517 + for (; bindex <= bbot; bindex++) {
6518 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6519 + br = au_sbr(sb, bindex);
6520 + xi = &br->br_xino;
6521 + AuDebugOn(xi->xi_dbgaufs);
6522 + /* debugfs acquires the parent i_mutex */
6524 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6525 + sbinfo, &dbgaufs_xino_fop);
6527 + /* ignore an error */
6528 + if (unlikely(!xi->xi_dbgaufs))
6529 + AuWarn1("failed %s under debugfs\n", name);
6533 +/* ---------------------------------------------------------------------- */
6535 +#ifdef CONFIG_AUFS_EXPORT
6536 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6539 + struct au_sbinfo *sbinfo;
6540 + struct super_block *sb;
6542 + sbinfo = inode->i_private;
6543 + sb = sbinfo->si_sb;
6544 + si_noflush_read_lock(sb);
6545 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6546 + si_read_unlock(sb);
6550 +static const struct file_operations dbgaufs_xigen_fop = {
6551 + .owner = THIS_MODULE,
6552 + .open = dbgaufs_xigen_open,
6553 + .release = dbgaufs_xi_release,
6554 + .read = dbgaufs_xi_read
6557 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6562 + * This function is a dynamic '__init' function actually,
6563 + * so the tiny check for si_rwsem is unnecessary.
6565 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6568 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6569 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6570 + &dbgaufs_xigen_fop);
6571 + if (sbinfo->si_dbgaufs_xigen)
6577 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6581 +#endif /* CONFIG_AUFS_EXPORT */
6583 +/* ---------------------------------------------------------------------- */
6585 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6588 + * This function is a dynamic '__fin' function actually,
6589 + * so the tiny check for si_rwsem is unnecessary.
6591 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6593 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6594 + sbinfo->si_dbgaufs = NULL;
6595 + kobject_put(&sbinfo->si_kobj);
6598 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6601 + char name[SysaufsSiNameLen];
6604 + * This function is a dynamic '__init' function actually,
6605 + * so the tiny check for si_rwsem is unnecessary.
6607 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6611 + AuErr1("/debug/aufs is uninitialized\n");
6616 + sysaufs_name(sbinfo, name);
6617 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6618 + if (unlikely(!sbinfo->si_dbgaufs))
6620 + kobject_get(&sbinfo->si_kobj);
6622 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6623 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6624 + &dbgaufs_xib_fop);
6625 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6628 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6629 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6630 + &dbgaufs_plink_fop);
6631 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6634 + err = dbgaufs_xigen_init(sbinfo);
6636 + goto out; /* success */
6639 + dbgaufs_si_fin(sbinfo);
6644 +/* ---------------------------------------------------------------------- */
6646 +void dbgaufs_fin(void)
6648 + debugfs_remove(dbgaufs);
6651 +int __init dbgaufs_init(void)
6656 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6661 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6662 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6663 +++ linux/fs/aufs/dbgaufs.h 2017-07-29 12:14:25.899708630 +0200
6666 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6668 + * This program, aufs is free software; you can redistribute it and/or modify
6669 + * it under the terms of the GNU General Public License as published by
6670 + * the Free Software Foundation; either version 2 of the License, or
6671 + * (at your option) any later version.
6673 + * This program is distributed in the hope that it will be useful,
6674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6676 + * GNU General Public License for more details.
6678 + * You should have received a copy of the GNU General Public License
6679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6683 + * debugfs interface
6686 +#ifndef __DBGAUFS_H__
6687 +#define __DBGAUFS_H__
6691 +struct super_block;
6694 +#ifdef CONFIG_DEBUG_FS
6696 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6697 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6698 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6699 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6700 +void dbgaufs_fin(void);
6701 +int __init dbgaufs_init(void);
6703 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6704 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6705 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6706 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6707 +AuStubVoid(dbgaufs_fin, void)
6708 +AuStubInt0(__init dbgaufs_init, void)
6709 +#endif /* CONFIG_DEBUG_FS */
6711 +#endif /* __KERNEL__ */
6712 +#endif /* __DBGAUFS_H__ */
6713 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6714 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6715 +++ linux/fs/aufs/dcsub.c 2017-07-29 12:14:25.899708630 +0200
6718 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6720 + * This program, aufs is free software; you can redistribute it and/or modify
6721 + * it under the terms of the GNU General Public License as published by
6722 + * the Free Software Foundation; either version 2 of the License, or
6723 + * (at your option) any later version.
6725 + * This program is distributed in the hope that it will be useful,
6726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6728 + * GNU General Public License for more details.
6730 + * You should have received a copy of the GNU General Public License
6731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6735 + * sub-routines for dentry cache
6740 +static void au_dpage_free(struct au_dpage *dpage)
6743 + struct dentry **p;
6745 + p = dpage->dentries;
6746 + for (i = 0; i < dpage->ndentry; i++)
6748 + free_page((unsigned long)dpage->dentries);
6751 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6757 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6758 + if (unlikely(!dpages->dpages))
6761 + p = (void *)__get_free_page(gfp);
6765 + dpages->dpages[0].ndentry = 0;
6766 + dpages->dpages[0].dentries = p;
6767 + dpages->ndpage = 1;
6768 + return 0; /* success */
6771 + kfree(dpages->dpages);
6776 +void au_dpages_free(struct au_dcsub_pages *dpages)
6779 + struct au_dpage *p;
6781 + p = dpages->dpages;
6782 + for (i = 0; i < dpages->ndpage; i++)
6783 + au_dpage_free(p++);
6784 + kfree(dpages->dpages);
6787 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6788 + struct dentry *dentry, gfp_t gfp)
6791 + struct au_dpage *dpage;
6794 + dpage = dpages->dpages + dpages->ndpage - 1;
6795 + sz = PAGE_SIZE / sizeof(dentry);
6796 + if (unlikely(dpage->ndentry >= sz)) {
6797 + AuLabel(new dpage);
6799 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6800 + p = au_kzrealloc(dpages->dpages, sz,
6801 + sz + sizeof(*dpages->dpages), gfp,
6806 + dpages->dpages = p;
6807 + dpage = dpages->dpages + dpages->ndpage;
6808 + p = (void *)__get_free_page(gfp);
6812 + dpage->ndentry = 0;
6813 + dpage->dentries = p;
6817 + AuDebugOn(au_dcount(dentry) <= 0);
6818 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6819 + return 0; /* success */
6825 +/* todo: BAD approach */
6826 +/* copied from linux/fs/dcache.c */
6834 +extern void d_walk(struct dentry *parent, void *data,
6835 + enum d_walk_ret (*enter)(void *, struct dentry *),
6836 + void (*finish)(void *));
6838 +struct ac_dpages_arg {
6840 + struct au_dcsub_pages *dpages;
6841 + struct super_block *sb;
6842 + au_dpages_test test;
6846 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6848 + enum d_walk_ret ret;
6849 + struct ac_dpages_arg *arg = _arg;
6851 + ret = D_WALK_CONTINUE;
6852 + if (dentry->d_sb == arg->sb
6853 + && !IS_ROOT(dentry)
6854 + && au_dcount(dentry) > 0
6856 + && (!arg->test || arg->test(dentry, arg->arg))) {
6857 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6858 + if (unlikely(arg->err))
6859 + ret = D_WALK_QUIT;
6865 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6866 + au_dpages_test test, void *arg)
6868 + struct ac_dpages_arg args = {
6876 + d_walk(root, &args, au_call_dpages_append, NULL);
6881 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6882 + int do_include, au_dpages_test test, void *arg)
6887 + write_seqlock(&rename_lock);
6888 + spin_lock(&dentry->d_lock);
6890 + && au_dcount(dentry) > 0
6891 + && (!test || test(dentry, arg)))
6892 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6893 + spin_unlock(&dentry->d_lock);
6894 + if (unlikely(err))
6898 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6901 + while (!IS_ROOT(dentry)) {
6902 + dentry = dentry->d_parent; /* rename_lock is locked */
6903 + spin_lock(&dentry->d_lock);
6904 + if (au_dcount(dentry) > 0
6905 + && (!test || test(dentry, arg)))
6906 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6907 + spin_unlock(&dentry->d_lock);
6908 + if (unlikely(err))
6913 + write_sequnlock(&rename_lock);
6917 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6919 + return au_di(dentry) && dentry->d_sb == arg;
6922 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6923 + struct dentry *dentry, int do_include)
6925 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6926 + au_dcsub_dpages_aufs, dentry->d_sb);
6929 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6931 + struct path path[2] = {
6940 + return path_is_under(path + 0, path + 1);
6942 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6943 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6944 +++ linux/fs/aufs/dcsub.h 2017-07-29 12:14:25.899708630 +0200
6947 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6949 + * This program, aufs is free software; you can redistribute it and/or modify
6950 + * it under the terms of the GNU General Public License as published by
6951 + * the Free Software Foundation; either version 2 of the License, or
6952 + * (at your option) any later version.
6954 + * This program is distributed in the hope that it will be useful,
6955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6957 + * GNU General Public License for more details.
6959 + * You should have received a copy of the GNU General Public License
6960 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6964 + * sub-routines for dentry cache
6967 +#ifndef __AUFS_DCSUB_H__
6968 +#define __AUFS_DCSUB_H__
6972 +#include <linux/dcache.h>
6973 +#include <linux/fs.h>
6977 + struct dentry **dentries;
6980 +struct au_dcsub_pages {
6982 + struct au_dpage *dpages;
6985 +/* ---------------------------------------------------------------------- */
6988 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6989 +void au_dpages_free(struct au_dcsub_pages *dpages);
6990 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6991 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6992 + au_dpages_test test, void *arg);
6993 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6994 + int do_include, au_dpages_test test, void *arg);
6995 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6996 + struct dentry *dentry, int do_include);
6997 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6999 +/* ---------------------------------------------------------------------- */
7002 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7003 + * include/linux/dcache.h. Try them (in the future).
7006 +static inline int au_d_hashed_positive(struct dentry *d)
7009 + struct inode *inode = d_inode(d);
7012 + if (unlikely(d_unhashed(d)
7013 + || d_is_negative(d)
7014 + || !inode->i_nlink))
7019 +static inline int au_d_linkable(struct dentry *d)
7022 + struct inode *inode = d_inode(d);
7024 + err = au_d_hashed_positive(d);
7026 + && d_is_positive(d)
7027 + && (inode->i_state & I_LINKABLE))
7032 +static inline int au_d_alive(struct dentry *d)
7035 + struct inode *inode;
7039 + err = au_d_hashed_positive(d);
7041 + inode = d_inode(d);
7042 + if (unlikely(d_unlinked(d)
7043 + || d_is_negative(d)
7044 + || !inode->i_nlink))
7050 +static inline int au_alive_dir(struct dentry *d)
7054 + err = au_d_alive(d);
7055 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7060 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7062 + return a->len == b->len
7063 + && !memcmp(a->name, b->name, a->len);
7068 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7070 + * the type of d_lockref.count became int, but the inlined function d_count()
7071 + * still returns unsigned int.
7072 + * I don't know why. Maybe it is for every d_count() users?
7073 + * Anyway au_dcount() lives on.
7075 +static inline int au_dcount(struct dentry *d)
7077 + return (int)d_count(d);
7080 +#endif /* __KERNEL__ */
7081 +#endif /* __AUFS_DCSUB_H__ */
7082 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7083 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7084 +++ linux/fs/aufs/debug.c 2017-07-29 12:14:25.899708630 +0200
7087 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7089 + * This program, aufs is free software; you can redistribute it and/or modify
7090 + * it under the terms of the GNU General Public License as published by
7091 + * the Free Software Foundation; either version 2 of the License, or
7092 + * (at your option) any later version.
7094 + * This program is distributed in the hope that it will be useful,
7095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7097 + * GNU General Public License for more details.
7099 + * You should have received a copy of the GNU General Public License
7100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7104 + * debug print functions
7109 +/* Returns 0, or -errno. arg is in kp->arg. */
7110 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7114 + err = kstrtoint(val, 0, &n);
7124 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7125 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7130 + return sprintf(buffer, "%d", atomic_read(a));
7133 +static struct kernel_param_ops param_ops_atomic_t = {
7134 + .set = param_atomic_t_set,
7135 + .get = param_atomic_t_get
7136 + /* void (*free)(void *arg) */
7139 +atomic_t aufs_debug = ATOMIC_INIT(0);
7140 +MODULE_PARM_DESC(debug, "debug print");
7141 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7143 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7144 +char *au_plevel = KERN_DEBUG;
7145 +#define dpri(fmt, ...) do { \
7147 + && strcmp(au_plevel, KERN_DEBUG)) \
7148 + || au_debug_test()) \
7149 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7152 +/* ---------------------------------------------------------------------- */
7154 +void au_dpri_whlist(struct au_nhash *whlist)
7156 + unsigned long ul, n;
7157 + struct hlist_head *head;
7158 + struct au_vdir_wh *pos;
7160 + n = whlist->nh_num;
7161 + head = whlist->nh_head;
7162 + for (ul = 0; ul < n; ul++) {
7163 + hlist_for_each_entry(pos, head, wh_hash)
7164 + dpri("b%d, %.*s, %d\n",
7166 + pos->wh_str.len, pos->wh_str.name,
7172 +void au_dpri_vdir(struct au_vdir *vdir)
7175 + union au_vdir_deblk_p p;
7178 + if (!vdir || IS_ERR(vdir)) {
7179 + dpri("err %ld\n", PTR_ERR(vdir));
7183 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7184 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7185 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7186 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7187 + p.deblk = vdir->vd_deblk[ul];
7189 + dpri("[%lu]: %p\n", ul, o);
7193 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7194 + struct dentry *wh)
7199 + if (!inode || IS_ERR(inode)) {
7200 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7204 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7205 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7206 + && sizeof(inode->i_blocks) != sizeof(u64));
7208 + n = (void *)wh->d_name.name;
7209 + l = wh->d_name.len;
7212 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7213 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7215 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7216 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7217 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7218 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7219 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7220 + inode->i_state, inode->i_flags, inode->i_version,
7221 + inode->i_generation,
7222 + l ? ", wh " : "", l, n);
7226 +void au_dpri_inode(struct inode *inode)
7228 + struct au_iinfo *iinfo;
7229 + struct au_hinode *hi;
7230 + aufs_bindex_t bindex;
7233 + err = do_pri_inode(-1, inode, -1, NULL);
7234 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7237 + iinfo = au_ii(inode);
7238 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7239 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7240 + if (iinfo->ii_btop < 0)
7243 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7244 + hi = au_hinode(iinfo, bindex);
7246 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7250 +void au_dpri_dalias(struct inode *inode)
7254 + spin_lock(&inode->i_lock);
7255 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7256 + au_dpri_dentry(d);
7257 + spin_unlock(&inode->i_lock);
7260 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7262 + struct dentry *wh = NULL;
7264 + struct inode *inode;
7265 + struct au_iinfo *iinfo;
7266 + struct au_hinode *hi;
7268 + if (!dentry || IS_ERR(dentry)) {
7269 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7272 + /* do not call dget_parent() here */
7273 + /* note: access d_xxx without d_lock */
7274 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7275 + bindex, dentry, dentry,
7276 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7277 + au_dcount(dentry), dentry->d_flags,
7278 + d_unhashed(dentry) ? "un" : "");
7281 + if (d_is_positive(dentry))
7282 + inode = d_inode(dentry);
7284 + && au_test_aufs(dentry->d_sb)
7286 + && !au_is_bad_inode(inode)) {
7287 + iinfo = au_ii(inode);
7288 + hi = au_hinode(iinfo, bindex);
7290 + wh = hi->hi_whdentry;
7292 + do_pri_inode(bindex, inode, hn, wh);
7296 +void au_dpri_dentry(struct dentry *dentry)
7298 + struct au_dinfo *dinfo;
7299 + aufs_bindex_t bindex;
7302 + err = do_pri_dentry(-1, dentry);
7303 + if (err || !au_test_aufs(dentry->d_sb))
7306 + dinfo = au_di(dentry);
7309 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7310 + dinfo->di_btop, dinfo->di_bbot,
7311 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7312 + dinfo->di_tmpfile);
7313 + if (dinfo->di_btop < 0)
7315 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7316 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7319 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7323 + if (!file || IS_ERR(file)) {
7324 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7329 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7330 + && au_test_aufs(file->f_path.dentry->d_sb)
7332 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7333 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7334 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7335 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7336 + file->f_version, file->f_pos, a);
7337 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7338 + do_pri_dentry(bindex, file->f_path.dentry);
7342 +void au_dpri_file(struct file *file)
7344 + struct au_finfo *finfo;
7345 + struct au_fidir *fidir;
7346 + struct au_hfile *hfile;
7347 + aufs_bindex_t bindex;
7350 + err = do_pri_file(-1, file);
7352 + || IS_ERR_OR_NULL(file->f_path.dentry)
7353 + || !au_test_aufs(file->f_path.dentry->d_sb))
7356 + finfo = au_fi(file);
7359 + if (finfo->fi_btop < 0)
7361 + fidir = finfo->fi_hdir;
7363 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7365 + for (bindex = finfo->fi_btop;
7366 + bindex >= 0 && bindex <= fidir->fd_bbot;
7368 + hfile = fidir->fd_hfile + bindex;
7369 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7373 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7375 + struct vfsmount *mnt;
7376 + struct super_block *sb;
7378 + if (!br || IS_ERR(br))
7380 + mnt = au_br_mnt(br);
7381 + if (!mnt || IS_ERR(mnt))
7384 + if (!sb || IS_ERR(sb))
7387 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7388 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7390 + bindex, br->br_perm, br->br_id, au_br_count(br),
7391 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7392 + sb->s_flags, sb->s_count,
7393 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7397 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7401 +void au_dpri_sb(struct super_block *sb)
7403 + struct au_sbinfo *sbinfo;
7404 + aufs_bindex_t bindex;
7406 + /* to reuduce stack size */
7408 + struct vfsmount mnt;
7409 + struct au_branch fake;
7412 + /* this function can be called from magic sysrq */
7413 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7414 + if (unlikely(!a)) {
7415 + dpri("no memory\n");
7419 + a->mnt.mnt_sb = sb;
7420 + a->fake.br_path.mnt = &a->mnt;
7421 + au_br_count_init(&a->fake);
7422 + err = do_pri_br(-1, &a->fake);
7423 + au_br_count_fin(&a->fake);
7425 + dpri("dev 0x%x\n", sb->s_dev);
7426 + if (err || !au_test_aufs(sb))
7429 + sbinfo = au_sbi(sb);
7432 + dpri("nw %d, gen %u, kobj %d\n",
7433 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7434 + kref_read(&sbinfo->si_kobj.kref));
7435 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7436 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7439 +/* ---------------------------------------------------------------------- */
7441 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7443 + struct inode *h_inode, *inode = d_inode(dentry);
7444 + struct dentry *h_dentry;
7445 + aufs_bindex_t bindex, bbot, bi;
7447 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7450 + bbot = au_dbbot(dentry);
7451 + bi = au_ibbot(inode);
7454 + bindex = au_dbtop(dentry);
7455 + bi = au_ibtop(inode);
7459 + for (; bindex <= bbot; bindex++) {
7460 + h_dentry = au_h_dptr(dentry, bindex);
7463 + h_inode = au_h_iptr(inode, bindex);
7464 + if (unlikely(h_inode != d_inode(h_dentry))) {
7466 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7467 + AuDbgDentry(dentry);
7468 + AuDbgInode(inode);
7475 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7478 + struct au_dcsub_pages dpages;
7479 + struct au_dpage *dpage;
7480 + struct dentry **dentries;
7482 + err = au_dpages_init(&dpages, GFP_NOFS);
7484 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7486 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7487 + dpage = dpages.dpages + i;
7488 + dentries = dpage->dentries;
7489 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7490 + AuDebugOn(au_digen_test(dentries[j], sigen));
7492 + au_dpages_free(&dpages);
7495 +void au_dbg_verify_kthread(void)
7497 + if (au_wkq_test()) {
7500 + * It may be recursive, but udba=notify between two aufs mounts,
7501 + * where a single ro branch is shared, is not a problem.
7507 +/* ---------------------------------------------------------------------- */
7509 +int __init au_debug_init(void)
7511 + aufs_bindex_t bindex;
7512 + struct au_vdir_destr destr;
7515 + AuDebugOn(bindex >= 0);
7518 + AuDebugOn(destr.len < NAME_MAX);
7520 +#ifdef CONFIG_4KSTACKS
7521 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7526 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7527 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7528 +++ linux/fs/aufs/debug.h 2017-07-29 12:14:25.899708630 +0200
7531 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7533 + * This program, aufs is free software; you can redistribute it and/or modify
7534 + * it under the terms of the GNU General Public License as published by
7535 + * the Free Software Foundation; either version 2 of the License, or
7536 + * (at your option) any later version.
7538 + * This program is distributed in the hope that it will be useful,
7539 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7540 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7541 + * GNU General Public License for more details.
7543 + * You should have received a copy of the GNU General Public License
7544 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7548 + * debug print functions
7551 +#ifndef __AUFS_DEBUG_H__
7552 +#define __AUFS_DEBUG_H__
7556 +#include <linux/atomic.h>
7557 +#include <linux/module.h>
7558 +#include <linux/kallsyms.h>
7559 +#include <linux/sysrq.h>
7561 +#ifdef CONFIG_AUFS_DEBUG
7562 +#define AuDebugOn(a) BUG_ON(a)
7564 +/* module parameter */
7565 +extern atomic_t aufs_debug;
7566 +static inline void au_debug_on(void)
7568 + atomic_inc(&aufs_debug);
7570 +static inline void au_debug_off(void)
7572 + atomic_dec_if_positive(&aufs_debug);
7575 +static inline int au_debug_test(void)
7577 + return atomic_read(&aufs_debug) > 0;
7580 +#define AuDebugOn(a) do {} while (0)
7581 +AuStubVoid(au_debug_on, void)
7582 +AuStubVoid(au_debug_off, void)
7583 +AuStubInt0(au_debug_test, void)
7584 +#endif /* CONFIG_AUFS_DEBUG */
7586 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7588 +/* ---------------------------------------------------------------------- */
7592 +#define AuDbg(fmt, ...) do { \
7593 + if (au_debug_test()) \
7594 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7596 +#define AuLabel(l) AuDbg(#l "\n")
7597 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7598 +#define AuWarn1(fmt, ...) do { \
7599 + static unsigned char _c; \
7601 + pr_warn(fmt, ##__VA_ARGS__); \
7604 +#define AuErr1(fmt, ...) do { \
7605 + static unsigned char _c; \
7607 + pr_err(fmt, ##__VA_ARGS__); \
7610 +#define AuIOErr1(fmt, ...) do { \
7611 + static unsigned char _c; \
7613 + AuIOErr(fmt, ##__VA_ARGS__); \
7616 +#define AuUnsupportMsg "This operation is not supported." \
7617 + " Please report this application to aufs-users ML."
7618 +#define AuUnsupport(fmt, ...) do { \
7619 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7623 +#define AuTraceErr(e) do { \
7624 + if (unlikely((e) < 0)) \
7625 + AuDbg("err %d\n", (int)(e)); \
7628 +#define AuTraceErrPtr(p) do { \
7630 + AuDbg("err %ld\n", PTR_ERR(p)); \
7633 +/* dirty macros for debug print, use with "%.*s" and caution */
7634 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7636 +/* ---------------------------------------------------------------------- */
7639 +#ifdef CONFIG_AUFS_DEBUG
7640 +extern struct mutex au_dbg_mtx;
7641 +extern char *au_plevel;
7643 +void au_dpri_whlist(struct au_nhash *whlist);
7645 +void au_dpri_vdir(struct au_vdir *vdir);
7647 +void au_dpri_inode(struct inode *inode);
7648 +void au_dpri_dalias(struct inode *inode);
7649 +void au_dpri_dentry(struct dentry *dentry);
7651 +void au_dpri_file(struct file *filp);
7652 +struct super_block;
7653 +void au_dpri_sb(struct super_block *sb);
7655 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7656 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7657 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7658 +void au_dbg_verify_kthread(void);
7660 +int __init au_debug_init(void);
7662 +#define AuDbgWhlist(w) do { \
7663 + mutex_lock(&au_dbg_mtx); \
7665 + au_dpri_whlist(w); \
7666 + mutex_unlock(&au_dbg_mtx); \
7669 +#define AuDbgVdir(v) do { \
7670 + mutex_lock(&au_dbg_mtx); \
7672 + au_dpri_vdir(v); \
7673 + mutex_unlock(&au_dbg_mtx); \
7676 +#define AuDbgInode(i) do { \
7677 + mutex_lock(&au_dbg_mtx); \
7679 + au_dpri_inode(i); \
7680 + mutex_unlock(&au_dbg_mtx); \
7683 +#define AuDbgDAlias(i) do { \
7684 + mutex_lock(&au_dbg_mtx); \
7686 + au_dpri_dalias(i); \
7687 + mutex_unlock(&au_dbg_mtx); \
7690 +#define AuDbgDentry(d) do { \
7691 + mutex_lock(&au_dbg_mtx); \
7693 + au_dpri_dentry(d); \
7694 + mutex_unlock(&au_dbg_mtx); \
7697 +#define AuDbgFile(f) do { \
7698 + mutex_lock(&au_dbg_mtx); \
7700 + au_dpri_file(f); \
7701 + mutex_unlock(&au_dbg_mtx); \
7704 +#define AuDbgSb(sb) do { \
7705 + mutex_lock(&au_dbg_mtx); \
7706 + AuDbg(#sb "\n"); \
7708 + mutex_unlock(&au_dbg_mtx); \
7711 +#define AuDbgSym(addr) do { \
7712 + char sym[KSYM_SYMBOL_LEN]; \
7713 + sprint_symbol(sym, (unsigned long)addr); \
7714 + AuDbg("%s\n", sym); \
7717 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7718 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7719 +AuStubVoid(au_dbg_verify_kthread, void)
7720 +AuStubInt0(__init au_debug_init, void)
7722 +#define AuDbgWhlist(w) do {} while (0)
7723 +#define AuDbgVdir(v) do {} while (0)
7724 +#define AuDbgInode(i) do {} while (0)
7725 +#define AuDbgDAlias(i) do {} while (0)
7726 +#define AuDbgDentry(d) do {} while (0)
7727 +#define AuDbgFile(f) do {} while (0)
7728 +#define AuDbgSb(sb) do {} while (0)
7729 +#define AuDbgSym(addr) do {} while (0)
7730 +#endif /* CONFIG_AUFS_DEBUG */
7732 +/* ---------------------------------------------------------------------- */
7734 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7735 +int __init au_sysrq_init(void);
7736 +void au_sysrq_fin(void);
7738 +#ifdef CONFIG_HW_CONSOLE
7739 +#define au_dbg_blocked() do { \
7741 + handle_sysrq('w'); \
7744 +AuStubVoid(au_dbg_blocked, void)
7748 +AuStubInt0(__init au_sysrq_init, void)
7749 +AuStubVoid(au_sysrq_fin, void)
7750 +AuStubVoid(au_dbg_blocked, void)
7751 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7753 +#endif /* __KERNEL__ */
7754 +#endif /* __AUFS_DEBUG_H__ */
7755 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7756 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7757 +++ linux/fs/aufs/dentry.c 2017-09-05 10:42:11.055421928 +0200
7760 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7762 + * This program, aufs is free software; you can redistribute it and/or modify
7763 + * it under the terms of the GNU General Public License as published by
7764 + * the Free Software Foundation; either version 2 of the License, or
7765 + * (at your option) any later version.
7767 + * This program is distributed in the hope that it will be useful,
7768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7770 + * GNU General Public License for more details.
7772 + * You should have received a copy of the GNU General Public License
7773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7777 + * lookup and dentry operations
7780 +#include <linux/namei.h>
7783 +struct au_do_lookup_args {
7784 + unsigned int flags;
7789 + * returns positive/negative dentry, NULL or an error.
7790 + * NULL means whiteout-ed or not-found.
7792 +static struct dentry*
7793 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7794 + aufs_bindex_t bindex, struct qstr *wh_name,
7795 + struct au_do_lookup_args *args)
7797 + struct dentry *h_dentry;
7798 + struct inode *h_inode;
7799 + struct au_branch *br;
7800 + int wh_found, opq;
7801 + unsigned char wh_able;
7802 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7803 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7807 + br = au_sbr(dentry->d_sb, bindex);
7808 + wh_able = !!au_br_whable(br->br_perm);
7810 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7811 + h_dentry = ERR_PTR(wh_found);
7814 + if (unlikely(wh_found < 0))
7817 + /* We found a whiteout */
7818 + /* au_set_dbbot(dentry, bindex); */
7819 + au_set_dbwh(dentry, bindex);
7821 + return NULL; /* success */
7825 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7827 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7828 + if (IS_ERR(h_dentry)) {
7829 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7835 + h_inode = d_inode(h_dentry);
7836 + if (d_is_negative(h_dentry)) {
7839 + } else if (wh_found
7840 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7843 + if (au_dbbot(dentry) <= bindex)
7844 + au_set_dbbot(dentry, bindex);
7845 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7846 + au_set_dbtop(dentry, bindex);
7847 + au_set_h_dptr(dentry, bindex, h_dentry);
7849 + if (!d_is_dir(h_dentry)
7851 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7852 + goto out; /* success */
7854 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
7855 + opq = au_diropq_test(h_dentry);
7856 + inode_unlock_shared(h_inode);
7858 + au_set_dbdiropq(dentry, bindex);
7859 + else if (unlikely(opq < 0)) {
7860 + au_set_h_dptr(dentry, bindex, NULL);
7861 + h_dentry = ERR_PTR(opq);
7872 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7874 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7875 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7881 + * returns the number of lower positive dentries,
7882 + * otherwise an error.
7883 + * can be called at unlinking with @type is zero.
7885 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7886 + unsigned int flags)
7888 + int npositive, err;
7889 + aufs_bindex_t bindex, btail, bdiropq;
7890 + unsigned char isdir, dirperm1;
7891 + struct qstr whname;
7892 + struct au_do_lookup_args args = {
7895 + const struct qstr *name = &dentry->d_name;
7896 + struct dentry *parent;
7897 + struct super_block *sb;
7899 + sb = dentry->d_sb;
7900 + err = au_test_shwh(sb, name);
7901 + if (unlikely(err))
7904 + err = au_wh_name_alloc(&whname, name);
7905 + if (unlikely(err))
7908 + isdir = !!d_is_dir(dentry);
7909 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7912 + parent = dget_parent(dentry);
7913 + btail = au_dbtaildir(parent);
7914 + for (bindex = btop; bindex <= btail; bindex++) {
7915 + struct dentry *h_parent, *h_dentry;
7916 + struct inode *h_inode, *h_dir;
7918 + h_dentry = au_h_dptr(dentry, bindex);
7920 + if (d_is_positive(h_dentry))
7924 + h_parent = au_h_dptr(parent, bindex);
7925 + if (!h_parent || !d_is_dir(h_parent))
7928 + h_dir = d_inode(h_parent);
7929 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
7930 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7932 + inode_unlock_shared(h_dir);
7933 + err = PTR_ERR(h_dentry);
7934 + if (IS_ERR(h_dentry))
7937 + au_fclr_lkup(args.flags, ALLOW_NEG);
7939 + au_fset_lkup(args.flags, IGNORE_PERM);
7941 + if (au_dbwh(dentry) == bindex)
7945 + if (d_is_negative(h_dentry))
7947 + h_inode = d_inode(h_dentry);
7950 + args.type = h_inode->i_mode & S_IFMT;
7951 + if (args.type != S_IFDIR)
7954 + /* the type of lower may be different */
7955 + bdiropq = au_dbdiropq(dentry);
7956 + if (bdiropq >= 0 && bdiropq <= bindex)
7962 + AuLabel(positive);
7963 + au_update_dbtop(dentry);
7966 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7967 + && au_dbtop(dentry) < 0)) {
7969 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7975 + kfree(whname.name);
7980 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7982 + struct dentry *dentry;
7985 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7986 + dentry = vfsub_lkup_one(name, parent);
7988 + struct vfsub_lkup_one_args args = {
7994 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7995 + if (unlikely(wkq_err))
7996 + dentry = ERR_PTR(wkq_err);
8003 + * lookup @dentry on @bindex which should be negative.
8005 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8008 + struct dentry *parent, *h_parent, *h_dentry;
8009 + struct au_branch *br;
8011 + parent = dget_parent(dentry);
8012 + h_parent = au_h_dptr(parent, bindex);
8013 + br = au_sbr(dentry->d_sb, bindex);
8015 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8017 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8018 + err = PTR_ERR(h_dentry);
8019 + if (IS_ERR(h_dentry))
8021 + if (unlikely(d_is_positive(h_dentry))) {
8023 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8029 + if (bindex < au_dbtop(dentry))
8030 + au_set_dbtop(dentry, bindex);
8031 + if (au_dbbot(dentry) < bindex)
8032 + au_set_dbbot(dentry, bindex);
8033 + au_set_h_dptr(dentry, bindex, h_dentry);
8040 +/* ---------------------------------------------------------------------- */
8042 +/* subset of struct inode */
8044 + unsigned long i_ino;
8045 + /* unsigned int i_nlink; */
8051 + blkcnt_t i_blocks;
8056 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8058 + ia->i_ino = h_inode->i_ino;
8059 + /* ia->i_nlink = h_inode->i_nlink; */
8060 + ia->i_uid = h_inode->i_uid;
8061 + ia->i_gid = h_inode->i_gid;
8062 + ia->i_version = h_inode->i_version;
8064 + ia->i_size = h_inode->i_size;
8065 + ia->i_blocks = h_inode->i_blocks;
8067 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8070 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8072 + return ia->i_ino != h_inode->i_ino
8073 + /* || ia->i_nlink != h_inode->i_nlink */
8074 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8075 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8076 + || ia->i_version != h_inode->i_version
8078 + || ia->i_size != h_inode->i_size
8079 + || ia->i_blocks != h_inode->i_blocks
8081 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8084 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8085 + struct au_branch *br)
8088 + struct au_iattr ia;
8089 + struct inode *h_inode;
8090 + struct dentry *h_d;
8091 + struct super_block *h_sb;
8094 + memset(&ia, -1, sizeof(ia));
8095 + h_sb = h_dentry->d_sb;
8097 + if (d_is_positive(h_dentry)) {
8098 + h_inode = d_inode(h_dentry);
8099 + au_iattr_save(&ia, h_inode);
8100 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8101 + /* nfs d_revalidate may return 0 for negative dentry */
8102 + /* fuse d_revalidate always return 0 for negative dentry */
8105 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8106 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8107 + err = PTR_ERR(h_d);
8112 + if (unlikely(h_d != h_dentry
8113 + || d_inode(h_d) != h_inode
8114 + || (h_inode && au_iattr_test(&ia, h_inode))))
8115 + err = au_busy_or_stale();
8123 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8124 + struct dentry *h_parent, struct au_branch *br)
8129 + if (udba == AuOpt_UDBA_REVAL
8130 + && !au_test_fs_remote(h_dentry->d_sb)) {
8132 + err = (d_inode(h_dentry->d_parent) != h_dir);
8133 + } else if (udba != AuOpt_UDBA_NONE)
8134 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8139 +/* ---------------------------------------------------------------------- */
8141 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8144 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8145 + struct au_hdentry tmp, *p, *q;
8146 + struct au_dinfo *dinfo;
8147 + struct super_block *sb;
8149 + DiMustWriteLock(dentry);
8151 + sb = dentry->d_sb;
8152 + dinfo = au_di(dentry);
8153 + bbot = dinfo->di_bbot;
8154 + bwh = dinfo->di_bwh;
8155 + bdiropq = dinfo->di_bdiropq;
8156 + bindex = dinfo->di_btop;
8157 + p = au_hdentry(dinfo, bindex);
8158 + for (; bindex <= bbot; bindex++, p++) {
8159 + if (!p->hd_dentry)
8162 + new_bindex = au_br_index(sb, p->hd_id);
8163 + if (new_bindex == bindex)
8166 + if (dinfo->di_bwh == bindex)
8168 + if (dinfo->di_bdiropq == bindex)
8169 + bdiropq = new_bindex;
8170 + if (new_bindex < 0) {
8172 + p->hd_dentry = NULL;
8176 + /* swap two lower dentries, and loop again */
8177 + q = au_hdentry(dinfo, new_bindex);
8181 + if (tmp.hd_dentry) {
8187 + dinfo->di_bwh = -1;
8188 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8189 + dinfo->di_bwh = bwh;
8191 + dinfo->di_bdiropq = -1;
8193 + && bdiropq <= au_sbbot(sb)
8194 + && au_sbr_whable(sb, bdiropq))
8195 + dinfo->di_bdiropq = bdiropq;
8198 + dinfo->di_btop = -1;
8199 + dinfo->di_bbot = -1;
8200 + bbot = au_dbbot(parent);
8202 + p = au_hdentry(dinfo, bindex);
8203 + for (; bindex <= bbot; bindex++, p++)
8204 + if (p->hd_dentry) {
8205 + dinfo->di_btop = bindex;
8209 + if (dinfo->di_btop >= 0) {
8211 + p = au_hdentry(dinfo, bindex);
8212 + for (; bindex >= 0; bindex--, p--)
8213 + if (p->hd_dentry) {
8214 + dinfo->di_bbot = bindex;
8223 +static void au_do_hide(struct dentry *dentry)
8225 + struct inode *inode;
8227 + if (d_really_is_positive(dentry)) {
8228 + inode = d_inode(dentry);
8229 + if (!d_is_dir(dentry)) {
8230 + if (inode->i_nlink && !d_unhashed(dentry))
8231 + drop_nlink(inode);
8233 + clear_nlink(inode);
8234 + /* stop next lookup */
8235 + inode->i_flags |= S_DEAD;
8237 + smp_mb(); /* necessary? */
8242 +static int au_hide_children(struct dentry *parent)
8244 + int err, i, j, ndentry;
8245 + struct au_dcsub_pages dpages;
8246 + struct au_dpage *dpage;
8247 + struct dentry *dentry;
8249 + err = au_dpages_init(&dpages, GFP_NOFS);
8250 + if (unlikely(err))
8252 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8253 + if (unlikely(err))
8256 + /* in reverse order */
8257 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8258 + dpage = dpages.dpages + i;
8259 + ndentry = dpage->ndentry;
8260 + for (j = ndentry - 1; j >= 0; j--) {
8261 + dentry = dpage->dentries[j];
8262 + if (dentry != parent)
8263 + au_do_hide(dentry);
8268 + au_dpages_free(&dpages);
8273 +static void au_hide(struct dentry *dentry)
8277 + AuDbgDentry(dentry);
8278 + if (d_is_dir(dentry)) {
8279 + /* shrink_dcache_parent(dentry); */
8280 + err = au_hide_children(dentry);
8281 + if (unlikely(err))
8282 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8285 + au_do_hide(dentry);
8289 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8291 + * a dirty branch is added
8292 + * - on the top of layers
8293 + * - in the middle of layers
8294 + * - to the bottom of layers
8296 + * on the added branch there exists
8299 + * - a same named entry
8301 + * * negative --> positive
8302 + * * positive --> positive
8303 + * - type is unchanged
8304 + * - type is changed
8306 + * * negative --> negative
8307 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8310 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8311 + struct au_dinfo *tmp)
8314 + aufs_bindex_t bindex, bbot;
8316 + struct dentry *dentry;
8317 + struct inode *inode;
8319 + } orig_h, tmp_h = {
8322 + struct au_hdentry *hd;
8323 + struct inode *inode, *h_inode;
8324 + struct dentry *h_dentry;
8327 + AuDebugOn(dinfo->di_btop < 0);
8329 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8330 + orig_h.inode = NULL;
8331 + if (d_is_positive(orig_h.dentry)) {
8332 + orig_h.inode = d_inode(orig_h.dentry);
8333 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8335 + if (tmp->di_btop >= 0) {
8336 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8337 + if (d_is_positive(tmp_h.dentry)) {
8338 + tmp_h.inode = d_inode(tmp_h.dentry);
8339 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8344 + if (d_really_is_positive(dentry))
8345 + inode = d_inode(dentry);
8346 + if (!orig_h.inode) {
8347 + AuDbg("nagative originally\n");
8353 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8354 + AuDebugOn(dinfo->di_bdiropq != -1);
8356 + if (!tmp_h.inode) {
8357 + AuDbg("negative --> negative\n");
8358 + /* should have only one negative lower */
8359 + if (tmp->di_btop >= 0
8360 + && tmp->di_btop < dinfo->di_btop) {
8361 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8362 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8363 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8364 + au_di_cp(dinfo, tmp);
8365 + hd = au_hdentry(tmp, tmp->di_btop);
8366 + au_set_h_dptr(dentry, tmp->di_btop,
8367 + dget(hd->hd_dentry));
8369 + au_dbg_verify_dinode(dentry);
8371 + AuDbg("negative --> positive\n");
8373 + * similar to the behaviour of creating with bypassing
8375 + * unhash it in order to force an error in the
8376 + * succeeding create operation.
8377 + * we should not set S_DEAD here.
8380 + /* au_di_swap(tmp, dinfo); */
8381 + au_dbg_verify_dinode(dentry);
8384 + AuDbg("positive originally\n");
8385 + /* inode may be NULL */
8386 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8387 + if (!tmp_h.inode) {
8388 + AuDbg("positive --> negative\n");
8389 + /* or bypassing aufs */
8391 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8392 + dinfo->di_bwh = tmp->di_bwh;
8394 + err = au_refresh_hinode_self(inode);
8395 + au_dbg_verify_dinode(dentry);
8396 + } else if (orig_h.mode == tmp_h.mode) {
8397 + AuDbg("positive --> positive, same type\n");
8398 + if (!S_ISDIR(orig_h.mode)
8399 + && dinfo->di_btop > tmp->di_btop) {
8401 + * similar to the behaviour of removing and
8406 + err = au_refresh_hinode_self(inode);
8407 + au_dbg_verify_dinode(dentry);
8409 + /* fill empty slots */
8410 + if (dinfo->di_btop > tmp->di_btop)
8411 + dinfo->di_btop = tmp->di_btop;
8412 + if (dinfo->di_bbot < tmp->di_bbot)
8413 + dinfo->di_bbot = tmp->di_bbot;
8414 + dinfo->di_bwh = tmp->di_bwh;
8415 + dinfo->di_bdiropq = tmp->di_bdiropq;
8416 + bbot = dinfo->di_bbot;
8417 + bindex = tmp->di_btop;
8418 + hd = au_hdentry(tmp, bindex);
8419 + for (; bindex <= bbot; bindex++, hd++) {
8420 + if (au_h_dptr(dentry, bindex))
8422 + h_dentry = hd->hd_dentry;
8425 + AuDebugOn(d_is_negative(h_dentry));
8426 + h_inode = d_inode(h_dentry);
8427 + AuDebugOn(orig_h.mode
8428 + != (h_inode->i_mode
8430 + au_set_h_dptr(dentry, bindex,
8434 + err = au_refresh_hinode(inode, dentry);
8435 + au_dbg_verify_dinode(dentry);
8438 + AuDbg("positive --> positive, different type\n");
8439 + /* similar to the behaviour of removing and creating */
8442 + err = au_refresh_hinode_self(inode);
8443 + au_dbg_verify_dinode(dentry);
8451 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8453 + const struct dentry_operations *dop
8454 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8455 + static const unsigned int mask
8456 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8458 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8460 + if (dentry->d_op == dop)
8463 + AuDbg("%pd\n", dentry);
8464 + spin_lock(&dentry->d_lock);
8465 + if (dop == &aufs_dop)
8466 + dentry->d_flags |= mask;
8468 + dentry->d_flags &= ~mask;
8469 + dentry->d_op = dop;
8470 + spin_unlock(&dentry->d_lock);
8473 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8475 + int err, ebrange, nbr;
8476 + unsigned int sigen;
8477 + struct au_dinfo *dinfo, *tmp;
8478 + struct super_block *sb;
8479 + struct inode *inode;
8481 + DiMustWriteLock(dentry);
8482 + AuDebugOn(IS_ROOT(dentry));
8483 + AuDebugOn(d_really_is_negative(parent));
8485 + sb = dentry->d_sb;
8486 + sigen = au_sigen(sb);
8487 + err = au_digen_test(parent, sigen);
8488 + if (unlikely(err))
8491 + nbr = au_sbbot(sb) + 1;
8492 + dinfo = au_di(dentry);
8493 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8494 + if (unlikely(err))
8496 + ebrange = au_dbrange_test(dentry);
8498 + ebrange = au_do_refresh_hdentry(dentry, parent);
8500 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8501 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8502 + if (d_really_is_positive(dentry)) {
8503 + inode = d_inode(dentry);
8504 + err = au_refresh_hinode_self(inode);
8506 + au_dbg_verify_dinode(dentry);
8508 + goto out_dgen; /* success */
8512 + /* temporary dinfo */
8513 + AuDbgDentry(dentry);
8515 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8516 + if (unlikely(!tmp))
8518 + au_di_swap(tmp, dinfo);
8519 + /* returns the number of positive dentries */
8521 + * if current working dir is removed, it returns an error.
8522 + * but the dentry is legal.
8524 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8525 + AuDbgDentry(dentry);
8526 + au_di_swap(tmp, dinfo);
8527 + if (err == -ENOENT)
8530 + /* compare/refresh by dinfo */
8531 + AuDbgDentry(dentry);
8532 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8533 + au_dbg_verify_dinode(dentry);
8536 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8537 + au_rw_write_unlock(&tmp->di_rwsem);
8539 + if (unlikely(err))
8543 + au_update_digen(dentry);
8545 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8546 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8547 + AuDbgDentry(dentry);
8553 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8554 + struct dentry *dentry, aufs_bindex_t bindex)
8559 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8562 + AuDbg("b%d\n", bindex);
8564 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8565 + * due to whiteout and branch permission.
8567 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8568 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8569 + /* it may return tri-state */
8570 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8572 + if (unlikely(valid < 0))
8582 +/* todo: remove this */
8583 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8584 + unsigned int flags, int do_udba)
8587 + umode_t mode, h_mode;
8588 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8589 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8590 + struct inode *h_inode, *h_cached_inode;
8591 + struct dentry *h_dentry;
8592 + struct qstr *name, *h_name;
8599 + unhashed = !!d_unhashed(dentry);
8600 + is_root = !!IS_ROOT(dentry);
8601 + name = &dentry->d_name;
8602 + tmpfile = au_di(dentry)->di_tmpfile;
8605 + * Theoretically, REVAL test should be unnecessary in case of
8607 + * But {fs,i}notify doesn't fire some necessary events,
8608 + * IN_ATTRIB for atime/nlink/pageio
8609 + * Let's do REVAL test too.
8611 + if (do_udba && inode) {
8612 + mode = (inode->i_mode & S_IFMT);
8613 + plus = (inode->i_nlink > 0);
8614 + ibs = au_ibtop(inode);
8615 + ibe = au_ibbot(inode);
8618 + btop = au_dbtop(dentry);
8620 + if (inode && S_ISDIR(inode->i_mode))
8621 + btail = au_dbtaildir(dentry);
8622 + for (bindex = btop; bindex <= btail; bindex++) {
8623 + h_dentry = au_h_dptr(dentry, bindex);
8627 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8628 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8629 + spin_lock(&h_dentry->d_lock);
8630 + h_name = &h_dentry->d_name;
8631 + if (unlikely(do_udba
8634 + && (unhashed != !!d_unhashed(h_dentry)
8636 + && !au_qstreq(name, h_name))
8639 + && !(flags & LOOKUP_OPEN)
8640 + && (h_dentry->d_flags
8641 + & DCACHE_NFSFS_RENAMED)))
8645 + h_unhashed = d_unhashed(h_dentry);
8646 + spin_unlock(&h_dentry->d_lock);
8647 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8648 + unhashed, h_unhashed, dentry, h_dentry);
8651 + spin_unlock(&h_dentry->d_lock);
8653 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8654 + if (unlikely(err))
8655 + /* do not goto err, to keep the errno */
8658 + /* todo: plink too? */
8663 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8667 + if (d_is_positive(h_dentry))
8668 + h_inode = d_inode(h_dentry);
8671 + h_cached_inode = h_inode;
8673 + h_mode = (h_inode->i_mode & S_IFMT);
8674 + h_plus = (h_inode->i_nlink > 0);
8676 + if (inode && ibs <= bindex && bindex <= ibe)
8677 + h_cached_inode = au_h_iptr(inode, bindex);
8680 + if (unlikely(plus != h_plus && !tmpfile))
8683 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8685 + && !IS_ROOT(h_dentry)
8686 + && unhashed != d_unhashed(h_dentry)))
8689 + if (unlikely(mode != h_mode
8690 + || h_cached_inode != h_inode))
8703 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8704 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8707 + struct dentry *parent;
8709 + if (!au_digen_test(dentry, sigen))
8712 + parent = dget_parent(dentry);
8713 + di_read_lock_parent(parent, AuLock_IR);
8714 + AuDebugOn(au_digen_test(parent, sigen));
8715 + au_dbg_verify_gen(parent, sigen);
8716 + err = au_refresh_dentry(dentry, parent);
8717 + di_read_unlock(parent, AuLock_IR);
8723 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8726 + struct dentry *d, *parent;
8728 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8729 + return simple_reval_dpath(dentry, sigen);
8731 + /* slow loop, keep it simple and stupid */
8732 + /* cf: au_cpup_dirs() */
8735 + while (au_digen_test(dentry, sigen)) {
8739 + parent = dget_parent(d);
8740 + if (!au_digen_test(parent, sigen))
8746 + di_write_lock_child2(d);
8748 + /* someone might update our dentry while we were sleeping */
8749 + if (au_digen_test(d, sigen)) {
8751 + * todo: consolidate with simple_reval_dpath(),
8752 + * do_refresh() and au_reval_for_attr().
8754 + di_read_lock_parent(parent, AuLock_IR);
8755 + err = au_refresh_dentry(d, parent);
8756 + di_read_unlock(parent, AuLock_IR);
8760 + di_write_unlock(d);
8762 + if (unlikely(err))
8770 + * if valid returns 1, otherwise 0.
8772 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8775 + unsigned int sigen;
8776 + unsigned char do_udba;
8777 + struct super_block *sb;
8778 + struct inode *inode;
8780 + /* todo: support rcu-walk? */
8781 + if (flags & LOOKUP_RCU)
8785 + if (unlikely(!au_di(dentry)))
8789 + sb = dentry->d_sb;
8792 + * i_mutex of parent dir may be held,
8793 + * but we should not return 'invalid' due to busy.
8795 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8796 + if (unlikely(err)) {
8802 + if (d_really_is_positive(dentry))
8803 + inode = d_inode(dentry);
8804 + if (unlikely(inode && au_is_bad_inode(inode))) {
8809 + if (unlikely(au_dbrange_test(dentry))) {
8815 + sigen = au_sigen(sb);
8816 + if (au_digen_test(dentry, sigen)) {
8817 + AuDebugOn(IS_ROOT(dentry));
8818 + err = au_reval_dpath(dentry, sigen);
8819 + if (unlikely(err)) {
8824 + di_downgrade_lock(dentry, AuLock_IR);
8827 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8829 + && !(inode->i_state && I_LINKABLE)
8830 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8835 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8836 + if (do_udba && inode) {
8837 + aufs_bindex_t btop = au_ibtop(inode);
8838 + struct inode *h_inode;
8841 + h_inode = au_h_iptr(inode, btop);
8842 + if (h_inode && au_test_higen(inode, h_inode)) {
8849 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8850 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8852 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8858 + di_downgrade_lock(dentry, AuLock_IR);
8860 + aufs_read_unlock(dentry, AuLock_IR);
8865 + AuDbg("%pd invalid, %d\n", dentry, valid);
8871 +static void aufs_d_release(struct dentry *dentry)
8873 + if (au_di(dentry)) {
8874 + au_di_fin(dentry);
8875 + au_hn_di_reinit(dentry);
8879 +const struct dentry_operations aufs_dop = {
8880 + .d_revalidate = aufs_d_revalidate,
8881 + .d_weak_revalidate = aufs_d_revalidate,
8882 + .d_release = aufs_d_release
8885 +/* aufs_dop without d_revalidate */
8886 +const struct dentry_operations aufs_dop_noreval = {
8887 + .d_release = aufs_d_release
8889 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8890 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8891 +++ linux/fs/aufs/dentry.h 2017-07-29 12:14:25.899708630 +0200
8894 + * Copyright (C) 2005-2017 Junjiro R. Okajima
8896 + * This program, aufs is free software; you can redistribute it and/or modify
8897 + * it under the terms of the GNU General Public License as published by
8898 + * the Free Software Foundation; either version 2 of the License, or
8899 + * (at your option) any later version.
8901 + * This program is distributed in the hope that it will be useful,
8902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8904 + * GNU General Public License for more details.
8906 + * You should have received a copy of the GNU General Public License
8907 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8911 + * lookup and dentry operations
8914 +#ifndef __AUFS_DENTRY_H__
8915 +#define __AUFS_DENTRY_H__
8919 +#include <linux/dcache.h>
8922 +struct au_hdentry {
8923 + struct dentry *hd_dentry;
8924 + aufs_bindex_t hd_id;
8928 + atomic_t di_generation;
8930 + struct au_rwsem di_rwsem;
8931 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8932 + unsigned char di_tmpfile; /* to allow the different name */
8933 + struct au_hdentry *di_hdentry;
8934 +} ____cacheline_aligned_in_smp;
8936 +/* ---------------------------------------------------------------------- */
8938 +/* flags for au_lkup_dentry() */
8939 +#define AuLkup_ALLOW_NEG 1
8940 +#define AuLkup_IGNORE_PERM (1 << 1)
8941 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8942 +#define au_fset_lkup(flags, name) \
8943 + do { (flags) |= AuLkup_##name; } while (0)
8944 +#define au_fclr_lkup(flags, name) \
8945 + do { (flags) &= ~AuLkup_##name; } while (0)
8947 +/* ---------------------------------------------------------------------- */
8950 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8952 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8953 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8954 + struct dentry *h_parent, struct au_branch *br);
8956 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8957 + unsigned int flags);
8958 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8959 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8960 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8961 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8964 +void au_di_init_once(void *_di);
8965 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8966 +void au_di_free(struct au_dinfo *dinfo);
8967 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8968 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8969 +int au_di_init(struct dentry *dentry);
8970 +void au_di_fin(struct dentry *dentry);
8971 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8973 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8974 +void di_read_unlock(struct dentry *d, int flags);
8975 +void di_downgrade_lock(struct dentry *d, int flags);
8976 +void di_write_lock(struct dentry *d, unsigned int lsc);
8977 +void di_write_unlock(struct dentry *d);
8978 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8979 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8980 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8982 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8983 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8984 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8985 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8987 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8988 + struct dentry *h_dentry);
8989 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8990 +int au_dbrange_test(struct dentry *dentry);
8991 +void au_update_digen(struct dentry *dentry);
8992 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8993 +void au_update_dbtop(struct dentry *dentry);
8994 +void au_update_dbbot(struct dentry *dentry);
8995 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8997 +/* ---------------------------------------------------------------------- */
8999 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9001 + return dentry->d_fsdata;
9004 +/* ---------------------------------------------------------------------- */
9006 +/* lock subclass for dinfo */
9008 + AuLsc_DI_CHILD, /* child first */
9009 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9010 + AuLsc_DI_CHILD3, /* copyup dirs */
9014 + AuLsc_DI_TMP /* temp for replacing dinfo */
9018 + * di_read_lock_child, di_write_lock_child,
9019 + * di_read_lock_child2, di_write_lock_child2,
9020 + * di_read_lock_child3, di_write_lock_child3,
9021 + * di_read_lock_parent, di_write_lock_parent,
9022 + * di_read_lock_parent2, di_write_lock_parent2,
9023 + * di_read_lock_parent3, di_write_lock_parent3,
9025 +#define AuReadLockFunc(name, lsc) \
9026 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9027 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9029 +#define AuWriteLockFunc(name, lsc) \
9030 +static inline void di_write_lock_##name(struct dentry *d) \
9031 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9033 +#define AuRWLockFuncs(name, lsc) \
9034 + AuReadLockFunc(name, lsc) \
9035 + AuWriteLockFunc(name, lsc)
9037 +AuRWLockFuncs(child, CHILD);
9038 +AuRWLockFuncs(child2, CHILD2);
9039 +AuRWLockFuncs(child3, CHILD3);
9040 +AuRWLockFuncs(parent, PARENT);
9041 +AuRWLockFuncs(parent2, PARENT2);
9042 +AuRWLockFuncs(parent3, PARENT3);
9044 +#undef AuReadLockFunc
9045 +#undef AuWriteLockFunc
9046 +#undef AuRWLockFuncs
9048 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9049 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9050 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9052 +/* ---------------------------------------------------------------------- */
9054 +/* todo: memory barrier? */
9055 +static inline unsigned int au_digen(struct dentry *d)
9057 + return atomic_read(&au_di(d)->di_generation);
9060 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9062 + hdentry->hd_dentry = NULL;
9065 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9066 + aufs_bindex_t bindex)
9068 + return di->di_hdentry + bindex;
9071 +static inline void au_hdput(struct au_hdentry *hd)
9074 + dput(hd->hd_dentry);
9077 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9079 + DiMustAnyLock(dentry);
9080 + return au_di(dentry)->di_btop;
9083 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9085 + DiMustAnyLock(dentry);
9086 + return au_di(dentry)->di_bbot;
9089 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9091 + DiMustAnyLock(dentry);
9092 + return au_di(dentry)->di_bwh;
9095 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9097 + DiMustAnyLock(dentry);
9098 + return au_di(dentry)->di_bdiropq;
9101 +/* todo: hard/soft set? */
9102 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9104 + DiMustWriteLock(dentry);
9105 + au_di(dentry)->di_btop = bindex;
9108 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9110 + DiMustWriteLock(dentry);
9111 + au_di(dentry)->di_bbot = bindex;
9114 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9116 + DiMustWriteLock(dentry);
9117 + /* dbwh can be outside of btop - bbot range */
9118 + au_di(dentry)->di_bwh = bindex;
9121 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9123 + DiMustWriteLock(dentry);
9124 + au_di(dentry)->di_bdiropq = bindex;
9127 +/* ---------------------------------------------------------------------- */
9129 +#ifdef CONFIG_AUFS_HNOTIFY
9130 +static inline void au_digen_dec(struct dentry *d)
9132 + atomic_dec(&au_di(d)->di_generation);
9135 +static inline void au_hn_di_reinit(struct dentry *dentry)
9137 + dentry->d_fsdata = NULL;
9140 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9141 +#endif /* CONFIG_AUFS_HNOTIFY */
9143 +#endif /* __KERNEL__ */
9144 +#endif /* __AUFS_DENTRY_H__ */
9145 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9146 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9147 +++ linux/fs/aufs/dinfo.c 2017-07-29 12:14:25.899708630 +0200
9150 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9152 + * This program, aufs is free software; you can redistribute it and/or modify
9153 + * it under the terms of the GNU General Public License as published by
9154 + * the Free Software Foundation; either version 2 of the License, or
9155 + * (at your option) any later version.
9157 + * This program is distributed in the hope that it will be useful,
9158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9160 + * GNU General Public License for more details.
9162 + * You should have received a copy of the GNU General Public License
9163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9167 + * dentry private data
9172 +void au_di_init_once(void *_dinfo)
9174 + struct au_dinfo *dinfo = _dinfo;
9176 + au_rw_init(&dinfo->di_rwsem);
9179 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9181 + struct au_dinfo *dinfo;
9184 + dinfo = au_cache_alloc_dinfo();
9185 + if (unlikely(!dinfo))
9188 + nbr = au_sbbot(sb) + 1;
9191 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9192 + if (dinfo->di_hdentry) {
9193 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9194 + dinfo->di_btop = -1;
9195 + dinfo->di_bbot = -1;
9196 + dinfo->di_bwh = -1;
9197 + dinfo->di_bdiropq = -1;
9198 + dinfo->di_tmpfile = 0;
9199 + for (i = 0; i < nbr; i++)
9200 + dinfo->di_hdentry[i].hd_id = -1;
9204 + au_cache_free_dinfo(dinfo);
9211 +void au_di_free(struct au_dinfo *dinfo)
9213 + struct au_hdentry *p;
9214 + aufs_bindex_t bbot, bindex;
9216 + /* dentry may not be revalidated */
9217 + bindex = dinfo->di_btop;
9218 + if (bindex >= 0) {
9219 + bbot = dinfo->di_bbot;
9220 + p = au_hdentry(dinfo, bindex);
9221 + while (bindex++ <= bbot)
9224 + kfree(dinfo->di_hdentry);
9225 + au_cache_free_dinfo(dinfo);
9228 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9230 + struct au_hdentry *p;
9233 + AuRwMustWriteLock(&a->di_rwsem);
9234 + AuRwMustWriteLock(&b->di_rwsem);
9236 +#define DiSwap(v, name) \
9238 + v = a->di_##name; \
9239 + a->di_##name = b->di_##name; \
9240 + b->di_##name = v; \
9243 + DiSwap(p, hdentry);
9247 + DiSwap(bi, bdiropq);
9253 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9255 + AuRwMustWriteLock(&dst->di_rwsem);
9256 + AuRwMustWriteLock(&src->di_rwsem);
9258 + dst->di_btop = src->di_btop;
9259 + dst->di_bbot = src->di_bbot;
9260 + dst->di_bwh = src->di_bwh;
9261 + dst->di_bdiropq = src->di_bdiropq;
9265 +int au_di_init(struct dentry *dentry)
9268 + struct super_block *sb;
9269 + struct au_dinfo *dinfo;
9272 + sb = dentry->d_sb;
9273 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9275 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9276 + /* smp_mb(); */ /* atomic_set */
9277 + dentry->d_fsdata = dinfo;
9284 +void au_di_fin(struct dentry *dentry)
9286 + struct au_dinfo *dinfo;
9288 + dinfo = au_di(dentry);
9289 + AuRwDestroy(&dinfo->di_rwsem);
9290 + au_di_free(dinfo);
9293 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9296 + struct au_hdentry *hdp;
9298 + AuRwMustWriteLock(&dinfo->di_rwsem);
9301 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9303 + sz = sizeof(*hdp);
9304 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9307 + dinfo->di_hdentry = hdp;
9314 +/* ---------------------------------------------------------------------- */
9316 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9319 + case AuLsc_DI_CHILD:
9320 + ii_write_lock_child(inode);
9322 + case AuLsc_DI_CHILD2:
9323 + ii_write_lock_child2(inode);
9325 + case AuLsc_DI_CHILD3:
9326 + ii_write_lock_child3(inode);
9328 + case AuLsc_DI_PARENT:
9329 + ii_write_lock_parent(inode);
9331 + case AuLsc_DI_PARENT2:
9332 + ii_write_lock_parent2(inode);
9334 + case AuLsc_DI_PARENT3:
9335 + ii_write_lock_parent3(inode);
9342 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9345 + case AuLsc_DI_CHILD:
9346 + ii_read_lock_child(inode);
9348 + case AuLsc_DI_CHILD2:
9349 + ii_read_lock_child2(inode);
9351 + case AuLsc_DI_CHILD3:
9352 + ii_read_lock_child3(inode);
9354 + case AuLsc_DI_PARENT:
9355 + ii_read_lock_parent(inode);
9357 + case AuLsc_DI_PARENT2:
9358 + ii_read_lock_parent2(inode);
9360 + case AuLsc_DI_PARENT3:
9361 + ii_read_lock_parent3(inode);
9368 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9370 + struct inode *inode;
9372 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9373 + if (d_really_is_positive(d)) {
9374 + inode = d_inode(d);
9375 + if (au_ftest_lock(flags, IW))
9376 + do_ii_write_lock(inode, lsc);
9377 + else if (au_ftest_lock(flags, IR))
9378 + do_ii_read_lock(inode, lsc);
9382 +void di_read_unlock(struct dentry *d, int flags)
9384 + struct inode *inode;
9386 + if (d_really_is_positive(d)) {
9387 + inode = d_inode(d);
9388 + if (au_ftest_lock(flags, IW)) {
9389 + au_dbg_verify_dinode(d);
9390 + ii_write_unlock(inode);
9391 + } else if (au_ftest_lock(flags, IR)) {
9392 + au_dbg_verify_dinode(d);
9393 + ii_read_unlock(inode);
9396 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9399 +void di_downgrade_lock(struct dentry *d, int flags)
9401 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9402 + ii_downgrade_lock(d_inode(d));
9403 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9406 +void di_write_lock(struct dentry *d, unsigned int lsc)
9408 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9409 + if (d_really_is_positive(d))
9410 + do_ii_write_lock(d_inode(d), lsc);
9413 +void di_write_unlock(struct dentry *d)
9415 + au_dbg_verify_dinode(d);
9416 + if (d_really_is_positive(d))
9417 + ii_write_unlock(d_inode(d));
9418 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9421 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9423 + AuDebugOn(d1 == d2
9424 + || d_inode(d1) == d_inode(d2)
9425 + || d1->d_sb != d2->d_sb);
9427 + if ((isdir && au_test_subdir(d1, d2))
9429 + di_write_lock_child(d1);
9430 + di_write_lock_child2(d2);
9432 + di_write_lock_child(d2);
9433 + di_write_lock_child2(d1);
9437 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9439 + AuDebugOn(d1 == d2
9440 + || d_inode(d1) == d_inode(d2)
9441 + || d1->d_sb != d2->d_sb);
9443 + if ((isdir && au_test_subdir(d1, d2))
9445 + di_write_lock_parent(d1);
9446 + di_write_lock_parent2(d2);
9448 + di_write_lock_parent(d2);
9449 + di_write_lock_parent2(d1);
9453 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9455 + di_write_unlock(d1);
9456 + if (d_inode(d1) == d_inode(d2))
9457 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9459 + di_write_unlock(d2);
9462 +/* ---------------------------------------------------------------------- */
9464 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9468 + DiMustAnyLock(dentry);
9470 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9472 + AuDebugOn(bindex < 0);
9473 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9474 + AuDebugOn(d && au_dcount(d) <= 0);
9479 + * extended version of au_h_dptr().
9480 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9483 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9485 + struct dentry *h_dentry;
9486 + struct inode *inode, *h_inode;
9488 + AuDebugOn(d_really_is_negative(dentry));
9491 + if (au_dbtop(dentry) <= bindex
9492 + && bindex <= au_dbbot(dentry))
9493 + h_dentry = au_h_dptr(dentry, bindex);
9494 + if (h_dentry && !au_d_linkable(h_dentry)) {
9496 + goto out; /* success */
9499 + inode = d_inode(dentry);
9500 + AuDebugOn(bindex < au_ibtop(inode));
9501 + AuDebugOn(au_ibbot(inode) < bindex);
9502 + h_inode = au_h_iptr(inode, bindex);
9503 + h_dentry = d_find_alias(h_inode);
9505 + if (!IS_ERR(h_dentry)) {
9506 + if (!au_d_linkable(h_dentry))
9507 + goto out; /* success */
9513 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9514 + h_dentry = au_plink_lkup(inode, bindex);
9515 + AuDebugOn(!h_dentry);
9516 + if (!IS_ERR(h_dentry)) {
9517 + if (!au_d_hashed_positive(h_dentry))
9518 + goto out; /* success */
9525 + AuDbgDentry(h_dentry);
9529 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9531 + aufs_bindex_t bbot, bwh;
9533 + bbot = au_dbbot(dentry);
9535 + bwh = au_dbwh(dentry);
9538 + if (0 < bwh && bwh < bbot)
9544 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9546 + aufs_bindex_t bbot, bopq;
9548 + bbot = au_dbtail(dentry);
9550 + bopq = au_dbdiropq(dentry);
9551 + if (0 <= bopq && bopq < bbot)
9557 +/* ---------------------------------------------------------------------- */
9559 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9560 + struct dentry *h_dentry)
9562 + struct au_dinfo *dinfo;
9563 + struct au_hdentry *hd;
9564 + struct au_branch *br;
9566 + DiMustWriteLock(dentry);
9568 + dinfo = au_di(dentry);
9569 + hd = au_hdentry(dinfo, bindex);
9571 + hd->hd_dentry = h_dentry;
9573 + br = au_sbr(dentry->d_sb, bindex);
9574 + hd->hd_id = br->br_id;
9578 +int au_dbrange_test(struct dentry *dentry)
9581 + aufs_bindex_t btop, bbot;
9584 + btop = au_dbtop(dentry);
9585 + bbot = au_dbbot(dentry);
9587 + AuDebugOn(bbot < 0 && btop > bbot);
9590 + AuDebugOn(bbot >= 0);
9596 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9601 + if (unlikely(au_digen(dentry) != sigen
9602 + || au_iigen_test(d_inode(dentry), sigen)))
9608 +void au_update_digen(struct dentry *dentry)
9610 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9611 + /* smp_mb(); */ /* atomic_set */
9614 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9616 + struct au_dinfo *dinfo;
9617 + struct dentry *h_d;
9618 + struct au_hdentry *hdp;
9619 + aufs_bindex_t bindex, bbot;
9621 + DiMustWriteLock(dentry);
9623 + dinfo = au_di(dentry);
9624 + if (!dinfo || dinfo->di_btop < 0)
9627 + if (do_put_zero) {
9628 + bbot = dinfo->di_bbot;
9629 + bindex = dinfo->di_btop;
9630 + hdp = au_hdentry(dinfo, bindex);
9631 + for (; bindex <= bbot; bindex++, hdp++) {
9632 + h_d = hdp->hd_dentry;
9633 + if (h_d && d_is_negative(h_d))
9634 + au_set_h_dptr(dentry, bindex, NULL);
9638 + dinfo->di_btop = 0;
9639 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9640 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9641 + if (hdp->hd_dentry)
9643 + if (dinfo->di_btop > dinfo->di_bbot) {
9644 + dinfo->di_btop = -1;
9645 + dinfo->di_bbot = -1;
9649 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9650 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9651 + if (hdp->hd_dentry)
9653 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9656 +void au_update_dbtop(struct dentry *dentry)
9658 + aufs_bindex_t bindex, bbot;
9659 + struct dentry *h_dentry;
9661 + bbot = au_dbbot(dentry);
9662 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9663 + h_dentry = au_h_dptr(dentry, bindex);
9666 + if (d_is_positive(h_dentry)) {
9667 + au_set_dbtop(dentry, bindex);
9670 + au_set_h_dptr(dentry, bindex, NULL);
9674 +void au_update_dbbot(struct dentry *dentry)
9676 + aufs_bindex_t bindex, btop;
9677 + struct dentry *h_dentry;
9679 + btop = au_dbtop(dentry);
9680 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9681 + h_dentry = au_h_dptr(dentry, bindex);
9684 + if (d_is_positive(h_dentry)) {
9685 + au_set_dbbot(dentry, bindex);
9688 + au_set_h_dptr(dentry, bindex, NULL);
9692 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9694 + aufs_bindex_t bindex, bbot;
9696 + bbot = au_dbbot(dentry);
9697 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9698 + if (au_h_dptr(dentry, bindex) == h_dentry)
9702 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9703 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9704 +++ linux/fs/aufs/dir.c 2017-09-05 10:42:11.058755349 +0200
9707 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9709 + * This program, aufs is free software; you can redistribute it and/or modify
9710 + * it under the terms of the GNU General Public License as published by
9711 + * the Free Software Foundation; either version 2 of the License, or
9712 + * (at your option) any later version.
9714 + * This program is distributed in the hope that it will be useful,
9715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9717 + * GNU General Public License for more details.
9719 + * You should have received a copy of the GNU General Public License
9720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9724 + * directory operations
9727 +#include <linux/fs_stack.h>
9730 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9732 + unsigned int nlink;
9734 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9736 + nlink = dir->i_nlink;
9737 + nlink += h_dir->i_nlink - 2;
9738 + if (h_dir->i_nlink < 2)
9740 + smp_mb(); /* for i_nlink */
9741 + /* 0 can happen in revaliding */
9742 + set_nlink(dir, nlink);
9745 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9747 + unsigned int nlink;
9749 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9751 + nlink = dir->i_nlink;
9752 + nlink -= h_dir->i_nlink - 2;
9753 + if (h_dir->i_nlink < 2)
9755 + smp_mb(); /* for i_nlink */
9756 + /* nlink == 0 means the branch-fs is broken */
9757 + set_nlink(dir, nlink);
9760 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9763 + aufs_bindex_t bindex, bbot;
9764 + struct file *h_file;
9765 + struct dentry *h_dentry;
9769 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9771 + bbot = au_fbbot_dir(file);
9772 + for (bindex = au_fbtop(file);
9773 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9775 + h_file = au_hf_dir(file, bindex);
9776 + if (h_file && file_inode(h_file))
9777 + sz += vfsub_f_size_read(h_file);
9780 + AuDebugOn(!dentry);
9781 + AuDebugOn(!d_is_dir(dentry));
9783 + bbot = au_dbtaildir(dentry);
9784 + for (bindex = au_dbtop(dentry);
9785 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9787 + h_dentry = au_h_dptr(dentry, bindex);
9788 + if (h_dentry && d_is_positive(h_dentry))
9789 + sz += i_size_read(d_inode(h_dentry));
9792 + if (sz < KMALLOC_MAX_SIZE)
9793 + sz = roundup_pow_of_two(sz);
9794 + if (sz > KMALLOC_MAX_SIZE)
9795 + sz = KMALLOC_MAX_SIZE;
9796 + else if (sz < NAME_MAX) {
9797 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9798 + sz = AUFS_RDBLK_DEF;
9803 +struct au_dir_ts_arg {
9804 + struct dentry *dentry;
9805 + aufs_bindex_t brid;
9808 +static void au_do_dir_ts(void *arg)
9810 + struct au_dir_ts_arg *a = arg;
9811 + struct au_dtime dt;
9812 + struct path h_path;
9813 + struct inode *dir, *h_dir;
9814 + struct super_block *sb;
9815 + struct au_branch *br;
9816 + struct au_hinode *hdir;
9818 + aufs_bindex_t btop, bindex;
9820 + sb = a->dentry->d_sb;
9821 + if (d_really_is_negative(a->dentry))
9823 + /* no dir->i_mutex lock */
9824 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9826 + dir = d_inode(a->dentry);
9827 + btop = au_ibtop(dir);
9828 + bindex = au_br_index(sb, a->brid);
9829 + if (bindex < btop)
9832 + br = au_sbr(sb, bindex);
9833 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9834 + if (!h_path.dentry)
9836 + h_path.mnt = au_br_mnt(br);
9837 + au_dtime_store(&dt, a->dentry, &h_path);
9839 + br = au_sbr(sb, btop);
9840 + if (!au_br_writable(br->br_perm))
9842 + h_path.dentry = au_h_dptr(a->dentry, btop);
9843 + h_path.mnt = au_br_mnt(br);
9844 + err = vfsub_mnt_want_write(h_path.mnt);
9847 + hdir = au_hi(dir, btop);
9848 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9849 + h_dir = au_h_iptr(dir, btop);
9850 + if (h_dir->i_nlink
9851 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9852 + dt.dt_h_path = h_path;
9853 + au_dtime_revert(&dt);
9855 + au_hn_inode_unlock(hdir);
9856 + vfsub_mnt_drop_write(h_path.mnt);
9857 + au_cpup_attr_timesizes(dir);
9860 + aufs_read_unlock(a->dentry, AuLock_DW);
9863 + au_nwt_done(&au_sbi(sb)->si_nowait);
9867 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9869 + int perm, wkq_err;
9870 + aufs_bindex_t btop;
9871 + struct au_dir_ts_arg *arg;
9872 + struct dentry *dentry;
9873 + struct super_block *sb;
9877 + dentry = d_find_any_alias(dir);
9878 + AuDebugOn(!dentry);
9879 + sb = dentry->d_sb;
9880 + btop = au_ibtop(dir);
9881 + if (btop == bindex) {
9882 + au_cpup_attr_timesizes(dir);
9886 + perm = au_sbr_perm(sb, btop);
9887 + if (!au_br_writable(perm))
9890 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9894 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9895 + arg->brid = au_sbr_id(sb, bindex);
9896 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9897 + if (unlikely(wkq_err)) {
9898 + pr_err("wkq %d\n", wkq_err);
9907 +/* ---------------------------------------------------------------------- */
9909 +static int reopen_dir(struct file *file)
9912 + unsigned int flags;
9913 + aufs_bindex_t bindex, btail, btop;
9914 + struct dentry *dentry, *h_dentry;
9915 + struct file *h_file;
9917 + /* open all lower dirs */
9918 + dentry = file->f_path.dentry;
9919 + btop = au_dbtop(dentry);
9920 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9921 + au_set_h_fptr(file, bindex, NULL);
9922 + au_set_fbtop(file, btop);
9924 + btail = au_dbtaildir(dentry);
9925 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9926 + au_set_h_fptr(file, bindex, NULL);
9927 + au_set_fbbot_dir(file, btail);
9929 + flags = vfsub_file_flags(file);
9930 + for (bindex = btop; bindex <= btail; bindex++) {
9931 + h_dentry = au_h_dptr(dentry, bindex);
9934 + h_file = au_hf_dir(file, bindex);
9938 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9939 + err = PTR_ERR(h_file);
9940 + if (IS_ERR(h_file))
9941 + goto out; /* close all? */
9942 + au_set_h_fptr(file, bindex, h_file);
9944 + au_update_figen(file);
9945 + /* todo: necessary? */
9946 + /* file->f_ra = h_file->f_ra; */
9953 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9956 + aufs_bindex_t bindex, btail;
9957 + struct dentry *dentry, *h_dentry;
9958 + struct vfsmount *mnt;
9960 + FiMustWriteLock(file);
9961 + AuDebugOn(h_file);
9964 + mnt = file->f_path.mnt;
9965 + dentry = file->f_path.dentry;
9966 + file->f_version = d_inode(dentry)->i_version;
9967 + bindex = au_dbtop(dentry);
9968 + au_set_fbtop(file, bindex);
9969 + btail = au_dbtaildir(dentry);
9970 + au_set_fbbot_dir(file, btail);
9971 + for (; !err && bindex <= btail; bindex++) {
9972 + h_dentry = au_h_dptr(dentry, bindex);
9976 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9977 + if (unlikely(err))
9979 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9980 + if (IS_ERR(h_file)) {
9981 + err = PTR_ERR(h_file);
9984 + au_set_h_fptr(file, bindex, h_file);
9986 + au_update_figen(file);
9987 + /* todo: necessary? */
9988 + /* file->f_ra = h_file->f_ra; */
9990 + return 0; /* success */
9993 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9994 + au_set_h_fptr(file, bindex, NULL);
9995 + au_set_fbtop(file, -1);
9996 + au_set_fbbot_dir(file, -1);
10001 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10002 + struct file *file)
10005 + struct super_block *sb;
10006 + struct au_fidir *fidir;
10009 + sb = file->f_path.dentry->d_sb;
10010 + si_read_lock(sb, AuLock_FLUSH);
10011 + fidir = au_fidir_alloc(sb);
10013 + struct au_do_open_args args = {
10014 + .open = do_open_dir,
10017 + err = au_do_open(file, &args);
10018 + if (unlikely(err))
10021 + si_read_unlock(sb);
10025 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10026 + struct file *file)
10028 + struct au_vdir *vdir_cache;
10029 + struct au_finfo *finfo;
10030 + struct au_fidir *fidir;
10031 + struct au_hfile *hf;
10032 + aufs_bindex_t bindex, bbot;
10034 + finfo = au_fi(file);
10035 + fidir = finfo->fi_hdir;
10037 + au_sphl_del(&finfo->fi_hlist,
10038 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10039 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10041 + au_vdir_free(vdir_cache);
10043 + bindex = finfo->fi_btop;
10044 + if (bindex >= 0) {
10045 + hf = fidir->fd_hfile + bindex;
10047 + * calls fput() instead of filp_close(),
10048 + * since no dnotify or lock for the lower file.
10050 + bbot = fidir->fd_bbot;
10051 + for (; bindex <= bbot; bindex++, hf++)
10053 + au_hfput(hf, /*execed*/0);
10056 + finfo->fi_hdir = NULL;
10058 + au_finfo_fin(file);
10062 +/* ---------------------------------------------------------------------- */
10064 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10067 + aufs_bindex_t bindex, bbot;
10068 + struct file *h_file;
10071 + bbot = au_fbbot_dir(file);
10072 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10073 + h_file = au_hf_dir(file, bindex);
10075 + err = vfsub_flush(h_file, id);
10080 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10082 + return au_do_flush(file, id, au_do_flush_dir);
10085 +/* ---------------------------------------------------------------------- */
10087 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10090 + aufs_bindex_t bbot, bindex;
10091 + struct inode *inode;
10092 + struct super_block *sb;
10095 + sb = dentry->d_sb;
10096 + inode = d_inode(dentry);
10097 + IMustLock(inode);
10098 + bbot = au_dbbot(dentry);
10099 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10100 + struct path h_path;
10102 + if (au_test_ro(sb, bindex, inode))
10104 + h_path.dentry = au_h_dptr(dentry, bindex);
10105 + if (!h_path.dentry)
10108 + h_path.mnt = au_sbr_mnt(sb, bindex);
10109 + err = vfsub_fsync(NULL, &h_path, datasync);
10115 +static int au_do_fsync_dir(struct file *file, int datasync)
10118 + aufs_bindex_t bbot, bindex;
10119 + struct file *h_file;
10120 + struct super_block *sb;
10121 + struct inode *inode;
10123 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10124 + if (unlikely(err))
10127 + inode = file_inode(file);
10128 + sb = inode->i_sb;
10129 + bbot = au_fbbot_dir(file);
10130 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10131 + h_file = au_hf_dir(file, bindex);
10132 + if (!h_file || au_test_ro(sb, bindex, inode))
10135 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10143 + * @file may be NULL
10145 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10149 + struct dentry *dentry;
10150 + struct inode *inode;
10151 + struct super_block *sb;
10154 + dentry = file->f_path.dentry;
10155 + inode = d_inode(dentry);
10156 + inode_lock(inode);
10157 + sb = dentry->d_sb;
10158 + si_noflush_read_lock(sb);
10160 + err = au_do_fsync_dir(file, datasync);
10162 + di_write_lock_child(dentry);
10163 + err = au_do_fsync_dir_no_file(dentry, datasync);
10165 + au_cpup_attr_timesizes(inode);
10166 + di_write_unlock(dentry);
10168 + fi_write_unlock(file);
10170 + si_read_unlock(sb);
10171 + inode_unlock(inode);
10175 +/* ---------------------------------------------------------------------- */
10177 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10180 + struct dentry *dentry;
10181 + struct inode *inode, *h_inode;
10182 + struct super_block *sb;
10184 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10186 + dentry = file->f_path.dentry;
10187 + inode = d_inode(dentry);
10188 + IMustLock(inode);
10190 + sb = dentry->d_sb;
10191 + si_read_lock(sb, AuLock_FLUSH);
10192 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10193 + if (unlikely(err))
10195 + err = au_alive_dir(dentry);
10197 + err = au_vdir_init(file);
10198 + di_downgrade_lock(dentry, AuLock_IR);
10199 + if (unlikely(err))
10202 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10203 + if (!au_test_nfsd()) {
10204 + err = au_vdir_fill_de(file, ctx);
10205 + fsstack_copy_attr_atime(inode, h_inode);
10208 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10209 + * encode_fh() and others.
10211 + atomic_inc(&h_inode->i_count);
10212 + di_read_unlock(dentry, AuLock_IR);
10213 + si_read_unlock(sb);
10214 + err = au_vdir_fill_de(file, ctx);
10215 + fsstack_copy_attr_atime(inode, h_inode);
10216 + fi_write_unlock(file);
10224 + di_read_unlock(dentry, AuLock_IR);
10225 + fi_write_unlock(file);
10227 + si_read_unlock(sb);
10231 +/* ---------------------------------------------------------------------- */
10233 +#define AuTestEmpty_WHONLY 1
10234 +#define AuTestEmpty_CALLED (1 << 1)
10235 +#define AuTestEmpty_SHWH (1 << 2)
10236 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10237 +#define au_fset_testempty(flags, name) \
10238 + do { (flags) |= AuTestEmpty_##name; } while (0)
10239 +#define au_fclr_testempty(flags, name) \
10240 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10242 +#ifndef CONFIG_AUFS_SHWH
10243 +#undef AuTestEmpty_SHWH
10244 +#define AuTestEmpty_SHWH 0
10247 +struct test_empty_arg {
10248 + struct dir_context ctx;
10249 + struct au_nhash *whlist;
10250 + unsigned int flags;
10252 + aufs_bindex_t bindex;
10255 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10256 + int namelen, loff_t offset __maybe_unused, u64 ino,
10257 + unsigned int d_type)
10259 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10261 + char *name = (void *)__name;
10264 + au_fset_testempty(arg->flags, CALLED);
10266 + if (name[0] == '.'
10267 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10268 + goto out; /* success */
10270 + if (namelen <= AUFS_WH_PFX_LEN
10271 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10272 + if (au_ftest_testempty(arg->flags, WHONLY)
10273 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10274 + arg->err = -ENOTEMPTY;
10278 + name += AUFS_WH_PFX_LEN;
10279 + namelen -= AUFS_WH_PFX_LEN;
10280 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10281 + arg->err = au_nhash_append_wh
10282 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10283 + au_ftest_testempty(arg->flags, SHWH));
10287 + AuTraceErr(arg->err);
10291 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10294 + struct file *h_file;
10296 + h_file = au_h_open(dentry, arg->bindex,
10297 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10298 + /*file*/NULL, /*force_wr*/0);
10299 + err = PTR_ERR(h_file);
10300 + if (IS_ERR(h_file))
10304 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10305 + && !file_inode(h_file)->i_nlink)
10310 + au_fclr_testempty(arg->flags, CALLED);
10312 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10315 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10319 + au_sbr_put(dentry->d_sb, arg->bindex);
10324 +struct do_test_empty_args {
10326 + struct dentry *dentry;
10327 + struct test_empty_arg *arg;
10330 +static void call_do_test_empty(void *args)
10332 + struct do_test_empty_args *a = args;
10333 + *a->errp = do_test_empty(a->dentry, a->arg);
10336 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10338 + int err, wkq_err;
10339 + struct dentry *h_dentry;
10340 + struct inode *h_inode;
10342 + h_dentry = au_h_dptr(dentry, arg->bindex);
10343 + h_inode = d_inode(h_dentry);
10344 + /* todo: i_mode changes anytime? */
10345 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10346 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10347 + inode_unlock_shared(h_inode);
10349 + err = do_test_empty(dentry, arg);
10351 + struct do_test_empty_args args = {
10353 + .dentry = dentry,
10356 + unsigned int flags = arg->flags;
10358 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10359 + if (unlikely(wkq_err))
10361 + arg->flags = flags;
10367 +int au_test_empty_lower(struct dentry *dentry)
10370 + unsigned int rdhash;
10371 + aufs_bindex_t bindex, btop, btail;
10372 + struct au_nhash whlist;
10373 + struct test_empty_arg arg = {
10375 + .actor = test_empty_cb
10378 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10380 + SiMustAnyLock(dentry->d_sb);
10382 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10384 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10385 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10386 + if (unlikely(err))
10390 + arg.whlist = &whlist;
10391 + btop = au_dbtop(dentry);
10392 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10393 + au_fset_testempty(arg.flags, SHWH);
10394 + test_empty = do_test_empty;
10395 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10396 + test_empty = sio_test_empty;
10397 + arg.bindex = btop;
10398 + err = test_empty(dentry, &arg);
10399 + if (unlikely(err))
10402 + au_fset_testempty(arg.flags, WHONLY);
10403 + btail = au_dbtaildir(dentry);
10404 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10405 + struct dentry *h_dentry;
10407 + h_dentry = au_h_dptr(dentry, bindex);
10408 + if (h_dentry && d_is_positive(h_dentry)) {
10409 + arg.bindex = bindex;
10410 + err = test_empty(dentry, &arg);
10415 + au_nhash_wh_free(&whlist);
10420 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10423 + struct test_empty_arg arg = {
10425 + .actor = test_empty_cb
10428 + aufs_bindex_t bindex, btail;
10431 + arg.whlist = whlist;
10432 + arg.flags = AuTestEmpty_WHONLY;
10433 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10434 + au_fset_testempty(arg.flags, SHWH);
10435 + btail = au_dbtaildir(dentry);
10436 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10437 + struct dentry *h_dentry;
10439 + h_dentry = au_h_dptr(dentry, bindex);
10440 + if (h_dentry && d_is_positive(h_dentry)) {
10441 + arg.bindex = bindex;
10442 + err = sio_test_empty(dentry, &arg);
10449 +/* ---------------------------------------------------------------------- */
10451 +const struct file_operations aufs_dir_fop = {
10452 + .owner = THIS_MODULE,
10453 + .llseek = default_llseek,
10454 + .read = generic_read_dir,
10455 + .iterate_shared = aufs_iterate_shared,
10456 + .unlocked_ioctl = aufs_ioctl_dir,
10457 +#ifdef CONFIG_COMPAT
10458 + .compat_ioctl = aufs_compat_ioctl_dir,
10460 + .open = aufs_open_dir,
10461 + .release = aufs_release_dir,
10462 + .flush = aufs_flush_dir,
10463 + .fsync = aufs_fsync_dir
10465 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10466 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10467 +++ linux/fs/aufs/dir.h 2017-07-29 12:14:25.899708630 +0200
10470 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10472 + * This program, aufs is free software; you can redistribute it and/or modify
10473 + * it under the terms of the GNU General Public License as published by
10474 + * the Free Software Foundation; either version 2 of the License, or
10475 + * (at your option) any later version.
10477 + * This program is distributed in the hope that it will be useful,
10478 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10480 + * GNU General Public License for more details.
10482 + * You should have received a copy of the GNU General Public License
10483 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10487 + * directory operations
10490 +#ifndef __AUFS_DIR_H__
10491 +#define __AUFS_DIR_H__
10495 +#include <linux/fs.h>
10497 +/* ---------------------------------------------------------------------- */
10499 +/* need to be faster and smaller */
10502 + unsigned int nh_num;
10503 + struct hlist_head *nh_head;
10506 +struct au_vdir_destr {
10507 + unsigned char len;
10508 + unsigned char name[0];
10511 +struct au_vdir_dehstr {
10512 + struct hlist_node hash;
10513 + struct au_vdir_destr *str;
10514 +} ____cacheline_aligned_in_smp;
10516 +struct au_vdir_de {
10518 + unsigned char de_type;
10519 + /* caution: packed */
10520 + struct au_vdir_destr de_str;
10523 +struct au_vdir_wh {
10524 + struct hlist_node wh_hash;
10525 +#ifdef CONFIG_AUFS_SHWH
10527 + aufs_bindex_t wh_bindex;
10528 + unsigned char wh_type;
10530 + aufs_bindex_t wh_bindex;
10532 + /* caution: packed */
10533 + struct au_vdir_destr wh_str;
10536 +union au_vdir_deblk_p {
10537 + unsigned char *deblk;
10538 + struct au_vdir_de *de;
10542 + unsigned char **vd_deblk;
10543 + unsigned long vd_nblk;
10545 + unsigned long ul;
10546 + union au_vdir_deblk_p p;
10549 + unsigned long vd_version;
10550 + unsigned int vd_deblk_sz;
10551 + unsigned long vd_jiffy;
10552 +} ____cacheline_aligned_in_smp;
10554 +/* ---------------------------------------------------------------------- */
10557 +extern const struct file_operations aufs_dir_fop;
10558 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10559 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10560 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10561 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10562 +int au_test_empty_lower(struct dentry *dentry);
10563 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10566 +unsigned int au_rdhash_est(loff_t sz);
10567 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10568 +void au_nhash_wh_free(struct au_nhash *whlist);
10569 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10571 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10572 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10573 + unsigned int d_type, aufs_bindex_t bindex,
10574 + unsigned char shwh);
10575 +void au_vdir_free(struct au_vdir *vdir);
10576 +int au_vdir_init(struct file *file);
10577 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10580 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10582 +#ifdef CONFIG_AUFS_RDU
10584 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10585 +#ifdef CONFIG_COMPAT
10586 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10587 + unsigned long arg);
10590 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10591 + unsigned int cmd, unsigned long arg)
10592 +#ifdef CONFIG_COMPAT
10593 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10594 + unsigned int cmd, unsigned long arg)
10598 +#endif /* __KERNEL__ */
10599 +#endif /* __AUFS_DIR_H__ */
10600 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10601 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10602 +++ linux/fs/aufs/dynop.c 2017-07-29 12:14:25.899708630 +0200
10605 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10607 + * This program, aufs is free software; you can redistribute it and/or modify
10608 + * it under the terms of the GNU General Public License as published by
10609 + * the Free Software Foundation; either version 2 of the License, or
10610 + * (at your option) any later version.
10612 + * This program is distributed in the hope that it will be useful,
10613 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10614 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10615 + * GNU General Public License for more details.
10617 + * You should have received a copy of the GNU General Public License
10618 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10622 + * dynamically customizable operations for regular files
10627 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10630 + * How large will these lists be?
10631 + * Usually just a few elements, 20-30 at most for each, I guess.
10633 +static struct au_sphlhead dynop[AuDyLast];
10635 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10637 + struct au_dykey *key, *tmp;
10638 + struct hlist_head *head;
10641 + head = &sphl->head;
10643 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10644 + if (tmp->dk_op.dy_hop == h_op) {
10646 + kref_get(&key->dk_kref);
10649 + rcu_read_unlock();
10654 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10656 + struct au_dykey **k, *found;
10657 + const void *h_op = key->dk_op.dy_hop;
10661 + k = br->br_dykey;
10662 + for (i = 0; i < AuBrDynOp; i++)
10664 + if (k[i]->dk_op.dy_hop == h_op) {
10671 + spin_lock(&br->br_dykey_lock);
10672 + for (; i < AuBrDynOp; i++)
10674 + if (k[i]->dk_op.dy_hop == h_op) {
10682 + spin_unlock(&br->br_dykey_lock);
10683 + BUG_ON(i == AuBrDynOp); /* expand the array */
10689 +/* kref_get() if @key is already added */
10690 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10692 + struct au_dykey *tmp, *found;
10693 + struct hlist_head *head;
10694 + const void *h_op = key->dk_op.dy_hop;
10697 + head = &sphl->head;
10698 + spin_lock(&sphl->spin);
10699 + hlist_for_each_entry(tmp, head, dk_hnode)
10700 + if (tmp->dk_op.dy_hop == h_op) {
10701 + kref_get(&tmp->dk_kref);
10706 + hlist_add_head_rcu(&key->dk_hnode, head);
10707 + spin_unlock(&sphl->spin);
10714 +static void dy_free_rcu(struct rcu_head *rcu)
10716 + struct au_dykey *key;
10718 + key = container_of(rcu, struct au_dykey, dk_rcu);
10723 +static void dy_free(struct kref *kref)
10725 + struct au_dykey *key;
10726 + struct au_sphlhead *sphl;
10728 + key = container_of(kref, struct au_dykey, dk_kref);
10729 + sphl = dynop + key->dk_op.dy_type;
10730 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10731 + call_rcu(&key->dk_rcu, dy_free_rcu);
10734 +void au_dy_put(struct au_dykey *key)
10736 + kref_put(&key->dk_kref, dy_free);
10739 +/* ---------------------------------------------------------------------- */
10741 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10743 +#ifdef CONFIG_AUFS_DEBUG
10744 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10745 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10747 +#define DyDbgDeclare(cnt) do {} while (0)
10748 +#define DyDbgInc(cnt) do {} while (0)
10751 +#define DySet(func, dst, src, h_op, h_sb) do { \
10753 + if (h_op->func) { \
10755 + dst.func = src.func; \
10757 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10761 +#define DySetForce(func, dst, src) do { \
10762 + AuDebugOn(!src.func); \
10764 + dst.func = src.func; \
10767 +#define DySetAop(func) \
10768 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10769 +#define DySetAopForce(func) \
10770 + DySetForce(func, dyaop->da_op, aufs_aop)
10772 +static void dy_aop(struct au_dykey *key, const void *h_op,
10773 + struct super_block *h_sb __maybe_unused)
10775 + struct au_dyaop *dyaop = (void *)key;
10776 + const struct address_space_operations *h_aop = h_op;
10777 + DyDbgDeclare(cnt);
10779 + AuDbg("%s\n", au_sbtype(h_sb));
10781 + DySetAop(writepage);
10782 + DySetAopForce(readpage); /* force */
10783 + DySetAop(writepages);
10784 + DySetAop(set_page_dirty);
10785 + DySetAop(readpages);
10786 + DySetAop(write_begin);
10787 + DySetAop(write_end);
10789 + DySetAop(invalidatepage);
10790 + DySetAop(releasepage);
10791 + DySetAop(freepage);
10792 + /* this one will be changed according to an aufs mount option */
10793 + DySetAop(direct_IO);
10794 + DySetAop(migratepage);
10795 + DySetAop(isolate_page);
10796 + DySetAop(putback_page);
10797 + DySetAop(launder_page);
10798 + DySetAop(is_partially_uptodate);
10799 + DySetAop(is_dirty_writeback);
10800 + DySetAop(error_remove_page);
10801 + DySetAop(swap_activate);
10802 + DySetAop(swap_deactivate);
10804 + DyDbgSize(cnt, *h_aop);
10807 +/* ---------------------------------------------------------------------- */
10809 +static void dy_bug(struct kref *kref)
10814 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10816 + struct au_dykey *key, *old;
10817 + struct au_sphlhead *sphl;
10820 + void (*set)(struct au_dykey *key, const void *h_op,
10821 + struct super_block *h_sb __maybe_unused);
10823 + static const struct op a[] = {
10825 + .sz = sizeof(struct au_dyaop),
10829 + const struct op *p;
10831 + sphl = dynop + op->dy_type;
10832 + key = dy_gfind_get(sphl, op->dy_hop);
10834 + goto out_add; /* success */
10836 + p = a + op->dy_type;
10837 + key = kzalloc(p->sz, GFP_NOFS);
10838 + if (unlikely(!key)) {
10839 + key = ERR_PTR(-ENOMEM);
10843 + key->dk_op.dy_hop = op->dy_hop;
10844 + kref_init(&key->dk_kref);
10845 + p->set(key, op->dy_hop, au_br_sb(br));
10846 + old = dy_gadd(sphl, key);
10853 + old = dy_bradd(br, key);
10855 + /* its ref-count should never be zero here */
10856 + kref_put(&key->dk_kref, dy_bug);
10861 +/* ---------------------------------------------------------------------- */
10863 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10864 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10865 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10866 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10867 + * See the aufs manual in detail.
10869 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10872 + dyaop->da_op.direct_IO = NULL;
10874 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10877 +static struct au_dyaop *dy_aget(struct au_branch *br,
10878 + const struct address_space_operations *h_aop,
10881 + struct au_dyaop *dyaop;
10882 + struct au_dynop op;
10884 + op.dy_type = AuDy_AOP;
10885 + op.dy_haop = h_aop;
10886 + dyaop = (void *)dy_get(&op, br);
10887 + if (IS_ERR(dyaop))
10889 + dy_adx(dyaop, do_dx);
10895 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10896 + struct inode *h_inode)
10899 + struct super_block *sb;
10900 + struct au_branch *br;
10901 + struct au_dyaop *dyaop;
10903 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10904 + IiMustWriteLock(inode);
10906 + sb = inode->i_sb;
10907 + br = au_sbr(sb, bindex);
10908 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10909 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10910 + err = PTR_ERR(dyaop);
10911 + if (IS_ERR(dyaop))
10912 + /* unnecessary to call dy_fput() */
10916 + inode->i_mapping->a_ops = &dyaop->da_op;
10923 + * Is it safe to replace a_ops during the inode/file is in operation?
10924 + * Yes, I hope so.
10926 +int au_dy_irefresh(struct inode *inode)
10929 + aufs_bindex_t btop;
10930 + struct inode *h_inode;
10933 + if (S_ISREG(inode->i_mode)) {
10934 + btop = au_ibtop(inode);
10935 + h_inode = au_h_iptr(inode, btop);
10936 + err = au_dy_iaop(inode, btop, h_inode);
10941 +void au_dy_arefresh(int do_dx)
10943 + struct au_sphlhead *sphl;
10944 + struct hlist_head *head;
10945 + struct au_dykey *key;
10947 + sphl = dynop + AuDy_AOP;
10948 + head = &sphl->head;
10949 + spin_lock(&sphl->spin);
10950 + hlist_for_each_entry(key, head, dk_hnode)
10951 + dy_adx((void *)key, do_dx);
10952 + spin_unlock(&sphl->spin);
10955 +/* ---------------------------------------------------------------------- */
10957 +void __init au_dy_init(void)
10961 + /* make sure that 'struct au_dykey *' can be any type */
10962 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10964 + for (i = 0; i < AuDyLast; i++)
10965 + au_sphl_init(dynop + i);
10968 +void au_dy_fin(void)
10972 + for (i = 0; i < AuDyLast; i++)
10973 + WARN_ON(!hlist_empty(&dynop[i].head));
10975 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10976 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10977 +++ linux/fs/aufs/dynop.h 2017-07-29 12:14:25.899708630 +0200
10980 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10982 + * This program, aufs is free software; you can redistribute it and/or modify
10983 + * it under the terms of the GNU General Public License as published by
10984 + * the Free Software Foundation; either version 2 of the License, or
10985 + * (at your option) any later version.
10987 + * This program is distributed in the hope that it will be useful,
10988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10990 + * GNU General Public License for more details.
10992 + * You should have received a copy of the GNU General Public License
10993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10997 + * dynamically customizable operations (for regular files only)
11000 +#ifndef __AUFS_DYNOP_H__
11001 +#define __AUFS_DYNOP_H__
11005 +#include <linux/fs.h>
11006 +#include <linux/kref.h>
11008 +enum {AuDy_AOP, AuDyLast};
11013 + const void *dy_hop;
11014 + const struct address_space_operations *dy_haop;
11020 + struct hlist_node dk_hnode;
11021 + struct rcu_head dk_rcu;
11023 + struct au_dynop dk_op;
11026 + * during I am in the branch local array, kref is gotten. when the
11027 + * branch is removed, kref is put.
11029 + struct kref dk_kref;
11032 +/* stop unioning since their sizes are very different from each other */
11034 + struct au_dykey da_key;
11035 + struct address_space_operations da_op; /* not const */
11038 +/* ---------------------------------------------------------------------- */
11042 +void au_dy_put(struct au_dykey *key);
11043 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
11044 + struct inode *h_inode);
11045 +int au_dy_irefresh(struct inode *inode);
11046 +void au_dy_arefresh(int do_dio);
11048 +void __init au_dy_init(void);
11049 +void au_dy_fin(void);
11051 +#endif /* __KERNEL__ */
11052 +#endif /* __AUFS_DYNOP_H__ */
11053 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
11054 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
11055 +++ linux/fs/aufs/export.c 2017-07-29 12:14:25.903042072 +0200
11058 + * Copyright (C) 2005-2017 Junjiro R. Okajima
11060 + * This program, aufs is free software; you can redistribute it and/or modify
11061 + * it under the terms of the GNU General Public License as published by
11062 + * the Free Software Foundation; either version 2 of the License, or
11063 + * (at your option) any later version.
11065 + * This program is distributed in the hope that it will be useful,
11066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11068 + * GNU General Public License for more details.
11070 + * You should have received a copy of the GNU General Public License
11071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11078 +#include <linux/exportfs.h>
11079 +#include <linux/fs_struct.h>
11080 +#include <linux/namei.h>
11081 +#include <linux/nsproxy.h>
11082 +#include <linux/random.h>
11083 +#include <linux/writeback.h>
11087 +#ifdef CONFIG_AUFS_INO_T_64
11095 +static ino_t decode_ino(__u32 *a)
11099 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11101 +#ifdef CONFIG_AUFS_INO_T_64
11107 +static void encode_ino(__u32 *a, ino_t ino)
11113 +#ifdef CONFIG_AUFS_INO_T_64
11118 +/* NFS file handle */
11122 +#ifdef CONFIG_AUFS_INO_T_64
11123 + /* support 64bit inode number */
11136 + Fh_ino = Fh_ino1,
11137 + Fh_dir_ino = Fh_dir_ino1
11140 +static int au_test_anon(struct dentry *dentry)
11142 + /* note: read d_flags without d_lock */
11143 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11146 +int au_test_nfsd(void)
11149 + struct task_struct *tsk = current;
11150 + char comm[sizeof(tsk->comm)];
11153 + if (tsk->flags & PF_KTHREAD) {
11154 + get_task_comm(comm, tsk);
11155 + ret = !strcmp(comm, "nfsd");
11161 +/* ---------------------------------------------------------------------- */
11162 +/* inode generation external table */
11164 +void au_xigen_inc(struct inode *inode)
11169 + struct super_block *sb;
11170 + struct au_sbinfo *sbinfo;
11172 + sb = inode->i_sb;
11173 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11175 + sbinfo = au_sbi(sb);
11176 + pos = inode->i_ino;
11177 + pos *= sizeof(igen);
11178 + igen = inode->i_generation + 1;
11179 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11180 + sizeof(igen), &pos);
11181 + if (sz == sizeof(igen))
11182 + return; /* success */
11184 + if (unlikely(sz >= 0))
11185 + AuIOErr("xigen error (%zd)\n", sz);
11188 +int au_xigen_new(struct inode *inode)
11193 + struct super_block *sb;
11194 + struct au_sbinfo *sbinfo;
11195 + struct file *file;
11198 + /* todo: dirty, at mount time */
11199 + if (inode->i_ino == AUFS_ROOT_INO)
11201 + sb = inode->i_sb;
11202 + SiMustAnyLock(sb);
11203 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11207 + pos = inode->i_ino;
11208 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11209 + AuIOErr1("too large i%lld\n", pos);
11212 + pos *= sizeof(inode->i_generation);
11215 + sbinfo = au_sbi(sb);
11216 + file = sbinfo->si_xigen;
11219 + if (vfsub_f_size_read(file)
11220 + < pos + sizeof(inode->i_generation)) {
11221 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11222 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11223 + sizeof(inode->i_generation), &pos);
11225 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11226 + sizeof(inode->i_generation), &pos);
11227 + if (sz == sizeof(inode->i_generation))
11228 + goto out; /* success */
11231 + if (unlikely(sz >= 0)) {
11233 + AuIOErr("xigen error (%zd)\n", sz);
11240 +int au_xigen_set(struct super_block *sb, struct file *base)
11243 + struct au_sbinfo *sbinfo;
11244 + struct file *file;
11246 + SiMustWriteLock(sb);
11248 + sbinfo = au_sbi(sb);
11249 + file = au_xino_create2(base, sbinfo->si_xigen);
11250 + err = PTR_ERR(file);
11251 + if (IS_ERR(file))
11254 + if (sbinfo->si_xigen)
11255 + fput(sbinfo->si_xigen);
11256 + sbinfo->si_xigen = file;
11262 +void au_xigen_clr(struct super_block *sb)
11264 + struct au_sbinfo *sbinfo;
11266 + SiMustWriteLock(sb);
11268 + sbinfo = au_sbi(sb);
11269 + if (sbinfo->si_xigen) {
11270 + fput(sbinfo->si_xigen);
11271 + sbinfo->si_xigen = NULL;
11275 +/* ---------------------------------------------------------------------- */
11277 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11280 + struct dentry *dentry, *d;
11281 + struct inode *inode;
11282 + unsigned int sigen;
11285 + inode = ilookup(sb, ino);
11289 + dentry = ERR_PTR(-ESTALE);
11290 + sigen = au_sigen(sb);
11291 + if (unlikely(au_is_bad_inode(inode)
11292 + || IS_DEADDIR(inode)
11293 + || sigen != au_iigen(inode, NULL)))
11297 + if (!dir_ino || S_ISDIR(inode->i_mode))
11298 + dentry = d_find_alias(inode);
11300 + spin_lock(&inode->i_lock);
11301 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11302 + spin_lock(&d->d_lock);
11303 + if (!au_test_anon(d)
11304 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11305 + dentry = dget_dlock(d);
11306 + spin_unlock(&d->d_lock);
11309 + spin_unlock(&d->d_lock);
11311 + spin_unlock(&inode->i_lock);
11313 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11314 + /* need to refresh */
11322 + AuTraceErrPtr(dentry);
11326 +/* ---------------------------------------------------------------------- */
11328 +/* todo: dirty? */
11329 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11331 +struct au_compare_mnt_args {
11333 + struct super_block *sb;
11336 + struct vfsmount *mnt;
11339 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11341 + struct au_compare_mnt_args *a = arg;
11343 + if (mnt->mnt_sb != a->sb)
11345 + a->mnt = mntget(mnt);
11349 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11352 + struct path root;
11353 + struct au_compare_mnt_args args = {
11357 + get_fs_root(current->fs, &root);
11359 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11360 + rcu_read_unlock();
11363 + AuDebugOn(!args.mnt);
11367 +struct au_nfsd_si_lock {
11368 + unsigned int sigen;
11369 + aufs_bindex_t bindex, br_id;
11370 + unsigned char force_lock;
11373 +static int si_nfsd_read_lock(struct super_block *sb,
11374 + struct au_nfsd_si_lock *nsi_lock)
11377 + aufs_bindex_t bindex;
11379 + si_read_lock(sb, AuLock_FLUSH);
11381 + /* branch id may be wrapped around */
11383 + bindex = au_br_index(sb, nsi_lock->br_id);
11384 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11385 + goto out; /* success */
11389 + if (!nsi_lock->force_lock)
11390 + si_read_unlock(sb);
11393 + nsi_lock->bindex = bindex;
11397 +struct find_name_by_ino {
11398 + struct dir_context ctx;
11399 + int called, found;
11406 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11407 + loff_t offset, u64 ino, unsigned int d_type)
11409 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11413 + if (a->ino != ino)
11416 + memcpy(a->name, name, namelen);
11417 + a->namelen = namelen;
11422 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11423 + struct au_nfsd_si_lock *nsi_lock)
11425 + struct dentry *dentry, *parent;
11426 + struct file *file;
11427 + struct inode *dir;
11428 + struct find_name_by_ino arg = {
11430 + .actor = find_name_by_ino
11435 + parent = path->dentry;
11437 + si_read_unlock(parent->d_sb);
11438 + file = vfsub_dentry_open(path, au_dir_roflags);
11439 + dentry = (void *)file;
11440 + if (IS_ERR(file))
11443 + dentry = ERR_PTR(-ENOMEM);
11444 + arg.name = (void *)__get_free_page(GFP_NOFS);
11445 + if (unlikely(!arg.name))
11452 + err = vfsub_iterate_dir(file, &arg.ctx);
11453 + } while (!err && !arg.found && arg.called);
11454 + dentry = ERR_PTR(err);
11455 + if (unlikely(err))
11457 + /* instead of ENOENT */
11458 + dentry = ERR_PTR(-ESTALE);
11462 + /* do not call vfsub_lkup_one() */
11463 + dir = d_inode(parent);
11464 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11465 + AuTraceErrPtr(dentry);
11466 + if (IS_ERR(dentry))
11468 + AuDebugOn(au_test_anon(dentry));
11469 + if (unlikely(d_really_is_negative(dentry))) {
11471 + dentry = ERR_PTR(-ENOENT);
11475 + free_page((unsigned long)arg.name);
11479 + if (unlikely(nsi_lock
11480 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11481 + if (!IS_ERR(dentry)) {
11483 + dentry = ERR_PTR(-ESTALE);
11485 + AuTraceErrPtr(dentry);
11489 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11491 + struct au_nfsd_si_lock *nsi_lock)
11493 + struct dentry *dentry;
11494 + struct path path;
11496 + if (dir_ino != AUFS_ROOT_INO) {
11497 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11498 + dentry = path.dentry;
11499 + if (!path.dentry || IS_ERR(path.dentry))
11501 + AuDebugOn(au_test_anon(path.dentry));
11503 + path.dentry = dget(sb->s_root);
11505 + path.mnt = au_mnt_get(sb);
11506 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11510 + AuTraceErrPtr(dentry);
11514 +/* ---------------------------------------------------------------------- */
11516 +static int h_acceptable(void *expv, struct dentry *dentry)
11521 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11522 + char *buf, int len, struct super_block *sb)
11526 + struct path path;
11528 + p = d_path(h_rootpath, buf, len);
11533 + path.mnt = h_rootpath->mnt;
11534 + path.dentry = h_parent;
11535 + p = d_path(&path, buf, len);
11541 + path.mnt = au_mnt_get(sb);
11542 + path.dentry = sb->s_root;
11543 + p = d_path(&path, buf, len - strlen(p));
11544 + mntput(path.mnt);
11548 + p[strlen(p)] = '/';
11551 + AuTraceErrPtr(p);
11556 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11557 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11559 + struct dentry *dentry, *h_parent, *root;
11560 + struct super_block *h_sb;
11561 + char *pathname, *p;
11562 + struct vfsmount *h_mnt;
11563 + struct au_branch *br;
11565 + struct path path;
11567 + br = au_sbr(sb, nsi_lock->bindex);
11568 + h_mnt = au_br_mnt(br);
11569 + h_sb = h_mnt->mnt_sb;
11570 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11572 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11573 + fh_len - Fh_tail, fh[Fh_h_type],
11574 + h_acceptable, /*context*/NULL);
11576 + dentry = h_parent;
11577 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11578 + AuWarn1("%s decode_fh failed, %ld\n",
11579 + au_sbtype(h_sb), PTR_ERR(h_parent));
11583 + if (unlikely(au_test_anon(h_parent))) {
11584 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11585 + au_sbtype(h_sb));
11586 + goto out_h_parent;
11589 + dentry = ERR_PTR(-ENOMEM);
11590 + pathname = (void *)__get_free_page(GFP_NOFS);
11591 + if (unlikely(!pathname))
11592 + goto out_h_parent;
11594 + root = sb->s_root;
11595 + path.mnt = h_mnt;
11596 + di_read_lock_parent(root, !AuLock_IR);
11597 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11598 + di_read_unlock(root, !AuLock_IR);
11599 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11600 + dentry = (void *)p;
11602 + goto out_pathname;
11604 + si_read_unlock(sb);
11605 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11606 + dentry = ERR_PTR(err);
11607 + if (unlikely(err))
11610 + dentry = ERR_PTR(-ENOENT);
11611 + AuDebugOn(au_test_anon(path.dentry));
11612 + if (unlikely(d_really_is_negative(path.dentry)))
11615 + if (ino != d_inode(path.dentry)->i_ino)
11616 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11618 + dentry = dget(path.dentry);
11623 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11624 + if (!IS_ERR(dentry)) {
11626 + dentry = ERR_PTR(-ESTALE);
11629 + free_page((unsigned long)pathname);
11633 + AuTraceErrPtr(dentry);
11637 +/* ---------------------------------------------------------------------- */
11639 +static struct dentry *
11640 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11643 + struct dentry *dentry;
11644 + __u32 *fh = fid->raw;
11645 + struct au_branch *br;
11646 + ino_t ino, dir_ino;
11647 + struct au_nfsd_si_lock nsi_lock = {
11651 + dentry = ERR_PTR(-ESTALE);
11652 + /* it should never happen, but the file handle is unreliable */
11653 + if (unlikely(fh_len < Fh_tail))
11655 + nsi_lock.sigen = fh[Fh_sigen];
11656 + nsi_lock.br_id = fh[Fh_br_id];
11658 + /* branch id may be wrapped around */
11660 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11662 + nsi_lock.force_lock = 1;
11664 + /* is this inode still cached? */
11665 + ino = decode_ino(fh + Fh_ino);
11666 + /* it should never happen */
11667 + if (unlikely(ino == AUFS_ROOT_INO))
11670 + dir_ino = decode_ino(fh + Fh_dir_ino);
11671 + dentry = decode_by_ino(sb, ino, dir_ino);
11672 + if (IS_ERR(dentry))
11677 + /* is the parent dir cached? */
11678 + br = au_sbr(sb, nsi_lock.bindex);
11680 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11681 + if (IS_ERR(dentry))
11686 + /* lookup path */
11687 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11688 + if (IS_ERR(dentry))
11690 + if (unlikely(!dentry))
11691 + /* todo?: make it ESTALE */
11695 + if (!au_digen_test(dentry, au_sigen(sb))
11696 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11697 + goto out_unlock; /* success */
11700 + dentry = ERR_PTR(-ESTALE);
11704 + si_read_unlock(sb);
11706 + AuTraceErrPtr(dentry);
11710 +#if 0 /* reserved for future use */
11711 +/* support subtreecheck option */
11712 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11713 + int fh_len, int fh_type)
11715 + struct dentry *parent;
11716 + __u32 *fh = fid->raw;
11719 + dir_ino = decode_ino(fh + Fh_dir_ino);
11720 + parent = decode_by_ino(sb, dir_ino, 0);
11721 + if (IS_ERR(parent))
11724 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11725 + dir_ino, fh, fh_len);
11728 + AuTraceErrPtr(parent);
11733 +/* ---------------------------------------------------------------------- */
11735 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11736 + struct inode *dir)
11739 + aufs_bindex_t bindex;
11740 + struct super_block *sb, *h_sb;
11741 + struct dentry *dentry, *parent, *h_parent;
11742 + struct inode *h_dir;
11743 + struct au_branch *br;
11746 + if (unlikely(*max_len <= Fh_tail)) {
11747 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11751 + err = FILEID_ROOT;
11752 + if (inode->i_ino == AUFS_ROOT_INO) {
11753 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11758 + sb = inode->i_sb;
11759 + err = si_read_lock(sb, AuLock_FLUSH);
11760 + if (unlikely(err))
11763 +#ifdef CONFIG_AUFS_DEBUG
11764 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11765 + AuWarn1("NFS-exporting requires xino\n");
11769 + ii_read_lock_child(inode);
11770 + bindex = au_ibtop(inode);
11772 + dentry = d_find_any_alias(inode);
11773 + if (unlikely(!dentry))
11775 + AuDebugOn(au_test_anon(dentry));
11776 + parent = dget_parent(dentry);
11778 + if (unlikely(!parent))
11780 + if (d_really_is_positive(parent))
11781 + dir = d_inode(parent);
11784 + ii_read_lock_parent(dir);
11785 + h_dir = au_h_iptr(dir, bindex);
11786 + ii_read_unlock(dir);
11787 + if (unlikely(!h_dir))
11789 + h_parent = d_find_any_alias(h_dir);
11790 + if (unlikely(!h_parent))
11791 + goto out_hparent;
11794 + br = au_sbr(sb, bindex);
11795 + h_sb = au_br_sb(br);
11796 + if (unlikely(!h_sb->s_export_op)) {
11797 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11798 + goto out_hparent;
11801 + fh[Fh_br_id] = br->br_id;
11802 + fh[Fh_sigen] = au_sigen(sb);
11803 + encode_ino(fh + Fh_ino, inode->i_ino);
11804 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11805 + fh[Fh_igen] = inode->i_generation;
11807 + *max_len -= Fh_tail;
11808 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11810 + /*connectable or subtreecheck*/0);
11811 + err = fh[Fh_h_type];
11812 + *max_len += Fh_tail;
11813 + /* todo: macros? */
11814 + if (err != FILEID_INVALID)
11817 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11824 + ii_read_unlock(inode);
11825 + si_read_unlock(sb);
11827 + if (unlikely(err < 0))
11828 + err = FILEID_INVALID;
11832 +/* ---------------------------------------------------------------------- */
11834 +static int aufs_commit_metadata(struct inode *inode)
11837 + aufs_bindex_t bindex;
11838 + struct super_block *sb;
11839 + struct inode *h_inode;
11840 + int (*f)(struct inode *inode);
11842 + sb = inode->i_sb;
11843 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11844 + ii_write_lock_child(inode);
11845 + bindex = au_ibtop(inode);
11846 + AuDebugOn(bindex < 0);
11847 + h_inode = au_h_iptr(inode, bindex);
11849 + f = h_inode->i_sb->s_export_op->commit_metadata;
11851 + err = f(h_inode);
11853 + struct writeback_control wbc = {
11854 + .sync_mode = WB_SYNC_ALL,
11855 + .nr_to_write = 0 /* metadata only */
11858 + err = sync_inode(h_inode, &wbc);
11861 + au_cpup_attr_timesizes(inode);
11862 + ii_write_unlock(inode);
11863 + si_read_unlock(sb);
11867 +/* ---------------------------------------------------------------------- */
11869 +static struct export_operations aufs_export_op = {
11870 + .fh_to_dentry = aufs_fh_to_dentry,
11871 + /* .fh_to_parent = aufs_fh_to_parent, */
11872 + .encode_fh = aufs_encode_fh,
11873 + .commit_metadata = aufs_commit_metadata
11876 +void au_export_init(struct super_block *sb)
11878 + struct au_sbinfo *sbinfo;
11881 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11882 + && IS_MODULE(CONFIG_EXPORTFS),
11883 + AUFS_NAME ": unsupported configuration "
11884 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11886 + sb->s_export_op = &aufs_export_op;
11887 + sbinfo = au_sbi(sb);
11888 + sbinfo->si_xigen = NULL;
11889 + get_random_bytes(&u, sizeof(u));
11890 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11891 + atomic_set(&sbinfo->si_xigen_next, u);
11893 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11894 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11895 +++ linux/fs/aufs/fhsm.c 2017-07-29 12:14:25.903042072 +0200
11898 + * Copyright (C) 2011-2017 Junjiro R. Okajima
11900 + * This program, aufs is free software; you can redistribute it and/or modify
11901 + * it under the terms of the GNU General Public License as published by
11902 + * the Free Software Foundation; either version 2 of the License, or
11903 + * (at your option) any later version.
11905 + * This program is distributed in the hope that it will be useful,
11906 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11907 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11908 + * GNU General Public License for more details.
11910 + * You should have received a copy of the GNU General Public License
11911 + * along with this program; if not, write to the Free Software
11912 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11916 + * File-based Hierarchy Storage Management
11919 +#include <linux/anon_inodes.h>
11920 +#include <linux/poll.h>
11921 +#include <linux/seq_file.h>
11922 +#include <linux/statfs.h>
11925 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11927 + struct au_sbinfo *sbinfo;
11928 + struct au_fhsm *fhsm;
11930 + SiMustAnyLock(sb);
11932 + sbinfo = au_sbi(sb);
11933 + fhsm = &sbinfo->si_fhsm;
11934 + AuDebugOn(!fhsm);
11935 + return fhsm->fhsm_bottom;
11938 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11940 + struct au_sbinfo *sbinfo;
11941 + struct au_fhsm *fhsm;
11943 + SiMustWriteLock(sb);
11945 + sbinfo = au_sbi(sb);
11946 + fhsm = &sbinfo->si_fhsm;
11947 + AuDebugOn(!fhsm);
11948 + fhsm->fhsm_bottom = bindex;
11951 +/* ---------------------------------------------------------------------- */
11953 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11955 + struct au_br_fhsm *bf;
11957 + bf = br->br_fhsm;
11958 + MtxMustLock(&bf->bf_lock);
11960 + return !bf->bf_readable
11961 + || time_after(jiffies,
11962 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11965 +/* ---------------------------------------------------------------------- */
11967 +static void au_fhsm_notify(struct super_block *sb, int val)
11969 + struct au_sbinfo *sbinfo;
11970 + struct au_fhsm *fhsm;
11972 + SiMustAnyLock(sb);
11974 + sbinfo = au_sbi(sb);
11975 + fhsm = &sbinfo->si_fhsm;
11976 + if (au_fhsm_pid(fhsm)
11977 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11978 + atomic_set(&fhsm->fhsm_readable, val);
11980 + wake_up(&fhsm->fhsm_wqh);
11984 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11985 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11988 + struct au_branch *br;
11989 + struct au_br_fhsm *bf;
11991 + br = au_sbr(sb, bindex);
11992 + AuDebugOn(au_br_rdonly(br));
11993 + bf = br->br_fhsm;
11997 + mutex_lock(&bf->bf_lock);
11999 + MtxMustLock(&bf->bf_lock);
12001 + /* sb->s_root for NFS is unreliable */
12002 + err = au_br_stfs(br, &bf->bf_stfs);
12003 + if (unlikely(err)) {
12004 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
12008 + bf->bf_jiffy = jiffies;
12009 + bf->bf_readable = 1;
12011 + au_fhsm_notify(sb, /*val*/1);
12013 + *rstfs = bf->bf_stfs;
12017 + mutex_unlock(&bf->bf_lock);
12018 + au_fhsm_notify(sb, /*val*/1);
12023 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
12026 + struct au_sbinfo *sbinfo;
12027 + struct au_fhsm *fhsm;
12028 + struct au_branch *br;
12029 + struct au_br_fhsm *bf;
12031 + AuDbg("b%d, force %d\n", bindex, force);
12032 + SiMustAnyLock(sb);
12034 + sbinfo = au_sbi(sb);
12035 + fhsm = &sbinfo->si_fhsm;
12036 + if (!au_ftest_si(sbinfo, FHSM)
12037 + || fhsm->fhsm_bottom == bindex)
12040 + br = au_sbr(sb, bindex);
12041 + bf = br->br_fhsm;
12043 + mutex_lock(&bf->bf_lock);
12045 + || au_fhsm_pid(fhsm)
12046 + || au_fhsm_test_jiffy(sbinfo, br))
12047 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
12049 + mutex_unlock(&bf->bf_lock);
12052 +void au_fhsm_wrote_all(struct super_block *sb, int force)
12054 + aufs_bindex_t bindex, bbot;
12055 + struct au_branch *br;
12057 + /* exclude the bottom */
12058 + bbot = au_fhsm_bottom(sb);
12059 + for (bindex = 0; bindex < bbot; bindex++) {
12060 + br = au_sbr(sb, bindex);
12061 + if (au_br_fhsm(br->br_perm))
12062 + au_fhsm_wrote(sb, bindex, force);
12066 +/* ---------------------------------------------------------------------- */
12068 +static unsigned int au_fhsm_poll(struct file *file,
12069 + struct poll_table_struct *wait)
12071 + unsigned int mask;
12072 + struct au_sbinfo *sbinfo;
12073 + struct au_fhsm *fhsm;
12076 + sbinfo = file->private_data;
12077 + fhsm = &sbinfo->si_fhsm;
12078 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12079 + if (atomic_read(&fhsm->fhsm_readable))
12080 + mask = POLLIN /* | POLLRDNORM */;
12082 + AuTraceErr((int)mask);
12086 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12087 + struct aufs_stfs *stfs, __s16 brid)
12091 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12093 + err = __put_user(brid, &stbr->brid);
12094 + if (unlikely(err))
12100 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12101 + struct aufs_stbr __user *stbr, size_t count)
12105 + aufs_bindex_t bindex, bbot;
12106 + struct au_branch *br;
12107 + struct au_br_fhsm *bf;
12109 + /* except the bottom branch */
12112 + bbot = au_fhsm_bottom(sb);
12113 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12114 + br = au_sbr(sb, bindex);
12115 + if (!au_br_fhsm(br->br_perm))
12118 + bf = br->br_fhsm;
12119 + mutex_lock(&bf->bf_lock);
12120 + if (bf->bf_readable) {
12122 + if (count >= sizeof(*stbr))
12123 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12126 + bf->bf_readable = 0;
12127 + count -= sizeof(*stbr);
12131 + mutex_unlock(&bf->bf_lock);
12134 + err = sizeof(*stbr) * nstbr;
12139 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12144 + aufs_bindex_t nfhsm, bindex, bbot;
12145 + struct au_sbinfo *sbinfo;
12146 + struct au_fhsm *fhsm;
12147 + struct au_branch *br;
12148 + struct super_block *sb;
12151 + sbinfo = file->private_data;
12152 + fhsm = &sbinfo->si_fhsm;
12154 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12155 + if (!atomic_read(&fhsm->fhsm_readable)) {
12156 + if (vfsub_file_flags(file) & O_NONBLOCK)
12159 + err = wait_event_interruptible_locked_irq
12161 + atomic_read(&fhsm->fhsm_readable));
12163 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12164 + if (unlikely(err))
12167 + /* sb may already be dead */
12168 + au_rw_read_lock(&sbinfo->si_rwsem);
12169 + readable = atomic_read(&fhsm->fhsm_readable);
12170 + if (readable > 0) {
12171 + sb = sbinfo->si_sb;
12173 + /* exclude the bottom branch */
12175 + bbot = au_fhsm_bottom(sb);
12176 + for (bindex = 0; bindex < bbot; bindex++) {
12177 + br = au_sbr(sb, bindex);
12178 + if (au_br_fhsm(br->br_perm))
12182 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12183 + atomic_set(&fhsm->fhsm_readable, 0);
12184 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12188 + au_rw_read_unlock(&sbinfo->si_rwsem);
12196 +static int au_fhsm_release(struct inode *inode, struct file *file)
12198 + struct au_sbinfo *sbinfo;
12199 + struct au_fhsm *fhsm;
12201 + /* sb may already be dead */
12202 + sbinfo = file->private_data;
12203 + fhsm = &sbinfo->si_fhsm;
12204 + spin_lock(&fhsm->fhsm_spin);
12205 + fhsm->fhsm_pid = 0;
12206 + spin_unlock(&fhsm->fhsm_spin);
12207 + kobject_put(&sbinfo->si_kobj);
12212 +static const struct file_operations au_fhsm_fops = {
12213 + .owner = THIS_MODULE,
12214 + .llseek = noop_llseek,
12215 + .read = au_fhsm_read,
12216 + .poll = au_fhsm_poll,
12217 + .release = au_fhsm_release
12220 +int au_fhsm_fd(struct super_block *sb, int oflags)
12223 + struct au_sbinfo *sbinfo;
12224 + struct au_fhsm *fhsm;
12227 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12231 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12235 + sbinfo = au_sbi(sb);
12236 + fhsm = &sbinfo->si_fhsm;
12237 + spin_lock(&fhsm->fhsm_spin);
12238 + if (!fhsm->fhsm_pid)
12239 + fhsm->fhsm_pid = current->pid;
12242 + spin_unlock(&fhsm->fhsm_spin);
12243 + if (unlikely(err))
12246 + oflags |= O_RDONLY;
12247 + /* oflags |= FMODE_NONOTIFY; */
12248 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12250 + if (unlikely(fd < 0))
12253 + /* succeed reglardless 'fhsm' status */
12254 + kobject_get(&sbinfo->si_kobj);
12255 + si_noflush_read_lock(sb);
12256 + if (au_ftest_si(sbinfo, FHSM))
12257 + au_fhsm_wrote_all(sb, /*force*/0);
12258 + si_read_unlock(sb);
12259 + goto out; /* success */
12262 + spin_lock(&fhsm->fhsm_spin);
12263 + fhsm->fhsm_pid = 0;
12264 + spin_unlock(&fhsm->fhsm_spin);
12270 +/* ---------------------------------------------------------------------- */
12272 +int au_fhsm_br_alloc(struct au_branch *br)
12277 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12279 + au_br_fhsm_init(br->br_fhsm);
12286 +/* ---------------------------------------------------------------------- */
12288 +void au_fhsm_fin(struct super_block *sb)
12290 + au_fhsm_notify(sb, /*val*/-1);
12293 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12295 + struct au_fhsm *fhsm;
12297 + fhsm = &sbinfo->si_fhsm;
12298 + spin_lock_init(&fhsm->fhsm_spin);
12299 + init_waitqueue_head(&fhsm->fhsm_wqh);
12300 + atomic_set(&fhsm->fhsm_readable, 0);
12301 + fhsm->fhsm_expire
12302 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12303 + fhsm->fhsm_bottom = -1;
12306 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12308 + sbinfo->si_fhsm.fhsm_expire
12309 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12312 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12316 + if (!au_ftest_si(sbinfo, FHSM))
12319 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12320 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12321 + seq_printf(seq, ",fhsm_sec=%u", u);
12323 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12324 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12325 +++ linux/fs/aufs/file.c 2017-07-29 12:14:25.903042072 +0200
12328 + * Copyright (C) 2005-2017 Junjiro R. Okajima
12330 + * This program, aufs is free software; you can redistribute it and/or modify
12331 + * it under the terms of the GNU General Public License as published by
12332 + * the Free Software Foundation; either version 2 of the License, or
12333 + * (at your option) any later version.
12335 + * This program is distributed in the hope that it will be useful,
12336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12338 + * GNU General Public License for more details.
12340 + * You should have received a copy of the GNU General Public License
12341 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12345 + * handling file/dir, and address_space operation
12348 +#ifdef CONFIG_AUFS_DEBUG
12349 +#include <linux/migrate.h>
12351 +#include <linux/pagemap.h>
12354 +/* drop flags for writing */
12355 +unsigned int au_file_roflags(unsigned int flags)
12357 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12358 + flags |= O_RDONLY | O_NOATIME;
12362 +/* common functions to regular file and dir */
12363 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12364 + struct file *file, int force_wr)
12366 + struct file *h_file;
12367 + struct dentry *h_dentry;
12368 + struct inode *h_inode;
12369 + struct super_block *sb;
12370 + struct au_branch *br;
12371 + struct path h_path;
12374 + /* a race condition can happen between open and unlink/rmdir */
12375 + h_file = ERR_PTR(-ENOENT);
12376 + h_dentry = au_h_dptr(dentry, bindex);
12377 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12379 + h_inode = d_inode(h_dentry);
12380 + spin_lock(&h_dentry->d_lock);
12381 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12382 + /* || !d_inode(dentry)->i_nlink */
12384 + spin_unlock(&h_dentry->d_lock);
12385 + if (unlikely(err))
12388 + sb = dentry->d_sb;
12389 + br = au_sbr(sb, bindex);
12390 + err = au_br_test_oflag(flags, br);
12391 + h_file = ERR_PTR(err);
12392 + if (unlikely(err))
12395 + /* drop flags for writing */
12396 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12397 + if (force_wr && !(flags & O_WRONLY))
12399 + flags = au_file_roflags(flags);
12401 + h_file = ERR_PTR(-EROFS);
12402 + flags = au_file_roflags(flags);
12403 + if (unlikely(vfsub_native_ro(h_inode)
12404 + || IS_APPEND(h_inode)))
12406 + flags &= ~O_ACCMODE;
12407 + flags |= O_WRONLY;
12410 + flags &= ~O_CREAT;
12412 + h_path.dentry = h_dentry;
12413 + h_path.mnt = au_br_mnt(br);
12414 + h_file = vfsub_dentry_open(&h_path, flags);
12415 + if (IS_ERR(h_file))
12418 + if (flags & __FMODE_EXEC) {
12419 + err = deny_write_access(h_file);
12420 + if (unlikely(err)) {
12422 + h_file = ERR_PTR(err);
12426 + fsnotify_open(h_file);
12427 + goto out; /* success */
12435 +static int au_cmoo(struct dentry *dentry)
12438 + unsigned int udba;
12439 + struct path h_path;
12440 + struct au_pin pin;
12441 + struct au_cp_generic cpg = {
12442 + .dentry = dentry,
12447 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12449 + struct inode *delegated;
12450 + struct super_block *sb;
12451 + struct au_sbinfo *sbinfo;
12452 + struct au_fhsm *fhsm;
12454 + struct au_branch *br;
12455 + struct dentry *parent;
12456 + struct au_hinode *hdir;
12458 + DiMustWriteLock(dentry);
12459 + IiMustWriteLock(d_inode(dentry));
12462 + if (IS_ROOT(dentry))
12464 + cpg.bsrc = au_dbtop(dentry);
12468 + sb = dentry->d_sb;
12469 + sbinfo = au_sbi(sb);
12470 + fhsm = &sbinfo->si_fhsm;
12471 + pid = au_fhsm_pid(fhsm);
12473 + && (current->pid == pid
12474 + || current->real_parent->pid == pid))
12477 + br = au_sbr(sb, cpg.bsrc);
12478 + cmoo = au_br_cmoo(br->br_perm);
12481 + if (!d_is_reg(dentry))
12482 + cmoo &= AuBrAttr_COO_ALL;
12486 + parent = dget_parent(dentry);
12487 + di_write_lock_parent(parent);
12488 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12490 + if (unlikely(err < 0)) {
12491 + err = 0; /* there is no upper writable branch */
12494 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12496 + /* do not respect the coo attrib for the target branch */
12497 + err = au_cpup_dirs(dentry, cpg.bdst);
12498 + if (unlikely(err))
12501 + di_downgrade_lock(parent, AuLock_IR);
12502 + udba = au_opt_udba(sb);
12503 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12504 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12505 + if (unlikely(err))
12508 + err = au_sio_cpup_simple(&cpg);
12510 + if (unlikely(err))
12512 + if (!(cmoo & AuBrWAttr_MOO))
12513 + goto out_parent; /* success */
12515 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12516 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12517 + if (unlikely(err))
12520 + h_path.mnt = au_br_mnt(br);
12521 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12522 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12523 + delegated = NULL;
12524 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12526 + /* todo: keep h_dentry or not? */
12527 + if (unlikely(err == -EWOULDBLOCK)) {
12528 + pr_warn("cannot retry for NFSv4 delegation"
12529 + " for an internal unlink\n");
12532 + if (unlikely(err)) {
12533 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12537 + goto out_parent; /* success */
12540 + di_downgrade_lock(parent, AuLock_IR);
12542 + di_read_unlock(parent, AuLock_IR);
12549 +int au_do_open(struct file *file, struct au_do_open_args *args)
12551 + int err, no_lock = args->no_lock;
12552 + struct dentry *dentry;
12553 + struct au_finfo *finfo;
12556 + err = au_finfo_init(file, args->fidir);
12559 + err = au_finfo_init(file, args->fidir);
12562 + if (unlikely(err))
12565 + dentry = file->f_path.dentry;
12566 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12568 + di_write_lock_child(dentry);
12569 + err = au_cmoo(dentry);
12570 + di_downgrade_lock(dentry, AuLock_IR);
12572 + err = args->open(file, vfsub_file_flags(file), NULL);
12573 + di_read_unlock(dentry, AuLock_IR);
12575 + err = au_cmoo(dentry);
12577 + err = args->open(file, vfsub_file_flags(file),
12579 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12581 + * cmoo happens after h_file was opened.
12582 + * need to refresh file later.
12584 + atomic_dec(&au_fi(file)->fi_generation);
12587 + finfo = au_fi(file);
12589 + finfo->fi_file = file;
12590 + au_sphl_add(&finfo->fi_hlist,
12591 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12594 + fi_write_unlock(file);
12597 + fi_write_unlock(file);
12600 + if (unlikely(err)) {
12601 + finfo->fi_hdir = NULL;
12602 + au_finfo_fin(file);
12609 +int au_reopen_nondir(struct file *file)
12612 + aufs_bindex_t btop;
12613 + struct dentry *dentry;
12614 + struct file *h_file, *h_file_tmp;
12616 + dentry = file->f_path.dentry;
12617 + btop = au_dbtop(dentry);
12618 + h_file_tmp = NULL;
12619 + if (au_fbtop(file) == btop) {
12620 + h_file = au_hf_top(file);
12621 + if (file->f_mode == h_file->f_mode)
12622 + return 0; /* success */
12623 + h_file_tmp = h_file;
12624 + get_file(h_file_tmp);
12625 + au_set_h_fptr(file, btop, NULL);
12627 + AuDebugOn(au_fi(file)->fi_hdir);
12630 + * file exists on both of rw and ro
12631 + * open --> dbtop and fbtop are both 0
12632 + * prepend a branch as rw, "rw" become ro
12634 + * delete the top branch, "rw" becomes rw again
12635 + * --> dbtop is 1, fbtop is still 0
12636 + * write --> fbtop is 0 but dbtop is 1
12638 + /* AuDebugOn(au_fbtop(file) < btop); */
12640 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12641 + file, /*force_wr*/0);
12642 + err = PTR_ERR(h_file);
12643 + if (IS_ERR(h_file)) {
12644 + if (h_file_tmp) {
12645 + au_sbr_get(dentry->d_sb, btop);
12646 + au_set_h_fptr(file, btop, h_file_tmp);
12647 + h_file_tmp = NULL;
12649 + goto out; /* todo: close all? */
12653 + au_set_fbtop(file, btop);
12654 + au_set_h_fptr(file, btop, h_file);
12655 + au_update_figen(file);
12656 + /* todo: necessary? */
12657 + /* file->f_ra = h_file->f_ra; */
12661 + fput(h_file_tmp);
12665 +/* ---------------------------------------------------------------------- */
12667 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12668 + struct dentry *hi_wh)
12671 + aufs_bindex_t btop;
12672 + struct au_dinfo *dinfo;
12673 + struct dentry *h_dentry;
12674 + struct au_hdentry *hdp;
12676 + dinfo = au_di(file->f_path.dentry);
12677 + AuRwMustWriteLock(&dinfo->di_rwsem);
12679 + btop = dinfo->di_btop;
12680 + dinfo->di_btop = btgt;
12681 + hdp = au_hdentry(dinfo, btgt);
12682 + h_dentry = hdp->hd_dentry;
12683 + hdp->hd_dentry = hi_wh;
12684 + err = au_reopen_nondir(file);
12685 + hdp->hd_dentry = h_dentry;
12686 + dinfo->di_btop = btop;
12691 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12692 + aufs_bindex_t bcpup, struct au_pin *pin)
12695 + struct inode *inode, *h_inode;
12696 + struct dentry *h_dentry, *hi_wh;
12697 + struct au_cp_generic cpg = {
12698 + .dentry = file->f_path.dentry,
12705 + au_update_dbtop(cpg.dentry);
12706 + inode = d_inode(cpg.dentry);
12708 + if (au_dbtop(cpg.dentry) <= bcpup
12709 + && au_dbbot(cpg.dentry) >= bcpup) {
12710 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12711 + if (h_dentry && d_is_positive(h_dentry))
12712 + h_inode = d_inode(h_dentry);
12714 + hi_wh = au_hi_wh(inode, bcpup);
12715 + if (!hi_wh && !h_inode)
12716 + err = au_sio_cpup_wh(&cpg, file);
12718 + /* already copied-up after unlink */
12719 + err = au_reopen_wh(file, bcpup, hi_wh);
12722 + && (inode->i_nlink > 1
12723 + || (inode->i_state & I_LINKABLE))
12724 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12725 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12731 + * prepare the @file for writing.
12733 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12736 + aufs_bindex_t dbtop;
12737 + struct dentry *parent;
12738 + struct inode *inode;
12739 + struct super_block *sb;
12740 + struct file *h_file;
12741 + struct au_cp_generic cpg = {
12742 + .dentry = file->f_path.dentry,
12747 + .flags = AuCpup_DTIME
12750 + sb = cpg.dentry->d_sb;
12751 + inode = d_inode(cpg.dentry);
12752 + cpg.bsrc = au_fbtop(file);
12753 + err = au_test_ro(sb, cpg.bsrc, inode);
12754 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12755 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12760 + /* need to cpup or reopen */
12761 + parent = dget_parent(cpg.dentry);
12762 + di_write_lock_parent(parent);
12763 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12765 + if (unlikely(err < 0))
12769 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12770 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12771 + if (unlikely(err))
12775 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12776 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12777 + if (unlikely(err))
12780 + dbtop = au_dbtop(cpg.dentry);
12781 + if (dbtop <= cpg.bdst)
12782 + cpg.bsrc = cpg.bdst;
12784 + if (dbtop <= cpg.bdst /* just reopen */
12785 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12787 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12788 + if (IS_ERR(h_file))
12789 + err = PTR_ERR(h_file);
12791 + di_downgrade_lock(parent, AuLock_IR);
12792 + if (dbtop > cpg.bdst)
12793 + err = au_sio_cpup_simple(&cpg);
12795 + err = au_reopen_nondir(file);
12796 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12798 + } else { /* copyup as wh and reopen */
12800 + * since writable hfsplus branch is not supported,
12801 + * h_open_pre/post() are unnecessary.
12803 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12804 + di_downgrade_lock(parent, AuLock_IR);
12808 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12809 + goto out_dput; /* success */
12815 + di_downgrade_lock(parent, AuLock_IR);
12817 + di_read_unlock(parent, AuLock_IR);
12824 +/* ---------------------------------------------------------------------- */
12826 +int au_do_flush(struct file *file, fl_owner_t id,
12827 + int (*flush)(struct file *file, fl_owner_t id))
12830 + struct super_block *sb;
12831 + struct inode *inode;
12833 + inode = file_inode(file);
12834 + sb = inode->i_sb;
12835 + si_noflush_read_lock(sb);
12836 + fi_read_lock(file);
12837 + ii_read_lock_child(inode);
12839 + err = flush(file, id);
12840 + au_cpup_attr_timesizes(inode);
12842 + ii_read_unlock(inode);
12843 + fi_read_unlock(file);
12844 + si_read_unlock(sb);
12848 +/* ---------------------------------------------------------------------- */
12850 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12853 + struct au_pin pin;
12854 + struct au_finfo *finfo;
12855 + struct dentry *parent, *hi_wh;
12856 + struct inode *inode;
12857 + struct super_block *sb;
12858 + struct au_cp_generic cpg = {
12859 + .dentry = file->f_path.dentry,
12864 + .flags = AuCpup_DTIME
12867 + FiMustWriteLock(file);
12870 + finfo = au_fi(file);
12871 + sb = cpg.dentry->d_sb;
12872 + inode = d_inode(cpg.dentry);
12873 + cpg.bdst = au_ibtop(inode);
12874 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12877 + parent = dget_parent(cpg.dentry);
12878 + if (au_test_ro(sb, cpg.bdst, inode)) {
12879 + di_read_lock_parent(parent, !AuLock_IR);
12880 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12882 + di_read_unlock(parent, !AuLock_IR);
12883 + if (unlikely(err < 0))
12888 + di_read_lock_parent(parent, AuLock_IR);
12889 + hi_wh = au_hi_wh(inode, cpg.bdst);
12890 + if (!S_ISDIR(inode->i_mode)
12891 + && au_opt_test(au_mntflags(sb), PLINK)
12892 + && au_plink_test(inode)
12893 + && !d_unhashed(cpg.dentry)
12894 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12895 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12896 + if (unlikely(err))
12899 + /* always superio. */
12900 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12901 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12903 + err = au_sio_cpup_simple(&cpg);
12906 + } else if (hi_wh) {
12907 + /* already copied-up after unlink */
12908 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12909 + *need_reopen = 0;
12913 + di_read_unlock(parent, AuLock_IR);
12920 +static void au_do_refresh_dir(struct file *file)
12922 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12923 + struct au_hfile *p, tmp, *q;
12924 + struct au_finfo *finfo;
12925 + struct super_block *sb;
12926 + struct au_fidir *fidir;
12928 + FiMustWriteLock(file);
12930 + sb = file->f_path.dentry->d_sb;
12931 + finfo = au_fi(file);
12932 + fidir = finfo->fi_hdir;
12933 + AuDebugOn(!fidir);
12934 + p = fidir->fd_hfile + finfo->fi_btop;
12935 + brid = p->hf_br->br_id;
12936 + bbot = fidir->fd_bbot;
12937 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12941 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12942 + if (new_bindex == bindex)
12944 + if (new_bindex < 0) {
12945 + au_set_h_fptr(file, bindex, NULL);
12949 + /* swap two lower inode, and loop again */
12950 + q = fidir->fd_hfile + new_bindex;
12954 + if (tmp.hf_file) {
12960 + p = fidir->fd_hfile;
12961 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12962 + bbot = au_sbbot(sb);
12963 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12964 + finfo->fi_btop++, p++)
12965 + if (p->hf_file) {
12966 + if (file_inode(p->hf_file))
12968 + au_hfput(p, /*execed*/0);
12971 + bbot = au_br_index(sb, brid);
12972 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12973 + finfo->fi_btop++, p++)
12975 + au_hfput(p, /*execed*/0);
12976 + bbot = au_sbbot(sb);
12979 + p = fidir->fd_hfile + bbot;
12980 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12981 + fidir->fd_bbot--, p--)
12982 + if (p->hf_file) {
12983 + if (file_inode(p->hf_file))
12985 + au_hfput(p, /*execed*/0);
12987 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12991 + * after branch manipulating, refresh the file.
12993 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12995 + int err, need_reopen, nbr;
12996 + aufs_bindex_t bbot, bindex;
12997 + struct dentry *dentry;
12998 + struct super_block *sb;
12999 + struct au_finfo *finfo;
13000 + struct au_hfile *hfile;
13002 + dentry = file->f_path.dentry;
13003 + sb = dentry->d_sb;
13004 + nbr = au_sbbot(sb) + 1;
13005 + finfo = au_fi(file);
13006 + if (!finfo->fi_hdir) {
13007 + hfile = &finfo->fi_htop;
13008 + AuDebugOn(!hfile->hf_file);
13009 + bindex = au_br_index(sb, hfile->hf_br->br_id);
13010 + AuDebugOn(bindex < 0);
13011 + if (bindex != finfo->fi_btop)
13012 + au_set_fbtop(file, bindex);
13014 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
13015 + if (unlikely(err))
13017 + au_do_refresh_dir(file);
13022 + if (!au_test_mmapped(file))
13023 + err = au_file_refresh_by_inode(file, &need_reopen);
13024 + if (finfo->fi_hdir)
13025 + /* harmless if err */
13026 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
13027 + if (!err && need_reopen && !d_unlinked(dentry))
13028 + err = reopen(file);
13030 + au_update_figen(file);
13031 + goto out; /* success */
13034 + /* error, close all lower files */
13035 + if (finfo->fi_hdir) {
13036 + bbot = au_fbbot_dir(file);
13037 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
13038 + au_set_h_fptr(file, bindex, NULL);
13045 +/* common function to regular file and dir */
13046 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13047 + int wlock, unsigned int fi_lsc)
13050 + unsigned int sigen, figen;
13051 + aufs_bindex_t btop;
13052 + unsigned char pseudo_link;
13053 + struct dentry *dentry;
13054 + struct inode *inode;
13057 + dentry = file->f_path.dentry;
13058 + inode = d_inode(dentry);
13059 + sigen = au_sigen(dentry->d_sb);
13060 + fi_write_lock_nested(file, fi_lsc);
13061 + figen = au_figen(file);
13063 + di_write_lock_child(dentry);
13065 + di_write_lock_child2(dentry);
13066 + btop = au_dbtop(dentry);
13067 + pseudo_link = (btop != au_ibtop(inode));
13068 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
13070 + di_downgrade_lock(dentry, AuLock_IR);
13071 + fi_downgrade_lock(file);
13073 + goto out; /* success */
13076 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13077 + if (au_digen_test(dentry, sigen)) {
13078 + err = au_reval_dpath(dentry, sigen);
13079 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13083 + err = refresh_file(file, reopen);
13086 + di_downgrade_lock(dentry, AuLock_IR);
13087 + fi_downgrade_lock(file);
13090 + di_write_unlock(dentry);
13091 + fi_write_unlock(file);
13098 +/* ---------------------------------------------------------------------- */
13100 +/* cf. aufs_nopage() */
13101 +/* for madvise(2) */
13102 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13104 + unlock_page(page);
13108 +/* it will never be called, but necessary to support O_DIRECT */
13109 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13110 +{ BUG(); return 0; }
13112 +/* they will never be called. */
13113 +#ifdef CONFIG_AUFS_DEBUG
13114 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13115 + loff_t pos, unsigned len, unsigned flags,
13116 + struct page **pagep, void **fsdata)
13117 +{ AuUnsupport(); return 0; }
13118 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13119 + loff_t pos, unsigned len, unsigned copied,
13120 + struct page *page, void *fsdata)
13121 +{ AuUnsupport(); return 0; }
13122 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13123 +{ AuUnsupport(); return 0; }
13125 +static int aufs_set_page_dirty(struct page *page)
13126 +{ AuUnsupport(); return 0; }
13127 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13128 + unsigned int length)
13129 +{ AuUnsupport(); }
13130 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13131 +{ AuUnsupport(); return 0; }
13132 +#if 0 /* called by memory compaction regardless file */
13133 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13134 + struct page *page, enum migrate_mode mode)
13135 +{ AuUnsupport(); return 0; }
13137 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13138 +{ AuUnsupport(); return true; }
13139 +static void aufs_putback_page(struct page *page)
13140 +{ AuUnsupport(); }
13141 +static int aufs_launder_page(struct page *page)
13142 +{ AuUnsupport(); return 0; }
13143 +static int aufs_is_partially_uptodate(struct page *page,
13144 + unsigned long from,
13145 + unsigned long count)
13146 +{ AuUnsupport(); return 0; }
13147 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13149 +{ AuUnsupport(); }
13150 +static int aufs_error_remove_page(struct address_space *mapping,
13151 + struct page *page)
13152 +{ AuUnsupport(); return 0; }
13153 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13155 +{ AuUnsupport(); return 0; }
13156 +static void aufs_swap_deactivate(struct file *file)
13157 +{ AuUnsupport(); }
13158 +#endif /* CONFIG_AUFS_DEBUG */
13160 +const struct address_space_operations aufs_aop = {
13161 + .readpage = aufs_readpage,
13162 + .direct_IO = aufs_direct_IO,
13163 +#ifdef CONFIG_AUFS_DEBUG
13164 + .writepage = aufs_writepage,
13165 + /* no writepages, because of writepage */
13166 + .set_page_dirty = aufs_set_page_dirty,
13167 + /* no readpages, because of readpage */
13168 + .write_begin = aufs_write_begin,
13169 + .write_end = aufs_write_end,
13170 + /* no bmap, no block device */
13171 + .invalidatepage = aufs_invalidatepage,
13172 + .releasepage = aufs_releasepage,
13173 + /* is fallback_migrate_page ok? */
13174 + /* .migratepage = aufs_migratepage, */
13175 + .isolate_page = aufs_isolate_page,
13176 + .putback_page = aufs_putback_page,
13177 + .launder_page = aufs_launder_page,
13178 + .is_partially_uptodate = aufs_is_partially_uptodate,
13179 + .is_dirty_writeback = aufs_is_dirty_writeback,
13180 + .error_remove_page = aufs_error_remove_page,
13181 + .swap_activate = aufs_swap_activate,
13182 + .swap_deactivate = aufs_swap_deactivate
13183 +#endif /* CONFIG_AUFS_DEBUG */
13185 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13186 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13187 +++ linux/fs/aufs/file.h 2017-09-05 10:42:11.058755349 +0200
13190 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13192 + * This program, aufs is free software; you can redistribute it and/or modify
13193 + * it under the terms of the GNU General Public License as published by
13194 + * the Free Software Foundation; either version 2 of the License, or
13195 + * (at your option) any later version.
13197 + * This program is distributed in the hope that it will be useful,
13198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13200 + * GNU General Public License for more details.
13202 + * You should have received a copy of the GNU General Public License
13203 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13207 + * file operations
13210 +#ifndef __AUFS_FILE_H__
13211 +#define __AUFS_FILE_H__
13215 +#include <linux/file.h>
13216 +#include <linux/fs.h>
13217 +#include <linux/mm_types.h>
13218 +#include <linux/poll.h>
13219 +#include "rwsem.h"
13223 + struct file *hf_file;
13224 + struct au_branch *hf_br;
13229 + aufs_bindex_t fd_bbot;
13230 + aufs_bindex_t fd_nent;
13231 + struct au_vdir *fd_vdir_cache;
13232 + struct au_hfile fd_hfile[];
13235 +static inline int au_fidir_sz(int nent)
13237 + AuDebugOn(nent < 0);
13238 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13242 + atomic_t fi_generation;
13244 + struct au_rwsem fi_rwsem;
13245 + aufs_bindex_t fi_btop;
13247 + /* do not union them */
13248 + struct { /* for non-dir */
13249 + struct au_hfile fi_htop;
13250 + atomic_t fi_mmapped;
13252 + struct au_fidir *fi_hdir; /* for dir only */
13254 + struct hlist_node fi_hlist;
13255 + struct file *fi_file; /* very ugly */
13256 +} ____cacheline_aligned_in_smp;
13258 +/* ---------------------------------------------------------------------- */
13261 +extern const struct address_space_operations aufs_aop;
13262 +unsigned int au_file_roflags(unsigned int flags);
13263 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13264 + struct file *file, int force_wr);
13265 +struct au_do_open_args {
13267 + int (*open)(struct file *file, int flags,
13268 + struct file *h_file);
13269 + struct au_fidir *fidir;
13270 + struct file *h_file;
13272 +int au_do_open(struct file *file, struct au_do_open_args *args);
13273 +int au_reopen_nondir(struct file *file);
13275 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13276 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13277 + int wlock, unsigned int fi_lsc);
13278 +int au_do_flush(struct file *file, fl_owner_t id,
13279 + int (*flush)(struct file *file, fl_owner_t id));
13282 +#ifdef CONFIG_AUFS_POLL
13283 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13286 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13288 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13290 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13291 + struct file *h_file);
13293 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13294 + aufs_bindex_t bindex, int force_wr)
13295 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13296 + struct file *h_file);
13300 +extern const struct file_operations aufs_file_fop;
13301 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13302 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13303 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
13306 +void au_hfput(struct au_hfile *hf, int execed);
13307 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13308 + struct file *h_file);
13310 +void au_update_figen(struct file *file);
13311 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13312 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13314 +void au_fi_init_once(void *_fi);
13315 +void au_finfo_fin(struct file *file);
13316 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13319 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13320 +#ifdef CONFIG_COMPAT
13321 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13322 + unsigned long arg);
13323 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13324 + unsigned long arg);
13327 +/* ---------------------------------------------------------------------- */
13329 +static inline struct au_finfo *au_fi(struct file *file)
13331 + return file->private_data;
13334 +/* ---------------------------------------------------------------------- */
13337 + * fi_read_lock, fi_write_lock,
13338 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13340 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13342 +/* lock subclass for finfo */
13348 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
13350 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13353 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
13355 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13359 + * fi_read_lock_1, fi_write_lock_1,
13360 + * fi_read_lock_2, fi_write_lock_2
13362 +#define AuReadLockFunc(name) \
13363 +static inline void fi_read_lock_##name(struct file *f) \
13364 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
13366 +#define AuWriteLockFunc(name) \
13367 +static inline void fi_write_lock_##name(struct file *f) \
13368 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
13370 +#define AuRWLockFuncs(name) \
13371 + AuReadLockFunc(name) \
13372 + AuWriteLockFunc(name)
13377 +#undef AuReadLockFunc
13378 +#undef AuWriteLockFunc
13379 +#undef AuRWLockFuncs
13381 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13382 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13383 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13385 +/* ---------------------------------------------------------------------- */
13387 +/* todo: hard/soft set? */
13388 +static inline aufs_bindex_t au_fbtop(struct file *file)
13390 + FiMustAnyLock(file);
13391 + return au_fi(file)->fi_btop;
13394 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13396 + FiMustAnyLock(file);
13397 + AuDebugOn(!au_fi(file)->fi_hdir);
13398 + return au_fi(file)->fi_hdir->fd_bbot;
13401 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13403 + FiMustAnyLock(file);
13404 + AuDebugOn(!au_fi(file)->fi_hdir);
13405 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13408 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13410 + FiMustWriteLock(file);
13411 + au_fi(file)->fi_btop = bindex;
13414 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13416 + FiMustWriteLock(file);
13417 + AuDebugOn(!au_fi(file)->fi_hdir);
13418 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13421 +static inline void au_set_fvdir_cache(struct file *file,
13422 + struct au_vdir *vdir_cache)
13424 + FiMustWriteLock(file);
13425 + AuDebugOn(!au_fi(file)->fi_hdir);
13426 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13429 +static inline struct file *au_hf_top(struct file *file)
13431 + FiMustAnyLock(file);
13432 + AuDebugOn(au_fi(file)->fi_hdir);
13433 + return au_fi(file)->fi_htop.hf_file;
13436 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13438 + FiMustAnyLock(file);
13439 + AuDebugOn(!au_fi(file)->fi_hdir);
13440 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13443 +/* todo: memory barrier? */
13444 +static inline unsigned int au_figen(struct file *f)
13446 + return atomic_read(&au_fi(f)->fi_generation);
13449 +static inline void au_set_mmapped(struct file *f)
13451 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13453 + pr_warn("fi_mmapped wrapped around\n");
13454 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13458 +static inline void au_unset_mmapped(struct file *f)
13460 + atomic_dec(&au_fi(f)->fi_mmapped);
13463 +static inline int au_test_mmapped(struct file *f)
13465 + return atomic_read(&au_fi(f)->fi_mmapped);
13468 +/* customize vma->vm_file */
13470 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13471 + struct file *file)
13475 + f = vma->vm_file;
13477 + vma->vm_file = file;
13482 +#define AuDbgVmRegion(file, vma) do {} while (0)
13484 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13485 + struct file *file)
13487 + au_do_vm_file_reset(vma, file);
13490 +#define AuDbgVmRegion(file, vma) \
13491 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13493 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13494 + struct file *file)
13498 + au_do_vm_file_reset(vma, file);
13499 + f = vma->vm_region->vm_file;
13501 + vma->vm_region->vm_file = file;
13504 +#endif /* CONFIG_MMU */
13506 +/* handle vma->vm_prfile */
13507 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13508 + struct file *file)
13511 + vma->vm_prfile = file;
13512 +#ifndef CONFIG_MMU
13514 + vma->vm_region->vm_prfile = file;
13518 +#endif /* __KERNEL__ */
13519 +#endif /* __AUFS_FILE_H__ */
13520 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13521 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13522 +++ linux/fs/aufs/finfo.c 2017-07-29 12:14:25.903042072 +0200
13525 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13527 + * This program, aufs is free software; you can redistribute it and/or modify
13528 + * it under the terms of the GNU General Public License as published by
13529 + * the Free Software Foundation; either version 2 of the License, or
13530 + * (at your option) any later version.
13532 + * This program is distributed in the hope that it will be useful,
13533 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13534 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13535 + * GNU General Public License for more details.
13537 + * You should have received a copy of the GNU General Public License
13538 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13542 + * file private data
13547 +void au_hfput(struct au_hfile *hf, int execed)
13550 + allow_write_access(hf->hf_file);
13551 + fput(hf->hf_file);
13552 + hf->hf_file = NULL;
13553 + au_br_put(hf->hf_br);
13554 + hf->hf_br = NULL;
13557 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13559 + struct au_finfo *finfo = au_fi(file);
13560 + struct au_hfile *hf;
13561 + struct au_fidir *fidir;
13563 + fidir = finfo->fi_hdir;
13565 + AuDebugOn(finfo->fi_btop != bindex);
13566 + hf = &finfo->fi_htop;
13568 + hf = fidir->fd_hfile + bindex;
13570 + if (hf && hf->hf_file)
13571 + au_hfput(hf, vfsub_file_execed(file));
13573 + FiMustWriteLock(file);
13574 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13575 + hf->hf_file = val;
13576 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13580 +void au_update_figen(struct file *file)
13582 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13583 + /* smp_mb(); */ /* atomic_set */
13586 +/* ---------------------------------------------------------------------- */
13588 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13590 + struct au_fidir *fidir;
13593 + nbr = au_sbbot(sb) + 1;
13595 + nbr = 2; /* initial allocate for 2 branches */
13596 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13598 + fidir->fd_bbot = -1;
13599 + fidir->fd_nent = nbr;
13605 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13608 + struct au_fidir *fidir, *p;
13610 + AuRwMustWriteLock(&finfo->fi_rwsem);
13611 + fidir = finfo->fi_hdir;
13612 + AuDebugOn(!fidir);
13615 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13616 + GFP_NOFS, may_shrink);
13618 + p->fd_nent = nbr;
13619 + finfo->fi_hdir = p;
13626 +/* ---------------------------------------------------------------------- */
13628 +void au_finfo_fin(struct file *file)
13630 + struct au_finfo *finfo;
13632 + au_nfiles_dec(file->f_path.dentry->d_sb);
13634 + finfo = au_fi(file);
13635 + AuDebugOn(finfo->fi_hdir);
13636 + AuRwDestroy(&finfo->fi_rwsem);
13637 + au_cache_free_finfo(finfo);
13640 +void au_fi_init_once(void *_finfo)
13642 + struct au_finfo *finfo = _finfo;
13644 + au_rw_init(&finfo->fi_rwsem);
13647 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13650 + struct au_finfo *finfo;
13651 + struct dentry *dentry;
13654 + dentry = file->f_path.dentry;
13655 + finfo = au_cache_alloc_finfo();
13656 + if (unlikely(!finfo))
13660 + au_nfiles_inc(dentry->d_sb);
13661 + au_rw_write_lock(&finfo->fi_rwsem);
13662 + finfo->fi_btop = -1;
13663 + finfo->fi_hdir = fidir;
13664 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13665 + /* smp_mb(); */ /* atomic_set */
13667 + file->private_data = finfo;
13672 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13673 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13674 +++ linux/fs/aufs/f_op.c 2017-07-29 12:14:25.903042072 +0200
13677 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13679 + * This program, aufs is free software; you can redistribute it and/or modify
13680 + * it under the terms of the GNU General Public License as published by
13681 + * the Free Software Foundation; either version 2 of the License, or
13682 + * (at your option) any later version.
13684 + * This program is distributed in the hope that it will be useful,
13685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13687 + * GNU General Public License for more details.
13689 + * You should have received a copy of the GNU General Public License
13690 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13694 + * file and vm operations
13697 +#include <linux/aio.h>
13698 +#include <linux/fs_stack.h>
13699 +#include <linux/mman.h>
13700 +#include <linux/security.h>
13703 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13706 + aufs_bindex_t bindex;
13707 + struct dentry *dentry, *h_dentry;
13708 + struct au_finfo *finfo;
13709 + struct inode *h_inode;
13711 + FiMustWriteLock(file);
13714 + dentry = file->f_path.dentry;
13715 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13716 + finfo = au_fi(file);
13717 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13718 + atomic_set(&finfo->fi_mmapped, 0);
13719 + bindex = au_dbtop(dentry);
13721 + h_dentry = au_h_dptr(dentry, bindex);
13722 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13723 + if (unlikely(err))
13725 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13727 + h_dentry = h_file->f_path.dentry;
13728 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13729 + if (unlikely(err))
13731 + get_file(h_file);
13733 + if (IS_ERR(h_file))
13734 + err = PTR_ERR(h_file);
13736 + if ((flags & __O_TMPFILE)
13737 + && !(flags & O_EXCL)) {
13738 + h_inode = file_inode(h_file);
13739 + spin_lock(&h_inode->i_lock);
13740 + h_inode->i_state |= I_LINKABLE;
13741 + spin_unlock(&h_inode->i_lock);
13743 + au_set_fbtop(file, bindex);
13744 + au_set_h_fptr(file, bindex, h_file);
13745 + au_update_figen(file);
13746 + /* todo: necessary? */
13747 + /* file->f_ra = h_file->f_ra; */
13754 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13755 + struct file *file)
13758 + struct super_block *sb;
13759 + struct au_do_open_args args = {
13760 + .open = au_do_open_nondir
13763 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13764 + file, vfsub_file_flags(file), file->f_mode);
13766 + sb = file->f_path.dentry->d_sb;
13767 + si_read_lock(sb, AuLock_FLUSH);
13768 + err = au_do_open(file, &args);
13769 + si_read_unlock(sb);
13773 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13775 + struct au_finfo *finfo;
13776 + aufs_bindex_t bindex;
13778 + finfo = au_fi(file);
13779 + au_sphl_del(&finfo->fi_hlist,
13780 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13781 + bindex = finfo->fi_btop;
13783 + au_set_h_fptr(file, bindex, NULL);
13785 + au_finfo_fin(file);
13789 +/* ---------------------------------------------------------------------- */
13791 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13794 + struct file *h_file;
13797 + h_file = au_hf_top(file);
13799 + err = vfsub_flush(h_file, id);
13803 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13805 + return au_do_flush(file, id, au_do_flush_nondir);
13808 +/* ---------------------------------------------------------------------- */
13810 + * read and write functions acquire [fdi]_rwsem once, but release before
13811 + * mmap_sem. This is because to stop a race condition between mmap(2).
13812 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13813 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13814 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13817 +/* Callers should call au_read_post() or fput() in the end */
13818 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
13820 + struct file *h_file;
13823 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
13825 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13826 + h_file = au_hf_top(file);
13827 + get_file(h_file);
13829 + fi_read_unlock(file);
13831 + h_file = ERR_PTR(err);
13836 +static void au_read_post(struct inode *inode, struct file *h_file)
13838 + /* update without lock, I don't think it a problem */
13839 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13843 +struct au_write_pre {
13845 + unsigned int lsc;
13849 + aufs_bindex_t btop;
13853 + * return with iinfo is write-locked
13854 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13857 +static struct file *au_write_pre(struct file *file, int do_ready,
13858 + struct au_write_pre *wpre)
13860 + struct file *h_file;
13861 + struct dentry *dentry;
13863 + unsigned int lsc;
13864 + struct au_pin pin;
13869 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
13870 + h_file = ERR_PTR(err);
13871 + if (unlikely(err))
13874 + dentry = file->f_path.dentry;
13876 + err = au_ready_to_write(file, -1, &pin);
13877 + if (unlikely(err)) {
13878 + h_file = ERR_PTR(err);
13879 + di_write_unlock(dentry);
13884 + di_downgrade_lock(dentry, /*flags*/0);
13886 + wpre->btop = au_fbtop(file);
13887 + h_file = au_hf_top(file);
13888 + get_file(h_file);
13890 + wpre->blks = file_inode(h_file)->i_blocks;
13893 + di_read_unlock(dentry, /*flags*/0);
13896 + fi_write_unlock(file);
13901 +static void au_write_post(struct inode *inode, struct file *h_file,
13902 + struct au_write_pre *wpre, ssize_t written)
13904 + struct inode *h_inode;
13906 + au_cpup_attr_timesizes(inode);
13907 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13908 + h_inode = file_inode(h_file);
13909 + inode->i_mode = h_inode->i_mode;
13910 + ii_write_unlock(inode);
13911 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13913 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13914 + /*force*/h_inode->i_blocks > wpre->blks);
13918 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13922 + struct inode *inode;
13923 + struct file *h_file;
13924 + struct super_block *sb;
13926 + inode = file_inode(file);
13927 + sb = inode->i_sb;
13928 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13930 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
13931 + err = PTR_ERR(h_file);
13932 + if (IS_ERR(h_file))
13935 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13936 + err = vfsub_read_u(h_file, buf, count, ppos);
13937 + /* todo: necessary? */
13938 + /* file->f_ra = h_file->f_ra; */
13939 + au_read_post(inode, h_file);
13942 + si_read_unlock(sb);
13947 + * todo: very ugly
13948 + * it locks both of i_mutex and si_rwsem for read in safe.
13949 + * if the plink maintenance mode continues forever (that is the problem),
13950 + * may loop forever.
13952 +static void au_mtx_and_read_lock(struct inode *inode)
13955 + struct super_block *sb = inode->i_sb;
13958 + inode_lock(inode);
13959 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13962 + inode_unlock(inode);
13963 + si_read_lock(sb, AuLock_NOPLMW);
13964 + si_read_unlock(sb);
13968 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13969 + size_t count, loff_t *ppos)
13972 + struct au_write_pre wpre;
13973 + struct inode *inode;
13974 + struct file *h_file;
13975 + char __user *buf = (char __user *)ubuf;
13977 + inode = file_inode(file);
13978 + au_mtx_and_read_lock(inode);
13981 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13982 + err = PTR_ERR(h_file);
13983 + if (IS_ERR(h_file))
13986 + err = vfsub_write_u(h_file, buf, count, ppos);
13987 + au_write_post(inode, h_file, &wpre, err);
13990 + si_read_unlock(inode->i_sb);
13991 + inode_unlock(inode);
13995 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13996 + struct iov_iter *iov_iter)
13999 + struct file *file;
14000 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
14002 + err = security_file_permission(h_file, rw);
14003 + if (unlikely(err))
14008 + if (rw == MAY_READ)
14009 + iter = h_file->f_op->read_iter;
14010 + else if (rw == MAY_WRITE)
14011 + iter = h_file->f_op->write_iter;
14013 + file = kio->ki_filp;
14014 + kio->ki_filp = h_file;
14017 + err = iter(kio, iov_iter);
14020 + /* currently there is no such fs */
14022 + kio->ki_filp = file;
14028 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14031 + struct file *file, *h_file;
14032 + struct inode *inode;
14033 + struct super_block *sb;
14035 + file = kio->ki_filp;
14036 + inode = file_inode(file);
14037 + sb = inode->i_sb;
14038 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14040 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
14041 + err = PTR_ERR(h_file);
14042 + if (IS_ERR(h_file))
14045 + if (au_test_loopback_kthread()) {
14046 + au_warn_loopback(h_file->f_path.dentry->d_sb);
14047 + if (file->f_mapping != h_file->f_mapping) {
14048 + file->f_mapping = h_file->f_mapping;
14049 + smp_mb(); /* unnecessary? */
14052 + fi_read_unlock(file);
14054 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
14055 + /* todo: necessary? */
14056 + /* file->f_ra = h_file->f_ra; */
14057 + au_read_post(inode, h_file);
14060 + si_read_unlock(sb);
14064 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14067 + struct au_write_pre wpre;
14068 + struct inode *inode;
14069 + struct file *file, *h_file;
14071 + file = kio->ki_filp;
14072 + inode = file_inode(file);
14073 + au_mtx_and_read_lock(inode);
14076 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14077 + err = PTR_ERR(h_file);
14078 + if (IS_ERR(h_file))
14081 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
14082 + au_write_post(inode, h_file, &wpre, err);
14085 + si_read_unlock(inode->i_sb);
14086 + inode_unlock(inode);
14090 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
14091 + struct pipe_inode_info *pipe, size_t len,
14092 + unsigned int flags)
14095 + struct file *h_file;
14096 + struct inode *inode;
14097 + struct super_block *sb;
14099 + inode = file_inode(file);
14100 + sb = inode->i_sb;
14101 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14103 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14104 + err = PTR_ERR(h_file);
14105 + if (IS_ERR(h_file))
14108 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14109 + /* todo: necessasry? */
14110 + /* file->f_ra = h_file->f_ra; */
14111 + au_read_post(inode, h_file);
14114 + si_read_unlock(sb);
14119 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14120 + size_t len, unsigned int flags)
14123 + struct au_write_pre wpre;
14124 + struct inode *inode;
14125 + struct file *h_file;
14127 + inode = file_inode(file);
14128 + au_mtx_and_read_lock(inode);
14131 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14132 + err = PTR_ERR(h_file);
14133 + if (IS_ERR(h_file))
14136 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14137 + au_write_post(inode, h_file, &wpre, err);
14140 + si_read_unlock(inode->i_sb);
14141 + inode_unlock(inode);
14145 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14149 + struct au_write_pre wpre;
14150 + struct inode *inode;
14151 + struct file *h_file;
14153 + inode = file_inode(file);
14154 + au_mtx_and_read_lock(inode);
14157 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14158 + err = PTR_ERR(h_file);
14159 + if (IS_ERR(h_file))
14163 + err = vfs_fallocate(h_file, mode, offset, len);
14165 + au_write_post(inode, h_file, &wpre, /*written*/1);
14168 + si_read_unlock(inode->i_sb);
14169 + inode_unlock(inode);
14173 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
14174 + struct file *dst, loff_t dst_pos,
14175 + size_t len, unsigned int flags)
14178 + struct au_write_pre wpre;
14179 + enum { SRC, DST };
14181 + struct inode *inode;
14182 + struct file *h_file;
14183 + struct super_block *h_sb;
14185 +#define a_src a[SRC]
14186 +#define a_dst a[DST]
14189 + a_src.inode = file_inode(src);
14190 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
14192 + a_dst.inode = file_inode(dst);
14193 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
14196 + au_mtx_and_read_lock(a_dst.inode);
14198 + * in order to match the order in di_write_lock2_{child,parent}(),
14199 + * use f_path.dentry for this comparision.
14201 + if (src->f_path.dentry < dst->f_path.dentry) {
14202 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
14203 + err = PTR_ERR(a_src.h_file);
14204 + if (IS_ERR(a_src.h_file))
14207 + wpre.lsc = AuLsc_FI_2;
14208 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14209 + err = PTR_ERR(a_dst.h_file);
14210 + if (IS_ERR(a_dst.h_file)) {
14211 + au_read_post(a_src.inode, a_src.h_file);
14215 + wpre.lsc = AuLsc_FI_1;
14216 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14217 + err = PTR_ERR(a_dst.h_file);
14218 + if (IS_ERR(a_dst.h_file))
14221 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
14222 + err = PTR_ERR(a_src.h_file);
14223 + if (IS_ERR(a_src.h_file)) {
14224 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
14231 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
14232 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
14233 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
14239 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
14240 + dst_pos, len, flags);
14243 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
14244 + fi_read_unlock(src);
14245 + au_read_post(a_src.inode, a_src.h_file);
14247 + si_read_unlock(a_dst.inode->i_sb);
14248 + inode_unlock(a_dst.inode);
14255 +/* ---------------------------------------------------------------------- */
14258 + * The locking order around current->mmap_sem.
14259 + * - in most and regular cases
14260 + * file I/O syscall -- aufs_read() or something
14261 + * -- si_rwsem for read -- mmap_sem
14262 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14264 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14265 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14266 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14267 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14268 + * It means that when aufs acquires si_rwsem for write, the process should never
14269 + * acquire mmap_sem.
14271 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14272 + * problem either since any directory is not able to be mmap-ed.
14273 + * The similar scenario is applied to aufs_readlink() too.
14276 +#if 0 /* stop calling security_file_mmap() */
14277 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14278 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14280 +static unsigned long au_arch_prot_conv(unsigned long flags)
14282 + /* currently ppc64 only */
14283 +#ifdef CONFIG_PPC64
14284 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14285 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14286 + return AuConv_VM_PROT(flags, SAO);
14288 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14293 +static unsigned long au_prot_conv(unsigned long flags)
14295 + return AuConv_VM_PROT(flags, READ)
14296 + | AuConv_VM_PROT(flags, WRITE)
14297 + | AuConv_VM_PROT(flags, EXEC)
14298 + | au_arch_prot_conv(flags);
14301 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14302 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14304 +static unsigned long au_flag_conv(unsigned long flags)
14306 + return AuConv_VM_MAP(flags, GROWSDOWN)
14307 + | AuConv_VM_MAP(flags, DENYWRITE)
14308 + | AuConv_VM_MAP(flags, LOCKED);
14312 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14315 + const unsigned char wlock
14316 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14317 + struct super_block *sb;
14318 + struct file *h_file;
14319 + struct inode *inode;
14321 + AuDbgVmRegion(file, vma);
14323 + inode = file_inode(file);
14324 + sb = inode->i_sb;
14326 + si_read_lock(sb, AuLock_NOPLMW);
14328 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14330 + err = PTR_ERR(h_file);
14331 + if (IS_ERR(h_file))
14335 + au_set_mmapped(file);
14336 + au_vm_file_reset(vma, h_file);
14338 + * we cannot call security_mmap_file() here since it may acquire
14339 + * mmap_sem or i_mutex.
14341 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14342 + * au_flag_conv(vma->vm_flags));
14345 + err = call_mmap(h_file, vma);
14347 + au_vm_prfile_set(vma, file);
14348 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14349 + goto out_fput; /* success */
14351 + au_unset_mmapped(file);
14352 + au_vm_file_reset(vma, file);
14356 + ii_write_unlock(inode);
14361 + si_read_unlock(sb);
14367 +/* ---------------------------------------------------------------------- */
14369 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14373 + struct au_write_pre wpre;
14374 + struct inode *inode;
14375 + struct file *h_file;
14377 + err = 0; /* -EBADF; */ /* posix? */
14378 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14381 + inode = file_inode(file);
14382 + au_mtx_and_read_lock(inode);
14385 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14386 + err = PTR_ERR(h_file);
14387 + if (IS_ERR(h_file))
14390 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14391 + au_write_post(inode, h_file, &wpre, /*written*/0);
14394 + si_read_unlock(inode->i_sb);
14395 + inode_unlock(inode);
14400 +static int aufs_fasync(int fd, struct file *file, int flag)
14403 + struct file *h_file;
14404 + struct super_block *sb;
14406 + sb = file->f_path.dentry->d_sb;
14407 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14409 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14410 + err = PTR_ERR(h_file);
14411 + if (IS_ERR(h_file))
14414 + if (h_file->f_op->fasync)
14415 + err = h_file->f_op->fasync(fd, h_file, flag);
14416 + fput(h_file); /* instead of au_read_post() */
14419 + si_read_unlock(sb);
14423 +static int aufs_setfl(struct file *file, unsigned long arg)
14426 + struct file *h_file;
14427 + struct super_block *sb;
14429 + sb = file->f_path.dentry->d_sb;
14430 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14432 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14433 + err = PTR_ERR(h_file);
14434 + if (IS_ERR(h_file))
14437 + /* stop calling h_file->fasync */
14438 + arg |= vfsub_file_flags(file) & FASYNC;
14439 + err = setfl(/*unused fd*/-1, h_file, arg);
14440 + fput(h_file); /* instead of au_read_post() */
14443 + si_read_unlock(sb);
14447 +/* ---------------------------------------------------------------------- */
14449 +/* no one supports this operation, currently */
14451 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14452 + size_t len, loff_t *pos, int more)
14457 +/* ---------------------------------------------------------------------- */
14459 +const struct file_operations aufs_file_fop = {
14460 + .owner = THIS_MODULE,
14462 + .llseek = default_llseek,
14464 + .read = aufs_read,
14465 + .write = aufs_write,
14466 + .read_iter = aufs_read_iter,
14467 + .write_iter = aufs_write_iter,
14469 +#ifdef CONFIG_AUFS_POLL
14470 + .poll = aufs_poll,
14472 + .unlocked_ioctl = aufs_ioctl_nondir,
14473 +#ifdef CONFIG_COMPAT
14474 + .compat_ioctl = aufs_compat_ioctl_nondir,
14476 + .mmap = aufs_mmap,
14477 + .open = aufs_open_nondir,
14478 + .flush = aufs_flush_nondir,
14479 + .release = aufs_release_nondir,
14480 + .fsync = aufs_fsync_nondir,
14481 + .fasync = aufs_fasync,
14482 + /* .sendpage = aufs_sendpage, */
14483 + .setfl = aufs_setfl,
14484 + .splice_write = aufs_splice_write,
14485 + .splice_read = aufs_splice_read,
14487 + .aio_splice_write = aufs_aio_splice_write,
14488 + .aio_splice_read = aufs_aio_splice_read,
14490 + .fallocate = aufs_fallocate,
14491 + .copy_file_range = aufs_copy_file_range
14493 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14494 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14495 +++ linux/fs/aufs/fstype.h 2017-07-29 12:14:25.903042072 +0200
14498 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14500 + * This program, aufs is free software; you can redistribute it and/or modify
14501 + * it under the terms of the GNU General Public License as published by
14502 + * the Free Software Foundation; either version 2 of the License, or
14503 + * (at your option) any later version.
14505 + * This program is distributed in the hope that it will be useful,
14506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14508 + * GNU General Public License for more details.
14510 + * You should have received a copy of the GNU General Public License
14511 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14515 + * judging filesystem type
14518 +#ifndef __AUFS_FSTYPE_H__
14519 +#define __AUFS_FSTYPE_H__
14523 +#include <linux/fs.h>
14524 +#include <linux/magic.h>
14525 +#include <linux/nfs_fs.h>
14526 +#include <linux/romfs_fs.h>
14528 +static inline int au_test_aufs(struct super_block *sb)
14530 + return sb->s_magic == AUFS_SUPER_MAGIC;
14533 +static inline const char *au_sbtype(struct super_block *sb)
14535 + return sb->s_type->name;
14538 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14540 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14541 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14547 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14549 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14550 + return sb->s_magic == ROMFS_MAGIC;
14556 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14558 +#if IS_ENABLED(CONFIG_CRAMFS)
14559 + return sb->s_magic == CRAMFS_MAGIC;
14564 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14566 +#if IS_ENABLED(CONFIG_NFS_FS)
14567 + return sb->s_magic == NFS_SUPER_MAGIC;
14573 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14575 +#if IS_ENABLED(CONFIG_FUSE_FS)
14576 + return sb->s_magic == FUSE_SUPER_MAGIC;
14582 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14584 +#if IS_ENABLED(CONFIG_XFS_FS)
14585 + return sb->s_magic == XFS_SB_MAGIC;
14591 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14593 +#ifdef CONFIG_TMPFS
14594 + return sb->s_magic == TMPFS_MAGIC;
14600 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14602 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14603 + return !strcmp(au_sbtype(sb), "ecryptfs");
14609 +static inline int au_test_ramfs(struct super_block *sb)
14611 + return sb->s_magic == RAMFS_MAGIC;
14614 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14616 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14617 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14623 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14625 +#ifdef CONFIG_PROC_FS
14626 + return sb->s_magic == PROC_SUPER_MAGIC;
14632 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14634 +#ifdef CONFIG_SYSFS
14635 + return sb->s_magic == SYSFS_MAGIC;
14641 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14643 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14644 + return sb->s_magic == CONFIGFS_MAGIC;
14650 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14652 +#if IS_ENABLED(CONFIG_MINIX_FS)
14653 + return sb->s_magic == MINIX3_SUPER_MAGIC
14654 + || sb->s_magic == MINIX2_SUPER_MAGIC
14655 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14656 + || sb->s_magic == MINIX_SUPER_MAGIC
14657 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14663 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14665 +#if IS_ENABLED(CONFIG_FAT_FS)
14666 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14672 +static inline int au_test_msdos(struct super_block *sb)
14674 + return au_test_fat(sb);
14677 +static inline int au_test_vfat(struct super_block *sb)
14679 + return au_test_fat(sb);
14682 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14684 +#ifdef CONFIG_SECURITYFS
14685 + return sb->s_magic == SECURITYFS_MAGIC;
14691 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14693 +#if IS_ENABLED(CONFIG_SQUASHFS)
14694 + return sb->s_magic == SQUASHFS_MAGIC;
14700 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14702 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14703 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14709 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14711 +#if IS_ENABLED(CONFIG_XENFS)
14712 + return sb->s_magic == XENFS_SUPER_MAGIC;
14718 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14720 +#ifdef CONFIG_DEBUG_FS
14721 + return sb->s_magic == DEBUGFS_MAGIC;
14727 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14729 +#if IS_ENABLED(CONFIG_NILFS)
14730 + return sb->s_magic == NILFS_SUPER_MAGIC;
14736 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14738 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14739 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14745 +/* ---------------------------------------------------------------------- */
14747 + * they can't be an aufs branch.
14749 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14752 +#ifndef CONFIG_AUFS_BR_RAMFS
14753 + au_test_ramfs(sb) ||
14755 + au_test_procfs(sb)
14756 + || au_test_sysfs(sb)
14757 + || au_test_configfs(sb)
14758 + || au_test_debugfs(sb)
14759 + || au_test_securityfs(sb)
14760 + || au_test_xenfs(sb)
14761 + || au_test_ecryptfs(sb)
14762 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14763 + || au_test_aufs(sb); /* will be supported in next version */
14766 +static inline int au_test_fs_remote(struct super_block *sb)
14768 + return !au_test_tmpfs(sb)
14769 +#ifdef CONFIG_AUFS_BR_RAMFS
14770 + && !au_test_ramfs(sb)
14772 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14775 +/* ---------------------------------------------------------------------- */
14778 + * Note: these functions (below) are created after reading ->getattr() in all
14779 + * filesystems under linux/fs. it means we have to do so in every update...
14783 + * some filesystems require getattr to refresh the inode attributes before
14785 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14786 + * and leave the work for d_revalidate()
14788 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14790 + return au_test_nfs(sb)
14791 + || au_test_fuse(sb)
14792 + /* || au_test_btrfs(sb) */ /* untested */
14797 + * filesystems which don't maintain i_size or i_blocks.
14799 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14801 + return au_test_xfs(sb)
14802 + || au_test_btrfs(sb)
14803 + || au_test_ubifs(sb)
14804 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14805 + /* || au_test_minix(sb) */ /* untested */
14810 + * filesystems which don't store the correct value in some of their inode
14813 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14815 + return au_test_fs_bad_iattr_size(sb)
14816 + || au_test_fat(sb)
14817 + || au_test_msdos(sb)
14818 + || au_test_vfat(sb);
14821 +/* they don't check i_nlink in link(2) */
14822 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14824 + return au_test_tmpfs(sb)
14825 +#ifdef CONFIG_AUFS_BR_RAMFS
14826 + || au_test_ramfs(sb)
14828 + || au_test_ubifs(sb)
14829 + || au_test_hfsplus(sb);
14833 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14835 +static inline int au_test_fs_notime(struct super_block *sb)
14837 + return au_test_nfs(sb)
14838 + || au_test_fuse(sb)
14839 + || au_test_ubifs(sb)
14843 +/* temporary support for i#1 in cramfs */
14844 +static inline int au_test_fs_unique_ino(struct inode *inode)
14846 + if (au_test_cramfs(inode->i_sb))
14847 + return inode->i_ino != 1;
14851 +/* ---------------------------------------------------------------------- */
14854 + * the filesystem where the xino files placed must support i/o after unlink and
14855 + * maintain i_size and i_blocks.
14857 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14859 + return au_test_fs_remote(sb)
14860 + || au_test_fs_bad_iattr_size(sb)
14861 + /* don't want unnecessary work for xino */
14862 + || au_test_aufs(sb)
14863 + || au_test_ecryptfs(sb)
14864 + || au_test_nilfs(sb);
14867 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14869 + return au_test_tmpfs(sb)
14870 + || au_test_ramfs(sb);
14874 + * test if the @sb is real-readonly.
14876 +static inline int au_test_fs_rr(struct super_block *sb)
14878 + return au_test_squashfs(sb)
14879 + || au_test_iso9660(sb)
14880 + || au_test_cramfs(sb)
14881 + || au_test_romfs(sb);
14885 + * test if the @inode is nfs with 'noacl' option
14886 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14888 +static inline int au_test_nfs_noacl(struct inode *inode)
14890 + return au_test_nfs(inode->i_sb)
14891 + /* && IS_POSIXACL(inode) */
14892 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14895 +#endif /* __KERNEL__ */
14896 +#endif /* __AUFS_FSTYPE_H__ */
14897 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14898 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14899 +++ linux/fs/aufs/hfsnotify.c 2017-07-31 10:27:18.853311720 +0200
14902 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14904 + * This program, aufs is free software; you can redistribute it and/or modify
14905 + * it under the terms of the GNU General Public License as published by
14906 + * the Free Software Foundation; either version 2 of the License, or
14907 + * (at your option) any later version.
14909 + * This program is distributed in the hope that it will be useful,
14910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14912 + * GNU General Public License for more details.
14914 + * You should have received a copy of the GNU General Public License
14915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14919 + * fsnotify for the lower directories
14924 +/* FS_IN_IGNORED is unnecessary */
14925 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14926 + | FS_CREATE | FS_EVENT_ON_CHILD);
14927 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14928 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14930 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14932 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14934 + /* AuDbg("here\n"); */
14935 + au_cache_free_hnotify(hn);
14936 + smp_mb__before_atomic();
14937 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14938 + wake_up(&au_hfsn_wq);
14941 +static int au_hfsn_alloc(struct au_hinode *hinode)
14944 + struct au_hnotify *hn;
14945 + struct super_block *sb;
14946 + struct au_branch *br;
14947 + struct fsnotify_mark *mark;
14948 + aufs_bindex_t bindex;
14950 + hn = hinode->hi_notify;
14951 + sb = hn->hn_aufs_inode->i_sb;
14952 + bindex = au_br_index(sb, hinode->hi_id);
14953 + br = au_sbr(sb, bindex);
14954 + AuDebugOn(!br->br_hfsn);
14956 + mark = &hn->hn_mark;
14957 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
14958 + mark->mask = AuHfsnMask;
14960 + * by udba rename or rmdir, aufs assign a new inode to the known
14961 + * h_inode, so specify 1 to allow dups.
14964 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
14965 + /*allow_dups*/1);
14971 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14973 + struct fsnotify_mark *mark;
14974 + unsigned long long ull;
14975 + struct fsnotify_group *group;
14977 + ull = atomic64_inc_return(&au_hfsn_ifree);
14980 + mark = &hn->hn_mark;
14981 + spin_lock(&mark->lock);
14982 + group = mark->group;
14983 + fsnotify_get_group(group);
14984 + spin_unlock(&mark->lock);
14986 + fsnotify_destroy_mark(mark, group);
14987 + fsnotify_put_mark(mark);
14988 + fsnotify_put_group(group);
14991 + /* free hn by myself */
14995 +/* ---------------------------------------------------------------------- */
14997 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14999 + struct fsnotify_mark *mark;
15001 + mark = &hinode->hi_notify->hn_mark;
15002 + spin_lock(&mark->lock);
15004 + AuDebugOn(mark->mask & AuHfsnMask);
15005 + mark->mask |= AuHfsnMask;
15007 + AuDebugOn(!(mark->mask & AuHfsnMask));
15008 + mark->mask &= ~AuHfsnMask;
15010 + spin_unlock(&mark->lock);
15011 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
15014 +/* ---------------------------------------------------------------------- */
15016 +/* #define AuDbgHnotify */
15017 +#ifdef AuDbgHnotify
15018 +static char *au_hfsn_name(u32 mask)
15020 +#ifdef CONFIG_AUFS_DEBUG
15021 +#define test_ret(flag) \
15023 + if (mask & flag) \
15026 + test_ret(FS_ACCESS);
15027 + test_ret(FS_MODIFY);
15028 + test_ret(FS_ATTRIB);
15029 + test_ret(FS_CLOSE_WRITE);
15030 + test_ret(FS_CLOSE_NOWRITE);
15031 + test_ret(FS_OPEN);
15032 + test_ret(FS_MOVED_FROM);
15033 + test_ret(FS_MOVED_TO);
15034 + test_ret(FS_CREATE);
15035 + test_ret(FS_DELETE);
15036 + test_ret(FS_DELETE_SELF);
15037 + test_ret(FS_MOVE_SELF);
15038 + test_ret(FS_UNMOUNT);
15039 + test_ret(FS_Q_OVERFLOW);
15040 + test_ret(FS_IN_IGNORED);
15041 + test_ret(FS_ISDIR);
15042 + test_ret(FS_IN_ONESHOT);
15043 + test_ret(FS_EVENT_ON_CHILD);
15052 +/* ---------------------------------------------------------------------- */
15054 +static void au_hfsn_free_group(struct fsnotify_group *group)
15056 + struct au_br_hfsnotify *hfsn = group->private;
15058 + /* AuDbg("here\n"); */
15062 +static int au_hfsn_handle_event(struct fsnotify_group *group,
15063 + struct inode *inode,
15064 + struct fsnotify_mark *inode_mark,
15065 + struct fsnotify_mark *vfsmount_mark,
15066 + u32 mask, const void *data, int data_type,
15067 + const unsigned char *file_name, u32 cookie,
15068 + struct fsnotify_iter_info *iter_info)
15071 + struct au_hnotify *hnotify;
15072 + struct inode *h_dir, *h_inode;
15073 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
15075 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
15078 + /* if FS_UNMOUNT happens, there must be another bug */
15079 + AuDebugOn(mask & FS_UNMOUNT);
15080 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
15085 +#ifdef AuDbgHnotify
15087 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
15088 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
15089 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
15090 + h_dir->i_ino, mask, au_hfsn_name(mask),
15091 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
15092 + /* WARN_ON(1); */
15097 + AuDebugOn(!inode_mark);
15098 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
15099 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
15105 +static struct fsnotify_ops au_hfsn_ops = {
15106 + .handle_event = au_hfsn_handle_event,
15107 + .free_group_priv = au_hfsn_free_group,
15108 + .free_mark = au_hfsn_free_mark
15111 +/* ---------------------------------------------------------------------- */
15113 +static void au_hfsn_fin_br(struct au_branch *br)
15115 + struct au_br_hfsnotify *hfsn;
15117 + hfsn = br->br_hfsn;
15120 + fsnotify_put_group(hfsn->hfsn_group);
15125 +static int au_hfsn_init_br(struct au_branch *br, int perm)
15128 + struct fsnotify_group *group;
15129 + struct au_br_hfsnotify *hfsn;
15132 + br->br_hfsn = NULL;
15133 + if (!au_br_hnotifyable(perm))
15137 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
15138 + if (unlikely(!hfsn))
15142 + group = fsnotify_alloc_group(&au_hfsn_ops);
15143 + if (IS_ERR(group)) {
15144 + err = PTR_ERR(group);
15145 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
15149 + group->private = hfsn;
15150 + hfsn->hfsn_group = group;
15151 + br->br_hfsn = hfsn;
15152 + goto out; /* success */
15160 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
15165 + if (!br->br_hfsn)
15166 + err = au_hfsn_init_br(br, perm);
15171 +/* ---------------------------------------------------------------------- */
15173 +static void au_hfsn_fin(void)
15175 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
15176 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
15179 +const struct au_hnotify_op au_hnotify_op = {
15180 + .ctl = au_hfsn_ctl,
15181 + .alloc = au_hfsn_alloc,
15182 + .free = au_hfsn_free,
15184 + .fin = au_hfsn_fin,
15186 + .reset_br = au_hfsn_reset_br,
15187 + .fin_br = au_hfsn_fin_br,
15188 + .init_br = au_hfsn_init_br
15190 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15191 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15192 +++ linux/fs/aufs/hfsplus.c 2017-07-29 12:14:25.903042072 +0200
15195 + * Copyright (C) 2010-2017 Junjiro R. Okajima
15197 + * This program, aufs is free software; you can redistribute it and/or modify
15198 + * it under the terms of the GNU General Public License as published by
15199 + * the Free Software Foundation; either version 2 of the License, or
15200 + * (at your option) any later version.
15202 + * This program is distributed in the hope that it will be useful,
15203 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15204 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15205 + * GNU General Public License for more details.
15207 + * You should have received a copy of the GNU General Public License
15208 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15212 + * special support for filesystems which aqucires an inode mutex
15213 + * at final closing a file, eg, hfsplus.
15215 + * This trick is very simple and stupid, just to open the file before really
15216 + * neceeary open to tell hfsplus that this is not the final closing.
15217 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15218 + * and au_h_open_post() after releasing it.
15223 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15226 + struct file *h_file;
15227 + struct dentry *h_dentry;
15229 + h_dentry = au_h_dptr(dentry, bindex);
15230 + AuDebugOn(!h_dentry);
15231 + AuDebugOn(d_is_negative(h_dentry));
15234 + if (au_test_hfsplus(h_dentry->d_sb)
15235 + && d_is_reg(h_dentry))
15236 + h_file = au_h_open(dentry, bindex,
15237 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15238 + /*file*/NULL, force_wr);
15242 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15243 + struct file *h_file)
15247 + au_sbr_put(dentry->d_sb, bindex);
15250 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15251 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15252 +++ linux/fs/aufs/hnotify.c 2017-09-05 10:42:11.058755349 +0200
15255 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15257 + * This program, aufs is free software; you can redistribute it and/or modify
15258 + * it under the terms of the GNU General Public License as published by
15259 + * the Free Software Foundation; either version 2 of the License, or
15260 + * (at your option) any later version.
15262 + * This program is distributed in the hope that it will be useful,
15263 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15264 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15265 + * GNU General Public License for more details.
15267 + * You should have received a copy of the GNU General Public License
15268 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15272 + * abstraction to notify the direct changes on lower directories
15277 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15280 + struct au_hnotify *hn;
15283 + hn = au_cache_alloc_hnotify();
15285 + hn->hn_aufs_inode = inode;
15286 + hinode->hi_notify = hn;
15287 + err = au_hnotify_op.alloc(hinode);
15289 + if (unlikely(err)) {
15290 + hinode->hi_notify = NULL;
15291 + au_cache_free_hnotify(hn);
15293 + * The upper dir was removed by udba, but the same named
15294 + * dir left. In this case, aufs assignes a new inode
15295 + * number and set the monitor again.
15296 + * For the lower dir, the old monitnor is still left.
15298 + if (err == -EEXIST)
15307 +void au_hn_free(struct au_hinode *hinode)
15309 + struct au_hnotify *hn;
15311 + hn = hinode->hi_notify;
15313 + hinode->hi_notify = NULL;
15314 + if (au_hnotify_op.free(hinode, hn))
15315 + au_cache_free_hnotify(hn);
15319 +/* ---------------------------------------------------------------------- */
15321 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15323 + if (hinode->hi_notify)
15324 + au_hnotify_op.ctl(hinode, do_set);
15327 +void au_hn_reset(struct inode *inode, unsigned int flags)
15329 + aufs_bindex_t bindex, bbot;
15330 + struct inode *hi;
15331 + struct dentry *iwhdentry;
15333 + bbot = au_ibbot(inode);
15334 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15335 + hi = au_h_iptr(inode, bindex);
15339 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15340 + iwhdentry = au_hi_wh(inode, bindex);
15344 + au_set_h_iptr(inode, bindex, NULL, 0);
15345 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15346 + flags & ~AuHi_XINO);
15349 + /* inode_unlock(hi); */
15353 +/* ---------------------------------------------------------------------- */
15355 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15358 + aufs_bindex_t bindex, bbot, bfound, btop;
15359 + struct inode *h_i;
15362 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15363 + pr_warn("branch root dir was changed\n");
15368 + bbot = au_ibbot(inode);
15369 + btop = au_ibtop(inode);
15370 +#if 0 /* reserved for future use */
15371 + if (bindex == bbot) {
15372 + /* keep this ino in rename case */
15376 + for (bindex = btop; bindex <= bbot; bindex++)
15377 + if (au_h_iptr(inode, bindex) == h_inode) {
15384 + for (bindex = btop; bindex <= bbot; bindex++) {
15385 + h_i = au_h_iptr(inode, bindex);
15389 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15390 + /* ignore this error */
15391 + /* bad action? */
15394 + /* children inode number will be broken */
15401 +static int hn_gen_tree(struct dentry *dentry)
15403 + int err, i, j, ndentry;
15404 + struct au_dcsub_pages dpages;
15405 + struct au_dpage *dpage;
15406 + struct dentry **dentries;
15408 + err = au_dpages_init(&dpages, GFP_NOFS);
15409 + if (unlikely(err))
15411 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15412 + if (unlikely(err))
15415 + for (i = 0; i < dpages.ndpage; i++) {
15416 + dpage = dpages.dpages + i;
15417 + dentries = dpage->dentries;
15418 + ndentry = dpage->ndentry;
15419 + for (j = 0; j < ndentry; j++) {
15420 + struct dentry *d;
15427 + if (d_really_is_positive(d))
15428 + /* todo: reset children xino?
15429 + cached children only? */
15430 + au_iigen_dec(d_inode(d));
15435 + au_dpages_free(&dpages);
15438 + /* discard children */
15439 + dentry_unhash(dentry);
15447 + * return 0 if processed.
15449 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15450 + const unsigned int isdir)
15453 + struct dentry *d;
15454 + struct qstr *dname;
15457 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15458 + pr_warn("branch root dir was changed\n");
15464 + AuDebugOn(!name);
15465 + au_iigen_dec(inode);
15466 + spin_lock(&inode->i_lock);
15467 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15468 + spin_lock(&d->d_lock);
15469 + dname = &d->d_name;
15470 + if (dname->len != nlen
15471 + && memcmp(dname->name, name, nlen)) {
15472 + spin_unlock(&d->d_lock);
15477 + spin_unlock(&d->d_lock);
15480 + spin_unlock(&inode->i_lock);
15482 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15483 + d = d_find_any_alias(inode);
15485 + au_iigen_dec(inode);
15489 + spin_lock(&d->d_lock);
15490 + dname = &d->d_name;
15491 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15492 + spin_unlock(&d->d_lock);
15493 + err = hn_gen_tree(d);
15494 + spin_lock(&d->d_lock);
15496 + spin_unlock(&d->d_lock);
15505 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15509 + if (IS_ROOT(dentry)) {
15510 + pr_warn("branch root dir was changed\n");
15516 + au_digen_dec(dentry);
15517 + if (d_really_is_positive(dentry))
15518 + au_iigen_dec(d_inode(dentry));
15520 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15521 + if (d_really_is_positive(dentry))
15522 + err = hn_gen_tree(dentry);
15529 +/* ---------------------------------------------------------------------- */
15531 +/* hnotify job flags */
15532 +#define AuHnJob_XINO0 1
15533 +#define AuHnJob_GEN (1 << 1)
15534 +#define AuHnJob_DIRENT (1 << 2)
15535 +#define AuHnJob_ISDIR (1 << 3)
15536 +#define AuHnJob_TRYXINO0 (1 << 4)
15537 +#define AuHnJob_MNTPNT (1 << 5)
15538 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15539 +#define au_fset_hnjob(flags, name) \
15540 + do { (flags) |= AuHnJob_##name; } while (0)
15541 +#define au_fclr_hnjob(flags, name) \
15542 + do { (flags) &= ~AuHnJob_##name; } while (0)
15550 +struct au_hnotify_args {
15551 + struct inode *h_dir, *dir, *h_child_inode;
15553 + unsigned int flags[AuHnLast];
15554 + unsigned int h_child_nlen;
15555 + char h_child_name[];
15558 +struct hn_job_args {
15559 + unsigned int flags;
15560 + struct inode *inode, *h_inode, *dir, *h_dir;
15561 + struct dentry *dentry;
15566 +static int hn_job(struct hn_job_args *a)
15568 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15572 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15573 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15575 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15578 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
15579 + if (!a->h_inode->i_nlink
15580 + && !(a->h_inode->i_state & I_LINKABLE))
15581 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15582 + inode_unlock_shared(a->h_inode);
15585 + /* make the generation obsolete */
15586 + if (au_ftest_hnjob(a->flags, GEN)) {
15589 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15591 + if (e && a->dentry)
15592 + hn_gen_by_name(a->dentry, isdir);
15593 + /* ignore this error */
15596 + /* make dir entries obsolete */
15597 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15598 + struct au_vdir *vdir;
15600 + vdir = au_ivdir(a->inode);
15602 + vdir->vd_jiffy = 0;
15603 + /* IMustLock(a->inode); */
15604 + /* a->inode->i_version++; */
15607 + /* can do nothing but warn */
15608 + if (au_ftest_hnjob(a->flags, MNTPNT)
15610 + && d_mountpoint(a->dentry))
15611 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15616 +/* ---------------------------------------------------------------------- */
15618 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15619 + struct inode *dir)
15621 + struct dentry *dentry, *d, *parent;
15622 + struct qstr *dname;
15624 + parent = d_find_any_alias(dir);
15629 + spin_lock(&parent->d_lock);
15630 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15631 + /* AuDbg("%pd\n", d); */
15632 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15633 + dname = &d->d_name;
15634 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15635 + goto cont_unlock;
15639 + goto cont_unlock;
15640 + if (au_dcount(d) > 0) {
15641 + dentry = dget_dlock(d);
15642 + spin_unlock(&d->d_lock);
15647 + spin_unlock(&d->d_lock);
15649 + spin_unlock(&parent->d_lock);
15653 + di_write_lock_child(dentry);
15658 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15659 + aufs_bindex_t bindex, ino_t h_ino)
15661 + struct inode *inode;
15666 + err = au_xino_read(sb, bindex, h_ino, &ino);
15668 + inode = ilookup(sb, ino);
15672 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15673 + pr_warn("wrong root branch\n");
15679 + ii_write_lock_child(inode);
15685 +static void au_hn_bh(void *_args)
15687 + struct au_hnotify_args *a = _args;
15688 + struct super_block *sb;
15689 + aufs_bindex_t bindex, bbot, bfound;
15690 + unsigned char xino, try_iput;
15692 + struct inode *inode;
15694 + struct hn_job_args args;
15695 + struct dentry *dentry;
15696 + struct au_sbinfo *sbinfo;
15698 + AuDebugOn(!_args);
15699 + AuDebugOn(!a->h_dir);
15700 + AuDebugOn(!a->dir);
15701 + AuDebugOn(!a->mask);
15702 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15703 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15704 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15709 + * do not lock a->dir->i_mutex here
15710 + * because of d_revalidate() may cause a deadlock.
15712 + sb = a->dir->i_sb;
15714 + sbinfo = au_sbi(sb);
15715 + AuDebugOn(!sbinfo);
15716 + si_write_lock(sb, AuLock_NOPLMW);
15718 + ii_read_lock_parent(a->dir);
15720 + bbot = au_ibbot(a->dir);
15721 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15722 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15726 + ii_read_unlock(a->dir);
15727 + if (unlikely(bfound < 0))
15730 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15732 + if (a->h_child_inode)
15733 + h_ino = a->h_child_inode->i_ino;
15735 + if (a->h_child_nlen
15736 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15737 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15738 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15741 + if (dentry && d_really_is_positive(dentry))
15742 + inode = d_inode(dentry);
15743 + if (xino && !inode && h_ino
15744 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15745 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15746 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15747 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15751 + args.flags = a->flags[AuHn_CHILD];
15752 + args.dentry = dentry;
15753 + args.inode = inode;
15754 + args.h_inode = a->h_child_inode;
15755 + args.dir = a->dir;
15756 + args.h_dir = a->h_dir;
15757 + args.h_name = a->h_child_name;
15758 + args.h_nlen = a->h_child_nlen;
15759 + err = hn_job(&args);
15761 + if (au_di(dentry))
15762 + di_write_unlock(dentry);
15765 + if (inode && try_iput) {
15766 + ii_write_unlock(inode);
15770 + ii_write_lock_parent(a->dir);
15771 + args.flags = a->flags[AuHn_PARENT];
15772 + args.dentry = NULL;
15773 + args.inode = a->dir;
15774 + args.h_inode = a->h_dir;
15776 + args.h_dir = NULL;
15777 + args.h_name = NULL;
15779 + err = hn_job(&args);
15780 + ii_write_unlock(a->dir);
15783 + iput(a->h_child_inode);
15786 + si_write_unlock(sb);
15787 + au_nwt_done(&sbinfo->si_nowait);
15791 +/* ---------------------------------------------------------------------- */
15793 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15794 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15797 + unsigned int flags[AuHnLast], f;
15798 + unsigned char isdir, isroot, wh;
15799 + struct inode *dir;
15800 + struct au_hnotify_args *args;
15801 + char *p, *h_child_name;
15804 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15805 + dir = igrab(hnotify->hn_aufs_inode);
15809 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15811 + h_child_name = (void *)h_child_qstr->name;
15812 + len = h_child_qstr->len;
15813 + if (h_child_name) {
15814 + if (len > AUFS_WH_PFX_LEN
15815 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15816 + h_child_name += AUFS_WH_PFX_LEN;
15817 + len -= AUFS_WH_PFX_LEN;
15823 + if (h_child_inode)
15824 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15825 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15826 + flags[AuHn_CHILD] = 0;
15828 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15829 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15830 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15831 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15832 + case FS_MOVED_FROM:
15833 + case FS_MOVED_TO:
15834 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15835 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15838 + AuDebugOn(!h_child_name);
15843 + * aufs never be able to get this child inode.
15844 + * revalidation should be in d_revalidate()
15845 + * by checking i_nlink, i_generation or d_unhashed().
15847 + AuDebugOn(!h_child_name);
15848 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15849 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15857 + h_child_inode = NULL;
15860 + /* iput() and kfree() will be called in au_hnotify() */
15861 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15862 + if (unlikely(!args)) {
15863 + AuErr1("no memory\n");
15867 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15868 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15869 + args->mask = mask;
15871 + args->h_dir = igrab(h_dir);
15872 + if (h_child_inode)
15873 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15874 + args->h_child_inode = h_child_inode;
15875 + args->h_child_nlen = len;
15877 + p = (void *)args;
15878 + p += sizeof(*args);
15879 + memcpy(p, h_child_name, len);
15883 + /* NFS fires the event for silly-renamed one from kworker */
15885 + if (!dir->i_nlink
15886 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15888 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15889 + if (unlikely(err)) {
15890 + pr_err("wkq %d\n", err);
15891 + iput(args->h_child_inode);
15892 + iput(args->h_dir);
15901 +/* ---------------------------------------------------------------------- */
15903 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15907 + AuDebugOn(!(udba & AuOptMask_UDBA));
15910 + if (au_hnotify_op.reset_br)
15911 + err = au_hnotify_op.reset_br(udba, br, perm);
15916 +int au_hnotify_init_br(struct au_branch *br, int perm)
15921 + if (au_hnotify_op.init_br)
15922 + err = au_hnotify_op.init_br(br, perm);
15927 +void au_hnotify_fin_br(struct au_branch *br)
15929 + if (au_hnotify_op.fin_br)
15930 + au_hnotify_op.fin_br(br);
15933 +static void au_hn_destroy_cache(void)
15935 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
15936 + au_cache[AuCache_HNOTIFY] = NULL;
15939 +int __init au_hnotify_init(void)
15944 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
15945 + if (au_cache[AuCache_HNOTIFY]) {
15947 + if (au_hnotify_op.init)
15948 + err = au_hnotify_op.init();
15949 + if (unlikely(err))
15950 + au_hn_destroy_cache();
15956 +void au_hnotify_fin(void)
15958 + if (au_hnotify_op.fin)
15959 + au_hnotify_op.fin();
15961 + /* cf. au_cache_fin() */
15962 + if (au_cache[AuCache_HNOTIFY])
15963 + au_hn_destroy_cache();
15965 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15966 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15967 +++ linux/fs/aufs/iinfo.c 2017-07-29 12:14:25.903042072 +0200
15970 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15972 + * This program, aufs is free software; you can redistribute it and/or modify
15973 + * it under the terms of the GNU General Public License as published by
15974 + * the Free Software Foundation; either version 2 of the License, or
15975 + * (at your option) any later version.
15977 + * This program is distributed in the hope that it will be useful,
15978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15980 + * GNU General Public License for more details.
15982 + * You should have received a copy of the GNU General Public License
15983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15987 + * inode private data
15992 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15994 + struct inode *h_inode;
15995 + struct au_hinode *hinode;
15997 + IiMustAnyLock(inode);
15999 + hinode = au_hinode(au_ii(inode), bindex);
16000 + h_inode = hinode->hi_inode;
16001 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16005 +/* todo: hard/soft set? */
16006 +void au_hiput(struct au_hinode *hinode)
16008 + au_hn_free(hinode);
16009 + dput(hinode->hi_whdentry);
16010 + iput(hinode->hi_inode);
16013 +unsigned int au_hi_flags(struct inode *inode, int isdir)
16015 + unsigned int flags;
16016 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
16019 + if (au_opt_test(mnt_flags, XINO))
16020 + au_fset_hi(flags, XINO);
16021 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
16022 + au_fset_hi(flags, HNOTIFY);
16026 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16027 + struct inode *h_inode, unsigned int flags)
16029 + struct au_hinode *hinode;
16030 + struct inode *hi;
16031 + struct au_iinfo *iinfo = au_ii(inode);
16033 + IiMustWriteLock(inode);
16035 + hinode = au_hinode(iinfo, bindex);
16036 + hi = hinode->hi_inode;
16037 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16040 + au_hiput(hinode);
16041 + hinode->hi_inode = h_inode;
16044 + struct super_block *sb = inode->i_sb;
16045 + struct au_branch *br;
16047 + AuDebugOn(inode->i_mode
16048 + && (h_inode->i_mode & S_IFMT)
16049 + != (inode->i_mode & S_IFMT));
16050 + if (bindex == iinfo->ii_btop)
16051 + au_cpup_igen(inode, h_inode);
16052 + br = au_sbr(sb, bindex);
16053 + hinode->hi_id = br->br_id;
16054 + if (au_ftest_hi(flags, XINO)) {
16055 + err = au_xino_write(sb, bindex, h_inode->i_ino,
16057 + if (unlikely(err))
16058 + AuIOErr1("failed au_xino_write() %d\n", err);
16061 + if (au_ftest_hi(flags, HNOTIFY)
16062 + && au_br_hnotifyable(br->br_perm)) {
16063 + err = au_hn_alloc(hinode, inode);
16064 + if (unlikely(err))
16065 + AuIOErr1("au_hn_alloc() %d\n", err);
16070 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16071 + struct dentry *h_wh)
16073 + struct au_hinode *hinode;
16075 + IiMustWriteLock(inode);
16077 + hinode = au_hinode(au_ii(inode), bindex);
16078 + AuDebugOn(hinode->hi_whdentry);
16079 + hinode->hi_whdentry = h_wh;
16082 +void au_update_iigen(struct inode *inode, int half)
16084 + struct au_iinfo *iinfo;
16085 + struct au_iigen *iigen;
16086 + unsigned int sigen;
16088 + sigen = au_sigen(inode->i_sb);
16089 + iinfo = au_ii(inode);
16090 + iigen = &iinfo->ii_generation;
16091 + spin_lock(&iigen->ig_spin);
16092 + iigen->ig_generation = sigen;
16094 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
16096 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
16097 + spin_unlock(&iigen->ig_spin);
16100 +/* it may be called at remount time, too */
16101 +void au_update_ibrange(struct inode *inode, int do_put_zero)
16103 + struct au_iinfo *iinfo;
16104 + aufs_bindex_t bindex, bbot;
16106 + AuDebugOn(au_is_bad_inode(inode));
16107 + IiMustWriteLock(inode);
16109 + iinfo = au_ii(inode);
16110 + if (do_put_zero && iinfo->ii_btop >= 0) {
16111 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16113 + struct inode *h_i;
16115 + h_i = au_hinode(iinfo, bindex)->hi_inode;
16118 + && !(h_i->i_state & I_LINKABLE))
16119 + au_set_h_iptr(inode, bindex, NULL, 0);
16123 + iinfo->ii_btop = -1;
16124 + iinfo->ii_bbot = -1;
16125 + bbot = au_sbbot(inode->i_sb);
16126 + for (bindex = 0; bindex <= bbot; bindex++)
16127 + if (au_hinode(iinfo, bindex)->hi_inode) {
16128 + iinfo->ii_btop = bindex;
16131 + if (iinfo->ii_btop >= 0)
16132 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
16133 + if (au_hinode(iinfo, bindex)->hi_inode) {
16134 + iinfo->ii_bbot = bindex;
16137 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
16140 +/* ---------------------------------------------------------------------- */
16142 +void au_icntnr_init_once(void *_c)
16144 + struct au_icntnr *c = _c;
16145 + struct au_iinfo *iinfo = &c->iinfo;
16147 + spin_lock_init(&iinfo->ii_generation.ig_spin);
16148 + au_rw_init(&iinfo->ii_rwsem);
16149 + inode_init_once(&c->vfs_inode);
16152 +void au_hinode_init(struct au_hinode *hinode)
16154 + hinode->hi_inode = NULL;
16155 + hinode->hi_id = -1;
16156 + au_hn_init(hinode);
16157 + hinode->hi_whdentry = NULL;
16160 +int au_iinfo_init(struct inode *inode)
16162 + struct au_iinfo *iinfo;
16163 + struct super_block *sb;
16164 + struct au_hinode *hi;
16167 + sb = inode->i_sb;
16168 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16169 + nbr = au_sbbot(sb) + 1;
16170 + if (unlikely(nbr <= 0))
16172 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
16174 + au_ninodes_inc(sb);
16176 + iinfo->ii_hinode = hi;
16177 + for (i = 0; i < nbr; i++, hi++)
16178 + au_hinode_init(hi);
16180 + iinfo->ii_generation.ig_generation = au_sigen(sb);
16181 + iinfo->ii_btop = -1;
16182 + iinfo->ii_bbot = -1;
16183 + iinfo->ii_vdir = NULL;
16189 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16192 + struct au_hinode *hip;
16194 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16197 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16200 + iinfo->ii_hinode = hip;
16201 + i = iinfo->ii_bbot + 1;
16203 + for (; i < nbr; i++, hip++)
16204 + au_hinode_init(hip);
16211 +void au_iinfo_fin(struct inode *inode)
16213 + struct au_iinfo *iinfo;
16214 + struct au_hinode *hi;
16215 + struct super_block *sb;
16216 + aufs_bindex_t bindex, bbot;
16217 + const unsigned char unlinked = !inode->i_nlink;
16219 + AuDebugOn(au_is_bad_inode(inode));
16221 + sb = inode->i_sb;
16222 + au_ninodes_dec(sb);
16223 + if (si_pid_test(sb))
16224 + au_xino_delete_inode(inode, unlinked);
16227 + * it is safe to hide the dependency between sbinfo and
16231 + si_noflush_read_lock(sb);
16232 + au_xino_delete_inode(inode, unlinked);
16233 + si_read_unlock(sb);
16237 + iinfo = au_ii(inode);
16238 + if (iinfo->ii_vdir)
16239 + au_vdir_free(iinfo->ii_vdir);
16241 + bindex = iinfo->ii_btop;
16242 + if (bindex >= 0) {
16243 + hi = au_hinode(iinfo, bindex);
16244 + bbot = iinfo->ii_bbot;
16245 + while (bindex++ <= bbot) {
16246 + if (hi->hi_inode)
16251 + kfree(iinfo->ii_hinode);
16252 + AuRwDestroy(&iinfo->ii_rwsem);
16254 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16255 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16256 +++ linux/fs/aufs/inode.c 2017-07-29 12:14:25.903042072 +0200
16259 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16261 + * This program, aufs is free software; you can redistribute it and/or modify
16262 + * it under the terms of the GNU General Public License as published by
16263 + * the Free Software Foundation; either version 2 of the License, or
16264 + * (at your option) any later version.
16266 + * This program is distributed in the hope that it will be useful,
16267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16269 + * GNU General Public License for more details.
16271 + * You should have received a copy of the GNU General Public License
16272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16276 + * inode functions
16281 +struct inode *au_igrab(struct inode *inode)
16284 + AuDebugOn(!atomic_read(&inode->i_count));
16290 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16292 + au_cpup_attr_all(inode, /*force*/0);
16293 + au_update_iigen(inode, /*half*/1);
16295 + inode->i_version++;
16298 +static int au_ii_refresh(struct inode *inode, int *update)
16302 + aufs_bindex_t bindex, new_bindex;
16303 + struct super_block *sb;
16304 + struct au_iinfo *iinfo;
16305 + struct au_hinode *p, *q, tmp;
16307 + AuDebugOn(au_is_bad_inode(inode));
16308 + IiMustWriteLock(inode);
16311 + sb = inode->i_sb;
16312 + nbr = au_sbbot(sb) + 1;
16313 + type = inode->i_mode & S_IFMT;
16314 + iinfo = au_ii(inode);
16315 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16316 + if (unlikely(err))
16319 + AuDebugOn(iinfo->ii_btop < 0);
16320 + p = au_hinode(iinfo, iinfo->ii_btop);
16321 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16323 + if (!p->hi_inode)
16326 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16327 + new_bindex = au_br_index(sb, p->hi_id);
16328 + if (new_bindex == bindex)
16331 + if (new_bindex < 0) {
16334 + p->hi_inode = NULL;
16338 + if (new_bindex < iinfo->ii_btop)
16339 + iinfo->ii_btop = new_bindex;
16340 + if (iinfo->ii_bbot < new_bindex)
16341 + iinfo->ii_bbot = new_bindex;
16342 + /* swap two lower inode, and loop again */
16343 + q = au_hinode(iinfo, new_bindex);
16347 + if (tmp.hi_inode) {
16352 + au_update_ibrange(inode, /*do_put_zero*/0);
16353 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16354 + e = au_dy_irefresh(inode);
16355 + if (unlikely(e && !err))
16363 +void au_refresh_iop(struct inode *inode, int force_getattr)
16366 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16367 + const struct inode_operations *iop
16368 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16370 + if (inode->i_op == iop)
16373 + switch (inode->i_mode & S_IFMT) {
16375 + type = AuIop_DIR;
16378 + type = AuIop_SYMLINK;
16381 + type = AuIop_OTHER;
16385 + inode->i_op = iop + type;
16386 + /* unnecessary smp_wmb() */
16389 +int au_refresh_hinode_self(struct inode *inode)
16393 + err = au_ii_refresh(inode, &update);
16395 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16401 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16403 + int err, e, update;
16404 + unsigned int flags;
16406 + aufs_bindex_t bindex, bbot;
16407 + unsigned char isdir;
16408 + struct au_hinode *p;
16409 + struct au_iinfo *iinfo;
16411 + err = au_ii_refresh(inode, &update);
16412 + if (unlikely(err))
16416 + iinfo = au_ii(inode);
16417 + p = au_hinode(iinfo, iinfo->ii_btop);
16418 + mode = (inode->i_mode & S_IFMT);
16419 + isdir = S_ISDIR(mode);
16420 + flags = au_hi_flags(inode, isdir);
16421 + bbot = au_dbbot(dentry);
16422 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16423 + struct inode *h_i, *h_inode;
16424 + struct dentry *h_d;
16426 + h_d = au_h_dptr(dentry, bindex);
16427 + if (!h_d || d_is_negative(h_d))
16430 + h_inode = d_inode(h_d);
16431 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16432 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16433 + h_i = au_h_iptr(inode, bindex);
16435 + if (h_i == h_inode)
16441 + if (bindex < iinfo->ii_btop)
16442 + iinfo->ii_btop = bindex;
16443 + if (iinfo->ii_bbot < bindex)
16444 + iinfo->ii_bbot = bindex;
16445 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16448 + au_update_ibrange(inode, /*do_put_zero*/0);
16449 + e = au_dy_irefresh(inode);
16450 + if (unlikely(e && !err))
16453 + au_refresh_hinode_attr(inode, update && isdir);
16460 +static int set_inode(struct inode *inode, struct dentry *dentry)
16463 + unsigned int flags;
16465 + aufs_bindex_t bindex, btop, btail;
16466 + unsigned char isdir;
16467 + struct dentry *h_dentry;
16468 + struct inode *h_inode;
16469 + struct au_iinfo *iinfo;
16470 + struct inode_operations *iop;
16472 + IiMustWriteLock(inode);
16476 + iop = au_sbi(inode->i_sb)->si_iop_array;
16477 + btop = au_dbtop(dentry);
16478 + h_dentry = au_h_dptr(dentry, btop);
16479 + h_inode = d_inode(h_dentry);
16480 + mode = h_inode->i_mode;
16481 + switch (mode & S_IFMT) {
16483 + btail = au_dbtail(dentry);
16484 + inode->i_op = iop + AuIop_OTHER;
16485 + inode->i_fop = &aufs_file_fop;
16486 + err = au_dy_iaop(inode, btop, h_inode);
16487 + if (unlikely(err))
16492 + btail = au_dbtaildir(dentry);
16493 + inode->i_op = iop + AuIop_DIR;
16494 + inode->i_fop = &aufs_dir_fop;
16497 + btail = au_dbtail(dentry);
16498 + inode->i_op = iop + AuIop_SYMLINK;
16504 + btail = au_dbtail(dentry);
16505 + inode->i_op = iop + AuIop_OTHER;
16506 + init_special_inode(inode, mode, h_inode->i_rdev);
16509 + AuIOErr("Unknown file type 0%o\n", mode);
16514 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16515 + flags = au_hi_flags(inode, isdir);
16516 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16517 + && au_ftest_hi(flags, HNOTIFY)
16518 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16519 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16520 + au_fclr_hi(flags, HNOTIFY);
16521 + iinfo = au_ii(inode);
16522 + iinfo->ii_btop = btop;
16523 + iinfo->ii_bbot = btail;
16524 + for (bindex = btop; bindex <= btail; bindex++) {
16525 + h_dentry = au_h_dptr(dentry, bindex);
16527 + au_set_h_iptr(inode, bindex,
16528 + au_igrab(d_inode(h_dentry)), flags);
16530 + au_cpup_attr_all(inode, /*force*/1);
16532 + * to force calling aufs_get_acl() every time,
16533 + * do not call cache_no_acl() for aufs inode.
16541 + * successful returns with iinfo write_locked
16543 + * zero: success, matched
16544 + * plus: no error, but unmatched
16546 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16549 + unsigned int gen, igflags;
16550 + aufs_bindex_t bindex, bbot;
16551 + struct inode *h_inode, *h_dinode;
16552 + struct dentry *h_dentry;
16555 + * before this function, if aufs got any iinfo lock, it must be only
16556 + * one, the parent dir.
16557 + * it can happen by UDBA and the obsoleted inode number.
16560 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16564 + ii_write_lock_new_child(inode);
16565 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16566 + h_dinode = d_inode(h_dentry);
16567 + bbot = au_ibbot(inode);
16568 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16569 + h_inode = au_h_iptr(inode, bindex);
16570 + if (!h_inode || h_inode != h_dinode)
16574 + gen = au_iigen(inode, &igflags);
16575 + if (gen == au_digen(dentry)
16576 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16579 + /* fully refresh inode using dentry */
16580 + err = au_refresh_hinode(inode, dentry);
16582 + au_update_iigen(inode, /*half*/0);
16586 + if (unlikely(err))
16587 + ii_write_unlock(inode);
16592 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16593 + unsigned int d_type, ino_t *ino)
16596 + const int isnondir = d_type != DT_DIR;
16598 + /* prevent hardlinked inode number from race condition */
16600 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
16601 + if (unlikely(err))
16605 + err = au_xino_read(sb, bindex, h_ino, ino);
16606 + if (unlikely(err))
16607 + goto out_xinondir;
16611 + *ino = au_xino_new_ino(sb);
16612 + if (unlikely(!*ino))
16613 + goto out_xinondir;
16614 + err = au_xino_write(sb, bindex, h_ino, *ino);
16615 + if (unlikely(err))
16616 + goto out_xinondir;
16620 + if (isnondir && idx >= 0)
16621 + au_xinondir_leave(sb, bindex, h_ino, idx);
16626 +/* successful returns with iinfo write_locked */
16627 +/* todo: return with unlocked? */
16628 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16630 + struct inode *inode, *h_inode;
16631 + struct dentry *h_dentry;
16632 + struct super_block *sb;
16633 + ino_t h_ino, ino;
16634 + int err, idx, hlinked;
16635 + aufs_bindex_t btop;
16637 + sb = dentry->d_sb;
16638 + btop = au_dbtop(dentry);
16639 + h_dentry = au_h_dptr(dentry, btop);
16640 + h_inode = d_inode(h_dentry);
16641 + h_ino = h_inode->i_ino;
16642 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
16646 + * stop 'race'-ing between hardlinks under different
16650 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16651 + inode = ERR_PTR(err);
16652 + if (unlikely(err))
16656 + err = au_xino_read(sb, btop, h_ino, &ino);
16657 + inode = ERR_PTR(err);
16658 + if (unlikely(err))
16659 + goto out_xinondir;
16662 + ino = au_xino_new_ino(sb);
16663 + if (unlikely(!ino)) {
16664 + inode = ERR_PTR(-EIO);
16665 + goto out_xinondir;
16669 + AuDbg("i%lu\n", (unsigned long)ino);
16670 + inode = au_iget_locked(sb, ino);
16671 + err = PTR_ERR(inode);
16672 + if (IS_ERR(inode))
16673 + goto out_xinondir;
16675 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16676 + if (inode->i_state & I_NEW) {
16677 + ii_write_lock_new_child(inode);
16678 + err = set_inode(inode, dentry);
16680 + unlock_new_inode(inode);
16681 + goto out_xinondir; /* success */
16685 + * iget_failed() calls iput(), but we need to call
16686 + * ii_write_unlock() after iget_failed(). so dirty hack for
16689 + atomic_inc(&inode->i_count);
16690 + iget_failed(inode);
16691 + ii_write_unlock(inode);
16692 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16693 + /* ignore this error */
16695 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16697 + * horrible race condition between lookup, readdir and copyup
16698 + * (or something).
16700 + if (hlinked && idx >= 0)
16701 + au_xinondir_leave(sb, btop, h_ino, idx);
16702 + err = reval_inode(inode, dentry);
16703 + if (unlikely(err < 0)) {
16708 + goto out; /* success */
16709 + else if (hlinked && idx >= 0) {
16710 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16711 + if (unlikely(err)) {
16713 + inode = ERR_PTR(err);
16719 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16720 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16721 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16722 + btop, au_sbtype(h_dentry->d_sb), dentry,
16723 + (unsigned long)h_ino, (unsigned long)ino);
16725 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16728 + if (hlinked && idx >= 0)
16729 + au_xinondir_leave(sb, btop, h_ino, idx);
16735 + inode = ERR_PTR(err);
16737 + if (hlinked && idx >= 0)
16738 + au_xinondir_leave(sb, btop, h_ino, idx);
16743 +/* ---------------------------------------------------------------------- */
16745 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16746 + struct inode *inode)
16749 + struct inode *hi;
16751 + err = au_br_rdonly(au_sbr(sb, bindex));
16753 + /* pseudo-link after flushed may happen out of bounds */
16756 + && au_ibtop(inode) <= bindex
16757 + && bindex <= au_ibbot(inode)) {
16759 + * permission check is unnecessary since vfsub routine
16760 + * will be called later
16762 + hi = au_h_iptr(inode, bindex);
16764 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16770 +int au_test_h_perm(struct inode *h_inode, int mask)
16772 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16774 + return inode_permission(h_inode, mask);
16777 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16779 + if (au_test_nfs(h_inode->i_sb)
16780 + && (mask & MAY_WRITE)
16781 + && S_ISDIR(h_inode->i_mode))
16782 + mask |= MAY_READ; /* force permission check */
16783 + return au_test_h_perm(h_inode, mask);
16785 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16786 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16787 +++ linux/fs/aufs/inode.h 2017-09-05 10:42:11.058755349 +0200
16790 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16792 + * This program, aufs is free software; you can redistribute it and/or modify
16793 + * it under the terms of the GNU General Public License as published by
16794 + * the Free Software Foundation; either version 2 of the License, or
16795 + * (at your option) any later version.
16797 + * This program is distributed in the hope that it will be useful,
16798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16800 + * GNU General Public License for more details.
16802 + * You should have received a copy of the GNU General Public License
16803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16807 + * inode operations
16810 +#ifndef __AUFS_INODE_H__
16811 +#define __AUFS_INODE_H__
16815 +#include <linux/fsnotify.h>
16816 +#include "rwsem.h"
16817 +#include "vfsub.h"
16821 +struct au_hnotify {
16822 +#ifdef CONFIG_AUFS_HNOTIFY
16823 +#ifdef CONFIG_AUFS_HFSNOTIFY
16824 + /* never use fsnotify_add_vfsmount_mark() */
16825 + struct fsnotify_mark hn_mark;
16827 + struct inode *hn_aufs_inode; /* no get/put */
16829 +} ____cacheline_aligned_in_smp;
16831 +struct au_hinode {
16832 + struct inode *hi_inode;
16833 + aufs_bindex_t hi_id;
16834 +#ifdef CONFIG_AUFS_HNOTIFY
16835 + struct au_hnotify *hi_notify;
16838 + /* reference to the copied-up whiteout with get/put */
16839 + struct dentry *hi_whdentry;
16843 +#define AuIG_HALF_REFRESHED 1
16844 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16845 +#define au_ig_fset(flags, name) \
16846 + do { (flags) |= AuIG_##name; } while (0)
16847 +#define au_ig_fclr(flags, name) \
16848 + do { (flags) &= ~AuIG_##name; } while (0)
16851 + spinlock_t ig_spin;
16852 + __u32 ig_generation, ig_flags;
16857 + struct au_iigen ii_generation;
16858 + struct super_block *ii_hsb1; /* no get/put */
16860 + struct au_rwsem ii_rwsem;
16861 + aufs_bindex_t ii_btop, ii_bbot;
16863 + struct au_hinode *ii_hinode;
16864 + struct au_vdir *ii_vdir;
16867 +struct au_icntnr {
16868 + struct au_iinfo iinfo;
16869 + struct inode vfs_inode;
16870 + struct hlist_node plink;
16871 +} ____cacheline_aligned_in_smp;
16873 +/* au_pin flags */
16874 +#define AuPin_DI_LOCKED 1
16875 +#define AuPin_MNT_WRITE (1 << 1)
16876 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16877 +#define au_fset_pin(flags, name) \
16878 + do { (flags) |= AuPin_##name; } while (0)
16879 +#define au_fclr_pin(flags, name) \
16880 + do { (flags) &= ~AuPin_##name; } while (0)
16884 + struct dentry *dentry;
16885 + unsigned int udba;
16886 + unsigned char lsc_di, lsc_hi, flags;
16887 + aufs_bindex_t bindex;
16890 + struct dentry *parent;
16891 + struct au_hinode *hdir;
16892 + struct vfsmount *h_mnt;
16894 + /* temporary unlock/relock for copyup */
16895 + struct dentry *h_dentry, *h_parent;
16896 + struct au_branch *br;
16897 + struct task_struct *task;
16900 +void au_pin_hdir_unlock(struct au_pin *p);
16901 +int au_pin_hdir_lock(struct au_pin *p);
16902 +int au_pin_hdir_relock(struct au_pin *p);
16903 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16904 +void au_pin_hdir_release(struct au_pin *p);
16906 +/* ---------------------------------------------------------------------- */
16908 +static inline struct au_iinfo *au_ii(struct inode *inode)
16910 + BUG_ON(is_bad_inode(inode));
16911 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16914 +/* ---------------------------------------------------------------------- */
16917 +struct inode *au_igrab(struct inode *inode);
16918 +void au_refresh_iop(struct inode *inode, int force_getattr);
16919 +int au_refresh_hinode_self(struct inode *inode);
16920 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16921 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16922 + unsigned int d_type, ino_t *ino);
16923 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16924 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16925 + struct inode *inode);
16926 +int au_test_h_perm(struct inode *h_inode, int mask);
16927 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16929 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16930 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16932 +#ifdef CONFIG_AUFS_SHWH
16933 + return au_ino(sb, bindex, h_ino, d_type, ino);
16946 +extern struct inode_operations aufs_iop[AuIop_Last],
16947 + aufs_iop_nogetattr[AuIop_Last];
16949 +/* au_wr_dir flags */
16950 +#define AuWrDir_ADD_ENTRY 1
16951 +#define AuWrDir_ISDIR (1 << 1)
16952 +#define AuWrDir_TMPFILE (1 << 2)
16953 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16954 +#define au_fset_wrdir(flags, name) \
16955 + do { (flags) |= AuWrDir_##name; } while (0)
16956 +#define au_fclr_wrdir(flags, name) \
16957 + do { (flags) &= ~AuWrDir_##name; } while (0)
16959 +struct au_wr_dir_args {
16960 + aufs_bindex_t force_btgt;
16961 + unsigned char flags;
16963 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16964 + struct au_wr_dir_args *args);
16966 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16967 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16968 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16969 + unsigned int udba, unsigned char flags);
16970 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16971 + unsigned int udba, unsigned char flags) __must_check;
16972 +int au_do_pin(struct au_pin *pin) __must_check;
16973 +void au_unpin(struct au_pin *pin);
16974 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16976 +#define AuIcpup_DID_CPUP 1
16977 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16978 +#define au_fset_icpup(flags, name) \
16979 + do { (flags) |= AuIcpup_##name; } while (0)
16980 +#define au_fclr_icpup(flags, name) \
16981 + do { (flags) &= ~AuIcpup_##name; } while (0)
16983 +struct au_icpup_args {
16984 + unsigned char flags;
16985 + unsigned char pin_flags;
16986 + aufs_bindex_t btgt;
16987 + unsigned int udba;
16988 + struct au_pin pin;
16989 + struct path h_path;
16990 + struct inode *h_inode;
16993 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16994 + struct au_icpup_args *a);
16996 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
17000 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17001 + struct dentry *h_parent, int isdir);
17002 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17004 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
17005 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17007 +struct vfsub_aopen_args;
17008 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17009 + struct vfsub_aopen_args *args);
17010 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
17011 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17012 + struct dentry *dentry);
17013 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
17016 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
17017 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17018 + struct dentry *h_parent, int isdir);
17019 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
17020 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
17023 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
17024 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
17025 + struct inode *dir, struct dentry *dentry,
17026 + unsigned int flags);
17029 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
17030 +void au_hiput(struct au_hinode *hinode);
17031 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17032 + struct dentry *h_wh);
17033 +unsigned int au_hi_flags(struct inode *inode, int isdir);
17035 +/* hinode flags */
17036 +#define AuHi_XINO 1
17037 +#define AuHi_HNOTIFY (1 << 1)
17038 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
17039 +#define au_fset_hi(flags, name) \
17040 + do { (flags) |= AuHi_##name; } while (0)
17041 +#define au_fclr_hi(flags, name) \
17042 + do { (flags) &= ~AuHi_##name; } while (0)
17044 +#ifndef CONFIG_AUFS_HNOTIFY
17045 +#undef AuHi_HNOTIFY
17046 +#define AuHi_HNOTIFY 0
17049 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17050 + struct inode *h_inode, unsigned int flags);
17052 +void au_update_iigen(struct inode *inode, int half);
17053 +void au_update_ibrange(struct inode *inode, int do_put_zero);
17055 +void au_icntnr_init_once(void *_c);
17056 +void au_hinode_init(struct au_hinode *hinode);
17057 +int au_iinfo_init(struct inode *inode);
17058 +void au_iinfo_fin(struct inode *inode);
17059 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
17061 +#ifdef CONFIG_PROC_FS
17063 +int au_plink_maint(struct super_block *sb, int flags);
17065 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
17066 +int au_plink_maint_enter(struct super_block *sb);
17067 +#ifdef CONFIG_AUFS_DEBUG
17068 +void au_plink_list(struct super_block *sb);
17070 +AuStubVoid(au_plink_list, struct super_block *sb)
17072 +int au_plink_test(struct inode *inode);
17073 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
17074 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
17075 + struct dentry *h_dentry);
17076 +void au_plink_put(struct super_block *sb, int verbose);
17077 +void au_plink_clean(struct super_block *sb, int verbose);
17078 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
17080 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
17081 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
17082 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
17083 +AuStubVoid(au_plink_list, struct super_block *sb);
17084 +AuStubInt0(au_plink_test, struct inode *inode);
17085 +AuStub(struct dentry *, au_plink_lkup, return NULL,
17086 + struct inode *inode, aufs_bindex_t bindex);
17087 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
17088 + struct dentry *h_dentry);
17089 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
17090 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
17091 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
17092 +#endif /* CONFIG_PROC_FS */
17094 +#ifdef CONFIG_AUFS_XATTR
17096 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
17097 + unsigned int verbose);
17098 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
17099 +void au_xattr_init(struct super_block *sb);
17101 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
17102 + int ignore_flags, unsigned int verbose);
17103 +AuStubVoid(au_xattr_init, struct super_block *sb);
17106 +#ifdef CONFIG_FS_POSIX_ACL
17107 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
17108 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
17111 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
17117 +struct au_sxattr {
17121 + const char *name;
17122 + const void *value;
17127 + struct posix_acl *acl;
17132 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
17133 + struct au_sxattr *arg);
17136 +/* ---------------------------------------------------------------------- */
17138 +/* lock subclass for iinfo */
17140 + AuLsc_II_CHILD, /* child first */
17141 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
17142 + AuLsc_II_CHILD3, /* copyup dirs */
17143 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
17144 + AuLsc_II_PARENT2,
17145 + AuLsc_II_PARENT3, /* copyup dirs */
17146 + AuLsc_II_NEW_CHILD
17150 + * ii_read_lock_child, ii_write_lock_child,
17151 + * ii_read_lock_child2, ii_write_lock_child2,
17152 + * ii_read_lock_child3, ii_write_lock_child3,
17153 + * ii_read_lock_parent, ii_write_lock_parent,
17154 + * ii_read_lock_parent2, ii_write_lock_parent2,
17155 + * ii_read_lock_parent3, ii_write_lock_parent3,
17156 + * ii_read_lock_new_child, ii_write_lock_new_child,
17158 +#define AuReadLockFunc(name, lsc) \
17159 +static inline void ii_read_lock_##name(struct inode *i) \
17161 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17164 +#define AuWriteLockFunc(name, lsc) \
17165 +static inline void ii_write_lock_##name(struct inode *i) \
17167 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17170 +#define AuRWLockFuncs(name, lsc) \
17171 + AuReadLockFunc(name, lsc) \
17172 + AuWriteLockFunc(name, lsc)
17174 +AuRWLockFuncs(child, CHILD);
17175 +AuRWLockFuncs(child2, CHILD2);
17176 +AuRWLockFuncs(child3, CHILD3);
17177 +AuRWLockFuncs(parent, PARENT);
17178 +AuRWLockFuncs(parent2, PARENT2);
17179 +AuRWLockFuncs(parent3, PARENT3);
17180 +AuRWLockFuncs(new_child, NEW_CHILD);
17182 +#undef AuReadLockFunc
17183 +#undef AuWriteLockFunc
17184 +#undef AuRWLockFuncs
17187 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17189 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17191 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17192 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17193 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17195 +/* ---------------------------------------------------------------------- */
17197 +static inline void au_icntnr_init(struct au_icntnr *c)
17199 +#ifdef CONFIG_AUFS_DEBUG
17200 + c->vfs_inode.i_mode = 0;
17204 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17206 + unsigned int gen;
17207 + struct au_iinfo *iinfo;
17208 + struct au_iigen *iigen;
17210 + iinfo = au_ii(inode);
17211 + iigen = &iinfo->ii_generation;
17212 + spin_lock(&iigen->ig_spin);
17214 + *igflags = iigen->ig_flags;
17215 + gen = iigen->ig_generation;
17216 + spin_unlock(&iigen->ig_spin);
17221 +/* tiny test for inode number */
17222 +/* tmpfs generation is too rough */
17223 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17225 + struct au_iinfo *iinfo;
17227 + iinfo = au_ii(inode);
17228 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17229 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17230 + && iinfo->ii_higen == h_inode->i_generation);
17233 +static inline void au_iigen_dec(struct inode *inode)
17235 + struct au_iinfo *iinfo;
17236 + struct au_iigen *iigen;
17238 + iinfo = au_ii(inode);
17239 + iigen = &iinfo->ii_generation;
17240 + spin_lock(&iigen->ig_spin);
17241 + iigen->ig_generation--;
17242 + spin_unlock(&iigen->ig_spin);
17245 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17250 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17256 +/* ---------------------------------------------------------------------- */
17258 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17259 + aufs_bindex_t bindex)
17261 + return iinfo->ii_hinode + bindex;
17264 +static inline int au_is_bad_inode(struct inode *inode)
17266 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17269 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17270 + aufs_bindex_t bindex)
17272 + IiMustAnyLock(inode);
17273 + return au_hinode(au_ii(inode), bindex)->hi_id;
17276 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17278 + IiMustAnyLock(inode);
17279 + return au_ii(inode)->ii_btop;
17282 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17284 + IiMustAnyLock(inode);
17285 + return au_ii(inode)->ii_bbot;
17288 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17290 + IiMustAnyLock(inode);
17291 + return au_ii(inode)->ii_vdir;
17294 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17296 + IiMustAnyLock(inode);
17297 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17300 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17302 + IiMustWriteLock(inode);
17303 + au_ii(inode)->ii_btop = bindex;
17306 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17308 + IiMustWriteLock(inode);
17309 + au_ii(inode)->ii_bbot = bindex;
17312 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17314 + IiMustWriteLock(inode);
17315 + au_ii(inode)->ii_vdir = vdir;
17318 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17320 + IiMustAnyLock(inode);
17321 + return au_hinode(au_ii(inode), bindex);
17324 +/* ---------------------------------------------------------------------- */
17326 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17329 + return pin->parent;
17333 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17335 + if (pin && pin->hdir)
17336 + return pin->hdir->hi_inode;
17340 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17343 + return pin->hdir;
17347 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17350 + pin->dentry = dentry;
17353 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17354 + unsigned char lflag)
17358 + au_fset_pin(pin->flags, DI_LOCKED);
17360 + au_fclr_pin(pin->flags, DI_LOCKED);
17364 +#if 0 /* reserved */
17365 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17368 + dput(pin->parent);
17369 + pin->parent = dget(parent);
17374 +/* ---------------------------------------------------------------------- */
17377 +#ifdef CONFIG_AUFS_HNOTIFY
17378 +struct au_hnotify_op {
17379 + void (*ctl)(struct au_hinode *hinode, int do_set);
17380 + int (*alloc)(struct au_hinode *hinode);
17383 + * if it returns true, the the caller should free hinode->hi_notify,
17384 + * otherwise ->free() frees it.
17386 + int (*free)(struct au_hinode *hinode,
17387 + struct au_hnotify *hn) __must_check;
17389 + void (*fin)(void);
17390 + int (*init)(void);
17392 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17393 + void (*fin_br)(struct au_branch *br);
17394 + int (*init_br)(struct au_branch *br, int perm);
17398 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17399 +void au_hn_free(struct au_hinode *hinode);
17400 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17401 +void au_hn_reset(struct inode *inode, unsigned int flags);
17402 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17403 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17404 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17405 +int au_hnotify_init_br(struct au_branch *br, int perm);
17406 +void au_hnotify_fin_br(struct au_branch *br);
17407 +int __init au_hnotify_init(void);
17408 +void au_hnotify_fin(void);
17411 +extern const struct au_hnotify_op au_hnotify_op;
17414 +void au_hn_init(struct au_hinode *hinode)
17416 + hinode->hi_notify = NULL;
17419 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17421 + return hinode->hi_notify;
17425 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17426 + struct au_hinode *hinode __maybe_unused,
17427 + struct inode *inode __maybe_unused)
17428 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17429 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17430 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17431 + int do_set __maybe_unused)
17432 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17433 + unsigned int flags __maybe_unused)
17434 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17435 + struct au_branch *br __maybe_unused,
17436 + int perm __maybe_unused)
17437 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17438 + int perm __maybe_unused)
17439 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17440 +AuStubInt0(__init au_hnotify_init, void)
17441 +AuStubVoid(au_hnotify_fin, void)
17442 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17443 +#endif /* CONFIG_AUFS_HNOTIFY */
17445 +static inline void au_hn_suspend(struct au_hinode *hdir)
17447 + au_hn_ctl(hdir, /*do_set*/0);
17450 +static inline void au_hn_resume(struct au_hinode *hdir)
17452 + au_hn_ctl(hdir, /*do_set*/1);
17455 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17457 + inode_lock(hdir->hi_inode);
17458 + au_hn_suspend(hdir);
17461 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17462 + unsigned int sc __maybe_unused)
17464 + inode_lock_nested(hdir->hi_inode, sc);
17465 + au_hn_suspend(hdir);
17468 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
17471 + vfsub_inode_lock_shared_nested(hdir->hi_inode, sc);
17472 + au_hn_suspend(hdir);
17475 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17477 + au_hn_resume(hdir);
17478 + inode_unlock(hdir->hi_inode);
17481 +#endif /* __KERNEL__ */
17482 +#endif /* __AUFS_INODE_H__ */
17483 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17484 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17485 +++ linux/fs/aufs/ioctl.c 2017-07-29 12:14:25.903042072 +0200
17488 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17490 + * This program, aufs is free software; you can redistribute it and/or modify
17491 + * it under the terms of the GNU General Public License as published by
17492 + * the Free Software Foundation; either version 2 of the License, or
17493 + * (at your option) any later version.
17495 + * This program is distributed in the hope that it will be useful,
17496 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17497 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17498 + * GNU General Public License for more details.
17500 + * You should have received a copy of the GNU General Public License
17501 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17506 + * plink-management and readdir in userspace.
17507 + * assist the pathconf(3) wrapper library.
17509 + * File-based Hierarchical Storage Management.
17512 +#include <linux/compat.h>
17513 +#include <linux/file.h>
17516 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17519 + aufs_bindex_t wbi, bindex, bbot;
17520 + struct file *h_file;
17521 + struct super_block *sb;
17522 + struct dentry *root;
17523 + struct au_branch *br;
17524 + struct aufs_wbr_fd wbrfd = {
17525 + .oflags = au_dir_roflags,
17528 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17529 + | O_NOATIME | O_CLOEXEC;
17531 + AuDebugOn(wbrfd.oflags & ~valid);
17534 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17535 + if (unlikely(err)) {
17541 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17542 + wbrfd.oflags |= au_dir_roflags;
17543 + AuDbg("0%o\n", wbrfd.oflags);
17544 + if (unlikely(wbrfd.oflags & ~valid))
17548 + fd = get_unused_fd_flags(0);
17550 + if (unlikely(fd < 0))
17553 + h_file = ERR_PTR(-EINVAL);
17556 + sb = path->dentry->d_sb;
17557 + root = sb->s_root;
17558 + aufs_read_lock(root, AuLock_IR);
17559 + bbot = au_sbbot(sb);
17560 + if (wbrfd.brid >= 0) {
17561 + wbi = au_br_index(sb, wbrfd.brid);
17562 + if (unlikely(wbi < 0 || wbi > bbot))
17566 + h_file = ERR_PTR(-ENOENT);
17567 + br = au_sbr(sb, wbi);
17568 + if (!au_br_writable(br->br_perm)) {
17572 + bindex = wbi + 1;
17574 + for (; bindex <= bbot; bindex++) {
17575 + br = au_sbr(sb, bindex);
17576 + if (au_br_writable(br->br_perm)) {
17578 + br = au_sbr(sb, wbi);
17583 + AuDbg("wbi %d\n", wbi);
17585 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17589 + aufs_read_unlock(root, AuLock_IR);
17590 + err = PTR_ERR(h_file);
17591 + if (IS_ERR(h_file))
17594 + au_br_put(br); /* cf. au_h_open() */
17595 + fd_install(fd, h_file);
17597 + goto out; /* success */
17600 + put_unused_fd(fd);
17606 +/* ---------------------------------------------------------------------- */
17608 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17611 + struct dentry *dentry;
17614 + case AUFS_CTL_RDU:
17615 + case AUFS_CTL_RDU_INO:
17616 + err = au_rdu_ioctl(file, cmd, arg);
17619 + case AUFS_CTL_WBR_FD:
17620 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17623 + case AUFS_CTL_IBUSY:
17624 + err = au_ibusy_ioctl(file, arg);
17627 + case AUFS_CTL_BRINFO:
17628 + err = au_brinfo_ioctl(file, arg);
17631 + case AUFS_CTL_FHSM_FD:
17632 + dentry = file->f_path.dentry;
17633 + if (IS_ROOT(dentry))
17634 + err = au_fhsm_fd(dentry->d_sb, arg);
17640 + /* do not call the lower */
17641 + AuDbg("0x%x\n", cmd);
17649 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17654 + case AUFS_CTL_MVDOWN:
17655 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17658 + case AUFS_CTL_WBR_FD:
17659 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17663 + /* do not call the lower */
17664 + AuDbg("0x%x\n", cmd);
17672 +#ifdef CONFIG_COMPAT
17673 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17674 + unsigned long arg)
17679 + case AUFS_CTL_RDU:
17680 + case AUFS_CTL_RDU_INO:
17681 + err = au_rdu_compat_ioctl(file, cmd, arg);
17684 + case AUFS_CTL_IBUSY:
17685 + err = au_ibusy_compat_ioctl(file, arg);
17688 + case AUFS_CTL_BRINFO:
17689 + err = au_brinfo_compat_ioctl(file, arg);
17693 + err = aufs_ioctl_dir(file, cmd, arg);
17700 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17701 + unsigned long arg)
17703 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17706 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17707 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17708 +++ linux/fs/aufs/i_op_add.c 2017-07-29 12:14:25.903042072 +0200
17711 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17713 + * This program, aufs is free software; you can redistribute it and/or modify
17714 + * it under the terms of the GNU General Public License as published by
17715 + * the Free Software Foundation; either version 2 of the License, or
17716 + * (at your option) any later version.
17718 + * This program is distributed in the hope that it will be useful,
17719 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17720 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17721 + * GNU General Public License for more details.
17723 + * You should have received a copy of the GNU General Public License
17724 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17728 + * inode operations (add entry)
17734 + * final procedure of adding a new entry, except link(2).
17735 + * remove whiteout, instantiate, copyup the parent dir's times and size
17736 + * and update version.
17737 + * if it failed, re-create the removed whiteout.
17739 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17740 + struct dentry *wh_dentry, struct dentry *dentry)
17743 + aufs_bindex_t bwh;
17744 + struct path h_path;
17745 + struct super_block *sb;
17746 + struct inode *inode, *h_dir;
17747 + struct dentry *wh;
17752 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17753 + IMustLock(h_dir);
17754 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17755 + bwh = au_dbwh(dentry);
17756 + h_path.dentry = wh_dentry;
17757 + h_path.mnt = au_sbr_mnt(sb, bindex);
17758 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17760 + if (unlikely(err))
17764 + inode = au_new_inode(dentry, /*must_new*/1);
17765 + if (!IS_ERR(inode)) {
17766 + d_instantiate(dentry, inode);
17767 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17769 + au_dir_ts(dir, bindex);
17770 + dir->i_version++;
17771 + au_fhsm_wrote(sb, bindex, /*force*/0);
17772 + return 0; /* success */
17775 + err = PTR_ERR(inode);
17780 + /* dir inode is locked */
17781 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17782 + rerr = PTR_ERR(wh);
17783 + if (IS_ERR(wh)) {
17784 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17785 + dentry, err, rerr);
17794 +static int au_d_may_add(struct dentry *dentry)
17799 + if (unlikely(d_unhashed(dentry)))
17801 + if (unlikely(d_really_is_positive(dentry)))
17807 + * simple tests for the adding inode operations.
17808 + * following the checks in vfs, plus the parent-child relationship.
17810 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17811 + struct dentry *h_parent, int isdir)
17815 + struct dentry *h_dentry;
17816 + struct inode *h_inode;
17818 + err = -ENAMETOOLONG;
17819 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17822 + h_dentry = au_h_dptr(dentry, bindex);
17823 + if (d_really_is_negative(dentry)) {
17825 + if (unlikely(d_is_positive(h_dentry)))
17828 + /* rename(2) case */
17830 + if (unlikely(d_is_negative(h_dentry)))
17832 + h_inode = d_inode(h_dentry);
17833 + if (unlikely(!h_inode->i_nlink))
17836 + h_mode = h_inode->i_mode;
17839 + if (unlikely(S_ISDIR(h_mode)))
17841 + } else if (unlikely(!S_ISDIR(h_mode))) {
17848 + /* expected parent dir is locked */
17849 + if (unlikely(h_parent != h_dentry->d_parent))
17858 + * initial procedure of adding a new entry.
17859 + * prepare writable branch and the parent dir, lock it,
17860 + * and lookup whiteout for the new entry.
17862 +static struct dentry*
17863 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17864 + struct dentry *src_dentry, struct au_pin *pin,
17865 + struct au_wr_dir_args *wr_dir_args)
17867 + struct dentry *wh_dentry, *h_parent;
17868 + struct super_block *sb;
17869 + struct au_branch *br;
17871 + unsigned int udba;
17872 + aufs_bindex_t bcpup;
17874 + AuDbg("%pd\n", dentry);
17876 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17878 + wh_dentry = ERR_PTR(err);
17879 + if (unlikely(err < 0))
17882 + sb = dentry->d_sb;
17883 + udba = au_opt_udba(sb);
17884 + err = au_pin(pin, dentry, bcpup, udba,
17885 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17886 + wh_dentry = ERR_PTR(err);
17887 + if (unlikely(err))
17890 + h_parent = au_pinned_h_parent(pin);
17891 + if (udba != AuOpt_UDBA_NONE
17892 + && au_dbtop(dentry) == bcpup)
17893 + err = au_may_add(dentry, bcpup, h_parent,
17894 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17895 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17896 + err = -ENAMETOOLONG;
17897 + wh_dentry = ERR_PTR(err);
17898 + if (unlikely(err))
17901 + br = au_sbr(sb, bcpup);
17903 + struct path tmp = {
17904 + .dentry = h_parent,
17905 + .mnt = au_br_mnt(br)
17907 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17910 + wh_dentry = NULL;
17911 + if (bcpup != au_dbwh(dentry))
17912 + goto out; /* success */
17915 + * ENAMETOOLONG here means that if we allowed create such name, then it
17916 + * would not be able to removed in the future. So we don't allow such
17917 + * name here and we don't handle ENAMETOOLONG differently here.
17919 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17922 + if (IS_ERR(wh_dentry))
17925 + return wh_dentry;
17928 +/* ---------------------------------------------------------------------- */
17930 +enum { Mknod, Symlink, Creat };
17931 +struct simple_arg {
17938 + struct vfsub_aopen_args *aopen;
17941 + const char *symname;
17950 +static int add_simple(struct inode *dir, struct dentry *dentry,
17951 + struct simple_arg *arg)
17954 + aufs_bindex_t btop;
17955 + unsigned char created;
17956 + const unsigned char try_aopen
17957 + = (arg->type == Creat && arg->u.c.try_aopen);
17958 + struct dentry *wh_dentry, *parent;
17959 + struct inode *h_dir;
17960 + struct super_block *sb;
17961 + struct au_branch *br;
17962 + /* to reuduce stack size */
17964 + struct au_dtime dt;
17965 + struct au_pin pin;
17966 + struct path h_path;
17967 + struct au_wr_dir_args wr_dir_args;
17970 + AuDbg("%pd\n", dentry);
17974 + a = kmalloc(sizeof(*a), GFP_NOFS);
17975 + if (unlikely(!a))
17977 + a->wr_dir_args.force_btgt = -1;
17978 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17980 + parent = dentry->d_parent; /* dir inode is locked */
17981 + if (!try_aopen) {
17982 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17983 + if (unlikely(err))
17986 + err = au_d_may_add(dentry);
17987 + if (unlikely(err))
17990 + di_write_lock_parent(parent);
17991 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17992 + &a->pin, &a->wr_dir_args);
17993 + err = PTR_ERR(wh_dentry);
17994 + if (IS_ERR(wh_dentry))
17997 + btop = au_dbtop(dentry);
17998 + sb = dentry->d_sb;
17999 + br = au_sbr(sb, btop);
18000 + a->h_path.dentry = au_h_dptr(dentry, btop);
18001 + a->h_path.mnt = au_br_mnt(br);
18002 + h_dir = au_pinned_h_dir(&a->pin);
18003 + switch (arg->type) {
18006 + if (!try_aopen || !h_dir->i_op->atomic_open)
18007 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
18008 + arg->u.c.want_excl);
18010 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
18011 + arg->u.c.aopen, br);
18014 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
18017 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
18025 + err = epilog(dir, btop, wh_dentry, dentry);
18028 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
18029 + /* no delegation since it is just created */
18030 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
18033 + AuIOErr("%pd revert failure(%d, %d)\n",
18034 + dentry, err, rerr);
18037 + au_dtime_revert(&a->dt);
18040 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
18041 + *arg->u.c.aopen->opened |= FILE_CREATED;
18043 + au_unpin(&a->pin);
18048 + di_write_unlock(parent);
18050 + if (unlikely(err)) {
18051 + au_update_dbtop(dentry);
18055 + aufs_read_unlock(dentry, AuLock_DW);
18062 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18065 + struct simple_arg arg = {
18072 + return add_simple(dir, dentry, &arg);
18075 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
18077 + struct simple_arg arg = {
18079 + .u.s.symname = symname
18081 + return add_simple(dir, dentry, &arg);
18084 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18087 + struct simple_arg arg = {
18091 + .want_excl = want_excl
18094 + return add_simple(dir, dentry, &arg);
18097 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18098 + struct vfsub_aopen_args *aopen_args)
18100 + struct simple_arg arg = {
18103 + .mode = aopen_args->create_mode,
18104 + .want_excl = aopen_args->open_flag & O_EXCL,
18105 + .try_aopen = true,
18106 + .aopen = aopen_args
18109 + return add_simple(dir, dentry, &arg);
18112 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
18115 + aufs_bindex_t bindex;
18116 + struct super_block *sb;
18117 + struct dentry *parent, *h_parent, *h_dentry;
18118 + struct inode *h_dir, *inode;
18119 + struct vfsmount *h_mnt;
18120 + struct au_wr_dir_args wr_dir_args = {
18121 + .force_btgt = -1,
18122 + .flags = AuWrDir_TMPFILE
18125 + /* copy-up may happen */
18129 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18130 + if (unlikely(err))
18133 + err = au_di_init(dentry);
18134 + if (unlikely(err))
18138 + parent = d_find_any_alias(dir);
18139 + AuDebugOn(!parent);
18140 + di_write_lock_parent(parent);
18141 + if (unlikely(d_inode(parent) != dir))
18144 + err = au_digen_test(parent, au_sigen(sb));
18145 + if (unlikely(err))
18148 + bindex = au_dbtop(parent);
18149 + au_set_dbtop(dentry, bindex);
18150 + au_set_dbbot(dentry, bindex);
18151 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18153 + if (unlikely(err < 0))
18156 + err = -EOPNOTSUPP;
18157 + h_dir = au_h_iptr(dir, bindex);
18158 + if (unlikely(!h_dir->i_op->tmpfile))
18161 + h_mnt = au_sbr_mnt(sb, bindex);
18162 + err = vfsub_mnt_want_write(h_mnt);
18163 + if (unlikely(err))
18166 + h_parent = au_h_dptr(parent, bindex);
18167 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
18168 + if (IS_ERR(h_dentry)) {
18169 + err = PTR_ERR(h_dentry);
18173 + au_set_dbtop(dentry, bindex);
18174 + au_set_dbbot(dentry, bindex);
18175 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18176 + inode = au_new_inode(dentry, /*must_new*/1);
18177 + if (IS_ERR(inode)) {
18178 + err = PTR_ERR(inode);
18179 + au_set_h_dptr(dentry, bindex, NULL);
18180 + au_set_dbtop(dentry, -1);
18181 + au_set_dbbot(dentry, -1);
18183 + if (!inode->i_nlink)
18184 + set_nlink(inode, 1);
18185 + d_tmpfile(dentry, inode);
18186 + au_di(dentry)->di_tmpfile = 1;
18188 + /* update without i_mutex */
18189 + if (au_ibtop(dir) == au_dbtop(dentry))
18190 + au_cpup_attr_timesizes(dir);
18195 + vfsub_mnt_drop_write(h_mnt);
18197 + di_write_unlock(parent);
18199 + di_write_unlock(dentry);
18200 + if (unlikely(err)) {
18201 + au_di_fin(dentry);
18202 + dentry->d_fsdata = NULL;
18205 + si_read_unlock(sb);
18207 + inode_unlock(dir);
18211 +/* ---------------------------------------------------------------------- */
18213 +struct au_link_args {
18214 + aufs_bindex_t bdst, bsrc;
18215 + struct au_pin pin;
18216 + struct path h_path;
18217 + struct dentry *src_parent, *parent;
18220 +static int au_cpup_before_link(struct dentry *src_dentry,
18221 + struct au_link_args *a)
18224 + struct dentry *h_src_dentry;
18225 + struct au_cp_generic cpg = {
18226 + .dentry = src_dentry,
18231 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18234 + di_read_lock_parent(a->src_parent, AuLock_IR);
18235 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18236 + if (unlikely(err))
18239 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18240 + err = au_pin(&a->pin, src_dentry, a->bdst,
18241 + au_opt_udba(src_dentry->d_sb),
18242 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18243 + if (unlikely(err))
18246 + err = au_sio_cpup_simple(&cpg);
18247 + au_unpin(&a->pin);
18250 + di_read_unlock(a->src_parent, AuLock_IR);
18254 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18255 + struct au_link_args *a)
18258 + unsigned char plink;
18259 + aufs_bindex_t bbot;
18260 + struct dentry *h_src_dentry;
18261 + struct inode *h_inode, *inode, *delegated;
18262 + struct super_block *sb;
18263 + struct file *h_file;
18267 + sb = src_dentry->d_sb;
18268 + inode = d_inode(src_dentry);
18269 + if (au_ibtop(inode) <= a->bdst)
18270 + h_inode = au_h_iptr(inode, a->bdst);
18271 + if (!h_inode || !h_inode->i_nlink) {
18272 + /* copyup src_dentry as the name of dentry. */
18273 + bbot = au_dbbot(dentry);
18274 + if (bbot < a->bsrc)
18275 + au_set_dbbot(dentry, a->bsrc);
18276 + au_set_h_dptr(dentry, a->bsrc,
18277 + dget(au_h_dptr(src_dentry, a->bsrc)));
18278 + dget(a->h_path.dentry);
18279 + au_set_h_dptr(dentry, a->bdst, NULL);
18280 + AuDbg("temporary d_inode...\n");
18281 + spin_lock(&dentry->d_lock);
18282 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18283 + spin_unlock(&dentry->d_lock);
18284 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18285 + if (IS_ERR(h_file))
18286 + err = PTR_ERR(h_file);
18288 + struct au_cp_generic cpg = {
18289 + .dentry = dentry,
18294 + .flags = AuCpup_KEEPLINO
18296 + err = au_sio_cpup_simple(&cpg);
18297 + au_h_open_post(dentry, a->bsrc, h_file);
18299 + dput(a->h_path.dentry);
18300 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18302 + au_set_h_dptr(dentry, a->bdst,
18303 + a->h_path.dentry);
18305 + spin_lock(&dentry->d_lock);
18306 + dentry->d_inode = NULL; /* restore */
18307 + spin_unlock(&dentry->d_lock);
18308 + AuDbg("temporary d_inode...done\n");
18309 + au_set_h_dptr(dentry, a->bsrc, NULL);
18310 + au_set_dbbot(dentry, bbot);
18312 + /* the inode of src_dentry already exists on a.bdst branch */
18313 + h_src_dentry = d_find_alias(h_inode);
18314 + if (!h_src_dentry && au_plink_test(inode)) {
18316 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18317 + err = PTR_ERR(h_src_dentry);
18318 + if (IS_ERR(h_src_dentry))
18321 + if (unlikely(d_is_negative(h_src_dentry))) {
18322 + dput(h_src_dentry);
18323 + h_src_dentry = NULL;
18327 + if (h_src_dentry) {
18328 + delegated = NULL;
18329 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18330 + &a->h_path, &delegated);
18331 + if (unlikely(err == -EWOULDBLOCK)) {
18332 + pr_warn("cannot retry for NFSv4 delegation"
18333 + " for an internal link\n");
18336 + dput(h_src_dentry);
18338 + AuIOErr("no dentry found for hi%lu on b%d\n",
18339 + h_inode->i_ino, a->bdst);
18344 + if (!err && !plink)
18345 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18352 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18353 + struct dentry *dentry)
18356 + struct au_dtime dt;
18357 + struct au_link_args *a;
18358 + struct dentry *wh_dentry, *h_src_dentry;
18359 + struct inode *inode, *delegated;
18360 + struct super_block *sb;
18361 + struct au_wr_dir_args wr_dir_args = {
18362 + /* .force_btgt = -1, */
18363 + .flags = AuWrDir_ADD_ENTRY
18367 + inode = d_inode(src_dentry);
18368 + IMustLock(inode);
18371 + a = kzalloc(sizeof(*a), GFP_NOFS);
18372 + if (unlikely(!a))
18375 + a->parent = dentry->d_parent; /* dir inode is locked */
18376 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18377 + AuLock_NOPLM | AuLock_GEN);
18378 + if (unlikely(err))
18380 + err = au_d_linkable(src_dentry);
18381 + if (unlikely(err))
18383 + err = au_d_may_add(dentry);
18384 + if (unlikely(err))
18387 + a->src_parent = dget_parent(src_dentry);
18388 + wr_dir_args.force_btgt = au_ibtop(inode);
18390 + di_write_lock_parent(a->parent);
18391 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18392 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18394 + err = PTR_ERR(wh_dentry);
18395 + if (IS_ERR(wh_dentry))
18399 + sb = dentry->d_sb;
18400 + a->bdst = au_dbtop(dentry);
18401 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18402 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18403 + a->bsrc = au_ibtop(inode);
18404 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18405 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18406 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18407 + if (!h_src_dentry) {
18408 + a->bsrc = au_dbtop(src_dentry);
18409 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18410 + AuDebugOn(!h_src_dentry);
18411 + } else if (IS_ERR(h_src_dentry)) {
18412 + err = PTR_ERR(h_src_dentry);
18417 + * aufs doesn't touch the credential so
18418 + * security_dentry_create_files_as() is unnecrssary.
18420 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18421 + if (a->bdst < a->bsrc
18422 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18423 + err = au_cpup_or_link(src_dentry, dentry, a);
18425 + delegated = NULL;
18426 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18427 + &a->h_path, &delegated);
18428 + if (unlikely(err == -EWOULDBLOCK)) {
18429 + pr_warn("cannot retry for NFSv4 delegation"
18430 + " for an internal link\n");
18434 + dput(h_src_dentry);
18437 + * copyup src_dentry to the branch we process,
18438 + * and then link(2) to it.
18440 + dput(h_src_dentry);
18441 + if (a->bdst < a->bsrc
18442 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18443 + au_unpin(&a->pin);
18444 + di_write_unlock(a->parent);
18445 + err = au_cpup_before_link(src_dentry, a);
18446 + di_write_lock_parent(a->parent);
18448 + err = au_pin(&a->pin, dentry, a->bdst,
18450 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18451 + if (unlikely(err))
18455 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18457 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18458 + delegated = NULL;
18459 + err = vfsub_link(h_src_dentry,
18460 + au_pinned_h_dir(&a->pin),
18461 + &a->h_path, &delegated);
18462 + if (unlikely(err == -EWOULDBLOCK)) {
18463 + pr_warn("cannot retry"
18464 + " for NFSv4 delegation"
18465 + " for an internal link\n");
18471 + if (unlikely(err))
18475 + a->h_path.dentry = wh_dentry;
18476 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18478 + if (unlikely(err))
18482 + au_dir_ts(dir, a->bdst);
18483 + dir->i_version++;
18484 + inc_nlink(inode);
18485 + inode->i_ctime = dir->i_ctime;
18486 + d_instantiate(dentry, au_igrab(inode));
18487 + if (d_unhashed(a->h_path.dentry))
18488 + /* some filesystem calls d_drop() */
18490 + /* some filesystems consume an inode even hardlink */
18491 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18492 + goto out_unpin; /* success */
18495 + /* no delegation since it is just created */
18496 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18497 + /*delegated*/NULL, /*force*/0);
18498 + if (unlikely(rerr)) {
18499 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18502 + au_dtime_revert(&dt);
18504 + au_unpin(&a->pin);
18508 + di_write_unlock(a->parent);
18509 + dput(a->src_parent);
18511 + if (unlikely(err)) {
18512 + au_update_dbtop(dentry);
18515 + aufs_read_and_write_unlock2(dentry, src_dentry);
18523 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18526 + aufs_bindex_t bindex;
18527 + unsigned char diropq;
18528 + struct path h_path;
18529 + struct dentry *wh_dentry, *parent, *opq_dentry;
18530 + struct inode *h_inode;
18531 + struct super_block *sb;
18533 + struct au_pin pin;
18534 + struct au_dtime dt;
18535 + } *a; /* reduce the stack usage */
18536 + struct au_wr_dir_args wr_dir_args = {
18537 + .force_btgt = -1,
18538 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18544 + a = kmalloc(sizeof(*a), GFP_NOFS);
18545 + if (unlikely(!a))
18548 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18549 + if (unlikely(err))
18551 + err = au_d_may_add(dentry);
18552 + if (unlikely(err))
18555 + parent = dentry->d_parent; /* dir inode is locked */
18556 + di_write_lock_parent(parent);
18557 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18558 + &a->pin, &wr_dir_args);
18559 + err = PTR_ERR(wh_dentry);
18560 + if (IS_ERR(wh_dentry))
18563 + sb = dentry->d_sb;
18564 + bindex = au_dbtop(dentry);
18565 + h_path.dentry = au_h_dptr(dentry, bindex);
18566 + h_path.mnt = au_sbr_mnt(sb, bindex);
18567 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18568 + if (unlikely(err))
18571 + /* make the dir opaque */
18573 + h_inode = d_inode(h_path.dentry);
18575 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18576 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18577 + opq_dentry = au_diropq_create(dentry, bindex);
18578 + inode_unlock(h_inode);
18579 + err = PTR_ERR(opq_dentry);
18580 + if (IS_ERR(opq_dentry))
18582 + dput(opq_dentry);
18586 + err = epilog(dir, bindex, wh_dentry, dentry);
18589 + goto out_unpin; /* success */
18594 + AuLabel(revert opq);
18595 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18596 + rerr = au_diropq_remove(dentry, bindex);
18597 + inode_unlock(h_inode);
18599 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18600 + dentry, err, rerr);
18606 + AuLabel(revert dir);
18607 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18609 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18610 + dentry, err, rerr);
18613 + au_dtime_revert(&a->dt);
18615 + au_unpin(&a->pin);
18618 + di_write_unlock(parent);
18620 + if (unlikely(err)) {
18621 + au_update_dbtop(dentry);
18624 + aufs_read_unlock(dentry, AuLock_DW);
18630 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18631 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18632 +++ linux/fs/aufs/i_op.c 2017-09-05 10:42:11.058755349 +0200
18635 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18637 + * This program, aufs is free software; you can redistribute it and/or modify
18638 + * it under the terms of the GNU General Public License as published by
18639 + * the Free Software Foundation; either version 2 of the License, or
18640 + * (at your option) any later version.
18642 + * This program is distributed in the hope that it will be useful,
18643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18645 + * GNU General Public License for more details.
18647 + * You should have received a copy of the GNU General Public License
18648 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18652 + * inode operations (except add/del/rename)
18655 +#include <linux/device_cgroup.h>
18656 +#include <linux/fs_stack.h>
18657 +#include <linux/namei.h>
18658 +#include <linux/security.h>
18661 +static int h_permission(struct inode *h_inode, int mask,
18662 + struct path *h_path, int brperm)
18665 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18668 + if (write_mask && IS_IMMUTABLE(h_inode))
18672 + if (((mask & MAY_EXEC)
18673 + && S_ISREG(h_inode->i_mode)
18674 + && (path_noexec(h_path)
18675 + || !(h_inode->i_mode & S_IXUGO))))
18679 + * - skip the lower fs test in the case of write to ro branch.
18680 + * - nfs dir permission write check is optimized, but a policy for
18681 + * link/rename requires a real check.
18682 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18683 + * in this case, generic_permission() returns -EOPNOTSUPP.
18685 + if ((write_mask && !au_br_writable(brperm))
18686 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18687 + && write_mask && !(mask & MAY_READ))
18688 + || !h_inode->i_op->permission) {
18689 + /* AuLabel(generic_permission); */
18690 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18691 + err = generic_permission(h_inode, mask);
18692 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18693 + err = h_inode->i_op->permission(h_inode, mask);
18696 + /* AuLabel(h_inode->permission); */
18697 + err = h_inode->i_op->permission(h_inode, mask);
18702 + err = devcgroup_inode_permission(h_inode, mask);
18704 + err = security_inode_permission(h_inode, mask);
18708 + /* todo: do we need to call ima_path_check()? */
18709 + struct path h_path = {
18713 + err = ima_path_check(&h_path,
18714 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18715 + IMA_COUNT_LEAVE);
18723 +static int aufs_permission(struct inode *inode, int mask)
18726 + aufs_bindex_t bindex, bbot;
18727 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18728 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18729 + struct inode *h_inode;
18730 + struct super_block *sb;
18731 + struct au_branch *br;
18733 + /* todo: support rcu-walk? */
18734 + if (mask & MAY_NOT_BLOCK)
18737 + sb = inode->i_sb;
18738 + si_read_lock(sb, AuLock_FLUSH);
18739 + ii_read_lock_child(inode);
18741 + err = au_iigen_test(inode, au_sigen(sb));
18742 + if (unlikely(err))
18748 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18749 + err = au_busy_or_stale();
18750 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18751 + if (unlikely(!h_inode
18752 + || (h_inode->i_mode & S_IFMT)
18753 + != (inode->i_mode & S_IFMT)))
18757 + bindex = au_ibtop(inode);
18758 + br = au_sbr(sb, bindex);
18759 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18762 + && !special_file(h_inode->i_mode)) {
18763 + /* test whether the upper writable branch exists */
18765 + for (; bindex >= 0; bindex--)
18766 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18774 + /* non-write to dir */
18776 + bbot = au_ibbot(inode);
18777 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18778 + h_inode = au_h_iptr(inode, bindex);
18780 + err = au_busy_or_stale();
18781 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18784 + br = au_sbr(sb, bindex);
18785 + err = h_permission(h_inode, mask, &br->br_path,
18791 + ii_read_unlock(inode);
18792 + si_read_unlock(sb);
18796 +/* ---------------------------------------------------------------------- */
18798 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18799 + unsigned int flags)
18801 + struct dentry *ret, *parent;
18802 + struct inode *inode;
18803 + struct super_block *sb;
18804 + int err, npositive;
18808 + /* todo: support rcu-walk? */
18809 + ret = ERR_PTR(-ECHILD);
18810 + if (flags & LOOKUP_RCU)
18813 + ret = ERR_PTR(-ENAMETOOLONG);
18814 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18818 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18819 + ret = ERR_PTR(err);
18820 + if (unlikely(err))
18823 + err = au_di_init(dentry);
18824 + ret = ERR_PTR(err);
18825 + if (unlikely(err))
18829 + npositive = 0; /* suppress a warning */
18830 + parent = dentry->d_parent; /* dir inode is locked */
18831 + di_read_lock_parent(parent, AuLock_IR);
18832 + err = au_alive_dir(parent);
18834 + err = au_digen_test(parent, au_sigen(sb));
18836 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18837 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18838 + AuLkup_ALLOW_NEG);
18841 + di_read_unlock(parent, AuLock_IR);
18842 + ret = ERR_PTR(err);
18843 + if (unlikely(err < 0))
18847 + inode = au_new_inode(dentry, /*must_new*/0);
18848 + if (IS_ERR(inode)) {
18849 + ret = (void *)inode;
18856 + atomic_inc(&inode->i_count);
18857 + ret = d_splice_alias(inode, dentry);
18859 + if (unlikely(d_need_lookup(dentry))) {
18860 + spin_lock(&dentry->d_lock);
18861 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18862 + spin_unlock(&dentry->d_lock);
18866 + if (!IS_ERR(ret)) {
18868 + if (ret && ret != dentry)
18869 + ii_write_unlock(inode);
18871 + ii_write_unlock(inode);
18878 + di_write_unlock(dentry);
18880 + si_read_unlock(sb);
18885 +/* ---------------------------------------------------------------------- */
18887 +struct aopen_node {
18888 + struct hlist_node hlist;
18889 + struct file *file, *h_file;
18892 +static int au_do_aopen(struct inode *inode, struct file *file)
18894 + struct au_sphlhead *aopen;
18895 + struct aopen_node *node;
18896 + struct au_do_open_args args = {
18898 + .open = au_do_open_nondir
18901 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18902 + spin_lock(&aopen->spin);
18903 + hlist_for_each_entry(node, &aopen->head, hlist)
18904 + if (node->file == file) {
18905 + args.h_file = node->h_file;
18908 + spin_unlock(&aopen->spin);
18909 + /* AuDebugOn(!args.h_file); */
18911 + return au_do_open(file, &args);
18914 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18915 + struct file *file, unsigned int open_flag,
18916 + umode_t create_mode, int *opened)
18918 + int err, h_opened = *opened;
18919 + unsigned int lkup_flags;
18920 + struct dentry *parent, *d;
18921 + struct au_sphlhead *aopen;
18922 + struct vfsub_aopen_args args = {
18923 + .open_flag = open_flag,
18924 + .create_mode = create_mode,
18925 + .opened = &h_opened
18927 + struct aopen_node aopen_node = {
18932 + AuDbg("open_flag 0%o\n", open_flag);
18933 + AuDbgDentry(dentry);
18936 + if (!au_di(dentry)) {
18937 + lkup_flags = LOOKUP_OPEN;
18938 + if (open_flag & O_CREAT)
18939 + lkup_flags |= LOOKUP_CREATE;
18940 + d = aufs_lookup(dir, dentry, lkup_flags);
18942 + err = PTR_ERR(d);
18947 + * obsoleted dentry found.
18948 + * another error will be returned later.
18954 + AuDbgDentry(dentry);
18957 + if (d_is_positive(dentry)
18958 + || d_unhashed(dentry)
18959 + || d_unlinked(dentry)
18960 + || !(open_flag & O_CREAT))
18961 + goto out_no_open;
18963 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18964 + if (unlikely(err))
18967 + parent = dentry->d_parent; /* dir is locked */
18968 + di_write_lock_parent(parent);
18969 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18970 + if (unlikely(err))
18973 + AuDbgDentry(dentry);
18974 + if (d_is_positive(dentry))
18977 + args.file = get_empty_filp();
18978 + err = PTR_ERR(args.file);
18979 + if (IS_ERR(args.file))
18982 + args.file->f_flags = file->f_flags;
18983 + err = au_aopen_or_create(dir, dentry, &args);
18985 + AuDbgFile(args.file);
18986 + if (unlikely(err < 0)) {
18987 + if (h_opened & FILE_OPENED)
18990 + put_filp(args.file);
18994 + /* some filesystems don't set FILE_CREATED while succeeded? */
18995 + *opened |= FILE_CREATED;
18996 + if (h_opened & FILE_OPENED)
18997 + aopen_node.h_file = args.file;
18999 + put_filp(args.file);
19000 + args.file = NULL;
19002 + aopen = &au_sbi(dir->i_sb)->si_aopen;
19003 + au_sphl_add(&aopen_node.hlist, aopen);
19004 + err = finish_open(file, dentry, au_do_aopen, opened);
19005 + au_sphl_del(&aopen_node.hlist, aopen);
19008 + if (aopen_node.h_file)
19009 + fput(aopen_node.h_file);
19012 + di_write_unlock(parent);
19013 + aufs_read_unlock(dentry, AuLock_DW);
19014 + AuDbgDentry(dentry);
19015 + if (unlikely(err < 0))
19018 + if (err >= 0 && !(*opened & FILE_CREATED)) {
19019 + AuLabel(out_no_open);
19021 + err = finish_no_open(file, dentry);
19024 + AuDbg("%pd%s%s\n", dentry,
19025 + (*opened & FILE_CREATED) ? " created" : "",
19026 + (*opened & FILE_OPENED) ? " opened" : "");
19032 +/* ---------------------------------------------------------------------- */
19034 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
19035 + const unsigned char add_entry, aufs_bindex_t bcpup,
19036 + aufs_bindex_t btop)
19039 + struct dentry *h_parent;
19040 + struct inode *h_dir;
19043 + IMustLock(d_inode(parent));
19045 + di_write_lock_parent(parent);
19048 + if (!au_h_dptr(parent, bcpup)) {
19049 + if (btop > bcpup)
19050 + err = au_cpup_dirs(dentry, bcpup);
19051 + else if (btop < bcpup)
19052 + err = au_cpdown_dirs(dentry, bcpup);
19056 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
19057 + h_parent = au_h_dptr(parent, bcpup);
19058 + h_dir = d_inode(h_parent);
19059 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
19060 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
19061 + /* todo: no unlock here */
19062 + inode_unlock_shared(h_dir);
19064 + AuDbg("bcpup %d\n", bcpup);
19066 + if (d_really_is_negative(dentry))
19067 + au_set_h_dptr(dentry, btop, NULL);
19068 + au_update_dbrange(dentry, /*do_put_zero*/0);
19073 + di_write_unlock(parent);
19075 + err = bcpup; /* success */
19082 + * decide the branch and the parent dir where we will create a new entry.
19083 + * returns new bindex or an error.
19084 + * copyup the parent dir if needed.
19086 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19087 + struct au_wr_dir_args *args)
19090 + unsigned int flags;
19091 + aufs_bindex_t bcpup, btop, src_btop;
19092 + const unsigned char add_entry
19093 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
19094 + | au_ftest_wrdir(args->flags, TMPFILE);
19095 + struct super_block *sb;
19096 + struct dentry *parent;
19097 + struct au_sbinfo *sbinfo;
19099 + sb = dentry->d_sb;
19100 + sbinfo = au_sbi(sb);
19101 + parent = dget_parent(dentry);
19102 + btop = au_dbtop(dentry);
19104 + if (args->force_btgt < 0) {
19105 + if (src_dentry) {
19106 + src_btop = au_dbtop(src_dentry);
19107 + if (src_btop < btop)
19108 + bcpup = src_btop;
19109 + } else if (add_entry) {
19111 + if (au_ftest_wrdir(args->flags, ISDIR))
19112 + au_fset_wbr(flags, DIR);
19113 + err = AuWbrCreate(sbinfo, dentry, flags);
19117 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
19119 + err = AuWbrCopyup(sbinfo, dentry);
19121 + if (!IS_ROOT(dentry)) {
19122 + di_read_lock_parent(parent, !AuLock_IR);
19123 + err = AuWbrCopyup(sbinfo, dentry);
19124 + di_read_unlock(parent, !AuLock_IR);
19126 + err = AuWbrCopyup(sbinfo, dentry);
19129 + if (unlikely(err < 0))
19133 + bcpup = args->force_btgt;
19134 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
19137 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
19139 + if (bcpup == btop)
19140 + goto out; /* success */
19142 + /* copyup the new parent into the branch we process */
19143 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
19145 + if (d_really_is_negative(dentry)) {
19146 + au_set_h_dptr(dentry, btop, NULL);
19147 + au_set_dbtop(dentry, bcpup);
19148 + au_set_dbbot(dentry, bcpup);
19150 + AuDebugOn(add_entry
19151 + && !au_ftest_wrdir(args->flags, TMPFILE)
19152 + && !au_h_dptr(dentry, bcpup));
19160 +/* ---------------------------------------------------------------------- */
19162 +void au_pin_hdir_unlock(struct au_pin *p)
19165 + au_hn_inode_unlock(p->hdir);
19168 +int au_pin_hdir_lock(struct au_pin *p)
19176 + /* even if an error happens later, keep this lock */
19177 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19180 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19185 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19186 + p->h_parent, p->br);
19192 +int au_pin_hdir_relock(struct au_pin *p)
19195 + struct inode *h_i;
19196 + struct dentry *h_d[] = {
19201 + err = au_pin_hdir_lock(p);
19202 + if (unlikely(err))
19205 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19208 + if (d_is_positive(h_d[i])) {
19209 + h_i = d_inode(h_d[i]);
19210 + err = !h_i->i_nlink;
19218 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19220 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19221 + p->hdir->hi_inode->i_rwsem.owner = task;
19225 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19228 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19229 + p->lsc_hi, 0, NULL, _RET_IP_);
19230 + au_pin_hdir_set_owner(p, current);
19234 +void au_pin_hdir_release(struct au_pin *p)
19237 + au_pin_hdir_set_owner(p, p->task);
19238 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19242 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19244 + if (pin && pin->parent)
19245 + return au_h_dptr(pin->parent, pin->bindex);
19249 +void au_unpin(struct au_pin *p)
19252 + au_pin_hdir_unlock(p);
19253 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19254 + vfsub_mnt_drop_write(p->h_mnt);
19258 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19259 + di_read_unlock(p->parent, AuLock_IR);
19260 + iput(p->hdir->hi_inode);
19262 + p->parent = NULL;
19265 + /* do not clear p->task */
19268 +int au_do_pin(struct au_pin *p)
19271 + struct super_block *sb;
19272 + struct inode *h_dir;
19275 + sb = p->dentry->d_sb;
19276 + p->br = au_sbr(sb, p->bindex);
19277 + if (IS_ROOT(p->dentry)) {
19278 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19279 + p->h_mnt = au_br_mnt(p->br);
19280 + err = vfsub_mnt_want_write(p->h_mnt);
19281 + if (unlikely(err)) {
19282 + au_fclr_pin(p->flags, MNT_WRITE);
19289 + p->h_dentry = NULL;
19290 + if (p->bindex <= au_dbbot(p->dentry))
19291 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19293 + p->parent = dget_parent(p->dentry);
19294 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19295 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19298 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19299 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19301 + h_dir = p->hdir->hi_inode;
19305 + * if DI_LOCKED is not set, then p->parent may be different
19306 + * and h_parent can be NULL.
19308 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19310 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19311 + di_read_unlock(p->parent, AuLock_IR);
19313 + p->parent = NULL;
19317 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19318 + p->h_mnt = au_br_mnt(p->br);
19319 + err = vfsub_mnt_want_write(p->h_mnt);
19320 + if (unlikely(err)) {
19321 + au_fclr_pin(p->flags, MNT_WRITE);
19322 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19323 + di_read_unlock(p->parent, AuLock_IR);
19325 + p->parent = NULL;
19331 + err = au_pin_hdir_lock(p);
19333 + goto out; /* success */
19338 + pr_err("err %d\n", err);
19339 + err = au_busy_or_stale();
19344 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19345 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19346 + unsigned int udba, unsigned char flags)
19348 + p->dentry = dentry;
19350 + p->lsc_di = lsc_di;
19351 + p->lsc_hi = lsc_hi;
19352 + p->flags = flags;
19353 + p->bindex = bindex;
19355 + p->parent = NULL;
19359 + p->h_dentry = NULL;
19360 + p->h_parent = NULL;
19362 + p->task = current;
19365 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19366 + unsigned int udba, unsigned char flags)
19368 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19370 + return au_do_pin(pin);
19373 +/* ---------------------------------------------------------------------- */
19376 + * ->setattr() and ->getattr() are called in various cases.
19377 + * chmod, stat: dentry is revalidated.
19378 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19380 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19382 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19383 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19386 + struct dentry *parent;
19389 + if (au_digen_test(dentry, sigen)) {
19390 + parent = dget_parent(dentry);
19391 + di_read_lock_parent(parent, AuLock_IR);
19392 + err = au_refresh_dentry(dentry, parent);
19393 + di_read_unlock(parent, AuLock_IR);
19401 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19402 + struct au_icpup_args *a)
19406 + aufs_bindex_t btop, ibtop;
19407 + struct dentry *hi_wh, *parent;
19408 + struct inode *inode;
19409 + struct au_wr_dir_args wr_dir_args = {
19410 + .force_btgt = -1,
19414 + if (d_is_dir(dentry))
19415 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19416 + /* plink or hi_wh() case */
19417 + btop = au_dbtop(dentry);
19418 + inode = d_inode(dentry);
19419 + ibtop = au_ibtop(inode);
19420 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19421 + wr_dir_args.force_btgt = ibtop;
19422 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19423 + if (unlikely(err < 0))
19427 + au_fset_icpup(a->flags, DID_CPUP);
19430 + a->pin_flags = AuPin_MNT_WRITE;
19432 + if (!IS_ROOT(dentry)) {
19433 + au_fset_pin(a->pin_flags, DI_LOCKED);
19434 + parent = dget_parent(dentry);
19435 + di_write_lock_parent(parent);
19438 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19439 + if (unlikely(err))
19443 + a->h_path.dentry = au_h_dptr(dentry, btop);
19444 + a->h_inode = d_inode(a->h_path.dentry);
19445 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19446 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
19447 + if (ia->ia_size < i_size_read(a->h_inode))
19448 + sz = ia->ia_size;
19449 + inode_unlock_shared(a->h_inode);
19453 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19454 + hi_wh = au_hi_wh(inode, a->btgt);
19456 + struct au_cp_generic cpg = {
19457 + .dentry = dentry,
19463 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19464 + if (unlikely(err))
19466 + hi_wh = au_hi_wh(inode, a->btgt);
19467 + /* todo: revalidate hi_wh? */
19472 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19473 + di_downgrade_lock(parent, AuLock_IR);
19477 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19478 + goto out; /* success */
19480 + if (!d_unhashed(dentry)) {
19481 + struct au_cp_generic cpg = {
19482 + .dentry = dentry,
19487 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19489 + err = au_sio_cpup_simple(&cpg);
19491 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19492 + } else if (!hi_wh)
19493 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19495 + a->h_path.dentry = hi_wh; /* do not dget here */
19498 + a->h_inode = d_inode(a->h_path.dentry);
19500 + goto out; /* success */
19501 + au_unpin(&a->pin);
19504 + di_write_unlock(parent);
19509 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19513 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19516 + struct inode *inode, *delegated;
19517 + struct super_block *sb;
19518 + struct file *file;
19519 + struct au_icpup_args *a;
19521 + inode = d_inode(dentry);
19522 + IMustLock(inode);
19524 + err = setattr_prepare(dentry, ia);
19525 + if (unlikely(err))
19529 + a = kzalloc(sizeof(*a), GFP_NOFS);
19530 + if (unlikely(!a))
19533 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19534 + ia->ia_valid &= ~ATTR_MODE;
19537 + sb = dentry->d_sb;
19538 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19539 + if (unlikely(err))
19542 + if (ia->ia_valid & ATTR_FILE) {
19543 + /* currently ftruncate(2) only */
19544 + AuDebugOn(!d_is_reg(dentry));
19545 + file = ia->ia_file;
19546 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
19548 + if (unlikely(err))
19550 + ia->ia_file = au_hf_top(file);
19551 + a->udba = AuOpt_UDBA_NONE;
19553 + /* fchmod() doesn't pass ia_file */
19554 + a->udba = au_opt_udba(sb);
19555 + di_write_lock_child(dentry);
19556 + /* no d_unlinked(), to set UDBA_NONE for root */
19557 + if (d_unhashed(dentry))
19558 + a->udba = AuOpt_UDBA_NONE;
19559 + if (a->udba != AuOpt_UDBA_NONE) {
19560 + AuDebugOn(IS_ROOT(dentry));
19561 + err = au_reval_for_attr(dentry, au_sigen(sb));
19562 + if (unlikely(err))
19567 + err = au_pin_and_icpup(dentry, ia, a);
19568 + if (unlikely(err < 0))
19570 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19571 + ia->ia_file = NULL;
19572 + ia->ia_valid &= ~ATTR_FILE;
19575 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19576 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19577 + == (ATTR_MODE | ATTR_CTIME)) {
19578 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19579 + if (unlikely(err))
19581 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19582 + && (ia->ia_valid & ATTR_CTIME)) {
19583 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19584 + if (unlikely(err))
19588 + if (ia->ia_valid & ATTR_SIZE) {
19591 + if (ia->ia_size < i_size_read(inode))
19593 + truncate_setsize(inode, ia->ia_size);
19596 + if (ia->ia_valid & ATTR_FILE)
19598 + inode_unlock(a->h_inode);
19599 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19600 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19602 + delegated = NULL;
19604 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19606 + err = break_deleg_wait(&delegated);
19614 + * regardless aufs 'acl' option setting.
19615 + * why don't all acl-aware fs call this func from their ->setattr()?
19617 + if (!err && (ia->ia_valid & ATTR_MODE))
19618 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19620 + au_cpup_attr_changeable(inode);
19623 + inode_unlock(a->h_inode);
19624 + au_unpin(&a->pin);
19625 + if (unlikely(err))
19626 + au_update_dbtop(dentry);
19628 + di_write_unlock(dentry);
19630 + fi_write_unlock(file);
19631 + ia->ia_file = file;
19632 + ia->ia_valid |= ATTR_FILE;
19635 + si_read_unlock(sb);
19643 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19644 +static int au_h_path_to_set_attr(struct dentry *dentry,
19645 + struct au_icpup_args *a, struct path *h_path)
19648 + struct super_block *sb;
19650 + sb = dentry->d_sb;
19651 + a->udba = au_opt_udba(sb);
19652 + /* no d_unlinked(), to set UDBA_NONE for root */
19653 + if (d_unhashed(dentry))
19654 + a->udba = AuOpt_UDBA_NONE;
19655 + if (a->udba != AuOpt_UDBA_NONE) {
19656 + AuDebugOn(IS_ROOT(dentry));
19657 + err = au_reval_for_attr(dentry, au_sigen(sb));
19658 + if (unlikely(err))
19661 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19662 + if (unlikely(err < 0))
19665 + h_path->dentry = a->h_path.dentry;
19666 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19672 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19673 + struct au_sxattr *arg)
19676 + struct path h_path;
19677 + struct super_block *sb;
19678 + struct au_icpup_args *a;
19679 + struct inode *h_inode;
19681 + IMustLock(inode);
19684 + a = kzalloc(sizeof(*a), GFP_NOFS);
19685 + if (unlikely(!a))
19688 + sb = dentry->d_sb;
19689 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19690 + if (unlikely(err))
19693 + h_path.dentry = NULL; /* silence gcc */
19694 + di_write_lock_child(dentry);
19695 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19696 + if (unlikely(err))
19699 + inode_unlock(a->h_inode);
19700 + switch (arg->type) {
19701 + case AU_XATTR_SET:
19702 + AuDebugOn(d_is_negative(h_path.dentry));
19703 + err = vfsub_setxattr(h_path.dentry,
19704 + arg->u.set.name, arg->u.set.value,
19705 + arg->u.set.size, arg->u.set.flags);
19708 + err = -EOPNOTSUPP;
19709 + h_inode = d_inode(h_path.dentry);
19710 + if (h_inode->i_op->set_acl)
19711 + /* this will call posix_acl_update_mode */
19712 + err = h_inode->i_op->set_acl(h_inode,
19713 + arg->u.acl_set.acl,
19714 + arg->u.acl_set.type);
19718 + au_cpup_attr_timesizes(inode);
19720 + au_unpin(&a->pin);
19721 + if (unlikely(err))
19722 + au_update_dbtop(dentry);
19725 + di_write_unlock(dentry);
19726 + si_read_unlock(sb);
19735 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19736 + unsigned int nlink)
19740 + inode->i_mode = st->mode;
19741 + /* don't i_[ug]id_write() here */
19742 + inode->i_uid = st->uid;
19743 + inode->i_gid = st->gid;
19744 + inode->i_atime = st->atime;
19745 + inode->i_mtime = st->mtime;
19746 + inode->i_ctime = st->ctime;
19748 + au_cpup_attr_nlink(inode, /*force*/0);
19749 + if (S_ISDIR(inode->i_mode)) {
19750 + n = inode->i_nlink;
19753 + smp_mb(); /* for i_nlink */
19754 + /* 0 can happen */
19755 + set_nlink(inode, n);
19758 + spin_lock(&inode->i_lock);
19759 + inode->i_blocks = st->blocks;
19760 + i_size_write(inode, st->size);
19761 + spin_unlock(&inode->i_lock);
19765 + * common routine for aufs_getattr() and au_getxattr().
19766 + * returns zero or negative (an error).
19767 + * @dentry will be read-locked in success.
19769 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19773 + unsigned int mnt_flags, sigen;
19774 + unsigned char udba_none;
19775 + aufs_bindex_t bindex;
19776 + struct super_block *sb, *h_sb;
19777 + struct inode *inode;
19779 + h_path->mnt = NULL;
19780 + h_path->dentry = NULL;
19783 + sb = dentry->d_sb;
19784 + mnt_flags = au_mntflags(sb);
19785 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19787 + if (unlikely(locked))
19788 + goto body; /* skip locking dinfo */
19790 + /* support fstat(2) */
19791 + if (!d_unlinked(dentry) && !udba_none) {
19792 + sigen = au_sigen(sb);
19793 + err = au_digen_test(dentry, sigen);
19795 + di_read_lock_child(dentry, AuLock_IR);
19796 + err = au_dbrange_test(dentry);
19797 + if (unlikely(err)) {
19798 + di_read_unlock(dentry, AuLock_IR);
19802 + AuDebugOn(IS_ROOT(dentry));
19803 + di_write_lock_child(dentry);
19804 + err = au_dbrange_test(dentry);
19806 + err = au_reval_for_attr(dentry, sigen);
19808 + di_downgrade_lock(dentry, AuLock_IR);
19810 + di_write_unlock(dentry);
19815 + di_read_lock_child(dentry, AuLock_IR);
19818 + inode = d_inode(dentry);
19819 + bindex = au_ibtop(inode);
19820 + h_path->mnt = au_sbr_mnt(sb, bindex);
19821 + h_sb = h_path->mnt->mnt_sb;
19823 + && !au_test_fs_bad_iattr(h_sb)
19825 + goto out; /* success */
19827 + if (au_dbtop(dentry) == bindex)
19828 + h_path->dentry = au_h_dptr(dentry, bindex);
19829 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19830 + h_path->dentry = au_plink_lkup(inode, bindex);
19831 + if (IS_ERR(h_path->dentry))
19832 + /* pretending success */
19833 + h_path->dentry = NULL;
19835 + dput(h_path->dentry);
19842 +static int aufs_getattr(const struct path *path, struct kstat *st,
19843 + u32 request, unsigned int query)
19846 + unsigned char positive;
19847 + struct path h_path;
19848 + struct dentry *dentry;
19849 + struct inode *inode;
19850 + struct super_block *sb;
19852 + dentry = path->dentry;
19853 + inode = d_inode(dentry);
19854 + sb = dentry->d_sb;
19855 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19856 + if (unlikely(err))
19858 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
19859 + if (unlikely(err))
19861 + if (unlikely(!h_path.dentry))
19862 + /* illegally overlapped or something */
19863 + goto out_fill; /* pretending success */
19865 + positive = d_is_positive(h_path.dentry);
19867 + /* no vfsub version */
19868 + err = vfs_getattr(&h_path, st, request, query);
19871 + au_refresh_iattr(inode, st,
19872 + d_inode(h_path.dentry)->i_nlink);
19873 + goto out_fill; /* success */
19879 + generic_fillattr(inode, st);
19881 + di_read_unlock(dentry, AuLock_IR);
19883 + si_read_unlock(sb);
19889 +/* ---------------------------------------------------------------------- */
19891 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19892 + struct delayed_call *done)
19895 + struct dentry *h_dentry;
19896 + struct inode *h_inode;
19898 + aufs_bindex_t bindex;
19900 + ret = NULL; /* suppress a warning */
19905 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19906 + if (unlikely(err))
19909 + err = au_d_hashed_positive(dentry);
19910 + if (unlikely(err))
19914 + inode = d_inode(dentry);
19915 + bindex = au_ibtop(inode);
19916 + h_inode = au_h_iptr(inode, bindex);
19917 + if (unlikely(!h_inode->i_op->get_link))
19922 + if (au_dbtop(dentry) <= bindex) {
19923 + h_dentry = au_h_dptr(dentry, bindex);
19928 + h_dentry = d_find_any_alias(h_inode);
19929 + if (IS_ERR(h_dentry)) {
19930 + err = PTR_ERR(h_dentry);
19934 + if (unlikely(!h_dentry))
19938 + AuDbg("%pf\n", h_inode->i_op->get_link);
19939 + AuDbgDentry(h_dentry);
19940 + ret = vfs_get_link(h_dentry, done);
19943 + err = PTR_ERR(ret);
19946 + aufs_read_unlock(dentry, AuLock_IR);
19948 + if (unlikely(err))
19949 + ret = ERR_PTR(err);
19950 + AuTraceErrPtr(ret);
19954 +/* ---------------------------------------------------------------------- */
19956 +static int au_is_special(struct inode *inode)
19958 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19961 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19964 + aufs_bindex_t bindex;
19965 + struct super_block *sb;
19966 + struct inode *h_inode;
19967 + struct vfsmount *h_mnt;
19969 + sb = inode->i_sb;
19970 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19971 + "unexpected s_flags 0x%lx", sb->s_flags);
19973 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19975 + si_read_lock(sb, AuLock_FLUSH);
19976 + ii_write_lock_child(inode);
19980 + bindex = au_ibtop(inode);
19981 + h_inode = au_h_iptr(inode, bindex);
19982 + if (!au_test_ro(sb, bindex, inode)) {
19983 + h_mnt = au_sbr_mnt(sb, bindex);
19984 + err = vfsub_mnt_want_write(h_mnt);
19986 + err = vfsub_update_time(h_inode, ts, flags);
19987 + vfsub_mnt_drop_write(h_mnt);
19989 + } else if (au_is_special(h_inode)) {
19991 + * Never copy-up here.
19992 + * These special files may already be opened and used for
19993 + * communicating. If we copied it up, then the communication
19994 + * would be corrupted.
19996 + AuWarn1("timestamps for i%lu are ignored "
19997 + "since it is on readonly branch (hi%lu).\n",
19998 + inode->i_ino, h_inode->i_ino);
19999 + } else if (flags & ~S_ATIME) {
20001 + AuIOErr1("unexpected flags 0x%x\n", flags);
20007 + au_cpup_attr_timesizes(inode);
20008 + ii_write_unlock(inode);
20009 + si_read_unlock(sb);
20012 + if (!err && (flags & S_VERSION))
20013 + inode_inc_iversion(inode);
20018 +/* ---------------------------------------------------------------------- */
20020 +/* no getattr version will be set by module.c:aufs_init() */
20021 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
20023 + [AuIop_SYMLINK] = {
20024 + .permission = aufs_permission,
20025 +#ifdef CONFIG_FS_POSIX_ACL
20026 + .get_acl = aufs_get_acl,
20027 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
20030 + .setattr = aufs_setattr,
20031 + .getattr = aufs_getattr,
20033 +#ifdef CONFIG_AUFS_XATTR
20034 + .listxattr = aufs_listxattr,
20037 + .get_link = aufs_get_link,
20039 + /* .update_time = aufs_update_time */
20042 + .create = aufs_create,
20043 + .lookup = aufs_lookup,
20044 + .link = aufs_link,
20045 + .unlink = aufs_unlink,
20046 + .symlink = aufs_symlink,
20047 + .mkdir = aufs_mkdir,
20048 + .rmdir = aufs_rmdir,
20049 + .mknod = aufs_mknod,
20050 + .rename = aufs_rename,
20052 + .permission = aufs_permission,
20053 +#ifdef CONFIG_FS_POSIX_ACL
20054 + .get_acl = aufs_get_acl,
20055 + .set_acl = aufs_set_acl,
20058 + .setattr = aufs_setattr,
20059 + .getattr = aufs_getattr,
20061 +#ifdef CONFIG_AUFS_XATTR
20062 + .listxattr = aufs_listxattr,
20065 + .update_time = aufs_update_time,
20066 + .atomic_open = aufs_atomic_open,
20067 + .tmpfile = aufs_tmpfile
20069 + [AuIop_OTHER] = {
20070 + .permission = aufs_permission,
20071 +#ifdef CONFIG_FS_POSIX_ACL
20072 + .get_acl = aufs_get_acl,
20073 + .set_acl = aufs_set_acl,
20076 + .setattr = aufs_setattr,
20077 + .getattr = aufs_getattr,
20079 +#ifdef CONFIG_AUFS_XATTR
20080 + .listxattr = aufs_listxattr,
20083 + .update_time = aufs_update_time
20086 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
20087 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
20088 +++ linux/fs/aufs/i_op_del.c 2017-07-29 12:14:25.903042072 +0200
20091 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20093 + * This program, aufs is free software; you can redistribute it and/or modify
20094 + * it under the terms of the GNU General Public License as published by
20095 + * the Free Software Foundation; either version 2 of the License, or
20096 + * (at your option) any later version.
20098 + * This program is distributed in the hope that it will be useful,
20099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20101 + * GNU General Public License for more details.
20103 + * You should have received a copy of the GNU General Public License
20104 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20108 + * inode operations (del entry)
20114 + * decide if a new whiteout for @dentry is necessary or not.
20115 + * when it is necessary, prepare the parent dir for the upper branch whose
20116 + * branch index is @bcpup for creation. the actual creation of the whiteout will
20117 + * be done by caller.
20119 + * 0: wh is unnecessary
20120 + * plus: wh is necessary
20123 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
20125 + int need_wh, err;
20126 + aufs_bindex_t btop;
20127 + struct super_block *sb;
20129 + sb = dentry->d_sb;
20130 + btop = au_dbtop(dentry);
20131 + if (*bcpup < 0) {
20133 + if (au_test_ro(sb, btop, d_inode(dentry))) {
20134 + err = AuWbrCopyup(au_sbi(sb), dentry);
20136 + if (unlikely(err < 0))
20140 + AuDebugOn(btop < *bcpup
20141 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
20142 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
20144 + if (*bcpup != btop) {
20145 + err = au_cpup_dirs(dentry, *bcpup);
20146 + if (unlikely(err))
20150 + struct au_dinfo *dinfo, *tmp;
20152 + need_wh = -ENOMEM;
20153 + dinfo = au_di(dentry);
20154 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
20156 + au_di_cp(tmp, dinfo);
20157 + au_di_swap(tmp, dinfo);
20158 + /* returns the number of positive dentries */
20159 + need_wh = au_lkup_dentry(dentry, btop + 1,
20160 + /* AuLkup_IGNORE_PERM */ 0);
20161 + au_di_swap(tmp, dinfo);
20162 + au_rw_write_unlock(&tmp->di_rwsem);
20166 + AuDbg("need_wh %d\n", need_wh);
20174 + * simple tests for the del-entry operations.
20175 + * following the checks in vfs, plus the parent-child relationship.
20177 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20178 + struct dentry *h_parent, int isdir)
20182 + struct dentry *h_dentry, *h_latest;
20183 + struct inode *h_inode;
20185 + h_dentry = au_h_dptr(dentry, bindex);
20186 + if (d_really_is_positive(dentry)) {
20188 + if (unlikely(d_is_negative(h_dentry)))
20190 + h_inode = d_inode(h_dentry);
20191 + if (unlikely(!h_inode->i_nlink))
20194 + h_mode = h_inode->i_mode;
20197 + if (unlikely(S_ISDIR(h_mode)))
20199 + } else if (unlikely(!S_ISDIR(h_mode))) {
20204 + /* rename(2) case */
20206 + if (unlikely(d_is_positive(h_dentry)))
20211 + /* expected parent dir is locked */
20212 + if (unlikely(h_parent != h_dentry->d_parent))
20217 + * rmdir a dir may break the consistency on some filesystem.
20218 + * let's try heavy test.
20221 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20222 + && au_test_h_perm(d_inode(h_parent),
20223 + MAY_EXEC | MAY_WRITE)))
20226 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20228 + if (IS_ERR(h_latest))
20230 + if (h_latest == h_dentry)
20239 + * decide the branch where we operate for @dentry. the branch index will be set
20240 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20241 + * dir for reverting.
20242 + * when a new whiteout is necessary, create it.
20244 +static struct dentry*
20245 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20246 + struct au_dtime *dt, struct au_pin *pin)
20248 + struct dentry *wh_dentry;
20249 + struct super_block *sb;
20250 + struct path h_path;
20251 + int err, need_wh;
20252 + unsigned int udba;
20253 + aufs_bindex_t bcpup;
20255 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20256 + wh_dentry = ERR_PTR(need_wh);
20257 + if (unlikely(need_wh < 0))
20260 + sb = dentry->d_sb;
20261 + udba = au_opt_udba(sb);
20263 + err = au_pin(pin, dentry, bcpup, udba,
20264 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20265 + wh_dentry = ERR_PTR(err);
20266 + if (unlikely(err))
20269 + h_path.dentry = au_pinned_h_parent(pin);
20270 + if (udba != AuOpt_UDBA_NONE
20271 + && au_dbtop(dentry) == bcpup) {
20272 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20273 + wh_dentry = ERR_PTR(err);
20274 + if (unlikely(err))
20278 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20279 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20280 + wh_dentry = NULL;
20282 + goto out; /* success, no need to create whiteout */
20284 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20285 + if (IS_ERR(wh_dentry))
20288 + /* returns with the parent is locked and wh_dentry is dget-ed */
20289 + goto out; /* success */
20294 + return wh_dentry;
20298 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20299 + * in order to be revertible and save time for removing many child whiteouts
20301 + * returns 1 when there are too many child whiteout and caller should remove
20302 + * them asynchronously. returns 0 when the number of children is enough small to
20303 + * remove now or the branch fs is a remote fs.
20304 + * otherwise return an error.
20306 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20307 + struct au_nhash *whlist, struct inode *dir)
20309 + int rmdir_later, err, dirwh;
20310 + struct dentry *h_dentry;
20311 + struct super_block *sb;
20312 + struct inode *inode;
20314 + sb = dentry->d_sb;
20315 + SiMustAnyLock(sb);
20316 + h_dentry = au_h_dptr(dentry, bindex);
20317 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20318 + if (unlikely(err))
20321 + /* stop monitoring */
20322 + inode = d_inode(dentry);
20323 + au_hn_free(au_hi(inode, bindex));
20325 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20326 + dirwh = au_sbi(sb)->si_dirwh;
20327 + rmdir_later = (dirwh <= 1);
20328 + if (!rmdir_later)
20329 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20332 + return rmdir_later;
20335 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20336 + if (unlikely(err)) {
20337 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20338 + h_dentry, bindex, err);
20348 + * final procedure for deleting a entry.
20349 + * maintain dentry and iattr.
20351 +static void epilog(struct inode *dir, struct dentry *dentry,
20352 + aufs_bindex_t bindex)
20354 + struct inode *inode;
20356 + inode = d_inode(dentry);
20358 + inode->i_ctime = dir->i_ctime;
20360 + au_dir_ts(dir, bindex);
20361 + dir->i_version++;
20365 + * when an error happened, remove the created whiteout and revert everything.
20367 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20368 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20369 + struct dentry *dentry, struct au_dtime *dt)
20372 + struct path h_path = {
20373 + .dentry = wh_dentry,
20374 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20377 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20379 + au_set_dbwh(dentry, bwh);
20380 + au_dtime_revert(dt);
20384 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20388 +/* ---------------------------------------------------------------------- */
20390 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20393 + aufs_bindex_t bwh, bindex, btop;
20394 + struct inode *inode, *h_dir, *delegated;
20395 + struct dentry *parent, *wh_dentry;
20396 + /* to reuduce stack size */
20398 + struct au_dtime dt;
20399 + struct au_pin pin;
20400 + struct path h_path;
20406 + a = kmalloc(sizeof(*a), GFP_NOFS);
20407 + if (unlikely(!a))
20410 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20411 + if (unlikely(err))
20413 + err = au_d_hashed_positive(dentry);
20414 + if (unlikely(err))
20416 + inode = d_inode(dentry);
20417 + IMustLock(inode);
20419 + if (unlikely(d_is_dir(dentry)))
20420 + goto out_unlock; /* possible? */
20422 + btop = au_dbtop(dentry);
20423 + bwh = au_dbwh(dentry);
20425 + parent = dentry->d_parent; /* dir inode is locked */
20426 + di_write_lock_parent(parent);
20427 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20429 + err = PTR_ERR(wh_dentry);
20430 + if (IS_ERR(wh_dentry))
20433 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20434 + a->h_path.dentry = au_h_dptr(dentry, btop);
20435 + dget(a->h_path.dentry);
20436 + if (bindex == btop) {
20437 + h_dir = au_pinned_h_dir(&a->pin);
20438 + delegated = NULL;
20439 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20440 + if (unlikely(err == -EWOULDBLOCK)) {
20441 + pr_warn("cannot retry for NFSv4 delegation"
20442 + " for an internal unlink\n");
20446 + /* dir inode is locked */
20447 + h_dir = d_inode(wh_dentry->d_parent);
20448 + IMustLock(h_dir);
20453 + vfsub_drop_nlink(inode);
20454 + epilog(dir, dentry, bindex);
20456 + /* update target timestamps */
20457 + if (bindex == btop) {
20458 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20460 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20462 + /* todo: this timestamp may be reverted later */
20463 + inode->i_ctime = h_dir->i_ctime;
20464 + goto out_unpin; /* success */
20471 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20478 + au_unpin(&a->pin);
20480 + dput(a->h_path.dentry);
20482 + di_write_unlock(parent);
20484 + aufs_read_unlock(dentry, AuLock_DW);
20491 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20493 + int err, rmdir_later;
20494 + aufs_bindex_t bwh, bindex, btop;
20495 + struct inode *inode;
20496 + struct dentry *parent, *wh_dentry, *h_dentry;
20497 + struct au_whtmp_rmdir *args;
20498 + /* to reuduce stack size */
20500 + struct au_dtime dt;
20501 + struct au_pin pin;
20507 + a = kmalloc(sizeof(*a), GFP_NOFS);
20508 + if (unlikely(!a))
20511 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20512 + if (unlikely(err))
20514 + err = au_alive_dir(dentry);
20515 + if (unlikely(err))
20517 + inode = d_inode(dentry);
20518 + IMustLock(inode);
20520 + if (unlikely(!d_is_dir(dentry)))
20521 + goto out_unlock; /* possible? */
20524 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20525 + if (unlikely(!args))
20528 + parent = dentry->d_parent; /* dir inode is locked */
20529 + di_write_lock_parent(parent);
20530 + err = au_test_empty(dentry, &args->whlist);
20531 + if (unlikely(err))
20534 + btop = au_dbtop(dentry);
20535 + bwh = au_dbwh(dentry);
20537 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20539 + err = PTR_ERR(wh_dentry);
20540 + if (IS_ERR(wh_dentry))
20543 + h_dentry = au_h_dptr(dentry, btop);
20546 + if (bindex == btop) {
20547 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20549 + rmdir_later = err;
20553 + /* stop monitoring */
20554 + au_hn_free(au_hi(inode, btop));
20556 + /* dir inode is locked */
20557 + IMustLock(d_inode(wh_dentry->d_parent));
20562 + vfsub_dead_dir(inode);
20563 + au_set_dbdiropq(dentry, -1);
20564 + epilog(dir, dentry, bindex);
20566 + if (rmdir_later) {
20567 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20571 + goto out_unpin; /* success */
20579 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20586 + au_unpin(&a->pin);
20590 + di_write_unlock(parent);
20592 + au_whtmp_rmdir_free(args);
20594 + aufs_read_unlock(dentry, AuLock_DW);
20601 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20602 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20603 +++ linux/fs/aufs/i_op_ren.c 2017-07-29 12:14:25.903042072 +0200
20606 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20608 + * This program, aufs is free software; you can redistribute it and/or modify
20609 + * it under the terms of the GNU General Public License as published by
20610 + * the Free Software Foundation; either version 2 of the License, or
20611 + * (at your option) any later version.
20613 + * This program is distributed in the hope that it will be useful,
20614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20616 + * GNU General Public License for more details.
20618 + * You should have received a copy of the GNU General Public License
20619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20623 + * inode operation (rename entry)
20624 + * todo: this is crazy monster
20629 +enum { AuSRC, AuDST, AuSrcDst };
20630 +enum { AuPARENT, AuCHILD, AuParentChild };
20632 +#define AuRen_ISDIR_SRC 1
20633 +#define AuRen_ISDIR_DST (1 << 1)
20634 +#define AuRen_ISSAMEDIR (1 << 2)
20635 +#define AuRen_WHSRC (1 << 3)
20636 +#define AuRen_WHDST (1 << 4)
20637 +#define AuRen_MNT_WRITE (1 << 5)
20638 +#define AuRen_DT_DSTDIR (1 << 6)
20639 +#define AuRen_DIROPQ_SRC (1 << 7)
20640 +#define AuRen_DIROPQ_DST (1 << 8)
20641 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20642 +#define au_fset_ren(flags, name) \
20643 + do { (flags) |= AuRen_##name; } while (0)
20644 +#define au_fclr_ren(flags, name) \
20645 + do { (flags) &= ~AuRen_##name; } while (0)
20647 +struct au_ren_args {
20649 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20651 + struct inode *dir, *inode;
20652 + struct au_hinode *hdir, *hinode;
20653 + struct au_dtime dt[AuParentChild];
20654 + aufs_bindex_t btop, bdiropq;
20657 +#define src_dentry sd[AuSRC].dentry
20658 +#define src_dir sd[AuSRC].dir
20659 +#define src_inode sd[AuSRC].inode
20660 +#define src_h_dentry sd[AuSRC].h_dentry
20661 +#define src_parent sd[AuSRC].parent
20662 +#define src_h_parent sd[AuSRC].h_parent
20663 +#define src_wh_dentry sd[AuSRC].wh_dentry
20664 +#define src_hdir sd[AuSRC].hdir
20665 +#define src_hinode sd[AuSRC].hinode
20666 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20667 +#define src_dt sd[AuSRC].dt
20668 +#define src_btop sd[AuSRC].btop
20669 +#define src_bdiropq sd[AuSRC].bdiropq
20671 +#define dst_dentry sd[AuDST].dentry
20672 +#define dst_dir sd[AuDST].dir
20673 +#define dst_inode sd[AuDST].inode
20674 +#define dst_h_dentry sd[AuDST].h_dentry
20675 +#define dst_parent sd[AuDST].parent
20676 +#define dst_h_parent sd[AuDST].h_parent
20677 +#define dst_wh_dentry sd[AuDST].wh_dentry
20678 +#define dst_hdir sd[AuDST].hdir
20679 +#define dst_hinode sd[AuDST].hinode
20680 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20681 +#define dst_dt sd[AuDST].dt
20682 +#define dst_btop sd[AuDST].btop
20683 +#define dst_bdiropq sd[AuDST].bdiropq
20685 + struct dentry *h_trap;
20686 + struct au_branch *br;
20687 + struct path h_path;
20688 + struct au_nhash whlist;
20689 + aufs_bindex_t btgt, src_bwh;
20692 + unsigned short auren_flags;
20693 + unsigned char flags; /* syscall parameter */
20694 + unsigned char exchange;
20697 + struct au_whtmp_rmdir *thargs;
20698 + struct dentry *h_dst;
20701 +/* ---------------------------------------------------------------------- */
20704 + * functions for reverting.
20705 + * when an error happened in a single rename systemcall, we should revert
20706 + * everything as if nothing happened.
20707 + * we don't need to revert the copied-up/down the parent dir since they are
20711 +#define RevertFailure(fmt, ...) do { \
20712 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20713 + ##__VA_ARGS__, err, rerr); \
20717 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20720 + struct dentry *d;
20721 +#define src_or_dst(member) a->sd[idx].member
20723 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20724 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20725 + rerr = au_diropq_remove(d, a->btgt);
20726 + au_hn_inode_unlock(src_or_dst(hinode));
20727 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20729 + RevertFailure("remove diropq %pd", d);
20731 +#undef src_or_dst_
20734 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20736 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20737 + au_ren_do_rev_diropq(err, a, AuSRC);
20738 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20739 + au_ren_do_rev_diropq(err, a, AuDST);
20742 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20745 + struct inode *delegated;
20747 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20748 + a->src_h_parent);
20749 + rerr = PTR_ERR(a->h_path.dentry);
20750 + if (IS_ERR(a->h_path.dentry)) {
20751 + RevertFailure("lkup one %pd", a->src_dentry);
20755 + delegated = NULL;
20756 + rerr = vfsub_rename(a->dst_h_dir,
20757 + au_h_dptr(a->src_dentry, a->btgt),
20758 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20759 + if (unlikely(rerr == -EWOULDBLOCK)) {
20760 + pr_warn("cannot retry for NFSv4 delegation"
20761 + " for an internal rename\n");
20764 + d_drop(a->h_path.dentry);
20765 + dput(a->h_path.dentry);
20766 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20768 + RevertFailure("rename %pd", a->src_dentry);
20771 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20774 + struct inode *delegated;
20776 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20777 + a->dst_h_parent);
20778 + rerr = PTR_ERR(a->h_path.dentry);
20779 + if (IS_ERR(a->h_path.dentry)) {
20780 + RevertFailure("lkup one %pd", a->dst_dentry);
20783 + if (d_is_positive(a->h_path.dentry)) {
20784 + d_drop(a->h_path.dentry);
20785 + dput(a->h_path.dentry);
20789 + delegated = NULL;
20790 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20791 + &delegated, a->flags);
20792 + if (unlikely(rerr == -EWOULDBLOCK)) {
20793 + pr_warn("cannot retry for NFSv4 delegation"
20794 + " for an internal rename\n");
20797 + d_drop(a->h_path.dentry);
20798 + dput(a->h_path.dentry);
20800 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20802 + RevertFailure("rename %pd", a->h_dst);
20805 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20809 + a->h_path.dentry = a->src_wh_dentry;
20810 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20811 + au_set_dbwh(a->src_dentry, a->src_bwh);
20813 + RevertFailure("unlink %pd", a->src_wh_dentry);
20815 +#undef RevertFailure
20817 +/* ---------------------------------------------------------------------- */
20820 + * when we have to copyup the renaming entry, do it with the rename-target name
20821 + * in order to minimize the cost (the later actual rename is unnecessary).
20822 + * otherwise rename it on the target branch.
20824 +static int au_ren_or_cpup(struct au_ren_args *a)
20827 + struct dentry *d;
20828 + struct inode *delegated;
20830 + d = a->src_dentry;
20831 + if (au_dbtop(d) == a->btgt) {
20832 + a->h_path.dentry = a->dst_h_dentry;
20833 + AuDebugOn(au_dbtop(d) != a->btgt);
20834 + delegated = NULL;
20835 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20836 + a->dst_h_dir, &a->h_path, &delegated,
20838 + if (unlikely(err == -EWOULDBLOCK)) {
20839 + pr_warn("cannot retry for NFSv4 delegation"
20840 + " for an internal rename\n");
20846 + if (!err && a->h_dst)
20847 + /* it will be set to dinfo later */
20853 +/* cf. aufs_rmdir() */
20854 +static int au_ren_del_whtmp(struct au_ren_args *a)
20857 + struct inode *dir;
20859 + dir = a->dst_dir;
20860 + SiMustAnyLock(dir->i_sb);
20861 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20862 + au_sbi(dir->i_sb)->si_dirwh)
20863 + || au_test_fs_remote(a->h_dst->d_sb)) {
20864 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20865 + if (unlikely(err))
20866 + pr_warn("failed removing whtmp dir %pd (%d), "
20867 + "ignored.\n", a->h_dst, err);
20869 + au_nhash_wh_free(&a->thargs->whlist);
20870 + a->thargs->whlist = a->whlist;
20871 + a->whlist.nh_num = 0;
20872 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20874 + a->thargs = NULL;
20880 +/* make it 'opaque' dir. */
20881 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20884 + struct dentry *d, *diropq;
20885 +#define src_or_dst(member) a->sd[idx].member
20888 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20889 + src_or_dst(bdiropq) = au_dbdiropq(d);
20890 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20891 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20892 + diropq = au_diropq_create(d, a->btgt);
20893 + au_hn_inode_unlock(src_or_dst(hinode));
20894 + if (IS_ERR(diropq))
20895 + err = PTR_ERR(diropq);
20899 +#undef src_or_dst_
20903 +static int au_ren_diropq(struct au_ren_args *a)
20906 + unsigned char always;
20907 + struct dentry *d;
20910 + d = a->dst_dentry; /* already renamed on the branch */
20911 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20912 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20913 + && a->btgt != au_dbdiropq(a->src_dentry)
20914 + && (a->dst_wh_dentry
20915 + || a->btgt <= au_dbdiropq(d)
20916 + /* hide the lower to keep xino */
20917 + /* the lowers may not be a dir, but we hide them anyway */
20918 + || a->btgt < au_dbbot(d)
20921 + err = au_ren_do_diropq(a, AuSRC);
20922 + if (unlikely(err))
20924 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20926 + if (!a->exchange)
20927 + goto out; /* success */
20929 + d = a->src_dentry; /* already renamed on the branch */
20930 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20931 + && a->btgt != au_dbdiropq(a->dst_dentry)
20932 + && (a->btgt < au_dbdiropq(d)
20933 + || a->btgt < au_dbbot(d)
20935 + AuDbgDentry(a->src_dentry);
20936 + AuDbgDentry(a->dst_dentry);
20937 + err = au_ren_do_diropq(a, AuDST);
20938 + if (unlikely(err))
20939 + goto out_rev_src;
20940 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20942 + goto out; /* success */
20945 + AuDbg("err %d, reverting src\n", err);
20946 + au_ren_rev_diropq(err, a);
20951 +static int do_rename(struct au_ren_args *a)
20954 + struct dentry *d, *h_d;
20956 + if (!a->exchange) {
20957 + /* prepare workqueue args for asynchronous rmdir */
20958 + h_d = a->dst_h_dentry;
20959 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20960 + && d_is_positive(h_d)) {
20962 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20964 + if (unlikely(!a->thargs))
20966 + a->h_dst = dget(h_d);
20969 + /* create whiteout for src_dentry */
20970 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20971 + a->src_bwh = au_dbwh(a->src_dentry);
20972 + AuDebugOn(a->src_bwh >= 0);
20973 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20974 + a->src_h_parent);
20975 + err = PTR_ERR(a->src_wh_dentry);
20976 + if (IS_ERR(a->src_wh_dentry))
20980 + /* lookup whiteout for dentry */
20981 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20982 + h_d = au_wh_lkup(a->dst_h_parent,
20983 + &a->dst_dentry->d_name, a->br);
20984 + err = PTR_ERR(h_d);
20987 + if (d_is_negative(h_d))
20990 + a->dst_wh_dentry = h_d;
20993 + /* rename dentry to tmpwh */
20995 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20996 + if (unlikely(err))
20999 + d = a->dst_dentry;
21000 + au_set_h_dptr(d, a->btgt, NULL);
21001 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
21002 + if (unlikely(err))
21004 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
21008 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
21010 + /* rename by vfs_rename or cpup */
21011 + err = au_ren_or_cpup(a);
21012 + if (unlikely(err))
21013 + /* leave the copied-up one */
21016 + /* make dir opaque */
21017 + err = au_ren_diropq(a);
21018 + if (unlikely(err))
21021 + /* update target timestamps */
21022 + if (a->exchange) {
21023 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
21024 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
21025 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21026 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21028 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
21029 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
21030 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21031 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21033 + if (!a->exchange) {
21034 + /* remove whiteout for dentry */
21035 + if (a->dst_wh_dentry) {
21036 + a->h_path.dentry = a->dst_wh_dentry;
21037 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
21039 + if (unlikely(err))
21043 + /* remove whtmp */
21045 + au_ren_del_whtmp(a); /* ignore this error */
21047 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
21050 + goto out_success;
21053 + au_ren_rev_diropq(err, a);
21055 + au_ren_rev_rename(err, a);
21059 + au_ren_rev_whtmp(err, a);
21061 + dput(a->dst_wh_dentry);
21062 + a->dst_wh_dentry = NULL;
21064 + if (a->src_wh_dentry)
21065 + au_ren_rev_whsrc(err, a);
21067 + dput(a->src_wh_dentry);
21068 + dput(a->dst_wh_dentry);
21072 + au_whtmp_rmdir_free(a->thargs);
21073 + a->thargs = NULL;
21079 +/* ---------------------------------------------------------------------- */
21082 + * test if @dentry dir can be rename destination or not.
21083 + * success means, it is a logically empty dir.
21085 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
21087 + return au_test_empty(dentry, whlist);
21091 + * test if @dentry dir can be rename source or not.
21092 + * if it can, return 0 and @children is filled.
21094 + * - it is a logically empty dir.
21095 + * - or, it exists on writable branch and has no children including whiteouts
21096 + * on the lower branch.
21098 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
21101 + unsigned int rdhash;
21102 + aufs_bindex_t btop;
21104 + btop = au_dbtop(dentry);
21105 + if (btop != btgt) {
21106 + struct au_nhash whlist;
21108 + SiMustAnyLock(dentry->d_sb);
21109 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
21111 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
21113 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
21114 + if (unlikely(err))
21116 + err = au_test_empty(dentry, &whlist);
21117 + au_nhash_wh_free(&whlist);
21121 + if (btop == au_dbtaildir(dentry))
21122 + return 0; /* success */
21124 + err = au_test_empty_lower(dentry);
21127 + if (err == -ENOTEMPTY) {
21128 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
21129 + " is not supported\n");
21135 +/* side effect: sets whlist and h_dentry */
21136 +static int au_ren_may_dir(struct au_ren_args *a)
21139 + unsigned int rdhash;
21140 + struct dentry *d;
21142 + d = a->dst_dentry;
21143 + SiMustAnyLock(d->d_sb);
21146 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
21147 + rdhash = au_sbi(d->d_sb)->si_rdhash;
21149 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
21150 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
21151 + if (unlikely(err))
21154 + if (!a->exchange) {
21155 + au_set_dbtop(d, a->dst_btop);
21156 + err = may_rename_dstdir(d, &a->whlist);
21157 + au_set_dbtop(d, a->btgt);
21159 + err = may_rename_srcdir(d, a->btgt);
21161 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
21162 + if (unlikely(err))
21165 + d = a->src_dentry;
21166 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
21167 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21168 + err = may_rename_srcdir(d, a->btgt);
21169 + if (unlikely(err)) {
21170 + au_nhash_wh_free(&a->whlist);
21171 + a->whlist.nh_num = 0;
21178 +/* ---------------------------------------------------------------------- */
21181 + * simple tests for rename.
21182 + * following the checks in vfs, plus the parent-child relationship.
21184 +static int au_may_ren(struct au_ren_args *a)
21187 + struct inode *h_inode;
21189 + if (a->src_btop == a->btgt) {
21190 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
21191 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
21192 + if (unlikely(err))
21195 + if (unlikely(a->src_h_dentry == a->h_trap))
21200 + if (a->dst_btop != a->btgt)
21203 + err = -ENOTEMPTY;
21204 + if (unlikely(a->dst_h_dentry == a->h_trap))
21208 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21209 + if (d_really_is_negative(a->dst_dentry)) {
21210 + if (d_is_negative(a->dst_h_dentry))
21211 + err = au_may_add(a->dst_dentry, a->btgt,
21212 + a->dst_h_parent, isdir);
21214 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21216 + h_inode = d_inode(a->dst_h_dentry);
21217 + if (h_inode->i_nlink)
21218 + err = au_may_del(a->dst_dentry, a->btgt,
21219 + a->dst_h_parent, isdir);
21223 + if (unlikely(err == -ENOENT || err == -EEXIST))
21229 +/* ---------------------------------------------------------------------- */
21234 + * - src_dir and dir by lock_rename()
21235 + * - inode if exitsts
21238 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21240 + * + di_write_lock2_child()
21241 + * + di_write_lock_child()
21242 + * + ii_write_lock_child()
21243 + * + di_write_lock_child2()
21244 + * + ii_write_lock_child2()
21245 + * + src_parent and parent
21246 + * + di_write_lock_parent()
21247 + * + ii_write_lock_parent()
21248 + * + di_write_lock_parent2()
21249 + * + ii_write_lock_parent2()
21250 + * + lower src_dir and dir by vfsub_lock_rename()
21251 + * + verify the every relationships between child and parent. if any
21252 + * of them failed, unlock all and return -EBUSY.
21254 +static void au_ren_unlock(struct au_ren_args *a)
21256 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21257 + a->dst_h_parent, a->dst_hdir);
21258 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21259 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21262 +static int au_ren_lock(struct au_ren_args *a)
21265 + unsigned int udba;
21268 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21269 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21270 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21271 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21273 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21274 + if (unlikely(err))
21276 + au_fset_ren(a->auren_flags, MNT_WRITE);
21277 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21278 + a->dst_h_parent, a->dst_hdir);
21279 + udba = au_opt_udba(a->src_dentry->d_sb);
21280 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21281 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21282 + err = au_busy_or_stale();
21283 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21284 + err = au_h_verify(a->src_h_dentry, udba,
21285 + d_inode(a->src_h_parent), a->src_h_parent,
21287 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21288 + err = au_h_verify(a->dst_h_dentry, udba,
21289 + d_inode(a->dst_h_parent), a->dst_h_parent,
21292 + goto out; /* success */
21294 + err = au_busy_or_stale();
21295 + au_ren_unlock(a);
21301 +/* ---------------------------------------------------------------------- */
21303 +static void au_ren_refresh_dir(struct au_ren_args *a)
21305 + struct inode *dir;
21307 + dir = a->dst_dir;
21308 + dir->i_version++;
21309 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21310 + /* is this updating defined in POSIX? */
21311 + au_cpup_attr_timesizes(a->src_inode);
21312 + au_cpup_attr_nlink(dir, /*force*/1);
21314 + au_dir_ts(dir, a->btgt);
21316 + if (a->exchange) {
21317 + dir = a->src_dir;
21318 + dir->i_version++;
21319 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21320 + /* is this updating defined in POSIX? */
21321 + au_cpup_attr_timesizes(a->dst_inode);
21322 + au_cpup_attr_nlink(dir, /*force*/1);
21324 + au_dir_ts(dir, a->btgt);
21327 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21330 + dir = a->src_dir;
21331 + dir->i_version++;
21332 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21333 + au_cpup_attr_nlink(dir, /*force*/1);
21334 + au_dir_ts(dir, a->btgt);
21337 +static void au_ren_refresh(struct au_ren_args *a)
21339 + aufs_bindex_t bbot, bindex;
21340 + struct dentry *d, *h_d;
21341 + struct inode *i, *h_i;
21342 + struct super_block *sb;
21344 + d = a->dst_dentry;
21347 + /* already dget-ed by au_ren_or_cpup() */
21348 + au_set_h_dptr(d, a->btgt, a->h_dst);
21350 + i = a->dst_inode;
21352 + if (!a->exchange) {
21353 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21354 + vfsub_drop_nlink(i);
21356 + vfsub_dead_dir(i);
21357 + au_cpup_attr_timesizes(i);
21359 + au_update_dbrange(d, /*do_put_zero*/1);
21361 + au_cpup_attr_nlink(i, /*force*/1);
21364 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21365 + au_set_h_dptr(d, bindex, NULL);
21366 + bbot = au_dbbot(d);
21367 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21368 + au_set_h_dptr(d, bindex, NULL);
21369 + au_update_dbrange(d, /*do_put_zero*/0);
21372 + d = a->src_dentry;
21373 + if (!a->exchange) {
21374 + au_set_dbwh(d, -1);
21375 + bbot = au_dbbot(d);
21376 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21377 + h_d = au_h_dptr(d, bindex);
21379 + au_set_h_dptr(d, bindex, NULL);
21381 + au_set_dbbot(d, a->btgt);
21384 + i = a->src_inode;
21385 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21386 + return; /* success */
21388 + bbot = au_ibbot(i);
21389 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21390 + h_i = au_h_iptr(i, bindex);
21392 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21393 + /* ignore this error */
21394 + au_set_h_iptr(i, bindex, NULL, 0);
21397 + au_set_ibbot(i, a->btgt);
21399 + d_drop(a->src_dentry);
21402 +/* ---------------------------------------------------------------------- */
21404 +/* mainly for link(2) and rename(2) */
21405 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21407 + aufs_bindex_t bdiropq, bwh;
21408 + struct dentry *parent;
21409 + struct au_branch *br;
21411 + parent = dentry->d_parent;
21412 + IMustLock(d_inode(parent)); /* dir is locked */
21414 + bdiropq = au_dbdiropq(parent);
21415 + bwh = au_dbwh(dentry);
21416 + br = au_sbr(dentry->d_sb, btgt);
21417 + if (au_br_rdonly(br)
21418 + || (0 <= bdiropq && bdiropq < btgt)
21419 + || (0 <= bwh && bwh < btgt))
21422 + AuDbg("btgt %d\n", btgt);
21426 +/* sets src_btop, dst_btop and btgt */
21427 +static int au_ren_wbr(struct au_ren_args *a)
21430 + struct au_wr_dir_args wr_dir_args = {
21431 + /* .force_btgt = -1, */
21432 + .flags = AuWrDir_ADD_ENTRY
21435 + a->src_btop = au_dbtop(a->src_dentry);
21436 + a->dst_btop = au_dbtop(a->dst_dentry);
21437 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21438 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21439 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21440 + wr_dir_args.force_btgt = a->src_btop;
21441 + if (a->dst_inode && a->dst_btop < a->src_btop)
21442 + wr_dir_args.force_btgt = a->dst_btop;
21443 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21444 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21447 + au_update_dbtop(a->dst_dentry);
21452 +static void au_ren_dt(struct au_ren_args *a)
21454 + a->h_path.dentry = a->src_h_parent;
21455 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21456 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21457 + a->h_path.dentry = a->dst_h_parent;
21458 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21461 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21462 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21466 + a->h_path.dentry = a->src_h_dentry;
21467 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21468 + if (d_is_positive(a->dst_h_dentry)) {
21469 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21470 + a->h_path.dentry = a->dst_h_dentry;
21471 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21475 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21477 + struct dentry *h_d;
21478 + struct inode *h_inode;
21480 + au_dtime_revert(a->src_dt + AuPARENT);
21481 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21482 + au_dtime_revert(a->dst_dt + AuPARENT);
21484 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21485 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21486 + h_inode = d_inode(h_d);
21487 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21488 + au_dtime_revert(a->src_dt + AuCHILD);
21489 + inode_unlock(h_inode);
21491 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21492 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21493 + h_inode = d_inode(h_d);
21494 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21495 + au_dtime_revert(a->dst_dt + AuCHILD);
21496 + inode_unlock(h_inode);
21501 +/* ---------------------------------------------------------------------- */
21503 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21504 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21505 + unsigned int _flags)
21507 + int err, lock_flags;
21508 + /* reduce stack space */
21509 + struct au_ren_args *a;
21510 + struct au_pin pin;
21512 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21513 + IMustLock(_src_dir);
21514 + IMustLock(_dst_dir);
21517 + if (unlikely(_flags & RENAME_WHITEOUT))
21521 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21522 + a = kzalloc(sizeof(*a), GFP_NOFS);
21523 + if (unlikely(!a))
21526 + a->flags = _flags;
21527 + a->exchange = _flags & RENAME_EXCHANGE;
21528 + a->src_dir = _src_dir;
21529 + a->src_dentry = _src_dentry;
21530 + a->src_inode = NULL;
21531 + if (d_really_is_positive(a->src_dentry))
21532 + a->src_inode = d_inode(a->src_dentry);
21533 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21534 + a->dst_dir = _dst_dir;
21535 + a->dst_dentry = _dst_dentry;
21536 + a->dst_inode = NULL;
21537 + if (d_really_is_positive(a->dst_dentry))
21538 + a->dst_inode = d_inode(a->dst_dentry);
21539 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21540 + if (a->dst_inode) {
21542 + * if EXCHANGE && src is non-dir && dst is dir,
21543 + * dst is not locked.
21545 + /* IMustLock(a->dst_inode); */
21546 + au_igrab(a->dst_inode);
21550 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21551 + if (d_is_dir(a->src_dentry)) {
21552 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21553 + if (unlikely(!a->exchange
21554 + && d_really_is_positive(a->dst_dentry)
21555 + && !d_is_dir(a->dst_dentry)))
21557 + lock_flags |= AuLock_DIRS;
21559 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21560 + au_fset_ren(a->auren_flags, ISDIR_DST);
21561 + if (unlikely(!a->exchange
21562 + && d_really_is_positive(a->src_dentry)
21563 + && !d_is_dir(a->src_dentry)))
21565 + lock_flags |= AuLock_DIRS;
21567 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21568 + if (unlikely(err))
21571 + err = au_d_hashed_positive(a->src_dentry);
21572 + if (unlikely(err))
21575 + if (a->dst_inode) {
21577 + * If it is a dir, VFS unhash it before this
21578 + * function. It means we cannot rely upon d_unhashed().
21580 + if (unlikely(!a->dst_inode->i_nlink))
21582 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21583 + err = au_d_hashed_positive(a->dst_dentry);
21584 + if (unlikely(err && !a->exchange))
21586 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21588 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21592 + * is it possible?
21593 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21594 + * there may exist a problem somewhere else.
21597 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21600 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21601 + di_write_lock_parent(a->dst_parent);
21603 + /* which branch we process */
21604 + err = au_ren_wbr(a);
21605 + if (unlikely(err < 0))
21607 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21608 + a->h_path.mnt = au_br_mnt(a->br);
21610 + /* are they available to be renamed */
21611 + err = au_ren_may_dir(a);
21612 + if (unlikely(err))
21613 + goto out_children;
21615 + /* prepare the writable parent dir on the same branch */
21616 + if (a->dst_btop == a->btgt) {
21617 + au_fset_ren(a->auren_flags, WHDST);
21619 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21620 + if (unlikely(err))
21621 + goto out_children;
21625 + if (!a->exchange) {
21626 + if (a->src_dir != a->dst_dir) {
21628 + * this temporary unlock is safe,
21629 + * because both dir->i_mutex are locked.
21631 + di_write_unlock(a->dst_parent);
21632 + di_write_lock_parent(a->src_parent);
21633 + err = au_wr_dir_need_wh(a->src_dentry,
21634 + au_ftest_ren(a->auren_flags,
21637 + di_write_unlock(a->src_parent);
21638 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21640 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21642 + err = au_wr_dir_need_wh(a->src_dentry,
21643 + au_ftest_ren(a->auren_flags,
21647 + if (unlikely(err < 0))
21648 + goto out_children;
21650 + au_fset_ren(a->auren_flags, WHSRC);
21653 + if (a->src_btop != a->btgt) {
21654 + err = au_pin(&pin, a->src_dentry, a->btgt,
21655 + au_opt_udba(a->src_dentry->d_sb),
21656 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21658 + struct au_cp_generic cpg = {
21659 + .dentry = a->src_dentry,
21661 + .bsrc = a->src_btop,
21664 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21666 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21667 + err = au_sio_cpup_simple(&cpg);
21670 + if (unlikely(err))
21671 + goto out_children;
21672 + a->src_btop = a->btgt;
21673 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21674 + if (!a->exchange)
21675 + au_fset_ren(a->auren_flags, WHSRC);
21679 + if (a->exchange && a->dst_inode
21680 + && a->dst_btop != a->btgt) {
21681 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21682 + au_opt_udba(a->dst_dentry->d_sb),
21683 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21685 + struct au_cp_generic cpg = {
21686 + .dentry = a->dst_dentry,
21688 + .bsrc = a->dst_btop,
21691 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21693 + err = au_sio_cpup_simple(&cpg);
21696 + if (unlikely(err))
21697 + goto out_children;
21698 + a->dst_btop = a->btgt;
21699 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21702 + /* lock them all */
21703 + err = au_ren_lock(a);
21704 + if (unlikely(err))
21705 + /* leave the copied-up one */
21706 + goto out_children;
21708 + if (!a->exchange) {
21709 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21710 + err = au_may_ren(a);
21711 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21712 + err = -ENAMETOOLONG;
21713 + if (unlikely(err))
21717 + /* store timestamps to be revertible */
21721 + err = do_rename(a);
21722 + if (unlikely(err))
21725 + /* update dir attributes */
21726 + au_ren_refresh_dir(a);
21728 + /* dput/iput all lower dentries */
21729 + au_ren_refresh(a);
21731 + goto out_hdir; /* success */
21734 + au_ren_rev_dt(err, a);
21736 + au_ren_unlock(a);
21738 + au_nhash_wh_free(&a->whlist);
21739 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21740 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21741 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21742 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21746 + if (!a->exchange)
21747 + d_move(a->src_dentry, a->dst_dentry);
21749 + d_exchange(a->src_dentry, a->dst_dentry);
21751 + au_update_dbtop(a->dst_dentry);
21752 + if (!a->dst_inode)
21753 + d_drop(a->dst_dentry);
21755 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21756 + di_write_unlock(a->dst_parent);
21758 + di_write_unlock2(a->src_parent, a->dst_parent);
21760 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21762 + iput(a->dst_inode);
21764 + au_whtmp_rmdir_free(a->thargs);
21770 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21771 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21772 +++ linux/fs/aufs/Kconfig 2017-07-29 12:14:25.896375188 +0200
21775 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21777 + Aufs is a stackable unification filesystem such as Unionfs,
21778 + which unifies several directories and provides a merged single
21780 + In the early days, aufs was entirely re-designed and
21781 + re-implemented Unionfs Version 1.x series. Introducing many
21782 + original ideas, approaches and improvements, it becomes totally
21783 + different from Unionfs while keeping the basic features.
21787 + prompt "Maximum number of branches"
21788 + default AUFS_BRANCH_MAX_127
21790 + Specifies the maximum number of branches (or member directories)
21791 + in a single aufs. The larger value consumes more system
21792 + resources and has a minor impact to performance.
21793 +config AUFS_BRANCH_MAX_127
21796 + Specifies the maximum number of branches (or member directories)
21797 + in a single aufs. The larger value consumes more system
21798 + resources and has a minor impact to performance.
21799 +config AUFS_BRANCH_MAX_511
21802 + Specifies the maximum number of branches (or member directories)
21803 + in a single aufs. The larger value consumes more system
21804 + resources and has a minor impact to performance.
21805 +config AUFS_BRANCH_MAX_1023
21808 + Specifies the maximum number of branches (or member directories)
21809 + in a single aufs. The larger value consumes more system
21810 + resources and has a minor impact to performance.
21811 +config AUFS_BRANCH_MAX_32767
21814 + Specifies the maximum number of branches (or member directories)
21815 + in a single aufs. The larger value consumes more system
21816 + resources and has a minor impact to performance.
21819 +config AUFS_SBILIST
21821 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21824 + Automatic configuration for internal use.
21825 + When aufs supports Magic SysRq or /proc, enabled automatically.
21827 +config AUFS_HNOTIFY
21828 + bool "Detect direct branch access (bypassing aufs)"
21830 + If you want to modify files on branches directly, eg. bypassing aufs,
21831 + and want aufs to detect the changes of them fully, then enable this
21832 + option and use 'udba=notify' mount option.
21833 + Currently there is only one available configuration, "fsnotify".
21834 + It will have a negative impact to the performance.
21835 + See detail in aufs.5.
21838 + prompt "method" if AUFS_HNOTIFY
21839 + default AUFS_HFSNOTIFY
21840 +config AUFS_HFSNOTIFY
21845 +config AUFS_EXPORT
21846 + bool "NFS-exportable aufs"
21847 + depends on EXPORTFS
21849 + If you want to export your mounted aufs via NFS, then enable this
21850 + option. There are several requirements for this configuration.
21851 + See detail in aufs.5.
21853 +config AUFS_INO_T_64
21855 + depends on AUFS_EXPORT
21856 + depends on 64BIT && !(ALPHA || S390)
21859 + Automatic configuration for internal use.
21860 + /* typedef unsigned long/int __kernel_ino_t */
21861 + /* alpha and s390x are int */
21864 + bool "support for XATTR/EA (including Security Labels)"
21866 + If your branch fs supports XATTR/EA and you want to make them
21867 + available in aufs too, then enable this opsion and specify the
21868 + branch attributes for EA.
21869 + See detail in aufs.5.
21872 + bool "File-based Hierarchical Storage Management"
21874 + Hierarchical Storage Management (or HSM) is a well-known feature
21875 + in the storage world. Aufs provides this feature as file-based.
21876 + with multiple branches.
21877 + These multiple branches are prioritized, ie. the topmost one
21878 + should be the fastest drive and be used heavily.
21881 + bool "Readdir in userspace"
21883 + Aufs has two methods to provide a merged view for a directory,
21884 + by a user-space library and by kernel-space natively. The latter
21885 + is always enabled but sometimes large and slow.
21886 + If you enable this option, install the library in aufs2-util
21887 + package, and set some environment variables for your readdir(3),
21888 + then the work will be handled in user-space which generally
21889 + shows better performance in most cases.
21890 + See detail in aufs.5.
21893 + bool "Show whiteouts"
21895 + If you want to make the whiteouts in aufs visible, then enable
21896 + this option and specify 'shwh' mount option. Although it may
21897 + sounds like philosophy or something, but in technically it
21898 + simply shows the name of whiteout with keeping its behaviour.
21900 +config AUFS_BR_RAMFS
21901 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21903 + If you want to use ramfs as an aufs branch fs, then enable this
21904 + option. Generally tmpfs is recommended.
21905 + Aufs prohibited them to be a branch fs by default, because
21906 + initramfs becomes unusable after switch_root or something
21907 + generally. If you sets initramfs as an aufs branch and boot your
21908 + system by switch_root, you will meet a problem easily since the
21909 + files in initramfs may be inaccessible.
21910 + Unless you are going to use ramfs as an aufs branch fs without
21911 + switch_root or something, leave it N.
21913 +config AUFS_BR_FUSE
21914 + bool "Fuse fs as an aufs branch"
21915 + depends on FUSE_FS
21918 + If you want to use fuse-based userspace filesystem as an aufs
21919 + branch fs, then enable this option.
21920 + It implements the internal poll(2) operation which is
21921 + implemented by fuse only (curretnly).
21926 + Automatic configuration for internal use.
21928 +config AUFS_BR_HFSPLUS
21929 + bool "Hfsplus as an aufs branch"
21930 + depends on HFSPLUS_FS
21933 + If you want to use hfsplus fs as an aufs branch fs, then enable
21934 + this option. This option introduces a small overhead at
21935 + copying-up a file on hfsplus.
21937 +config AUFS_BDEV_LOOP
21939 + depends on BLK_DEV_LOOP
21942 + Automatic configuration for internal use.
21943 + Convert =[ym] into =y.
21946 + bool "Debug aufs"
21948 + Enable this to compile aufs internal debug code.
21949 + It will have a negative impact to the performance.
21951 +config AUFS_MAGIC_SYSRQ
21953 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21956 + Automatic configuration for internal use.
21957 + When aufs supports Magic SysRq, enabled automatically.
21959 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21960 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21961 +++ linux/fs/aufs/loop.c 2017-07-29 12:14:25.903042072 +0200
21964 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21966 + * This program, aufs is free software; you can redistribute it and/or modify
21967 + * it under the terms of the GNU General Public License as published by
21968 + * the Free Software Foundation; either version 2 of the License, or
21969 + * (at your option) any later version.
21971 + * This program is distributed in the hope that it will be useful,
21972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21974 + * GNU General Public License for more details.
21976 + * You should have received a copy of the GNU General Public License
21977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21981 + * support for loopback block device as a branch
21986 +/* added into drivers/block/loop.c */
21987 +static struct file *(*backing_file_func)(struct super_block *sb);
21990 + * test if two lower dentries have overlapping branches.
21992 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21994 + struct super_block *h_sb;
21995 + struct file *backing_file;
21997 + if (unlikely(!backing_file_func)) {
21998 + /* don't load "loop" module here */
21999 + backing_file_func = symbol_get(loop_backing_file);
22000 + if (unlikely(!backing_file_func))
22001 + /* "loop" module is not loaded */
22005 + h_sb = h_adding->d_sb;
22006 + backing_file = backing_file_func(h_sb);
22007 + if (!backing_file)
22010 + h_adding = backing_file->f_path.dentry;
22012 + * h_adding can be local NFS.
22013 + * in this case aufs cannot detect the loop.
22015 + if (unlikely(h_adding->d_sb == sb))
22017 + return !!au_test_subdir(h_adding, sb->s_root);
22020 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
22021 +int au_test_loopback_kthread(void)
22024 + struct task_struct *tsk = current;
22025 + char c, comm[sizeof(tsk->comm)];
22028 + if (tsk->flags & PF_KTHREAD) {
22029 + get_task_comm(comm, tsk);
22031 + ret = ('0' <= c && c <= '9'
22032 + && !strncmp(comm, "loop", 4));
22038 +/* ---------------------------------------------------------------------- */
22040 +#define au_warn_loopback_step 16
22041 +static int au_warn_loopback_nelem = au_warn_loopback_step;
22042 +static unsigned long *au_warn_loopback_array;
22044 +void au_warn_loopback(struct super_block *h_sb)
22046 + int i, new_nelem;
22047 + unsigned long *a, magic;
22048 + static DEFINE_SPINLOCK(spin);
22050 + magic = h_sb->s_magic;
22051 + spin_lock(&spin);
22052 + a = au_warn_loopback_array;
22053 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
22054 + if (a[i] == magic) {
22055 + spin_unlock(&spin);
22059 + /* h_sb is new to us, print it */
22060 + if (i < au_warn_loopback_nelem) {
22065 + /* expand the array */
22066 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
22067 + a = au_kzrealloc(au_warn_loopback_array,
22068 + au_warn_loopback_nelem * sizeof(unsigned long),
22069 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
22070 + /*may_shrink*/0);
22072 + au_warn_loopback_nelem = new_nelem;
22073 + au_warn_loopback_array = a;
22078 + spin_unlock(&spin);
22079 + AuWarn1("realloc failed, ignored\n");
22083 + spin_unlock(&spin);
22084 + pr_warn("you may want to try another patch for loopback file "
22085 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
22088 +int au_loopback_init(void)
22091 + struct super_block *sb __maybe_unused;
22093 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
22096 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
22097 + sizeof(unsigned long), GFP_NOFS);
22098 + if (unlikely(!au_warn_loopback_array))
22104 +void au_loopback_fin(void)
22106 + if (backing_file_func)
22107 + symbol_put(loop_backing_file);
22108 + kfree(au_warn_loopback_array);
22110 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
22111 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
22112 +++ linux/fs/aufs/loop.h 2017-07-29 12:14:25.903042072 +0200
22115 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22117 + * This program, aufs is free software; you can redistribute it and/or modify
22118 + * it under the terms of the GNU General Public License as published by
22119 + * the Free Software Foundation; either version 2 of the License, or
22120 + * (at your option) any later version.
22122 + * This program is distributed in the hope that it will be useful,
22123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22125 + * GNU General Public License for more details.
22127 + * You should have received a copy of the GNU General Public License
22128 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22132 + * support for loopback mount as a branch
22135 +#ifndef __AUFS_LOOP_H__
22136 +#define __AUFS_LOOP_H__
22141 +struct super_block;
22143 +#ifdef CONFIG_AUFS_BDEV_LOOP
22144 +/* drivers/block/loop.c */
22145 +struct file *loop_backing_file(struct super_block *sb);
22148 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
22149 +int au_test_loopback_kthread(void);
22150 +void au_warn_loopback(struct super_block *h_sb);
22152 +int au_loopback_init(void);
22153 +void au_loopback_fin(void);
22155 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
22156 + struct dentry *h_adding)
22157 +AuStubInt0(au_test_loopback_kthread, void)
22158 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
22160 +AuStubInt0(au_loopback_init, void)
22161 +AuStubVoid(au_loopback_fin, void)
22162 +#endif /* BLK_DEV_LOOP */
22164 +#endif /* __KERNEL__ */
22165 +#endif /* __AUFS_LOOP_H__ */
22166 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
22167 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
22168 +++ linux/fs/aufs/magic.mk 2017-07-29 12:14:25.903042072 +0200
22171 +# defined in ${srctree}/fs/fuse/inode.c
22173 +ifdef CONFIG_FUSE_FS
22174 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
22177 +# defined in ${srctree}/fs/xfs/xfs_sb.h
22179 +ifdef CONFIG_XFS_FS
22180 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
22183 +# defined in ${srctree}/fs/configfs/mount.c
22185 +ifdef CONFIG_CONFIGFS_FS
22186 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
22189 +# defined in ${srctree}/fs/ubifs/ubifs.h
22191 +ifdef CONFIG_UBIFS_FS
22192 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
22195 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22197 +ifdef CONFIG_HFSPLUS_FS
22198 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22200 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22201 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22202 +++ linux/fs/aufs/Makefile 2017-07-29 12:14:25.896375188 +0200
22205 +include ${src}/magic.mk
22206 +ifeq (${CONFIG_AUFS_FS},m)
22207 +include ${src}/conf.mk
22209 +-include ${src}/priv_def.mk
22211 +# cf. include/linux/kernel.h
22213 +ccflags-y += -DDEBUG
22214 +# sparse requires the full pathname
22216 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22218 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22221 +obj-$(CONFIG_AUFS_FS) += aufs.o
22222 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22223 + wkq.o vfsub.o dcsub.o \
22224 + cpup.o whout.o wbr_policy.o \
22225 + dinfo.o dentry.o \
22227 + finfo.o file.o f_op.o \
22229 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22233 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22234 +aufs-$(CONFIG_SYSFS) += sysfs.o
22235 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22236 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22237 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22238 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22239 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22240 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22241 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22242 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22243 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22244 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22245 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22246 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22247 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22248 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22249 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22250 +++ linux/fs/aufs/module.c 2017-07-29 12:14:25.903042072 +0200
22253 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22255 + * This program, aufs is free software; you can redistribute it and/or modify
22256 + * it under the terms of the GNU General Public License as published by
22257 + * the Free Software Foundation; either version 2 of the License, or
22258 + * (at your option) any later version.
22260 + * This program is distributed in the hope that it will be useful,
22261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22263 + * GNU General Public License for more details.
22265 + * You should have received a copy of the GNU General Public License
22266 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22270 + * module global variables and operations
22273 +#include <linux/module.h>
22274 +#include <linux/seq_file.h>
22277 +/* shrinkable realloc */
22278 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22286 +#if 0 /* unused */
22293 + AuDebugOn(!new_sz);
22296 + diff = au_kmidx_sub(sz, new_sz);
22302 + /* expand or SLOB */
22303 + p = krealloc(p, new_sz, gfp);
22304 + else if (new_sz < sz && may_shrink) {
22308 + q = kmalloc(new_sz, gfp);
22311 + memcpy(q, p, new_sz);
22323 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22326 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22327 + if (p && new_sz > nused)
22328 + memset(p + nused, 0, new_sz - nused);
22332 +/* ---------------------------------------------------------------------- */
22336 +struct kmem_cache *au_cache[AuCache_Last];
22338 +static void au_cache_fin(void)
22343 + * Make sure all delayed rcu free inodes are flushed before we
22348 + /* excluding AuCache_HNOTIFY */
22349 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22350 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22351 + kmem_cache_destroy(au_cache[i]);
22352 + au_cache[i] = NULL;
22356 +static int __init au_cache_init(void)
22358 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
22359 + if (au_cache[AuCache_DINFO])
22360 + /* SLAB_DESTROY_BY_RCU */
22361 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
22362 + au_icntnr_init_once);
22363 + if (au_cache[AuCache_ICNTNR])
22364 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
22365 + au_fi_init_once);
22366 + if (au_cache[AuCache_FINFO])
22367 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
22368 + if (au_cache[AuCache_VDIR])
22369 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
22370 + if (au_cache[AuCache_DEHSTR])
22377 +/* ---------------------------------------------------------------------- */
22379 +int au_dir_roflags;
22381 +#ifdef CONFIG_AUFS_SBILIST
22383 + * iterate_supers_type() doesn't protect us from
22384 + * remounting (branch management)
22386 +struct au_sphlhead au_sbilist;
22390 + * functions for module interface.
22392 +MODULE_LICENSE("GPL");
22393 +/* MODULE_LICENSE("GPL v2"); */
22394 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22395 +MODULE_DESCRIPTION(AUFS_NAME
22396 + " -- Advanced multi layered unification filesystem");
22397 +MODULE_VERSION(AUFS_VERSION);
22398 +MODULE_ALIAS_FS(AUFS_NAME);
22400 +/* this module parameter has no meaning when SYSFS is disabled */
22401 +int sysaufs_brs = 1;
22402 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22403 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22405 +/* this module parameter has no meaning when USER_NS is disabled */
22407 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22408 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22410 +/* ---------------------------------------------------------------------- */
22412 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22414 +int au_seq_path(struct seq_file *seq, struct path *path)
22418 + err = seq_path(seq, path, au_esc_chars);
22427 +/* ---------------------------------------------------------------------- */
22429 +static int __init aufs_init(void)
22434 + p = au_esc_chars;
22435 + for (i = 1; i <= ' '; i++)
22441 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22443 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22444 + for (i = 0; i < AuIop_Last; i++)
22445 + aufs_iop_nogetattr[i].getattr = NULL;
22447 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
22449 + au_sbilist_init();
22450 + sysaufs_brs_init();
22453 + err = sysaufs_init();
22454 + if (unlikely(err))
22456 + err = au_procfs_init();
22457 + if (unlikely(err))
22458 + goto out_sysaufs;
22459 + err = au_wkq_init();
22460 + if (unlikely(err))
22462 + err = au_loopback_init();
22463 + if (unlikely(err))
22465 + err = au_hnotify_init();
22466 + if (unlikely(err))
22467 + goto out_loopback;
22468 + err = au_sysrq_init();
22469 + if (unlikely(err))
22471 + err = au_cache_init();
22472 + if (unlikely(err))
22475 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22476 + err = register_filesystem(&aufs_fs_type);
22477 + if (unlikely(err))
22480 + /* since we define pr_fmt, call printk directly */
22481 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22482 + goto out; /* success */
22489 + au_hnotify_fin();
22491 + au_loopback_fin();
22503 +static void __exit aufs_exit(void)
22505 + unregister_filesystem(&aufs_fs_type);
22508 + au_hnotify_fin();
22509 + au_loopback_fin();
22516 +module_init(aufs_init);
22517 +module_exit(aufs_exit);
22518 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22519 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22520 +++ linux/fs/aufs/module.h 2017-07-29 12:14:25.903042072 +0200
22523 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22525 + * This program, aufs is free software; you can redistribute it and/or modify
22526 + * it under the terms of the GNU General Public License as published by
22527 + * the Free Software Foundation; either version 2 of the License, or
22528 + * (at your option) any later version.
22530 + * This program is distributed in the hope that it will be useful,
22531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22533 + * GNU General Public License for more details.
22535 + * You should have received a copy of the GNU General Public License
22536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22540 + * module initialization and module-global
22543 +#ifndef __AUFS_MODULE_H__
22544 +#define __AUFS_MODULE_H__
22548 +#include <linux/slab.h>
22553 +/* module parameters */
22554 +extern int sysaufs_brs;
22555 +extern bool au_userns;
22557 +/* ---------------------------------------------------------------------- */
22559 +extern int au_dir_roflags;
22561 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22562 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22565 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22567 +#ifndef CONFIG_SLOB
22568 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22570 + return -1; /* SLOB is untested */
22574 +int au_seq_path(struct seq_file *seq, struct path *path);
22576 +#ifdef CONFIG_PROC_FS
22578 +int __init au_procfs_init(void);
22579 +void au_procfs_fin(void);
22581 +AuStubInt0(au_procfs_init, void);
22582 +AuStubVoid(au_procfs_fin, void);
22585 +/* ---------------------------------------------------------------------- */
22594 + AuCache_HNOTIFY, /* must be last */
22598 +extern struct kmem_cache *au_cache[AuCache_Last];
22600 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22601 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22602 +#define AuCacheCtor(type, ctor) \
22603 + kmem_cache_create(#type, sizeof(struct type), \
22604 + __alignof__(struct type), AuCacheFlags, ctor)
22606 +#define AuCacheFuncs(name, index) \
22607 +static inline struct au_##name *au_cache_alloc_##name(void) \
22608 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
22609 +static inline void au_cache_free_##name(struct au_##name *p) \
22610 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
22612 +AuCacheFuncs(dinfo, DINFO);
22613 +AuCacheFuncs(icntnr, ICNTNR);
22614 +AuCacheFuncs(finfo, FINFO);
22615 +AuCacheFuncs(vdir, VDIR);
22616 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22617 +#ifdef CONFIG_AUFS_HNOTIFY
22618 +AuCacheFuncs(hnotify, HNOTIFY);
22621 +#endif /* __KERNEL__ */
22622 +#endif /* __AUFS_MODULE_H__ */
22623 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22624 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22625 +++ linux/fs/aufs/mvdown.c 2017-07-29 12:14:25.903042072 +0200
22628 + * Copyright (C) 2011-2017 Junjiro R. Okajima
22630 + * This program, aufs is free software; you can redistribute it and/or modify
22631 + * it under the terms of the GNU General Public License as published by
22632 + * the Free Software Foundation; either version 2 of the License, or
22633 + * (at your option) any later version.
22635 + * This program is distributed in the hope that it will be useful,
22636 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22637 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22638 + * GNU General Public License for more details.
22640 + * You should have received a copy of the GNU General Public License
22641 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22645 + * move-down, opposite of copy-up
22650 +struct au_mvd_args {
22652 + struct super_block *h_sb;
22653 + struct dentry *h_parent;
22654 + struct au_hinode *hdir;
22655 + struct inode *h_dir, *h_inode;
22656 + struct au_pin pin;
22657 + } info[AUFS_MVDOWN_NARRAY];
22659 + struct aufs_mvdown mvdown;
22660 + struct dentry *dentry, *parent;
22661 + struct inode *inode, *dir;
22662 + struct super_block *sb;
22663 + aufs_bindex_t bopq, bwh, bfound;
22664 + unsigned char rename_lock;
22667 +#define mvd_errno mvdown.au_errno
22668 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22669 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22670 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22671 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22673 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22674 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22675 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22676 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22677 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22678 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22680 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22681 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22682 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22683 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22684 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22685 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22687 +#define AU_MVD_PR(flag, ...) do { \
22689 + pr_err(__VA_ARGS__); \
22692 +static int find_lower_writable(struct au_mvd_args *a)
22694 + struct super_block *sb;
22695 + aufs_bindex_t bindex, bbot;
22696 + struct au_branch *br;
22699 + bindex = a->mvd_bsrc;
22700 + bbot = au_sbbot(sb);
22701 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22702 + for (bindex++; bindex <= bbot; bindex++) {
22703 + br = au_sbr(sb, bindex);
22704 + if (au_br_fhsm(br->br_perm)
22705 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22708 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22709 + for (bindex++; bindex <= bbot; bindex++) {
22710 + br = au_sbr(sb, bindex);
22711 + if (!au_br_rdonly(br))
22715 + for (bindex++; bindex <= bbot; bindex++) {
22716 + br = au_sbr(sb, bindex);
22717 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22718 + if (au_br_rdonly(br))
22720 + |= AUFS_MVDOWN_ROLOWER_R;
22728 +/* make the parent dir on bdst */
22729 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22734 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22735 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22736 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22737 + a->mvd_h_dst_parent = NULL;
22738 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22739 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22740 + if (!a->mvd_h_dst_parent) {
22741 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22742 + if (unlikely(err)) {
22743 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22746 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22754 +/* lock them all */
22755 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22758 + struct dentry *h_trap;
22760 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22761 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22762 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22763 + au_opt_udba(a->sb),
22764 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22766 + if (unlikely(err)) {
22767 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22771 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22772 + a->rename_lock = 0;
22773 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22774 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22775 + au_opt_udba(a->sb),
22776 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22777 + err = au_do_pin(&a->mvd_pin_src);
22779 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22780 + if (unlikely(err)) {
22781 + AU_MVD_PR(dmsg, "pin_src failed\n");
22784 + goto out; /* success */
22787 + a->rename_lock = 1;
22788 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22789 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22790 + au_opt_udba(a->sb),
22791 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22793 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22794 + if (unlikely(err)) {
22795 + AU_MVD_PR(dmsg, "pin_src failed\n");
22796 + au_pin_hdir_lock(&a->mvd_pin_dst);
22799 + au_pin_hdir_unlock(&a->mvd_pin_src);
22800 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22801 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22803 + err = (h_trap != a->mvd_h_src_parent);
22805 + err = (h_trap != a->mvd_h_dst_parent);
22807 + BUG_ON(err); /* it should never happen */
22808 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22811 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22812 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22813 + au_pin_hdir_lock(&a->mvd_pin_src);
22814 + au_unpin(&a->mvd_pin_src);
22815 + au_pin_hdir_lock(&a->mvd_pin_dst);
22818 + goto out; /* success */
22821 + au_unpin(&a->mvd_pin_dst);
22827 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22829 + if (!a->rename_lock)
22830 + au_unpin(&a->mvd_pin_src);
22832 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22833 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22834 + au_pin_hdir_lock(&a->mvd_pin_src);
22835 + au_unpin(&a->mvd_pin_src);
22836 + au_pin_hdir_lock(&a->mvd_pin_dst);
22838 + au_unpin(&a->mvd_pin_dst);
22841 +/* copy-down the file */
22842 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22845 + struct au_cp_generic cpg = {
22846 + .dentry = a->dentry,
22847 + .bdst = a->mvd_bdst,
22848 + .bsrc = a->mvd_bsrc,
22850 + .pin = &a->mvd_pin_dst,
22851 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22854 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22855 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22856 + au_fset_cpup(cpg.flags, OVERWRITE);
22857 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22858 + au_fset_cpup(cpg.flags, RWDST);
22859 + err = au_sio_cpdown_simple(&cpg);
22860 + if (unlikely(err))
22861 + AU_MVD_PR(dmsg, "cpdown failed\n");
22868 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22871 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22874 + struct path h_path;
22875 + struct au_branch *br;
22876 + struct inode *delegated;
22878 + br = au_sbr(a->sb, a->mvd_bdst);
22879 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22880 + err = PTR_ERR(h_path.dentry);
22881 + if (IS_ERR(h_path.dentry)) {
22882 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22887 + if (d_is_positive(h_path.dentry)) {
22888 + h_path.mnt = au_br_mnt(br);
22889 + delegated = NULL;
22890 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22891 + &delegated, /*force*/0);
22892 + if (unlikely(err == -EWOULDBLOCK)) {
22893 + pr_warn("cannot retry for NFSv4 delegation"
22894 + " for an internal unlink\n");
22897 + if (unlikely(err))
22898 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22900 + dput(h_path.dentry);
22908 + * unlink the topmost h_dentry
22910 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22913 + struct path h_path;
22914 + struct inode *delegated;
22916 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22917 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22918 + delegated = NULL;
22919 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22920 + if (unlikely(err == -EWOULDBLOCK)) {
22921 + pr_warn("cannot retry for NFSv4 delegation"
22922 + " for an internal unlink\n");
22925 + if (unlikely(err))
22926 + AU_MVD_PR(dmsg, "unlink failed\n");
22932 +/* Since mvdown succeeded, we ignore an error of this function */
22933 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22936 + struct au_branch *br;
22938 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22939 + br = au_sbr(a->sb, a->mvd_bsrc);
22940 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22942 + br = au_sbr(a->sb, a->mvd_bdst);
22943 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22944 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22947 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22949 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22953 + * copy-down the file and unlink the bsrc file.
22954 + * - unlink the bdst whout if exist
22955 + * - copy-down the file (with whtmp name and rename)
22956 + * - unlink the bsrc file
22958 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22962 + err = au_do_mkdir(dmsg, a);
22964 + err = au_do_lock(dmsg, a);
22965 + if (unlikely(err))
22969 + * do not revert the activities we made on bdst since they should be
22970 + * harmless in aufs.
22973 + err = au_do_cpdown(dmsg, a);
22975 + err = au_do_unlink_wh(dmsg, a);
22976 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22977 + err = au_do_unlink(dmsg, a);
22978 + if (unlikely(err))
22981 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22982 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22983 + if (find_lower_writable(a) < 0)
22984 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22986 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22987 + au_do_stfs(dmsg, a);
22989 + /* maintain internal array */
22990 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22991 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22992 + au_set_dbtop(a->dentry, a->mvd_bdst);
22993 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22994 + au_set_ibtop(a->inode, a->mvd_bdst);
22996 + /* hide the lower */
22997 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22998 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22999 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
23000 + au_set_ibbot(a->inode, a->mvd_bsrc);
23002 + if (au_dbbot(a->dentry) < a->mvd_bdst)
23003 + au_set_dbbot(a->dentry, a->mvd_bdst);
23004 + if (au_ibbot(a->inode) < a->mvd_bdst)
23005 + au_set_ibbot(a->inode, a->mvd_bdst);
23008 + au_do_unlock(dmsg, a);
23014 +/* ---------------------------------------------------------------------- */
23016 +/* make sure the file is idle */
23017 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
23019 + int err, plinked;
23022 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
23023 + if (au_dbtop(a->dentry) == a->mvd_bsrc
23024 + && au_dcount(a->dentry) == 1
23025 + && atomic_read(&a->inode->i_count) == 1
23026 + /* && a->mvd_h_src_inode->i_nlink == 1 */
23027 + && (!plinked || !au_plink_test(a->inode))
23028 + && a->inode->i_nlink == 1)
23033 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
23034 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
23035 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
23036 + a->mvd_h_src_inode->i_nlink,
23037 + plinked, plinked ? au_plink_test(a->inode) : 0);
23044 +/* make sure the parent dir is fine */
23045 +static int au_mvd_args_parent(const unsigned char dmsg,
23046 + struct au_mvd_args *a)
23049 + aufs_bindex_t bindex;
23052 + if (unlikely(au_alive_dir(a->parent))) {
23054 + AU_MVD_PR(dmsg, "parent dir is dead\n");
23058 + a->bopq = au_dbdiropq(a->parent);
23059 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
23060 + AuDbg("b%d\n", bindex);
23061 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
23062 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
23064 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
23065 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
23066 + a->bopq, a->mvd_bdst);
23074 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23075 + struct au_mvd_args *a)
23078 + struct au_dinfo *dinfo, *tmp;
23080 + /* lookup the next lower positive entry */
23082 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23083 + if (unlikely(!tmp))
23088 + dinfo = au_di(a->dentry);
23089 + au_di_cp(tmp, dinfo);
23090 + au_di_swap(tmp, dinfo);
23092 + /* returns the number of positive dentries */
23093 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23094 + /* AuLkup_IGNORE_PERM */ 0);
23096 + a->bwh = au_dbwh(a->dentry);
23097 + else if (err > 0)
23098 + a->bfound = au_dbtop(a->dentry);
23100 + au_di_swap(tmp, dinfo);
23101 + au_rw_write_unlock(&tmp->di_rwsem);
23103 + if (unlikely(err < 0))
23104 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23107 + * here, we have these cases.
23109 + * no positive dentry under bsrc. there are more sub-cases.
23111 + * there no whiteout, we can safely move-down.
23114 + * bsrc < bwh && bwh < bdst
23115 + * there is a whiteout on RO branch. cannot proceed.
23117 + * there is a whiteout on the RW target branch. it should
23120 + * there is a whiteout somewhere unrelated branch.
23121 + * -1 < bfound && bfound <= bsrc
23124 + * found, but it is on RO branch between bsrc and bdst. cannot
23127 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23130 + * found, after we create the file on bdst, it will be hidden.
23133 + AuDebugOn(a->bfound == -1
23135 + && a->bwh <= a->mvd_bsrc);
23136 + AuDebugOn(-1 < a->bfound
23137 + && a->bfound <= a->mvd_bsrc);
23140 + if (a->bfound == -1
23141 + && a->mvd_bsrc < a->bwh
23143 + && a->bwh < a->mvd_bdst) {
23144 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23145 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23146 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23148 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23149 + a->mvd_errno = EAU_MVDOWN_UPPER;
23150 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23151 + a->mvd_bdst, a->bfound);
23155 + err = 0; /* success */
23162 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23167 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23168 + && a->bfound == a->mvd_bdst)
23174 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23177 + struct au_branch *br;
23180 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23184 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23185 + a->mvd_bsrc = au_ibtop(a->inode);
23187 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23188 + if (unlikely(a->mvd_bsrc < 0
23189 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23190 + || au_dbbot(a->dentry) < a->mvd_bsrc
23191 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23192 + || (a->mvd_bsrc < au_ibtop(a->inode)
23193 + || au_ibbot(a->inode) < a->mvd_bsrc
23194 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23195 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23196 + AU_MVD_PR(dmsg, "no upper\n");
23200 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23201 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23202 + AU_MVD_PR(dmsg, "on the bottom\n");
23205 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23206 + br = au_sbr(a->sb, a->mvd_bsrc);
23207 + err = au_br_rdonly(br);
23208 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23209 + if (unlikely(err))
23211 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23212 + || IS_APPEND(a->mvd_h_src_inode))) {
23214 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23220 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23221 + a->mvd_bdst = find_lower_writable(a);
23222 + if (unlikely(a->mvd_bdst < 0)) {
23223 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23224 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23228 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23229 + if (unlikely(a->mvd_bdst < 0
23230 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23231 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23232 + AU_MVD_PR(dmsg, "no lower brid\n");
23237 + err = au_mvd_args_busy(dmsg, a);
23239 + err = au_mvd_args_parent(dmsg, a);
23241 + err = au_mvd_args_intermediate(dmsg, a);
23243 + err = au_mvd_args_exist(dmsg, a);
23245 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23252 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23255 + unsigned char dmsg;
23256 + struct au_mvd_args *args;
23257 + struct inode *inode;
23259 + inode = d_inode(dentry);
23261 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23265 + args = kmalloc(sizeof(*args), GFP_NOFS);
23266 + if (unlikely(!args))
23269 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23271 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23272 + if (unlikely(err)) {
23277 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23278 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23279 + args->mvdown.au_errno = 0;
23280 + args->dentry = dentry;
23281 + args->inode = inode;
23282 + args->sb = dentry->d_sb;
23285 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23286 + args->parent = dget_parent(dentry);
23287 + args->dir = d_inode(args->parent);
23288 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23289 + dput(args->parent);
23290 + if (unlikely(args->parent != dentry->d_parent)) {
23291 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23295 + inode_lock_nested(inode, I_MUTEX_CHILD);
23296 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23297 + if (unlikely(err))
23300 + di_write_lock_parent(args->parent);
23301 + err = au_mvd_args(dmsg, args);
23302 + if (unlikely(err))
23305 + err = au_do_mvdown(dmsg, args);
23306 + if (unlikely(err))
23309 + au_cpup_attr_timesizes(args->dir);
23310 + au_cpup_attr_timesizes(inode);
23311 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23312 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23313 + /* au_digen_dec(dentry); */
23316 + di_write_unlock(args->parent);
23317 + aufs_read_unlock(dentry, AuLock_DW);
23319 + inode_unlock(inode);
23321 + inode_unlock(args->dir);
23323 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23331 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23332 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23333 +++ linux/fs/aufs/opts.c 2017-07-29 12:14:25.903042072 +0200
23336 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23338 + * This program, aufs is free software; you can redistribute it and/or modify
23339 + * it under the terms of the GNU General Public License as published by
23340 + * the Free Software Foundation; either version 2 of the License, or
23341 + * (at your option) any later version.
23343 + * This program is distributed in the hope that it will be useful,
23344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23346 + * GNU General Public License for more details.
23348 + * You should have received a copy of the GNU General Public License
23349 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23353 + * mount options/flags
23356 +#include <linux/namei.h>
23357 +#include <linux/types.h> /* a distribution requires */
23358 +#include <linux/parser.h>
23361 +/* ---------------------------------------------------------------------- */
23365 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23366 + Opt_idel, Opt_imod,
23367 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23368 + Opt_rdblk_def, Opt_rdhash_def,
23369 + Opt_xino, Opt_noxino,
23370 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23371 + Opt_trunc_xino_path, Opt_itrunc_xino,
23372 + Opt_trunc_xib, Opt_notrunc_xib,
23373 + Opt_shwh, Opt_noshwh,
23374 + Opt_plink, Opt_noplink, Opt_list_plink,
23376 + Opt_dio, Opt_nodio,
23377 + Opt_diropq_a, Opt_diropq_w,
23378 + Opt_warn_perm, Opt_nowarn_perm,
23379 + Opt_wbr_copyup, Opt_wbr_create,
23381 + Opt_verbose, Opt_noverbose,
23382 + Opt_sum, Opt_nosum, Opt_wsum,
23383 + Opt_dirperm1, Opt_nodirperm1,
23384 + Opt_acl, Opt_noacl,
23385 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23388 +static match_table_t options = {
23389 + {Opt_br, "br=%s"},
23390 + {Opt_br, "br:%s"},
23392 + {Opt_add, "add=%d:%s"},
23393 + {Opt_add, "add:%d:%s"},
23394 + {Opt_add, "ins=%d:%s"},
23395 + {Opt_add, "ins:%d:%s"},
23396 + {Opt_append, "append=%s"},
23397 + {Opt_append, "append:%s"},
23398 + {Opt_prepend, "prepend=%s"},
23399 + {Opt_prepend, "prepend:%s"},
23401 + {Opt_del, "del=%s"},
23402 + {Opt_del, "del:%s"},
23403 + /* {Opt_idel, "idel:%d"}, */
23404 + {Opt_mod, "mod=%s"},
23405 + {Opt_mod, "mod:%s"},
23406 + /* {Opt_imod, "imod:%d:%s"}, */
23408 + {Opt_dirwh, "dirwh=%d"},
23410 + {Opt_xino, "xino=%s"},
23411 + {Opt_noxino, "noxino"},
23412 + {Opt_trunc_xino, "trunc_xino"},
23413 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23414 + {Opt_notrunc_xino, "notrunc_xino"},
23415 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23416 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23417 + /* {Opt_zxino, "zxino=%s"}, */
23418 + {Opt_trunc_xib, "trunc_xib"},
23419 + {Opt_notrunc_xib, "notrunc_xib"},
23421 +#ifdef CONFIG_PROC_FS
23422 + {Opt_plink, "plink"},
23424 + {Opt_ignore_silent, "plink"},
23427 + {Opt_noplink, "noplink"},
23429 +#ifdef CONFIG_AUFS_DEBUG
23430 + {Opt_list_plink, "list_plink"},
23433 + {Opt_udba, "udba=%s"},
23435 + {Opt_dio, "dio"},
23436 + {Opt_nodio, "nodio"},
23438 +#ifdef CONFIG_AUFS_FHSM
23439 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23441 + {Opt_ignore_silent, "fhsm_sec=%d"},
23444 + {Opt_diropq_a, "diropq=always"},
23445 + {Opt_diropq_a, "diropq=a"},
23446 + {Opt_diropq_w, "diropq=whiteouted"},
23447 + {Opt_diropq_w, "diropq=w"},
23449 + {Opt_warn_perm, "warn_perm"},
23450 + {Opt_nowarn_perm, "nowarn_perm"},
23452 + /* keep them temporary */
23453 + {Opt_ignore_silent, "nodlgt"},
23454 + {Opt_ignore_silent, "clean_plink"},
23456 +#ifdef CONFIG_AUFS_SHWH
23457 + {Opt_shwh, "shwh"},
23459 + {Opt_noshwh, "noshwh"},
23461 + {Opt_dirperm1, "dirperm1"},
23462 + {Opt_nodirperm1, "nodirperm1"},
23464 + {Opt_verbose, "verbose"},
23465 + {Opt_verbose, "v"},
23466 + {Opt_noverbose, "noverbose"},
23467 + {Opt_noverbose, "quiet"},
23468 + {Opt_noverbose, "q"},
23469 + {Opt_noverbose, "silent"},
23471 + {Opt_sum, "sum"},
23472 + {Opt_nosum, "nosum"},
23473 + {Opt_wsum, "wsum"},
23475 + {Opt_rdcache, "rdcache=%d"},
23476 + {Opt_rdblk, "rdblk=%d"},
23477 + {Opt_rdblk_def, "rdblk=def"},
23478 + {Opt_rdhash, "rdhash=%d"},
23479 + {Opt_rdhash_def, "rdhash=def"},
23481 + {Opt_wbr_create, "create=%s"},
23482 + {Opt_wbr_create, "create_policy=%s"},
23483 + {Opt_wbr_copyup, "cpup=%s"},
23484 + {Opt_wbr_copyup, "copyup=%s"},
23485 + {Opt_wbr_copyup, "copyup_policy=%s"},
23487 + /* generic VFS flag */
23488 +#ifdef CONFIG_FS_POSIX_ACL
23489 + {Opt_acl, "acl"},
23490 + {Opt_noacl, "noacl"},
23492 + {Opt_ignore_silent, "acl"},
23493 + {Opt_ignore_silent, "noacl"},
23496 + /* internal use for the scripts */
23497 + {Opt_ignore_silent, "si=%s"},
23499 + {Opt_br, "dirs=%s"},
23500 + {Opt_ignore, "debug=%d"},
23501 + {Opt_ignore, "delete=whiteout"},
23502 + {Opt_ignore, "delete=all"},
23503 + {Opt_ignore, "imap=%s"},
23505 + /* temporary workaround, due to old mount(8)? */
23506 + {Opt_ignore_silent, "relatime"},
23511 +/* ---------------------------------------------------------------------- */
23513 +static const char *au_parser_pattern(int val, match_table_t tbl)
23515 + struct match_token *p;
23518 + while (p->pattern) {
23519 + if (p->token == val)
23520 + return p->pattern;
23527 +static const char *au_optstr(int *val, match_table_t tbl)
23529 + struct match_token *p;
23536 + while (p->pattern) {
23538 + && (v & p->token) == p->token) {
23539 + *val &= ~p->token;
23540 + return p->pattern;
23549 +/* ---------------------------------------------------------------------- */
23551 +static match_table_t brperm = {
23552 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23553 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23554 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23558 +static match_table_t brattr = {
23560 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23561 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23562 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23563 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23564 +#ifdef CONFIG_AUFS_FHSM
23565 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23567 +#ifdef CONFIG_AUFS_XATTR
23568 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23569 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23570 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23571 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23572 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23573 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23576 + /* ro/rr branch */
23577 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23580 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23581 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23586 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23593 + p = strchr(str, '+');
23596 + v = match_token(str, table, args);
23598 + if (v & AuBrAttr_CMOO_Mask)
23599 + attr &= ~AuBrAttr_CMOO_Mask;
23604 + pr_warn("ignored branch attribute %s\n", str);
23614 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23622 + p = au_optstr(&perm, brattr);
23625 + memcpy(q, p, sz + 1);
23631 + p = au_optstr(&perm, brattr);
23635 + memcpy(q, p, sz + 1);
23641 + return q - str->a;
23644 +static int noinline_for_stack br_perm_val(char *perm)
23646 + int val, bad, sz;
23648 + substring_t args[MAX_OPT_ARGS];
23649 + au_br_perm_str_t attr;
23651 + p = strchr(perm, '+');
23654 + val = match_token(perm, brperm, args);
23658 + pr_warn("ignored branch permission %s\n", perm);
23659 + val = AuBrPerm_RO;
23665 + val |= br_attr_val(p + 1, brattr, args);
23668 + switch (val & AuBrPerm_Mask) {
23669 + case AuBrPerm_RO:
23670 + case AuBrPerm_RR:
23671 + bad = val & AuBrWAttr_Mask;
23672 + val &= ~AuBrWAttr_Mask;
23674 + case AuBrPerm_RW:
23675 + bad = val & AuBrRAttr_Mask;
23676 + val &= ~AuBrRAttr_Mask;
23681 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23682 + * does not treat it as an error, just warning.
23683 + * this is a tiny guard for the user operation.
23685 + if (val & AuBrAttr_UNPIN) {
23686 + bad |= AuBrAttr_UNPIN;
23687 + val &= ~AuBrAttr_UNPIN;
23690 + if (unlikely(bad)) {
23691 + sz = au_do_optstr_br_attr(&attr, bad);
23693 + pr_warn("ignored branch attribute %s\n", attr.a);
23700 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23702 + au_br_perm_str_t attr;
23708 + p = au_optstr(&perm, brperm);
23709 + AuDebugOn(!p || !*p);
23711 + memcpy(q, p, sz + 1);
23714 + sz = au_do_optstr_br_attr(&attr, perm);
23717 + memcpy(q, attr.a, sz + 1);
23720 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23723 +/* ---------------------------------------------------------------------- */
23725 +static match_table_t udbalevel = {
23726 + {AuOpt_UDBA_REVAL, "reval"},
23727 + {AuOpt_UDBA_NONE, "none"},
23728 +#ifdef CONFIG_AUFS_HNOTIFY
23729 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23730 +#ifdef CONFIG_AUFS_HFSNOTIFY
23731 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23737 +static int noinline_for_stack udba_val(char *str)
23739 + substring_t args[MAX_OPT_ARGS];
23741 + return match_token(str, udbalevel, args);
23744 +const char *au_optstr_udba(int udba)
23746 + return au_parser_pattern(udba, udbalevel);
23749 +/* ---------------------------------------------------------------------- */
23751 +static match_table_t au_wbr_create_policy = {
23752 + {AuWbrCreate_TDP, "tdp"},
23753 + {AuWbrCreate_TDP, "top-down-parent"},
23754 + {AuWbrCreate_RR, "rr"},
23755 + {AuWbrCreate_RR, "round-robin"},
23756 + {AuWbrCreate_MFS, "mfs"},
23757 + {AuWbrCreate_MFS, "most-free-space"},
23758 + {AuWbrCreate_MFSV, "mfs:%d"},
23759 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23761 + /* top-down regardless the parent, and then mfs */
23762 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23763 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23765 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23766 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23767 + {AuWbrCreate_PMFS, "pmfs"},
23768 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23769 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23770 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23775 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23776 + struct au_opt_wbr_create *create)
23779 + unsigned long long ull;
23782 + if (!match_u64(arg, &ull))
23783 + create->mfsrr_watermark = ull;
23785 + pr_err("bad integer in %s\n", str);
23792 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23793 + struct au_opt_wbr_create *create)
23798 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23799 + create->mfs_second = n;
23801 + pr_err("bad integer in %s\n", str);
23808 +static int noinline_for_stack
23809 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23812 + substring_t args[MAX_OPT_ARGS];
23814 + err = match_token(str, au_wbr_create_policy, args);
23815 + create->wbr_create = err;
23817 + case AuWbrCreate_MFSRRV:
23818 + case AuWbrCreate_TDMFSV:
23819 + case AuWbrCreate_PMFSRRV:
23820 + e = au_wbr_mfs_wmark(&args[0], str, create);
23822 + e = au_wbr_mfs_sec(&args[1], str, create);
23826 + case AuWbrCreate_MFSRR:
23827 + case AuWbrCreate_TDMFS:
23828 + case AuWbrCreate_PMFSRR:
23829 + e = au_wbr_mfs_wmark(&args[0], str, create);
23830 + if (unlikely(e)) {
23835 + case AuWbrCreate_MFS:
23836 + case AuWbrCreate_PMFS:
23837 + create->mfs_second = AUFS_MFS_DEF_SEC;
23839 + case AuWbrCreate_MFSV:
23840 + case AuWbrCreate_PMFSV:
23841 + e = au_wbr_mfs_sec(&args[0], str, create);
23850 +const char *au_optstr_wbr_create(int wbr_create)
23852 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23855 +static match_table_t au_wbr_copyup_policy = {
23856 + {AuWbrCopyup_TDP, "tdp"},
23857 + {AuWbrCopyup_TDP, "top-down-parent"},
23858 + {AuWbrCopyup_BUP, "bup"},
23859 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23860 + {AuWbrCopyup_BU, "bu"},
23861 + {AuWbrCopyup_BU, "bottom-up"},
23865 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23867 + substring_t args[MAX_OPT_ARGS];
23869 + return match_token(str, au_wbr_copyup_policy, args);
23872 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23874 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23877 +/* ---------------------------------------------------------------------- */
23879 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23881 +static void dump_opts(struct au_opts *opts)
23883 +#ifdef CONFIG_AUFS_DEBUG
23884 + /* reduce stack space */
23886 + struct au_opt_add *add;
23887 + struct au_opt_del *del;
23888 + struct au_opt_mod *mod;
23889 + struct au_opt_xino *xino;
23890 + struct au_opt_xino_itrunc *xino_itrunc;
23891 + struct au_opt_wbr_create *create;
23893 + struct au_opt *opt;
23896 + while (opt->type != Opt_tail) {
23897 + switch (opt->type) {
23899 + u.add = &opt->add;
23900 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23901 + u.add->bindex, u.add->pathname, u.add->perm,
23902 + u.add->path.dentry);
23906 + u.del = &opt->del;
23907 + AuDbg("del {%s, %p}\n",
23908 + u.del->pathname, u.del->h_path.dentry);
23912 + u.mod = &opt->mod;
23913 + AuDbg("mod {%s, 0x%x, %p}\n",
23914 + u.mod->path, u.mod->perm, u.mod->h_root);
23917 + u.add = &opt->add;
23918 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23919 + u.add->bindex, u.add->pathname, u.add->perm,
23920 + u.add->path.dentry);
23922 + case Opt_prepend:
23923 + u.add = &opt->add;
23924 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23925 + u.add->bindex, u.add->pathname, u.add->perm,
23926 + u.add->path.dentry);
23929 + AuDbg("dirwh %d\n", opt->dirwh);
23931 + case Opt_rdcache:
23932 + AuDbg("rdcache %d\n", opt->rdcache);
23935 + AuDbg("rdblk %u\n", opt->rdblk);
23937 + case Opt_rdblk_def:
23938 + AuDbg("rdblk_def\n");
23941 + AuDbg("rdhash %u\n", opt->rdhash);
23943 + case Opt_rdhash_def:
23944 + AuDbg("rdhash_def\n");
23947 + u.xino = &opt->xino;
23948 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23950 + case Opt_trunc_xino:
23951 + AuLabel(trunc_xino);
23953 + case Opt_notrunc_xino:
23954 + AuLabel(notrunc_xino);
23956 + case Opt_trunc_xino_path:
23957 + case Opt_itrunc_xino:
23958 + u.xino_itrunc = &opt->xino_itrunc;
23959 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23964 + case Opt_trunc_xib:
23965 + AuLabel(trunc_xib);
23967 + case Opt_notrunc_xib:
23968 + AuLabel(notrunc_xib);
23976 + case Opt_dirperm1:
23977 + AuLabel(dirperm1);
23979 + case Opt_nodirperm1:
23980 + AuLabel(nodirperm1);
23985 + case Opt_noplink:
23986 + AuLabel(noplink);
23988 + case Opt_list_plink:
23989 + AuLabel(list_plink);
23992 + AuDbg("udba %d, %s\n",
23993 + opt->udba, au_optstr_udba(opt->udba));
24001 + case Opt_diropq_a:
24002 + AuLabel(diropq_a);
24004 + case Opt_diropq_w:
24005 + AuLabel(diropq_w);
24007 + case Opt_warn_perm:
24008 + AuLabel(warn_perm);
24010 + case Opt_nowarn_perm:
24011 + AuLabel(nowarn_perm);
24013 + case Opt_verbose:
24014 + AuLabel(verbose);
24016 + case Opt_noverbose:
24017 + AuLabel(noverbose);
24028 + case Opt_wbr_create:
24029 + u.create = &opt->wbr_create;
24030 + AuDbg("create %d, %s\n", u.create->wbr_create,
24031 + au_optstr_wbr_create(u.create->wbr_create));
24032 + switch (u.create->wbr_create) {
24033 + case AuWbrCreate_MFSV:
24034 + case AuWbrCreate_PMFSV:
24035 + AuDbg("%d sec\n", u.create->mfs_second);
24037 + case AuWbrCreate_MFSRR:
24038 + case AuWbrCreate_TDMFS:
24039 + AuDbg("%llu watermark\n",
24040 + u.create->mfsrr_watermark);
24042 + case AuWbrCreate_MFSRRV:
24043 + case AuWbrCreate_TDMFSV:
24044 + case AuWbrCreate_PMFSRRV:
24045 + AuDbg("%llu watermark, %d sec\n",
24046 + u.create->mfsrr_watermark,
24047 + u.create->mfs_second);
24051 + case Opt_wbr_copyup:
24052 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
24053 + au_optstr_wbr_copyup(opt->wbr_copyup));
24055 + case Opt_fhsm_sec:
24056 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24072 +void au_opts_free(struct au_opts *opts)
24074 + struct au_opt *opt;
24077 + while (opt->type != Opt_tail) {
24078 + switch (opt->type) {
24081 + case Opt_prepend:
24082 + path_put(&opt->add.path);
24086 + path_put(&opt->del.h_path);
24090 + dput(opt->mod.h_root);
24093 + fput(opt->xino.file);
24100 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24101 + aufs_bindex_t bindex)
24104 + struct au_opt_add *add = &opt->add;
24107 + add->bindex = bindex;
24108 + add->perm = AuBrPerm_RO;
24109 + add->pathname = opt_str;
24110 + p = strchr(opt_str, '=');
24114 + add->perm = br_perm_val(p);
24117 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24120 + add->perm = AuBrPerm_RO;
24121 + if (au_test_fs_rr(add->path.dentry->d_sb))
24122 + add->perm = AuBrPerm_RR;
24123 + else if (!bindex && !(sb_flags & MS_RDONLY))
24124 + add->perm = AuBrPerm_RW;
24126 + opt->type = Opt_add;
24129 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24136 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24140 + del->pathname = args[0].from;
24141 + AuDbg("del path %s\n", del->pathname);
24143 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24144 + if (unlikely(err))
24145 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24150 +#if 0 /* reserved for future use */
24151 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24152 + struct au_opt_del *del, substring_t args[])
24155 + struct dentry *root;
24158 + root = sb->s_root;
24159 + aufs_read_lock(root, AuLock_FLUSH);
24160 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24161 + pr_err("out of bounds, %d\n", bindex);
24166 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24167 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24170 + aufs_read_unlock(root, !AuLock_IR);
24175 +static int noinline_for_stack
24176 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24179 + struct path path;
24183 + mod->path = args[0].from;
24184 + p = strchr(mod->path, '=');
24185 + if (unlikely(!p)) {
24186 + pr_err("no permssion %s\n", args[0].from);
24191 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24192 + if (unlikely(err)) {
24193 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24197 + mod->perm = br_perm_val(p);
24198 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24199 + mod->h_root = dget(path.dentry);
24206 +#if 0 /* reserved for future use */
24207 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24208 + struct au_opt_mod *mod, substring_t args[])
24211 + struct dentry *root;
24214 + root = sb->s_root;
24215 + aufs_read_lock(root, AuLock_FLUSH);
24216 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24217 + pr_err("out of bounds, %d\n", bindex);
24222 + mod->perm = br_perm_val(args[1].from);
24223 + AuDbg("mod path %s, perm 0x%x, %s\n",
24224 + mod->path, mod->perm, args[1].from);
24225 + mod->h_root = dget(au_h_dptr(root, bindex));
24228 + aufs_read_unlock(root, !AuLock_IR);
24233 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24234 + substring_t args[])
24237 + struct file *file;
24239 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24240 + err = PTR_ERR(file);
24241 + if (IS_ERR(file))
24245 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24247 + pr_err("%s must be outside\n", args[0].from);
24252 + xino->file = file;
24253 + xino->path = args[0].from;
24259 +static int noinline_for_stack
24260 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24261 + struct au_opt_xino_itrunc *xino_itrunc,
24262 + substring_t args[])
24265 + aufs_bindex_t bbot, bindex;
24266 + struct path path;
24267 + struct dentry *root;
24269 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24270 + if (unlikely(err)) {
24271 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24275 + xino_itrunc->bindex = -1;
24276 + root = sb->s_root;
24277 + aufs_read_lock(root, AuLock_FLUSH);
24278 + bbot = au_sbbot(sb);
24279 + for (bindex = 0; bindex <= bbot; bindex++) {
24280 + if (au_h_dptr(root, bindex) == path.dentry) {
24281 + xino_itrunc->bindex = bindex;
24285 + aufs_read_unlock(root, !AuLock_IR);
24288 + if (unlikely(xino_itrunc->bindex < 0)) {
24289 + pr_err("no such branch %s\n", args[0].from);
24297 +/* called without aufs lock */
24298 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24300 + int err, n, token;
24301 + aufs_bindex_t bindex;
24302 + unsigned char skipped;
24303 + struct dentry *root;
24304 + struct au_opt *opt, *opt_tail;
24306 + /* reduce the stack space */
24308 + struct au_opt_xino_itrunc *xino_itrunc;
24309 + struct au_opt_wbr_create *create;
24312 + substring_t args[MAX_OPT_ARGS];
24316 + a = kmalloc(sizeof(*a), GFP_NOFS);
24317 + if (unlikely(!a))
24320 + root = sb->s_root;
24324 + opt_tail = opt + opts->max_opt - 1;
24325 + opt->type = Opt_tail;
24326 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24329 + token = match_token(opt_str, options, a->args);
24333 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24335 + err = opt_add(opt, opt_str, opts->sb_flags,
24337 + if (unlikely(!err && ++opt > opt_tail)) {
24341 + opt->type = Opt_tail;
24346 + if (unlikely(match_int(&a->args[0], &n))) {
24347 + pr_err("bad integer in %s\n", opt_str);
24351 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24354 + opt->type = token;
24357 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24358 + /*dummy bindex*/1);
24360 + opt->type = token;
24362 + case Opt_prepend:
24363 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24366 + opt->type = token;
24369 + err = au_opts_parse_del(&opt->del, a->args);
24371 + opt->type = token;
24373 +#if 0 /* reserved for future use */
24375 + del->pathname = "(indexed)";
24376 + if (unlikely(match_int(&args[0], &n))) {
24377 + pr_err("bad integer in %s\n", opt_str);
24380 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24382 + opt->type = token;
24386 + err = au_opts_parse_mod(&opt->mod, a->args);
24388 + opt->type = token;
24390 +#ifdef IMOD /* reserved for future use */
24392 + u.mod->path = "(indexed)";
24393 + if (unlikely(match_int(&a->args[0], &n))) {
24394 + pr_err("bad integer in %s\n", opt_str);
24397 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24399 + opt->type = token;
24403 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24405 + opt->type = token;
24408 + case Opt_trunc_xino_path:
24409 + err = au_opts_parse_xino_itrunc_path
24410 + (sb, &opt->xino_itrunc, a->args);
24412 + opt->type = token;
24415 + case Opt_itrunc_xino:
24416 + u.xino_itrunc = &opt->xino_itrunc;
24417 + if (unlikely(match_int(&a->args[0], &n))) {
24418 + pr_err("bad integer in %s\n", opt_str);
24421 + u.xino_itrunc->bindex = n;
24422 + aufs_read_lock(root, AuLock_FLUSH);
24423 + if (n < 0 || au_sbbot(sb) < n) {
24424 + pr_err("out of bounds, %d\n", n);
24425 + aufs_read_unlock(root, !AuLock_IR);
24428 + aufs_read_unlock(root, !AuLock_IR);
24430 + opt->type = token;
24434 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24437 + opt->type = token;
24440 + case Opt_rdcache:
24441 + if (unlikely(match_int(&a->args[0], &n))) {
24442 + pr_err("bad integer in %s\n", opt_str);
24445 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24446 + pr_err("rdcache must be smaller than %d\n",
24447 + AUFS_RDCACHE_MAX);
24450 + opt->rdcache = n;
24452 + opt->type = token;
24455 + if (unlikely(match_int(&a->args[0], &n)
24457 + || n > KMALLOC_MAX_SIZE)) {
24458 + pr_err("bad integer in %s\n", opt_str);
24461 + if (unlikely(n && n < NAME_MAX)) {
24462 + pr_err("rdblk must be larger than %d\n",
24468 + opt->type = token;
24471 + if (unlikely(match_int(&a->args[0], &n)
24473 + || n * sizeof(struct hlist_head)
24474 + > KMALLOC_MAX_SIZE)) {
24475 + pr_err("bad integer in %s\n", opt_str);
24480 + opt->type = token;
24483 + case Opt_trunc_xino:
24484 + case Opt_notrunc_xino:
24486 + case Opt_trunc_xib:
24487 + case Opt_notrunc_xib:
24490 + case Opt_dirperm1:
24491 + case Opt_nodirperm1:
24493 + case Opt_noplink:
24494 + case Opt_list_plink:
24497 + case Opt_diropq_a:
24498 + case Opt_diropq_w:
24499 + case Opt_warn_perm:
24500 + case Opt_nowarn_perm:
24501 + case Opt_verbose:
24502 + case Opt_noverbose:
24506 + case Opt_rdblk_def:
24507 + case Opt_rdhash_def:
24511 + opt->type = token;
24515 + opt->udba = udba_val(a->args[0].from);
24516 + if (opt->udba >= 0) {
24518 + opt->type = token;
24520 + pr_err("wrong value, %s\n", opt_str);
24523 + case Opt_wbr_create:
24524 + u.create = &opt->wbr_create;
24525 + u.create->wbr_create
24526 + = au_wbr_create_val(a->args[0].from, u.create);
24527 + if (u.create->wbr_create >= 0) {
24529 + opt->type = token;
24531 + pr_err("wrong value, %s\n", opt_str);
24533 + case Opt_wbr_copyup:
24534 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24535 + if (opt->wbr_copyup >= 0) {
24537 + opt->type = token;
24539 + pr_err("wrong value, %s\n", opt_str);
24542 + case Opt_fhsm_sec:
24543 + if (unlikely(match_int(&a->args[0], &n)
24545 + pr_err("bad integer in %s\n", opt_str);
24548 + if (sysaufs_brs) {
24549 + opt->fhsm_second = n;
24550 + opt->type = token;
24552 + pr_warn("ignored %s\n", opt_str);
24557 + pr_warn("ignored %s\n", opt_str);
24559 + case Opt_ignore_silent:
24564 + pr_err("unknown option %s\n", opt_str);
24568 + if (!err && !skipped) {
24569 + if (unlikely(++opt > opt_tail)) {
24572 + opt->type = Opt_tail;
24575 + opt->type = Opt_tail;
24581 + if (unlikely(err))
24582 + au_opts_free(opts);
24588 +static int au_opt_wbr_create(struct super_block *sb,
24589 + struct au_opt_wbr_create *create)
24592 + struct au_sbinfo *sbinfo;
24594 + SiMustWriteLock(sb);
24596 + err = 1; /* handled */
24597 + sbinfo = au_sbi(sb);
24598 + if (sbinfo->si_wbr_create_ops->fin) {
24599 + err = sbinfo->si_wbr_create_ops->fin(sb);
24604 + sbinfo->si_wbr_create = create->wbr_create;
24605 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24606 + switch (create->wbr_create) {
24607 + case AuWbrCreate_MFSRRV:
24608 + case AuWbrCreate_MFSRR:
24609 + case AuWbrCreate_TDMFS:
24610 + case AuWbrCreate_TDMFSV:
24611 + case AuWbrCreate_PMFSRR:
24612 + case AuWbrCreate_PMFSRRV:
24613 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24615 + case AuWbrCreate_MFS:
24616 + case AuWbrCreate_MFSV:
24617 + case AuWbrCreate_PMFS:
24618 + case AuWbrCreate_PMFSV:
24619 + sbinfo->si_wbr_mfs.mfs_expire
24620 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24624 + if (sbinfo->si_wbr_create_ops->init)
24625 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24632 + * plus: processed without an error
24633 + * zero: unprocessed
24635 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24636 + struct au_opts *opts)
24639 + struct au_sbinfo *sbinfo;
24641 + SiMustWriteLock(sb);
24643 + err = 1; /* handled */
24644 + sbinfo = au_sbi(sb);
24645 + switch (opt->type) {
24647 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24648 + sbinfo->si_mntflags |= opt->udba;
24649 + opts->given_udba |= opt->udba;
24653 + au_opt_set(sbinfo->si_mntflags, PLINK);
24655 + case Opt_noplink:
24656 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24657 + au_plink_put(sb, /*verbose*/1);
24658 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24660 + case Opt_list_plink:
24661 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24662 + au_plink_list(sb);
24666 + au_opt_set(sbinfo->si_mntflags, DIO);
24667 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24670 + au_opt_clr(sbinfo->si_mntflags, DIO);
24671 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24674 + case Opt_fhsm_sec:
24675 + au_fhsm_set(sbinfo, opt->fhsm_second);
24678 + case Opt_diropq_a:
24679 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24681 + case Opt_diropq_w:
24682 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24685 + case Opt_warn_perm:
24686 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24688 + case Opt_nowarn_perm:
24689 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24692 + case Opt_verbose:
24693 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24695 + case Opt_noverbose:
24696 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24700 + au_opt_set(sbinfo->si_mntflags, SUM);
24703 + au_opt_clr(sbinfo->si_mntflags, SUM);
24704 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24706 + au_opt_clr(sbinfo->si_mntflags, SUM);
24707 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24710 + case Opt_wbr_create:
24711 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24713 + case Opt_wbr_copyup:
24714 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24715 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24719 + sbinfo->si_dirwh = opt->dirwh;
24722 + case Opt_rdcache:
24723 + sbinfo->si_rdcache
24724 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24727 + sbinfo->si_rdblk = opt->rdblk;
24729 + case Opt_rdblk_def:
24730 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24733 + sbinfo->si_rdhash = opt->rdhash;
24735 + case Opt_rdhash_def:
24736 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24740 + au_opt_set(sbinfo->si_mntflags, SHWH);
24743 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24746 + case Opt_dirperm1:
24747 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24749 + case Opt_nodirperm1:
24750 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24753 + case Opt_trunc_xino:
24754 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24756 + case Opt_notrunc_xino:
24757 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24760 + case Opt_trunc_xino_path:
24761 + case Opt_itrunc_xino:
24762 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24767 + case Opt_trunc_xib:
24768 + au_fset_opts(opts->flags, TRUNC_XIB);
24770 + case Opt_notrunc_xib:
24771 + au_fclr_opts(opts->flags, TRUNC_XIB);
24775 + sb->s_flags |= MS_POSIXACL;
24778 + sb->s_flags &= ~MS_POSIXACL;
24790 + * returns tri-state.
24791 + * plus: processed without an error
24792 + * zero: unprocessed
24795 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24796 + struct au_opts *opts)
24798 + int err, do_refresh;
24801 + switch (opt->type) {
24803 + opt->add.bindex = au_sbbot(sb) + 1;
24804 + if (opt->add.bindex < 0)
24805 + opt->add.bindex = 0;
24807 + case Opt_prepend:
24808 + opt->add.bindex = 0;
24809 + add: /* indented label */
24811 + err = au_br_add(sb, &opt->add,
24812 + au_ftest_opts(opts->flags, REMOUNT));
24815 + au_fset_opts(opts->flags, REFRESH);
24821 + err = au_br_del(sb, &opt->del,
24822 + au_ftest_opts(opts->flags, REMOUNT));
24825 + au_fset_opts(opts->flags, TRUNC_XIB);
24826 + au_fset_opts(opts->flags, REFRESH);
24832 + err = au_br_mod(sb, &opt->mod,
24833 + au_ftest_opts(opts->flags, REMOUNT),
24838 + au_fset_opts(opts->flags, REFRESH);
24845 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24846 + struct au_opt_xino **opt_xino,
24847 + struct au_opts *opts)
24850 + aufs_bindex_t bbot, bindex;
24851 + struct dentry *root, *parent, *h_root;
24854 + switch (opt->type) {
24856 + err = au_xino_set(sb, &opt->xino,
24857 + !!au_ftest_opts(opts->flags, REMOUNT));
24858 + if (unlikely(err))
24861 + *opt_xino = &opt->xino;
24862 + au_xino_brid_set(sb, -1);
24864 + /* safe d_parent access */
24865 + parent = opt->xino.file->f_path.dentry->d_parent;
24866 + root = sb->s_root;
24867 + bbot = au_sbbot(sb);
24868 + for (bindex = 0; bindex <= bbot; bindex++) {
24869 + h_root = au_h_dptr(root, bindex);
24870 + if (h_root == parent) {
24871 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24879 + au_xino_brid_set(sb, -1);
24880 + *opt_xino = (void *)-1;
24887 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24888 + unsigned int pending)
24891 + aufs_bindex_t bindex, bbot;
24892 + unsigned char do_plink, skip, do_free, can_no_dreval;
24893 + struct au_branch *br;
24894 + struct au_wbr *wbr;
24895 + struct dentry *root, *dentry;
24896 + struct inode *dir, *h_dir;
24897 + struct au_sbinfo *sbinfo;
24898 + struct au_hinode *hdir;
24900 + SiMustAnyLock(sb);
24902 + sbinfo = au_sbi(sb);
24903 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24905 + if (!(sb_flags & MS_RDONLY)) {
24906 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24907 + pr_warn("first branch should be rw\n");
24908 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24909 + pr_warn_once("shwh should be used with ro\n");
24912 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24913 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24914 + pr_warn_once("udba=*notify requires xino\n");
24916 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24917 + pr_warn_once("dirperm1 breaks the protection"
24918 + " by the permission bits on the lower branch\n");
24922 + root = sb->s_root;
24923 + dir = d_inode(root);
24924 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24925 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24927 + bbot = au_sbbot(sb);
24928 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24930 + h_dir = au_h_iptr(dir, bindex);
24931 + br = au_sbr(sb, bindex);
24933 + if ((br->br_perm & AuBrAttr_ICEX)
24934 + && !h_dir->i_op->listxattr)
24935 + br->br_perm &= ~AuBrAttr_ICEX;
24937 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24938 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24939 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24943 + wbr = br->br_wbr;
24945 + wbr_wh_read_lock(wbr);
24947 + if (!au_br_writable(br->br_perm)) {
24950 + || (!wbr->wbr_whbase
24951 + && !wbr->wbr_plink
24952 + && !wbr->wbr_orph));
24953 + } else if (!au_br_wh_linkable(br->br_perm)) {
24954 + /* skip = (!br->br_whbase && !br->br_orph); */
24955 + skip = (!wbr || !wbr->wbr_whbase);
24956 + if (skip && wbr) {
24958 + skip = !!wbr->wbr_plink;
24960 + skip = !wbr->wbr_plink;
24963 + /* skip = (br->br_whbase && br->br_ohph); */
24964 + skip = (wbr && wbr->wbr_whbase);
24967 + skip = !!wbr->wbr_plink;
24969 + skip = !wbr->wbr_plink;
24973 + wbr_wh_read_unlock(wbr);
24975 + if (can_no_dreval) {
24976 + dentry = br->br_path.dentry;
24977 + spin_lock(&dentry->d_lock);
24978 + if (dentry->d_flags &
24979 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24980 + can_no_dreval = 0;
24981 + spin_unlock(&dentry->d_lock);
24984 + if (au_br_fhsm(br->br_perm)) {
24986 + AuDebugOn(!br->br_fhsm);
24992 + hdir = au_hi(dir, bindex);
24993 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24995 + wbr_wh_write_lock(wbr);
24996 + err = au_wh_init(br, sb);
24998 + wbr_wh_write_unlock(wbr);
24999 + au_hn_inode_unlock(hdir);
25001 + if (!err && do_free) {
25003 + br->br_wbr = NULL;
25007 + if (can_no_dreval)
25008 + au_fset_si(sbinfo, NO_DREVAL);
25010 + au_fclr_si(sbinfo, NO_DREVAL);
25013 + au_fset_si(sbinfo, FHSM);
25014 + for (bindex = bbot; bindex >= 0; bindex--) {
25015 + br = au_sbr(sb, bindex);
25016 + if (au_br_fhsm(br->br_perm)) {
25017 + au_fhsm_set_bottom(sb, bindex);
25022 + au_fclr_si(sbinfo, FHSM);
25023 + au_fhsm_set_bottom(sb, -1);
25029 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
25032 + unsigned int tmp;
25033 + aufs_bindex_t bindex, bbot;
25034 + struct au_opt *opt;
25035 + struct au_opt_xino *opt_xino, xino;
25036 + struct au_sbinfo *sbinfo;
25037 + struct au_branch *br;
25038 + struct inode *dir;
25040 + SiMustWriteLock(sb);
25045 + while (err >= 0 && opt->type != Opt_tail)
25046 + err = au_opt_simple(sb, opt++, opts);
25049 + else if (unlikely(err < 0))
25052 + /* disable xino and udba temporary */
25053 + sbinfo = au_sbi(sb);
25054 + tmp = sbinfo->si_mntflags;
25055 + au_opt_clr(sbinfo->si_mntflags, XINO);
25056 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25059 + while (err >= 0 && opt->type != Opt_tail)
25060 + err = au_opt_br(sb, opt++, opts);
25063 + else if (unlikely(err < 0))
25066 + bbot = au_sbbot(sb);
25067 + if (unlikely(bbot < 0)) {
25069 + pr_err("no branches\n");
25073 + if (au_opt_test(tmp, XINO))
25074 + au_opt_set(sbinfo->si_mntflags, XINO);
25076 + while (!err && opt->type != Opt_tail)
25077 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25078 + if (unlikely(err))
25081 + err = au_opts_verify(sb, sb->s_flags, tmp);
25082 + if (unlikely(err))
25085 + /* restore xino */
25086 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25087 + xino.file = au_xino_def(sb);
25088 + err = PTR_ERR(xino.file);
25089 + if (IS_ERR(xino.file))
25092 + err = au_xino_set(sb, &xino, /*remount*/0);
25094 + if (unlikely(err))
25098 + /* restore udba */
25099 + tmp &= AuOptMask_UDBA;
25100 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25101 + sbinfo->si_mntflags |= tmp;
25102 + bbot = au_sbbot(sb);
25103 + for (bindex = 0; bindex <= bbot; bindex++) {
25104 + br = au_sbr(sb, bindex);
25105 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25106 + if (unlikely(err))
25107 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25109 + /* go on even if err */
25111 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25112 + dir = d_inode(sb->s_root);
25113 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25120 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25123 + unsigned char no_dreval;
25124 + struct inode *dir;
25125 + struct au_opt_xino *opt_xino;
25126 + struct au_opt *opt;
25127 + struct au_sbinfo *sbinfo;
25129 + SiMustWriteLock(sb);
25132 + dir = d_inode(sb->s_root);
25133 + sbinfo = au_sbi(sb);
25136 + while (err >= 0 && opt->type != Opt_tail) {
25137 + err = au_opt_simple(sb, opt, opts);
25139 + err = au_opt_br(sb, opt, opts);
25141 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25147 + /* go on even err */
25149 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25150 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25151 + if (unlikely(rerr && !err))
25154 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25155 + au_fset_opts(opts->flags, REFRESH_IDOP);
25157 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25158 + rerr = au_xib_trunc(sb);
25159 + if (unlikely(rerr && !err))
25163 + /* will be handled by the caller */
25164 + if (!au_ftest_opts(opts->flags, REFRESH)
25165 + && (opts->given_udba
25166 + || au_opt_test(sbinfo->si_mntflags, XINO)
25167 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25169 + au_fset_opts(opts->flags, REFRESH);
25171 + AuDbg("status 0x%x\n", opts->flags);
25175 +/* ---------------------------------------------------------------------- */
25177 +unsigned int au_opt_udba(struct super_block *sb)
25179 + return au_mntflags(sb) & AuOptMask_UDBA;
25181 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25182 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25183 +++ linux/fs/aufs/opts.h 2017-09-05 10:42:11.058755349 +0200
25186 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25188 + * This program, aufs is free software; you can redistribute it and/or modify
25189 + * it under the terms of the GNU General Public License as published by
25190 + * the Free Software Foundation; either version 2 of the License, or
25191 + * (at your option) any later version.
25193 + * This program is distributed in the hope that it will be useful,
25194 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25195 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25196 + * GNU General Public License for more details.
25198 + * You should have received a copy of the GNU General Public License
25199 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25203 + * mount options/flags
25206 +#ifndef __AUFS_OPTS_H__
25207 +#define __AUFS_OPTS_H__
25211 +#include <linux/path.h>
25215 +/* ---------------------------------------------------------------------- */
25218 +#define AuOpt_XINO 1 /* external inode number bitmap
25219 + and translation table */
25220 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25221 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25222 +#define AuOpt_UDBA_REVAL (1 << 3)
25223 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25224 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25225 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25226 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25228 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25229 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25230 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25231 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25232 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25233 +#define AuOpt_DIO (1 << 14) /* direct io */
25235 +#ifndef CONFIG_AUFS_HNOTIFY
25236 +#undef AuOpt_UDBA_HNOTIFY
25237 +#define AuOpt_UDBA_HNOTIFY 0
25239 +#ifndef CONFIG_AUFS_SHWH
25241 +#define AuOpt_SHWH 0
25244 +#define AuOpt_Def (AuOpt_XINO \
25245 + | AuOpt_UDBA_REVAL \
25247 + /* | AuOpt_DIRPERM1 */ \
25248 + | AuOpt_WARN_PERM)
25249 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25250 + | AuOpt_UDBA_REVAL \
25251 + | AuOpt_UDBA_HNOTIFY)
25253 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25254 +#define au_opt_set(flags, name) do { \
25255 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25256 + ((flags) |= AuOpt_##name); \
25258 +#define au_opt_set_udba(flags, name) do { \
25259 + (flags) &= ~AuOptMask_UDBA; \
25260 + ((flags) |= AuOpt_##name); \
25262 +#define au_opt_clr(flags, name) do { \
25263 + ((flags) &= ~AuOpt_##name); \
25266 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25268 +#ifdef CONFIG_PROC_FS
25271 + return mntflags & ~AuOpt_PLINK;
25275 +/* ---------------------------------------------------------------------- */
25277 +/* policies to select one among multiple writable branches */
25279 + AuWbrCreate_TDP, /* top down parent */
25280 + AuWbrCreate_RR, /* round robin */
25281 + AuWbrCreate_MFS, /* most free space */
25282 + AuWbrCreate_MFSV, /* mfs with seconds */
25283 + AuWbrCreate_MFSRR, /* mfs then rr */
25284 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25285 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25286 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25287 + AuWbrCreate_PMFS, /* parent and mfs */
25288 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25289 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25290 + AuWbrCreate_PMFSRRV, /* plus seconds */
25292 + AuWbrCreate_Def = AuWbrCreate_TDP
25296 + AuWbrCopyup_TDP, /* top down parent */
25297 + AuWbrCopyup_BUP, /* bottom up parent */
25298 + AuWbrCopyup_BU, /* bottom up */
25300 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25303 +/* ---------------------------------------------------------------------- */
25305 +struct au_opt_add {
25306 + aufs_bindex_t bindex;
25309 + struct path path;
25312 +struct au_opt_del {
25314 + struct path h_path;
25317 +struct au_opt_mod {
25320 + struct dentry *h_root;
25323 +struct au_opt_xino {
25325 + struct file *file;
25328 +struct au_opt_xino_itrunc {
25329 + aufs_bindex_t bindex;
25332 +struct au_opt_wbr_create {
25335 + unsigned long long mfsrr_watermark;
25341 + struct au_opt_xino xino;
25342 + struct au_opt_xino_itrunc xino_itrunc;
25343 + struct au_opt_add add;
25344 + struct au_opt_del del;
25345 + struct au_opt_mod mod;
25348 + unsigned int rdblk;
25349 + unsigned int rdhash;
25351 + struct au_opt_wbr_create wbr_create;
25353 + unsigned int fhsm_second;
25358 +#define AuOpts_REMOUNT 1
25359 +#define AuOpts_REFRESH (1 << 1)
25360 +#define AuOpts_TRUNC_XIB (1 << 2)
25361 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25362 +#define AuOpts_REFRESH_IDOP (1 << 4)
25363 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25364 +#define au_fset_opts(flags, name) \
25365 + do { (flags) |= AuOpts_##name; } while (0)
25366 +#define au_fclr_opts(flags, name) \
25367 + do { (flags) &= ~AuOpts_##name; } while (0)
25370 + struct au_opt *opt;
25373 + unsigned int given_udba;
25374 + unsigned int flags;
25375 + unsigned long sb_flags;
25378 +/* ---------------------------------------------------------------------- */
25381 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25382 +const char *au_optstr_udba(int udba);
25383 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25384 +const char *au_optstr_wbr_create(int wbr_create);
25386 +void au_opts_free(struct au_opts *opts);
25387 +struct super_block;
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-09-05 10:42:11.058755349 +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 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
25620 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25621 + inode_unlock_shared(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-09-05 10:42:11.058755349 +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 +/* why VFS doesn't define it? */
31548 +void vfsub_inode_lock_shared_nested(struct inode *inode, unsigned int sc)
31550 + down_read_nested(&inode->i_rwsem, sc);
31553 +/* ---------------------------------------------------------------------- */
31555 +static inline void vfsub_drop_nlink(struct inode *inode)
31557 + AuDebugOn(!inode->i_nlink);
31558 + drop_nlink(inode);
31561 +static inline void vfsub_dead_dir(struct inode *inode)
31563 + AuDebugOn(!S_ISDIR(inode->i_mode));
31564 + inode->i_flags |= S_DEAD;
31565 + clear_nlink(inode);
31568 +static inline int vfsub_native_ro(struct inode *inode)
31570 + return (inode->i_sb->s_flags & MS_RDONLY)
31571 + || IS_RDONLY(inode)
31572 + /* || IS_APPEND(inode) */
31573 + || IS_IMMUTABLE(inode);
31576 +#ifdef CONFIG_AUFS_BR_FUSE
31577 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31579 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31582 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
31584 +/* ---------------------------------------------------------------------- */
31586 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31587 +struct file *vfsub_dentry_open(struct path *path, int flags);
31588 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31589 +struct vfsub_aopen_args {
31590 + struct file *file;
31591 + unsigned int open_flag;
31592 + umode_t create_mode;
31596 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31597 + struct vfsub_aopen_args *args, struct au_branch *br);
31598 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31600 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31601 + struct dentry *parent, int len);
31602 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31605 +struct vfsub_lkup_one_args {
31606 + struct dentry **errp;
31607 + struct qstr *name;
31608 + struct dentry *parent;
31611 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31612 + struct dentry *parent)
31614 + return vfsub_lookup_one_len(name->name, parent, name->len);
31617 +void vfsub_call_lkup_one(void *args);
31619 +/* ---------------------------------------------------------------------- */
31621 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31626 + err = mnt_want_write(mnt);
31631 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31634 + mnt_drop_write(mnt);
31638 +#if 0 /* reserved */
31639 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31642 + mnt_drop_write_file(file);
31647 +/* ---------------------------------------------------------------------- */
31650 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31651 + struct dentry *d2, struct au_hinode *hdir2);
31652 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31653 + struct dentry *d2, struct au_hinode *hdir2);
31655 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31657 +int vfsub_symlink(struct inode *dir, struct path *path,
31658 + const char *symname);
31659 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31660 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31661 + struct path *path, struct inode **delegated_inode);
31662 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31663 + struct inode *hdir, struct path *path,
31664 + struct inode **delegated_inode, unsigned int flags);
31665 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31666 +int vfsub_rmdir(struct inode *dir, struct path *path);
31668 +/* ---------------------------------------------------------------------- */
31670 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31672 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31674 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31676 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31678 +int vfsub_flush(struct file *file, fl_owner_t id);
31679 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31681 +static inline loff_t vfsub_f_size_read(struct file *file)
31683 + return i_size_read(file_inode(file));
31686 +static inline unsigned int vfsub_file_flags(struct file *file)
31688 + unsigned int flags;
31690 + spin_lock(&file->f_lock);
31691 + flags = file->f_flags;
31692 + spin_unlock(&file->f_lock);
31697 +static inline int vfsub_file_execed(struct file *file)
31699 + /* todo: direct access f_flags */
31700 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31703 +#if 0 /* reserved */
31704 +static inline void vfsub_file_accessed(struct file *h_file)
31706 + file_accessed(h_file);
31707 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31711 +#if 0 /* reserved */
31712 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31713 + struct dentry *h_dentry)
31715 + struct path h_path = {
31716 + .dentry = h_dentry,
31719 + touch_atime(&h_path);
31720 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31724 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31727 + return update_time(h_inode, ts, flags);
31728 + /* no vfsub_update_h_iattr() since we don't have struct path */
31731 +#ifdef CONFIG_FS_POSIX_ACL
31732 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31736 + err = posix_acl_chmod(h_inode, h_mode);
31737 + if (err == -EOPNOTSUPP)
31742 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31745 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31746 + struct pipe_inode_info *pipe, size_t len,
31747 + unsigned int flags);
31748 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31749 + loff_t *ppos, size_t len, unsigned int flags);
31751 +static inline long vfsub_truncate(struct path *path, loff_t length)
31756 + err = vfs_truncate(path, length);
31761 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31762 + struct file *h_file);
31763 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31766 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
31769 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
31775 + err = vfs_clone_file_range(src, 0, dst, 0, len);
31781 +/* copy_file_range(2) is a systemcall */
31782 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
31783 + struct file *dst, loff_t dst_pos,
31784 + size_t len, unsigned int flags)
31789 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
31795 +/* ---------------------------------------------------------------------- */
31797 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31802 + err = vfs_llseek(file, offset, origin);
31807 +/* ---------------------------------------------------------------------- */
31809 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31810 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31811 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31812 + struct inode **delegated_inode);
31813 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31814 + struct inode **delegated_inode);
31815 +int vfsub_unlink(struct inode *dir, struct path *path,
31816 + struct inode **delegated_inode, int force);
31818 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
31820 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
31823 +/* ---------------------------------------------------------------------- */
31825 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31826 + const void *value, size_t size, int flags)
31831 + err = vfs_setxattr(dentry, name, value, size, flags);
31837 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31842 + err = vfs_removexattr(dentry, name);
31848 +#endif /* __KERNEL__ */
31849 +#endif /* __AUFS_VFSUB_H__ */
31850 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31851 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31852 +++ linux/fs/aufs/wbr_policy.c 2017-07-29 12:14:25.906375514 +0200
31855 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31857 + * This program, aufs is free software; you can redistribute it and/or modify
31858 + * it under the terms of the GNU General Public License as published by
31859 + * the Free Software Foundation; either version 2 of the License, or
31860 + * (at your option) any later version.
31862 + * This program is distributed in the hope that it will be useful,
31863 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31864 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31865 + * GNU General Public License for more details.
31867 + * You should have received a copy of the GNU General Public License
31868 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31872 + * policies for selecting one among multiple writable branches
31875 +#include <linux/statfs.h>
31878 +/* subset of cpup_attr() */
31879 +static noinline_for_stack
31880 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31884 + struct inode *h_isrc;
31886 + h_isrc = d_inode(h_src);
31887 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31888 + ia.ia_mode = h_isrc->i_mode;
31889 + ia.ia_uid = h_isrc->i_uid;
31890 + ia.ia_gid = h_isrc->i_gid;
31891 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31892 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31893 + /* no delegation since it is just created */
31894 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31896 + /* is this nfs only? */
31897 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31898 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31899 + ia.ia_mode = h_isrc->i_mode;
31900 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31906 +#define AuCpdown_PARENT_OPQ 1
31907 +#define AuCpdown_WHED (1 << 1)
31908 +#define AuCpdown_MADE_DIR (1 << 2)
31909 +#define AuCpdown_DIROPQ (1 << 3)
31910 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31911 +#define au_fset_cpdown(flags, name) \
31912 + do { (flags) |= AuCpdown_##name; } while (0)
31913 +#define au_fclr_cpdown(flags, name) \
31914 + do { (flags) &= ~AuCpdown_##name; } while (0)
31916 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31917 + unsigned int *flags)
31920 + struct dentry *opq_dentry;
31922 + opq_dentry = au_diropq_create(dentry, bdst);
31923 + err = PTR_ERR(opq_dentry);
31924 + if (IS_ERR(opq_dentry))
31926 + dput(opq_dentry);
31927 + au_fset_cpdown(*flags, DIROPQ);
31933 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31934 + struct inode *dir, aufs_bindex_t bdst)
31937 + struct path h_path;
31938 + struct au_branch *br;
31940 + br = au_sbr(dentry->d_sb, bdst);
31941 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31942 + err = PTR_ERR(h_path.dentry);
31943 + if (IS_ERR(h_path.dentry))
31947 + if (d_is_positive(h_path.dentry)) {
31948 + h_path.mnt = au_br_mnt(br);
31949 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31952 + dput(h_path.dentry);
31958 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31959 + struct au_pin *pin,
31960 + struct dentry *h_parent, void *arg)
31963 + aufs_bindex_t bopq, btop;
31964 + struct path h_path;
31965 + struct dentry *parent;
31966 + struct inode *h_dir, *h_inode, *inode, *dir;
31967 + unsigned int *flags = arg;
31969 + btop = au_dbtop(dentry);
31970 + /* dentry is di-locked */
31971 + parent = dget_parent(dentry);
31972 + dir = d_inode(parent);
31973 + h_dir = d_inode(h_parent);
31974 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31975 + IMustLock(h_dir);
31977 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31978 + if (unlikely(err < 0))
31980 + h_path.dentry = au_h_dptr(dentry, bdst);
31981 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31982 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31983 + S_IRWXU | S_IRUGO | S_IXUGO);
31984 + if (unlikely(err))
31986 + au_fset_cpdown(*flags, MADE_DIR);
31988 + bopq = au_dbdiropq(dentry);
31989 + au_fclr_cpdown(*flags, WHED);
31990 + au_fclr_cpdown(*flags, DIROPQ);
31991 + if (au_dbwh(dentry) == bdst)
31992 + au_fset_cpdown(*flags, WHED);
31993 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31994 + au_fset_cpdown(*flags, PARENT_OPQ);
31995 + h_inode = d_inode(h_path.dentry);
31996 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31997 + if (au_ftest_cpdown(*flags, WHED)) {
31998 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31999 + if (unlikely(err)) {
32000 + inode_unlock(h_inode);
32005 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
32006 + inode_unlock(h_inode);
32007 + if (unlikely(err))
32010 + if (au_ftest_cpdown(*flags, WHED)) {
32011 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
32012 + if (unlikely(err))
32016 + inode = d_inode(dentry);
32017 + if (au_ibbot(inode) < bdst)
32018 + au_set_ibbot(inode, bdst);
32019 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
32020 + au_hi_flags(inode, /*isdir*/1));
32021 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
32022 + goto out; /* success */
32026 + if (au_ftest_cpdown(*flags, DIROPQ)) {
32027 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
32028 + rerr = au_diropq_remove(dentry, bdst);
32029 + inode_unlock(h_inode);
32030 + if (unlikely(rerr)) {
32031 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
32032 + dentry, bdst, rerr);
32038 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
32039 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
32040 + if (unlikely(rerr)) {
32041 + AuIOErr("failed removing %pd b%d (%d)\n",
32042 + dentry, bdst, rerr);
32047 + au_set_h_dptr(dentry, bdst, NULL);
32048 + if (au_dbbot(dentry) == bdst)
32049 + au_update_dbbot(dentry);
32055 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
32058 + unsigned int flags;
32061 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
32066 +/* ---------------------------------------------------------------------- */
32068 +/* policies for create */
32070 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
32072 + int err, i, j, ndentry;
32073 + aufs_bindex_t bopq;
32074 + struct au_dcsub_pages dpages;
32075 + struct au_dpage *dpage;
32076 + struct dentry **dentries, *parent, *d;
32078 + err = au_dpages_init(&dpages, GFP_NOFS);
32079 + if (unlikely(err))
32081 + parent = dget_parent(dentry);
32082 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
32083 + if (unlikely(err))
32087 + for (i = 0; i < dpages.ndpage; i++) {
32088 + dpage = dpages.dpages + i;
32089 + dentries = dpage->dentries;
32090 + ndentry = dpage->ndentry;
32091 + for (j = 0; j < ndentry; j++) {
32093 + di_read_lock_parent2(d, !AuLock_IR);
32094 + bopq = au_dbdiropq(d);
32095 + di_read_unlock(d, !AuLock_IR);
32096 + if (bopq >= 0 && bopq < err)
32103 + au_dpages_free(&dpages);
32108 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32110 + for (; bindex >= 0; bindex--)
32111 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32116 +/* top down parent */
32117 +static int au_wbr_create_tdp(struct dentry *dentry,
32118 + unsigned int flags __maybe_unused)
32121 + aufs_bindex_t btop, bindex;
32122 + struct super_block *sb;
32123 + struct dentry *parent, *h_parent;
32125 + sb = dentry->d_sb;
32126 + btop = au_dbtop(dentry);
32128 + if (!au_br_rdonly(au_sbr(sb, btop)))
32132 + parent = dget_parent(dentry);
32133 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32134 + h_parent = au_h_dptr(parent, bindex);
32135 + if (!h_parent || d_is_negative(h_parent))
32138 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32145 + /* bottom up here */
32146 + if (unlikely(err < 0)) {
32147 + err = au_wbr_bu(sb, btop - 1);
32149 + err = au_wbr_nonopq(dentry, err);
32153 + AuDbg("b%d\n", err);
32157 +/* ---------------------------------------------------------------------- */
32159 +/* an exception for the policy other than tdp */
32160 +static int au_wbr_create_exp(struct dentry *dentry)
32163 + aufs_bindex_t bwh, bdiropq;
32164 + struct dentry *parent;
32167 + bwh = au_dbwh(dentry);
32168 + parent = dget_parent(dentry);
32169 + bdiropq = au_dbdiropq(parent);
32171 + if (bdiropq >= 0)
32172 + err = min(bdiropq, bwh);
32175 + AuDbg("%d\n", err);
32176 + } else if (bdiropq >= 0) {
32178 + AuDbg("%d\n", err);
32183 + err = au_wbr_nonopq(dentry, err);
32185 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32188 + AuDbg("%d\n", err);
32192 +/* ---------------------------------------------------------------------- */
32195 +static int au_wbr_create_init_rr(struct super_block *sb)
32199 + err = au_wbr_bu(sb, au_sbbot(sb));
32200 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32203 + AuDbg("b%d\n", err);
32207 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32211 + aufs_bindex_t bindex, bbot;
32212 + struct super_block *sb;
32215 + err = au_wbr_create_exp(dentry);
32219 + sb = dentry->d_sb;
32220 + next = &au_sbi(sb)->si_wbr_rr_next;
32221 + bbot = au_sbbot(sb);
32223 + for (bindex = 0; bindex <= bbot; bindex++) {
32224 + if (!au_ftest_wbr(flags, DIR)) {
32225 + err = atomic_dec_return(next) + 1;
32226 + /* modulo for 0 is meaningless */
32227 + if (unlikely(!err))
32228 + err = atomic_dec_return(next) + 1;
32230 + err = atomic_read(next);
32231 + AuDbg("%d\n", err);
32234 + AuDbg("%d\n", err);
32235 + if (!au_br_rdonly(au_sbr(sb, err)))
32241 + err = au_wbr_nonopq(dentry, err);
32244 + AuDbg("%d\n", err);
32248 +/* ---------------------------------------------------------------------- */
32250 +/* most free space */
32251 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32253 + struct super_block *sb;
32254 + struct au_branch *br;
32255 + struct au_wbr_mfs *mfs;
32256 + struct dentry *h_parent;
32257 + aufs_bindex_t bindex, bbot;
32259 + unsigned long long b, bavail;
32260 + struct path h_path;
32261 + /* reduce the stack usage */
32262 + struct kstatfs *st;
32264 + st = kmalloc(sizeof(*st), GFP_NOFS);
32265 + if (unlikely(!st)) {
32266 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32271 + sb = dentry->d_sb;
32272 + mfs = &au_sbi(sb)->si_wbr_mfs;
32273 + MtxMustLock(&mfs->mfs_lock);
32274 + mfs->mfs_bindex = -EROFS;
32275 + mfs->mfsrr_bytes = 0;
32278 + bbot = au_sbbot(sb);
32280 + bindex = au_dbtop(parent);
32281 + bbot = au_dbtaildir(parent);
32284 + for (; bindex <= bbot; bindex++) {
32286 + h_parent = au_h_dptr(parent, bindex);
32287 + if (!h_parent || d_is_negative(h_parent))
32290 + br = au_sbr(sb, bindex);
32291 + if (au_br_rdonly(br))
32294 + /* sb->s_root for NFS is unreliable */
32295 + h_path.mnt = au_br_mnt(br);
32296 + h_path.dentry = h_path.mnt->mnt_root;
32297 + err = vfs_statfs(&h_path, st);
32298 + if (unlikely(err)) {
32299 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32303 + /* when the available size is equal, select the lower one */
32304 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32305 + || sizeof(b) < sizeof(st->f_bsize));
32306 + b = st->f_bavail * st->f_bsize;
32307 + br->br_wbr->wbr_bytes = b;
32308 + if (b >= bavail) {
32310 + mfs->mfs_bindex = bindex;
32311 + mfs->mfs_jiffy = jiffies;
32315 + mfs->mfsrr_bytes = bavail;
32316 + AuDbg("b%d\n", mfs->mfs_bindex);
32320 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32323 + struct dentry *parent;
32324 + struct super_block *sb;
32325 + struct au_wbr_mfs *mfs;
32327 + err = au_wbr_create_exp(dentry);
32331 + sb = dentry->d_sb;
32333 + if (au_ftest_wbr(flags, PARENT))
32334 + parent = dget_parent(dentry);
32335 + mfs = &au_sbi(sb)->si_wbr_mfs;
32336 + mutex_lock(&mfs->mfs_lock);
32337 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32338 + || mfs->mfs_bindex < 0
32339 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32340 + au_mfs(dentry, parent);
32341 + mutex_unlock(&mfs->mfs_lock);
32342 + err = mfs->mfs_bindex;
32346 + err = au_wbr_nonopq(dentry, err);
32349 + AuDbg("b%d\n", err);
32353 +static int au_wbr_create_init_mfs(struct super_block *sb)
32355 + struct au_wbr_mfs *mfs;
32357 + mfs = &au_sbi(sb)->si_wbr_mfs;
32358 + mutex_init(&mfs->mfs_lock);
32359 + mfs->mfs_jiffy = 0;
32360 + mfs->mfs_bindex = -EROFS;
32365 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32367 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32371 +/* ---------------------------------------------------------------------- */
32373 +/* top down regardless parent, and then mfs */
32374 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32375 + unsigned int flags __maybe_unused)
32378 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32379 + unsigned long long watermark;
32380 + struct super_block *sb;
32381 + struct au_wbr_mfs *mfs;
32382 + struct au_branch *br;
32383 + struct dentry *parent;
32385 + sb = dentry->d_sb;
32386 + mfs = &au_sbi(sb)->si_wbr_mfs;
32387 + mutex_lock(&mfs->mfs_lock);
32388 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32389 + || mfs->mfs_bindex < 0)
32390 + au_mfs(dentry, /*parent*/NULL);
32391 + watermark = mfs->mfsrr_watermark;
32392 + bmfs = mfs->mfs_bindex;
32393 + mutex_unlock(&mfs->mfs_lock);
32395 + /* another style of au_wbr_create_exp() */
32396 + bwh = au_dbwh(dentry);
32397 + parent = dget_parent(dentry);
32398 + btail = au_dbtaildir(parent);
32399 + if (bwh >= 0 && bwh < btail)
32402 + err = au_wbr_nonopq(dentry, btail);
32403 + if (unlikely(err < 0))
32407 + for (bindex = 0; bindex <= btail; bindex++) {
32408 + br = au_sbr(sb, bindex);
32409 + if (au_br_rdonly(br))
32411 + if (br->br_wbr->wbr_bytes > watermark) {
32422 + AuDbg("b%d\n", err);
32426 +/* ---------------------------------------------------------------------- */
32428 +/* most free space and then round robin */
32429 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32432 + struct au_wbr_mfs *mfs;
32434 + err = au_wbr_create_mfs(dentry, flags);
32436 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32437 + mutex_lock(&mfs->mfs_lock);
32438 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32439 + err = au_wbr_create_rr(dentry, flags);
32440 + mutex_unlock(&mfs->mfs_lock);
32443 + AuDbg("b%d\n", err);
32447 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32451 + au_wbr_create_init_mfs(sb); /* ignore */
32452 + err = au_wbr_create_init_rr(sb);
32457 +/* ---------------------------------------------------------------------- */
32459 +/* top down parent and most free space */
32460 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32463 + unsigned long long b;
32464 + aufs_bindex_t bindex, btop, bbot;
32465 + struct super_block *sb;
32466 + struct dentry *parent, *h_parent;
32467 + struct au_branch *br;
32469 + err = au_wbr_create_tdp(dentry, flags);
32470 + if (unlikely(err < 0))
32472 + parent = dget_parent(dentry);
32473 + btop = au_dbtop(parent);
32474 + bbot = au_dbtaildir(parent);
32475 + if (btop == bbot)
32476 + goto out_parent; /* success */
32478 + e2 = au_wbr_create_mfs(dentry, flags);
32480 + goto out_parent; /* success */
32482 + /* when the available size is equal, select upper one */
32483 + sb = dentry->d_sb;
32484 + br = au_sbr(sb, err);
32485 + b = br->br_wbr->wbr_bytes;
32486 + AuDbg("b%d, %llu\n", err, b);
32488 + for (bindex = btop; bindex <= bbot; bindex++) {
32489 + h_parent = au_h_dptr(parent, bindex);
32490 + if (!h_parent || d_is_negative(h_parent))
32493 + br = au_sbr(sb, bindex);
32494 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32495 + b = br->br_wbr->wbr_bytes;
32497 + AuDbg("b%d, %llu\n", err, b);
32502 + err = au_wbr_nonopq(dentry, err);
32507 + AuDbg("b%d\n", err);
32511 +/* ---------------------------------------------------------------------- */
32514 + * - top down parent
32515 + * - most free space with parent
32516 + * - most free space round-robin regardless parent
32518 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32521 + unsigned long long watermark;
32522 + struct super_block *sb;
32523 + struct au_branch *br;
32524 + struct au_wbr_mfs *mfs;
32526 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32527 + if (unlikely(err < 0))
32530 + sb = dentry->d_sb;
32531 + br = au_sbr(sb, err);
32532 + mfs = &au_sbi(sb)->si_wbr_mfs;
32533 + mutex_lock(&mfs->mfs_lock);
32534 + watermark = mfs->mfsrr_watermark;
32535 + mutex_unlock(&mfs->mfs_lock);
32536 + if (br->br_wbr->wbr_bytes < watermark)
32537 + /* regardless the parent dir */
32538 + err = au_wbr_create_mfsrr(dentry, flags);
32541 + AuDbg("b%d\n", err);
32545 +/* ---------------------------------------------------------------------- */
32547 +/* policies for copyup */
32549 +/* top down parent */
32550 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32552 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32555 +/* bottom up parent */
32556 +static int au_wbr_copyup_bup(struct dentry *dentry)
32559 + aufs_bindex_t bindex, btop;
32560 + struct dentry *parent, *h_parent;
32561 + struct super_block *sb;
32564 + sb = dentry->d_sb;
32565 + parent = dget_parent(dentry);
32566 + btop = au_dbtop(parent);
32567 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32568 + h_parent = au_h_dptr(parent, bindex);
32569 + if (!h_parent || d_is_negative(h_parent))
32572 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32579 + /* bottom up here */
32580 + if (unlikely(err < 0))
32581 + err = au_wbr_bu(sb, btop - 1);
32583 + AuDbg("b%d\n", err);
32588 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32592 + err = au_wbr_bu(dentry->d_sb, btop);
32593 + AuDbg("b%d\n", err);
32595 + err = au_wbr_nonopq(dentry, err);
32597 + AuDbg("b%d\n", err);
32601 +static int au_wbr_copyup_bu(struct dentry *dentry)
32604 + aufs_bindex_t btop;
32606 + btop = au_dbtop(dentry);
32607 + err = au_wbr_do_copyup_bu(dentry, btop);
32611 +/* ---------------------------------------------------------------------- */
32613 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32614 + [AuWbrCopyup_TDP] = {
32615 + .copyup = au_wbr_copyup_tdp
32617 + [AuWbrCopyup_BUP] = {
32618 + .copyup = au_wbr_copyup_bup
32620 + [AuWbrCopyup_BU] = {
32621 + .copyup = au_wbr_copyup_bu
32625 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32626 + [AuWbrCreate_TDP] = {
32627 + .create = au_wbr_create_tdp
32629 + [AuWbrCreate_RR] = {
32630 + .create = au_wbr_create_rr,
32631 + .init = au_wbr_create_init_rr
32633 + [AuWbrCreate_MFS] = {
32634 + .create = au_wbr_create_mfs,
32635 + .init = au_wbr_create_init_mfs,
32636 + .fin = au_wbr_create_fin_mfs
32638 + [AuWbrCreate_MFSV] = {
32639 + .create = au_wbr_create_mfs,
32640 + .init = au_wbr_create_init_mfs,
32641 + .fin = au_wbr_create_fin_mfs
32643 + [AuWbrCreate_MFSRR] = {
32644 + .create = au_wbr_create_mfsrr,
32645 + .init = au_wbr_create_init_mfsrr,
32646 + .fin = au_wbr_create_fin_mfs
32648 + [AuWbrCreate_MFSRRV] = {
32649 + .create = au_wbr_create_mfsrr,
32650 + .init = au_wbr_create_init_mfsrr,
32651 + .fin = au_wbr_create_fin_mfs
32653 + [AuWbrCreate_TDMFS] = {
32654 + .create = au_wbr_create_tdmfs,
32655 + .init = au_wbr_create_init_mfs,
32656 + .fin = au_wbr_create_fin_mfs
32658 + [AuWbrCreate_TDMFSV] = {
32659 + .create = au_wbr_create_tdmfs,
32660 + .init = au_wbr_create_init_mfs,
32661 + .fin = au_wbr_create_fin_mfs
32663 + [AuWbrCreate_PMFS] = {
32664 + .create = au_wbr_create_pmfs,
32665 + .init = au_wbr_create_init_mfs,
32666 + .fin = au_wbr_create_fin_mfs
32668 + [AuWbrCreate_PMFSV] = {
32669 + .create = au_wbr_create_pmfs,
32670 + .init = au_wbr_create_init_mfs,
32671 + .fin = au_wbr_create_fin_mfs
32673 + [AuWbrCreate_PMFSRR] = {
32674 + .create = au_wbr_create_pmfsrr,
32675 + .init = au_wbr_create_init_mfsrr,
32676 + .fin = au_wbr_create_fin_mfs
32678 + [AuWbrCreate_PMFSRRV] = {
32679 + .create = au_wbr_create_pmfsrr,
32680 + .init = au_wbr_create_init_mfsrr,
32681 + .fin = au_wbr_create_fin_mfs
32684 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32685 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32686 +++ linux/fs/aufs/whout.c 2017-07-29 12:14:25.906375514 +0200
32689 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32691 + * This program, aufs is free software; you can redistribute it and/or modify
32692 + * it under the terms of the GNU General Public License as published by
32693 + * the Free Software Foundation; either version 2 of the License, or
32694 + * (at your option) any later version.
32696 + * This program is distributed in the hope that it will be useful,
32697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32699 + * GNU General Public License for more details.
32701 + * You should have received a copy of the GNU General Public License
32702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32706 + * whiteout for logical deletion and opaque directory
32711 +#define WH_MASK S_IRUGO
32714 + * If a directory contains this file, then it is opaque. We start with the
32715 + * .wh. flag so that it is blocked by lookup.
32717 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32718 + sizeof(AUFS_WH_DIROPQ) - 1);
32721 + * generate whiteout name, which is NOT terminated by NULL.
32722 + * @name: original d_name.name
32723 + * @len: original d_name.len
32724 + * @wh: whiteout qstr
32725 + * returns zero when succeeds, otherwise error.
32726 + * succeeded value as wh->name should be freed by kfree().
32728 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32732 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32733 + return -ENAMETOOLONG;
32735 + wh->len = name->len + AUFS_WH_PFX_LEN;
32736 + p = kmalloc(wh->len, GFP_NOFS);
32739 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32740 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32747 +/* ---------------------------------------------------------------------- */
32750 + * test if the @wh_name exists under @h_parent.
32751 + * @try_sio specifies the necessary of super-io.
32753 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32756 + struct dentry *wh_dentry;
32759 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32761 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32762 + err = PTR_ERR(wh_dentry);
32763 + if (IS_ERR(wh_dentry)) {
32764 + if (err == -ENAMETOOLONG)
32770 + if (d_is_negative(wh_dentry))
32771 + goto out_wh; /* success */
32774 + if (d_is_reg(wh_dentry))
32775 + goto out_wh; /* success */
32778 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32779 + wh_dentry, d_inode(wh_dentry)->i_mode);
32788 + * test if the @h_dentry sets opaque or not.
32790 +int au_diropq_test(struct dentry *h_dentry)
32793 + struct inode *h_dir;
32795 + h_dir = d_inode(h_dentry);
32796 + err = au_wh_test(h_dentry, &diropq_name,
32797 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32802 + * returns a negative dentry whose name is unique and temporary.
32804 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32805 + struct qstr *prefix)
32807 + struct dentry *dentry;
32809 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32811 + /* strict atomic_t is unnecessary here */
32812 + static unsigned short cnt;
32815 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32818 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32819 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32820 + dentry = ERR_PTR(-ENAMETOOLONG);
32821 + if (unlikely(qs.len > NAME_MAX))
32823 + dentry = ERR_PTR(-ENOMEM);
32824 + name = kmalloc(qs.len + 1, GFP_NOFS);
32825 + if (unlikely(!name))
32829 + /* doubly whiteout-ed */
32830 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32831 + p = name + AUFS_WH_PFX_LEN * 2;
32832 + memcpy(p, prefix->name, prefix->len);
32833 + p += prefix->len;
32835 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32838 + for (i = 0; i < 3; i++) {
32839 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32840 + dentry = au_sio_lkup_one(&qs, h_parent);
32841 + if (IS_ERR(dentry) || d_is_negative(dentry))
32845 + /* pr_warn("could not get random name\n"); */
32846 + dentry = ERR_PTR(-EEXIST);
32847 + AuDbg("%.*s\n", AuLNPair(&qs));
32851 + if (name != defname)
32854 + AuTraceErrPtr(dentry);
32859 + * rename the @h_dentry on @br to the whiteouted temporary name.
32861 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32864 + struct path h_path = {
32865 + .mnt = au_br_mnt(br)
32867 + struct inode *h_dir, *delegated;
32868 + struct dentry *h_parent;
32870 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32871 + h_dir = d_inode(h_parent);
32872 + IMustLock(h_dir);
32874 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32875 + err = PTR_ERR(h_path.dentry);
32876 + if (IS_ERR(h_path.dentry))
32879 + /* under the same dir, no need to lock_rename() */
32880 + delegated = NULL;
32881 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
32884 + if (unlikely(err == -EWOULDBLOCK)) {
32885 + pr_warn("cannot retry for NFSv4 delegation"
32886 + " for an internal rename\n");
32889 + dput(h_path.dentry);
32896 +/* ---------------------------------------------------------------------- */
32898 + * functions for removing a whiteout
32901 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32904 + struct inode *delegated;
32907 + * forces superio when the dir has a sticky bit.
32908 + * this may be a violation of unix fs semantics.
32910 + force = (h_dir->i_mode & S_ISVTX)
32911 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32912 + delegated = NULL;
32913 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32914 + if (unlikely(err == -EWOULDBLOCK)) {
32915 + pr_warn("cannot retry for NFSv4 delegation"
32916 + " for an internal unlink\n");
32922 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32923 + struct dentry *dentry)
32927 + err = do_unlink_wh(h_dir, h_path);
32928 + if (!err && dentry)
32929 + au_set_dbwh(dentry, -1);
32934 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32935 + struct au_branch *br)
32938 + struct path h_path = {
32939 + .mnt = au_br_mnt(br)
32943 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32944 + if (IS_ERR(h_path.dentry))
32945 + err = PTR_ERR(h_path.dentry);
32947 + if (d_is_reg(h_path.dentry))
32948 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32949 + dput(h_path.dentry);
32955 +/* ---------------------------------------------------------------------- */
32957 + * initialize/clean whiteout for a branch
32960 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32964 + struct inode *delegated;
32966 + if (d_is_negative(whpath->dentry))
32970 + err = vfsub_rmdir(h_dir, whpath);
32972 + delegated = NULL;
32973 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32974 + if (unlikely(err == -EWOULDBLOCK)) {
32975 + pr_warn("cannot retry for NFSv4 delegation"
32976 + " for an internal unlink\n");
32980 + if (unlikely(err))
32981 + pr_warn("failed removing %pd (%d), ignored.\n",
32982 + whpath->dentry, err);
32985 +static int test_linkable(struct dentry *h_root)
32987 + struct inode *h_dir = d_inode(h_root);
32989 + if (h_dir->i_op->link)
32992 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32993 + h_root, au_sbtype(h_root->d_sb));
32997 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32998 +static int au_whdir(struct inode *h_dir, struct path *path)
33003 + if (d_is_negative(path->dentry)) {
33004 + int mode = S_IRWXU;
33006 + if (au_test_nfs(path->dentry->d_sb))
33008 + err = vfsub_mkdir(h_dir, path, mode);
33009 + } else if (d_is_dir(path->dentry))
33012 + pr_err("unknown %pd exists\n", path->dentry);
33017 +struct au_wh_base {
33018 + const struct qstr *name;
33019 + struct dentry *dentry;
33022 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
33023 + struct path *h_path)
33025 + h_path->dentry = base[AuBrWh_BASE].dentry;
33026 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33027 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33028 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33029 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33030 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33034 + * returns tri-state,
33035 + * minus: error, caller should print the message
33037 + * plus: error, caller should NOT print the message
33039 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
33040 + int do_plink, struct au_wh_base base[],
33041 + struct path *h_path)
33044 + struct inode *h_dir;
33046 + h_dir = d_inode(h_root);
33047 + h_path->dentry = base[AuBrWh_BASE].dentry;
33048 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33049 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33051 + err = test_linkable(h_root);
33052 + if (unlikely(err)) {
33057 + err = au_whdir(h_dir, h_path);
33058 + if (unlikely(err))
33060 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33062 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33063 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33064 + err = au_whdir(h_dir, h_path);
33065 + if (unlikely(err))
33067 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33074 + * for the moment, aufs supports the branch filesystem which does not support
33075 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
33076 + * copyup failed. finally, such filesystem will not be used as the writable
33079 + * returns tri-state, see above.
33081 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
33082 + int do_plink, struct au_wh_base base[],
33083 + struct path *h_path)
33086 + struct inode *h_dir;
33088 + WbrWhMustWriteLock(wbr);
33090 + err = test_linkable(h_root);
33091 + if (unlikely(err)) {
33097 + * todo: should this create be done in /sbin/mount.aufs helper?
33100 + h_dir = d_inode(h_root);
33101 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33102 + h_path->dentry = base[AuBrWh_BASE].dentry;
33103 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33104 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33107 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33108 + if (unlikely(err))
33111 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33113 + err = au_whdir(h_dir, h_path);
33114 + if (unlikely(err))
33116 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33118 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33119 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33121 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33122 + err = au_whdir(h_dir, h_path);
33123 + if (unlikely(err))
33125 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33132 + * initialize the whiteout base file/dir for @br.
33134 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33137 + const unsigned char do_plink
33138 + = !!au_opt_test(au_mntflags(sb), PLINK);
33139 + struct inode *h_dir;
33140 + struct path path = br->br_path;
33141 + struct dentry *h_root = path.dentry;
33142 + struct au_wbr *wbr = br->br_wbr;
33143 + static const struct qstr base_name[] = {
33144 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33145 + sizeof(AUFS_BASE_NAME) - 1),
33146 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33147 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33148 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33149 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33151 + struct au_wh_base base[] = {
33152 + [AuBrWh_BASE] = {
33153 + .name = base_name + AuBrWh_BASE,
33156 + [AuBrWh_PLINK] = {
33157 + .name = base_name + AuBrWh_PLINK,
33160 + [AuBrWh_ORPH] = {
33161 + .name = base_name + AuBrWh_ORPH,
33167 + WbrWhMustWriteLock(wbr);
33169 + for (i = 0; i < AuBrWh_Last; i++) {
33170 + /* doubly whiteouted */
33171 + struct dentry *d;
33173 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33174 + err = PTR_ERR(d);
33178 + base[i].dentry = d;
33180 + && wbr->wbr_wh[i]
33181 + && wbr->wbr_wh[i] != base[i].dentry);
33185 + for (i = 0; i < AuBrWh_Last; i++) {
33186 + dput(wbr->wbr_wh[i]);
33187 + wbr->wbr_wh[i] = NULL;
33191 + if (!au_br_writable(br->br_perm)) {
33192 + h_dir = d_inode(h_root);
33193 + au_wh_init_ro(h_dir, base, &path);
33194 + } else if (!au_br_wh_linkable(br->br_perm)) {
33195 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33201 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33207 + goto out; /* success */
33210 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33211 + err, h_root, au_sbtype(h_root->d_sb));
33213 + for (i = 0; i < AuBrWh_Last; i++)
33214 + dput(base[i].dentry);
33218 +/* ---------------------------------------------------------------------- */
33220 + * whiteouts are all hard-linked usually.
33221 + * when its link count reaches a ceiling, we create a new whiteout base
33222 + * asynchronously.
33225 +struct reinit_br_wh {
33226 + struct super_block *sb;
33227 + struct au_branch *br;
33230 +static void reinit_br_wh(void *arg)
33233 + aufs_bindex_t bindex;
33234 + struct path h_path;
33235 + struct reinit_br_wh *a = arg;
33236 + struct au_wbr *wbr;
33237 + struct inode *dir, *delegated;
33238 + struct dentry *h_root;
33239 + struct au_hinode *hdir;
33242 + wbr = a->br->br_wbr;
33243 + /* big aufs lock */
33244 + si_noflush_write_lock(a->sb);
33245 + if (!au_br_writable(a->br->br_perm))
33247 + bindex = au_br_index(a->sb, a->br->br_id);
33248 + if (unlikely(bindex < 0))
33251 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33252 + dir = d_inode(a->sb->s_root);
33253 + hdir = au_hi(dir, bindex);
33254 + h_root = au_h_dptr(a->sb->s_root, bindex);
33255 + AuDebugOn(h_root != au_br_dentry(a->br));
33257 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33258 + wbr_wh_write_lock(wbr);
33259 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33262 + h_path.dentry = wbr->wbr_whbase;
33263 + h_path.mnt = au_br_mnt(a->br);
33264 + delegated = NULL;
33265 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33267 + if (unlikely(err == -EWOULDBLOCK)) {
33268 + pr_warn("cannot retry for NFSv4 delegation"
33269 + " for an internal unlink\n");
33273 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33276 + dput(wbr->wbr_whbase);
33277 + wbr->wbr_whbase = NULL;
33279 + err = au_wh_init(a->br, a->sb);
33280 + wbr_wh_write_unlock(wbr);
33281 + au_hn_inode_unlock(hdir);
33282 + di_read_unlock(a->sb->s_root, AuLock_IR);
33284 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33288 + atomic_dec(&wbr->wbr_wh_running);
33289 + au_br_put(a->br);
33290 + si_write_unlock(a->sb);
33291 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33293 + if (unlikely(err))
33294 + AuIOErr("err %d\n", err);
33297 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33299 + int do_dec, wkq_err;
33300 + struct reinit_br_wh *arg;
33303 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33306 + /* ignore ENOMEM */
33307 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33310 + * dec(wh_running), kfree(arg) and dec(br_count)
33311 + * in reinit function
33316 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33317 + if (unlikely(wkq_err)) {
33318 + atomic_dec(&br->br_wbr->wbr_wh_running);
33327 + atomic_dec(&br->br_wbr->wbr_wh_running);
33330 +/* ---------------------------------------------------------------------- */
33333 + * create the whiteout @wh.
33335 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33336 + struct dentry *wh)
33339 + struct path h_path = {
33342 + struct au_branch *br;
33343 + struct au_wbr *wbr;
33344 + struct dentry *h_parent;
33345 + struct inode *h_dir, *delegated;
33347 + h_parent = wh->d_parent; /* dir inode is locked */
33348 + h_dir = d_inode(h_parent);
33349 + IMustLock(h_dir);
33351 + br = au_sbr(sb, bindex);
33352 + h_path.mnt = au_br_mnt(br);
33353 + wbr = br->br_wbr;
33354 + wbr_wh_read_lock(wbr);
33355 + if (wbr->wbr_whbase) {
33356 + delegated = NULL;
33357 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33358 + if (unlikely(err == -EWOULDBLOCK)) {
33359 + pr_warn("cannot retry for NFSv4 delegation"
33360 + " for an internal link\n");
33363 + if (!err || err != -EMLINK)
33366 + /* link count full. re-initialize br_whbase. */
33367 + kick_reinit_br_wh(sb, br);
33370 + /* return this error in this context */
33371 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33373 + au_fhsm_wrote(sb, bindex, /*force*/0);
33376 + wbr_wh_read_unlock(wbr);
33380 +/* ---------------------------------------------------------------------- */
33383 + * create or remove the diropq.
33385 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33386 + unsigned int flags)
33388 + struct dentry *opq_dentry, *h_dentry;
33389 + struct super_block *sb;
33390 + struct au_branch *br;
33393 + sb = dentry->d_sb;
33394 + br = au_sbr(sb, bindex);
33395 + h_dentry = au_h_dptr(dentry, bindex);
33396 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33397 + if (IS_ERR(opq_dentry))
33400 + if (au_ftest_diropq(flags, CREATE)) {
33401 + err = link_or_create_wh(sb, bindex, opq_dentry);
33403 + au_set_dbdiropq(dentry, bindex);
33404 + goto out; /* success */
33407 + struct path tmp = {
33408 + .dentry = opq_dentry,
33409 + .mnt = au_br_mnt(br)
33411 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33413 + au_set_dbdiropq(dentry, -1);
33415 + dput(opq_dentry);
33416 + opq_dentry = ERR_PTR(err);
33419 + return opq_dentry;
33422 +struct do_diropq_args {
33423 + struct dentry **errp;
33424 + struct dentry *dentry;
33425 + aufs_bindex_t bindex;
33426 + unsigned int flags;
33429 +static void call_do_diropq(void *args)
33431 + struct do_diropq_args *a = args;
33432 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33435 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33436 + unsigned int flags)
33438 + struct dentry *diropq, *h_dentry;
33440 + h_dentry = au_h_dptr(dentry, bindex);
33441 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33442 + diropq = do_diropq(dentry, bindex, flags);
33445 + struct do_diropq_args args = {
33447 + .dentry = dentry,
33448 + .bindex = bindex,
33452 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33453 + if (unlikely(wkq_err))
33454 + diropq = ERR_PTR(wkq_err);
33460 +/* ---------------------------------------------------------------------- */
33463 + * lookup whiteout dentry.
33464 + * @h_parent: lower parent dentry which must exist and be locked
33465 + * @base_name: name of dentry which will be whiteouted
33466 + * returns dentry for whiteout.
33468 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33469 + struct au_branch *br)
33472 + struct qstr wh_name;
33473 + struct dentry *wh_dentry;
33475 + err = au_wh_name_alloc(&wh_name, base_name);
33476 + wh_dentry = ERR_PTR(err);
33478 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33479 + kfree(wh_name.name);
33481 + return wh_dentry;
33485 + * link/create a whiteout for @dentry on @bindex.
33487 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33488 + struct dentry *h_parent)
33490 + struct dentry *wh_dentry;
33491 + struct super_block *sb;
33494 + sb = dentry->d_sb;
33495 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33496 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33497 + err = link_or_create_wh(sb, bindex, wh_dentry);
33499 + au_set_dbwh(dentry, bindex);
33500 + au_fhsm_wrote(sb, bindex, /*force*/0);
33503 + wh_dentry = ERR_PTR(err);
33507 + return wh_dentry;
33510 +/* ---------------------------------------------------------------------- */
33512 +/* Delete all whiteouts in this directory on branch bindex. */
33513 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33514 + aufs_bindex_t bindex, struct au_branch *br)
33517 + unsigned long ul, n;
33518 + struct qstr wh_name;
33520 + struct hlist_head *head;
33521 + struct au_vdir_wh *pos;
33522 + struct au_vdir_destr *str;
33525 + p = (void *)__get_free_page(GFP_NOFS);
33526 + wh_name.name = p;
33527 + if (unlikely(!wh_name.name))
33531 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33532 + p += AUFS_WH_PFX_LEN;
33533 + n = whlist->nh_num;
33534 + head = whlist->nh_head;
33535 + for (ul = 0; !err && ul < n; ul++, head++) {
33536 + hlist_for_each_entry(pos, head, wh_hash) {
33537 + if (pos->wh_bindex != bindex)
33540 + str = &pos->wh_str;
33541 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33542 + memcpy(p, str->name, str->len);
33543 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33544 + err = unlink_wh_name(h_dentry, &wh_name, br);
33549 + AuIOErr("whiteout name too long %.*s\n",
33550 + str->len, str->name);
33555 + free_page((unsigned long)wh_name.name);
33561 +struct del_wh_children_args {
33563 + struct dentry *h_dentry;
33564 + struct au_nhash *whlist;
33565 + aufs_bindex_t bindex;
33566 + struct au_branch *br;
33569 +static void call_del_wh_children(void *args)
33571 + struct del_wh_children_args *a = args;
33572 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33575 +/* ---------------------------------------------------------------------- */
33577 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33579 + struct au_whtmp_rmdir *whtmp;
33581 + unsigned int rdhash;
33583 + SiMustAnyLock(sb);
33585 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33586 + if (unlikely(!whtmp)) {
33587 + whtmp = ERR_PTR(-ENOMEM);
33591 + /* no estimation for dir size */
33592 + rdhash = au_sbi(sb)->si_rdhash;
33594 + rdhash = AUFS_RDHASH_DEF;
33595 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33596 + if (unlikely(err)) {
33598 + whtmp = ERR_PTR(err);
33605 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33608 + au_br_put(whtmp->br);
33609 + dput(whtmp->wh_dentry);
33610 + iput(whtmp->dir);
33611 + au_nhash_wh_free(&whtmp->whlist);
33616 + * rmdir the whiteouted temporary named dir @h_dentry.
33617 + * @whlist: whiteouted children.
33619 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33620 + struct dentry *wh_dentry, struct au_nhash *whlist)
33623 + unsigned int h_nlink;
33624 + struct path h_tmp;
33625 + struct inode *wh_inode, *h_dir;
33626 + struct au_branch *br;
33628 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33629 + IMustLock(h_dir);
33631 + br = au_sbr(dir->i_sb, bindex);
33632 + wh_inode = d_inode(wh_dentry);
33633 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33636 + * someone else might change some whiteouts while we were sleeping.
33637 + * it means this whlist may have an obsoleted entry.
33639 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33640 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33643 + struct del_wh_children_args args = {
33645 + .h_dentry = wh_dentry,
33646 + .whlist = whlist,
33647 + .bindex = bindex,
33651 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33652 + if (unlikely(wkq_err))
33655 + inode_unlock(wh_inode);
33658 + h_tmp.dentry = wh_dentry;
33659 + h_tmp.mnt = au_br_mnt(br);
33660 + h_nlink = h_dir->i_nlink;
33661 + err = vfsub_rmdir(h_dir, &h_tmp);
33662 + /* some fs doesn't change the parent nlink in some cases */
33663 + h_nlink -= h_dir->i_nlink;
33667 + if (au_ibtop(dir) == bindex) {
33668 + /* todo: dir->i_mutex is necessary */
33669 + au_cpup_attr_timesizes(dir);
33671 + vfsub_drop_nlink(dir);
33673 + return 0; /* success */
33676 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33680 +static void call_rmdir_whtmp(void *args)
33683 + aufs_bindex_t bindex;
33684 + struct au_whtmp_rmdir *a = args;
33685 + struct super_block *sb;
33686 + struct dentry *h_parent;
33687 + struct inode *h_dir;
33688 + struct au_hinode *hdir;
33690 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33691 + /* inode_lock(a->dir); */
33693 + sb = a->dir->i_sb;
33694 + si_read_lock(sb, !AuLock_FLUSH);
33695 + if (!au_br_writable(a->br->br_perm))
33697 + bindex = au_br_index(sb, a->br->br_id);
33698 + if (unlikely(bindex < 0))
33702 + ii_write_lock_parent(a->dir);
33703 + h_parent = dget_parent(a->wh_dentry);
33704 + h_dir = d_inode(h_parent);
33705 + hdir = au_hi(a->dir, bindex);
33706 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33707 + if (unlikely(err))
33709 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33710 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33713 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33714 + au_hn_inode_unlock(hdir);
33715 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33719 + ii_write_unlock(a->dir);
33721 + /* inode_unlock(a->dir); */
33722 + au_whtmp_rmdir_free(a);
33723 + si_read_unlock(sb);
33724 + au_nwt_done(&au_sbi(sb)->si_nowait);
33725 + if (unlikely(err))
33726 + AuIOErr("err %d\n", err);
33729 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33730 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33733 + struct super_block *sb;
33737 + /* all post-process will be done in do_rmdir_whtmp(). */
33739 + args->dir = au_igrab(dir);
33740 + args->br = au_sbr(sb, bindex);
33741 + au_br_get(args->br);
33742 + args->wh_dentry = dget(wh_dentry);
33743 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33744 + if (unlikely(wkq_err)) {
33745 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33746 + au_whtmp_rmdir_free(args);
33749 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33750 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33751 +++ linux/fs/aufs/whout.h 2017-09-05 10:42:11.058755349 +0200
33754 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33756 + * This program, aufs is free software; you can redistribute it and/or modify
33757 + * it under the terms of the GNU General Public License as published by
33758 + * the Free Software Foundation; either version 2 of the License, or
33759 + * (at your option) any later version.
33761 + * This program is distributed in the hope that it will be useful,
33762 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33763 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33764 + * GNU General Public License for more details.
33766 + * You should have received a copy of the GNU General Public License
33767 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33771 + * whiteout for logical deletion and opaque directory
33774 +#ifndef __AUFS_WHOUT_H__
33775 +#define __AUFS_WHOUT_H__
33782 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33783 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33784 +int au_diropq_test(struct dentry *h_dentry);
33786 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33787 + struct qstr *prefix);
33788 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33789 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33790 + struct dentry *dentry);
33791 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33793 +/* diropq flags */
33794 +#define AuDiropq_CREATE 1
33795 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33796 +#define au_fset_diropq(flags, name) \
33797 + do { (flags) |= AuDiropq_##name; } while (0)
33798 +#define au_fclr_diropq(flags, name) \
33799 + do { (flags) &= ~AuDiropq_##name; } while (0)
33801 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33802 + unsigned int flags);
33803 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33804 + struct au_branch *br);
33805 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33806 + struct dentry *h_parent);
33808 +/* real rmdir for the whiteout-ed dir */
33809 +struct au_whtmp_rmdir {
33810 + struct inode *dir;
33811 + struct au_branch *br;
33812 + struct dentry *wh_dentry;
33813 + struct au_nhash whlist;
33816 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33817 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33818 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33819 + struct dentry *wh_dentry, struct au_nhash *whlist);
33820 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33821 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33823 +/* ---------------------------------------------------------------------- */
33825 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33826 + aufs_bindex_t bindex)
33828 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33831 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33833 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33836 +#endif /* __KERNEL__ */
33837 +#endif /* __AUFS_WHOUT_H__ */
33838 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33839 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33840 +++ linux/fs/aufs/wkq.c 2017-07-29 12:14:25.906375514 +0200
33843 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33845 + * This program, aufs is free software; you can redistribute it and/or modify
33846 + * it under the terms of the GNU General Public License as published by
33847 + * the Free Software Foundation; either version 2 of the License, or
33848 + * (at your option) any later version.
33850 + * This program is distributed in the hope that it will be useful,
33851 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33852 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33853 + * GNU General Public License for more details.
33855 + * You should have received a copy of the GNU General Public License
33856 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33860 + * workqueue for asynchronous/super-io operations
33861 + * todo: try new dredential scheme
33864 +#include <linux/module.h>
33867 +/* internal workqueue named AUFS_WKQ_NAME */
33869 +static struct workqueue_struct *au_wkq;
33871 +struct au_wkinfo {
33872 + struct work_struct wk;
33873 + struct kobject *kobj;
33875 + unsigned int flags; /* see wkq.h */
33877 + au_wkq_func_t func;
33880 + struct completion *comp;
33883 +/* ---------------------------------------------------------------------- */
33885 +static void wkq_func(struct work_struct *wk)
33887 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33889 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33890 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33892 + wkinfo->func(wkinfo->args);
33893 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33894 + complete(wkinfo->comp);
33896 + kobject_put(wkinfo->kobj);
33897 + module_put(THIS_MODULE); /* todo: ?? */
33903 + * Since struct completion is large, try allocating it dynamically.
33905 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33906 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33908 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33910 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33912 + init_completion(*comp);
33913 + wkinfo->comp = *comp;
33919 +static void au_wkq_comp_free(struct completion *comp)
33927 +#define AuWkqCompDeclare(name) \
33928 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33929 + struct completion *comp = &_ ## name
33931 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33933 + wkinfo->comp = *comp;
33937 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33941 +#endif /* 4KSTACKS */
33943 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33945 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33946 + if (au_wkq_test()) {
33947 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33948 + " due to a dead dir by UDBA?\n");
33949 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33952 + au_dbg_verify_kthread();
33954 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33955 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33956 + queue_work(au_wkq, &wkinfo->wk);
33958 + INIT_WORK(&wkinfo->wk, wkq_func);
33959 + schedule_work(&wkinfo->wk);
33964 + * Be careful. It is easy to make deadlock happen.
33965 + * processA: lock, wkq and wait
33966 + * processB: wkq and wait, lock in wkq
33969 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33972 + AuWkqCompDeclare(comp);
33973 + struct au_wkinfo wkinfo = {
33979 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33981 + au_wkq_run(&wkinfo);
33982 + /* no timeout, no interrupt */
33983 + wait_for_completion(wkinfo.comp);
33984 + au_wkq_comp_free(comp);
33985 + destroy_work_on_stack(&wkinfo.wk);
33993 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33994 + * problem in a concurrent umounting.
33996 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33997 + unsigned int flags)
34000 + struct au_wkinfo *wkinfo;
34002 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
34005 + * wkq_func() must free this wkinfo.
34006 + * it highly depends upon the implementation of workqueue.
34009 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
34011 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
34012 + wkinfo->flags = flags & ~AuWkq_WAIT;
34013 + wkinfo->func = func;
34014 + wkinfo->args = args;
34015 + wkinfo->comp = NULL;
34016 + kobject_get(wkinfo->kobj);
34017 + __module_get(THIS_MODULE); /* todo: ?? */
34019 + au_wkq_run(wkinfo);
34022 + au_nwt_done(&au_sbi(sb)->si_nowait);
34028 +/* ---------------------------------------------------------------------- */
34030 +void au_nwt_init(struct au_nowait_tasks *nwt)
34032 + atomic_set(&nwt->nw_len, 0);
34033 + /* smp_mb(); */ /* atomic_set */
34034 + init_waitqueue_head(&nwt->nw_wq);
34037 +void au_wkq_fin(void)
34039 + destroy_workqueue(au_wkq);
34042 +int __init au_wkq_init(void)
34047 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
34048 + if (IS_ERR(au_wkq))
34049 + err = PTR_ERR(au_wkq);
34050 + else if (!au_wkq)
34055 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
34056 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
34057 +++ linux/fs/aufs/wkq.h 2017-07-29 12:14:25.906375514 +0200
34060 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34062 + * This program, aufs is free software; you can redistribute it and/or modify
34063 + * it under the terms of the GNU General Public License as published by
34064 + * the Free Software Foundation; either version 2 of the License, or
34065 + * (at your option) any later version.
34067 + * This program is distributed in the hope that it will be useful,
34068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34070 + * GNU General Public License for more details.
34072 + * You should have received a copy of the GNU General Public License
34073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34077 + * workqueue for asynchronous/super-io operations
34078 + * todo: try new credentials management scheme
34081 +#ifndef __AUFS_WKQ_H__
34082 +#define __AUFS_WKQ_H__
34086 +#include <linux/percpu_counter.h>
34088 +struct super_block;
34090 +/* ---------------------------------------------------------------------- */
34093 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34095 +struct au_nowait_tasks {
34097 + wait_queue_head_t nw_wq;
34100 +/* ---------------------------------------------------------------------- */
34102 +typedef void (*au_wkq_func_t)(void *args);
34105 +#define AuWkq_WAIT 1
34106 +#define AuWkq_NEST (1 << 1)
34107 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34108 +#define au_fset_wkq(flags, name) \
34109 + do { (flags) |= AuWkq_##name; } while (0)
34110 +#define au_fclr_wkq(flags, name) \
34111 + do { (flags) &= ~AuWkq_##name; } while (0)
34113 +#ifndef CONFIG_AUFS_HNOTIFY
34115 +#define AuWkq_NEST 0
34119 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34120 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34121 + unsigned int flags);
34122 +void au_nwt_init(struct au_nowait_tasks *nwt);
34123 +int __init au_wkq_init(void);
34124 +void au_wkq_fin(void);
34126 +/* ---------------------------------------------------------------------- */
34128 +static inline int au_wkq_test(void)
34130 + return current->flags & PF_WQ_WORKER;
34133 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34135 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34138 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34140 + if (atomic_dec_and_test(&nwt->nw_len))
34141 + wake_up_all(&nwt->nw_wq);
34144 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34146 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34150 +#endif /* __KERNEL__ */
34151 +#endif /* __AUFS_WKQ_H__ */
34152 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34153 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34154 +++ linux/fs/aufs/xattr.c 2017-09-05 10:42:11.058755349 +0200
34157 + * Copyright (C) 2014-2017 Junjiro R. Okajima
34159 + * This program, aufs is free software; you can redistribute it and/or modify
34160 + * it under the terms of the GNU General Public License as published by
34161 + * the Free Software Foundation; either version 2 of the License, or
34162 + * (at your option) any later version.
34164 + * This program is distributed in the hope that it will be useful,
34165 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34166 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34167 + * GNU General Public License for more details.
34169 + * You should have received a copy of the GNU General Public License
34170 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34174 + * handling xattr functions
34177 +#include <linux/fs.h>
34178 +#include <linux/posix_acl_xattr.h>
34179 +#include <linux/xattr.h>
34182 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34184 + if (!ignore_flags)
34192 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34197 +#define cmp(brattr, prefix) do { \
34198 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34199 + XATTR_##prefix##_PREFIX_LEN)) { \
34200 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34206 + cmp(SEC, SECURITY);
34207 + cmp(SYS, SYSTEM);
34208 + cmp(TR, TRUSTED);
34212 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34219 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34221 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34222 + char *name, char **buf, unsigned int ignore_flags,
34223 + unsigned int verbose)
34227 + struct inode *h_idst;
34229 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34231 + if (unlikely(err <= 0)) {
34232 + if (err == -ENODATA
34233 + || (err == -EOPNOTSUPP
34234 + && ((ignore_flags & au_xattr_out_of_list)
34235 + || (au_test_nfs_noacl(d_inode(h_src))
34236 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34238 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34241 + if (err && (verbose || au_debug_test()))
34242 + pr_err("%s, err %d\n", name, err);
34246 + /* unlock it temporary */
34247 + h_idst = d_inode(h_dst);
34248 + inode_unlock(h_idst);
34249 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34250 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34251 + if (unlikely(err)) {
34252 + if (verbose || au_debug_test())
34253 + pr_err("%s, err %d\n", name, err);
34254 + err = au_xattr_ignore(err, name, ignore_flags);
34261 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34262 + unsigned int verbose)
34264 + int err, unlocked, acl_access, acl_default;
34266 + struct inode *h_isrc, *h_idst;
34267 + char *value, *p, *o, *e;
34269 + /* try stopping to update the source inode while we are referencing */
34270 + /* there should not be the parent-child relationship between them */
34271 + h_isrc = d_inode(h_src);
34272 + h_idst = d_inode(h_dst);
34273 + inode_unlock(h_idst);
34274 + vfsub_inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
34275 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34278 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34279 + ssz = vfs_listxattr(h_src, NULL, 0);
34281 + if (unlikely(err < 0)) {
34283 + if (err == -ENODATA
34284 + || err == -EOPNOTSUPP)
34285 + err = 0; /* ignore */
34294 + p = kmalloc(ssz, GFP_NOFS);
34296 + if (unlikely(!p))
34298 + err = vfs_listxattr(h_src, p, ssz);
34300 + inode_unlock_shared(h_isrc);
34302 + AuDbg("err %d, ssz %zd\n", err, ssz);
34303 + if (unlikely(err < 0))
34311 + while (!err && p < e) {
34312 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34313 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34314 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34315 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34317 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34319 + p += strlen(p) + 1;
34322 + ignore_flags |= au_xattr_out_of_list;
34323 + if (!err && !acl_access) {
34324 + err = au_do_cpup_xattr(h_dst, h_src,
34325 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34326 + ignore_flags, verbose);
34329 + if (!err && !acl_default) {
34330 + err = au_do_cpup_xattr(h_dst, h_src,
34331 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34332 + ignore_flags, verbose);
34344 + inode_unlock_shared(h_isrc);
34349 +/* ---------------------------------------------------------------------- */
34351 +static int au_smack_reentering(struct super_block *sb)
34353 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
34355 + * as a part of lookup, smack_d_instantiate() is called, and it calls
34356 + * i_op->getxattr(). ouch.
34358 + return si_pid_test(sb);
34369 +struct au_lgxattr {
34377 + const char *name;
34384 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34388 + struct path h_path;
34389 + struct super_block *sb;
34391 + sb = dentry->d_sb;
34392 + reenter = au_smack_reentering(sb);
34394 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34395 + if (unlikely(err))
34398 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
34399 + if (unlikely(err))
34401 + if (unlikely(!h_path.dentry))
34402 + /* illegally overlapped or something */
34403 + goto out_di; /* pretending success */
34405 + /* always topmost entry only */
34406 + switch (arg->type) {
34407 + case AU_XATTR_LIST:
34408 + err = vfs_listxattr(h_path.dentry,
34409 + arg->u.list.list, arg->u.list.size);
34411 + case AU_XATTR_GET:
34412 + AuDebugOn(d_is_negative(h_path.dentry));
34413 + err = vfs_getxattr(h_path.dentry,
34414 + arg->u.get.name, arg->u.get.value,
34415 + arg->u.get.size);
34421 + di_read_unlock(dentry, AuLock_IR);
34424 + si_read_unlock(sb);
34430 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34432 + struct au_lgxattr arg = {
34433 + .type = AU_XATTR_LIST,
34440 + return au_lgxattr(dentry, &arg);
34443 +static ssize_t au_getxattr(struct dentry *dentry,
34444 + struct inode *inode __maybe_unused,
34445 + const char *name, void *value, size_t size)
34447 + struct au_lgxattr arg = {
34448 + .type = AU_XATTR_GET,
34456 + return au_lgxattr(dentry, &arg);
34459 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34460 + const char *name, const void *value, size_t size,
34463 + struct au_sxattr arg = {
34464 + .type = AU_XATTR_SET,
34473 + return au_sxattr(dentry, inode, &arg);
34476 +/* ---------------------------------------------------------------------- */
34478 +static int au_xattr_get(const struct xattr_handler *handler,
34479 + struct dentry *dentry, struct inode *inode,
34480 + const char *name, void *buffer, size_t size)
34482 + return au_getxattr(dentry, inode, name, buffer, size);
34485 +static int au_xattr_set(const struct xattr_handler *handler,
34486 + struct dentry *dentry, struct inode *inode,
34487 + const char *name, const void *value, size_t size,
34490 + return au_setxattr(dentry, inode, name, value, size, flags);
34493 +static const struct xattr_handler au_xattr_handler = {
34496 + .get = au_xattr_get,
34497 + .set = au_xattr_set
34500 +static const struct xattr_handler *au_xattr_handlers[] = {
34501 +#ifdef CONFIG_FS_POSIX_ACL
34502 + &posix_acl_access_xattr_handler,
34503 + &posix_acl_default_xattr_handler,
34505 + &au_xattr_handler, /* must be last */
34509 +void au_xattr_init(struct super_block *sb)
34511 + sb->s_xattr = au_xattr_handlers;
34513 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34514 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34515 +++ linux/fs/aufs/xino.c 2017-07-29 12:14:25.906375514 +0200
34518 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34520 + * This program, aufs is free software; you can redistribute it and/or modify
34521 + * it under the terms of the GNU General Public License as published by
34522 + * the Free Software Foundation; either version 2 of the License, or
34523 + * (at your option) any later version.
34525 + * This program is distributed in the hope that it will be useful,
34526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34528 + * GNU General Public License for more details.
34530 + * You should have received a copy of the GNU General Public License
34531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34535 + * external inode number translation table and bitmap
34538 +#include <linux/seq_file.h>
34539 +#include <linux/statfs.h>
34542 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34543 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34547 + mm_segment_t oldfs;
34554 + oldfs = get_fs();
34555 + set_fs(KERNEL_DS);
34557 + /* todo: signal_pending? */
34558 + err = func(file, buf.u, size, pos);
34559 + } while (err == -EAGAIN || err == -EINTR);
34562 +#if 0 /* reserved for future use */
34564 + fsnotify_access(file->f_path.dentry);
34570 +/* ---------------------------------------------------------------------- */
34572 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34573 + size_t size, loff_t *pos);
34575 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34576 + size_t size, loff_t *pos)
34579 + mm_segment_t oldfs;
34582 + const char __user *u;
34585 + const int prevent_endless = 10;
34589 + oldfs = get_fs();
34590 + set_fs(KERNEL_DS);
34592 + err = func(file, buf.u, size, pos);
34593 + if (err == -EINTR
34594 + && !au_wkq_test()
34595 + && fatal_signal_pending(current)) {
34597 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34598 + BUG_ON(err == -EINTR);
34599 + oldfs = get_fs();
34600 + set_fs(KERNEL_DS);
34602 + } while (i++ < prevent_endless
34603 + && (err == -EAGAIN || err == -EINTR));
34606 +#if 0 /* reserved for future use */
34608 + fsnotify_modify(file->f_path.dentry);
34614 +struct do_xino_fwrite_args {
34616 + vfs_writef_t func;
34617 + struct file *file;
34623 +static void call_do_xino_fwrite(void *args)
34625 + struct do_xino_fwrite_args *a = args;
34626 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34629 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34630 + size_t size, loff_t *pos)
34634 + struct do_xino_fwrite_args args = {
34644 + * it breaks RLIMIT_FSIZE and normal user's limit,
34645 + * users should care about quota and real 'filesystem full.'
34647 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34648 + if (unlikely(wkq_err))
34654 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34655 + size_t size, loff_t *pos)
34659 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34661 + err = do_xino_fwrite(func, file, buf, size, pos);
34664 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34669 +/* ---------------------------------------------------------------------- */
34672 + * create a new xinofile at the same place/path as @base_file.
34674 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34676 + struct file *file;
34677 + struct dentry *base, *parent;
34678 + struct inode *dir, *delegated;
34679 + struct qstr *name;
34680 + struct path path;
34683 + base = base_file->f_path.dentry;
34684 + parent = base->d_parent; /* dir inode is locked */
34685 + dir = d_inode(parent);
34688 + file = ERR_PTR(-EINVAL);
34689 + name = &base->d_name;
34690 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34691 + if (IS_ERR(path.dentry)) {
34692 + file = (void *)path.dentry;
34693 + pr_err("%pd lookup err %ld\n",
34694 + base, PTR_ERR(path.dentry));
34698 + /* no need to mnt_want_write() since we call dentry_open() later */
34699 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34700 + if (unlikely(err)) {
34701 + file = ERR_PTR(err);
34702 + pr_err("%pd create err %d\n", base, err);
34706 + path.mnt = base_file->f_path.mnt;
34707 + file = vfsub_dentry_open(&path,
34708 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34709 + /* | __FMODE_NONOTIFY */);
34710 + if (IS_ERR(file)) {
34711 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34715 + delegated = NULL;
34716 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34717 + if (unlikely(err == -EWOULDBLOCK)) {
34718 + pr_warn("cannot retry for NFSv4 delegation"
34719 + " for an internal unlink\n");
34722 + if (unlikely(err)) {
34723 + pr_err("%pd unlink err %d\n", base, err);
34728 + /* no one can touch copy_src xino */
34729 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34730 + if (unlikely(err)) {
34731 + pr_err("%pd copy err %d\n", base, err);
34735 + goto out_dput; /* success */
34739 + file = ERR_PTR(err);
34741 + dput(path.dentry);
34746 +struct au_xino_lock_dir {
34747 + struct au_hinode *hdir;
34748 + struct dentry *parent;
34749 + struct inode *dir;
34752 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34753 + struct au_xino_lock_dir *ldir)
34755 + aufs_bindex_t brid, bindex;
34757 + ldir->hdir = NULL;
34759 + brid = au_xino_brid(sb);
34761 + bindex = au_br_index(sb, brid);
34762 + if (bindex >= 0) {
34763 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34764 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34766 + ldir->parent = dget_parent(xino->f_path.dentry);
34767 + ldir->dir = d_inode(ldir->parent);
34768 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34772 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34775 + au_hn_inode_unlock(ldir->hdir);
34777 + inode_unlock(ldir->dir);
34778 + dput(ldir->parent);
34782 +/* ---------------------------------------------------------------------- */
34784 +/* trucate xino files asynchronously */
34786 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34789 + unsigned long jiffy;
34791 + aufs_bindex_t bi, bbot;
34792 + struct kstatfs *st;
34793 + struct au_branch *br;
34794 + struct file *new_xino, *file;
34795 + struct super_block *h_sb;
34796 + struct au_xino_lock_dir ldir;
34799 + st = kmalloc(sizeof(*st), GFP_NOFS);
34800 + if (unlikely(!st))
34804 + bbot = au_sbbot(sb);
34805 + if (unlikely(bindex < 0 || bbot < bindex))
34807 + br = au_sbr(sb, bindex);
34808 + file = br->br_xino.xi_file;
34812 + err = vfs_statfs(&file->f_path, st);
34813 + if (unlikely(err))
34814 + AuErr1("statfs err %d, ignored\n", err);
34816 + blocks = file_inode(file)->i_blocks;
34817 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34818 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34820 + au_xino_lock_dir(sb, file, &ldir);
34821 + /* mnt_want_write() is unnecessary here */
34822 + new_xino = au_xino_create2(file, file);
34823 + au_xino_unlock_dir(&ldir);
34824 + err = PTR_ERR(new_xino);
34825 + if (IS_ERR(new_xino)) {
34826 + pr_err("err %d, ignored\n", err);
34831 + br->br_xino.xi_file = new_xino;
34833 + h_sb = au_br_sb(br);
34834 + for (bi = 0; bi <= bbot; bi++) {
34835 + if (unlikely(bi == bindex))
34837 + br = au_sbr(sb, bi);
34838 + if (au_br_sb(br) != h_sb)
34841 + fput(br->br_xino.xi_file);
34842 + br->br_xino.xi_file = new_xino;
34843 + get_file(new_xino);
34846 + err = vfs_statfs(&new_xino->f_path, st);
34848 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34849 + bindex, (u64)file_inode(new_xino)->i_blocks,
34850 + st->f_bfree, st->f_blocks);
34851 + if (file_inode(new_xino)->i_blocks < blocks)
34852 + au_sbi(sb)->si_xino_jiffy = jiffy;
34854 + AuErr1("statfs err %d, ignored\n", err);
34862 +struct xino_do_trunc_args {
34863 + struct super_block *sb;
34864 + struct au_branch *br;
34867 +static void xino_do_trunc(void *_args)
34869 + struct xino_do_trunc_args *args = _args;
34870 + struct super_block *sb;
34871 + struct au_branch *br;
34872 + struct inode *dir;
34874 + aufs_bindex_t bindex;
34878 + dir = d_inode(sb->s_root);
34881 + si_noflush_write_lock(sb);
34882 + ii_read_lock_parent(dir);
34883 + bindex = au_br_index(sb, br->br_id);
34884 + err = au_xino_trunc(sb, bindex);
34885 + ii_read_unlock(dir);
34886 + if (unlikely(err))
34887 + pr_warn("err b%d, (%d)\n", bindex, err);
34888 + atomic_dec(&br->br_xino_running);
34890 + si_write_unlock(sb);
34891 + au_nwt_done(&au_sbi(sb)->si_nowait);
34895 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34898 + struct kstatfs st;
34899 + struct au_sbinfo *sbinfo;
34901 + /* todo: si_xino_expire and the ratio should be customizable */
34902 + sbinfo = au_sbi(sb);
34903 + if (time_before(jiffies,
34904 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34907 + /* truncation border */
34908 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34909 + if (unlikely(err)) {
34910 + AuErr1("statfs err %d, ignored\n", err);
34913 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34919 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34921 + struct xino_do_trunc_args *args;
34924 + if (!xino_trunc_test(sb, br))
34927 + if (atomic_inc_return(&br->br_xino_running) > 1)
34930 + /* lock and kfree() will be called in trunc_xino() */
34931 + args = kmalloc(sizeof(*args), GFP_NOFS);
34932 + if (unlikely(!args)) {
34933 + AuErr1("no memory\n");
34940 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34942 + return; /* success */
34944 + pr_err("wkq %d\n", wkq_err);
34949 + atomic_dec(&br->br_xino_running);
34952 +/* ---------------------------------------------------------------------- */
34954 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34955 + ino_t h_ino, ino_t ino)
34961 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34962 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34965 + pos *= sizeof(ino);
34966 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34967 + if (sz == sizeof(ino))
34968 + return 0; /* success */
34970 + AuIOErr("write failed (%zd)\n", sz);
34975 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34976 + * at the position of @h_ino.
34977 + * even if @ino is zero, it is written to the xinofile and means no entry.
34978 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34979 + * try truncating it.
34981 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34985 + unsigned int mnt_flags;
34986 + struct au_branch *br;
34988 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34989 + || ((loff_t)-1) > 0);
34990 + SiMustAnyLock(sb);
34992 + mnt_flags = au_mntflags(sb);
34993 + if (!au_opt_test(mnt_flags, XINO))
34996 + br = au_sbr(sb, bindex);
34997 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35000 + if (au_opt_test(mnt_flags, TRUNC_XINO)
35001 + && au_test_fs_trunc_xino(au_br_sb(br)))
35002 + xino_try_trunc(sb, br);
35003 + return 0; /* success */
35006 + AuIOErr("write failed (%d)\n", err);
35010 +/* ---------------------------------------------------------------------- */
35012 +/* aufs inode number bitmap */
35014 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
35015 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
35019 + AuDebugOn(bit < 0 || page_bits <= bit);
35020 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
35024 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
35026 + AuDebugOn(ino < AUFS_FIRST_INO);
35027 + ino -= AUFS_FIRST_INO;
35028 + *pindex = ino / page_bits;
35029 + *bit = ino % page_bits;
35032 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
35037 + struct au_sbinfo *sbinfo;
35038 + struct file *xib;
35039 + unsigned long *p;
35041 + sbinfo = au_sbi(sb);
35042 + MtxMustLock(&sbinfo->si_xib_mtx);
35043 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
35044 + || !au_opt_test(sbinfo->si_mntflags, XINO));
35046 + if (pindex == sbinfo->si_xib_last_pindex)
35049 + xib = sbinfo->si_xib;
35050 + p = sbinfo->si_xib_buf;
35051 + pos = sbinfo->si_xib_last_pindex;
35052 + pos *= PAGE_SIZE;
35053 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35054 + if (unlikely(sz != PAGE_SIZE))
35058 + pos *= PAGE_SIZE;
35059 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
35060 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
35062 + memset(p, 0, PAGE_SIZE);
35063 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35065 + if (sz == PAGE_SIZE) {
35066 + sbinfo->si_xib_last_pindex = pindex;
35067 + return 0; /* success */
35071 + AuIOErr1("write failed (%zd)\n", sz);
35078 +/* ---------------------------------------------------------------------- */
35080 +static void au_xib_clear_bit(struct inode *inode)
35083 + unsigned long pindex;
35084 + struct super_block *sb;
35085 + struct au_sbinfo *sbinfo;
35087 + AuDebugOn(inode->i_nlink);
35089 + sb = inode->i_sb;
35090 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35091 + AuDebugOn(page_bits <= bit);
35092 + sbinfo = au_sbi(sb);
35093 + mutex_lock(&sbinfo->si_xib_mtx);
35094 + err = xib_pindex(sb, pindex);
35096 + clear_bit(bit, sbinfo->si_xib_buf);
35097 + sbinfo->si_xib_next_bit = bit;
35099 + mutex_unlock(&sbinfo->si_xib_mtx);
35102 +/* for s_op->delete_inode() */
35103 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35106 + unsigned int mnt_flags;
35107 + aufs_bindex_t bindex, bbot, bi;
35108 + unsigned char try_trunc;
35109 + struct au_iinfo *iinfo;
35110 + struct super_block *sb;
35111 + struct au_hinode *hi;
35112 + struct inode *h_inode;
35113 + struct au_branch *br;
35114 + vfs_writef_t xwrite;
35116 + AuDebugOn(au_is_bad_inode(inode));
35118 + sb = inode->i_sb;
35119 + mnt_flags = au_mntflags(sb);
35120 + if (!au_opt_test(mnt_flags, XINO)
35121 + || inode->i_ino == AUFS_ROOT_INO)
35125 + au_xigen_inc(inode);
35126 + au_xib_clear_bit(inode);
35129 + iinfo = au_ii(inode);
35130 + bindex = iinfo->ii_btop;
35134 + xwrite = au_sbi(sb)->si_xwrite;
35135 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35136 + hi = au_hinode(iinfo, bindex);
35137 + bbot = iinfo->ii_bbot;
35138 + for (; bindex <= bbot; bindex++, hi++) {
35139 + h_inode = hi->hi_inode;
35141 + || (!unlinked && h_inode->i_nlink))
35144 + /* inode may not be revalidated */
35145 + bi = au_br_index(sb, hi->hi_id);
35149 + br = au_sbr(sb, bi);
35150 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35151 + h_inode->i_ino, /*ino*/0);
35152 + if (!err && try_trunc
35153 + && au_test_fs_trunc_xino(au_br_sb(br)))
35154 + xino_try_trunc(sb, br);
35158 +/* get an unused inode number from bitmap */
35159 +ino_t au_xino_new_ino(struct super_block *sb)
35162 + unsigned long *p, pindex, ul, pend;
35163 + struct au_sbinfo *sbinfo;
35164 + struct file *file;
35165 + int free_bit, err;
35167 + if (!au_opt_test(au_mntflags(sb), XINO))
35168 + return iunique(sb, AUFS_FIRST_INO);
35170 + sbinfo = au_sbi(sb);
35171 + mutex_lock(&sbinfo->si_xib_mtx);
35172 + p = sbinfo->si_xib_buf;
35173 + free_bit = sbinfo->si_xib_next_bit;
35174 + if (free_bit < page_bits && !test_bit(free_bit, p))
35175 + goto out; /* success */
35176 + free_bit = find_first_zero_bit(p, page_bits);
35177 + if (free_bit < page_bits)
35178 + goto out; /* success */
35180 + pindex = sbinfo->si_xib_last_pindex;
35181 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35182 + err = xib_pindex(sb, ul);
35183 + if (unlikely(err))
35185 + free_bit = find_first_zero_bit(p, page_bits);
35186 + if (free_bit < page_bits)
35187 + goto out; /* success */
35190 + file = sbinfo->si_xib;
35191 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35192 + for (ul = pindex + 1; ul <= pend; ul++) {
35193 + err = xib_pindex(sb, ul);
35194 + if (unlikely(err))
35196 + free_bit = find_first_zero_bit(p, page_bits);
35197 + if (free_bit < page_bits)
35198 + goto out; /* success */
35203 + set_bit(free_bit, p);
35204 + sbinfo->si_xib_next_bit = free_bit + 1;
35205 + pindex = sbinfo->si_xib_last_pindex;
35206 + mutex_unlock(&sbinfo->si_xib_mtx);
35207 + ino = xib_calc_ino(pindex, free_bit);
35208 + AuDbg("i%lu\n", (unsigned long)ino);
35211 + mutex_unlock(&sbinfo->si_xib_mtx);
35217 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35218 + * at the position of @h_ino.
35219 + * if @ino does not exist and @do_new is true, get new one.
35221 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35227 + struct file *file;
35228 + struct au_sbinfo *sbinfo;
35231 + if (!au_opt_test(au_mntflags(sb), XINO))
35232 + return 0; /* no xino */
35235 + sbinfo = au_sbi(sb);
35237 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35238 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35241 + pos *= sizeof(*ino);
35243 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35244 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35245 + return 0; /* no ino */
35247 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35248 + if (sz == sizeof(*ino))
35249 + return 0; /* success */
35252 + if (unlikely(sz >= 0)) {
35254 + AuIOErr("xino read error (%zd)\n", sz);
35260 +/* ---------------------------------------------------------------------- */
35262 +/* create and set a new xino file */
35264 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35266 + struct file *file;
35267 + struct dentry *h_parent, *d;
35268 + struct inode *h_dir, *inode;
35272 + * at mount-time, and the xino file is the default path,
35273 + * hnotify is disabled so we have no notify events to ignore.
35274 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35276 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35277 + /* | __FMODE_NONOTIFY */,
35278 + S_IRUGO | S_IWUGO);
35279 + if (IS_ERR(file)) {
35281 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35285 + /* keep file count */
35287 + inode = file_inode(file);
35288 + h_parent = dget_parent(file->f_path.dentry);
35289 + h_dir = d_inode(h_parent);
35290 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35291 + /* mnt_want_write() is unnecessary here */
35292 + /* no delegation since it is just created */
35293 + if (inode->i_nlink)
35294 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35296 + inode_unlock(h_dir);
35298 + if (unlikely(err)) {
35300 + pr_err("unlink %s(%d)\n", fname, err);
35305 + d = file->f_path.dentry;
35306 + if (unlikely(sb == d->d_sb)) {
35308 + pr_err("%s must be outside\n", fname);
35311 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35313 + pr_err("xino doesn't support %s(%s)\n",
35314 + fname, au_sbtype(d->d_sb));
35317 + return file; /* success */
35321 + file = ERR_PTR(err);
35326 + * find another branch who is on the same filesystem of the specified
35327 + * branch{@btgt}. search until @bbot.
35329 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35330 + aufs_bindex_t bbot)
35332 + aufs_bindex_t bindex;
35333 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35335 + for (bindex = 0; bindex < btgt; bindex++)
35336 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35338 + for (bindex++; bindex <= bbot; bindex++)
35339 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35344 +/* ---------------------------------------------------------------------- */
35347 + * initialize the xinofile for the specified branch @br
35348 + * at the place/path where @base_file indicates.
35349 + * test whether another branch is on the same filesystem or not,
35350 + * if @do_test is true.
35352 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35353 + struct file *base_file, int do_test)
35357 + aufs_bindex_t bbot, bindex;
35358 + struct au_branch *shared_br, *b;
35359 + struct file *file;
35360 + struct super_block *tgt_sb;
35362 + shared_br = NULL;
35363 + bbot = au_sbbot(sb);
35365 + tgt_sb = au_br_sb(br);
35366 + for (bindex = 0; bindex <= bbot; bindex++) {
35367 + b = au_sbr(sb, bindex);
35368 + if (tgt_sb == au_br_sb(b)) {
35375 + if (!shared_br || !shared_br->br_xino.xi_file) {
35376 + struct au_xino_lock_dir ldir;
35378 + au_xino_lock_dir(sb, base_file, &ldir);
35379 + /* mnt_want_write() is unnecessary here */
35380 + file = au_xino_create2(base_file, NULL);
35381 + au_xino_unlock_dir(&ldir);
35382 + err = PTR_ERR(file);
35383 + if (IS_ERR(file))
35385 + br->br_xino.xi_file = file;
35387 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35388 + get_file(br->br_xino.xi_file);
35391 + ino = AUFS_ROOT_INO;
35392 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35394 + if (unlikely(err)) {
35395 + fput(br->br_xino.xi_file);
35396 + br->br_xino.xi_file = NULL;
35403 +/* ---------------------------------------------------------------------- */
35405 +/* trucate a xino bitmap file */
35408 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35412 + unsigned long pindex;
35413 + loff_t pos, pend;
35414 + struct au_sbinfo *sbinfo;
35415 + vfs_readf_t func;
35417 + unsigned long *p;
35420 + sbinfo = au_sbi(sb);
35421 + MtxMustLock(&sbinfo->si_xib_mtx);
35422 + p = sbinfo->si_xib_buf;
35423 + func = sbinfo->si_xread;
35424 + pend = vfsub_f_size_read(file);
35426 + while (pos < pend) {
35427 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35429 + if (unlikely(sz <= 0))
35433 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35434 + if (unlikely(*ino < AUFS_FIRST_INO))
35437 + xib_calc_bit(*ino, &pindex, &bit);
35438 + AuDebugOn(page_bits <= bit);
35439 + err = xib_pindex(sb, pindex);
35451 +static int xib_restore(struct super_block *sb)
35454 + aufs_bindex_t bindex, bbot;
35458 + page = (void *)__get_free_page(GFP_NOFS);
35459 + if (unlikely(!page))
35463 + bbot = au_sbbot(sb);
35464 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35465 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35466 + err = do_xib_restore
35467 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35469 + AuDbg("b%d\n", bindex);
35470 + free_page((unsigned long)page);
35476 +int au_xib_trunc(struct super_block *sb)
35481 + struct au_xino_lock_dir ldir;
35482 + struct au_sbinfo *sbinfo;
35483 + unsigned long *p;
35484 + struct file *file;
35486 + SiMustWriteLock(sb);
35489 + sbinfo = au_sbi(sb);
35490 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35493 + file = sbinfo->si_xib;
35494 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35497 + au_xino_lock_dir(sb, file, &ldir);
35498 + /* mnt_want_write() is unnecessary here */
35499 + file = au_xino_create2(sbinfo->si_xib, NULL);
35500 + au_xino_unlock_dir(&ldir);
35501 + err = PTR_ERR(file);
35502 + if (IS_ERR(file))
35504 + fput(sbinfo->si_xib);
35505 + sbinfo->si_xib = file;
35507 + p = sbinfo->si_xib_buf;
35508 + memset(p, 0, PAGE_SIZE);
35510 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35511 + if (unlikely(sz != PAGE_SIZE)) {
35513 + AuIOErr("err %d\n", err);
35519 + mutex_lock(&sbinfo->si_xib_mtx);
35520 + /* mnt_want_write() is unnecessary here */
35521 + err = xib_restore(sb);
35522 + mutex_unlock(&sbinfo->si_xib_mtx);
35528 +/* ---------------------------------------------------------------------- */
35531 + * xino mount option handlers
35535 +static void xino_clear_xib(struct super_block *sb)
35537 + struct au_sbinfo *sbinfo;
35539 + SiMustWriteLock(sb);
35541 + sbinfo = au_sbi(sb);
35542 + sbinfo->si_xread = NULL;
35543 + sbinfo->si_xwrite = NULL;
35544 + if (sbinfo->si_xib)
35545 + fput(sbinfo->si_xib);
35546 + sbinfo->si_xib = NULL;
35547 + if (sbinfo->si_xib_buf)
35548 + free_page((unsigned long)sbinfo->si_xib_buf);
35549 + sbinfo->si_xib_buf = NULL;
35552 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35556 + struct au_sbinfo *sbinfo;
35557 + struct file *file;
35559 + SiMustWriteLock(sb);
35561 + sbinfo = au_sbi(sb);
35562 + file = au_xino_create2(base, sbinfo->si_xib);
35563 + err = PTR_ERR(file);
35564 + if (IS_ERR(file))
35566 + if (sbinfo->si_xib)
35567 + fput(sbinfo->si_xib);
35568 + sbinfo->si_xib = file;
35569 + sbinfo->si_xread = vfs_readf(file);
35570 + sbinfo->si_xwrite = vfs_writef(file);
35573 + if (!sbinfo->si_xib_buf)
35574 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35575 + if (unlikely(!sbinfo->si_xib_buf))
35578 + sbinfo->si_xib_last_pindex = 0;
35579 + sbinfo->si_xib_next_bit = 0;
35580 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35582 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35583 + PAGE_SIZE, &pos);
35584 + if (unlikely(err != PAGE_SIZE))
35588 + goto out; /* success */
35591 + if (sbinfo->si_xib_buf)
35592 + free_page((unsigned long)sbinfo->si_xib_buf);
35593 + sbinfo->si_xib_buf = NULL;
35597 + fput(sbinfo->si_xib);
35598 + sbinfo->si_xib = NULL;
35599 + sbinfo->si_xread = NULL;
35600 + sbinfo->si_xwrite = NULL;
35605 +/* xino for each branch */
35606 +static void xino_clear_br(struct super_block *sb)
35608 + aufs_bindex_t bindex, bbot;
35609 + struct au_branch *br;
35611 + bbot = au_sbbot(sb);
35612 + for (bindex = 0; bindex <= bbot; bindex++) {
35613 + br = au_sbr(sb, bindex);
35614 + if (!br || !br->br_xino.xi_file)
35617 + fput(br->br_xino.xi_file);
35618 + br->br_xino.xi_file = NULL;
35622 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35626 + aufs_bindex_t bindex, bbot, bshared;
35628 + struct file *old, *new;
35630 + struct au_branch *br;
35631 + struct inode *inode;
35632 + vfs_writef_t writef;
35634 + SiMustWriteLock(sb);
35637 + bbot = au_sbbot(sb);
35638 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35639 + if (unlikely(!fpair))
35642 + inode = d_inode(sb->s_root);
35643 + ino = AUFS_ROOT_INO;
35644 + writef = au_sbi(sb)->si_xwrite;
35645 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35646 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35647 + if (bshared >= 0) {
35648 + /* shared xino */
35649 + *p = fpair[bshared];
35650 + get_file(p->new);
35655 + br = au_sbr(sb, bindex);
35656 + p->old = br->br_xino.xi_file;
35657 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35658 + err = PTR_ERR(p->new);
35659 + if (IS_ERR(p->new)) {
35665 + err = au_xino_do_write(writef, p->new,
35666 + au_h_iptr(inode, bindex)->i_ino, ino);
35667 + if (unlikely(err))
35671 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35672 + br = au_sbr(sb, bindex);
35673 + if (br->br_xino.xi_file)
35674 + fput(br->br_xino.xi_file);
35675 + get_file(p->new);
35676 + br->br_xino.xi_file = p->new;
35680 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35690 +void au_xino_clr(struct super_block *sb)
35692 + struct au_sbinfo *sbinfo;
35694 + au_xigen_clr(sb);
35695 + xino_clear_xib(sb);
35696 + xino_clear_br(sb);
35697 + sbinfo = au_sbi(sb);
35698 + /* lvalue, do not call au_mntflags() */
35699 + au_opt_clr(sbinfo->si_mntflags, XINO);
35702 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35705 + struct dentry *parent, *cur_parent;
35706 + struct qstr *dname, *cur_name;
35707 + struct file *cur_xino;
35708 + struct inode *dir;
35709 + struct au_sbinfo *sbinfo;
35711 + SiMustWriteLock(sb);
35714 + sbinfo = au_sbi(sb);
35715 + parent = dget_parent(xino->file->f_path.dentry);
35718 + dname = &xino->file->f_path.dentry->d_name;
35719 + cur_xino = sbinfo->si_xib;
35721 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35722 + cur_name = &cur_xino->f_path.dentry->d_name;
35723 + skip = (cur_parent == parent
35724 + && au_qstreq(dname, cur_name));
35725 + dput(cur_parent);
35731 + au_opt_set(sbinfo->si_mntflags, XINO);
35732 + dir = d_inode(parent);
35733 + inode_lock_nested(dir, AuLsc_I_PARENT);
35734 + /* mnt_want_write() is unnecessary here */
35735 + err = au_xino_set_xib(sb, xino->file);
35737 + err = au_xigen_set(sb, xino->file);
35739 + err = au_xino_set_br(sb, xino->file);
35740 + inode_unlock(dir);
35742 + goto out; /* success */
35745 + AuIOErr("failed creating xino(%d).\n", err);
35746 + au_xigen_clr(sb);
35747 + xino_clear_xib(sb);
35754 +/* ---------------------------------------------------------------------- */
35757 + * create a xinofile at the default place/path.
35759 +struct file *au_xino_def(struct super_block *sb)
35761 + struct file *file;
35763 + struct au_branch *br;
35764 + struct super_block *h_sb;
35765 + struct path path;
35766 + aufs_bindex_t bbot, bindex, bwr;
35769 + bbot = au_sbbot(sb);
35771 + for (bindex = 0; bindex <= bbot; bindex++) {
35772 + br = au_sbr(sb, bindex);
35773 + if (au_br_writable(br->br_perm)
35774 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35781 + file = ERR_PTR(-ENOMEM);
35782 + page = (void *)__get_free_page(GFP_NOFS);
35783 + if (unlikely(!page))
35785 + path.mnt = au_br_mnt(br);
35786 + path.dentry = au_h_dptr(sb->s_root, bwr);
35787 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35788 + file = (void *)p;
35789 + if (!IS_ERR(p)) {
35790 + strcat(p, "/" AUFS_XINO_FNAME);
35791 + AuDbg("%s\n", p);
35792 + file = au_xino_create(sb, p, /*silent*/0);
35793 + if (!IS_ERR(file))
35794 + au_xino_brid_set(sb, br->br_id);
35796 + free_page((unsigned long)page);
35798 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35799 + if (IS_ERR(file))
35801 + h_sb = file->f_path.dentry->d_sb;
35802 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35803 + pr_err("xino doesn't support %s(%s)\n",
35804 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35806 + file = ERR_PTR(-EINVAL);
35808 + if (!IS_ERR(file))
35809 + au_xino_brid_set(sb, -1);
35816 +/* ---------------------------------------------------------------------- */
35818 +int au_xino_path(struct seq_file *seq, struct file *file)
35822 + err = au_seq_path(seq, &file->f_path);
35823 + if (unlikely(err))
35826 +#define Deleted "\\040(deleted)"
35827 + seq->count -= sizeof(Deleted) - 1;
35828 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35829 + sizeof(Deleted) - 1));
35836 +/* ---------------------------------------------------------------------- */
35838 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
35839 + ino_t h_ino, int idx)
35841 + struct au_xino_file *xino;
35843 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
35844 + xino = &au_sbr(sb, bindex)->br_xino;
35845 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
35847 + spin_lock(&xino->xi_nondir.spin);
35848 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
35849 + xino->xi_nondir.array[idx] = 0;
35850 + spin_unlock(&xino->xi_nondir.spin);
35851 + wake_up_all(&xino->xi_nondir.wqh);
35854 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
35856 + int found, total, i;
35859 + total = xino->xi_nondir.total;
35860 + for (i = 0; i < total; i++) {
35861 + if (xino->xi_nondir.array[i] != h_ino)
35870 +static int au_xinondir_expand(struct au_xino_file *xino)
35875 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
35878 + sz = xino->xi_nondir.total * sizeof(ino_t);
35879 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
35881 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
35882 + /*may_shrink*/0);
35884 + xino->xi_nondir.array = p;
35885 + xino->xi_nondir.total <<= 1;
35886 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
35894 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35897 + int err, found, empty;
35898 + struct au_xino_file *xino;
35902 + if (!au_opt_test(au_mntflags(sb), XINO))
35903 + goto out; /* no xino */
35905 + xino = &au_sbr(sb, bindex)->br_xino;
35908 + spin_lock(&xino->xi_nondir.spin);
35909 + found = au_xinondir_find(xino, h_ino);
35910 + if (found == -1) {
35911 + empty = au_xinondir_find(xino, /*h_ino*/0);
35912 + if (empty == -1) {
35913 + empty = xino->xi_nondir.total;
35914 + err = au_xinondir_expand(xino);
35915 + if (unlikely(err))
35918 + xino->xi_nondir.array[empty] = h_ino;
35921 + spin_unlock(&xino->xi_nondir.spin);
35922 + wait_event(xino->xi_nondir.wqh,
35923 + xino->xi_nondir.array[found] != h_ino);
35928 + spin_unlock(&xino->xi_nondir.spin);
35932 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35933 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35934 +++ linux/include/uapi/linux/aufs_type.h 2017-09-05 10:42:11.058755349 +0200
35937 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35939 + * This program, aufs is free software; you can redistribute it and/or modify
35940 + * it under the terms of the GNU General Public License as published by
35941 + * the Free Software Foundation; either version 2 of the License, or
35942 + * (at your option) any later version.
35944 + * This program is distributed in the hope that it will be useful,
35945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35947 + * GNU General Public License for more details.
35949 + * You should have received a copy of the GNU General Public License
35950 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35953 +#ifndef __AUFS_TYPE_H__
35954 +#define __AUFS_TYPE_H__
35956 +#define AUFS_NAME "aufs"
35960 + * define it before including all other headers.
35961 + * sched.h may use pr_* macros before defining "current", so define the
35962 + * no-current version first, and re-define later.
35964 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35965 +#include <linux/sched.h>
35967 +#define pr_fmt(fmt) \
35968 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35969 + (int)sizeof(current->comm), current->comm, current->pid
35971 +#include <stdint.h>
35972 +#include <sys/types.h>
35973 +#endif /* __KERNEL__ */
35975 +#include <linux/limits.h>
35977 +#define AUFS_VERSION "4.x-rcN-20170904"
35979 +/* todo? move this to linux-2.6.19/include/magic.h */
35980 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35982 +/* ---------------------------------------------------------------------- */
35984 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35985 +typedef int8_t aufs_bindex_t;
35986 +#define AUFS_BRANCH_MAX 127
35988 +typedef int16_t aufs_bindex_t;
35989 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35990 +#define AUFS_BRANCH_MAX 511
35991 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35992 +#define AUFS_BRANCH_MAX 1023
35993 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35994 +#define AUFS_BRANCH_MAX 32767
35999 +#ifndef AUFS_BRANCH_MAX
36000 +#error unknown CONFIG_AUFS_BRANCH_MAX value
36002 +#endif /* __KERNEL__ */
36004 +/* ---------------------------------------------------------------------- */
36006 +#define AUFS_FSTYPE AUFS_NAME
36008 +#define AUFS_ROOT_INO 2
36009 +#define AUFS_FIRST_INO 11
36011 +#define AUFS_WH_PFX ".wh."
36012 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
36013 +#define AUFS_WH_TMP_LEN 4
36014 +/* a limit for rmdir/rename a dir and copyup */
36015 +#define AUFS_MAX_NAMELEN (NAME_MAX \
36016 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
36018 + - AUFS_WH_TMP_LEN) /* hex */
36019 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
36020 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
36021 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
36022 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
36023 +#define AUFS_DIRWH_DEF 3
36024 +#define AUFS_RDCACHE_DEF 10 /* seconds */
36025 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
36026 +#define AUFS_RDBLK_DEF 512 /* bytes */
36027 +#define AUFS_RDHASH_DEF 32
36028 +#define AUFS_WKQ_NAME AUFS_NAME "d"
36029 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
36030 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
36031 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
36032 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
36034 +/* pseudo-link maintenace under /proc */
36035 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
36036 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
36037 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
36039 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
36040 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
36042 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
36043 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
36044 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
36046 +/* doubly whiteouted */
36047 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
36048 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
36049 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
36051 +/* branch permissions and attributes */
36052 +#define AUFS_BRPERM_RW "rw"
36053 +#define AUFS_BRPERM_RO "ro"
36054 +#define AUFS_BRPERM_RR "rr"
36055 +#define AUFS_BRATTR_COO_REG "coo_reg"
36056 +#define AUFS_BRATTR_COO_ALL "coo_all"
36057 +#define AUFS_BRATTR_FHSM "fhsm"
36058 +#define AUFS_BRATTR_UNPIN "unpin"
36059 +#define AUFS_BRATTR_ICEX "icex"
36060 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
36061 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
36062 +#define AUFS_BRATTR_ICEX_TR "icextr"
36063 +#define AUFS_BRATTR_ICEX_USR "icexusr"
36064 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
36065 +#define AUFS_BRRATTR_WH "wh"
36066 +#define AUFS_BRWATTR_NLWH "nolwh"
36067 +#define AUFS_BRWATTR_MOO "moo"
36069 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
36070 +#define AuBrPerm_RO (1 << 1) /* readonly */
36071 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
36072 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
36074 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
36075 +#define AuBrAttr_COO_ALL (1 << 4)
36076 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
36078 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
36079 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
36080 + branch. meaningless since
36081 + linux-3.18-rc1 */
36083 +/* ignore error in copying XATTR */
36084 +#define AuBrAttr_ICEX_SEC (1 << 7)
36085 +#define AuBrAttr_ICEX_SYS (1 << 8)
36086 +#define AuBrAttr_ICEX_TR (1 << 9)
36087 +#define AuBrAttr_ICEX_USR (1 << 10)
36088 +#define AuBrAttr_ICEX_OTH (1 << 11)
36089 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
36090 + | AuBrAttr_ICEX_SYS \
36091 + | AuBrAttr_ICEX_TR \
36092 + | AuBrAttr_ICEX_USR \
36093 + | AuBrAttr_ICEX_OTH)
36095 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
36096 +#define AuBrRAttr_Mask AuBrRAttr_WH
36098 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
36099 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
36100 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
36102 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
36104 +/* #warning test userspace */
36106 +#ifndef CONFIG_AUFS_FHSM
36107 +#undef AuBrAttr_FHSM
36108 +#define AuBrAttr_FHSM 0
36110 +#ifndef CONFIG_AUFS_XATTR
36111 +#undef AuBrAttr_ICEX
36112 +#define AuBrAttr_ICEX 0
36113 +#undef AuBrAttr_ICEX_SEC
36114 +#define AuBrAttr_ICEX_SEC 0
36115 +#undef AuBrAttr_ICEX_SYS
36116 +#define AuBrAttr_ICEX_SYS 0
36117 +#undef AuBrAttr_ICEX_TR
36118 +#define AuBrAttr_ICEX_TR 0
36119 +#undef AuBrAttr_ICEX_USR
36120 +#define AuBrAttr_ICEX_USR 0
36121 +#undef AuBrAttr_ICEX_OTH
36122 +#define AuBrAttr_ICEX_OTH 0
36126 +/* the longest combination */
36127 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
36128 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
36129 + "+" AUFS_BRATTR_COO_REG \
36130 + "+" AUFS_BRATTR_FHSM \
36131 + "+" AUFS_BRATTR_UNPIN \
36132 + "+" AUFS_BRATTR_ICEX_SEC \
36133 + "+" AUFS_BRATTR_ICEX_SYS \
36134 + "+" AUFS_BRATTR_ICEX_USR \
36135 + "+" AUFS_BRATTR_ICEX_OTH \
36136 + "+" AUFS_BRWATTR_NLWH)
36139 + char a[AuBrPermStrSz];
36140 +} au_br_perm_str_t;
36142 +static inline int au_br_writable(int brperm)
36144 + return brperm & AuBrPerm_RW;
36147 +static inline int au_br_whable(int brperm)
36149 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
36152 +static inline int au_br_wh_linkable(int brperm)
36154 + return !(brperm & AuBrWAttr_NoLinkWH);
36157 +static inline int au_br_cmoo(int brperm)
36159 + return brperm & AuBrAttr_CMOO_Mask;
36162 +static inline int au_br_fhsm(int brperm)
36164 + return brperm & AuBrAttr_FHSM;
36167 +/* ---------------------------------------------------------------------- */
36171 + /* readdir in userspace */
36175 + AuCtl_WBR_FD, /* pathconf wrapper */
36176 + AuCtl_IBUSY, /* busy inode */
36177 + AuCtl_MVDOWN, /* move-down */
36178 + AuCtl_BR, /* info about branches */
36179 + AuCtl_FHSM_FD /* connection for fhsm */
36182 +/* borrowed from linux/include/linux/kernel.h */
36184 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36185 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36188 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36190 +#define __aligned(x) __attribute__((aligned(x)))
36195 +#define __packed __attribute__((packed))
36199 +struct au_rdu_cookie {
36204 + uint32_t generation;
36207 +struct au_rdu_ent {
36216 +static inline int au_rdu_len(int nlen)
36218 + /* include the terminating NULL */
36219 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36220 + sizeof(uint64_t));
36223 +union au_rdu_ent_ul {
36224 + struct au_rdu_ent __user *e;
36236 + uint64_t sz; /* AuCtl_RDU */
36237 + uint64_t nent; /* AuCtl_RDU_INO */
36239 + union au_rdu_ent_ul ent;
36240 + uint16_t verify[AufsCtlRduV_End];
36242 + /* input/output */
36246 + union au_rdu_ent_ul tail;
36247 + /* number of entries which were added in a single call */
36252 + struct au_rdu_cookie cookie;
36255 +/* ---------------------------------------------------------------------- */
36257 +struct aufs_wbr_fd {
36262 +/* ---------------------------------------------------------------------- */
36264 +struct aufs_ibusy {
36265 + uint64_t ino, h_ino;
36269 +/* ---------------------------------------------------------------------- */
36271 +/* error code for move-down */
36272 +/* the actual message strings are implemented in aufs-util.git */
36274 + EAU_MVDOWN_OPAQUE = 1,
36275 + EAU_MVDOWN_WHITEOUT,
36276 + EAU_MVDOWN_UPPER,
36277 + EAU_MVDOWN_BOTTOM,
36278 + EAU_MVDOWN_NOUPPER,
36279 + EAU_MVDOWN_NOLOWERBR,
36283 +/* flags for move-down */
36284 +#define AUFS_MVDOWN_DMSG 1
36285 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36286 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36287 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36288 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36289 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36290 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36291 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36292 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36293 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36294 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36295 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36296 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36298 +/* index for move-down */
36300 + AUFS_MVDOWN_UPPER,
36301 + AUFS_MVDOWN_LOWER,
36302 + AUFS_MVDOWN_NARRAY
36306 + * additional info of move-down
36307 + * number of free blocks and inodes.
36308 + * subset of struct kstatfs, but smaller and always 64bit.
36310 +struct aufs_stfs {
36311 + uint64_t f_blocks;
36312 + uint64_t f_bavail;
36313 + uint64_t f_files;
36314 + uint64_t f_ffree;
36317 +struct aufs_stbr {
36318 + int16_t brid; /* optional input */
36319 + int16_t bindex; /* output */
36320 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36323 +struct aufs_mvdown {
36324 + uint32_t flags; /* input/output */
36325 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36326 + int8_t au_errno; /* output */
36329 +/* ---------------------------------------------------------------------- */
36331 +union aufs_brinfo {
36332 + /* PATH_MAX may differ between kernel-space and user-space */
36333 + char _spacer[4096];
36341 +/* ---------------------------------------------------------------------- */
36343 +#define AuCtlType 'A'
36344 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36345 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36346 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36347 + struct aufs_wbr_fd)
36348 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36349 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36350 + struct aufs_mvdown)
36351 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36352 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36354 +#endif /* __AUFS_TYPE_H__ */
36355 aufs4.x-rcN loopback patch
36357 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36358 index 10707c3..af32e47 100644
36359 --- a/drivers/block/loop.c
36360 +++ b/drivers/block/loop.c
36361 @@ -547,7 +547,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36364 struct switch_request {
36365 - struct file *file;
36366 + struct file *file, *virt_file;
36367 struct completion wait;
36370 @@ -573,6 +573,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36371 mapping = file->f_mapping;
36372 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36373 lo->lo_backing_file = file;
36374 + lo->lo_backing_virt_file = p->virt_file;
36375 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36376 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36377 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36378 @@ -585,11 +586,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36379 * First it needs to flush existing IO, it does this by sending a magic
36380 * BIO down the pipe. The completion of this BIO does the actual switch.
36382 -static int loop_switch(struct loop_device *lo, struct file *file)
36383 +static int loop_switch(struct loop_device *lo, struct file *file,
36384 + struct file *virt_file)
36386 struct switch_request w;
36389 + w.virt_file = virt_file;
36391 /* freeze queue and wait for completion of scheduled requests */
36392 blk_mq_freeze_queue(lo->lo_queue);
36393 @@ -611,7 +614,16 @@ static int loop_flush(struct loop_device *lo)
36394 /* loop not yet configured, no running thread, nothing to flush */
36395 if (lo->lo_state != Lo_bound)
36397 - return loop_switch(lo, NULL);
36398 + return loop_switch(lo, NULL, NULL);
36401 +static struct file *loop_real_file(struct file *file)
36403 + struct file *f = NULL;
36405 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36406 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36410 static void loop_reread_partitions(struct loop_device *lo,
36411 @@ -648,6 +660,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36414 struct file *file, *old_file;
36415 + struct file *f, *virt_file = NULL, *old_virt_file;
36416 struct inode *inode;
36419 @@ -664,9 +677,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36423 + f = loop_real_file(file);
36425 + virt_file = file;
36430 inode = file->f_mapping->host;
36431 old_file = lo->lo_backing_file;
36432 + old_virt_file = lo->lo_backing_virt_file;
36436 @@ -678,17 +698,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36439 /* and ... switch */
36440 - error = loop_switch(lo, file);
36441 + error = loop_switch(lo, file, virt_file);
36446 + if (old_virt_file)
36447 + fput(old_virt_file);
36448 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36449 loop_reread_partitions(lo, bdev);
36459 @@ -882,7 +906,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36460 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36461 struct block_device *bdev, unsigned int arg)
36463 - struct file *file, *f;
36464 + struct file *file, *f, *virt_file = NULL;
36465 struct inode *inode;
36466 struct address_space *mapping;
36467 unsigned lo_blocksize;
36468 @@ -897,6 +921,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36472 + f = loop_real_file(file);
36474 + virt_file = file;
36480 if (lo->lo_state != Lo_unbound)
36481 @@ -949,6 +979,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36482 lo->lo_device = bdev;
36483 lo->lo_flags = lo_flags;
36484 lo->lo_backing_file = file;
36485 + lo->lo_backing_virt_file = virt_file;
36486 lo->transfer = NULL;
36488 lo->lo_sizelimit = 0;
36489 @@ -981,6 +1012,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36496 /* This is safe: open() is still holding a reference. */
36497 module_put(THIS_MODULE);
36498 @@ -1027,6 +1060,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36499 static int loop_clr_fd(struct loop_device *lo)
36501 struct file *filp = lo->lo_backing_file;
36502 + struct file *virt_filp = lo->lo_backing_virt_file;
36503 gfp_t gfp = lo->old_gfp_mask;
36504 struct block_device *bdev = lo->lo_device;
36506 @@ -1058,6 +1092,7 @@ static int loop_clr_fd(struct loop_device *lo)
36507 spin_lock_irq(&lo->lo_lock);
36508 lo->lo_state = Lo_rundown;
36509 lo->lo_backing_file = NULL;
36510 + lo->lo_backing_virt_file = NULL;
36511 spin_unlock_irq(&lo->lo_lock);
36513 loop_release_xfer(lo);
36514 @@ -1102,6 +1137,8 @@ static int loop_clr_fd(struct loop_device *lo)
36515 * bd_mutex which is usually taken before lo_ctl_mutex.
36523 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36524 index fecd3f9..6b3a7c9 100644
36525 --- a/drivers/block/loop.h
36526 +++ b/drivers/block/loop.h
36527 @@ -46,7 +46,7 @@ struct loop_device {
36528 int (*ioctl)(struct loop_device *, int cmd,
36529 unsigned long arg);
36531 - struct file * lo_backing_file;
36532 + struct file * lo_backing_file, *lo_backing_virt_file;
36533 struct block_device *lo_device;
36534 unsigned lo_blocksize;
36536 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36537 index 870717e..ea7fee0 100644
36538 --- a/fs/aufs/f_op.c
36539 +++ b/fs/aufs/f_op.c
36540 @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36541 if (IS_ERR(h_file))
36544 - if (au_test_loopback_kthread()) {
36545 + if (0 && au_test_loopback_kthread()) {
36546 au_warn_loopback(h_file->f_path.dentry->d_sb);
36547 if (file->f_mapping != h_file->f_mapping) {
36548 file->f_mapping = h_file->f_mapping;
36549 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36550 index e35f015..b37f1ae 100644
36551 --- a/fs/aufs/loop.c
36552 +++ b/fs/aufs/loop.c
36553 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36554 symbol_put(loop_backing_file);
36555 kfree(au_warn_loopback_array);
36558 +/* ---------------------------------------------------------------------- */
36560 +/* support the loopback block device insude aufs */
36562 +struct file *aufs_real_loop(struct file *file)
36566 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36567 + fi_read_lock(file);
36568 + f = au_hf_top(file);
36569 + fi_read_unlock(file);
36573 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36574 index e2df495..36e5052 100644
36575 --- a/fs/aufs/loop.h
36576 +++ b/fs/aufs/loop.h
36577 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36579 int au_loopback_init(void);
36580 void au_loopback_fin(void);
36582 +struct file *aufs_real_loop(struct file *file);
36584 +AuStub(struct file *, loop_backing_file, return NULL)
36586 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36587 struct dentry *h_adding)
36588 AuStubInt0(au_test_loopback_kthread, void)
36589 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36591 AuStubInt0(au_loopback_init, void)
36592 AuStubVoid(au_loopback_fin, void)
36594 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36595 #endif /* BLK_DEV_LOOP */
36597 #endif /* __KERNEL__ */
36598 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36599 index 5455fb1..8b9df60 100644
36600 --- a/fs/aufs/super.c
36601 +++ b/fs/aufs/super.c
36602 @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = {
36603 .statfs = aufs_statfs,
36604 .put_super = aufs_put_super,
36605 .sync_fs = aufs_sync_fs,
36606 - .remount_fs = aufs_remount_fs
36607 + .remount_fs = aufs_remount_fs,
36608 +#ifdef CONFIG_AUFS_BDEV_LOOP
36609 + .real_loop = aufs_real_loop
36613 /* ---------------------------------------------------------------------- */
36614 diff --git a/include/linux/fs.h b/include/linux/fs.h
36615 index 9b21bb5..f7124fa 100644
36616 --- a/include/linux/fs.h
36617 +++ b/include/linux/fs.h
36618 @@ -1814,6 +1814,10 @@ struct super_operations {
36619 struct shrink_control *);
36620 long (*free_cached_objects)(struct super_block *,
36621 struct shrink_control *);
36622 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36624 + struct file *(*real_loop)(struct file *);