1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index b0e42b6..7fa4b68 100644
7 @@ -249,6 +249,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 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 09b5ab6..6640ab1 100644
30 @@ -2348,6 +2348,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 ebbd0c3..6b8a6a4c 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 a9f995f..3458af5 100644
83 @@ -1164,7 +1164,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 f4e7267..d39404c 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 db59147..69cbe9c 100644
118 @@ -1640,7 +1640,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 19d4d88..05033f7 100644
129 --- a/fs/read_write.c
130 +++ b/fs/read_write.c
131 @@ -513,6 +513,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 540c4a4..4a0bc62 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 11ba023..abf6a5d 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 803e5a9..22d2910 100644
215 --- a/include/linux/fs.h
216 +++ b/include/linux/fs.h
217 @@ -1248,6 +1248,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 void f_setown(struct file *filp, unsigned long arg, int force);
224 extern void f_delown(struct file *filp);
225 @@ -1674,6 +1675,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 @@ -1750,6 +1752,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 @@ -2131,6 +2139,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 @@ -2411,6 +2420,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 f1e1927..7b5af0c 100644
283 @@ -1943,7 +1943,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 520802d..61a037d 100644
310 --- a/fs/proc/task_mmu.c
311 +++ b/fs/proc/task_mmu.c
312 @@ -292,7 +292,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 @@ -1638,7 +1641,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 6f543a4..696494b 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 45cdb27..1a40012 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 e53770d..cdf7516 100644
406 @@ -665,7 +665,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 026f6a8..723da17 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 6f1be57..69a8d94 100644
432 @@ -2408,7 +2408,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 a5e3dcd..a5d908c 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 @@ -2571,7 +2571,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 @@ -2590,7 +2590,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 @@ -2744,7 +2744,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 @@ -2819,10 +2819,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 @@ -3113,7 +3130,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 3458af5..5fd25bb 100644
679 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
683 +EXPORT_SYMBOL_GPL(d_walk);
686 struct vfsmount *mnt;
687 @@ -2862,6 +2863,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 9041990..31f14c6 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 d39404c..ac1dc66 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 954d510..4fb5b10 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 @@ -259,6 +260,7 @@ void flush_delayed_fput(void)
735 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
737 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
739 @@ -301,6 +303,7 @@ void __fput_sync(struct file *file)
743 +EXPORT_SYMBOL_GPL(__fput_sync);
745 void put_filp(struct file *file)
747 @@ -309,6 +312,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 69cbe9c..764566d 100644
759 @@ -1649,6 +1649,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 5a44384..cc6f6fb 100644
771 @@ -462,6 +462,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 @@ -1881,6 +1882,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 cd0c5be..491442a 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 05033f7..ce062e8 100644
881 --- a/fs/read_write.c
882 +++ b/fs/read_write.c
883 @@ -523,6 +523,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 @@ -534,6 +535,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 4a0bc62..21d7893 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 abf6a5d..c86fe9c 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 b9fea39..afa97dd 100644
993 --- a/security/security.c
994 +++ b/security/security.c
995 @@ -492,6 +492,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 @@ -508,6 +509,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 @@ -516,6 +518,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 @@ -543,6 +546,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 @@ -550,6 +554,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 @@ -557,6 +562,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 @@ -642,6 +648,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 @@ -657,6 +664,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 @@ -828,6 +836,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 @@ -887,6 +896,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-07-29 12:14:25.893041746 +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] | [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-07-29 12:14:25.899708630 +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(h_src_inode);
5060 + err = au_copy_file(dst, src, len);
5061 + inode_lock(h_src_inode);
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(h_src_inode);
5083 + err = vfsub_clone_file_range(src, dst, len);
5084 + inode_lock(h_src_inode);
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 + inode_lock_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(h_src_inode);
5199 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5200 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5202 + if (unlikely(err)) {
5203 + inode_unlock(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(h_src_inode);
5211 + inode_unlock(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-07-29 12:14:25.899708630 +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 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7855 + opq = au_diropq_test(h_dentry);
7856 + inode_unlock(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 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7930 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7932 + inode_unlock(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-07-29 12:14:25.899708630 +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 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10346 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10347 + inode_unlock(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-07-29 12:14:25.903042072 +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/poll.h>
13218 +#include "rwsem.h"
13222 + struct file *hf_file;
13223 + struct au_branch *hf_br;
13228 + aufs_bindex_t fd_bbot;
13229 + aufs_bindex_t fd_nent;
13230 + struct au_vdir *fd_vdir_cache;
13231 + struct au_hfile fd_hfile[];
13234 +static inline int au_fidir_sz(int nent)
13236 + AuDebugOn(nent < 0);
13237 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13241 + atomic_t fi_generation;
13243 + struct au_rwsem fi_rwsem;
13244 + aufs_bindex_t fi_btop;
13246 + /* do not union them */
13247 + struct { /* for non-dir */
13248 + struct au_hfile fi_htop;
13249 + atomic_t fi_mmapped;
13251 + struct au_fidir *fi_hdir; /* for dir only */
13253 + struct hlist_node fi_hlist;
13254 + struct file *fi_file; /* very ugly */
13255 +} ____cacheline_aligned_in_smp;
13257 +/* ---------------------------------------------------------------------- */
13260 +extern const struct address_space_operations aufs_aop;
13261 +unsigned int au_file_roflags(unsigned int flags);
13262 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13263 + struct file *file, int force_wr);
13264 +struct au_do_open_args {
13266 + int (*open)(struct file *file, int flags,
13267 + struct file *h_file);
13268 + struct au_fidir *fidir;
13269 + struct file *h_file;
13271 +int au_do_open(struct file *file, struct au_do_open_args *args);
13272 +int au_reopen_nondir(struct file *file);
13274 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13275 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13276 + int wlock, unsigned int fi_lsc);
13277 +int au_do_flush(struct file *file, fl_owner_t id,
13278 + int (*flush)(struct file *file, fl_owner_t id));
13281 +#ifdef CONFIG_AUFS_POLL
13282 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13285 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13287 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13289 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13290 + struct file *h_file);
13292 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13293 + aufs_bindex_t bindex, int force_wr)
13294 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13295 + struct file *h_file);
13299 +extern const struct file_operations aufs_file_fop;
13300 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13301 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13302 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
13305 +void au_hfput(struct au_hfile *hf, int execed);
13306 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13307 + struct file *h_file);
13309 +void au_update_figen(struct file *file);
13310 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13311 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13313 +void au_fi_init_once(void *_fi);
13314 +void au_finfo_fin(struct file *file);
13315 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13318 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13319 +#ifdef CONFIG_COMPAT
13320 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13321 + unsigned long arg);
13322 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13323 + unsigned long arg);
13326 +/* ---------------------------------------------------------------------- */
13328 +static inline struct au_finfo *au_fi(struct file *file)
13330 + return file->private_data;
13333 +/* ---------------------------------------------------------------------- */
13336 + * fi_read_lock, fi_write_lock,
13337 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13339 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13341 +/* lock subclass for finfo */
13347 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
13349 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13352 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
13354 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
13358 + * fi_read_lock_1, fi_write_lock_1,
13359 + * fi_read_lock_2, fi_write_lock_2
13361 +#define AuReadLockFunc(name) \
13362 +static inline void fi_read_lock_##name(struct file *f) \
13363 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
13365 +#define AuWriteLockFunc(name) \
13366 +static inline void fi_write_lock_##name(struct file *f) \
13367 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
13369 +#define AuRWLockFuncs(name) \
13370 + AuReadLockFunc(name) \
13371 + AuWriteLockFunc(name)
13376 +#undef AuReadLockFunc
13377 +#undef AuWriteLockFunc
13378 +#undef AuRWLockFuncs
13380 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13381 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13382 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13384 +/* ---------------------------------------------------------------------- */
13386 +/* todo: hard/soft set? */
13387 +static inline aufs_bindex_t au_fbtop(struct file *file)
13389 + FiMustAnyLock(file);
13390 + return au_fi(file)->fi_btop;
13393 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13395 + FiMustAnyLock(file);
13396 + AuDebugOn(!au_fi(file)->fi_hdir);
13397 + return au_fi(file)->fi_hdir->fd_bbot;
13400 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13402 + FiMustAnyLock(file);
13403 + AuDebugOn(!au_fi(file)->fi_hdir);
13404 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13407 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13409 + FiMustWriteLock(file);
13410 + au_fi(file)->fi_btop = bindex;
13413 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13415 + FiMustWriteLock(file);
13416 + AuDebugOn(!au_fi(file)->fi_hdir);
13417 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13420 +static inline void au_set_fvdir_cache(struct file *file,
13421 + struct au_vdir *vdir_cache)
13423 + FiMustWriteLock(file);
13424 + AuDebugOn(!au_fi(file)->fi_hdir);
13425 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13428 +static inline struct file *au_hf_top(struct file *file)
13430 + FiMustAnyLock(file);
13431 + AuDebugOn(au_fi(file)->fi_hdir);
13432 + return au_fi(file)->fi_htop.hf_file;
13435 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13437 + FiMustAnyLock(file);
13438 + AuDebugOn(!au_fi(file)->fi_hdir);
13439 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13442 +/* todo: memory barrier? */
13443 +static inline unsigned int au_figen(struct file *f)
13445 + return atomic_read(&au_fi(f)->fi_generation);
13448 +static inline void au_set_mmapped(struct file *f)
13450 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13452 + pr_warn("fi_mmapped wrapped around\n");
13453 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13457 +static inline void au_unset_mmapped(struct file *f)
13459 + atomic_dec(&au_fi(f)->fi_mmapped);
13462 +static inline int au_test_mmapped(struct file *f)
13464 + return atomic_read(&au_fi(f)->fi_mmapped);
13467 +/* customize vma->vm_file */
13469 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13470 + struct file *file)
13474 + f = vma->vm_file;
13476 + vma->vm_file = file;
13481 +#define AuDbgVmRegion(file, vma) do {} while (0)
13483 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13484 + struct file *file)
13486 + au_do_vm_file_reset(vma, file);
13489 +#define AuDbgVmRegion(file, vma) \
13490 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13492 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13493 + struct file *file)
13497 + au_do_vm_file_reset(vma, file);
13498 + f = vma->vm_region->vm_file;
13500 + vma->vm_region->vm_file = file;
13503 +#endif /* CONFIG_MMU */
13505 +/* handle vma->vm_prfile */
13506 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13507 + struct file *file)
13510 + vma->vm_prfile = file;
13511 +#ifndef CONFIG_MMU
13513 + vma->vm_region->vm_prfile = file;
13517 +#endif /* __KERNEL__ */
13518 +#endif /* __AUFS_FILE_H__ */
13519 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13520 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13521 +++ linux/fs/aufs/finfo.c 2017-07-29 12:14:25.903042072 +0200
13524 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13526 + * This program, aufs is free software; you can redistribute it and/or modify
13527 + * it under the terms of the GNU General Public License as published by
13528 + * the Free Software Foundation; either version 2 of the License, or
13529 + * (at your option) any later version.
13531 + * This program is distributed in the hope that it will be useful,
13532 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13533 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13534 + * GNU General Public License for more details.
13536 + * You should have received a copy of the GNU General Public License
13537 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13541 + * file private data
13546 +void au_hfput(struct au_hfile *hf, int execed)
13549 + allow_write_access(hf->hf_file);
13550 + fput(hf->hf_file);
13551 + hf->hf_file = NULL;
13552 + au_br_put(hf->hf_br);
13553 + hf->hf_br = NULL;
13556 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13558 + struct au_finfo *finfo = au_fi(file);
13559 + struct au_hfile *hf;
13560 + struct au_fidir *fidir;
13562 + fidir = finfo->fi_hdir;
13564 + AuDebugOn(finfo->fi_btop != bindex);
13565 + hf = &finfo->fi_htop;
13567 + hf = fidir->fd_hfile + bindex;
13569 + if (hf && hf->hf_file)
13570 + au_hfput(hf, vfsub_file_execed(file));
13572 + FiMustWriteLock(file);
13573 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13574 + hf->hf_file = val;
13575 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13579 +void au_update_figen(struct file *file)
13581 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13582 + /* smp_mb(); */ /* atomic_set */
13585 +/* ---------------------------------------------------------------------- */
13587 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13589 + struct au_fidir *fidir;
13592 + nbr = au_sbbot(sb) + 1;
13594 + nbr = 2; /* initial allocate for 2 branches */
13595 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13597 + fidir->fd_bbot = -1;
13598 + fidir->fd_nent = nbr;
13604 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13607 + struct au_fidir *fidir, *p;
13609 + AuRwMustWriteLock(&finfo->fi_rwsem);
13610 + fidir = finfo->fi_hdir;
13611 + AuDebugOn(!fidir);
13614 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13615 + GFP_NOFS, may_shrink);
13617 + p->fd_nent = nbr;
13618 + finfo->fi_hdir = p;
13625 +/* ---------------------------------------------------------------------- */
13627 +void au_finfo_fin(struct file *file)
13629 + struct au_finfo *finfo;
13631 + au_nfiles_dec(file->f_path.dentry->d_sb);
13633 + finfo = au_fi(file);
13634 + AuDebugOn(finfo->fi_hdir);
13635 + AuRwDestroy(&finfo->fi_rwsem);
13636 + au_cache_free_finfo(finfo);
13639 +void au_fi_init_once(void *_finfo)
13641 + struct au_finfo *finfo = _finfo;
13643 + au_rw_init(&finfo->fi_rwsem);
13646 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13649 + struct au_finfo *finfo;
13650 + struct dentry *dentry;
13653 + dentry = file->f_path.dentry;
13654 + finfo = au_cache_alloc_finfo();
13655 + if (unlikely(!finfo))
13659 + au_nfiles_inc(dentry->d_sb);
13660 + au_rw_write_lock(&finfo->fi_rwsem);
13661 + finfo->fi_btop = -1;
13662 + finfo->fi_hdir = fidir;
13663 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13664 + /* smp_mb(); */ /* atomic_set */
13666 + file->private_data = finfo;
13671 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13672 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13673 +++ linux/fs/aufs/f_op.c 2017-07-29 12:14:25.903042072 +0200
13676 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13678 + * This program, aufs is free software; you can redistribute it and/or modify
13679 + * it under the terms of the GNU General Public License as published by
13680 + * the Free Software Foundation; either version 2 of the License, or
13681 + * (at your option) any later version.
13683 + * This program is distributed in the hope that it will be useful,
13684 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13685 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13686 + * GNU General Public License for more details.
13688 + * You should have received a copy of the GNU General Public License
13689 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13693 + * file and vm operations
13696 +#include <linux/aio.h>
13697 +#include <linux/fs_stack.h>
13698 +#include <linux/mman.h>
13699 +#include <linux/security.h>
13702 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13705 + aufs_bindex_t bindex;
13706 + struct dentry *dentry, *h_dentry;
13707 + struct au_finfo *finfo;
13708 + struct inode *h_inode;
13710 + FiMustWriteLock(file);
13713 + dentry = file->f_path.dentry;
13714 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13715 + finfo = au_fi(file);
13716 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13717 + atomic_set(&finfo->fi_mmapped, 0);
13718 + bindex = au_dbtop(dentry);
13720 + h_dentry = au_h_dptr(dentry, bindex);
13721 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13722 + if (unlikely(err))
13724 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13726 + h_dentry = h_file->f_path.dentry;
13727 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13728 + if (unlikely(err))
13730 + get_file(h_file);
13732 + if (IS_ERR(h_file))
13733 + err = PTR_ERR(h_file);
13735 + if ((flags & __O_TMPFILE)
13736 + && !(flags & O_EXCL)) {
13737 + h_inode = file_inode(h_file);
13738 + spin_lock(&h_inode->i_lock);
13739 + h_inode->i_state |= I_LINKABLE;
13740 + spin_unlock(&h_inode->i_lock);
13742 + au_set_fbtop(file, bindex);
13743 + au_set_h_fptr(file, bindex, h_file);
13744 + au_update_figen(file);
13745 + /* todo: necessary? */
13746 + /* file->f_ra = h_file->f_ra; */
13753 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13754 + struct file *file)
13757 + struct super_block *sb;
13758 + struct au_do_open_args args = {
13759 + .open = au_do_open_nondir
13762 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13763 + file, vfsub_file_flags(file), file->f_mode);
13765 + sb = file->f_path.dentry->d_sb;
13766 + si_read_lock(sb, AuLock_FLUSH);
13767 + err = au_do_open(file, &args);
13768 + si_read_unlock(sb);
13772 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13774 + struct au_finfo *finfo;
13775 + aufs_bindex_t bindex;
13777 + finfo = au_fi(file);
13778 + au_sphl_del(&finfo->fi_hlist,
13779 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13780 + bindex = finfo->fi_btop;
13782 + au_set_h_fptr(file, bindex, NULL);
13784 + au_finfo_fin(file);
13788 +/* ---------------------------------------------------------------------- */
13790 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13793 + struct file *h_file;
13796 + h_file = au_hf_top(file);
13798 + err = vfsub_flush(h_file, id);
13802 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13804 + return au_do_flush(file, id, au_do_flush_nondir);
13807 +/* ---------------------------------------------------------------------- */
13809 + * read and write functions acquire [fdi]_rwsem once, but release before
13810 + * mmap_sem. This is because to stop a race condition between mmap(2).
13811 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13812 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13813 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13816 +/* Callers should call au_read_post() or fput() in the end */
13817 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
13819 + struct file *h_file;
13822 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
13824 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13825 + h_file = au_hf_top(file);
13826 + get_file(h_file);
13828 + fi_read_unlock(file);
13830 + h_file = ERR_PTR(err);
13835 +static void au_read_post(struct inode *inode, struct file *h_file)
13837 + /* update without lock, I don't think it a problem */
13838 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13842 +struct au_write_pre {
13844 + unsigned int lsc;
13848 + aufs_bindex_t btop;
13852 + * return with iinfo is write-locked
13853 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13856 +static struct file *au_write_pre(struct file *file, int do_ready,
13857 + struct au_write_pre *wpre)
13859 + struct file *h_file;
13860 + struct dentry *dentry;
13862 + unsigned int lsc;
13863 + struct au_pin pin;
13868 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
13869 + h_file = ERR_PTR(err);
13870 + if (unlikely(err))
13873 + dentry = file->f_path.dentry;
13875 + err = au_ready_to_write(file, -1, &pin);
13876 + if (unlikely(err)) {
13877 + h_file = ERR_PTR(err);
13878 + di_write_unlock(dentry);
13883 + di_downgrade_lock(dentry, /*flags*/0);
13885 + wpre->btop = au_fbtop(file);
13886 + h_file = au_hf_top(file);
13887 + get_file(h_file);
13889 + wpre->blks = file_inode(h_file)->i_blocks;
13892 + di_read_unlock(dentry, /*flags*/0);
13895 + fi_write_unlock(file);
13900 +static void au_write_post(struct inode *inode, struct file *h_file,
13901 + struct au_write_pre *wpre, ssize_t written)
13903 + struct inode *h_inode;
13905 + au_cpup_attr_timesizes(inode);
13906 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13907 + h_inode = file_inode(h_file);
13908 + inode->i_mode = h_inode->i_mode;
13909 + ii_write_unlock(inode);
13910 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13912 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13913 + /*force*/h_inode->i_blocks > wpre->blks);
13917 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13921 + struct inode *inode;
13922 + struct file *h_file;
13923 + struct super_block *sb;
13925 + inode = file_inode(file);
13926 + sb = inode->i_sb;
13927 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13929 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
13930 + err = PTR_ERR(h_file);
13931 + if (IS_ERR(h_file))
13934 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13935 + err = vfsub_read_u(h_file, buf, count, ppos);
13936 + /* todo: necessary? */
13937 + /* file->f_ra = h_file->f_ra; */
13938 + au_read_post(inode, h_file);
13941 + si_read_unlock(sb);
13946 + * todo: very ugly
13947 + * it locks both of i_mutex and si_rwsem for read in safe.
13948 + * if the plink maintenance mode continues forever (that is the problem),
13949 + * may loop forever.
13951 +static void au_mtx_and_read_lock(struct inode *inode)
13954 + struct super_block *sb = inode->i_sb;
13957 + inode_lock(inode);
13958 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13961 + inode_unlock(inode);
13962 + si_read_lock(sb, AuLock_NOPLMW);
13963 + si_read_unlock(sb);
13967 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13968 + size_t count, loff_t *ppos)
13971 + struct au_write_pre wpre;
13972 + struct inode *inode;
13973 + struct file *h_file;
13974 + char __user *buf = (char __user *)ubuf;
13976 + inode = file_inode(file);
13977 + au_mtx_and_read_lock(inode);
13980 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13981 + err = PTR_ERR(h_file);
13982 + if (IS_ERR(h_file))
13985 + err = vfsub_write_u(h_file, buf, count, ppos);
13986 + au_write_post(inode, h_file, &wpre, err);
13989 + si_read_unlock(inode->i_sb);
13990 + inode_unlock(inode);
13994 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13995 + struct iov_iter *iov_iter)
13998 + struct file *file;
13999 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
14001 + err = security_file_permission(h_file, rw);
14002 + if (unlikely(err))
14007 + if (rw == MAY_READ)
14008 + iter = h_file->f_op->read_iter;
14009 + else if (rw == MAY_WRITE)
14010 + iter = h_file->f_op->write_iter;
14012 + file = kio->ki_filp;
14013 + kio->ki_filp = h_file;
14016 + err = iter(kio, iov_iter);
14019 + /* currently there is no such fs */
14021 + kio->ki_filp = file;
14027 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14030 + struct file *file, *h_file;
14031 + struct inode *inode;
14032 + struct super_block *sb;
14034 + file = kio->ki_filp;
14035 + inode = file_inode(file);
14036 + sb = inode->i_sb;
14037 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14039 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
14040 + err = PTR_ERR(h_file);
14041 + if (IS_ERR(h_file))
14044 + if (au_test_loopback_kthread()) {
14045 + au_warn_loopback(h_file->f_path.dentry->d_sb);
14046 + if (file->f_mapping != h_file->f_mapping) {
14047 + file->f_mapping = h_file->f_mapping;
14048 + smp_mb(); /* unnecessary? */
14051 + fi_read_unlock(file);
14053 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
14054 + /* todo: necessary? */
14055 + /* file->f_ra = h_file->f_ra; */
14056 + au_read_post(inode, h_file);
14059 + si_read_unlock(sb);
14063 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
14066 + struct au_write_pre wpre;
14067 + struct inode *inode;
14068 + struct file *file, *h_file;
14070 + file = kio->ki_filp;
14071 + inode = file_inode(file);
14072 + au_mtx_and_read_lock(inode);
14075 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14076 + err = PTR_ERR(h_file);
14077 + if (IS_ERR(h_file))
14080 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
14081 + au_write_post(inode, h_file, &wpre, err);
14084 + si_read_unlock(inode->i_sb);
14085 + inode_unlock(inode);
14089 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
14090 + struct pipe_inode_info *pipe, size_t len,
14091 + unsigned int flags)
14094 + struct file *h_file;
14095 + struct inode *inode;
14096 + struct super_block *sb;
14098 + inode = file_inode(file);
14099 + sb = inode->i_sb;
14100 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14102 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14103 + err = PTR_ERR(h_file);
14104 + if (IS_ERR(h_file))
14107 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14108 + /* todo: necessasry? */
14109 + /* file->f_ra = h_file->f_ra; */
14110 + au_read_post(inode, h_file);
14113 + si_read_unlock(sb);
14118 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14119 + size_t len, unsigned int flags)
14122 + struct au_write_pre wpre;
14123 + struct inode *inode;
14124 + struct file *h_file;
14126 + inode = file_inode(file);
14127 + au_mtx_and_read_lock(inode);
14130 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14131 + err = PTR_ERR(h_file);
14132 + if (IS_ERR(h_file))
14135 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14136 + au_write_post(inode, h_file, &wpre, err);
14139 + si_read_unlock(inode->i_sb);
14140 + inode_unlock(inode);
14144 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14148 + struct au_write_pre wpre;
14149 + struct inode *inode;
14150 + struct file *h_file;
14152 + inode = file_inode(file);
14153 + au_mtx_and_read_lock(inode);
14156 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14157 + err = PTR_ERR(h_file);
14158 + if (IS_ERR(h_file))
14162 + err = vfs_fallocate(h_file, mode, offset, len);
14164 + au_write_post(inode, h_file, &wpre, /*written*/1);
14167 + si_read_unlock(inode->i_sb);
14168 + inode_unlock(inode);
14172 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
14173 + struct file *dst, loff_t dst_pos,
14174 + size_t len, unsigned int flags)
14177 + struct au_write_pre wpre;
14178 + enum { SRC, DST };
14180 + struct inode *inode;
14181 + struct file *h_file;
14182 + struct super_block *h_sb;
14184 +#define a_src a[SRC]
14185 +#define a_dst a[DST]
14188 + a_src.inode = file_inode(src);
14189 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
14191 + a_dst.inode = file_inode(dst);
14192 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
14195 + au_mtx_and_read_lock(a_dst.inode);
14197 + * in order to match the order in di_write_lock2_{child,parent}(),
14198 + * use f_path.dentry for this comparision.
14200 + if (src->f_path.dentry < dst->f_path.dentry) {
14201 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
14202 + err = PTR_ERR(a_src.h_file);
14203 + if (IS_ERR(a_src.h_file))
14206 + wpre.lsc = AuLsc_FI_2;
14207 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14208 + err = PTR_ERR(a_dst.h_file);
14209 + if (IS_ERR(a_dst.h_file)) {
14210 + au_read_post(a_src.inode, a_src.h_file);
14214 + wpre.lsc = AuLsc_FI_1;
14215 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
14216 + err = PTR_ERR(a_dst.h_file);
14217 + if (IS_ERR(a_dst.h_file))
14220 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
14221 + err = PTR_ERR(a_src.h_file);
14222 + if (IS_ERR(a_src.h_file)) {
14223 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
14230 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
14231 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
14232 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
14238 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
14239 + dst_pos, len, flags);
14242 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
14243 + fi_read_unlock(src);
14244 + au_read_post(a_src.inode, a_src.h_file);
14246 + si_read_unlock(a_dst.inode->i_sb);
14247 + inode_unlock(a_dst.inode);
14254 +/* ---------------------------------------------------------------------- */
14257 + * The locking order around current->mmap_sem.
14258 + * - in most and regular cases
14259 + * file I/O syscall -- aufs_read() or something
14260 + * -- si_rwsem for read -- mmap_sem
14261 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14263 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14264 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14265 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14266 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14267 + * It means that when aufs acquires si_rwsem for write, the process should never
14268 + * acquire mmap_sem.
14270 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14271 + * problem either since any directory is not able to be mmap-ed.
14272 + * The similar scenario is applied to aufs_readlink() too.
14275 +#if 0 /* stop calling security_file_mmap() */
14276 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14277 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14279 +static unsigned long au_arch_prot_conv(unsigned long flags)
14281 + /* currently ppc64 only */
14282 +#ifdef CONFIG_PPC64
14283 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14284 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14285 + return AuConv_VM_PROT(flags, SAO);
14287 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14292 +static unsigned long au_prot_conv(unsigned long flags)
14294 + return AuConv_VM_PROT(flags, READ)
14295 + | AuConv_VM_PROT(flags, WRITE)
14296 + | AuConv_VM_PROT(flags, EXEC)
14297 + | au_arch_prot_conv(flags);
14300 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14301 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14303 +static unsigned long au_flag_conv(unsigned long flags)
14305 + return AuConv_VM_MAP(flags, GROWSDOWN)
14306 + | AuConv_VM_MAP(flags, DENYWRITE)
14307 + | AuConv_VM_MAP(flags, LOCKED);
14311 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14314 + const unsigned char wlock
14315 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14316 + struct super_block *sb;
14317 + struct file *h_file;
14318 + struct inode *inode;
14320 + AuDbgVmRegion(file, vma);
14322 + inode = file_inode(file);
14323 + sb = inode->i_sb;
14325 + si_read_lock(sb, AuLock_NOPLMW);
14327 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14329 + err = PTR_ERR(h_file);
14330 + if (IS_ERR(h_file))
14334 + au_set_mmapped(file);
14335 + au_vm_file_reset(vma, h_file);
14337 + * we cannot call security_mmap_file() here since it may acquire
14338 + * mmap_sem or i_mutex.
14340 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14341 + * au_flag_conv(vma->vm_flags));
14344 + err = call_mmap(h_file, vma);
14346 + au_vm_prfile_set(vma, file);
14347 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14348 + goto out_fput; /* success */
14350 + au_unset_mmapped(file);
14351 + au_vm_file_reset(vma, file);
14355 + ii_write_unlock(inode);
14360 + si_read_unlock(sb);
14366 +/* ---------------------------------------------------------------------- */
14368 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14372 + struct au_write_pre wpre;
14373 + struct inode *inode;
14374 + struct file *h_file;
14376 + err = 0; /* -EBADF; */ /* posix? */
14377 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14380 + inode = file_inode(file);
14381 + au_mtx_and_read_lock(inode);
14384 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14385 + err = PTR_ERR(h_file);
14386 + if (IS_ERR(h_file))
14389 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14390 + au_write_post(inode, h_file, &wpre, /*written*/0);
14393 + si_read_unlock(inode->i_sb);
14394 + inode_unlock(inode);
14399 +static int aufs_fasync(int fd, struct file *file, int flag)
14402 + struct file *h_file;
14403 + struct super_block *sb;
14405 + sb = file->f_path.dentry->d_sb;
14406 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14408 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14409 + err = PTR_ERR(h_file);
14410 + if (IS_ERR(h_file))
14413 + if (h_file->f_op->fasync)
14414 + err = h_file->f_op->fasync(fd, h_file, flag);
14415 + fput(h_file); /* instead of au_read_post() */
14418 + si_read_unlock(sb);
14422 +static int aufs_setfl(struct file *file, unsigned long arg)
14425 + struct file *h_file;
14426 + struct super_block *sb;
14428 + sb = file->f_path.dentry->d_sb;
14429 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14431 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
14432 + err = PTR_ERR(h_file);
14433 + if (IS_ERR(h_file))
14436 + /* stop calling h_file->fasync */
14437 + arg |= vfsub_file_flags(file) & FASYNC;
14438 + err = setfl(/*unused fd*/-1, h_file, arg);
14439 + fput(h_file); /* instead of au_read_post() */
14442 + si_read_unlock(sb);
14446 +/* ---------------------------------------------------------------------- */
14448 +/* no one supports this operation, currently */
14450 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14451 + size_t len, loff_t *pos, int more)
14456 +/* ---------------------------------------------------------------------- */
14458 +const struct file_operations aufs_file_fop = {
14459 + .owner = THIS_MODULE,
14461 + .llseek = default_llseek,
14463 + .read = aufs_read,
14464 + .write = aufs_write,
14465 + .read_iter = aufs_read_iter,
14466 + .write_iter = aufs_write_iter,
14468 +#ifdef CONFIG_AUFS_POLL
14469 + .poll = aufs_poll,
14471 + .unlocked_ioctl = aufs_ioctl_nondir,
14472 +#ifdef CONFIG_COMPAT
14473 + .compat_ioctl = aufs_compat_ioctl_nondir,
14475 + .mmap = aufs_mmap,
14476 + .open = aufs_open_nondir,
14477 + .flush = aufs_flush_nondir,
14478 + .release = aufs_release_nondir,
14479 + .fsync = aufs_fsync_nondir,
14480 + .fasync = aufs_fasync,
14481 + /* .sendpage = aufs_sendpage, */
14482 + .setfl = aufs_setfl,
14483 + .splice_write = aufs_splice_write,
14484 + .splice_read = aufs_splice_read,
14486 + .aio_splice_write = aufs_aio_splice_write,
14487 + .aio_splice_read = aufs_aio_splice_read,
14489 + .fallocate = aufs_fallocate,
14490 + .copy_file_range = aufs_copy_file_range
14492 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14493 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14494 +++ linux/fs/aufs/fstype.h 2017-07-29 12:14:25.903042072 +0200
14497 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14499 + * This program, aufs is free software; you can redistribute it and/or modify
14500 + * it under the terms of the GNU General Public License as published by
14501 + * the Free Software Foundation; either version 2 of the License, or
14502 + * (at your option) any later version.
14504 + * This program is distributed in the hope that it will be useful,
14505 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14507 + * GNU General Public License for more details.
14509 + * You should have received a copy of the GNU General Public License
14510 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14514 + * judging filesystem type
14517 +#ifndef __AUFS_FSTYPE_H__
14518 +#define __AUFS_FSTYPE_H__
14522 +#include <linux/fs.h>
14523 +#include <linux/magic.h>
14524 +#include <linux/nfs_fs.h>
14525 +#include <linux/romfs_fs.h>
14527 +static inline int au_test_aufs(struct super_block *sb)
14529 + return sb->s_magic == AUFS_SUPER_MAGIC;
14532 +static inline const char *au_sbtype(struct super_block *sb)
14534 + return sb->s_type->name;
14537 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14539 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14540 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14546 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14548 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14549 + return sb->s_magic == ROMFS_MAGIC;
14555 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14557 +#if IS_ENABLED(CONFIG_CRAMFS)
14558 + return sb->s_magic == CRAMFS_MAGIC;
14563 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14565 +#if IS_ENABLED(CONFIG_NFS_FS)
14566 + return sb->s_magic == NFS_SUPER_MAGIC;
14572 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14574 +#if IS_ENABLED(CONFIG_FUSE_FS)
14575 + return sb->s_magic == FUSE_SUPER_MAGIC;
14581 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14583 +#if IS_ENABLED(CONFIG_XFS_FS)
14584 + return sb->s_magic == XFS_SB_MAGIC;
14590 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14592 +#ifdef CONFIG_TMPFS
14593 + return sb->s_magic == TMPFS_MAGIC;
14599 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14601 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14602 + return !strcmp(au_sbtype(sb), "ecryptfs");
14608 +static inline int au_test_ramfs(struct super_block *sb)
14610 + return sb->s_magic == RAMFS_MAGIC;
14613 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14615 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14616 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14622 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14624 +#ifdef CONFIG_PROC_FS
14625 + return sb->s_magic == PROC_SUPER_MAGIC;
14631 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14633 +#ifdef CONFIG_SYSFS
14634 + return sb->s_magic == SYSFS_MAGIC;
14640 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14642 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14643 + return sb->s_magic == CONFIGFS_MAGIC;
14649 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14651 +#if IS_ENABLED(CONFIG_MINIX_FS)
14652 + return sb->s_magic == MINIX3_SUPER_MAGIC
14653 + || sb->s_magic == MINIX2_SUPER_MAGIC
14654 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14655 + || sb->s_magic == MINIX_SUPER_MAGIC
14656 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14662 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14664 +#if IS_ENABLED(CONFIG_FAT_FS)
14665 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14671 +static inline int au_test_msdos(struct super_block *sb)
14673 + return au_test_fat(sb);
14676 +static inline int au_test_vfat(struct super_block *sb)
14678 + return au_test_fat(sb);
14681 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14683 +#ifdef CONFIG_SECURITYFS
14684 + return sb->s_magic == SECURITYFS_MAGIC;
14690 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14692 +#if IS_ENABLED(CONFIG_SQUASHFS)
14693 + return sb->s_magic == SQUASHFS_MAGIC;
14699 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14701 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14702 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14708 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14710 +#if IS_ENABLED(CONFIG_XENFS)
14711 + return sb->s_magic == XENFS_SUPER_MAGIC;
14717 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14719 +#ifdef CONFIG_DEBUG_FS
14720 + return sb->s_magic == DEBUGFS_MAGIC;
14726 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14728 +#if IS_ENABLED(CONFIG_NILFS)
14729 + return sb->s_magic == NILFS_SUPER_MAGIC;
14735 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14737 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14738 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14744 +/* ---------------------------------------------------------------------- */
14746 + * they can't be an aufs branch.
14748 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14751 +#ifndef CONFIG_AUFS_BR_RAMFS
14752 + au_test_ramfs(sb) ||
14754 + au_test_procfs(sb)
14755 + || au_test_sysfs(sb)
14756 + || au_test_configfs(sb)
14757 + || au_test_debugfs(sb)
14758 + || au_test_securityfs(sb)
14759 + || au_test_xenfs(sb)
14760 + || au_test_ecryptfs(sb)
14761 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14762 + || au_test_aufs(sb); /* will be supported in next version */
14765 +static inline int au_test_fs_remote(struct super_block *sb)
14767 + return !au_test_tmpfs(sb)
14768 +#ifdef CONFIG_AUFS_BR_RAMFS
14769 + && !au_test_ramfs(sb)
14771 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14774 +/* ---------------------------------------------------------------------- */
14777 + * Note: these functions (below) are created after reading ->getattr() in all
14778 + * filesystems under linux/fs. it means we have to do so in every update...
14782 + * some filesystems require getattr to refresh the inode attributes before
14784 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14785 + * and leave the work for d_revalidate()
14787 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14789 + return au_test_nfs(sb)
14790 + || au_test_fuse(sb)
14791 + /* || au_test_btrfs(sb) */ /* untested */
14796 + * filesystems which don't maintain i_size or i_blocks.
14798 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14800 + return au_test_xfs(sb)
14801 + || au_test_btrfs(sb)
14802 + || au_test_ubifs(sb)
14803 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14804 + /* || au_test_minix(sb) */ /* untested */
14809 + * filesystems which don't store the correct value in some of their inode
14812 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14814 + return au_test_fs_bad_iattr_size(sb)
14815 + || au_test_fat(sb)
14816 + || au_test_msdos(sb)
14817 + || au_test_vfat(sb);
14820 +/* they don't check i_nlink in link(2) */
14821 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14823 + return au_test_tmpfs(sb)
14824 +#ifdef CONFIG_AUFS_BR_RAMFS
14825 + || au_test_ramfs(sb)
14827 + || au_test_ubifs(sb)
14828 + || au_test_hfsplus(sb);
14832 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14834 +static inline int au_test_fs_notime(struct super_block *sb)
14836 + return au_test_nfs(sb)
14837 + || au_test_fuse(sb)
14838 + || au_test_ubifs(sb)
14842 +/* temporary support for i#1 in cramfs */
14843 +static inline int au_test_fs_unique_ino(struct inode *inode)
14845 + if (au_test_cramfs(inode->i_sb))
14846 + return inode->i_ino != 1;
14850 +/* ---------------------------------------------------------------------- */
14853 + * the filesystem where the xino files placed must support i/o after unlink and
14854 + * maintain i_size and i_blocks.
14856 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14858 + return au_test_fs_remote(sb)
14859 + || au_test_fs_bad_iattr_size(sb)
14860 + /* don't want unnecessary work for xino */
14861 + || au_test_aufs(sb)
14862 + || au_test_ecryptfs(sb)
14863 + || au_test_nilfs(sb);
14866 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14868 + return au_test_tmpfs(sb)
14869 + || au_test_ramfs(sb);
14873 + * test if the @sb is real-readonly.
14875 +static inline int au_test_fs_rr(struct super_block *sb)
14877 + return au_test_squashfs(sb)
14878 + || au_test_iso9660(sb)
14879 + || au_test_cramfs(sb)
14880 + || au_test_romfs(sb);
14884 + * test if the @inode is nfs with 'noacl' option
14885 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14887 +static inline int au_test_nfs_noacl(struct inode *inode)
14889 + return au_test_nfs(inode->i_sb)
14890 + /* && IS_POSIXACL(inode) */
14891 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14894 +#endif /* __KERNEL__ */
14895 +#endif /* __AUFS_FSTYPE_H__ */
14896 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14897 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14898 +++ linux/fs/aufs/hfsnotify.c 2017-07-31 10:27:18.853311720 +0200
14901 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14903 + * This program, aufs is free software; you can redistribute it and/or modify
14904 + * it under the terms of the GNU General Public License as published by
14905 + * the Free Software Foundation; either version 2 of the License, or
14906 + * (at your option) any later version.
14908 + * This program is distributed in the hope that it will be useful,
14909 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14910 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14911 + * GNU General Public License for more details.
14913 + * You should have received a copy of the GNU General Public License
14914 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14918 + * fsnotify for the lower directories
14923 +/* FS_IN_IGNORED is unnecessary */
14924 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14925 + | FS_CREATE | FS_EVENT_ON_CHILD);
14926 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14927 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14929 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14931 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14933 + /* AuDbg("here\n"); */
14934 + au_cache_free_hnotify(hn);
14935 + smp_mb__before_atomic();
14936 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14937 + wake_up(&au_hfsn_wq);
14940 +static int au_hfsn_alloc(struct au_hinode *hinode)
14943 + struct au_hnotify *hn;
14944 + struct super_block *sb;
14945 + struct au_branch *br;
14946 + struct fsnotify_mark *mark;
14947 + aufs_bindex_t bindex;
14949 + hn = hinode->hi_notify;
14950 + sb = hn->hn_aufs_inode->i_sb;
14951 + bindex = au_br_index(sb, hinode->hi_id);
14952 + br = au_sbr(sb, bindex);
14953 + AuDebugOn(!br->br_hfsn);
14955 + mark = &hn->hn_mark;
14956 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
14957 + mark->mask = AuHfsnMask;
14959 + * by udba rename or rmdir, aufs assign a new inode to the known
14960 + * h_inode, so specify 1 to allow dups.
14963 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
14964 + /*allow_dups*/1);
14970 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14972 + struct fsnotify_mark *mark;
14973 + unsigned long long ull;
14974 + struct fsnotify_group *group;
14976 + ull = atomic64_inc_return(&au_hfsn_ifree);
14979 + mark = &hn->hn_mark;
14980 + spin_lock(&mark->lock);
14981 + group = mark->group;
14982 + fsnotify_get_group(group);
14983 + spin_unlock(&mark->lock);
14985 + fsnotify_destroy_mark(mark, group);
14986 + fsnotify_put_mark(mark);
14987 + fsnotify_put_group(group);
14990 + /* free hn by myself */
14994 +/* ---------------------------------------------------------------------- */
14996 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14998 + struct fsnotify_mark *mark;
15000 + mark = &hinode->hi_notify->hn_mark;
15001 + spin_lock(&mark->lock);
15003 + AuDebugOn(mark->mask & AuHfsnMask);
15004 + mark->mask |= AuHfsnMask;
15006 + AuDebugOn(!(mark->mask & AuHfsnMask));
15007 + mark->mask &= ~AuHfsnMask;
15009 + spin_unlock(&mark->lock);
15010 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
15013 +/* ---------------------------------------------------------------------- */
15015 +/* #define AuDbgHnotify */
15016 +#ifdef AuDbgHnotify
15017 +static char *au_hfsn_name(u32 mask)
15019 +#ifdef CONFIG_AUFS_DEBUG
15020 +#define test_ret(flag) \
15022 + if (mask & flag) \
15025 + test_ret(FS_ACCESS);
15026 + test_ret(FS_MODIFY);
15027 + test_ret(FS_ATTRIB);
15028 + test_ret(FS_CLOSE_WRITE);
15029 + test_ret(FS_CLOSE_NOWRITE);
15030 + test_ret(FS_OPEN);
15031 + test_ret(FS_MOVED_FROM);
15032 + test_ret(FS_MOVED_TO);
15033 + test_ret(FS_CREATE);
15034 + test_ret(FS_DELETE);
15035 + test_ret(FS_DELETE_SELF);
15036 + test_ret(FS_MOVE_SELF);
15037 + test_ret(FS_UNMOUNT);
15038 + test_ret(FS_Q_OVERFLOW);
15039 + test_ret(FS_IN_IGNORED);
15040 + test_ret(FS_ISDIR);
15041 + test_ret(FS_IN_ONESHOT);
15042 + test_ret(FS_EVENT_ON_CHILD);
15051 +/* ---------------------------------------------------------------------- */
15053 +static void au_hfsn_free_group(struct fsnotify_group *group)
15055 + struct au_br_hfsnotify *hfsn = group->private;
15057 + /* AuDbg("here\n"); */
15061 +static int au_hfsn_handle_event(struct fsnotify_group *group,
15062 + struct inode *inode,
15063 + struct fsnotify_mark *inode_mark,
15064 + struct fsnotify_mark *vfsmount_mark,
15065 + u32 mask, const void *data, int data_type,
15066 + const unsigned char *file_name, u32 cookie,
15067 + struct fsnotify_iter_info *iter_info)
15070 + struct au_hnotify *hnotify;
15071 + struct inode *h_dir, *h_inode;
15072 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
15074 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
15077 + /* if FS_UNMOUNT happens, there must be another bug */
15078 + AuDebugOn(mask & FS_UNMOUNT);
15079 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
15084 +#ifdef AuDbgHnotify
15086 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
15087 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
15088 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
15089 + h_dir->i_ino, mask, au_hfsn_name(mask),
15090 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
15091 + /* WARN_ON(1); */
15096 + AuDebugOn(!inode_mark);
15097 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
15098 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
15104 +static struct fsnotify_ops au_hfsn_ops = {
15105 + .handle_event = au_hfsn_handle_event,
15106 + .free_group_priv = au_hfsn_free_group,
15107 + .free_mark = au_hfsn_free_mark
15110 +/* ---------------------------------------------------------------------- */
15112 +static void au_hfsn_fin_br(struct au_branch *br)
15114 + struct au_br_hfsnotify *hfsn;
15116 + hfsn = br->br_hfsn;
15119 + fsnotify_put_group(hfsn->hfsn_group);
15124 +static int au_hfsn_init_br(struct au_branch *br, int perm)
15127 + struct fsnotify_group *group;
15128 + struct au_br_hfsnotify *hfsn;
15131 + br->br_hfsn = NULL;
15132 + if (!au_br_hnotifyable(perm))
15136 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
15137 + if (unlikely(!hfsn))
15141 + group = fsnotify_alloc_group(&au_hfsn_ops);
15142 + if (IS_ERR(group)) {
15143 + err = PTR_ERR(group);
15144 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
15148 + group->private = hfsn;
15149 + hfsn->hfsn_group = group;
15150 + br->br_hfsn = hfsn;
15151 + goto out; /* success */
15159 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
15164 + if (!br->br_hfsn)
15165 + err = au_hfsn_init_br(br, perm);
15170 +/* ---------------------------------------------------------------------- */
15172 +static void au_hfsn_fin(void)
15174 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
15175 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
15178 +const struct au_hnotify_op au_hnotify_op = {
15179 + .ctl = au_hfsn_ctl,
15180 + .alloc = au_hfsn_alloc,
15181 + .free = au_hfsn_free,
15183 + .fin = au_hfsn_fin,
15185 + .reset_br = au_hfsn_reset_br,
15186 + .fin_br = au_hfsn_fin_br,
15187 + .init_br = au_hfsn_init_br
15189 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15190 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15191 +++ linux/fs/aufs/hfsplus.c 2017-07-29 12:14:25.903042072 +0200
15194 + * Copyright (C) 2010-2017 Junjiro R. Okajima
15196 + * This program, aufs is free software; you can redistribute it and/or modify
15197 + * it under the terms of the GNU General Public License as published by
15198 + * the Free Software Foundation; either version 2 of the License, or
15199 + * (at your option) any later version.
15201 + * This program is distributed in the hope that it will be useful,
15202 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15203 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15204 + * GNU General Public License for more details.
15206 + * You should have received a copy of the GNU General Public License
15207 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15211 + * special support for filesystems which aqucires an inode mutex
15212 + * at final closing a file, eg, hfsplus.
15214 + * This trick is very simple and stupid, just to open the file before really
15215 + * neceeary open to tell hfsplus that this is not the final closing.
15216 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15217 + * and au_h_open_post() after releasing it.
15222 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15225 + struct file *h_file;
15226 + struct dentry *h_dentry;
15228 + h_dentry = au_h_dptr(dentry, bindex);
15229 + AuDebugOn(!h_dentry);
15230 + AuDebugOn(d_is_negative(h_dentry));
15233 + if (au_test_hfsplus(h_dentry->d_sb)
15234 + && d_is_reg(h_dentry))
15235 + h_file = au_h_open(dentry, bindex,
15236 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15237 + /*file*/NULL, force_wr);
15241 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15242 + struct file *h_file)
15246 + au_sbr_put(dentry->d_sb, bindex);
15249 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15250 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15251 +++ linux/fs/aufs/hnotify.c 2017-07-29 12:14:25.903042072 +0200
15254 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15256 + * This program, aufs is free software; you can redistribute it and/or modify
15257 + * it under the terms of the GNU General Public License as published by
15258 + * the Free Software Foundation; either version 2 of the License, or
15259 + * (at your option) any later version.
15261 + * This program is distributed in the hope that it will be useful,
15262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15264 + * GNU General Public License for more details.
15266 + * You should have received a copy of the GNU General Public License
15267 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15271 + * abstraction to notify the direct changes on lower directories
15276 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15279 + struct au_hnotify *hn;
15282 + hn = au_cache_alloc_hnotify();
15284 + hn->hn_aufs_inode = inode;
15285 + hinode->hi_notify = hn;
15286 + err = au_hnotify_op.alloc(hinode);
15288 + if (unlikely(err)) {
15289 + hinode->hi_notify = NULL;
15290 + au_cache_free_hnotify(hn);
15292 + * The upper dir was removed by udba, but the same named
15293 + * dir left. In this case, aufs assignes a new inode
15294 + * number and set the monitor again.
15295 + * For the lower dir, the old monitnor is still left.
15297 + if (err == -EEXIST)
15306 +void au_hn_free(struct au_hinode *hinode)
15308 + struct au_hnotify *hn;
15310 + hn = hinode->hi_notify;
15312 + hinode->hi_notify = NULL;
15313 + if (au_hnotify_op.free(hinode, hn))
15314 + au_cache_free_hnotify(hn);
15318 +/* ---------------------------------------------------------------------- */
15320 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15322 + if (hinode->hi_notify)
15323 + au_hnotify_op.ctl(hinode, do_set);
15326 +void au_hn_reset(struct inode *inode, unsigned int flags)
15328 + aufs_bindex_t bindex, bbot;
15329 + struct inode *hi;
15330 + struct dentry *iwhdentry;
15332 + bbot = au_ibbot(inode);
15333 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15334 + hi = au_h_iptr(inode, bindex);
15338 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15339 + iwhdentry = au_hi_wh(inode, bindex);
15343 + au_set_h_iptr(inode, bindex, NULL, 0);
15344 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15345 + flags & ~AuHi_XINO);
15348 + /* inode_unlock(hi); */
15352 +/* ---------------------------------------------------------------------- */
15354 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15357 + aufs_bindex_t bindex, bbot, bfound, btop;
15358 + struct inode *h_i;
15361 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15362 + pr_warn("branch root dir was changed\n");
15367 + bbot = au_ibbot(inode);
15368 + btop = au_ibtop(inode);
15369 +#if 0 /* reserved for future use */
15370 + if (bindex == bbot) {
15371 + /* keep this ino in rename case */
15375 + for (bindex = btop; bindex <= bbot; bindex++)
15376 + if (au_h_iptr(inode, bindex) == h_inode) {
15383 + for (bindex = btop; bindex <= bbot; bindex++) {
15384 + h_i = au_h_iptr(inode, bindex);
15388 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15389 + /* ignore this error */
15390 + /* bad action? */
15393 + /* children inode number will be broken */
15400 +static int hn_gen_tree(struct dentry *dentry)
15402 + int err, i, j, ndentry;
15403 + struct au_dcsub_pages dpages;
15404 + struct au_dpage *dpage;
15405 + struct dentry **dentries;
15407 + err = au_dpages_init(&dpages, GFP_NOFS);
15408 + if (unlikely(err))
15410 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15411 + if (unlikely(err))
15414 + for (i = 0; i < dpages.ndpage; i++) {
15415 + dpage = dpages.dpages + i;
15416 + dentries = dpage->dentries;
15417 + ndentry = dpage->ndentry;
15418 + for (j = 0; j < ndentry; j++) {
15419 + struct dentry *d;
15426 + if (d_really_is_positive(d))
15427 + /* todo: reset children xino?
15428 + cached children only? */
15429 + au_iigen_dec(d_inode(d));
15434 + au_dpages_free(&dpages);
15437 + /* discard children */
15438 + dentry_unhash(dentry);
15446 + * return 0 if processed.
15448 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15449 + const unsigned int isdir)
15452 + struct dentry *d;
15453 + struct qstr *dname;
15456 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15457 + pr_warn("branch root dir was changed\n");
15463 + AuDebugOn(!name);
15464 + au_iigen_dec(inode);
15465 + spin_lock(&inode->i_lock);
15466 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15467 + spin_lock(&d->d_lock);
15468 + dname = &d->d_name;
15469 + if (dname->len != nlen
15470 + && memcmp(dname->name, name, nlen)) {
15471 + spin_unlock(&d->d_lock);
15476 + spin_unlock(&d->d_lock);
15479 + spin_unlock(&inode->i_lock);
15481 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15482 + d = d_find_any_alias(inode);
15484 + au_iigen_dec(inode);
15488 + spin_lock(&d->d_lock);
15489 + dname = &d->d_name;
15490 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15491 + spin_unlock(&d->d_lock);
15492 + err = hn_gen_tree(d);
15493 + spin_lock(&d->d_lock);
15495 + spin_unlock(&d->d_lock);
15504 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15508 + if (IS_ROOT(dentry)) {
15509 + pr_warn("branch root dir was changed\n");
15515 + au_digen_dec(dentry);
15516 + if (d_really_is_positive(dentry))
15517 + au_iigen_dec(d_inode(dentry));
15519 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15520 + if (d_really_is_positive(dentry))
15521 + err = hn_gen_tree(dentry);
15528 +/* ---------------------------------------------------------------------- */
15530 +/* hnotify job flags */
15531 +#define AuHnJob_XINO0 1
15532 +#define AuHnJob_GEN (1 << 1)
15533 +#define AuHnJob_DIRENT (1 << 2)
15534 +#define AuHnJob_ISDIR (1 << 3)
15535 +#define AuHnJob_TRYXINO0 (1 << 4)
15536 +#define AuHnJob_MNTPNT (1 << 5)
15537 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15538 +#define au_fset_hnjob(flags, name) \
15539 + do { (flags) |= AuHnJob_##name; } while (0)
15540 +#define au_fclr_hnjob(flags, name) \
15541 + do { (flags) &= ~AuHnJob_##name; } while (0)
15549 +struct au_hnotify_args {
15550 + struct inode *h_dir, *dir, *h_child_inode;
15552 + unsigned int flags[AuHnLast];
15553 + unsigned int h_child_nlen;
15554 + char h_child_name[];
15557 +struct hn_job_args {
15558 + unsigned int flags;
15559 + struct inode *inode, *h_inode, *dir, *h_dir;
15560 + struct dentry *dentry;
15565 +static int hn_job(struct hn_job_args *a)
15567 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15571 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15572 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15574 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15577 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15578 + if (!a->h_inode->i_nlink
15579 + && !(a->h_inode->i_state & I_LINKABLE))
15580 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15581 + inode_unlock(a->h_inode);
15584 + /* make the generation obsolete */
15585 + if (au_ftest_hnjob(a->flags, GEN)) {
15588 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15590 + if (e && a->dentry)
15591 + hn_gen_by_name(a->dentry, isdir);
15592 + /* ignore this error */
15595 + /* make dir entries obsolete */
15596 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15597 + struct au_vdir *vdir;
15599 + vdir = au_ivdir(a->inode);
15601 + vdir->vd_jiffy = 0;
15602 + /* IMustLock(a->inode); */
15603 + /* a->inode->i_version++; */
15606 + /* can do nothing but warn */
15607 + if (au_ftest_hnjob(a->flags, MNTPNT)
15609 + && d_mountpoint(a->dentry))
15610 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15615 +/* ---------------------------------------------------------------------- */
15617 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15618 + struct inode *dir)
15620 + struct dentry *dentry, *d, *parent;
15621 + struct qstr *dname;
15623 + parent = d_find_any_alias(dir);
15628 + spin_lock(&parent->d_lock);
15629 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15630 + /* AuDbg("%pd\n", d); */
15631 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15632 + dname = &d->d_name;
15633 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15634 + goto cont_unlock;
15638 + goto cont_unlock;
15639 + if (au_dcount(d) > 0) {
15640 + dentry = dget_dlock(d);
15641 + spin_unlock(&d->d_lock);
15646 + spin_unlock(&d->d_lock);
15648 + spin_unlock(&parent->d_lock);
15652 + di_write_lock_child(dentry);
15657 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15658 + aufs_bindex_t bindex, ino_t h_ino)
15660 + struct inode *inode;
15665 + err = au_xino_read(sb, bindex, h_ino, &ino);
15667 + inode = ilookup(sb, ino);
15671 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15672 + pr_warn("wrong root branch\n");
15678 + ii_write_lock_child(inode);
15684 +static void au_hn_bh(void *_args)
15686 + struct au_hnotify_args *a = _args;
15687 + struct super_block *sb;
15688 + aufs_bindex_t bindex, bbot, bfound;
15689 + unsigned char xino, try_iput;
15691 + struct inode *inode;
15693 + struct hn_job_args args;
15694 + struct dentry *dentry;
15695 + struct au_sbinfo *sbinfo;
15697 + AuDebugOn(!_args);
15698 + AuDebugOn(!a->h_dir);
15699 + AuDebugOn(!a->dir);
15700 + AuDebugOn(!a->mask);
15701 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15702 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15703 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15708 + * do not lock a->dir->i_mutex here
15709 + * because of d_revalidate() may cause a deadlock.
15711 + sb = a->dir->i_sb;
15713 + sbinfo = au_sbi(sb);
15714 + AuDebugOn(!sbinfo);
15715 + si_write_lock(sb, AuLock_NOPLMW);
15717 + ii_read_lock_parent(a->dir);
15719 + bbot = au_ibbot(a->dir);
15720 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15721 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15725 + ii_read_unlock(a->dir);
15726 + if (unlikely(bfound < 0))
15729 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15731 + if (a->h_child_inode)
15732 + h_ino = a->h_child_inode->i_ino;
15734 + if (a->h_child_nlen
15735 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15736 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15737 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15740 + if (dentry && d_really_is_positive(dentry))
15741 + inode = d_inode(dentry);
15742 + if (xino && !inode && h_ino
15743 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15744 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15745 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15746 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15750 + args.flags = a->flags[AuHn_CHILD];
15751 + args.dentry = dentry;
15752 + args.inode = inode;
15753 + args.h_inode = a->h_child_inode;
15754 + args.dir = a->dir;
15755 + args.h_dir = a->h_dir;
15756 + args.h_name = a->h_child_name;
15757 + args.h_nlen = a->h_child_nlen;
15758 + err = hn_job(&args);
15760 + if (au_di(dentry))
15761 + di_write_unlock(dentry);
15764 + if (inode && try_iput) {
15765 + ii_write_unlock(inode);
15769 + ii_write_lock_parent(a->dir);
15770 + args.flags = a->flags[AuHn_PARENT];
15771 + args.dentry = NULL;
15772 + args.inode = a->dir;
15773 + args.h_inode = a->h_dir;
15775 + args.h_dir = NULL;
15776 + args.h_name = NULL;
15778 + err = hn_job(&args);
15779 + ii_write_unlock(a->dir);
15782 + iput(a->h_child_inode);
15785 + si_write_unlock(sb);
15786 + au_nwt_done(&sbinfo->si_nowait);
15790 +/* ---------------------------------------------------------------------- */
15792 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15793 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15796 + unsigned int flags[AuHnLast], f;
15797 + unsigned char isdir, isroot, wh;
15798 + struct inode *dir;
15799 + struct au_hnotify_args *args;
15800 + char *p, *h_child_name;
15803 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15804 + dir = igrab(hnotify->hn_aufs_inode);
15808 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15810 + h_child_name = (void *)h_child_qstr->name;
15811 + len = h_child_qstr->len;
15812 + if (h_child_name) {
15813 + if (len > AUFS_WH_PFX_LEN
15814 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15815 + h_child_name += AUFS_WH_PFX_LEN;
15816 + len -= AUFS_WH_PFX_LEN;
15822 + if (h_child_inode)
15823 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15824 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15825 + flags[AuHn_CHILD] = 0;
15827 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15828 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15829 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15830 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15831 + case FS_MOVED_FROM:
15832 + case FS_MOVED_TO:
15833 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15834 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15837 + AuDebugOn(!h_child_name);
15842 + * aufs never be able to get this child inode.
15843 + * revalidation should be in d_revalidate()
15844 + * by checking i_nlink, i_generation or d_unhashed().
15846 + AuDebugOn(!h_child_name);
15847 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15848 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15856 + h_child_inode = NULL;
15859 + /* iput() and kfree() will be called in au_hnotify() */
15860 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15861 + if (unlikely(!args)) {
15862 + AuErr1("no memory\n");
15866 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15867 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15868 + args->mask = mask;
15870 + args->h_dir = igrab(h_dir);
15871 + if (h_child_inode)
15872 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15873 + args->h_child_inode = h_child_inode;
15874 + args->h_child_nlen = len;
15876 + p = (void *)args;
15877 + p += sizeof(*args);
15878 + memcpy(p, h_child_name, len);
15882 + /* NFS fires the event for silly-renamed one from kworker */
15884 + if (!dir->i_nlink
15885 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15887 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15888 + if (unlikely(err)) {
15889 + pr_err("wkq %d\n", err);
15890 + iput(args->h_child_inode);
15891 + iput(args->h_dir);
15900 +/* ---------------------------------------------------------------------- */
15902 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15906 + AuDebugOn(!(udba & AuOptMask_UDBA));
15909 + if (au_hnotify_op.reset_br)
15910 + err = au_hnotify_op.reset_br(udba, br, perm);
15915 +int au_hnotify_init_br(struct au_branch *br, int perm)
15920 + if (au_hnotify_op.init_br)
15921 + err = au_hnotify_op.init_br(br, perm);
15926 +void au_hnotify_fin_br(struct au_branch *br)
15928 + if (au_hnotify_op.fin_br)
15929 + au_hnotify_op.fin_br(br);
15932 +static void au_hn_destroy_cache(void)
15934 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
15935 + au_cache[AuCache_HNOTIFY] = NULL;
15938 +int __init au_hnotify_init(void)
15943 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
15944 + if (au_cache[AuCache_HNOTIFY]) {
15946 + if (au_hnotify_op.init)
15947 + err = au_hnotify_op.init();
15948 + if (unlikely(err))
15949 + au_hn_destroy_cache();
15955 +void au_hnotify_fin(void)
15957 + if (au_hnotify_op.fin)
15958 + au_hnotify_op.fin();
15960 + /* cf. au_cache_fin() */
15961 + if (au_cache[AuCache_HNOTIFY])
15962 + au_hn_destroy_cache();
15964 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15965 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15966 +++ linux/fs/aufs/iinfo.c 2017-07-29 12:14:25.903042072 +0200
15969 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15971 + * This program, aufs is free software; you can redistribute it and/or modify
15972 + * it under the terms of the GNU General Public License as published by
15973 + * the Free Software Foundation; either version 2 of the License, or
15974 + * (at your option) any later version.
15976 + * This program is distributed in the hope that it will be useful,
15977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15979 + * GNU General Public License for more details.
15981 + * You should have received a copy of the GNU General Public License
15982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15986 + * inode private data
15991 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15993 + struct inode *h_inode;
15994 + struct au_hinode *hinode;
15996 + IiMustAnyLock(inode);
15998 + hinode = au_hinode(au_ii(inode), bindex);
15999 + h_inode = hinode->hi_inode;
16000 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16004 +/* todo: hard/soft set? */
16005 +void au_hiput(struct au_hinode *hinode)
16007 + au_hn_free(hinode);
16008 + dput(hinode->hi_whdentry);
16009 + iput(hinode->hi_inode);
16012 +unsigned int au_hi_flags(struct inode *inode, int isdir)
16014 + unsigned int flags;
16015 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
16018 + if (au_opt_test(mnt_flags, XINO))
16019 + au_fset_hi(flags, XINO);
16020 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
16021 + au_fset_hi(flags, HNOTIFY);
16025 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16026 + struct inode *h_inode, unsigned int flags)
16028 + struct au_hinode *hinode;
16029 + struct inode *hi;
16030 + struct au_iinfo *iinfo = au_ii(inode);
16032 + IiMustWriteLock(inode);
16034 + hinode = au_hinode(iinfo, bindex);
16035 + hi = hinode->hi_inode;
16036 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
16039 + au_hiput(hinode);
16040 + hinode->hi_inode = h_inode;
16043 + struct super_block *sb = inode->i_sb;
16044 + struct au_branch *br;
16046 + AuDebugOn(inode->i_mode
16047 + && (h_inode->i_mode & S_IFMT)
16048 + != (inode->i_mode & S_IFMT));
16049 + if (bindex == iinfo->ii_btop)
16050 + au_cpup_igen(inode, h_inode);
16051 + br = au_sbr(sb, bindex);
16052 + hinode->hi_id = br->br_id;
16053 + if (au_ftest_hi(flags, XINO)) {
16054 + err = au_xino_write(sb, bindex, h_inode->i_ino,
16056 + if (unlikely(err))
16057 + AuIOErr1("failed au_xino_write() %d\n", err);
16060 + if (au_ftest_hi(flags, HNOTIFY)
16061 + && au_br_hnotifyable(br->br_perm)) {
16062 + err = au_hn_alloc(hinode, inode);
16063 + if (unlikely(err))
16064 + AuIOErr1("au_hn_alloc() %d\n", err);
16069 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16070 + struct dentry *h_wh)
16072 + struct au_hinode *hinode;
16074 + IiMustWriteLock(inode);
16076 + hinode = au_hinode(au_ii(inode), bindex);
16077 + AuDebugOn(hinode->hi_whdentry);
16078 + hinode->hi_whdentry = h_wh;
16081 +void au_update_iigen(struct inode *inode, int half)
16083 + struct au_iinfo *iinfo;
16084 + struct au_iigen *iigen;
16085 + unsigned int sigen;
16087 + sigen = au_sigen(inode->i_sb);
16088 + iinfo = au_ii(inode);
16089 + iigen = &iinfo->ii_generation;
16090 + spin_lock(&iigen->ig_spin);
16091 + iigen->ig_generation = sigen;
16093 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
16095 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
16096 + spin_unlock(&iigen->ig_spin);
16099 +/* it may be called at remount time, too */
16100 +void au_update_ibrange(struct inode *inode, int do_put_zero)
16102 + struct au_iinfo *iinfo;
16103 + aufs_bindex_t bindex, bbot;
16105 + AuDebugOn(au_is_bad_inode(inode));
16106 + IiMustWriteLock(inode);
16108 + iinfo = au_ii(inode);
16109 + if (do_put_zero && iinfo->ii_btop >= 0) {
16110 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16112 + struct inode *h_i;
16114 + h_i = au_hinode(iinfo, bindex)->hi_inode;
16117 + && !(h_i->i_state & I_LINKABLE))
16118 + au_set_h_iptr(inode, bindex, NULL, 0);
16122 + iinfo->ii_btop = -1;
16123 + iinfo->ii_bbot = -1;
16124 + bbot = au_sbbot(inode->i_sb);
16125 + for (bindex = 0; bindex <= bbot; bindex++)
16126 + if (au_hinode(iinfo, bindex)->hi_inode) {
16127 + iinfo->ii_btop = bindex;
16130 + if (iinfo->ii_btop >= 0)
16131 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
16132 + if (au_hinode(iinfo, bindex)->hi_inode) {
16133 + iinfo->ii_bbot = bindex;
16136 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
16139 +/* ---------------------------------------------------------------------- */
16141 +void au_icntnr_init_once(void *_c)
16143 + struct au_icntnr *c = _c;
16144 + struct au_iinfo *iinfo = &c->iinfo;
16146 + spin_lock_init(&iinfo->ii_generation.ig_spin);
16147 + au_rw_init(&iinfo->ii_rwsem);
16148 + inode_init_once(&c->vfs_inode);
16151 +void au_hinode_init(struct au_hinode *hinode)
16153 + hinode->hi_inode = NULL;
16154 + hinode->hi_id = -1;
16155 + au_hn_init(hinode);
16156 + hinode->hi_whdentry = NULL;
16159 +int au_iinfo_init(struct inode *inode)
16161 + struct au_iinfo *iinfo;
16162 + struct super_block *sb;
16163 + struct au_hinode *hi;
16166 + sb = inode->i_sb;
16167 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16168 + nbr = au_sbbot(sb) + 1;
16169 + if (unlikely(nbr <= 0))
16171 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
16173 + au_ninodes_inc(sb);
16175 + iinfo->ii_hinode = hi;
16176 + for (i = 0; i < nbr; i++, hi++)
16177 + au_hinode_init(hi);
16179 + iinfo->ii_generation.ig_generation = au_sigen(sb);
16180 + iinfo->ii_btop = -1;
16181 + iinfo->ii_bbot = -1;
16182 + iinfo->ii_vdir = NULL;
16188 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16191 + struct au_hinode *hip;
16193 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16196 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16199 + iinfo->ii_hinode = hip;
16200 + i = iinfo->ii_bbot + 1;
16202 + for (; i < nbr; i++, hip++)
16203 + au_hinode_init(hip);
16210 +void au_iinfo_fin(struct inode *inode)
16212 + struct au_iinfo *iinfo;
16213 + struct au_hinode *hi;
16214 + struct super_block *sb;
16215 + aufs_bindex_t bindex, bbot;
16216 + const unsigned char unlinked = !inode->i_nlink;
16218 + AuDebugOn(au_is_bad_inode(inode));
16220 + sb = inode->i_sb;
16221 + au_ninodes_dec(sb);
16222 + if (si_pid_test(sb))
16223 + au_xino_delete_inode(inode, unlinked);
16226 + * it is safe to hide the dependency between sbinfo and
16230 + si_noflush_read_lock(sb);
16231 + au_xino_delete_inode(inode, unlinked);
16232 + si_read_unlock(sb);
16236 + iinfo = au_ii(inode);
16237 + if (iinfo->ii_vdir)
16238 + au_vdir_free(iinfo->ii_vdir);
16240 + bindex = iinfo->ii_btop;
16241 + if (bindex >= 0) {
16242 + hi = au_hinode(iinfo, bindex);
16243 + bbot = iinfo->ii_bbot;
16244 + while (bindex++ <= bbot) {
16245 + if (hi->hi_inode)
16250 + kfree(iinfo->ii_hinode);
16251 + AuRwDestroy(&iinfo->ii_rwsem);
16253 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16254 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16255 +++ linux/fs/aufs/inode.c 2017-07-29 12:14:25.903042072 +0200
16258 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16260 + * This program, aufs is free software; you can redistribute it and/or modify
16261 + * it under the terms of the GNU General Public License as published by
16262 + * the Free Software Foundation; either version 2 of the License, or
16263 + * (at your option) any later version.
16265 + * This program is distributed in the hope that it will be useful,
16266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16268 + * GNU General Public License for more details.
16270 + * You should have received a copy of the GNU General Public License
16271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16275 + * inode functions
16280 +struct inode *au_igrab(struct inode *inode)
16283 + AuDebugOn(!atomic_read(&inode->i_count));
16289 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16291 + au_cpup_attr_all(inode, /*force*/0);
16292 + au_update_iigen(inode, /*half*/1);
16294 + inode->i_version++;
16297 +static int au_ii_refresh(struct inode *inode, int *update)
16301 + aufs_bindex_t bindex, new_bindex;
16302 + struct super_block *sb;
16303 + struct au_iinfo *iinfo;
16304 + struct au_hinode *p, *q, tmp;
16306 + AuDebugOn(au_is_bad_inode(inode));
16307 + IiMustWriteLock(inode);
16310 + sb = inode->i_sb;
16311 + nbr = au_sbbot(sb) + 1;
16312 + type = inode->i_mode & S_IFMT;
16313 + iinfo = au_ii(inode);
16314 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16315 + if (unlikely(err))
16318 + AuDebugOn(iinfo->ii_btop < 0);
16319 + p = au_hinode(iinfo, iinfo->ii_btop);
16320 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16322 + if (!p->hi_inode)
16325 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16326 + new_bindex = au_br_index(sb, p->hi_id);
16327 + if (new_bindex == bindex)
16330 + if (new_bindex < 0) {
16333 + p->hi_inode = NULL;
16337 + if (new_bindex < iinfo->ii_btop)
16338 + iinfo->ii_btop = new_bindex;
16339 + if (iinfo->ii_bbot < new_bindex)
16340 + iinfo->ii_bbot = new_bindex;
16341 + /* swap two lower inode, and loop again */
16342 + q = au_hinode(iinfo, new_bindex);
16346 + if (tmp.hi_inode) {
16351 + au_update_ibrange(inode, /*do_put_zero*/0);
16352 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16353 + e = au_dy_irefresh(inode);
16354 + if (unlikely(e && !err))
16362 +void au_refresh_iop(struct inode *inode, int force_getattr)
16365 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16366 + const struct inode_operations *iop
16367 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16369 + if (inode->i_op == iop)
16372 + switch (inode->i_mode & S_IFMT) {
16374 + type = AuIop_DIR;
16377 + type = AuIop_SYMLINK;
16380 + type = AuIop_OTHER;
16384 + inode->i_op = iop + type;
16385 + /* unnecessary smp_wmb() */
16388 +int au_refresh_hinode_self(struct inode *inode)
16392 + err = au_ii_refresh(inode, &update);
16394 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16400 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16402 + int err, e, update;
16403 + unsigned int flags;
16405 + aufs_bindex_t bindex, bbot;
16406 + unsigned char isdir;
16407 + struct au_hinode *p;
16408 + struct au_iinfo *iinfo;
16410 + err = au_ii_refresh(inode, &update);
16411 + if (unlikely(err))
16415 + iinfo = au_ii(inode);
16416 + p = au_hinode(iinfo, iinfo->ii_btop);
16417 + mode = (inode->i_mode & S_IFMT);
16418 + isdir = S_ISDIR(mode);
16419 + flags = au_hi_flags(inode, isdir);
16420 + bbot = au_dbbot(dentry);
16421 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16422 + struct inode *h_i, *h_inode;
16423 + struct dentry *h_d;
16425 + h_d = au_h_dptr(dentry, bindex);
16426 + if (!h_d || d_is_negative(h_d))
16429 + h_inode = d_inode(h_d);
16430 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16431 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16432 + h_i = au_h_iptr(inode, bindex);
16434 + if (h_i == h_inode)
16440 + if (bindex < iinfo->ii_btop)
16441 + iinfo->ii_btop = bindex;
16442 + if (iinfo->ii_bbot < bindex)
16443 + iinfo->ii_bbot = bindex;
16444 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16447 + au_update_ibrange(inode, /*do_put_zero*/0);
16448 + e = au_dy_irefresh(inode);
16449 + if (unlikely(e && !err))
16452 + au_refresh_hinode_attr(inode, update && isdir);
16459 +static int set_inode(struct inode *inode, struct dentry *dentry)
16462 + unsigned int flags;
16464 + aufs_bindex_t bindex, btop, btail;
16465 + unsigned char isdir;
16466 + struct dentry *h_dentry;
16467 + struct inode *h_inode;
16468 + struct au_iinfo *iinfo;
16469 + struct inode_operations *iop;
16471 + IiMustWriteLock(inode);
16475 + iop = au_sbi(inode->i_sb)->si_iop_array;
16476 + btop = au_dbtop(dentry);
16477 + h_dentry = au_h_dptr(dentry, btop);
16478 + h_inode = d_inode(h_dentry);
16479 + mode = h_inode->i_mode;
16480 + switch (mode & S_IFMT) {
16482 + btail = au_dbtail(dentry);
16483 + inode->i_op = iop + AuIop_OTHER;
16484 + inode->i_fop = &aufs_file_fop;
16485 + err = au_dy_iaop(inode, btop, h_inode);
16486 + if (unlikely(err))
16491 + btail = au_dbtaildir(dentry);
16492 + inode->i_op = iop + AuIop_DIR;
16493 + inode->i_fop = &aufs_dir_fop;
16496 + btail = au_dbtail(dentry);
16497 + inode->i_op = iop + AuIop_SYMLINK;
16503 + btail = au_dbtail(dentry);
16504 + inode->i_op = iop + AuIop_OTHER;
16505 + init_special_inode(inode, mode, h_inode->i_rdev);
16508 + AuIOErr("Unknown file type 0%o\n", mode);
16513 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16514 + flags = au_hi_flags(inode, isdir);
16515 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16516 + && au_ftest_hi(flags, HNOTIFY)
16517 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16518 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16519 + au_fclr_hi(flags, HNOTIFY);
16520 + iinfo = au_ii(inode);
16521 + iinfo->ii_btop = btop;
16522 + iinfo->ii_bbot = btail;
16523 + for (bindex = btop; bindex <= btail; bindex++) {
16524 + h_dentry = au_h_dptr(dentry, bindex);
16526 + au_set_h_iptr(inode, bindex,
16527 + au_igrab(d_inode(h_dentry)), flags);
16529 + au_cpup_attr_all(inode, /*force*/1);
16531 + * to force calling aufs_get_acl() every time,
16532 + * do not call cache_no_acl() for aufs inode.
16540 + * successful returns with iinfo write_locked
16542 + * zero: success, matched
16543 + * plus: no error, but unmatched
16545 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16548 + unsigned int gen, igflags;
16549 + aufs_bindex_t bindex, bbot;
16550 + struct inode *h_inode, *h_dinode;
16551 + struct dentry *h_dentry;
16554 + * before this function, if aufs got any iinfo lock, it must be only
16555 + * one, the parent dir.
16556 + * it can happen by UDBA and the obsoleted inode number.
16559 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16563 + ii_write_lock_new_child(inode);
16564 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16565 + h_dinode = d_inode(h_dentry);
16566 + bbot = au_ibbot(inode);
16567 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16568 + h_inode = au_h_iptr(inode, bindex);
16569 + if (!h_inode || h_inode != h_dinode)
16573 + gen = au_iigen(inode, &igflags);
16574 + if (gen == au_digen(dentry)
16575 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16578 + /* fully refresh inode using dentry */
16579 + err = au_refresh_hinode(inode, dentry);
16581 + au_update_iigen(inode, /*half*/0);
16585 + if (unlikely(err))
16586 + ii_write_unlock(inode);
16591 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16592 + unsigned int d_type, ino_t *ino)
16595 + const int isnondir = d_type != DT_DIR;
16597 + /* prevent hardlinked inode number from race condition */
16599 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
16600 + if (unlikely(err))
16604 + err = au_xino_read(sb, bindex, h_ino, ino);
16605 + if (unlikely(err))
16606 + goto out_xinondir;
16610 + *ino = au_xino_new_ino(sb);
16611 + if (unlikely(!*ino))
16612 + goto out_xinondir;
16613 + err = au_xino_write(sb, bindex, h_ino, *ino);
16614 + if (unlikely(err))
16615 + goto out_xinondir;
16619 + if (isnondir && idx >= 0)
16620 + au_xinondir_leave(sb, bindex, h_ino, idx);
16625 +/* successful returns with iinfo write_locked */
16626 +/* todo: return with unlocked? */
16627 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16629 + struct inode *inode, *h_inode;
16630 + struct dentry *h_dentry;
16631 + struct super_block *sb;
16632 + ino_t h_ino, ino;
16633 + int err, idx, hlinked;
16634 + aufs_bindex_t btop;
16636 + sb = dentry->d_sb;
16637 + btop = au_dbtop(dentry);
16638 + h_dentry = au_h_dptr(dentry, btop);
16639 + h_inode = d_inode(h_dentry);
16640 + h_ino = h_inode->i_ino;
16641 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
16645 + * stop 'race'-ing between hardlinks under different
16649 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16650 + inode = ERR_PTR(err);
16651 + if (unlikely(err))
16655 + err = au_xino_read(sb, btop, h_ino, &ino);
16656 + inode = ERR_PTR(err);
16657 + if (unlikely(err))
16658 + goto out_xinondir;
16661 + ino = au_xino_new_ino(sb);
16662 + if (unlikely(!ino)) {
16663 + inode = ERR_PTR(-EIO);
16664 + goto out_xinondir;
16668 + AuDbg("i%lu\n", (unsigned long)ino);
16669 + inode = au_iget_locked(sb, ino);
16670 + err = PTR_ERR(inode);
16671 + if (IS_ERR(inode))
16672 + goto out_xinondir;
16674 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16675 + if (inode->i_state & I_NEW) {
16676 + ii_write_lock_new_child(inode);
16677 + err = set_inode(inode, dentry);
16679 + unlock_new_inode(inode);
16680 + goto out_xinondir; /* success */
16684 + * iget_failed() calls iput(), but we need to call
16685 + * ii_write_unlock() after iget_failed(). so dirty hack for
16688 + atomic_inc(&inode->i_count);
16689 + iget_failed(inode);
16690 + ii_write_unlock(inode);
16691 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16692 + /* ignore this error */
16694 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16696 + * horrible race condition between lookup, readdir and copyup
16697 + * (or something).
16699 + if (hlinked && idx >= 0)
16700 + au_xinondir_leave(sb, btop, h_ino, idx);
16701 + err = reval_inode(inode, dentry);
16702 + if (unlikely(err < 0)) {
16707 + goto out; /* success */
16708 + else if (hlinked && idx >= 0) {
16709 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
16710 + if (unlikely(err)) {
16712 + inode = ERR_PTR(err);
16718 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16719 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16720 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16721 + btop, au_sbtype(h_dentry->d_sb), dentry,
16722 + (unsigned long)h_ino, (unsigned long)ino);
16724 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16727 + if (hlinked && idx >= 0)
16728 + au_xinondir_leave(sb, btop, h_ino, idx);
16734 + inode = ERR_PTR(err);
16736 + if (hlinked && idx >= 0)
16737 + au_xinondir_leave(sb, btop, h_ino, idx);
16742 +/* ---------------------------------------------------------------------- */
16744 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16745 + struct inode *inode)
16748 + struct inode *hi;
16750 + err = au_br_rdonly(au_sbr(sb, bindex));
16752 + /* pseudo-link after flushed may happen out of bounds */
16755 + && au_ibtop(inode) <= bindex
16756 + && bindex <= au_ibbot(inode)) {
16758 + * permission check is unnecessary since vfsub routine
16759 + * will be called later
16761 + hi = au_h_iptr(inode, bindex);
16763 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16769 +int au_test_h_perm(struct inode *h_inode, int mask)
16771 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16773 + return inode_permission(h_inode, mask);
16776 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16778 + if (au_test_nfs(h_inode->i_sb)
16779 + && (mask & MAY_WRITE)
16780 + && S_ISDIR(h_inode->i_mode))
16781 + mask |= MAY_READ; /* force permission check */
16782 + return au_test_h_perm(h_inode, mask);
16784 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16785 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16786 +++ linux/fs/aufs/inode.h 2017-07-29 12:14:25.903042072 +0200
16789 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16791 + * This program, aufs is free software; you can redistribute it and/or modify
16792 + * it under the terms of the GNU General Public License as published by
16793 + * the Free Software Foundation; either version 2 of the License, or
16794 + * (at your option) any later version.
16796 + * This program is distributed in the hope that it will be useful,
16797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16799 + * GNU General Public License for more details.
16801 + * You should have received a copy of the GNU General Public License
16802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16806 + * inode operations
16809 +#ifndef __AUFS_INODE_H__
16810 +#define __AUFS_INODE_H__
16814 +#include <linux/fsnotify.h>
16815 +#include "rwsem.h"
16819 +struct au_hnotify {
16820 +#ifdef CONFIG_AUFS_HNOTIFY
16821 +#ifdef CONFIG_AUFS_HFSNOTIFY
16822 + /* never use fsnotify_add_vfsmount_mark() */
16823 + struct fsnotify_mark hn_mark;
16825 + struct inode *hn_aufs_inode; /* no get/put */
16827 +} ____cacheline_aligned_in_smp;
16829 +struct au_hinode {
16830 + struct inode *hi_inode;
16831 + aufs_bindex_t hi_id;
16832 +#ifdef CONFIG_AUFS_HNOTIFY
16833 + struct au_hnotify *hi_notify;
16836 + /* reference to the copied-up whiteout with get/put */
16837 + struct dentry *hi_whdentry;
16841 +#define AuIG_HALF_REFRESHED 1
16842 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16843 +#define au_ig_fset(flags, name) \
16844 + do { (flags) |= AuIG_##name; } while (0)
16845 +#define au_ig_fclr(flags, name) \
16846 + do { (flags) &= ~AuIG_##name; } while (0)
16849 + spinlock_t ig_spin;
16850 + __u32 ig_generation, ig_flags;
16855 + struct au_iigen ii_generation;
16856 + struct super_block *ii_hsb1; /* no get/put */
16858 + struct au_rwsem ii_rwsem;
16859 + aufs_bindex_t ii_btop, ii_bbot;
16861 + struct au_hinode *ii_hinode;
16862 + struct au_vdir *ii_vdir;
16865 +struct au_icntnr {
16866 + struct au_iinfo iinfo;
16867 + struct inode vfs_inode;
16868 + struct hlist_node plink;
16869 +} ____cacheline_aligned_in_smp;
16871 +/* au_pin flags */
16872 +#define AuPin_DI_LOCKED 1
16873 +#define AuPin_MNT_WRITE (1 << 1)
16874 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16875 +#define au_fset_pin(flags, name) \
16876 + do { (flags) |= AuPin_##name; } while (0)
16877 +#define au_fclr_pin(flags, name) \
16878 + do { (flags) &= ~AuPin_##name; } while (0)
16882 + struct dentry *dentry;
16883 + unsigned int udba;
16884 + unsigned char lsc_di, lsc_hi, flags;
16885 + aufs_bindex_t bindex;
16888 + struct dentry *parent;
16889 + struct au_hinode *hdir;
16890 + struct vfsmount *h_mnt;
16892 + /* temporary unlock/relock for copyup */
16893 + struct dentry *h_dentry, *h_parent;
16894 + struct au_branch *br;
16895 + struct task_struct *task;
16898 +void au_pin_hdir_unlock(struct au_pin *p);
16899 +int au_pin_hdir_lock(struct au_pin *p);
16900 +int au_pin_hdir_relock(struct au_pin *p);
16901 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16902 +void au_pin_hdir_release(struct au_pin *p);
16904 +/* ---------------------------------------------------------------------- */
16906 +static inline struct au_iinfo *au_ii(struct inode *inode)
16908 + BUG_ON(is_bad_inode(inode));
16909 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16912 +/* ---------------------------------------------------------------------- */
16915 +struct inode *au_igrab(struct inode *inode);
16916 +void au_refresh_iop(struct inode *inode, int force_getattr);
16917 +int au_refresh_hinode_self(struct inode *inode);
16918 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16919 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16920 + unsigned int d_type, ino_t *ino);
16921 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16922 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16923 + struct inode *inode);
16924 +int au_test_h_perm(struct inode *h_inode, int mask);
16925 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16927 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16928 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16930 +#ifdef CONFIG_AUFS_SHWH
16931 + return au_ino(sb, bindex, h_ino, d_type, ino);
16944 +extern struct inode_operations aufs_iop[AuIop_Last],
16945 + aufs_iop_nogetattr[AuIop_Last];
16947 +/* au_wr_dir flags */
16948 +#define AuWrDir_ADD_ENTRY 1
16949 +#define AuWrDir_ISDIR (1 << 1)
16950 +#define AuWrDir_TMPFILE (1 << 2)
16951 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16952 +#define au_fset_wrdir(flags, name) \
16953 + do { (flags) |= AuWrDir_##name; } while (0)
16954 +#define au_fclr_wrdir(flags, name) \
16955 + do { (flags) &= ~AuWrDir_##name; } while (0)
16957 +struct au_wr_dir_args {
16958 + aufs_bindex_t force_btgt;
16959 + unsigned char flags;
16961 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16962 + struct au_wr_dir_args *args);
16964 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16965 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16966 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16967 + unsigned int udba, unsigned char flags);
16968 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16969 + unsigned int udba, unsigned char flags) __must_check;
16970 +int au_do_pin(struct au_pin *pin) __must_check;
16971 +void au_unpin(struct au_pin *pin);
16972 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16974 +#define AuIcpup_DID_CPUP 1
16975 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16976 +#define au_fset_icpup(flags, name) \
16977 + do { (flags) |= AuIcpup_##name; } while (0)
16978 +#define au_fclr_icpup(flags, name) \
16979 + do { (flags) &= ~AuIcpup_##name; } while (0)
16981 +struct au_icpup_args {
16982 + unsigned char flags;
16983 + unsigned char pin_flags;
16984 + aufs_bindex_t btgt;
16985 + unsigned int udba;
16986 + struct au_pin pin;
16987 + struct path h_path;
16988 + struct inode *h_inode;
16991 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16992 + struct au_icpup_args *a);
16994 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
16998 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16999 + struct dentry *h_parent, int isdir);
17000 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17002 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
17003 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17005 +struct vfsub_aopen_args;
17006 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17007 + struct vfsub_aopen_args *args);
17008 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
17009 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17010 + struct dentry *dentry);
17011 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
17014 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
17015 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17016 + struct dentry *h_parent, int isdir);
17017 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
17018 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
17021 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
17022 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
17023 + struct inode *dir, struct dentry *dentry,
17024 + unsigned int flags);
17027 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
17028 +void au_hiput(struct au_hinode *hinode);
17029 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17030 + struct dentry *h_wh);
17031 +unsigned int au_hi_flags(struct inode *inode, int isdir);
17033 +/* hinode flags */
17034 +#define AuHi_XINO 1
17035 +#define AuHi_HNOTIFY (1 << 1)
17036 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
17037 +#define au_fset_hi(flags, name) \
17038 + do { (flags) |= AuHi_##name; } while (0)
17039 +#define au_fclr_hi(flags, name) \
17040 + do { (flags) &= ~AuHi_##name; } while (0)
17042 +#ifndef CONFIG_AUFS_HNOTIFY
17043 +#undef AuHi_HNOTIFY
17044 +#define AuHi_HNOTIFY 0
17047 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17048 + struct inode *h_inode, unsigned int flags);
17050 +void au_update_iigen(struct inode *inode, int half);
17051 +void au_update_ibrange(struct inode *inode, int do_put_zero);
17053 +void au_icntnr_init_once(void *_c);
17054 +void au_hinode_init(struct au_hinode *hinode);
17055 +int au_iinfo_init(struct inode *inode);
17056 +void au_iinfo_fin(struct inode *inode);
17057 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
17059 +#ifdef CONFIG_PROC_FS
17061 +int au_plink_maint(struct super_block *sb, int flags);
17063 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
17064 +int au_plink_maint_enter(struct super_block *sb);
17065 +#ifdef CONFIG_AUFS_DEBUG
17066 +void au_plink_list(struct super_block *sb);
17068 +AuStubVoid(au_plink_list, struct super_block *sb)
17070 +int au_plink_test(struct inode *inode);
17071 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
17072 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
17073 + struct dentry *h_dentry);
17074 +void au_plink_put(struct super_block *sb, int verbose);
17075 +void au_plink_clean(struct super_block *sb, int verbose);
17076 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
17078 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
17079 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
17080 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
17081 +AuStubVoid(au_plink_list, struct super_block *sb);
17082 +AuStubInt0(au_plink_test, struct inode *inode);
17083 +AuStub(struct dentry *, au_plink_lkup, return NULL,
17084 + struct inode *inode, aufs_bindex_t bindex);
17085 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
17086 + struct dentry *h_dentry);
17087 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
17088 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
17089 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
17090 +#endif /* CONFIG_PROC_FS */
17092 +#ifdef CONFIG_AUFS_XATTR
17094 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
17095 + unsigned int verbose);
17096 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
17097 +void au_xattr_init(struct super_block *sb);
17099 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
17100 + int ignore_flags, unsigned int verbose);
17101 +AuStubVoid(au_xattr_init, struct super_block *sb);
17104 +#ifdef CONFIG_FS_POSIX_ACL
17105 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
17106 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
17109 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
17115 +struct au_sxattr {
17119 + const char *name;
17120 + const void *value;
17125 + struct posix_acl *acl;
17130 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
17131 + struct au_sxattr *arg);
17134 +/* ---------------------------------------------------------------------- */
17136 +/* lock subclass for iinfo */
17138 + AuLsc_II_CHILD, /* child first */
17139 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
17140 + AuLsc_II_CHILD3, /* copyup dirs */
17141 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
17142 + AuLsc_II_PARENT2,
17143 + AuLsc_II_PARENT3, /* copyup dirs */
17144 + AuLsc_II_NEW_CHILD
17148 + * ii_read_lock_child, ii_write_lock_child,
17149 + * ii_read_lock_child2, ii_write_lock_child2,
17150 + * ii_read_lock_child3, ii_write_lock_child3,
17151 + * ii_read_lock_parent, ii_write_lock_parent,
17152 + * ii_read_lock_parent2, ii_write_lock_parent2,
17153 + * ii_read_lock_parent3, ii_write_lock_parent3,
17154 + * ii_read_lock_new_child, ii_write_lock_new_child,
17156 +#define AuReadLockFunc(name, lsc) \
17157 +static inline void ii_read_lock_##name(struct inode *i) \
17159 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17162 +#define AuWriteLockFunc(name, lsc) \
17163 +static inline void ii_write_lock_##name(struct inode *i) \
17165 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17168 +#define AuRWLockFuncs(name, lsc) \
17169 + AuReadLockFunc(name, lsc) \
17170 + AuWriteLockFunc(name, lsc)
17172 +AuRWLockFuncs(child, CHILD);
17173 +AuRWLockFuncs(child2, CHILD2);
17174 +AuRWLockFuncs(child3, CHILD3);
17175 +AuRWLockFuncs(parent, PARENT);
17176 +AuRWLockFuncs(parent2, PARENT2);
17177 +AuRWLockFuncs(parent3, PARENT3);
17178 +AuRWLockFuncs(new_child, NEW_CHILD);
17180 +#undef AuReadLockFunc
17181 +#undef AuWriteLockFunc
17182 +#undef AuRWLockFuncs
17185 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17187 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17189 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17190 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17191 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17193 +/* ---------------------------------------------------------------------- */
17195 +static inline void au_icntnr_init(struct au_icntnr *c)
17197 +#ifdef CONFIG_AUFS_DEBUG
17198 + c->vfs_inode.i_mode = 0;
17202 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17204 + unsigned int gen;
17205 + struct au_iinfo *iinfo;
17206 + struct au_iigen *iigen;
17208 + iinfo = au_ii(inode);
17209 + iigen = &iinfo->ii_generation;
17210 + spin_lock(&iigen->ig_spin);
17212 + *igflags = iigen->ig_flags;
17213 + gen = iigen->ig_generation;
17214 + spin_unlock(&iigen->ig_spin);
17219 +/* tiny test for inode number */
17220 +/* tmpfs generation is too rough */
17221 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17223 + struct au_iinfo *iinfo;
17225 + iinfo = au_ii(inode);
17226 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17227 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17228 + && iinfo->ii_higen == h_inode->i_generation);
17231 +static inline void au_iigen_dec(struct inode *inode)
17233 + struct au_iinfo *iinfo;
17234 + struct au_iigen *iigen;
17236 + iinfo = au_ii(inode);
17237 + iigen = &iinfo->ii_generation;
17238 + spin_lock(&iigen->ig_spin);
17239 + iigen->ig_generation--;
17240 + spin_unlock(&iigen->ig_spin);
17243 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17248 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17254 +/* ---------------------------------------------------------------------- */
17256 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17257 + aufs_bindex_t bindex)
17259 + return iinfo->ii_hinode + bindex;
17262 +static inline int au_is_bad_inode(struct inode *inode)
17264 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17267 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17268 + aufs_bindex_t bindex)
17270 + IiMustAnyLock(inode);
17271 + return au_hinode(au_ii(inode), bindex)->hi_id;
17274 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17276 + IiMustAnyLock(inode);
17277 + return au_ii(inode)->ii_btop;
17280 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17282 + IiMustAnyLock(inode);
17283 + return au_ii(inode)->ii_bbot;
17286 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17288 + IiMustAnyLock(inode);
17289 + return au_ii(inode)->ii_vdir;
17292 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17294 + IiMustAnyLock(inode);
17295 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17298 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17300 + IiMustWriteLock(inode);
17301 + au_ii(inode)->ii_btop = bindex;
17304 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17306 + IiMustWriteLock(inode);
17307 + au_ii(inode)->ii_bbot = bindex;
17310 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17312 + IiMustWriteLock(inode);
17313 + au_ii(inode)->ii_vdir = vdir;
17316 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17318 + IiMustAnyLock(inode);
17319 + return au_hinode(au_ii(inode), bindex);
17322 +/* ---------------------------------------------------------------------- */
17324 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17327 + return pin->parent;
17331 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17333 + if (pin && pin->hdir)
17334 + return pin->hdir->hi_inode;
17338 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17341 + return pin->hdir;
17345 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17348 + pin->dentry = dentry;
17351 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17352 + unsigned char lflag)
17356 + au_fset_pin(pin->flags, DI_LOCKED);
17358 + au_fclr_pin(pin->flags, DI_LOCKED);
17362 +#if 0 /* reserved */
17363 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17366 + dput(pin->parent);
17367 + pin->parent = dget(parent);
17372 +/* ---------------------------------------------------------------------- */
17375 +#ifdef CONFIG_AUFS_HNOTIFY
17376 +struct au_hnotify_op {
17377 + void (*ctl)(struct au_hinode *hinode, int do_set);
17378 + int (*alloc)(struct au_hinode *hinode);
17381 + * if it returns true, the the caller should free hinode->hi_notify,
17382 + * otherwise ->free() frees it.
17384 + int (*free)(struct au_hinode *hinode,
17385 + struct au_hnotify *hn) __must_check;
17387 + void (*fin)(void);
17388 + int (*init)(void);
17390 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17391 + void (*fin_br)(struct au_branch *br);
17392 + int (*init_br)(struct au_branch *br, int perm);
17396 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17397 +void au_hn_free(struct au_hinode *hinode);
17398 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17399 +void au_hn_reset(struct inode *inode, unsigned int flags);
17400 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17401 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17402 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17403 +int au_hnotify_init_br(struct au_branch *br, int perm);
17404 +void au_hnotify_fin_br(struct au_branch *br);
17405 +int __init au_hnotify_init(void);
17406 +void au_hnotify_fin(void);
17409 +extern const struct au_hnotify_op au_hnotify_op;
17412 +void au_hn_init(struct au_hinode *hinode)
17414 + hinode->hi_notify = NULL;
17417 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17419 + return hinode->hi_notify;
17423 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17424 + struct au_hinode *hinode __maybe_unused,
17425 + struct inode *inode __maybe_unused)
17426 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17427 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17428 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17429 + int do_set __maybe_unused)
17430 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17431 + unsigned int flags __maybe_unused)
17432 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17433 + struct au_branch *br __maybe_unused,
17434 + int perm __maybe_unused)
17435 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17436 + int perm __maybe_unused)
17437 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17438 +AuStubInt0(__init au_hnotify_init, void)
17439 +AuStubVoid(au_hnotify_fin, void)
17440 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17441 +#endif /* CONFIG_AUFS_HNOTIFY */
17443 +static inline void au_hn_suspend(struct au_hinode *hdir)
17445 + au_hn_ctl(hdir, /*do_set*/0);
17448 +static inline void au_hn_resume(struct au_hinode *hdir)
17450 + au_hn_ctl(hdir, /*do_set*/1);
17453 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17455 + inode_lock(hdir->hi_inode);
17456 + au_hn_suspend(hdir);
17459 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17460 + unsigned int sc __maybe_unused)
17462 + inode_lock_nested(hdir->hi_inode, sc);
17463 + au_hn_suspend(hdir);
17466 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17468 + au_hn_resume(hdir);
17469 + inode_unlock(hdir->hi_inode);
17472 +#endif /* __KERNEL__ */
17473 +#endif /* __AUFS_INODE_H__ */
17474 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17475 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17476 +++ linux/fs/aufs/ioctl.c 2017-07-29 12:14:25.903042072 +0200
17479 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17481 + * This program, aufs is free software; you can redistribute it and/or modify
17482 + * it under the terms of the GNU General Public License as published by
17483 + * the Free Software Foundation; either version 2 of the License, or
17484 + * (at your option) any later version.
17486 + * This program is distributed in the hope that it will be useful,
17487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17489 + * GNU General Public License for more details.
17491 + * You should have received a copy of the GNU General Public License
17492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17497 + * plink-management and readdir in userspace.
17498 + * assist the pathconf(3) wrapper library.
17500 + * File-based Hierarchical Storage Management.
17503 +#include <linux/compat.h>
17504 +#include <linux/file.h>
17507 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17510 + aufs_bindex_t wbi, bindex, bbot;
17511 + struct file *h_file;
17512 + struct super_block *sb;
17513 + struct dentry *root;
17514 + struct au_branch *br;
17515 + struct aufs_wbr_fd wbrfd = {
17516 + .oflags = au_dir_roflags,
17519 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17520 + | O_NOATIME | O_CLOEXEC;
17522 + AuDebugOn(wbrfd.oflags & ~valid);
17525 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17526 + if (unlikely(err)) {
17532 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17533 + wbrfd.oflags |= au_dir_roflags;
17534 + AuDbg("0%o\n", wbrfd.oflags);
17535 + if (unlikely(wbrfd.oflags & ~valid))
17539 + fd = get_unused_fd_flags(0);
17541 + if (unlikely(fd < 0))
17544 + h_file = ERR_PTR(-EINVAL);
17547 + sb = path->dentry->d_sb;
17548 + root = sb->s_root;
17549 + aufs_read_lock(root, AuLock_IR);
17550 + bbot = au_sbbot(sb);
17551 + if (wbrfd.brid >= 0) {
17552 + wbi = au_br_index(sb, wbrfd.brid);
17553 + if (unlikely(wbi < 0 || wbi > bbot))
17557 + h_file = ERR_PTR(-ENOENT);
17558 + br = au_sbr(sb, wbi);
17559 + if (!au_br_writable(br->br_perm)) {
17563 + bindex = wbi + 1;
17565 + for (; bindex <= bbot; bindex++) {
17566 + br = au_sbr(sb, bindex);
17567 + if (au_br_writable(br->br_perm)) {
17569 + br = au_sbr(sb, wbi);
17574 + AuDbg("wbi %d\n", wbi);
17576 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17580 + aufs_read_unlock(root, AuLock_IR);
17581 + err = PTR_ERR(h_file);
17582 + if (IS_ERR(h_file))
17585 + au_br_put(br); /* cf. au_h_open() */
17586 + fd_install(fd, h_file);
17588 + goto out; /* success */
17591 + put_unused_fd(fd);
17597 +/* ---------------------------------------------------------------------- */
17599 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17602 + struct dentry *dentry;
17605 + case AUFS_CTL_RDU:
17606 + case AUFS_CTL_RDU_INO:
17607 + err = au_rdu_ioctl(file, cmd, arg);
17610 + case AUFS_CTL_WBR_FD:
17611 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17614 + case AUFS_CTL_IBUSY:
17615 + err = au_ibusy_ioctl(file, arg);
17618 + case AUFS_CTL_BRINFO:
17619 + err = au_brinfo_ioctl(file, arg);
17622 + case AUFS_CTL_FHSM_FD:
17623 + dentry = file->f_path.dentry;
17624 + if (IS_ROOT(dentry))
17625 + err = au_fhsm_fd(dentry->d_sb, arg);
17631 + /* do not call the lower */
17632 + AuDbg("0x%x\n", cmd);
17640 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17645 + case AUFS_CTL_MVDOWN:
17646 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17649 + case AUFS_CTL_WBR_FD:
17650 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17654 + /* do not call the lower */
17655 + AuDbg("0x%x\n", cmd);
17663 +#ifdef CONFIG_COMPAT
17664 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17665 + unsigned long arg)
17670 + case AUFS_CTL_RDU:
17671 + case AUFS_CTL_RDU_INO:
17672 + err = au_rdu_compat_ioctl(file, cmd, arg);
17675 + case AUFS_CTL_IBUSY:
17676 + err = au_ibusy_compat_ioctl(file, arg);
17679 + case AUFS_CTL_BRINFO:
17680 + err = au_brinfo_compat_ioctl(file, arg);
17684 + err = aufs_ioctl_dir(file, cmd, arg);
17691 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17692 + unsigned long arg)
17694 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17697 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17698 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17699 +++ linux/fs/aufs/i_op_add.c 2017-07-29 12:14:25.903042072 +0200
17702 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17704 + * This program, aufs is free software; you can redistribute it and/or modify
17705 + * it under the terms of the GNU General Public License as published by
17706 + * the Free Software Foundation; either version 2 of the License, or
17707 + * (at your option) any later version.
17709 + * This program is distributed in the hope that it will be useful,
17710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17712 + * GNU General Public License for more details.
17714 + * You should have received a copy of the GNU General Public License
17715 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17719 + * inode operations (add entry)
17725 + * final procedure of adding a new entry, except link(2).
17726 + * remove whiteout, instantiate, copyup the parent dir's times and size
17727 + * and update version.
17728 + * if it failed, re-create the removed whiteout.
17730 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17731 + struct dentry *wh_dentry, struct dentry *dentry)
17734 + aufs_bindex_t bwh;
17735 + struct path h_path;
17736 + struct super_block *sb;
17737 + struct inode *inode, *h_dir;
17738 + struct dentry *wh;
17743 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17744 + IMustLock(h_dir);
17745 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17746 + bwh = au_dbwh(dentry);
17747 + h_path.dentry = wh_dentry;
17748 + h_path.mnt = au_sbr_mnt(sb, bindex);
17749 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17751 + if (unlikely(err))
17755 + inode = au_new_inode(dentry, /*must_new*/1);
17756 + if (!IS_ERR(inode)) {
17757 + d_instantiate(dentry, inode);
17758 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17760 + au_dir_ts(dir, bindex);
17761 + dir->i_version++;
17762 + au_fhsm_wrote(sb, bindex, /*force*/0);
17763 + return 0; /* success */
17766 + err = PTR_ERR(inode);
17771 + /* dir inode is locked */
17772 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17773 + rerr = PTR_ERR(wh);
17774 + if (IS_ERR(wh)) {
17775 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17776 + dentry, err, rerr);
17785 +static int au_d_may_add(struct dentry *dentry)
17790 + if (unlikely(d_unhashed(dentry)))
17792 + if (unlikely(d_really_is_positive(dentry)))
17798 + * simple tests for the adding inode operations.
17799 + * following the checks in vfs, plus the parent-child relationship.
17801 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17802 + struct dentry *h_parent, int isdir)
17806 + struct dentry *h_dentry;
17807 + struct inode *h_inode;
17809 + err = -ENAMETOOLONG;
17810 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17813 + h_dentry = au_h_dptr(dentry, bindex);
17814 + if (d_really_is_negative(dentry)) {
17816 + if (unlikely(d_is_positive(h_dentry)))
17819 + /* rename(2) case */
17821 + if (unlikely(d_is_negative(h_dentry)))
17823 + h_inode = d_inode(h_dentry);
17824 + if (unlikely(!h_inode->i_nlink))
17827 + h_mode = h_inode->i_mode;
17830 + if (unlikely(S_ISDIR(h_mode)))
17832 + } else if (unlikely(!S_ISDIR(h_mode))) {
17839 + /* expected parent dir is locked */
17840 + if (unlikely(h_parent != h_dentry->d_parent))
17849 + * initial procedure of adding a new entry.
17850 + * prepare writable branch and the parent dir, lock it,
17851 + * and lookup whiteout for the new entry.
17853 +static struct dentry*
17854 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17855 + struct dentry *src_dentry, struct au_pin *pin,
17856 + struct au_wr_dir_args *wr_dir_args)
17858 + struct dentry *wh_dentry, *h_parent;
17859 + struct super_block *sb;
17860 + struct au_branch *br;
17862 + unsigned int udba;
17863 + aufs_bindex_t bcpup;
17865 + AuDbg("%pd\n", dentry);
17867 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17869 + wh_dentry = ERR_PTR(err);
17870 + if (unlikely(err < 0))
17873 + sb = dentry->d_sb;
17874 + udba = au_opt_udba(sb);
17875 + err = au_pin(pin, dentry, bcpup, udba,
17876 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17877 + wh_dentry = ERR_PTR(err);
17878 + if (unlikely(err))
17881 + h_parent = au_pinned_h_parent(pin);
17882 + if (udba != AuOpt_UDBA_NONE
17883 + && au_dbtop(dentry) == bcpup)
17884 + err = au_may_add(dentry, bcpup, h_parent,
17885 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17886 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17887 + err = -ENAMETOOLONG;
17888 + wh_dentry = ERR_PTR(err);
17889 + if (unlikely(err))
17892 + br = au_sbr(sb, bcpup);
17894 + struct path tmp = {
17895 + .dentry = h_parent,
17896 + .mnt = au_br_mnt(br)
17898 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17901 + wh_dentry = NULL;
17902 + if (bcpup != au_dbwh(dentry))
17903 + goto out; /* success */
17906 + * ENAMETOOLONG here means that if we allowed create such name, then it
17907 + * would not be able to removed in the future. So we don't allow such
17908 + * name here and we don't handle ENAMETOOLONG differently here.
17910 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17913 + if (IS_ERR(wh_dentry))
17916 + return wh_dentry;
17919 +/* ---------------------------------------------------------------------- */
17921 +enum { Mknod, Symlink, Creat };
17922 +struct simple_arg {
17929 + struct vfsub_aopen_args *aopen;
17932 + const char *symname;
17941 +static int add_simple(struct inode *dir, struct dentry *dentry,
17942 + struct simple_arg *arg)
17945 + aufs_bindex_t btop;
17946 + unsigned char created;
17947 + const unsigned char try_aopen
17948 + = (arg->type == Creat && arg->u.c.try_aopen);
17949 + struct dentry *wh_dentry, *parent;
17950 + struct inode *h_dir;
17951 + struct super_block *sb;
17952 + struct au_branch *br;
17953 + /* to reuduce stack size */
17955 + struct au_dtime dt;
17956 + struct au_pin pin;
17957 + struct path h_path;
17958 + struct au_wr_dir_args wr_dir_args;
17961 + AuDbg("%pd\n", dentry);
17965 + a = kmalloc(sizeof(*a), GFP_NOFS);
17966 + if (unlikely(!a))
17968 + a->wr_dir_args.force_btgt = -1;
17969 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17971 + parent = dentry->d_parent; /* dir inode is locked */
17972 + if (!try_aopen) {
17973 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17974 + if (unlikely(err))
17977 + err = au_d_may_add(dentry);
17978 + if (unlikely(err))
17981 + di_write_lock_parent(parent);
17982 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17983 + &a->pin, &a->wr_dir_args);
17984 + err = PTR_ERR(wh_dentry);
17985 + if (IS_ERR(wh_dentry))
17988 + btop = au_dbtop(dentry);
17989 + sb = dentry->d_sb;
17990 + br = au_sbr(sb, btop);
17991 + a->h_path.dentry = au_h_dptr(dentry, btop);
17992 + a->h_path.mnt = au_br_mnt(br);
17993 + h_dir = au_pinned_h_dir(&a->pin);
17994 + switch (arg->type) {
17997 + if (!try_aopen || !h_dir->i_op->atomic_open)
17998 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17999 + arg->u.c.want_excl);
18001 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
18002 + arg->u.c.aopen, br);
18005 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
18008 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
18016 + err = epilog(dir, btop, wh_dentry, dentry);
18019 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
18020 + /* no delegation since it is just created */
18021 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
18024 + AuIOErr("%pd revert failure(%d, %d)\n",
18025 + dentry, err, rerr);
18028 + au_dtime_revert(&a->dt);
18031 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
18032 + *arg->u.c.aopen->opened |= FILE_CREATED;
18034 + au_unpin(&a->pin);
18039 + di_write_unlock(parent);
18041 + if (unlikely(err)) {
18042 + au_update_dbtop(dentry);
18046 + aufs_read_unlock(dentry, AuLock_DW);
18053 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18056 + struct simple_arg arg = {
18063 + return add_simple(dir, dentry, &arg);
18066 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
18068 + struct simple_arg arg = {
18070 + .u.s.symname = symname
18072 + return add_simple(dir, dentry, &arg);
18075 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18078 + struct simple_arg arg = {
18082 + .want_excl = want_excl
18085 + return add_simple(dir, dentry, &arg);
18088 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18089 + struct vfsub_aopen_args *aopen_args)
18091 + struct simple_arg arg = {
18094 + .mode = aopen_args->create_mode,
18095 + .want_excl = aopen_args->open_flag & O_EXCL,
18096 + .try_aopen = true,
18097 + .aopen = aopen_args
18100 + return add_simple(dir, dentry, &arg);
18103 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
18106 + aufs_bindex_t bindex;
18107 + struct super_block *sb;
18108 + struct dentry *parent, *h_parent, *h_dentry;
18109 + struct inode *h_dir, *inode;
18110 + struct vfsmount *h_mnt;
18111 + struct au_wr_dir_args wr_dir_args = {
18112 + .force_btgt = -1,
18113 + .flags = AuWrDir_TMPFILE
18116 + /* copy-up may happen */
18120 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18121 + if (unlikely(err))
18124 + err = au_di_init(dentry);
18125 + if (unlikely(err))
18129 + parent = d_find_any_alias(dir);
18130 + AuDebugOn(!parent);
18131 + di_write_lock_parent(parent);
18132 + if (unlikely(d_inode(parent) != dir))
18135 + err = au_digen_test(parent, au_sigen(sb));
18136 + if (unlikely(err))
18139 + bindex = au_dbtop(parent);
18140 + au_set_dbtop(dentry, bindex);
18141 + au_set_dbbot(dentry, bindex);
18142 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18144 + if (unlikely(err < 0))
18147 + err = -EOPNOTSUPP;
18148 + h_dir = au_h_iptr(dir, bindex);
18149 + if (unlikely(!h_dir->i_op->tmpfile))
18152 + h_mnt = au_sbr_mnt(sb, bindex);
18153 + err = vfsub_mnt_want_write(h_mnt);
18154 + if (unlikely(err))
18157 + h_parent = au_h_dptr(parent, bindex);
18158 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
18159 + if (IS_ERR(h_dentry)) {
18160 + err = PTR_ERR(h_dentry);
18164 + au_set_dbtop(dentry, bindex);
18165 + au_set_dbbot(dentry, bindex);
18166 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18167 + inode = au_new_inode(dentry, /*must_new*/1);
18168 + if (IS_ERR(inode)) {
18169 + err = PTR_ERR(inode);
18170 + au_set_h_dptr(dentry, bindex, NULL);
18171 + au_set_dbtop(dentry, -1);
18172 + au_set_dbbot(dentry, -1);
18174 + if (!inode->i_nlink)
18175 + set_nlink(inode, 1);
18176 + d_tmpfile(dentry, inode);
18177 + au_di(dentry)->di_tmpfile = 1;
18179 + /* update without i_mutex */
18180 + if (au_ibtop(dir) == au_dbtop(dentry))
18181 + au_cpup_attr_timesizes(dir);
18186 + vfsub_mnt_drop_write(h_mnt);
18188 + di_write_unlock(parent);
18190 + di_write_unlock(dentry);
18191 + if (unlikely(err)) {
18192 + au_di_fin(dentry);
18193 + dentry->d_fsdata = NULL;
18196 + si_read_unlock(sb);
18198 + inode_unlock(dir);
18202 +/* ---------------------------------------------------------------------- */
18204 +struct au_link_args {
18205 + aufs_bindex_t bdst, bsrc;
18206 + struct au_pin pin;
18207 + struct path h_path;
18208 + struct dentry *src_parent, *parent;
18211 +static int au_cpup_before_link(struct dentry *src_dentry,
18212 + struct au_link_args *a)
18215 + struct dentry *h_src_dentry;
18216 + struct au_cp_generic cpg = {
18217 + .dentry = src_dentry,
18222 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18225 + di_read_lock_parent(a->src_parent, AuLock_IR);
18226 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18227 + if (unlikely(err))
18230 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18231 + err = au_pin(&a->pin, src_dentry, a->bdst,
18232 + au_opt_udba(src_dentry->d_sb),
18233 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18234 + if (unlikely(err))
18237 + err = au_sio_cpup_simple(&cpg);
18238 + au_unpin(&a->pin);
18241 + di_read_unlock(a->src_parent, AuLock_IR);
18245 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18246 + struct au_link_args *a)
18249 + unsigned char plink;
18250 + aufs_bindex_t bbot;
18251 + struct dentry *h_src_dentry;
18252 + struct inode *h_inode, *inode, *delegated;
18253 + struct super_block *sb;
18254 + struct file *h_file;
18258 + sb = src_dentry->d_sb;
18259 + inode = d_inode(src_dentry);
18260 + if (au_ibtop(inode) <= a->bdst)
18261 + h_inode = au_h_iptr(inode, a->bdst);
18262 + if (!h_inode || !h_inode->i_nlink) {
18263 + /* copyup src_dentry as the name of dentry. */
18264 + bbot = au_dbbot(dentry);
18265 + if (bbot < a->bsrc)
18266 + au_set_dbbot(dentry, a->bsrc);
18267 + au_set_h_dptr(dentry, a->bsrc,
18268 + dget(au_h_dptr(src_dentry, a->bsrc)));
18269 + dget(a->h_path.dentry);
18270 + au_set_h_dptr(dentry, a->bdst, NULL);
18271 + AuDbg("temporary d_inode...\n");
18272 + spin_lock(&dentry->d_lock);
18273 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18274 + spin_unlock(&dentry->d_lock);
18275 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18276 + if (IS_ERR(h_file))
18277 + err = PTR_ERR(h_file);
18279 + struct au_cp_generic cpg = {
18280 + .dentry = dentry,
18285 + .flags = AuCpup_KEEPLINO
18287 + err = au_sio_cpup_simple(&cpg);
18288 + au_h_open_post(dentry, a->bsrc, h_file);
18290 + dput(a->h_path.dentry);
18291 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18293 + au_set_h_dptr(dentry, a->bdst,
18294 + a->h_path.dentry);
18296 + spin_lock(&dentry->d_lock);
18297 + dentry->d_inode = NULL; /* restore */
18298 + spin_unlock(&dentry->d_lock);
18299 + AuDbg("temporary d_inode...done\n");
18300 + au_set_h_dptr(dentry, a->bsrc, NULL);
18301 + au_set_dbbot(dentry, bbot);
18303 + /* the inode of src_dentry already exists on a.bdst branch */
18304 + h_src_dentry = d_find_alias(h_inode);
18305 + if (!h_src_dentry && au_plink_test(inode)) {
18307 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18308 + err = PTR_ERR(h_src_dentry);
18309 + if (IS_ERR(h_src_dentry))
18312 + if (unlikely(d_is_negative(h_src_dentry))) {
18313 + dput(h_src_dentry);
18314 + h_src_dentry = NULL;
18318 + if (h_src_dentry) {
18319 + delegated = NULL;
18320 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18321 + &a->h_path, &delegated);
18322 + if (unlikely(err == -EWOULDBLOCK)) {
18323 + pr_warn("cannot retry for NFSv4 delegation"
18324 + " for an internal link\n");
18327 + dput(h_src_dentry);
18329 + AuIOErr("no dentry found for hi%lu on b%d\n",
18330 + h_inode->i_ino, a->bdst);
18335 + if (!err && !plink)
18336 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18343 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18344 + struct dentry *dentry)
18347 + struct au_dtime dt;
18348 + struct au_link_args *a;
18349 + struct dentry *wh_dentry, *h_src_dentry;
18350 + struct inode *inode, *delegated;
18351 + struct super_block *sb;
18352 + struct au_wr_dir_args wr_dir_args = {
18353 + /* .force_btgt = -1, */
18354 + .flags = AuWrDir_ADD_ENTRY
18358 + inode = d_inode(src_dentry);
18359 + IMustLock(inode);
18362 + a = kzalloc(sizeof(*a), GFP_NOFS);
18363 + if (unlikely(!a))
18366 + a->parent = dentry->d_parent; /* dir inode is locked */
18367 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18368 + AuLock_NOPLM | AuLock_GEN);
18369 + if (unlikely(err))
18371 + err = au_d_linkable(src_dentry);
18372 + if (unlikely(err))
18374 + err = au_d_may_add(dentry);
18375 + if (unlikely(err))
18378 + a->src_parent = dget_parent(src_dentry);
18379 + wr_dir_args.force_btgt = au_ibtop(inode);
18381 + di_write_lock_parent(a->parent);
18382 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18383 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18385 + err = PTR_ERR(wh_dentry);
18386 + if (IS_ERR(wh_dentry))
18390 + sb = dentry->d_sb;
18391 + a->bdst = au_dbtop(dentry);
18392 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18393 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18394 + a->bsrc = au_ibtop(inode);
18395 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18396 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18397 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18398 + if (!h_src_dentry) {
18399 + a->bsrc = au_dbtop(src_dentry);
18400 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18401 + AuDebugOn(!h_src_dentry);
18402 + } else if (IS_ERR(h_src_dentry)) {
18403 + err = PTR_ERR(h_src_dentry);
18408 + * aufs doesn't touch the credential so
18409 + * security_dentry_create_files_as() is unnecrssary.
18411 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18412 + if (a->bdst < a->bsrc
18413 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18414 + err = au_cpup_or_link(src_dentry, dentry, a);
18416 + delegated = NULL;
18417 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18418 + &a->h_path, &delegated);
18419 + if (unlikely(err == -EWOULDBLOCK)) {
18420 + pr_warn("cannot retry for NFSv4 delegation"
18421 + " for an internal link\n");
18425 + dput(h_src_dentry);
18428 + * copyup src_dentry to the branch we process,
18429 + * and then link(2) to it.
18431 + dput(h_src_dentry);
18432 + if (a->bdst < a->bsrc
18433 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18434 + au_unpin(&a->pin);
18435 + di_write_unlock(a->parent);
18436 + err = au_cpup_before_link(src_dentry, a);
18437 + di_write_lock_parent(a->parent);
18439 + err = au_pin(&a->pin, dentry, a->bdst,
18441 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18442 + if (unlikely(err))
18446 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18448 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18449 + delegated = NULL;
18450 + err = vfsub_link(h_src_dentry,
18451 + au_pinned_h_dir(&a->pin),
18452 + &a->h_path, &delegated);
18453 + if (unlikely(err == -EWOULDBLOCK)) {
18454 + pr_warn("cannot retry"
18455 + " for NFSv4 delegation"
18456 + " for an internal link\n");
18462 + if (unlikely(err))
18466 + a->h_path.dentry = wh_dentry;
18467 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18469 + if (unlikely(err))
18473 + au_dir_ts(dir, a->bdst);
18474 + dir->i_version++;
18475 + inc_nlink(inode);
18476 + inode->i_ctime = dir->i_ctime;
18477 + d_instantiate(dentry, au_igrab(inode));
18478 + if (d_unhashed(a->h_path.dentry))
18479 + /* some filesystem calls d_drop() */
18481 + /* some filesystems consume an inode even hardlink */
18482 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18483 + goto out_unpin; /* success */
18486 + /* no delegation since it is just created */
18487 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18488 + /*delegated*/NULL, /*force*/0);
18489 + if (unlikely(rerr)) {
18490 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18493 + au_dtime_revert(&dt);
18495 + au_unpin(&a->pin);
18499 + di_write_unlock(a->parent);
18500 + dput(a->src_parent);
18502 + if (unlikely(err)) {
18503 + au_update_dbtop(dentry);
18506 + aufs_read_and_write_unlock2(dentry, src_dentry);
18514 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18517 + aufs_bindex_t bindex;
18518 + unsigned char diropq;
18519 + struct path h_path;
18520 + struct dentry *wh_dentry, *parent, *opq_dentry;
18521 + struct inode *h_inode;
18522 + struct super_block *sb;
18524 + struct au_pin pin;
18525 + struct au_dtime dt;
18526 + } *a; /* reduce the stack usage */
18527 + struct au_wr_dir_args wr_dir_args = {
18528 + .force_btgt = -1,
18529 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18535 + a = kmalloc(sizeof(*a), GFP_NOFS);
18536 + if (unlikely(!a))
18539 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18540 + if (unlikely(err))
18542 + err = au_d_may_add(dentry);
18543 + if (unlikely(err))
18546 + parent = dentry->d_parent; /* dir inode is locked */
18547 + di_write_lock_parent(parent);
18548 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18549 + &a->pin, &wr_dir_args);
18550 + err = PTR_ERR(wh_dentry);
18551 + if (IS_ERR(wh_dentry))
18554 + sb = dentry->d_sb;
18555 + bindex = au_dbtop(dentry);
18556 + h_path.dentry = au_h_dptr(dentry, bindex);
18557 + h_path.mnt = au_sbr_mnt(sb, bindex);
18558 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18559 + if (unlikely(err))
18562 + /* make the dir opaque */
18564 + h_inode = d_inode(h_path.dentry);
18566 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18567 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18568 + opq_dentry = au_diropq_create(dentry, bindex);
18569 + inode_unlock(h_inode);
18570 + err = PTR_ERR(opq_dentry);
18571 + if (IS_ERR(opq_dentry))
18573 + dput(opq_dentry);
18577 + err = epilog(dir, bindex, wh_dentry, dentry);
18580 + goto out_unpin; /* success */
18585 + AuLabel(revert opq);
18586 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18587 + rerr = au_diropq_remove(dentry, bindex);
18588 + inode_unlock(h_inode);
18590 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18591 + dentry, err, rerr);
18597 + AuLabel(revert dir);
18598 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18600 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18601 + dentry, err, rerr);
18604 + au_dtime_revert(&a->dt);
18606 + au_unpin(&a->pin);
18609 + di_write_unlock(parent);
18611 + if (unlikely(err)) {
18612 + au_update_dbtop(dentry);
18615 + aufs_read_unlock(dentry, AuLock_DW);
18621 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18622 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18623 +++ linux/fs/aufs/i_op.c 2017-07-29 12:14:25.903042072 +0200
18626 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18628 + * This program, aufs is free software; you can redistribute it and/or modify
18629 + * it under the terms of the GNU General Public License as published by
18630 + * the Free Software Foundation; either version 2 of the License, or
18631 + * (at your option) any later version.
18633 + * This program is distributed in the hope that it will be useful,
18634 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18635 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18636 + * GNU General Public License for more details.
18638 + * You should have received a copy of the GNU General Public License
18639 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18643 + * inode operations (except add/del/rename)
18646 +#include <linux/device_cgroup.h>
18647 +#include <linux/fs_stack.h>
18648 +#include <linux/namei.h>
18649 +#include <linux/security.h>
18652 +static int h_permission(struct inode *h_inode, int mask,
18653 + struct path *h_path, int brperm)
18656 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18659 + if (write_mask && IS_IMMUTABLE(h_inode))
18663 + if (((mask & MAY_EXEC)
18664 + && S_ISREG(h_inode->i_mode)
18665 + && (path_noexec(h_path)
18666 + || !(h_inode->i_mode & S_IXUGO))))
18670 + * - skip the lower fs test in the case of write to ro branch.
18671 + * - nfs dir permission write check is optimized, but a policy for
18672 + * link/rename requires a real check.
18673 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18674 + * in this case, generic_permission() returns -EOPNOTSUPP.
18676 + if ((write_mask && !au_br_writable(brperm))
18677 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18678 + && write_mask && !(mask & MAY_READ))
18679 + || !h_inode->i_op->permission) {
18680 + /* AuLabel(generic_permission); */
18681 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18682 + err = generic_permission(h_inode, mask);
18683 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18684 + err = h_inode->i_op->permission(h_inode, mask);
18687 + /* AuLabel(h_inode->permission); */
18688 + err = h_inode->i_op->permission(h_inode, mask);
18693 + err = devcgroup_inode_permission(h_inode, mask);
18695 + err = security_inode_permission(h_inode, mask);
18699 + /* todo: do we need to call ima_path_check()? */
18700 + struct path h_path = {
18704 + err = ima_path_check(&h_path,
18705 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18706 + IMA_COUNT_LEAVE);
18714 +static int aufs_permission(struct inode *inode, int mask)
18717 + aufs_bindex_t bindex, bbot;
18718 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18719 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18720 + struct inode *h_inode;
18721 + struct super_block *sb;
18722 + struct au_branch *br;
18724 + /* todo: support rcu-walk? */
18725 + if (mask & MAY_NOT_BLOCK)
18728 + sb = inode->i_sb;
18729 + si_read_lock(sb, AuLock_FLUSH);
18730 + ii_read_lock_child(inode);
18732 + err = au_iigen_test(inode, au_sigen(sb));
18733 + if (unlikely(err))
18739 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18740 + err = au_busy_or_stale();
18741 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18742 + if (unlikely(!h_inode
18743 + || (h_inode->i_mode & S_IFMT)
18744 + != (inode->i_mode & S_IFMT)))
18748 + bindex = au_ibtop(inode);
18749 + br = au_sbr(sb, bindex);
18750 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18753 + && !special_file(h_inode->i_mode)) {
18754 + /* test whether the upper writable branch exists */
18756 + for (; bindex >= 0; bindex--)
18757 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18765 + /* non-write to dir */
18767 + bbot = au_ibbot(inode);
18768 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18769 + h_inode = au_h_iptr(inode, bindex);
18771 + err = au_busy_or_stale();
18772 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18775 + br = au_sbr(sb, bindex);
18776 + err = h_permission(h_inode, mask, &br->br_path,
18782 + ii_read_unlock(inode);
18783 + si_read_unlock(sb);
18787 +/* ---------------------------------------------------------------------- */
18789 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18790 + unsigned int flags)
18792 + struct dentry *ret, *parent;
18793 + struct inode *inode;
18794 + struct super_block *sb;
18795 + int err, npositive;
18799 + /* todo: support rcu-walk? */
18800 + ret = ERR_PTR(-ECHILD);
18801 + if (flags & LOOKUP_RCU)
18804 + ret = ERR_PTR(-ENAMETOOLONG);
18805 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18809 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18810 + ret = ERR_PTR(err);
18811 + if (unlikely(err))
18814 + err = au_di_init(dentry);
18815 + ret = ERR_PTR(err);
18816 + if (unlikely(err))
18820 + npositive = 0; /* suppress a warning */
18821 + parent = dentry->d_parent; /* dir inode is locked */
18822 + di_read_lock_parent(parent, AuLock_IR);
18823 + err = au_alive_dir(parent);
18825 + err = au_digen_test(parent, au_sigen(sb));
18827 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18828 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18829 + AuLkup_ALLOW_NEG);
18832 + di_read_unlock(parent, AuLock_IR);
18833 + ret = ERR_PTR(err);
18834 + if (unlikely(err < 0))
18838 + inode = au_new_inode(dentry, /*must_new*/0);
18839 + if (IS_ERR(inode)) {
18840 + ret = (void *)inode;
18847 + atomic_inc(&inode->i_count);
18848 + ret = d_splice_alias(inode, dentry);
18850 + if (unlikely(d_need_lookup(dentry))) {
18851 + spin_lock(&dentry->d_lock);
18852 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18853 + spin_unlock(&dentry->d_lock);
18857 + if (!IS_ERR(ret)) {
18859 + if (ret && ret != dentry)
18860 + ii_write_unlock(inode);
18862 + ii_write_unlock(inode);
18869 + di_write_unlock(dentry);
18871 + si_read_unlock(sb);
18876 +/* ---------------------------------------------------------------------- */
18878 +struct aopen_node {
18879 + struct hlist_node hlist;
18880 + struct file *file, *h_file;
18883 +static int au_do_aopen(struct inode *inode, struct file *file)
18885 + struct au_sphlhead *aopen;
18886 + struct aopen_node *node;
18887 + struct au_do_open_args args = {
18889 + .open = au_do_open_nondir
18892 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18893 + spin_lock(&aopen->spin);
18894 + hlist_for_each_entry(node, &aopen->head, hlist)
18895 + if (node->file == file) {
18896 + args.h_file = node->h_file;
18899 + spin_unlock(&aopen->spin);
18900 + /* AuDebugOn(!args.h_file); */
18902 + return au_do_open(file, &args);
18905 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18906 + struct file *file, unsigned int open_flag,
18907 + umode_t create_mode, int *opened)
18909 + int err, h_opened = *opened;
18910 + unsigned int lkup_flags;
18911 + struct dentry *parent, *d;
18912 + struct au_sphlhead *aopen;
18913 + struct vfsub_aopen_args args = {
18914 + .open_flag = open_flag,
18915 + .create_mode = create_mode,
18916 + .opened = &h_opened
18918 + struct aopen_node aopen_node = {
18923 + AuDbg("open_flag 0%o\n", open_flag);
18924 + AuDbgDentry(dentry);
18927 + if (!au_di(dentry)) {
18928 + lkup_flags = LOOKUP_OPEN;
18929 + if (open_flag & O_CREAT)
18930 + lkup_flags |= LOOKUP_CREATE;
18931 + d = aufs_lookup(dir, dentry, lkup_flags);
18933 + err = PTR_ERR(d);
18938 + * obsoleted dentry found.
18939 + * another error will be returned later.
18945 + AuDbgDentry(dentry);
18948 + if (d_is_positive(dentry)
18949 + || d_unhashed(dentry)
18950 + || d_unlinked(dentry)
18951 + || !(open_flag & O_CREAT))
18952 + goto out_no_open;
18954 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18955 + if (unlikely(err))
18958 + parent = dentry->d_parent; /* dir is locked */
18959 + di_write_lock_parent(parent);
18960 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18961 + if (unlikely(err))
18964 + AuDbgDentry(dentry);
18965 + if (d_is_positive(dentry))
18968 + args.file = get_empty_filp();
18969 + err = PTR_ERR(args.file);
18970 + if (IS_ERR(args.file))
18973 + args.file->f_flags = file->f_flags;
18974 + err = au_aopen_or_create(dir, dentry, &args);
18976 + AuDbgFile(args.file);
18977 + if (unlikely(err < 0)) {
18978 + if (h_opened & FILE_OPENED)
18981 + put_filp(args.file);
18985 + /* some filesystems don't set FILE_CREATED while succeeded? */
18986 + *opened |= FILE_CREATED;
18987 + if (h_opened & FILE_OPENED)
18988 + aopen_node.h_file = args.file;
18990 + put_filp(args.file);
18991 + args.file = NULL;
18993 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18994 + au_sphl_add(&aopen_node.hlist, aopen);
18995 + err = finish_open(file, dentry, au_do_aopen, opened);
18996 + au_sphl_del(&aopen_node.hlist, aopen);
18999 + if (aopen_node.h_file)
19000 + fput(aopen_node.h_file);
19003 + di_write_unlock(parent);
19004 + aufs_read_unlock(dentry, AuLock_DW);
19005 + AuDbgDentry(dentry);
19006 + if (unlikely(err < 0))
19009 + if (err >= 0 && !(*opened & FILE_CREATED)) {
19010 + AuLabel(out_no_open);
19012 + err = finish_no_open(file, dentry);
19015 + AuDbg("%pd%s%s\n", dentry,
19016 + (*opened & FILE_CREATED) ? " created" : "",
19017 + (*opened & FILE_OPENED) ? " opened" : "");
19023 +/* ---------------------------------------------------------------------- */
19025 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
19026 + const unsigned char add_entry, aufs_bindex_t bcpup,
19027 + aufs_bindex_t btop)
19030 + struct dentry *h_parent;
19031 + struct inode *h_dir;
19034 + IMustLock(d_inode(parent));
19036 + di_write_lock_parent(parent);
19039 + if (!au_h_dptr(parent, bcpup)) {
19040 + if (btop > bcpup)
19041 + err = au_cpup_dirs(dentry, bcpup);
19042 + else if (btop < bcpup)
19043 + err = au_cpdown_dirs(dentry, bcpup);
19047 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
19048 + h_parent = au_h_dptr(parent, bcpup);
19049 + h_dir = d_inode(h_parent);
19050 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
19051 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
19052 + /* todo: no unlock here */
19053 + inode_unlock(h_dir);
19055 + AuDbg("bcpup %d\n", bcpup);
19057 + if (d_really_is_negative(dentry))
19058 + au_set_h_dptr(dentry, btop, NULL);
19059 + au_update_dbrange(dentry, /*do_put_zero*/0);
19064 + di_write_unlock(parent);
19066 + err = bcpup; /* success */
19073 + * decide the branch and the parent dir where we will create a new entry.
19074 + * returns new bindex or an error.
19075 + * copyup the parent dir if needed.
19077 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19078 + struct au_wr_dir_args *args)
19081 + unsigned int flags;
19082 + aufs_bindex_t bcpup, btop, src_btop;
19083 + const unsigned char add_entry
19084 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
19085 + | au_ftest_wrdir(args->flags, TMPFILE);
19086 + struct super_block *sb;
19087 + struct dentry *parent;
19088 + struct au_sbinfo *sbinfo;
19090 + sb = dentry->d_sb;
19091 + sbinfo = au_sbi(sb);
19092 + parent = dget_parent(dentry);
19093 + btop = au_dbtop(dentry);
19095 + if (args->force_btgt < 0) {
19096 + if (src_dentry) {
19097 + src_btop = au_dbtop(src_dentry);
19098 + if (src_btop < btop)
19099 + bcpup = src_btop;
19100 + } else if (add_entry) {
19102 + if (au_ftest_wrdir(args->flags, ISDIR))
19103 + au_fset_wbr(flags, DIR);
19104 + err = AuWbrCreate(sbinfo, dentry, flags);
19108 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
19110 + err = AuWbrCopyup(sbinfo, dentry);
19112 + if (!IS_ROOT(dentry)) {
19113 + di_read_lock_parent(parent, !AuLock_IR);
19114 + err = AuWbrCopyup(sbinfo, dentry);
19115 + di_read_unlock(parent, !AuLock_IR);
19117 + err = AuWbrCopyup(sbinfo, dentry);
19120 + if (unlikely(err < 0))
19124 + bcpup = args->force_btgt;
19125 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
19128 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
19130 + if (bcpup == btop)
19131 + goto out; /* success */
19133 + /* copyup the new parent into the branch we process */
19134 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
19136 + if (d_really_is_negative(dentry)) {
19137 + au_set_h_dptr(dentry, btop, NULL);
19138 + au_set_dbtop(dentry, bcpup);
19139 + au_set_dbbot(dentry, bcpup);
19141 + AuDebugOn(add_entry
19142 + && !au_ftest_wrdir(args->flags, TMPFILE)
19143 + && !au_h_dptr(dentry, bcpup));
19151 +/* ---------------------------------------------------------------------- */
19153 +void au_pin_hdir_unlock(struct au_pin *p)
19156 + au_hn_inode_unlock(p->hdir);
19159 +int au_pin_hdir_lock(struct au_pin *p)
19167 + /* even if an error happens later, keep this lock */
19168 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19171 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19176 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19177 + p->h_parent, p->br);
19183 +int au_pin_hdir_relock(struct au_pin *p)
19186 + struct inode *h_i;
19187 + struct dentry *h_d[] = {
19192 + err = au_pin_hdir_lock(p);
19193 + if (unlikely(err))
19196 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19199 + if (d_is_positive(h_d[i])) {
19200 + h_i = d_inode(h_d[i]);
19201 + err = !h_i->i_nlink;
19209 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19211 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19212 + p->hdir->hi_inode->i_rwsem.owner = task;
19216 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19219 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19220 + p->lsc_hi, 0, NULL, _RET_IP_);
19221 + au_pin_hdir_set_owner(p, current);
19225 +void au_pin_hdir_release(struct au_pin *p)
19228 + au_pin_hdir_set_owner(p, p->task);
19229 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19233 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19235 + if (pin && pin->parent)
19236 + return au_h_dptr(pin->parent, pin->bindex);
19240 +void au_unpin(struct au_pin *p)
19243 + au_pin_hdir_unlock(p);
19244 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19245 + vfsub_mnt_drop_write(p->h_mnt);
19249 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19250 + di_read_unlock(p->parent, AuLock_IR);
19251 + iput(p->hdir->hi_inode);
19253 + p->parent = NULL;
19256 + /* do not clear p->task */
19259 +int au_do_pin(struct au_pin *p)
19262 + struct super_block *sb;
19263 + struct inode *h_dir;
19266 + sb = p->dentry->d_sb;
19267 + p->br = au_sbr(sb, p->bindex);
19268 + if (IS_ROOT(p->dentry)) {
19269 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19270 + p->h_mnt = au_br_mnt(p->br);
19271 + err = vfsub_mnt_want_write(p->h_mnt);
19272 + if (unlikely(err)) {
19273 + au_fclr_pin(p->flags, MNT_WRITE);
19280 + p->h_dentry = NULL;
19281 + if (p->bindex <= au_dbbot(p->dentry))
19282 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19284 + p->parent = dget_parent(p->dentry);
19285 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19286 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19289 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19290 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19292 + h_dir = p->hdir->hi_inode;
19296 + * if DI_LOCKED is not set, then p->parent may be different
19297 + * and h_parent can be NULL.
19299 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19301 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19302 + di_read_unlock(p->parent, AuLock_IR);
19304 + p->parent = NULL;
19308 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19309 + p->h_mnt = au_br_mnt(p->br);
19310 + err = vfsub_mnt_want_write(p->h_mnt);
19311 + if (unlikely(err)) {
19312 + au_fclr_pin(p->flags, MNT_WRITE);
19313 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19314 + di_read_unlock(p->parent, AuLock_IR);
19316 + p->parent = NULL;
19322 + err = au_pin_hdir_lock(p);
19324 + goto out; /* success */
19329 + pr_err("err %d\n", err);
19330 + err = au_busy_or_stale();
19335 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19336 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19337 + unsigned int udba, unsigned char flags)
19339 + p->dentry = dentry;
19341 + p->lsc_di = lsc_di;
19342 + p->lsc_hi = lsc_hi;
19343 + p->flags = flags;
19344 + p->bindex = bindex;
19346 + p->parent = NULL;
19350 + p->h_dentry = NULL;
19351 + p->h_parent = NULL;
19353 + p->task = current;
19356 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19357 + unsigned int udba, unsigned char flags)
19359 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19361 + return au_do_pin(pin);
19364 +/* ---------------------------------------------------------------------- */
19367 + * ->setattr() and ->getattr() are called in various cases.
19368 + * chmod, stat: dentry is revalidated.
19369 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19371 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19373 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19374 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19377 + struct dentry *parent;
19380 + if (au_digen_test(dentry, sigen)) {
19381 + parent = dget_parent(dentry);
19382 + di_read_lock_parent(parent, AuLock_IR);
19383 + err = au_refresh_dentry(dentry, parent);
19384 + di_read_unlock(parent, AuLock_IR);
19392 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19393 + struct au_icpup_args *a)
19397 + aufs_bindex_t btop, ibtop;
19398 + struct dentry *hi_wh, *parent;
19399 + struct inode *inode;
19400 + struct au_wr_dir_args wr_dir_args = {
19401 + .force_btgt = -1,
19405 + if (d_is_dir(dentry))
19406 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19407 + /* plink or hi_wh() case */
19408 + btop = au_dbtop(dentry);
19409 + inode = d_inode(dentry);
19410 + ibtop = au_ibtop(inode);
19411 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19412 + wr_dir_args.force_btgt = ibtop;
19413 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19414 + if (unlikely(err < 0))
19418 + au_fset_icpup(a->flags, DID_CPUP);
19421 + a->pin_flags = AuPin_MNT_WRITE;
19423 + if (!IS_ROOT(dentry)) {
19424 + au_fset_pin(a->pin_flags, DI_LOCKED);
19425 + parent = dget_parent(dentry);
19426 + di_write_lock_parent(parent);
19429 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19430 + if (unlikely(err))
19434 + a->h_path.dentry = au_h_dptr(dentry, btop);
19435 + a->h_inode = d_inode(a->h_path.dentry);
19436 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19437 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19438 + if (ia->ia_size < i_size_read(a->h_inode))
19439 + sz = ia->ia_size;
19440 + inode_unlock(a->h_inode);
19444 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19445 + hi_wh = au_hi_wh(inode, a->btgt);
19447 + struct au_cp_generic cpg = {
19448 + .dentry = dentry,
19454 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19455 + if (unlikely(err))
19457 + hi_wh = au_hi_wh(inode, a->btgt);
19458 + /* todo: revalidate hi_wh? */
19463 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19464 + di_downgrade_lock(parent, AuLock_IR);
19468 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19469 + goto out; /* success */
19471 + if (!d_unhashed(dentry)) {
19472 + struct au_cp_generic cpg = {
19473 + .dentry = dentry,
19478 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19480 + err = au_sio_cpup_simple(&cpg);
19482 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19483 + } else if (!hi_wh)
19484 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19486 + a->h_path.dentry = hi_wh; /* do not dget here */
19489 + a->h_inode = d_inode(a->h_path.dentry);
19491 + goto out; /* success */
19492 + au_unpin(&a->pin);
19495 + di_write_unlock(parent);
19500 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19504 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19507 + struct inode *inode, *delegated;
19508 + struct super_block *sb;
19509 + struct file *file;
19510 + struct au_icpup_args *a;
19512 + inode = d_inode(dentry);
19513 + IMustLock(inode);
19515 + err = setattr_prepare(dentry, ia);
19516 + if (unlikely(err))
19520 + a = kzalloc(sizeof(*a), GFP_NOFS);
19521 + if (unlikely(!a))
19524 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19525 + ia->ia_valid &= ~ATTR_MODE;
19528 + sb = dentry->d_sb;
19529 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19530 + if (unlikely(err))
19533 + if (ia->ia_valid & ATTR_FILE) {
19534 + /* currently ftruncate(2) only */
19535 + AuDebugOn(!d_is_reg(dentry));
19536 + file = ia->ia_file;
19537 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
19539 + if (unlikely(err))
19541 + ia->ia_file = au_hf_top(file);
19542 + a->udba = AuOpt_UDBA_NONE;
19544 + /* fchmod() doesn't pass ia_file */
19545 + a->udba = au_opt_udba(sb);
19546 + di_write_lock_child(dentry);
19547 + /* no d_unlinked(), to set UDBA_NONE for root */
19548 + if (d_unhashed(dentry))
19549 + a->udba = AuOpt_UDBA_NONE;
19550 + if (a->udba != AuOpt_UDBA_NONE) {
19551 + AuDebugOn(IS_ROOT(dentry));
19552 + err = au_reval_for_attr(dentry, au_sigen(sb));
19553 + if (unlikely(err))
19558 + err = au_pin_and_icpup(dentry, ia, a);
19559 + if (unlikely(err < 0))
19561 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19562 + ia->ia_file = NULL;
19563 + ia->ia_valid &= ~ATTR_FILE;
19566 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19567 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19568 + == (ATTR_MODE | ATTR_CTIME)) {
19569 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19570 + if (unlikely(err))
19572 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19573 + && (ia->ia_valid & ATTR_CTIME)) {
19574 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19575 + if (unlikely(err))
19579 + if (ia->ia_valid & ATTR_SIZE) {
19582 + if (ia->ia_size < i_size_read(inode))
19584 + truncate_setsize(inode, ia->ia_size);
19587 + if (ia->ia_valid & ATTR_FILE)
19589 + inode_unlock(a->h_inode);
19590 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19591 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19593 + delegated = NULL;
19595 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19597 + err = break_deleg_wait(&delegated);
19605 + * regardless aufs 'acl' option setting.
19606 + * why don't all acl-aware fs call this func from their ->setattr()?
19608 + if (!err && (ia->ia_valid & ATTR_MODE))
19609 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19611 + au_cpup_attr_changeable(inode);
19614 + inode_unlock(a->h_inode);
19615 + au_unpin(&a->pin);
19616 + if (unlikely(err))
19617 + au_update_dbtop(dentry);
19619 + di_write_unlock(dentry);
19621 + fi_write_unlock(file);
19622 + ia->ia_file = file;
19623 + ia->ia_valid |= ATTR_FILE;
19626 + si_read_unlock(sb);
19634 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19635 +static int au_h_path_to_set_attr(struct dentry *dentry,
19636 + struct au_icpup_args *a, struct path *h_path)
19639 + struct super_block *sb;
19641 + sb = dentry->d_sb;
19642 + a->udba = au_opt_udba(sb);
19643 + /* no d_unlinked(), to set UDBA_NONE for root */
19644 + if (d_unhashed(dentry))
19645 + a->udba = AuOpt_UDBA_NONE;
19646 + if (a->udba != AuOpt_UDBA_NONE) {
19647 + AuDebugOn(IS_ROOT(dentry));
19648 + err = au_reval_for_attr(dentry, au_sigen(sb));
19649 + if (unlikely(err))
19652 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19653 + if (unlikely(err < 0))
19656 + h_path->dentry = a->h_path.dentry;
19657 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19663 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19664 + struct au_sxattr *arg)
19667 + struct path h_path;
19668 + struct super_block *sb;
19669 + struct au_icpup_args *a;
19670 + struct inode *h_inode;
19672 + IMustLock(inode);
19675 + a = kzalloc(sizeof(*a), GFP_NOFS);
19676 + if (unlikely(!a))
19679 + sb = dentry->d_sb;
19680 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19681 + if (unlikely(err))
19684 + h_path.dentry = NULL; /* silence gcc */
19685 + di_write_lock_child(dentry);
19686 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19687 + if (unlikely(err))
19690 + inode_unlock(a->h_inode);
19691 + switch (arg->type) {
19692 + case AU_XATTR_SET:
19693 + AuDebugOn(d_is_negative(h_path.dentry));
19694 + err = vfsub_setxattr(h_path.dentry,
19695 + arg->u.set.name, arg->u.set.value,
19696 + arg->u.set.size, arg->u.set.flags);
19699 + err = -EOPNOTSUPP;
19700 + h_inode = d_inode(h_path.dentry);
19701 + if (h_inode->i_op->set_acl)
19702 + /* this will call posix_acl_update_mode */
19703 + err = h_inode->i_op->set_acl(h_inode,
19704 + arg->u.acl_set.acl,
19705 + arg->u.acl_set.type);
19709 + au_cpup_attr_timesizes(inode);
19711 + au_unpin(&a->pin);
19712 + if (unlikely(err))
19713 + au_update_dbtop(dentry);
19716 + di_write_unlock(dentry);
19717 + si_read_unlock(sb);
19726 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19727 + unsigned int nlink)
19731 + inode->i_mode = st->mode;
19732 + /* don't i_[ug]id_write() here */
19733 + inode->i_uid = st->uid;
19734 + inode->i_gid = st->gid;
19735 + inode->i_atime = st->atime;
19736 + inode->i_mtime = st->mtime;
19737 + inode->i_ctime = st->ctime;
19739 + au_cpup_attr_nlink(inode, /*force*/0);
19740 + if (S_ISDIR(inode->i_mode)) {
19741 + n = inode->i_nlink;
19744 + smp_mb(); /* for i_nlink */
19745 + /* 0 can happen */
19746 + set_nlink(inode, n);
19749 + spin_lock(&inode->i_lock);
19750 + inode->i_blocks = st->blocks;
19751 + i_size_write(inode, st->size);
19752 + spin_unlock(&inode->i_lock);
19756 + * common routine for aufs_getattr() and au_getxattr().
19757 + * returns zero or negative (an error).
19758 + * @dentry will be read-locked in success.
19760 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19764 + unsigned int mnt_flags, sigen;
19765 + unsigned char udba_none;
19766 + aufs_bindex_t bindex;
19767 + struct super_block *sb, *h_sb;
19768 + struct inode *inode;
19770 + h_path->mnt = NULL;
19771 + h_path->dentry = NULL;
19774 + sb = dentry->d_sb;
19775 + mnt_flags = au_mntflags(sb);
19776 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19778 + if (unlikely(locked))
19779 + goto body; /* skip locking dinfo */
19781 + /* support fstat(2) */
19782 + if (!d_unlinked(dentry) && !udba_none) {
19783 + sigen = au_sigen(sb);
19784 + err = au_digen_test(dentry, sigen);
19786 + di_read_lock_child(dentry, AuLock_IR);
19787 + err = au_dbrange_test(dentry);
19788 + if (unlikely(err)) {
19789 + di_read_unlock(dentry, AuLock_IR);
19793 + AuDebugOn(IS_ROOT(dentry));
19794 + di_write_lock_child(dentry);
19795 + err = au_dbrange_test(dentry);
19797 + err = au_reval_for_attr(dentry, sigen);
19799 + di_downgrade_lock(dentry, AuLock_IR);
19801 + di_write_unlock(dentry);
19806 + di_read_lock_child(dentry, AuLock_IR);
19809 + inode = d_inode(dentry);
19810 + bindex = au_ibtop(inode);
19811 + h_path->mnt = au_sbr_mnt(sb, bindex);
19812 + h_sb = h_path->mnt->mnt_sb;
19814 + && !au_test_fs_bad_iattr(h_sb)
19816 + goto out; /* success */
19818 + if (au_dbtop(dentry) == bindex)
19819 + h_path->dentry = au_h_dptr(dentry, bindex);
19820 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19821 + h_path->dentry = au_plink_lkup(inode, bindex);
19822 + if (IS_ERR(h_path->dentry))
19823 + /* pretending success */
19824 + h_path->dentry = NULL;
19826 + dput(h_path->dentry);
19833 +static int aufs_getattr(const struct path *path, struct kstat *st,
19834 + u32 request, unsigned int query)
19837 + unsigned char positive;
19838 + struct path h_path;
19839 + struct dentry *dentry;
19840 + struct inode *inode;
19841 + struct super_block *sb;
19843 + dentry = path->dentry;
19844 + inode = d_inode(dentry);
19845 + sb = dentry->d_sb;
19846 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19847 + if (unlikely(err))
19849 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
19850 + if (unlikely(err))
19852 + if (unlikely(!h_path.dentry))
19853 + /* illegally overlapped or something */
19854 + goto out_fill; /* pretending success */
19856 + positive = d_is_positive(h_path.dentry);
19858 + /* no vfsub version */
19859 + err = vfs_getattr(&h_path, st, request, query);
19862 + au_refresh_iattr(inode, st,
19863 + d_inode(h_path.dentry)->i_nlink);
19864 + goto out_fill; /* success */
19870 + generic_fillattr(inode, st);
19872 + di_read_unlock(dentry, AuLock_IR);
19874 + si_read_unlock(sb);
19880 +/* ---------------------------------------------------------------------- */
19882 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19883 + struct delayed_call *done)
19886 + struct dentry *h_dentry;
19887 + struct inode *h_inode;
19889 + aufs_bindex_t bindex;
19891 + ret = NULL; /* suppress a warning */
19896 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19897 + if (unlikely(err))
19900 + err = au_d_hashed_positive(dentry);
19901 + if (unlikely(err))
19905 + inode = d_inode(dentry);
19906 + bindex = au_ibtop(inode);
19907 + h_inode = au_h_iptr(inode, bindex);
19908 + if (unlikely(!h_inode->i_op->get_link))
19913 + if (au_dbtop(dentry) <= bindex) {
19914 + h_dentry = au_h_dptr(dentry, bindex);
19919 + h_dentry = d_find_any_alias(h_inode);
19920 + if (IS_ERR(h_dentry)) {
19921 + err = PTR_ERR(h_dentry);
19925 + if (unlikely(!h_dentry))
19929 + AuDbg("%pf\n", h_inode->i_op->get_link);
19930 + AuDbgDentry(h_dentry);
19931 + ret = vfs_get_link(h_dentry, done);
19934 + err = PTR_ERR(ret);
19937 + aufs_read_unlock(dentry, AuLock_IR);
19939 + if (unlikely(err))
19940 + ret = ERR_PTR(err);
19941 + AuTraceErrPtr(ret);
19945 +/* ---------------------------------------------------------------------- */
19947 +static int au_is_special(struct inode *inode)
19949 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19952 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19955 + aufs_bindex_t bindex;
19956 + struct super_block *sb;
19957 + struct inode *h_inode;
19958 + struct vfsmount *h_mnt;
19960 + sb = inode->i_sb;
19961 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19962 + "unexpected s_flags 0x%lx", sb->s_flags);
19964 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19966 + si_read_lock(sb, AuLock_FLUSH);
19967 + ii_write_lock_child(inode);
19971 + bindex = au_ibtop(inode);
19972 + h_inode = au_h_iptr(inode, bindex);
19973 + if (!au_test_ro(sb, bindex, inode)) {
19974 + h_mnt = au_sbr_mnt(sb, bindex);
19975 + err = vfsub_mnt_want_write(h_mnt);
19977 + err = vfsub_update_time(h_inode, ts, flags);
19978 + vfsub_mnt_drop_write(h_mnt);
19980 + } else if (au_is_special(h_inode)) {
19982 + * Never copy-up here.
19983 + * These special files may already be opened and used for
19984 + * communicating. If we copied it up, then the communication
19985 + * would be corrupted.
19987 + AuWarn1("timestamps for i%lu are ignored "
19988 + "since it is on readonly branch (hi%lu).\n",
19989 + inode->i_ino, h_inode->i_ino);
19990 + } else if (flags & ~S_ATIME) {
19992 + AuIOErr1("unexpected flags 0x%x\n", flags);
19998 + au_cpup_attr_timesizes(inode);
19999 + ii_write_unlock(inode);
20000 + si_read_unlock(sb);
20003 + if (!err && (flags & S_VERSION))
20004 + inode_inc_iversion(inode);
20009 +/* ---------------------------------------------------------------------- */
20011 +/* no getattr version will be set by module.c:aufs_init() */
20012 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
20014 + [AuIop_SYMLINK] = {
20015 + .permission = aufs_permission,
20016 +#ifdef CONFIG_FS_POSIX_ACL
20017 + .get_acl = aufs_get_acl,
20018 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
20021 + .setattr = aufs_setattr,
20022 + .getattr = aufs_getattr,
20024 +#ifdef CONFIG_AUFS_XATTR
20025 + .listxattr = aufs_listxattr,
20028 + .get_link = aufs_get_link,
20030 + /* .update_time = aufs_update_time */
20033 + .create = aufs_create,
20034 + .lookup = aufs_lookup,
20035 + .link = aufs_link,
20036 + .unlink = aufs_unlink,
20037 + .symlink = aufs_symlink,
20038 + .mkdir = aufs_mkdir,
20039 + .rmdir = aufs_rmdir,
20040 + .mknod = aufs_mknod,
20041 + .rename = aufs_rename,
20043 + .permission = aufs_permission,
20044 +#ifdef CONFIG_FS_POSIX_ACL
20045 + .get_acl = aufs_get_acl,
20046 + .set_acl = aufs_set_acl,
20049 + .setattr = aufs_setattr,
20050 + .getattr = aufs_getattr,
20052 +#ifdef CONFIG_AUFS_XATTR
20053 + .listxattr = aufs_listxattr,
20056 + .update_time = aufs_update_time,
20057 + .atomic_open = aufs_atomic_open,
20058 + .tmpfile = aufs_tmpfile
20060 + [AuIop_OTHER] = {
20061 + .permission = aufs_permission,
20062 +#ifdef CONFIG_FS_POSIX_ACL
20063 + .get_acl = aufs_get_acl,
20064 + .set_acl = aufs_set_acl,
20067 + .setattr = aufs_setattr,
20068 + .getattr = aufs_getattr,
20070 +#ifdef CONFIG_AUFS_XATTR
20071 + .listxattr = aufs_listxattr,
20074 + .update_time = aufs_update_time
20077 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
20078 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
20079 +++ linux/fs/aufs/i_op_del.c 2017-07-29 12:14:25.903042072 +0200
20082 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20084 + * This program, aufs is free software; you can redistribute it and/or modify
20085 + * it under the terms of the GNU General Public License as published by
20086 + * the Free Software Foundation; either version 2 of the License, or
20087 + * (at your option) any later version.
20089 + * This program is distributed in the hope that it will be useful,
20090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20092 + * GNU General Public License for more details.
20094 + * You should have received a copy of the GNU General Public License
20095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20099 + * inode operations (del entry)
20105 + * decide if a new whiteout for @dentry is necessary or not.
20106 + * when it is necessary, prepare the parent dir for the upper branch whose
20107 + * branch index is @bcpup for creation. the actual creation of the whiteout will
20108 + * be done by caller.
20110 + * 0: wh is unnecessary
20111 + * plus: wh is necessary
20114 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
20116 + int need_wh, err;
20117 + aufs_bindex_t btop;
20118 + struct super_block *sb;
20120 + sb = dentry->d_sb;
20121 + btop = au_dbtop(dentry);
20122 + if (*bcpup < 0) {
20124 + if (au_test_ro(sb, btop, d_inode(dentry))) {
20125 + err = AuWbrCopyup(au_sbi(sb), dentry);
20127 + if (unlikely(err < 0))
20131 + AuDebugOn(btop < *bcpup
20132 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
20133 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
20135 + if (*bcpup != btop) {
20136 + err = au_cpup_dirs(dentry, *bcpup);
20137 + if (unlikely(err))
20141 + struct au_dinfo *dinfo, *tmp;
20143 + need_wh = -ENOMEM;
20144 + dinfo = au_di(dentry);
20145 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
20147 + au_di_cp(tmp, dinfo);
20148 + au_di_swap(tmp, dinfo);
20149 + /* returns the number of positive dentries */
20150 + need_wh = au_lkup_dentry(dentry, btop + 1,
20151 + /* AuLkup_IGNORE_PERM */ 0);
20152 + au_di_swap(tmp, dinfo);
20153 + au_rw_write_unlock(&tmp->di_rwsem);
20157 + AuDbg("need_wh %d\n", need_wh);
20165 + * simple tests for the del-entry operations.
20166 + * following the checks in vfs, plus the parent-child relationship.
20168 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20169 + struct dentry *h_parent, int isdir)
20173 + struct dentry *h_dentry, *h_latest;
20174 + struct inode *h_inode;
20176 + h_dentry = au_h_dptr(dentry, bindex);
20177 + if (d_really_is_positive(dentry)) {
20179 + if (unlikely(d_is_negative(h_dentry)))
20181 + h_inode = d_inode(h_dentry);
20182 + if (unlikely(!h_inode->i_nlink))
20185 + h_mode = h_inode->i_mode;
20188 + if (unlikely(S_ISDIR(h_mode)))
20190 + } else if (unlikely(!S_ISDIR(h_mode))) {
20195 + /* rename(2) case */
20197 + if (unlikely(d_is_positive(h_dentry)))
20202 + /* expected parent dir is locked */
20203 + if (unlikely(h_parent != h_dentry->d_parent))
20208 + * rmdir a dir may break the consistency on some filesystem.
20209 + * let's try heavy test.
20212 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20213 + && au_test_h_perm(d_inode(h_parent),
20214 + MAY_EXEC | MAY_WRITE)))
20217 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20219 + if (IS_ERR(h_latest))
20221 + if (h_latest == h_dentry)
20230 + * decide the branch where we operate for @dentry. the branch index will be set
20231 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20232 + * dir for reverting.
20233 + * when a new whiteout is necessary, create it.
20235 +static struct dentry*
20236 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20237 + struct au_dtime *dt, struct au_pin *pin)
20239 + struct dentry *wh_dentry;
20240 + struct super_block *sb;
20241 + struct path h_path;
20242 + int err, need_wh;
20243 + unsigned int udba;
20244 + aufs_bindex_t bcpup;
20246 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20247 + wh_dentry = ERR_PTR(need_wh);
20248 + if (unlikely(need_wh < 0))
20251 + sb = dentry->d_sb;
20252 + udba = au_opt_udba(sb);
20254 + err = au_pin(pin, dentry, bcpup, udba,
20255 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20256 + wh_dentry = ERR_PTR(err);
20257 + if (unlikely(err))
20260 + h_path.dentry = au_pinned_h_parent(pin);
20261 + if (udba != AuOpt_UDBA_NONE
20262 + && au_dbtop(dentry) == bcpup) {
20263 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20264 + wh_dentry = ERR_PTR(err);
20265 + if (unlikely(err))
20269 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20270 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20271 + wh_dentry = NULL;
20273 + goto out; /* success, no need to create whiteout */
20275 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20276 + if (IS_ERR(wh_dentry))
20279 + /* returns with the parent is locked and wh_dentry is dget-ed */
20280 + goto out; /* success */
20285 + return wh_dentry;
20289 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20290 + * in order to be revertible and save time for removing many child whiteouts
20292 + * returns 1 when there are too many child whiteout and caller should remove
20293 + * them asynchronously. returns 0 when the number of children is enough small to
20294 + * remove now or the branch fs is a remote fs.
20295 + * otherwise return an error.
20297 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20298 + struct au_nhash *whlist, struct inode *dir)
20300 + int rmdir_later, err, dirwh;
20301 + struct dentry *h_dentry;
20302 + struct super_block *sb;
20303 + struct inode *inode;
20305 + sb = dentry->d_sb;
20306 + SiMustAnyLock(sb);
20307 + h_dentry = au_h_dptr(dentry, bindex);
20308 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20309 + if (unlikely(err))
20312 + /* stop monitoring */
20313 + inode = d_inode(dentry);
20314 + au_hn_free(au_hi(inode, bindex));
20316 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20317 + dirwh = au_sbi(sb)->si_dirwh;
20318 + rmdir_later = (dirwh <= 1);
20319 + if (!rmdir_later)
20320 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20323 + return rmdir_later;
20326 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20327 + if (unlikely(err)) {
20328 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20329 + h_dentry, bindex, err);
20339 + * final procedure for deleting a entry.
20340 + * maintain dentry and iattr.
20342 +static void epilog(struct inode *dir, struct dentry *dentry,
20343 + aufs_bindex_t bindex)
20345 + struct inode *inode;
20347 + inode = d_inode(dentry);
20349 + inode->i_ctime = dir->i_ctime;
20351 + au_dir_ts(dir, bindex);
20352 + dir->i_version++;
20356 + * when an error happened, remove the created whiteout and revert everything.
20358 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20359 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20360 + struct dentry *dentry, struct au_dtime *dt)
20363 + struct path h_path = {
20364 + .dentry = wh_dentry,
20365 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20368 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20370 + au_set_dbwh(dentry, bwh);
20371 + au_dtime_revert(dt);
20375 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20379 +/* ---------------------------------------------------------------------- */
20381 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20384 + aufs_bindex_t bwh, bindex, btop;
20385 + struct inode *inode, *h_dir, *delegated;
20386 + struct dentry *parent, *wh_dentry;
20387 + /* to reuduce stack size */
20389 + struct au_dtime dt;
20390 + struct au_pin pin;
20391 + struct path h_path;
20397 + a = kmalloc(sizeof(*a), GFP_NOFS);
20398 + if (unlikely(!a))
20401 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20402 + if (unlikely(err))
20404 + err = au_d_hashed_positive(dentry);
20405 + if (unlikely(err))
20407 + inode = d_inode(dentry);
20408 + IMustLock(inode);
20410 + if (unlikely(d_is_dir(dentry)))
20411 + goto out_unlock; /* possible? */
20413 + btop = au_dbtop(dentry);
20414 + bwh = au_dbwh(dentry);
20416 + parent = dentry->d_parent; /* dir inode is locked */
20417 + di_write_lock_parent(parent);
20418 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20420 + err = PTR_ERR(wh_dentry);
20421 + if (IS_ERR(wh_dentry))
20424 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20425 + a->h_path.dentry = au_h_dptr(dentry, btop);
20426 + dget(a->h_path.dentry);
20427 + if (bindex == btop) {
20428 + h_dir = au_pinned_h_dir(&a->pin);
20429 + delegated = NULL;
20430 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20431 + if (unlikely(err == -EWOULDBLOCK)) {
20432 + pr_warn("cannot retry for NFSv4 delegation"
20433 + " for an internal unlink\n");
20437 + /* dir inode is locked */
20438 + h_dir = d_inode(wh_dentry->d_parent);
20439 + IMustLock(h_dir);
20444 + vfsub_drop_nlink(inode);
20445 + epilog(dir, dentry, bindex);
20447 + /* update target timestamps */
20448 + if (bindex == btop) {
20449 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20451 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20453 + /* todo: this timestamp may be reverted later */
20454 + inode->i_ctime = h_dir->i_ctime;
20455 + goto out_unpin; /* success */
20462 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20469 + au_unpin(&a->pin);
20471 + dput(a->h_path.dentry);
20473 + di_write_unlock(parent);
20475 + aufs_read_unlock(dentry, AuLock_DW);
20482 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20484 + int err, rmdir_later;
20485 + aufs_bindex_t bwh, bindex, btop;
20486 + struct inode *inode;
20487 + struct dentry *parent, *wh_dentry, *h_dentry;
20488 + struct au_whtmp_rmdir *args;
20489 + /* to reuduce stack size */
20491 + struct au_dtime dt;
20492 + struct au_pin pin;
20498 + a = kmalloc(sizeof(*a), GFP_NOFS);
20499 + if (unlikely(!a))
20502 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20503 + if (unlikely(err))
20505 + err = au_alive_dir(dentry);
20506 + if (unlikely(err))
20508 + inode = d_inode(dentry);
20509 + IMustLock(inode);
20511 + if (unlikely(!d_is_dir(dentry)))
20512 + goto out_unlock; /* possible? */
20515 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20516 + if (unlikely(!args))
20519 + parent = dentry->d_parent; /* dir inode is locked */
20520 + di_write_lock_parent(parent);
20521 + err = au_test_empty(dentry, &args->whlist);
20522 + if (unlikely(err))
20525 + btop = au_dbtop(dentry);
20526 + bwh = au_dbwh(dentry);
20528 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20530 + err = PTR_ERR(wh_dentry);
20531 + if (IS_ERR(wh_dentry))
20534 + h_dentry = au_h_dptr(dentry, btop);
20537 + if (bindex == btop) {
20538 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20540 + rmdir_later = err;
20544 + /* stop monitoring */
20545 + au_hn_free(au_hi(inode, btop));
20547 + /* dir inode is locked */
20548 + IMustLock(d_inode(wh_dentry->d_parent));
20553 + vfsub_dead_dir(inode);
20554 + au_set_dbdiropq(dentry, -1);
20555 + epilog(dir, dentry, bindex);
20557 + if (rmdir_later) {
20558 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20562 + goto out_unpin; /* success */
20570 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20577 + au_unpin(&a->pin);
20581 + di_write_unlock(parent);
20583 + au_whtmp_rmdir_free(args);
20585 + aufs_read_unlock(dentry, AuLock_DW);
20592 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20593 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20594 +++ linux/fs/aufs/i_op_ren.c 2017-07-29 12:14:25.903042072 +0200
20597 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20599 + * This program, aufs is free software; you can redistribute it and/or modify
20600 + * it under the terms of the GNU General Public License as published by
20601 + * the Free Software Foundation; either version 2 of the License, or
20602 + * (at your option) any later version.
20604 + * This program is distributed in the hope that it will be useful,
20605 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20606 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20607 + * GNU General Public License for more details.
20609 + * You should have received a copy of the GNU General Public License
20610 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20614 + * inode operation (rename entry)
20615 + * todo: this is crazy monster
20620 +enum { AuSRC, AuDST, AuSrcDst };
20621 +enum { AuPARENT, AuCHILD, AuParentChild };
20623 +#define AuRen_ISDIR_SRC 1
20624 +#define AuRen_ISDIR_DST (1 << 1)
20625 +#define AuRen_ISSAMEDIR (1 << 2)
20626 +#define AuRen_WHSRC (1 << 3)
20627 +#define AuRen_WHDST (1 << 4)
20628 +#define AuRen_MNT_WRITE (1 << 5)
20629 +#define AuRen_DT_DSTDIR (1 << 6)
20630 +#define AuRen_DIROPQ_SRC (1 << 7)
20631 +#define AuRen_DIROPQ_DST (1 << 8)
20632 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20633 +#define au_fset_ren(flags, name) \
20634 + do { (flags) |= AuRen_##name; } while (0)
20635 +#define au_fclr_ren(flags, name) \
20636 + do { (flags) &= ~AuRen_##name; } while (0)
20638 +struct au_ren_args {
20640 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20642 + struct inode *dir, *inode;
20643 + struct au_hinode *hdir, *hinode;
20644 + struct au_dtime dt[AuParentChild];
20645 + aufs_bindex_t btop, bdiropq;
20648 +#define src_dentry sd[AuSRC].dentry
20649 +#define src_dir sd[AuSRC].dir
20650 +#define src_inode sd[AuSRC].inode
20651 +#define src_h_dentry sd[AuSRC].h_dentry
20652 +#define src_parent sd[AuSRC].parent
20653 +#define src_h_parent sd[AuSRC].h_parent
20654 +#define src_wh_dentry sd[AuSRC].wh_dentry
20655 +#define src_hdir sd[AuSRC].hdir
20656 +#define src_hinode sd[AuSRC].hinode
20657 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20658 +#define src_dt sd[AuSRC].dt
20659 +#define src_btop sd[AuSRC].btop
20660 +#define src_bdiropq sd[AuSRC].bdiropq
20662 +#define dst_dentry sd[AuDST].dentry
20663 +#define dst_dir sd[AuDST].dir
20664 +#define dst_inode sd[AuDST].inode
20665 +#define dst_h_dentry sd[AuDST].h_dentry
20666 +#define dst_parent sd[AuDST].parent
20667 +#define dst_h_parent sd[AuDST].h_parent
20668 +#define dst_wh_dentry sd[AuDST].wh_dentry
20669 +#define dst_hdir sd[AuDST].hdir
20670 +#define dst_hinode sd[AuDST].hinode
20671 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20672 +#define dst_dt sd[AuDST].dt
20673 +#define dst_btop sd[AuDST].btop
20674 +#define dst_bdiropq sd[AuDST].bdiropq
20676 + struct dentry *h_trap;
20677 + struct au_branch *br;
20678 + struct path h_path;
20679 + struct au_nhash whlist;
20680 + aufs_bindex_t btgt, src_bwh;
20683 + unsigned short auren_flags;
20684 + unsigned char flags; /* syscall parameter */
20685 + unsigned char exchange;
20688 + struct au_whtmp_rmdir *thargs;
20689 + struct dentry *h_dst;
20692 +/* ---------------------------------------------------------------------- */
20695 + * functions for reverting.
20696 + * when an error happened in a single rename systemcall, we should revert
20697 + * everything as if nothing happened.
20698 + * we don't need to revert the copied-up/down the parent dir since they are
20702 +#define RevertFailure(fmt, ...) do { \
20703 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20704 + ##__VA_ARGS__, err, rerr); \
20708 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20711 + struct dentry *d;
20712 +#define src_or_dst(member) a->sd[idx].member
20714 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20715 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20716 + rerr = au_diropq_remove(d, a->btgt);
20717 + au_hn_inode_unlock(src_or_dst(hinode));
20718 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20720 + RevertFailure("remove diropq %pd", d);
20722 +#undef src_or_dst_
20725 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20727 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20728 + au_ren_do_rev_diropq(err, a, AuSRC);
20729 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20730 + au_ren_do_rev_diropq(err, a, AuDST);
20733 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20736 + struct inode *delegated;
20738 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20739 + a->src_h_parent);
20740 + rerr = PTR_ERR(a->h_path.dentry);
20741 + if (IS_ERR(a->h_path.dentry)) {
20742 + RevertFailure("lkup one %pd", a->src_dentry);
20746 + delegated = NULL;
20747 + rerr = vfsub_rename(a->dst_h_dir,
20748 + au_h_dptr(a->src_dentry, a->btgt),
20749 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20750 + if (unlikely(rerr == -EWOULDBLOCK)) {
20751 + pr_warn("cannot retry for NFSv4 delegation"
20752 + " for an internal rename\n");
20755 + d_drop(a->h_path.dentry);
20756 + dput(a->h_path.dentry);
20757 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20759 + RevertFailure("rename %pd", a->src_dentry);
20762 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20765 + struct inode *delegated;
20767 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20768 + a->dst_h_parent);
20769 + rerr = PTR_ERR(a->h_path.dentry);
20770 + if (IS_ERR(a->h_path.dentry)) {
20771 + RevertFailure("lkup one %pd", a->dst_dentry);
20774 + if (d_is_positive(a->h_path.dentry)) {
20775 + d_drop(a->h_path.dentry);
20776 + dput(a->h_path.dentry);
20780 + delegated = NULL;
20781 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20782 + &delegated, a->flags);
20783 + if (unlikely(rerr == -EWOULDBLOCK)) {
20784 + pr_warn("cannot retry for NFSv4 delegation"
20785 + " for an internal rename\n");
20788 + d_drop(a->h_path.dentry);
20789 + dput(a->h_path.dentry);
20791 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20793 + RevertFailure("rename %pd", a->h_dst);
20796 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20800 + a->h_path.dentry = a->src_wh_dentry;
20801 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20802 + au_set_dbwh(a->src_dentry, a->src_bwh);
20804 + RevertFailure("unlink %pd", a->src_wh_dentry);
20806 +#undef RevertFailure
20808 +/* ---------------------------------------------------------------------- */
20811 + * when we have to copyup the renaming entry, do it with the rename-target name
20812 + * in order to minimize the cost (the later actual rename is unnecessary).
20813 + * otherwise rename it on the target branch.
20815 +static int au_ren_or_cpup(struct au_ren_args *a)
20818 + struct dentry *d;
20819 + struct inode *delegated;
20821 + d = a->src_dentry;
20822 + if (au_dbtop(d) == a->btgt) {
20823 + a->h_path.dentry = a->dst_h_dentry;
20824 + AuDebugOn(au_dbtop(d) != a->btgt);
20825 + delegated = NULL;
20826 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20827 + a->dst_h_dir, &a->h_path, &delegated,
20829 + if (unlikely(err == -EWOULDBLOCK)) {
20830 + pr_warn("cannot retry for NFSv4 delegation"
20831 + " for an internal rename\n");
20837 + if (!err && a->h_dst)
20838 + /* it will be set to dinfo later */
20844 +/* cf. aufs_rmdir() */
20845 +static int au_ren_del_whtmp(struct au_ren_args *a)
20848 + struct inode *dir;
20850 + dir = a->dst_dir;
20851 + SiMustAnyLock(dir->i_sb);
20852 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20853 + au_sbi(dir->i_sb)->si_dirwh)
20854 + || au_test_fs_remote(a->h_dst->d_sb)) {
20855 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20856 + if (unlikely(err))
20857 + pr_warn("failed removing whtmp dir %pd (%d), "
20858 + "ignored.\n", a->h_dst, err);
20860 + au_nhash_wh_free(&a->thargs->whlist);
20861 + a->thargs->whlist = a->whlist;
20862 + a->whlist.nh_num = 0;
20863 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20865 + a->thargs = NULL;
20871 +/* make it 'opaque' dir. */
20872 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20875 + struct dentry *d, *diropq;
20876 +#define src_or_dst(member) a->sd[idx].member
20879 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20880 + src_or_dst(bdiropq) = au_dbdiropq(d);
20881 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20882 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20883 + diropq = au_diropq_create(d, a->btgt);
20884 + au_hn_inode_unlock(src_or_dst(hinode));
20885 + if (IS_ERR(diropq))
20886 + err = PTR_ERR(diropq);
20890 +#undef src_or_dst_
20894 +static int au_ren_diropq(struct au_ren_args *a)
20897 + unsigned char always;
20898 + struct dentry *d;
20901 + d = a->dst_dentry; /* already renamed on the branch */
20902 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20903 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20904 + && a->btgt != au_dbdiropq(a->src_dentry)
20905 + && (a->dst_wh_dentry
20906 + || a->btgt <= au_dbdiropq(d)
20907 + /* hide the lower to keep xino */
20908 + /* the lowers may not be a dir, but we hide them anyway */
20909 + || a->btgt < au_dbbot(d)
20912 + err = au_ren_do_diropq(a, AuSRC);
20913 + if (unlikely(err))
20915 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20917 + if (!a->exchange)
20918 + goto out; /* success */
20920 + d = a->src_dentry; /* already renamed on the branch */
20921 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20922 + && a->btgt != au_dbdiropq(a->dst_dentry)
20923 + && (a->btgt < au_dbdiropq(d)
20924 + || a->btgt < au_dbbot(d)
20926 + AuDbgDentry(a->src_dentry);
20927 + AuDbgDentry(a->dst_dentry);
20928 + err = au_ren_do_diropq(a, AuDST);
20929 + if (unlikely(err))
20930 + goto out_rev_src;
20931 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20933 + goto out; /* success */
20936 + AuDbg("err %d, reverting src\n", err);
20937 + au_ren_rev_diropq(err, a);
20942 +static int do_rename(struct au_ren_args *a)
20945 + struct dentry *d, *h_d;
20947 + if (!a->exchange) {
20948 + /* prepare workqueue args for asynchronous rmdir */
20949 + h_d = a->dst_h_dentry;
20950 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20951 + && d_is_positive(h_d)) {
20953 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20955 + if (unlikely(!a->thargs))
20957 + a->h_dst = dget(h_d);
20960 + /* create whiteout for src_dentry */
20961 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20962 + a->src_bwh = au_dbwh(a->src_dentry);
20963 + AuDebugOn(a->src_bwh >= 0);
20964 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20965 + a->src_h_parent);
20966 + err = PTR_ERR(a->src_wh_dentry);
20967 + if (IS_ERR(a->src_wh_dentry))
20971 + /* lookup whiteout for dentry */
20972 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20973 + h_d = au_wh_lkup(a->dst_h_parent,
20974 + &a->dst_dentry->d_name, a->br);
20975 + err = PTR_ERR(h_d);
20978 + if (d_is_negative(h_d))
20981 + a->dst_wh_dentry = h_d;
20984 + /* rename dentry to tmpwh */
20986 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20987 + if (unlikely(err))
20990 + d = a->dst_dentry;
20991 + au_set_h_dptr(d, a->btgt, NULL);
20992 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20993 + if (unlikely(err))
20995 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20999 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
21001 + /* rename by vfs_rename or cpup */
21002 + err = au_ren_or_cpup(a);
21003 + if (unlikely(err))
21004 + /* leave the copied-up one */
21007 + /* make dir opaque */
21008 + err = au_ren_diropq(a);
21009 + if (unlikely(err))
21012 + /* update target timestamps */
21013 + if (a->exchange) {
21014 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
21015 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
21016 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21017 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21019 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
21020 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
21021 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
21022 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
21024 + if (!a->exchange) {
21025 + /* remove whiteout for dentry */
21026 + if (a->dst_wh_dentry) {
21027 + a->h_path.dentry = a->dst_wh_dentry;
21028 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
21030 + if (unlikely(err))
21034 + /* remove whtmp */
21036 + au_ren_del_whtmp(a); /* ignore this error */
21038 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
21041 + goto out_success;
21044 + au_ren_rev_diropq(err, a);
21046 + au_ren_rev_rename(err, a);
21050 + au_ren_rev_whtmp(err, a);
21052 + dput(a->dst_wh_dentry);
21053 + a->dst_wh_dentry = NULL;
21055 + if (a->src_wh_dentry)
21056 + au_ren_rev_whsrc(err, a);
21058 + dput(a->src_wh_dentry);
21059 + dput(a->dst_wh_dentry);
21063 + au_whtmp_rmdir_free(a->thargs);
21064 + a->thargs = NULL;
21070 +/* ---------------------------------------------------------------------- */
21073 + * test if @dentry dir can be rename destination or not.
21074 + * success means, it is a logically empty dir.
21076 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
21078 + return au_test_empty(dentry, whlist);
21082 + * test if @dentry dir can be rename source or not.
21083 + * if it can, return 0 and @children is filled.
21085 + * - it is a logically empty dir.
21086 + * - or, it exists on writable branch and has no children including whiteouts
21087 + * on the lower branch.
21089 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
21092 + unsigned int rdhash;
21093 + aufs_bindex_t btop;
21095 + btop = au_dbtop(dentry);
21096 + if (btop != btgt) {
21097 + struct au_nhash whlist;
21099 + SiMustAnyLock(dentry->d_sb);
21100 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
21102 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
21104 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
21105 + if (unlikely(err))
21107 + err = au_test_empty(dentry, &whlist);
21108 + au_nhash_wh_free(&whlist);
21112 + if (btop == au_dbtaildir(dentry))
21113 + return 0; /* success */
21115 + err = au_test_empty_lower(dentry);
21118 + if (err == -ENOTEMPTY) {
21119 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
21120 + " is not supported\n");
21126 +/* side effect: sets whlist and h_dentry */
21127 +static int au_ren_may_dir(struct au_ren_args *a)
21130 + unsigned int rdhash;
21131 + struct dentry *d;
21133 + d = a->dst_dentry;
21134 + SiMustAnyLock(d->d_sb);
21137 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
21138 + rdhash = au_sbi(d->d_sb)->si_rdhash;
21140 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
21141 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
21142 + if (unlikely(err))
21145 + if (!a->exchange) {
21146 + au_set_dbtop(d, a->dst_btop);
21147 + err = may_rename_dstdir(d, &a->whlist);
21148 + au_set_dbtop(d, a->btgt);
21150 + err = may_rename_srcdir(d, a->btgt);
21152 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
21153 + if (unlikely(err))
21156 + d = a->src_dentry;
21157 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
21158 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21159 + err = may_rename_srcdir(d, a->btgt);
21160 + if (unlikely(err)) {
21161 + au_nhash_wh_free(&a->whlist);
21162 + a->whlist.nh_num = 0;
21169 +/* ---------------------------------------------------------------------- */
21172 + * simple tests for rename.
21173 + * following the checks in vfs, plus the parent-child relationship.
21175 +static int au_may_ren(struct au_ren_args *a)
21178 + struct inode *h_inode;
21180 + if (a->src_btop == a->btgt) {
21181 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
21182 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
21183 + if (unlikely(err))
21186 + if (unlikely(a->src_h_dentry == a->h_trap))
21191 + if (a->dst_btop != a->btgt)
21194 + err = -ENOTEMPTY;
21195 + if (unlikely(a->dst_h_dentry == a->h_trap))
21199 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21200 + if (d_really_is_negative(a->dst_dentry)) {
21201 + if (d_is_negative(a->dst_h_dentry))
21202 + err = au_may_add(a->dst_dentry, a->btgt,
21203 + a->dst_h_parent, isdir);
21205 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21207 + h_inode = d_inode(a->dst_h_dentry);
21208 + if (h_inode->i_nlink)
21209 + err = au_may_del(a->dst_dentry, a->btgt,
21210 + a->dst_h_parent, isdir);
21214 + if (unlikely(err == -ENOENT || err == -EEXIST))
21220 +/* ---------------------------------------------------------------------- */
21225 + * - src_dir and dir by lock_rename()
21226 + * - inode if exitsts
21229 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21231 + * + di_write_lock2_child()
21232 + * + di_write_lock_child()
21233 + * + ii_write_lock_child()
21234 + * + di_write_lock_child2()
21235 + * + ii_write_lock_child2()
21236 + * + src_parent and parent
21237 + * + di_write_lock_parent()
21238 + * + ii_write_lock_parent()
21239 + * + di_write_lock_parent2()
21240 + * + ii_write_lock_parent2()
21241 + * + lower src_dir and dir by vfsub_lock_rename()
21242 + * + verify the every relationships between child and parent. if any
21243 + * of them failed, unlock all and return -EBUSY.
21245 +static void au_ren_unlock(struct au_ren_args *a)
21247 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21248 + a->dst_h_parent, a->dst_hdir);
21249 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21250 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21253 +static int au_ren_lock(struct au_ren_args *a)
21256 + unsigned int udba;
21259 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21260 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21261 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21262 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21264 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21265 + if (unlikely(err))
21267 + au_fset_ren(a->auren_flags, MNT_WRITE);
21268 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21269 + a->dst_h_parent, a->dst_hdir);
21270 + udba = au_opt_udba(a->src_dentry->d_sb);
21271 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21272 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21273 + err = au_busy_or_stale();
21274 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21275 + err = au_h_verify(a->src_h_dentry, udba,
21276 + d_inode(a->src_h_parent), a->src_h_parent,
21278 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21279 + err = au_h_verify(a->dst_h_dentry, udba,
21280 + d_inode(a->dst_h_parent), a->dst_h_parent,
21283 + goto out; /* success */
21285 + err = au_busy_or_stale();
21286 + au_ren_unlock(a);
21292 +/* ---------------------------------------------------------------------- */
21294 +static void au_ren_refresh_dir(struct au_ren_args *a)
21296 + struct inode *dir;
21298 + dir = a->dst_dir;
21299 + dir->i_version++;
21300 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21301 + /* is this updating defined in POSIX? */
21302 + au_cpup_attr_timesizes(a->src_inode);
21303 + au_cpup_attr_nlink(dir, /*force*/1);
21305 + au_dir_ts(dir, a->btgt);
21307 + if (a->exchange) {
21308 + dir = a->src_dir;
21309 + dir->i_version++;
21310 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21311 + /* is this updating defined in POSIX? */
21312 + au_cpup_attr_timesizes(a->dst_inode);
21313 + au_cpup_attr_nlink(dir, /*force*/1);
21315 + au_dir_ts(dir, a->btgt);
21318 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21321 + dir = a->src_dir;
21322 + dir->i_version++;
21323 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21324 + au_cpup_attr_nlink(dir, /*force*/1);
21325 + au_dir_ts(dir, a->btgt);
21328 +static void au_ren_refresh(struct au_ren_args *a)
21330 + aufs_bindex_t bbot, bindex;
21331 + struct dentry *d, *h_d;
21332 + struct inode *i, *h_i;
21333 + struct super_block *sb;
21335 + d = a->dst_dentry;
21338 + /* already dget-ed by au_ren_or_cpup() */
21339 + au_set_h_dptr(d, a->btgt, a->h_dst);
21341 + i = a->dst_inode;
21343 + if (!a->exchange) {
21344 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21345 + vfsub_drop_nlink(i);
21347 + vfsub_dead_dir(i);
21348 + au_cpup_attr_timesizes(i);
21350 + au_update_dbrange(d, /*do_put_zero*/1);
21352 + au_cpup_attr_nlink(i, /*force*/1);
21355 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21356 + au_set_h_dptr(d, bindex, NULL);
21357 + bbot = au_dbbot(d);
21358 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21359 + au_set_h_dptr(d, bindex, NULL);
21360 + au_update_dbrange(d, /*do_put_zero*/0);
21363 + d = a->src_dentry;
21364 + if (!a->exchange) {
21365 + au_set_dbwh(d, -1);
21366 + bbot = au_dbbot(d);
21367 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21368 + h_d = au_h_dptr(d, bindex);
21370 + au_set_h_dptr(d, bindex, NULL);
21372 + au_set_dbbot(d, a->btgt);
21375 + i = a->src_inode;
21376 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21377 + return; /* success */
21379 + bbot = au_ibbot(i);
21380 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21381 + h_i = au_h_iptr(i, bindex);
21383 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21384 + /* ignore this error */
21385 + au_set_h_iptr(i, bindex, NULL, 0);
21388 + au_set_ibbot(i, a->btgt);
21390 + d_drop(a->src_dentry);
21393 +/* ---------------------------------------------------------------------- */
21395 +/* mainly for link(2) and rename(2) */
21396 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21398 + aufs_bindex_t bdiropq, bwh;
21399 + struct dentry *parent;
21400 + struct au_branch *br;
21402 + parent = dentry->d_parent;
21403 + IMustLock(d_inode(parent)); /* dir is locked */
21405 + bdiropq = au_dbdiropq(parent);
21406 + bwh = au_dbwh(dentry);
21407 + br = au_sbr(dentry->d_sb, btgt);
21408 + if (au_br_rdonly(br)
21409 + || (0 <= bdiropq && bdiropq < btgt)
21410 + || (0 <= bwh && bwh < btgt))
21413 + AuDbg("btgt %d\n", btgt);
21417 +/* sets src_btop, dst_btop and btgt */
21418 +static int au_ren_wbr(struct au_ren_args *a)
21421 + struct au_wr_dir_args wr_dir_args = {
21422 + /* .force_btgt = -1, */
21423 + .flags = AuWrDir_ADD_ENTRY
21426 + a->src_btop = au_dbtop(a->src_dentry);
21427 + a->dst_btop = au_dbtop(a->dst_dentry);
21428 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21429 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21430 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21431 + wr_dir_args.force_btgt = a->src_btop;
21432 + if (a->dst_inode && a->dst_btop < a->src_btop)
21433 + wr_dir_args.force_btgt = a->dst_btop;
21434 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21435 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21438 + au_update_dbtop(a->dst_dentry);
21443 +static void au_ren_dt(struct au_ren_args *a)
21445 + a->h_path.dentry = a->src_h_parent;
21446 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21447 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21448 + a->h_path.dentry = a->dst_h_parent;
21449 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21452 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21453 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21457 + a->h_path.dentry = a->src_h_dentry;
21458 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21459 + if (d_is_positive(a->dst_h_dentry)) {
21460 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21461 + a->h_path.dentry = a->dst_h_dentry;
21462 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21466 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21468 + struct dentry *h_d;
21469 + struct inode *h_inode;
21471 + au_dtime_revert(a->src_dt + AuPARENT);
21472 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21473 + au_dtime_revert(a->dst_dt + AuPARENT);
21475 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21476 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21477 + h_inode = d_inode(h_d);
21478 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21479 + au_dtime_revert(a->src_dt + AuCHILD);
21480 + inode_unlock(h_inode);
21482 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21483 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21484 + h_inode = d_inode(h_d);
21485 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21486 + au_dtime_revert(a->dst_dt + AuCHILD);
21487 + inode_unlock(h_inode);
21492 +/* ---------------------------------------------------------------------- */
21494 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21495 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21496 + unsigned int _flags)
21498 + int err, lock_flags;
21499 + /* reduce stack space */
21500 + struct au_ren_args *a;
21501 + struct au_pin pin;
21503 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21504 + IMustLock(_src_dir);
21505 + IMustLock(_dst_dir);
21508 + if (unlikely(_flags & RENAME_WHITEOUT))
21512 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21513 + a = kzalloc(sizeof(*a), GFP_NOFS);
21514 + if (unlikely(!a))
21517 + a->flags = _flags;
21518 + a->exchange = _flags & RENAME_EXCHANGE;
21519 + a->src_dir = _src_dir;
21520 + a->src_dentry = _src_dentry;
21521 + a->src_inode = NULL;
21522 + if (d_really_is_positive(a->src_dentry))
21523 + a->src_inode = d_inode(a->src_dentry);
21524 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21525 + a->dst_dir = _dst_dir;
21526 + a->dst_dentry = _dst_dentry;
21527 + a->dst_inode = NULL;
21528 + if (d_really_is_positive(a->dst_dentry))
21529 + a->dst_inode = d_inode(a->dst_dentry);
21530 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21531 + if (a->dst_inode) {
21533 + * if EXCHANGE && src is non-dir && dst is dir,
21534 + * dst is not locked.
21536 + /* IMustLock(a->dst_inode); */
21537 + au_igrab(a->dst_inode);
21541 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21542 + if (d_is_dir(a->src_dentry)) {
21543 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21544 + if (unlikely(!a->exchange
21545 + && d_really_is_positive(a->dst_dentry)
21546 + && !d_is_dir(a->dst_dentry)))
21548 + lock_flags |= AuLock_DIRS;
21550 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21551 + au_fset_ren(a->auren_flags, ISDIR_DST);
21552 + if (unlikely(!a->exchange
21553 + && d_really_is_positive(a->src_dentry)
21554 + && !d_is_dir(a->src_dentry)))
21556 + lock_flags |= AuLock_DIRS;
21558 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21559 + if (unlikely(err))
21562 + err = au_d_hashed_positive(a->src_dentry);
21563 + if (unlikely(err))
21566 + if (a->dst_inode) {
21568 + * If it is a dir, VFS unhash it before this
21569 + * function. It means we cannot rely upon d_unhashed().
21571 + if (unlikely(!a->dst_inode->i_nlink))
21573 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21574 + err = au_d_hashed_positive(a->dst_dentry);
21575 + if (unlikely(err && !a->exchange))
21577 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21579 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21583 + * is it possible?
21584 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21585 + * there may exist a problem somewhere else.
21588 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21591 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21592 + di_write_lock_parent(a->dst_parent);
21594 + /* which branch we process */
21595 + err = au_ren_wbr(a);
21596 + if (unlikely(err < 0))
21598 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21599 + a->h_path.mnt = au_br_mnt(a->br);
21601 + /* are they available to be renamed */
21602 + err = au_ren_may_dir(a);
21603 + if (unlikely(err))
21604 + goto out_children;
21606 + /* prepare the writable parent dir on the same branch */
21607 + if (a->dst_btop == a->btgt) {
21608 + au_fset_ren(a->auren_flags, WHDST);
21610 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21611 + if (unlikely(err))
21612 + goto out_children;
21616 + if (!a->exchange) {
21617 + if (a->src_dir != a->dst_dir) {
21619 + * this temporary unlock is safe,
21620 + * because both dir->i_mutex are locked.
21622 + di_write_unlock(a->dst_parent);
21623 + di_write_lock_parent(a->src_parent);
21624 + err = au_wr_dir_need_wh(a->src_dentry,
21625 + au_ftest_ren(a->auren_flags,
21628 + di_write_unlock(a->src_parent);
21629 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21631 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21633 + err = au_wr_dir_need_wh(a->src_dentry,
21634 + au_ftest_ren(a->auren_flags,
21638 + if (unlikely(err < 0))
21639 + goto out_children;
21641 + au_fset_ren(a->auren_flags, WHSRC);
21644 + if (a->src_btop != a->btgt) {
21645 + err = au_pin(&pin, a->src_dentry, a->btgt,
21646 + au_opt_udba(a->src_dentry->d_sb),
21647 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21649 + struct au_cp_generic cpg = {
21650 + .dentry = a->src_dentry,
21652 + .bsrc = a->src_btop,
21655 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21657 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21658 + err = au_sio_cpup_simple(&cpg);
21661 + if (unlikely(err))
21662 + goto out_children;
21663 + a->src_btop = a->btgt;
21664 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21665 + if (!a->exchange)
21666 + au_fset_ren(a->auren_flags, WHSRC);
21670 + if (a->exchange && a->dst_inode
21671 + && a->dst_btop != a->btgt) {
21672 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21673 + au_opt_udba(a->dst_dentry->d_sb),
21674 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21676 + struct au_cp_generic cpg = {
21677 + .dentry = a->dst_dentry,
21679 + .bsrc = a->dst_btop,
21682 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21684 + err = au_sio_cpup_simple(&cpg);
21687 + if (unlikely(err))
21688 + goto out_children;
21689 + a->dst_btop = a->btgt;
21690 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21693 + /* lock them all */
21694 + err = au_ren_lock(a);
21695 + if (unlikely(err))
21696 + /* leave the copied-up one */
21697 + goto out_children;
21699 + if (!a->exchange) {
21700 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21701 + err = au_may_ren(a);
21702 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21703 + err = -ENAMETOOLONG;
21704 + if (unlikely(err))
21708 + /* store timestamps to be revertible */
21712 + err = do_rename(a);
21713 + if (unlikely(err))
21716 + /* update dir attributes */
21717 + au_ren_refresh_dir(a);
21719 + /* dput/iput all lower dentries */
21720 + au_ren_refresh(a);
21722 + goto out_hdir; /* success */
21725 + au_ren_rev_dt(err, a);
21727 + au_ren_unlock(a);
21729 + au_nhash_wh_free(&a->whlist);
21730 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21731 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21732 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21733 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21737 + if (!a->exchange)
21738 + d_move(a->src_dentry, a->dst_dentry);
21740 + d_exchange(a->src_dentry, a->dst_dentry);
21742 + au_update_dbtop(a->dst_dentry);
21743 + if (!a->dst_inode)
21744 + d_drop(a->dst_dentry);
21746 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21747 + di_write_unlock(a->dst_parent);
21749 + di_write_unlock2(a->src_parent, a->dst_parent);
21751 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21753 + iput(a->dst_inode);
21755 + au_whtmp_rmdir_free(a->thargs);
21761 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21762 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21763 +++ linux/fs/aufs/Kconfig 2017-07-29 12:14:25.896375188 +0200
21766 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21768 + Aufs is a stackable unification filesystem such as Unionfs,
21769 + which unifies several directories and provides a merged single
21771 + In the early days, aufs was entirely re-designed and
21772 + re-implemented Unionfs Version 1.x series. Introducing many
21773 + original ideas, approaches and improvements, it becomes totally
21774 + different from Unionfs while keeping the basic features.
21778 + prompt "Maximum number of branches"
21779 + default AUFS_BRANCH_MAX_127
21781 + Specifies the maximum number of branches (or member directories)
21782 + in a single aufs. The larger value consumes more system
21783 + resources and has a minor impact to performance.
21784 +config AUFS_BRANCH_MAX_127
21787 + Specifies the maximum number of branches (or member directories)
21788 + in a single aufs. The larger value consumes more system
21789 + resources and has a minor impact to performance.
21790 +config AUFS_BRANCH_MAX_511
21793 + Specifies the maximum number of branches (or member directories)
21794 + in a single aufs. The larger value consumes more system
21795 + resources and has a minor impact to performance.
21796 +config AUFS_BRANCH_MAX_1023
21799 + Specifies the maximum number of branches (or member directories)
21800 + in a single aufs. The larger value consumes more system
21801 + resources and has a minor impact to performance.
21802 +config AUFS_BRANCH_MAX_32767
21805 + Specifies the maximum number of branches (or member directories)
21806 + in a single aufs. The larger value consumes more system
21807 + resources and has a minor impact to performance.
21810 +config AUFS_SBILIST
21812 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21815 + Automatic configuration for internal use.
21816 + When aufs supports Magic SysRq or /proc, enabled automatically.
21818 +config AUFS_HNOTIFY
21819 + bool "Detect direct branch access (bypassing aufs)"
21821 + If you want to modify files on branches directly, eg. bypassing aufs,
21822 + and want aufs to detect the changes of them fully, then enable this
21823 + option and use 'udba=notify' mount option.
21824 + Currently there is only one available configuration, "fsnotify".
21825 + It will have a negative impact to the performance.
21826 + See detail in aufs.5.
21829 + prompt "method" if AUFS_HNOTIFY
21830 + default AUFS_HFSNOTIFY
21831 +config AUFS_HFSNOTIFY
21836 +config AUFS_EXPORT
21837 + bool "NFS-exportable aufs"
21838 + depends on EXPORTFS
21840 + If you want to export your mounted aufs via NFS, then enable this
21841 + option. There are several requirements for this configuration.
21842 + See detail in aufs.5.
21844 +config AUFS_INO_T_64
21846 + depends on AUFS_EXPORT
21847 + depends on 64BIT && !(ALPHA || S390)
21850 + Automatic configuration for internal use.
21851 + /* typedef unsigned long/int __kernel_ino_t */
21852 + /* alpha and s390x are int */
21855 + bool "support for XATTR/EA (including Security Labels)"
21857 + If your branch fs supports XATTR/EA and you want to make them
21858 + available in aufs too, then enable this opsion and specify the
21859 + branch attributes for EA.
21860 + See detail in aufs.5.
21863 + bool "File-based Hierarchical Storage Management"
21865 + Hierarchical Storage Management (or HSM) is a well-known feature
21866 + in the storage world. Aufs provides this feature as file-based.
21867 + with multiple branches.
21868 + These multiple branches are prioritized, ie. the topmost one
21869 + should be the fastest drive and be used heavily.
21872 + bool "Readdir in userspace"
21874 + Aufs has two methods to provide a merged view for a directory,
21875 + by a user-space library and by kernel-space natively. The latter
21876 + is always enabled but sometimes large and slow.
21877 + If you enable this option, install the library in aufs2-util
21878 + package, and set some environment variables for your readdir(3),
21879 + then the work will be handled in user-space which generally
21880 + shows better performance in most cases.
21881 + See detail in aufs.5.
21884 + bool "Show whiteouts"
21886 + If you want to make the whiteouts in aufs visible, then enable
21887 + this option and specify 'shwh' mount option. Although it may
21888 + sounds like philosophy or something, but in technically it
21889 + simply shows the name of whiteout with keeping its behaviour.
21891 +config AUFS_BR_RAMFS
21892 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21894 + If you want to use ramfs as an aufs branch fs, then enable this
21895 + option. Generally tmpfs is recommended.
21896 + Aufs prohibited them to be a branch fs by default, because
21897 + initramfs becomes unusable after switch_root or something
21898 + generally. If you sets initramfs as an aufs branch and boot your
21899 + system by switch_root, you will meet a problem easily since the
21900 + files in initramfs may be inaccessible.
21901 + Unless you are going to use ramfs as an aufs branch fs without
21902 + switch_root or something, leave it N.
21904 +config AUFS_BR_FUSE
21905 + bool "Fuse fs as an aufs branch"
21906 + depends on FUSE_FS
21909 + If you want to use fuse-based userspace filesystem as an aufs
21910 + branch fs, then enable this option.
21911 + It implements the internal poll(2) operation which is
21912 + implemented by fuse only (curretnly).
21917 + Automatic configuration for internal use.
21919 +config AUFS_BR_HFSPLUS
21920 + bool "Hfsplus as an aufs branch"
21921 + depends on HFSPLUS_FS
21924 + If you want to use hfsplus fs as an aufs branch fs, then enable
21925 + this option. This option introduces a small overhead at
21926 + copying-up a file on hfsplus.
21928 +config AUFS_BDEV_LOOP
21930 + depends on BLK_DEV_LOOP
21933 + Automatic configuration for internal use.
21934 + Convert =[ym] into =y.
21937 + bool "Debug aufs"
21939 + Enable this to compile aufs internal debug code.
21940 + It will have a negative impact to the performance.
21942 +config AUFS_MAGIC_SYSRQ
21944 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21947 + Automatic configuration for internal use.
21948 + When aufs supports Magic SysRq, enabled automatically.
21950 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21951 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21952 +++ linux/fs/aufs/loop.c 2017-07-29 12:14:25.903042072 +0200
21955 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21957 + * This program, aufs is free software; you can redistribute it and/or modify
21958 + * it under the terms of the GNU General Public License as published by
21959 + * the Free Software Foundation; either version 2 of the License, or
21960 + * (at your option) any later version.
21962 + * This program is distributed in the hope that it will be useful,
21963 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21964 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21965 + * GNU General Public License for more details.
21967 + * You should have received a copy of the GNU General Public License
21968 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21972 + * support for loopback block device as a branch
21977 +/* added into drivers/block/loop.c */
21978 +static struct file *(*backing_file_func)(struct super_block *sb);
21981 + * test if two lower dentries have overlapping branches.
21983 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21985 + struct super_block *h_sb;
21986 + struct file *backing_file;
21988 + if (unlikely(!backing_file_func)) {
21989 + /* don't load "loop" module here */
21990 + backing_file_func = symbol_get(loop_backing_file);
21991 + if (unlikely(!backing_file_func))
21992 + /* "loop" module is not loaded */
21996 + h_sb = h_adding->d_sb;
21997 + backing_file = backing_file_func(h_sb);
21998 + if (!backing_file)
22001 + h_adding = backing_file->f_path.dentry;
22003 + * h_adding can be local NFS.
22004 + * in this case aufs cannot detect the loop.
22006 + if (unlikely(h_adding->d_sb == sb))
22008 + return !!au_test_subdir(h_adding, sb->s_root);
22011 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
22012 +int au_test_loopback_kthread(void)
22015 + struct task_struct *tsk = current;
22016 + char c, comm[sizeof(tsk->comm)];
22019 + if (tsk->flags & PF_KTHREAD) {
22020 + get_task_comm(comm, tsk);
22022 + ret = ('0' <= c && c <= '9'
22023 + && !strncmp(comm, "loop", 4));
22029 +/* ---------------------------------------------------------------------- */
22031 +#define au_warn_loopback_step 16
22032 +static int au_warn_loopback_nelem = au_warn_loopback_step;
22033 +static unsigned long *au_warn_loopback_array;
22035 +void au_warn_loopback(struct super_block *h_sb)
22037 + int i, new_nelem;
22038 + unsigned long *a, magic;
22039 + static DEFINE_SPINLOCK(spin);
22041 + magic = h_sb->s_magic;
22042 + spin_lock(&spin);
22043 + a = au_warn_loopback_array;
22044 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
22045 + if (a[i] == magic) {
22046 + spin_unlock(&spin);
22050 + /* h_sb is new to us, print it */
22051 + if (i < au_warn_loopback_nelem) {
22056 + /* expand the array */
22057 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
22058 + a = au_kzrealloc(au_warn_loopback_array,
22059 + au_warn_loopback_nelem * sizeof(unsigned long),
22060 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
22061 + /*may_shrink*/0);
22063 + au_warn_loopback_nelem = new_nelem;
22064 + au_warn_loopback_array = a;
22069 + spin_unlock(&spin);
22070 + AuWarn1("realloc failed, ignored\n");
22074 + spin_unlock(&spin);
22075 + pr_warn("you may want to try another patch for loopback file "
22076 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
22079 +int au_loopback_init(void)
22082 + struct super_block *sb __maybe_unused;
22084 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
22087 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
22088 + sizeof(unsigned long), GFP_NOFS);
22089 + if (unlikely(!au_warn_loopback_array))
22095 +void au_loopback_fin(void)
22097 + if (backing_file_func)
22098 + symbol_put(loop_backing_file);
22099 + kfree(au_warn_loopback_array);
22101 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
22102 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
22103 +++ linux/fs/aufs/loop.h 2017-07-29 12:14:25.903042072 +0200
22106 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22108 + * This program, aufs is free software; you can redistribute it and/or modify
22109 + * it under the terms of the GNU General Public License as published by
22110 + * the Free Software Foundation; either version 2 of the License, or
22111 + * (at your option) any later version.
22113 + * This program is distributed in the hope that it will be useful,
22114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22116 + * GNU General Public License for more details.
22118 + * You should have received a copy of the GNU General Public License
22119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22123 + * support for loopback mount as a branch
22126 +#ifndef __AUFS_LOOP_H__
22127 +#define __AUFS_LOOP_H__
22132 +struct super_block;
22134 +#ifdef CONFIG_AUFS_BDEV_LOOP
22135 +/* drivers/block/loop.c */
22136 +struct file *loop_backing_file(struct super_block *sb);
22139 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
22140 +int au_test_loopback_kthread(void);
22141 +void au_warn_loopback(struct super_block *h_sb);
22143 +int au_loopback_init(void);
22144 +void au_loopback_fin(void);
22146 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
22147 + struct dentry *h_adding)
22148 +AuStubInt0(au_test_loopback_kthread, void)
22149 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
22151 +AuStubInt0(au_loopback_init, void)
22152 +AuStubVoid(au_loopback_fin, void)
22153 +#endif /* BLK_DEV_LOOP */
22155 +#endif /* __KERNEL__ */
22156 +#endif /* __AUFS_LOOP_H__ */
22157 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
22158 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
22159 +++ linux/fs/aufs/magic.mk 2017-07-29 12:14:25.903042072 +0200
22162 +# defined in ${srctree}/fs/fuse/inode.c
22164 +ifdef CONFIG_FUSE_FS
22165 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
22168 +# defined in ${srctree}/fs/xfs/xfs_sb.h
22170 +ifdef CONFIG_XFS_FS
22171 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
22174 +# defined in ${srctree}/fs/configfs/mount.c
22176 +ifdef CONFIG_CONFIGFS_FS
22177 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
22180 +# defined in ${srctree}/fs/ubifs/ubifs.h
22182 +ifdef CONFIG_UBIFS_FS
22183 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
22186 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22188 +ifdef CONFIG_HFSPLUS_FS
22189 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22191 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22192 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22193 +++ linux/fs/aufs/Makefile 2017-07-29 12:14:25.896375188 +0200
22196 +include ${src}/magic.mk
22197 +ifeq (${CONFIG_AUFS_FS},m)
22198 +include ${src}/conf.mk
22200 +-include ${src}/priv_def.mk
22202 +# cf. include/linux/kernel.h
22204 +ccflags-y += -DDEBUG
22205 +# sparse requires the full pathname
22207 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22209 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22212 +obj-$(CONFIG_AUFS_FS) += aufs.o
22213 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22214 + wkq.o vfsub.o dcsub.o \
22215 + cpup.o whout.o wbr_policy.o \
22216 + dinfo.o dentry.o \
22218 + finfo.o file.o f_op.o \
22220 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22224 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22225 +aufs-$(CONFIG_SYSFS) += sysfs.o
22226 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22227 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22228 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22229 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22230 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22231 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22232 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22233 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22234 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22235 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22236 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22237 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22238 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22239 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22240 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22241 +++ linux/fs/aufs/module.c 2017-07-29 12:14:25.903042072 +0200
22244 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22246 + * This program, aufs is free software; you can redistribute it and/or modify
22247 + * it under the terms of the GNU General Public License as published by
22248 + * the Free Software Foundation; either version 2 of the License, or
22249 + * (at your option) any later version.
22251 + * This program is distributed in the hope that it will be useful,
22252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22254 + * GNU General Public License for more details.
22256 + * You should have received a copy of the GNU General Public License
22257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22261 + * module global variables and operations
22264 +#include <linux/module.h>
22265 +#include <linux/seq_file.h>
22268 +/* shrinkable realloc */
22269 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22277 +#if 0 /* unused */
22284 + AuDebugOn(!new_sz);
22287 + diff = au_kmidx_sub(sz, new_sz);
22293 + /* expand or SLOB */
22294 + p = krealloc(p, new_sz, gfp);
22295 + else if (new_sz < sz && may_shrink) {
22299 + q = kmalloc(new_sz, gfp);
22302 + memcpy(q, p, new_sz);
22314 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22317 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22318 + if (p && new_sz > nused)
22319 + memset(p + nused, 0, new_sz - nused);
22323 +/* ---------------------------------------------------------------------- */
22327 +struct kmem_cache *au_cache[AuCache_Last];
22329 +static void au_cache_fin(void)
22334 + * Make sure all delayed rcu free inodes are flushed before we
22339 + /* excluding AuCache_HNOTIFY */
22340 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22341 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22342 + kmem_cache_destroy(au_cache[i]);
22343 + au_cache[i] = NULL;
22347 +static int __init au_cache_init(void)
22349 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
22350 + if (au_cache[AuCache_DINFO])
22351 + /* SLAB_DESTROY_BY_RCU */
22352 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
22353 + au_icntnr_init_once);
22354 + if (au_cache[AuCache_ICNTNR])
22355 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
22356 + au_fi_init_once);
22357 + if (au_cache[AuCache_FINFO])
22358 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
22359 + if (au_cache[AuCache_VDIR])
22360 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
22361 + if (au_cache[AuCache_DEHSTR])
22368 +/* ---------------------------------------------------------------------- */
22370 +int au_dir_roflags;
22372 +#ifdef CONFIG_AUFS_SBILIST
22374 + * iterate_supers_type() doesn't protect us from
22375 + * remounting (branch management)
22377 +struct au_sphlhead au_sbilist;
22381 + * functions for module interface.
22383 +MODULE_LICENSE("GPL");
22384 +/* MODULE_LICENSE("GPL v2"); */
22385 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22386 +MODULE_DESCRIPTION(AUFS_NAME
22387 + " -- Advanced multi layered unification filesystem");
22388 +MODULE_VERSION(AUFS_VERSION);
22389 +MODULE_ALIAS_FS(AUFS_NAME);
22391 +/* this module parameter has no meaning when SYSFS is disabled */
22392 +int sysaufs_brs = 1;
22393 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22394 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22396 +/* this module parameter has no meaning when USER_NS is disabled */
22398 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22399 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22401 +/* ---------------------------------------------------------------------- */
22403 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22405 +int au_seq_path(struct seq_file *seq, struct path *path)
22409 + err = seq_path(seq, path, au_esc_chars);
22418 +/* ---------------------------------------------------------------------- */
22420 +static int __init aufs_init(void)
22425 + p = au_esc_chars;
22426 + for (i = 1; i <= ' '; i++)
22432 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22434 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22435 + for (i = 0; i < AuIop_Last; i++)
22436 + aufs_iop_nogetattr[i].getattr = NULL;
22438 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
22440 + au_sbilist_init();
22441 + sysaufs_brs_init();
22444 + err = sysaufs_init();
22445 + if (unlikely(err))
22447 + err = au_procfs_init();
22448 + if (unlikely(err))
22449 + goto out_sysaufs;
22450 + err = au_wkq_init();
22451 + if (unlikely(err))
22453 + err = au_loopback_init();
22454 + if (unlikely(err))
22456 + err = au_hnotify_init();
22457 + if (unlikely(err))
22458 + goto out_loopback;
22459 + err = au_sysrq_init();
22460 + if (unlikely(err))
22462 + err = au_cache_init();
22463 + if (unlikely(err))
22466 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22467 + err = register_filesystem(&aufs_fs_type);
22468 + if (unlikely(err))
22471 + /* since we define pr_fmt, call printk directly */
22472 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22473 + goto out; /* success */
22480 + au_hnotify_fin();
22482 + au_loopback_fin();
22494 +static void __exit aufs_exit(void)
22496 + unregister_filesystem(&aufs_fs_type);
22499 + au_hnotify_fin();
22500 + au_loopback_fin();
22507 +module_init(aufs_init);
22508 +module_exit(aufs_exit);
22509 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22510 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22511 +++ linux/fs/aufs/module.h 2017-07-29 12:14:25.903042072 +0200
22514 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22516 + * This program, aufs is free software; you can redistribute it and/or modify
22517 + * it under the terms of the GNU General Public License as published by
22518 + * the Free Software Foundation; either version 2 of the License, or
22519 + * (at your option) any later version.
22521 + * This program is distributed in the hope that it will be useful,
22522 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22523 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22524 + * GNU General Public License for more details.
22526 + * You should have received a copy of the GNU General Public License
22527 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22531 + * module initialization and module-global
22534 +#ifndef __AUFS_MODULE_H__
22535 +#define __AUFS_MODULE_H__
22539 +#include <linux/slab.h>
22544 +/* module parameters */
22545 +extern int sysaufs_brs;
22546 +extern bool au_userns;
22548 +/* ---------------------------------------------------------------------- */
22550 +extern int au_dir_roflags;
22552 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22553 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22556 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22558 +#ifndef CONFIG_SLOB
22559 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22561 + return -1; /* SLOB is untested */
22565 +int au_seq_path(struct seq_file *seq, struct path *path);
22567 +#ifdef CONFIG_PROC_FS
22569 +int __init au_procfs_init(void);
22570 +void au_procfs_fin(void);
22572 +AuStubInt0(au_procfs_init, void);
22573 +AuStubVoid(au_procfs_fin, void);
22576 +/* ---------------------------------------------------------------------- */
22585 + AuCache_HNOTIFY, /* must be last */
22589 +extern struct kmem_cache *au_cache[AuCache_Last];
22591 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22592 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22593 +#define AuCacheCtor(type, ctor) \
22594 + kmem_cache_create(#type, sizeof(struct type), \
22595 + __alignof__(struct type), AuCacheFlags, ctor)
22597 +#define AuCacheFuncs(name, index) \
22598 +static inline struct au_##name *au_cache_alloc_##name(void) \
22599 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
22600 +static inline void au_cache_free_##name(struct au_##name *p) \
22601 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
22603 +AuCacheFuncs(dinfo, DINFO);
22604 +AuCacheFuncs(icntnr, ICNTNR);
22605 +AuCacheFuncs(finfo, FINFO);
22606 +AuCacheFuncs(vdir, VDIR);
22607 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22608 +#ifdef CONFIG_AUFS_HNOTIFY
22609 +AuCacheFuncs(hnotify, HNOTIFY);
22612 +#endif /* __KERNEL__ */
22613 +#endif /* __AUFS_MODULE_H__ */
22614 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22615 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22616 +++ linux/fs/aufs/mvdown.c 2017-07-29 12:14:25.903042072 +0200
22619 + * Copyright (C) 2011-2017 Junjiro R. Okajima
22621 + * This program, aufs is free software; you can redistribute it and/or modify
22622 + * it under the terms of the GNU General Public License as published by
22623 + * the Free Software Foundation; either version 2 of the License, or
22624 + * (at your option) any later version.
22626 + * This program is distributed in the hope that it will be useful,
22627 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22628 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22629 + * GNU General Public License for more details.
22631 + * You should have received a copy of the GNU General Public License
22632 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22636 + * move-down, opposite of copy-up
22641 +struct au_mvd_args {
22643 + struct super_block *h_sb;
22644 + struct dentry *h_parent;
22645 + struct au_hinode *hdir;
22646 + struct inode *h_dir, *h_inode;
22647 + struct au_pin pin;
22648 + } info[AUFS_MVDOWN_NARRAY];
22650 + struct aufs_mvdown mvdown;
22651 + struct dentry *dentry, *parent;
22652 + struct inode *inode, *dir;
22653 + struct super_block *sb;
22654 + aufs_bindex_t bopq, bwh, bfound;
22655 + unsigned char rename_lock;
22658 +#define mvd_errno mvdown.au_errno
22659 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22660 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22661 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22662 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22664 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22665 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22666 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22667 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22668 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22669 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22671 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22672 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22673 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22674 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22675 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22676 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22678 +#define AU_MVD_PR(flag, ...) do { \
22680 + pr_err(__VA_ARGS__); \
22683 +static int find_lower_writable(struct au_mvd_args *a)
22685 + struct super_block *sb;
22686 + aufs_bindex_t bindex, bbot;
22687 + struct au_branch *br;
22690 + bindex = a->mvd_bsrc;
22691 + bbot = au_sbbot(sb);
22692 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22693 + for (bindex++; bindex <= bbot; bindex++) {
22694 + br = au_sbr(sb, bindex);
22695 + if (au_br_fhsm(br->br_perm)
22696 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22699 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22700 + for (bindex++; bindex <= bbot; bindex++) {
22701 + br = au_sbr(sb, bindex);
22702 + if (!au_br_rdonly(br))
22706 + for (bindex++; bindex <= bbot; bindex++) {
22707 + br = au_sbr(sb, bindex);
22708 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22709 + if (au_br_rdonly(br))
22711 + |= AUFS_MVDOWN_ROLOWER_R;
22719 +/* make the parent dir on bdst */
22720 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22725 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22726 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22727 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22728 + a->mvd_h_dst_parent = NULL;
22729 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22730 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22731 + if (!a->mvd_h_dst_parent) {
22732 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22733 + if (unlikely(err)) {
22734 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22737 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22745 +/* lock them all */
22746 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22749 + struct dentry *h_trap;
22751 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22752 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22753 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22754 + au_opt_udba(a->sb),
22755 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22757 + if (unlikely(err)) {
22758 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22762 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22763 + a->rename_lock = 0;
22764 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22765 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22766 + au_opt_udba(a->sb),
22767 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22768 + err = au_do_pin(&a->mvd_pin_src);
22770 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22771 + if (unlikely(err)) {
22772 + AU_MVD_PR(dmsg, "pin_src failed\n");
22775 + goto out; /* success */
22778 + a->rename_lock = 1;
22779 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22780 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22781 + au_opt_udba(a->sb),
22782 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22784 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22785 + if (unlikely(err)) {
22786 + AU_MVD_PR(dmsg, "pin_src failed\n");
22787 + au_pin_hdir_lock(&a->mvd_pin_dst);
22790 + au_pin_hdir_unlock(&a->mvd_pin_src);
22791 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22792 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22794 + err = (h_trap != a->mvd_h_src_parent);
22796 + err = (h_trap != a->mvd_h_dst_parent);
22798 + BUG_ON(err); /* it should never happen */
22799 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22802 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22803 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22804 + au_pin_hdir_lock(&a->mvd_pin_src);
22805 + au_unpin(&a->mvd_pin_src);
22806 + au_pin_hdir_lock(&a->mvd_pin_dst);
22809 + goto out; /* success */
22812 + au_unpin(&a->mvd_pin_dst);
22818 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22820 + if (!a->rename_lock)
22821 + au_unpin(&a->mvd_pin_src);
22823 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22824 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22825 + au_pin_hdir_lock(&a->mvd_pin_src);
22826 + au_unpin(&a->mvd_pin_src);
22827 + au_pin_hdir_lock(&a->mvd_pin_dst);
22829 + au_unpin(&a->mvd_pin_dst);
22832 +/* copy-down the file */
22833 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22836 + struct au_cp_generic cpg = {
22837 + .dentry = a->dentry,
22838 + .bdst = a->mvd_bdst,
22839 + .bsrc = a->mvd_bsrc,
22841 + .pin = &a->mvd_pin_dst,
22842 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22845 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22846 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22847 + au_fset_cpup(cpg.flags, OVERWRITE);
22848 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22849 + au_fset_cpup(cpg.flags, RWDST);
22850 + err = au_sio_cpdown_simple(&cpg);
22851 + if (unlikely(err))
22852 + AU_MVD_PR(dmsg, "cpdown failed\n");
22859 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22862 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22865 + struct path h_path;
22866 + struct au_branch *br;
22867 + struct inode *delegated;
22869 + br = au_sbr(a->sb, a->mvd_bdst);
22870 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22871 + err = PTR_ERR(h_path.dentry);
22872 + if (IS_ERR(h_path.dentry)) {
22873 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22878 + if (d_is_positive(h_path.dentry)) {
22879 + h_path.mnt = au_br_mnt(br);
22880 + delegated = NULL;
22881 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22882 + &delegated, /*force*/0);
22883 + if (unlikely(err == -EWOULDBLOCK)) {
22884 + pr_warn("cannot retry for NFSv4 delegation"
22885 + " for an internal unlink\n");
22888 + if (unlikely(err))
22889 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22891 + dput(h_path.dentry);
22899 + * unlink the topmost h_dentry
22901 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22904 + struct path h_path;
22905 + struct inode *delegated;
22907 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22908 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22909 + delegated = NULL;
22910 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22911 + if (unlikely(err == -EWOULDBLOCK)) {
22912 + pr_warn("cannot retry for NFSv4 delegation"
22913 + " for an internal unlink\n");
22916 + if (unlikely(err))
22917 + AU_MVD_PR(dmsg, "unlink failed\n");
22923 +/* Since mvdown succeeded, we ignore an error of this function */
22924 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22927 + struct au_branch *br;
22929 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22930 + br = au_sbr(a->sb, a->mvd_bsrc);
22931 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22933 + br = au_sbr(a->sb, a->mvd_bdst);
22934 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22935 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22938 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22940 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22944 + * copy-down the file and unlink the bsrc file.
22945 + * - unlink the bdst whout if exist
22946 + * - copy-down the file (with whtmp name and rename)
22947 + * - unlink the bsrc file
22949 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22953 + err = au_do_mkdir(dmsg, a);
22955 + err = au_do_lock(dmsg, a);
22956 + if (unlikely(err))
22960 + * do not revert the activities we made on bdst since they should be
22961 + * harmless in aufs.
22964 + err = au_do_cpdown(dmsg, a);
22966 + err = au_do_unlink_wh(dmsg, a);
22967 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22968 + err = au_do_unlink(dmsg, a);
22969 + if (unlikely(err))
22972 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22973 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22974 + if (find_lower_writable(a) < 0)
22975 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22977 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22978 + au_do_stfs(dmsg, a);
22980 + /* maintain internal array */
22981 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22982 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22983 + au_set_dbtop(a->dentry, a->mvd_bdst);
22984 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22985 + au_set_ibtop(a->inode, a->mvd_bdst);
22987 + /* hide the lower */
22988 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22989 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22990 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22991 + au_set_ibbot(a->inode, a->mvd_bsrc);
22993 + if (au_dbbot(a->dentry) < a->mvd_bdst)
22994 + au_set_dbbot(a->dentry, a->mvd_bdst);
22995 + if (au_ibbot(a->inode) < a->mvd_bdst)
22996 + au_set_ibbot(a->inode, a->mvd_bdst);
22999 + au_do_unlock(dmsg, a);
23005 +/* ---------------------------------------------------------------------- */
23007 +/* make sure the file is idle */
23008 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
23010 + int err, plinked;
23013 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
23014 + if (au_dbtop(a->dentry) == a->mvd_bsrc
23015 + && au_dcount(a->dentry) == 1
23016 + && atomic_read(&a->inode->i_count) == 1
23017 + /* && a->mvd_h_src_inode->i_nlink == 1 */
23018 + && (!plinked || !au_plink_test(a->inode))
23019 + && a->inode->i_nlink == 1)
23024 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
23025 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
23026 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
23027 + a->mvd_h_src_inode->i_nlink,
23028 + plinked, plinked ? au_plink_test(a->inode) : 0);
23035 +/* make sure the parent dir is fine */
23036 +static int au_mvd_args_parent(const unsigned char dmsg,
23037 + struct au_mvd_args *a)
23040 + aufs_bindex_t bindex;
23043 + if (unlikely(au_alive_dir(a->parent))) {
23045 + AU_MVD_PR(dmsg, "parent dir is dead\n");
23049 + a->bopq = au_dbdiropq(a->parent);
23050 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
23051 + AuDbg("b%d\n", bindex);
23052 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
23053 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
23055 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
23056 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
23057 + a->bopq, a->mvd_bdst);
23065 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23066 + struct au_mvd_args *a)
23069 + struct au_dinfo *dinfo, *tmp;
23071 + /* lookup the next lower positive entry */
23073 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23074 + if (unlikely(!tmp))
23079 + dinfo = au_di(a->dentry);
23080 + au_di_cp(tmp, dinfo);
23081 + au_di_swap(tmp, dinfo);
23083 + /* returns the number of positive dentries */
23084 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23085 + /* AuLkup_IGNORE_PERM */ 0);
23087 + a->bwh = au_dbwh(a->dentry);
23088 + else if (err > 0)
23089 + a->bfound = au_dbtop(a->dentry);
23091 + au_di_swap(tmp, dinfo);
23092 + au_rw_write_unlock(&tmp->di_rwsem);
23094 + if (unlikely(err < 0))
23095 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23098 + * here, we have these cases.
23100 + * no positive dentry under bsrc. there are more sub-cases.
23102 + * there no whiteout, we can safely move-down.
23105 + * bsrc < bwh && bwh < bdst
23106 + * there is a whiteout on RO branch. cannot proceed.
23108 + * there is a whiteout on the RW target branch. it should
23111 + * there is a whiteout somewhere unrelated branch.
23112 + * -1 < bfound && bfound <= bsrc
23115 + * found, but it is on RO branch between bsrc and bdst. cannot
23118 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23121 + * found, after we create the file on bdst, it will be hidden.
23124 + AuDebugOn(a->bfound == -1
23126 + && a->bwh <= a->mvd_bsrc);
23127 + AuDebugOn(-1 < a->bfound
23128 + && a->bfound <= a->mvd_bsrc);
23131 + if (a->bfound == -1
23132 + && a->mvd_bsrc < a->bwh
23134 + && a->bwh < a->mvd_bdst) {
23135 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23136 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23137 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23139 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23140 + a->mvd_errno = EAU_MVDOWN_UPPER;
23141 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23142 + a->mvd_bdst, a->bfound);
23146 + err = 0; /* success */
23153 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23158 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23159 + && a->bfound == a->mvd_bdst)
23165 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23168 + struct au_branch *br;
23171 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23175 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23176 + a->mvd_bsrc = au_ibtop(a->inode);
23178 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23179 + if (unlikely(a->mvd_bsrc < 0
23180 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23181 + || au_dbbot(a->dentry) < a->mvd_bsrc
23182 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23183 + || (a->mvd_bsrc < au_ibtop(a->inode)
23184 + || au_ibbot(a->inode) < a->mvd_bsrc
23185 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23186 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23187 + AU_MVD_PR(dmsg, "no upper\n");
23191 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23192 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23193 + AU_MVD_PR(dmsg, "on the bottom\n");
23196 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23197 + br = au_sbr(a->sb, a->mvd_bsrc);
23198 + err = au_br_rdonly(br);
23199 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23200 + if (unlikely(err))
23202 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23203 + || IS_APPEND(a->mvd_h_src_inode))) {
23205 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23211 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23212 + a->mvd_bdst = find_lower_writable(a);
23213 + if (unlikely(a->mvd_bdst < 0)) {
23214 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23215 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23219 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23220 + if (unlikely(a->mvd_bdst < 0
23221 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23222 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23223 + AU_MVD_PR(dmsg, "no lower brid\n");
23228 + err = au_mvd_args_busy(dmsg, a);
23230 + err = au_mvd_args_parent(dmsg, a);
23232 + err = au_mvd_args_intermediate(dmsg, a);
23234 + err = au_mvd_args_exist(dmsg, a);
23236 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23243 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23246 + unsigned char dmsg;
23247 + struct au_mvd_args *args;
23248 + struct inode *inode;
23250 + inode = d_inode(dentry);
23252 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23256 + args = kmalloc(sizeof(*args), GFP_NOFS);
23257 + if (unlikely(!args))
23260 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23262 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23263 + if (unlikely(err)) {
23268 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23269 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23270 + args->mvdown.au_errno = 0;
23271 + args->dentry = dentry;
23272 + args->inode = inode;
23273 + args->sb = dentry->d_sb;
23276 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23277 + args->parent = dget_parent(dentry);
23278 + args->dir = d_inode(args->parent);
23279 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23280 + dput(args->parent);
23281 + if (unlikely(args->parent != dentry->d_parent)) {
23282 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23286 + inode_lock_nested(inode, I_MUTEX_CHILD);
23287 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23288 + if (unlikely(err))
23291 + di_write_lock_parent(args->parent);
23292 + err = au_mvd_args(dmsg, args);
23293 + if (unlikely(err))
23296 + err = au_do_mvdown(dmsg, args);
23297 + if (unlikely(err))
23300 + au_cpup_attr_timesizes(args->dir);
23301 + au_cpup_attr_timesizes(inode);
23302 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23303 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23304 + /* au_digen_dec(dentry); */
23307 + di_write_unlock(args->parent);
23308 + aufs_read_unlock(dentry, AuLock_DW);
23310 + inode_unlock(inode);
23312 + inode_unlock(args->dir);
23314 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23322 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23323 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23324 +++ linux/fs/aufs/opts.c 2017-07-29 12:14:25.903042072 +0200
23327 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23329 + * This program, aufs is free software; you can redistribute it and/or modify
23330 + * it under the terms of the GNU General Public License as published by
23331 + * the Free Software Foundation; either version 2 of the License, or
23332 + * (at your option) any later version.
23334 + * This program is distributed in the hope that it will be useful,
23335 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23336 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23337 + * GNU General Public License for more details.
23339 + * You should have received a copy of the GNU General Public License
23340 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23344 + * mount options/flags
23347 +#include <linux/namei.h>
23348 +#include <linux/types.h> /* a distribution requires */
23349 +#include <linux/parser.h>
23352 +/* ---------------------------------------------------------------------- */
23356 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23357 + Opt_idel, Opt_imod,
23358 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23359 + Opt_rdblk_def, Opt_rdhash_def,
23360 + Opt_xino, Opt_noxino,
23361 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23362 + Opt_trunc_xino_path, Opt_itrunc_xino,
23363 + Opt_trunc_xib, Opt_notrunc_xib,
23364 + Opt_shwh, Opt_noshwh,
23365 + Opt_plink, Opt_noplink, Opt_list_plink,
23367 + Opt_dio, Opt_nodio,
23368 + Opt_diropq_a, Opt_diropq_w,
23369 + Opt_warn_perm, Opt_nowarn_perm,
23370 + Opt_wbr_copyup, Opt_wbr_create,
23372 + Opt_verbose, Opt_noverbose,
23373 + Opt_sum, Opt_nosum, Opt_wsum,
23374 + Opt_dirperm1, Opt_nodirperm1,
23375 + Opt_acl, Opt_noacl,
23376 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23379 +static match_table_t options = {
23380 + {Opt_br, "br=%s"},
23381 + {Opt_br, "br:%s"},
23383 + {Opt_add, "add=%d:%s"},
23384 + {Opt_add, "add:%d:%s"},
23385 + {Opt_add, "ins=%d:%s"},
23386 + {Opt_add, "ins:%d:%s"},
23387 + {Opt_append, "append=%s"},
23388 + {Opt_append, "append:%s"},
23389 + {Opt_prepend, "prepend=%s"},
23390 + {Opt_prepend, "prepend:%s"},
23392 + {Opt_del, "del=%s"},
23393 + {Opt_del, "del:%s"},
23394 + /* {Opt_idel, "idel:%d"}, */
23395 + {Opt_mod, "mod=%s"},
23396 + {Opt_mod, "mod:%s"},
23397 + /* {Opt_imod, "imod:%d:%s"}, */
23399 + {Opt_dirwh, "dirwh=%d"},
23401 + {Opt_xino, "xino=%s"},
23402 + {Opt_noxino, "noxino"},
23403 + {Opt_trunc_xino, "trunc_xino"},
23404 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23405 + {Opt_notrunc_xino, "notrunc_xino"},
23406 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23407 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23408 + /* {Opt_zxino, "zxino=%s"}, */
23409 + {Opt_trunc_xib, "trunc_xib"},
23410 + {Opt_notrunc_xib, "notrunc_xib"},
23412 +#ifdef CONFIG_PROC_FS
23413 + {Opt_plink, "plink"},
23415 + {Opt_ignore_silent, "plink"},
23418 + {Opt_noplink, "noplink"},
23420 +#ifdef CONFIG_AUFS_DEBUG
23421 + {Opt_list_plink, "list_plink"},
23424 + {Opt_udba, "udba=%s"},
23426 + {Opt_dio, "dio"},
23427 + {Opt_nodio, "nodio"},
23429 +#ifdef CONFIG_AUFS_FHSM
23430 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23432 + {Opt_ignore_silent, "fhsm_sec=%d"},
23435 + {Opt_diropq_a, "diropq=always"},
23436 + {Opt_diropq_a, "diropq=a"},
23437 + {Opt_diropq_w, "diropq=whiteouted"},
23438 + {Opt_diropq_w, "diropq=w"},
23440 + {Opt_warn_perm, "warn_perm"},
23441 + {Opt_nowarn_perm, "nowarn_perm"},
23443 + /* keep them temporary */
23444 + {Opt_ignore_silent, "nodlgt"},
23445 + {Opt_ignore_silent, "clean_plink"},
23447 +#ifdef CONFIG_AUFS_SHWH
23448 + {Opt_shwh, "shwh"},
23450 + {Opt_noshwh, "noshwh"},
23452 + {Opt_dirperm1, "dirperm1"},
23453 + {Opt_nodirperm1, "nodirperm1"},
23455 + {Opt_verbose, "verbose"},
23456 + {Opt_verbose, "v"},
23457 + {Opt_noverbose, "noverbose"},
23458 + {Opt_noverbose, "quiet"},
23459 + {Opt_noverbose, "q"},
23460 + {Opt_noverbose, "silent"},
23462 + {Opt_sum, "sum"},
23463 + {Opt_nosum, "nosum"},
23464 + {Opt_wsum, "wsum"},
23466 + {Opt_rdcache, "rdcache=%d"},
23467 + {Opt_rdblk, "rdblk=%d"},
23468 + {Opt_rdblk_def, "rdblk=def"},
23469 + {Opt_rdhash, "rdhash=%d"},
23470 + {Opt_rdhash_def, "rdhash=def"},
23472 + {Opt_wbr_create, "create=%s"},
23473 + {Opt_wbr_create, "create_policy=%s"},
23474 + {Opt_wbr_copyup, "cpup=%s"},
23475 + {Opt_wbr_copyup, "copyup=%s"},
23476 + {Opt_wbr_copyup, "copyup_policy=%s"},
23478 + /* generic VFS flag */
23479 +#ifdef CONFIG_FS_POSIX_ACL
23480 + {Opt_acl, "acl"},
23481 + {Opt_noacl, "noacl"},
23483 + {Opt_ignore_silent, "acl"},
23484 + {Opt_ignore_silent, "noacl"},
23487 + /* internal use for the scripts */
23488 + {Opt_ignore_silent, "si=%s"},
23490 + {Opt_br, "dirs=%s"},
23491 + {Opt_ignore, "debug=%d"},
23492 + {Opt_ignore, "delete=whiteout"},
23493 + {Opt_ignore, "delete=all"},
23494 + {Opt_ignore, "imap=%s"},
23496 + /* temporary workaround, due to old mount(8)? */
23497 + {Opt_ignore_silent, "relatime"},
23502 +/* ---------------------------------------------------------------------- */
23504 +static const char *au_parser_pattern(int val, match_table_t tbl)
23506 + struct match_token *p;
23509 + while (p->pattern) {
23510 + if (p->token == val)
23511 + return p->pattern;
23518 +static const char *au_optstr(int *val, match_table_t tbl)
23520 + struct match_token *p;
23527 + while (p->pattern) {
23529 + && (v & p->token) == p->token) {
23530 + *val &= ~p->token;
23531 + return p->pattern;
23540 +/* ---------------------------------------------------------------------- */
23542 +static match_table_t brperm = {
23543 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23544 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23545 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23549 +static match_table_t brattr = {
23551 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23552 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23553 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23554 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23555 +#ifdef CONFIG_AUFS_FHSM
23556 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23558 +#ifdef CONFIG_AUFS_XATTR
23559 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23560 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23561 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23562 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23563 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23564 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23567 + /* ro/rr branch */
23568 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23571 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23572 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23577 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23584 + p = strchr(str, '+');
23587 + v = match_token(str, table, args);
23589 + if (v & AuBrAttr_CMOO_Mask)
23590 + attr &= ~AuBrAttr_CMOO_Mask;
23595 + pr_warn("ignored branch attribute %s\n", str);
23605 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23613 + p = au_optstr(&perm, brattr);
23616 + memcpy(q, p, sz + 1);
23622 + p = au_optstr(&perm, brattr);
23626 + memcpy(q, p, sz + 1);
23632 + return q - str->a;
23635 +static int noinline_for_stack br_perm_val(char *perm)
23637 + int val, bad, sz;
23639 + substring_t args[MAX_OPT_ARGS];
23640 + au_br_perm_str_t attr;
23642 + p = strchr(perm, '+');
23645 + val = match_token(perm, brperm, args);
23649 + pr_warn("ignored branch permission %s\n", perm);
23650 + val = AuBrPerm_RO;
23656 + val |= br_attr_val(p + 1, brattr, args);
23659 + switch (val & AuBrPerm_Mask) {
23660 + case AuBrPerm_RO:
23661 + case AuBrPerm_RR:
23662 + bad = val & AuBrWAttr_Mask;
23663 + val &= ~AuBrWAttr_Mask;
23665 + case AuBrPerm_RW:
23666 + bad = val & AuBrRAttr_Mask;
23667 + val &= ~AuBrRAttr_Mask;
23672 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23673 + * does not treat it as an error, just warning.
23674 + * this is a tiny guard for the user operation.
23676 + if (val & AuBrAttr_UNPIN) {
23677 + bad |= AuBrAttr_UNPIN;
23678 + val &= ~AuBrAttr_UNPIN;
23681 + if (unlikely(bad)) {
23682 + sz = au_do_optstr_br_attr(&attr, bad);
23684 + pr_warn("ignored branch attribute %s\n", attr.a);
23691 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23693 + au_br_perm_str_t attr;
23699 + p = au_optstr(&perm, brperm);
23700 + AuDebugOn(!p || !*p);
23702 + memcpy(q, p, sz + 1);
23705 + sz = au_do_optstr_br_attr(&attr, perm);
23708 + memcpy(q, attr.a, sz + 1);
23711 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23714 +/* ---------------------------------------------------------------------- */
23716 +static match_table_t udbalevel = {
23717 + {AuOpt_UDBA_REVAL, "reval"},
23718 + {AuOpt_UDBA_NONE, "none"},
23719 +#ifdef CONFIG_AUFS_HNOTIFY
23720 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23721 +#ifdef CONFIG_AUFS_HFSNOTIFY
23722 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23728 +static int noinline_for_stack udba_val(char *str)
23730 + substring_t args[MAX_OPT_ARGS];
23732 + return match_token(str, udbalevel, args);
23735 +const char *au_optstr_udba(int udba)
23737 + return au_parser_pattern(udba, udbalevel);
23740 +/* ---------------------------------------------------------------------- */
23742 +static match_table_t au_wbr_create_policy = {
23743 + {AuWbrCreate_TDP, "tdp"},
23744 + {AuWbrCreate_TDP, "top-down-parent"},
23745 + {AuWbrCreate_RR, "rr"},
23746 + {AuWbrCreate_RR, "round-robin"},
23747 + {AuWbrCreate_MFS, "mfs"},
23748 + {AuWbrCreate_MFS, "most-free-space"},
23749 + {AuWbrCreate_MFSV, "mfs:%d"},
23750 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23752 + /* top-down regardless the parent, and then mfs */
23753 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23754 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23756 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23757 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23758 + {AuWbrCreate_PMFS, "pmfs"},
23759 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23760 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23761 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23766 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23767 + struct au_opt_wbr_create *create)
23770 + unsigned long long ull;
23773 + if (!match_u64(arg, &ull))
23774 + create->mfsrr_watermark = ull;
23776 + pr_err("bad integer in %s\n", str);
23783 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23784 + struct au_opt_wbr_create *create)
23789 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23790 + create->mfs_second = n;
23792 + pr_err("bad integer in %s\n", str);
23799 +static int noinline_for_stack
23800 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23803 + substring_t args[MAX_OPT_ARGS];
23805 + err = match_token(str, au_wbr_create_policy, args);
23806 + create->wbr_create = err;
23808 + case AuWbrCreate_MFSRRV:
23809 + case AuWbrCreate_TDMFSV:
23810 + case AuWbrCreate_PMFSRRV:
23811 + e = au_wbr_mfs_wmark(&args[0], str, create);
23813 + e = au_wbr_mfs_sec(&args[1], str, create);
23817 + case AuWbrCreate_MFSRR:
23818 + case AuWbrCreate_TDMFS:
23819 + case AuWbrCreate_PMFSRR:
23820 + e = au_wbr_mfs_wmark(&args[0], str, create);
23821 + if (unlikely(e)) {
23826 + case AuWbrCreate_MFS:
23827 + case AuWbrCreate_PMFS:
23828 + create->mfs_second = AUFS_MFS_DEF_SEC;
23830 + case AuWbrCreate_MFSV:
23831 + case AuWbrCreate_PMFSV:
23832 + e = au_wbr_mfs_sec(&args[0], str, create);
23841 +const char *au_optstr_wbr_create(int wbr_create)
23843 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23846 +static match_table_t au_wbr_copyup_policy = {
23847 + {AuWbrCopyup_TDP, "tdp"},
23848 + {AuWbrCopyup_TDP, "top-down-parent"},
23849 + {AuWbrCopyup_BUP, "bup"},
23850 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23851 + {AuWbrCopyup_BU, "bu"},
23852 + {AuWbrCopyup_BU, "bottom-up"},
23856 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23858 + substring_t args[MAX_OPT_ARGS];
23860 + return match_token(str, au_wbr_copyup_policy, args);
23863 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23865 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23868 +/* ---------------------------------------------------------------------- */
23870 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23872 +static void dump_opts(struct au_opts *opts)
23874 +#ifdef CONFIG_AUFS_DEBUG
23875 + /* reduce stack space */
23877 + struct au_opt_add *add;
23878 + struct au_opt_del *del;
23879 + struct au_opt_mod *mod;
23880 + struct au_opt_xino *xino;
23881 + struct au_opt_xino_itrunc *xino_itrunc;
23882 + struct au_opt_wbr_create *create;
23884 + struct au_opt *opt;
23887 + while (opt->type != Opt_tail) {
23888 + switch (opt->type) {
23890 + u.add = &opt->add;
23891 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23892 + u.add->bindex, u.add->pathname, u.add->perm,
23893 + u.add->path.dentry);
23897 + u.del = &opt->del;
23898 + AuDbg("del {%s, %p}\n",
23899 + u.del->pathname, u.del->h_path.dentry);
23903 + u.mod = &opt->mod;
23904 + AuDbg("mod {%s, 0x%x, %p}\n",
23905 + u.mod->path, u.mod->perm, u.mod->h_root);
23908 + u.add = &opt->add;
23909 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23910 + u.add->bindex, u.add->pathname, u.add->perm,
23911 + u.add->path.dentry);
23913 + case Opt_prepend:
23914 + u.add = &opt->add;
23915 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23916 + u.add->bindex, u.add->pathname, u.add->perm,
23917 + u.add->path.dentry);
23920 + AuDbg("dirwh %d\n", opt->dirwh);
23922 + case Opt_rdcache:
23923 + AuDbg("rdcache %d\n", opt->rdcache);
23926 + AuDbg("rdblk %u\n", opt->rdblk);
23928 + case Opt_rdblk_def:
23929 + AuDbg("rdblk_def\n");
23932 + AuDbg("rdhash %u\n", opt->rdhash);
23934 + case Opt_rdhash_def:
23935 + AuDbg("rdhash_def\n");
23938 + u.xino = &opt->xino;
23939 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23941 + case Opt_trunc_xino:
23942 + AuLabel(trunc_xino);
23944 + case Opt_notrunc_xino:
23945 + AuLabel(notrunc_xino);
23947 + case Opt_trunc_xino_path:
23948 + case Opt_itrunc_xino:
23949 + u.xino_itrunc = &opt->xino_itrunc;
23950 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23955 + case Opt_trunc_xib:
23956 + AuLabel(trunc_xib);
23958 + case Opt_notrunc_xib:
23959 + AuLabel(notrunc_xib);
23967 + case Opt_dirperm1:
23968 + AuLabel(dirperm1);
23970 + case Opt_nodirperm1:
23971 + AuLabel(nodirperm1);
23976 + case Opt_noplink:
23977 + AuLabel(noplink);
23979 + case Opt_list_plink:
23980 + AuLabel(list_plink);
23983 + AuDbg("udba %d, %s\n",
23984 + opt->udba, au_optstr_udba(opt->udba));
23992 + case Opt_diropq_a:
23993 + AuLabel(diropq_a);
23995 + case Opt_diropq_w:
23996 + AuLabel(diropq_w);
23998 + case Opt_warn_perm:
23999 + AuLabel(warn_perm);
24001 + case Opt_nowarn_perm:
24002 + AuLabel(nowarn_perm);
24004 + case Opt_verbose:
24005 + AuLabel(verbose);
24007 + case Opt_noverbose:
24008 + AuLabel(noverbose);
24019 + case Opt_wbr_create:
24020 + u.create = &opt->wbr_create;
24021 + AuDbg("create %d, %s\n", u.create->wbr_create,
24022 + au_optstr_wbr_create(u.create->wbr_create));
24023 + switch (u.create->wbr_create) {
24024 + case AuWbrCreate_MFSV:
24025 + case AuWbrCreate_PMFSV:
24026 + AuDbg("%d sec\n", u.create->mfs_second);
24028 + case AuWbrCreate_MFSRR:
24029 + case AuWbrCreate_TDMFS:
24030 + AuDbg("%llu watermark\n",
24031 + u.create->mfsrr_watermark);
24033 + case AuWbrCreate_MFSRRV:
24034 + case AuWbrCreate_TDMFSV:
24035 + case AuWbrCreate_PMFSRRV:
24036 + AuDbg("%llu watermark, %d sec\n",
24037 + u.create->mfsrr_watermark,
24038 + u.create->mfs_second);
24042 + case Opt_wbr_copyup:
24043 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
24044 + au_optstr_wbr_copyup(opt->wbr_copyup));
24046 + case Opt_fhsm_sec:
24047 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24063 +void au_opts_free(struct au_opts *opts)
24065 + struct au_opt *opt;
24068 + while (opt->type != Opt_tail) {
24069 + switch (opt->type) {
24072 + case Opt_prepend:
24073 + path_put(&opt->add.path);
24077 + path_put(&opt->del.h_path);
24081 + dput(opt->mod.h_root);
24084 + fput(opt->xino.file);
24091 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24092 + aufs_bindex_t bindex)
24095 + struct au_opt_add *add = &opt->add;
24098 + add->bindex = bindex;
24099 + add->perm = AuBrPerm_RO;
24100 + add->pathname = opt_str;
24101 + p = strchr(opt_str, '=');
24105 + add->perm = br_perm_val(p);
24108 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24111 + add->perm = AuBrPerm_RO;
24112 + if (au_test_fs_rr(add->path.dentry->d_sb))
24113 + add->perm = AuBrPerm_RR;
24114 + else if (!bindex && !(sb_flags & MS_RDONLY))
24115 + add->perm = AuBrPerm_RW;
24117 + opt->type = Opt_add;
24120 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24127 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24131 + del->pathname = args[0].from;
24132 + AuDbg("del path %s\n", del->pathname);
24134 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24135 + if (unlikely(err))
24136 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24141 +#if 0 /* reserved for future use */
24142 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24143 + struct au_opt_del *del, substring_t args[])
24146 + struct dentry *root;
24149 + root = sb->s_root;
24150 + aufs_read_lock(root, AuLock_FLUSH);
24151 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24152 + pr_err("out of bounds, %d\n", bindex);
24157 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24158 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24161 + aufs_read_unlock(root, !AuLock_IR);
24166 +static int noinline_for_stack
24167 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24170 + struct path path;
24174 + mod->path = args[0].from;
24175 + p = strchr(mod->path, '=');
24176 + if (unlikely(!p)) {
24177 + pr_err("no permssion %s\n", args[0].from);
24182 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24183 + if (unlikely(err)) {
24184 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24188 + mod->perm = br_perm_val(p);
24189 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24190 + mod->h_root = dget(path.dentry);
24197 +#if 0 /* reserved for future use */
24198 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24199 + struct au_opt_mod *mod, substring_t args[])
24202 + struct dentry *root;
24205 + root = sb->s_root;
24206 + aufs_read_lock(root, AuLock_FLUSH);
24207 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24208 + pr_err("out of bounds, %d\n", bindex);
24213 + mod->perm = br_perm_val(args[1].from);
24214 + AuDbg("mod path %s, perm 0x%x, %s\n",
24215 + mod->path, mod->perm, args[1].from);
24216 + mod->h_root = dget(au_h_dptr(root, bindex));
24219 + aufs_read_unlock(root, !AuLock_IR);
24224 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24225 + substring_t args[])
24228 + struct file *file;
24230 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24231 + err = PTR_ERR(file);
24232 + if (IS_ERR(file))
24236 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24238 + pr_err("%s must be outside\n", args[0].from);
24243 + xino->file = file;
24244 + xino->path = args[0].from;
24250 +static int noinline_for_stack
24251 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24252 + struct au_opt_xino_itrunc *xino_itrunc,
24253 + substring_t args[])
24256 + aufs_bindex_t bbot, bindex;
24257 + struct path path;
24258 + struct dentry *root;
24260 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24261 + if (unlikely(err)) {
24262 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24266 + xino_itrunc->bindex = -1;
24267 + root = sb->s_root;
24268 + aufs_read_lock(root, AuLock_FLUSH);
24269 + bbot = au_sbbot(sb);
24270 + for (bindex = 0; bindex <= bbot; bindex++) {
24271 + if (au_h_dptr(root, bindex) == path.dentry) {
24272 + xino_itrunc->bindex = bindex;
24276 + aufs_read_unlock(root, !AuLock_IR);
24279 + if (unlikely(xino_itrunc->bindex < 0)) {
24280 + pr_err("no such branch %s\n", args[0].from);
24288 +/* called without aufs lock */
24289 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24291 + int err, n, token;
24292 + aufs_bindex_t bindex;
24293 + unsigned char skipped;
24294 + struct dentry *root;
24295 + struct au_opt *opt, *opt_tail;
24297 + /* reduce the stack space */
24299 + struct au_opt_xino_itrunc *xino_itrunc;
24300 + struct au_opt_wbr_create *create;
24303 + substring_t args[MAX_OPT_ARGS];
24307 + a = kmalloc(sizeof(*a), GFP_NOFS);
24308 + if (unlikely(!a))
24311 + root = sb->s_root;
24315 + opt_tail = opt + opts->max_opt - 1;
24316 + opt->type = Opt_tail;
24317 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24320 + token = match_token(opt_str, options, a->args);
24324 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24326 + err = opt_add(opt, opt_str, opts->sb_flags,
24328 + if (unlikely(!err && ++opt > opt_tail)) {
24332 + opt->type = Opt_tail;
24337 + if (unlikely(match_int(&a->args[0], &n))) {
24338 + pr_err("bad integer in %s\n", opt_str);
24342 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24345 + opt->type = token;
24348 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24349 + /*dummy bindex*/1);
24351 + opt->type = token;
24353 + case Opt_prepend:
24354 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24357 + opt->type = token;
24360 + err = au_opts_parse_del(&opt->del, a->args);
24362 + opt->type = token;
24364 +#if 0 /* reserved for future use */
24366 + del->pathname = "(indexed)";
24367 + if (unlikely(match_int(&args[0], &n))) {
24368 + pr_err("bad integer in %s\n", opt_str);
24371 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24373 + opt->type = token;
24377 + err = au_opts_parse_mod(&opt->mod, a->args);
24379 + opt->type = token;
24381 +#ifdef IMOD /* reserved for future use */
24383 + u.mod->path = "(indexed)";
24384 + if (unlikely(match_int(&a->args[0], &n))) {
24385 + pr_err("bad integer in %s\n", opt_str);
24388 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24390 + opt->type = token;
24394 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24396 + opt->type = token;
24399 + case Opt_trunc_xino_path:
24400 + err = au_opts_parse_xino_itrunc_path
24401 + (sb, &opt->xino_itrunc, a->args);
24403 + opt->type = token;
24406 + case Opt_itrunc_xino:
24407 + u.xino_itrunc = &opt->xino_itrunc;
24408 + if (unlikely(match_int(&a->args[0], &n))) {
24409 + pr_err("bad integer in %s\n", opt_str);
24412 + u.xino_itrunc->bindex = n;
24413 + aufs_read_lock(root, AuLock_FLUSH);
24414 + if (n < 0 || au_sbbot(sb) < n) {
24415 + pr_err("out of bounds, %d\n", n);
24416 + aufs_read_unlock(root, !AuLock_IR);
24419 + aufs_read_unlock(root, !AuLock_IR);
24421 + opt->type = token;
24425 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24428 + opt->type = token;
24431 + case Opt_rdcache:
24432 + if (unlikely(match_int(&a->args[0], &n))) {
24433 + pr_err("bad integer in %s\n", opt_str);
24436 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24437 + pr_err("rdcache must be smaller than %d\n",
24438 + AUFS_RDCACHE_MAX);
24441 + opt->rdcache = n;
24443 + opt->type = token;
24446 + if (unlikely(match_int(&a->args[0], &n)
24448 + || n > KMALLOC_MAX_SIZE)) {
24449 + pr_err("bad integer in %s\n", opt_str);
24452 + if (unlikely(n && n < NAME_MAX)) {
24453 + pr_err("rdblk must be larger than %d\n",
24459 + opt->type = token;
24462 + if (unlikely(match_int(&a->args[0], &n)
24464 + || n * sizeof(struct hlist_head)
24465 + > KMALLOC_MAX_SIZE)) {
24466 + pr_err("bad integer in %s\n", opt_str);
24471 + opt->type = token;
24474 + case Opt_trunc_xino:
24475 + case Opt_notrunc_xino:
24477 + case Opt_trunc_xib:
24478 + case Opt_notrunc_xib:
24481 + case Opt_dirperm1:
24482 + case Opt_nodirperm1:
24484 + case Opt_noplink:
24485 + case Opt_list_plink:
24488 + case Opt_diropq_a:
24489 + case Opt_diropq_w:
24490 + case Opt_warn_perm:
24491 + case Opt_nowarn_perm:
24492 + case Opt_verbose:
24493 + case Opt_noverbose:
24497 + case Opt_rdblk_def:
24498 + case Opt_rdhash_def:
24502 + opt->type = token;
24506 + opt->udba = udba_val(a->args[0].from);
24507 + if (opt->udba >= 0) {
24509 + opt->type = token;
24511 + pr_err("wrong value, %s\n", opt_str);
24514 + case Opt_wbr_create:
24515 + u.create = &opt->wbr_create;
24516 + u.create->wbr_create
24517 + = au_wbr_create_val(a->args[0].from, u.create);
24518 + if (u.create->wbr_create >= 0) {
24520 + opt->type = token;
24522 + pr_err("wrong value, %s\n", opt_str);
24524 + case Opt_wbr_copyup:
24525 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24526 + if (opt->wbr_copyup >= 0) {
24528 + opt->type = token;
24530 + pr_err("wrong value, %s\n", opt_str);
24533 + case Opt_fhsm_sec:
24534 + if (unlikely(match_int(&a->args[0], &n)
24536 + pr_err("bad integer in %s\n", opt_str);
24539 + if (sysaufs_brs) {
24540 + opt->fhsm_second = n;
24541 + opt->type = token;
24543 + pr_warn("ignored %s\n", opt_str);
24548 + pr_warn("ignored %s\n", opt_str);
24550 + case Opt_ignore_silent:
24555 + pr_err("unknown option %s\n", opt_str);
24559 + if (!err && !skipped) {
24560 + if (unlikely(++opt > opt_tail)) {
24563 + opt->type = Opt_tail;
24566 + opt->type = Opt_tail;
24572 + if (unlikely(err))
24573 + au_opts_free(opts);
24579 +static int au_opt_wbr_create(struct super_block *sb,
24580 + struct au_opt_wbr_create *create)
24583 + struct au_sbinfo *sbinfo;
24585 + SiMustWriteLock(sb);
24587 + err = 1; /* handled */
24588 + sbinfo = au_sbi(sb);
24589 + if (sbinfo->si_wbr_create_ops->fin) {
24590 + err = sbinfo->si_wbr_create_ops->fin(sb);
24595 + sbinfo->si_wbr_create = create->wbr_create;
24596 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24597 + switch (create->wbr_create) {
24598 + case AuWbrCreate_MFSRRV:
24599 + case AuWbrCreate_MFSRR:
24600 + case AuWbrCreate_TDMFS:
24601 + case AuWbrCreate_TDMFSV:
24602 + case AuWbrCreate_PMFSRR:
24603 + case AuWbrCreate_PMFSRRV:
24604 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24606 + case AuWbrCreate_MFS:
24607 + case AuWbrCreate_MFSV:
24608 + case AuWbrCreate_PMFS:
24609 + case AuWbrCreate_PMFSV:
24610 + sbinfo->si_wbr_mfs.mfs_expire
24611 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24615 + if (sbinfo->si_wbr_create_ops->init)
24616 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24623 + * plus: processed without an error
24624 + * zero: unprocessed
24626 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24627 + struct au_opts *opts)
24630 + struct au_sbinfo *sbinfo;
24632 + SiMustWriteLock(sb);
24634 + err = 1; /* handled */
24635 + sbinfo = au_sbi(sb);
24636 + switch (opt->type) {
24638 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24639 + sbinfo->si_mntflags |= opt->udba;
24640 + opts->given_udba |= opt->udba;
24644 + au_opt_set(sbinfo->si_mntflags, PLINK);
24646 + case Opt_noplink:
24647 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24648 + au_plink_put(sb, /*verbose*/1);
24649 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24651 + case Opt_list_plink:
24652 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24653 + au_plink_list(sb);
24657 + au_opt_set(sbinfo->si_mntflags, DIO);
24658 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24661 + au_opt_clr(sbinfo->si_mntflags, DIO);
24662 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24665 + case Opt_fhsm_sec:
24666 + au_fhsm_set(sbinfo, opt->fhsm_second);
24669 + case Opt_diropq_a:
24670 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24672 + case Opt_diropq_w:
24673 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24676 + case Opt_warn_perm:
24677 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24679 + case Opt_nowarn_perm:
24680 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24683 + case Opt_verbose:
24684 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24686 + case Opt_noverbose:
24687 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24691 + au_opt_set(sbinfo->si_mntflags, SUM);
24694 + au_opt_clr(sbinfo->si_mntflags, SUM);
24695 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24697 + au_opt_clr(sbinfo->si_mntflags, SUM);
24698 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24701 + case Opt_wbr_create:
24702 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24704 + case Opt_wbr_copyup:
24705 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24706 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24710 + sbinfo->si_dirwh = opt->dirwh;
24713 + case Opt_rdcache:
24714 + sbinfo->si_rdcache
24715 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24718 + sbinfo->si_rdblk = opt->rdblk;
24720 + case Opt_rdblk_def:
24721 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24724 + sbinfo->si_rdhash = opt->rdhash;
24726 + case Opt_rdhash_def:
24727 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24731 + au_opt_set(sbinfo->si_mntflags, SHWH);
24734 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24737 + case Opt_dirperm1:
24738 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24740 + case Opt_nodirperm1:
24741 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24744 + case Opt_trunc_xino:
24745 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24747 + case Opt_notrunc_xino:
24748 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24751 + case Opt_trunc_xino_path:
24752 + case Opt_itrunc_xino:
24753 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24758 + case Opt_trunc_xib:
24759 + au_fset_opts(opts->flags, TRUNC_XIB);
24761 + case Opt_notrunc_xib:
24762 + au_fclr_opts(opts->flags, TRUNC_XIB);
24766 + sb->s_flags |= MS_POSIXACL;
24769 + sb->s_flags &= ~MS_POSIXACL;
24781 + * returns tri-state.
24782 + * plus: processed without an error
24783 + * zero: unprocessed
24786 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24787 + struct au_opts *opts)
24789 + int err, do_refresh;
24792 + switch (opt->type) {
24794 + opt->add.bindex = au_sbbot(sb) + 1;
24795 + if (opt->add.bindex < 0)
24796 + opt->add.bindex = 0;
24798 + case Opt_prepend:
24799 + opt->add.bindex = 0;
24800 + add: /* indented label */
24802 + err = au_br_add(sb, &opt->add,
24803 + au_ftest_opts(opts->flags, REMOUNT));
24806 + au_fset_opts(opts->flags, REFRESH);
24812 + err = au_br_del(sb, &opt->del,
24813 + au_ftest_opts(opts->flags, REMOUNT));
24816 + au_fset_opts(opts->flags, TRUNC_XIB);
24817 + au_fset_opts(opts->flags, REFRESH);
24823 + err = au_br_mod(sb, &opt->mod,
24824 + au_ftest_opts(opts->flags, REMOUNT),
24829 + au_fset_opts(opts->flags, REFRESH);
24836 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24837 + struct au_opt_xino **opt_xino,
24838 + struct au_opts *opts)
24841 + aufs_bindex_t bbot, bindex;
24842 + struct dentry *root, *parent, *h_root;
24845 + switch (opt->type) {
24847 + err = au_xino_set(sb, &opt->xino,
24848 + !!au_ftest_opts(opts->flags, REMOUNT));
24849 + if (unlikely(err))
24852 + *opt_xino = &opt->xino;
24853 + au_xino_brid_set(sb, -1);
24855 + /* safe d_parent access */
24856 + parent = opt->xino.file->f_path.dentry->d_parent;
24857 + root = sb->s_root;
24858 + bbot = au_sbbot(sb);
24859 + for (bindex = 0; bindex <= bbot; bindex++) {
24860 + h_root = au_h_dptr(root, bindex);
24861 + if (h_root == parent) {
24862 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24870 + au_xino_brid_set(sb, -1);
24871 + *opt_xino = (void *)-1;
24878 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24879 + unsigned int pending)
24882 + aufs_bindex_t bindex, bbot;
24883 + unsigned char do_plink, skip, do_free, can_no_dreval;
24884 + struct au_branch *br;
24885 + struct au_wbr *wbr;
24886 + struct dentry *root, *dentry;
24887 + struct inode *dir, *h_dir;
24888 + struct au_sbinfo *sbinfo;
24889 + struct au_hinode *hdir;
24891 + SiMustAnyLock(sb);
24893 + sbinfo = au_sbi(sb);
24894 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24896 + if (!(sb_flags & MS_RDONLY)) {
24897 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24898 + pr_warn("first branch should be rw\n");
24899 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24900 + pr_warn_once("shwh should be used with ro\n");
24903 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24904 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24905 + pr_warn_once("udba=*notify requires xino\n");
24907 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24908 + pr_warn_once("dirperm1 breaks the protection"
24909 + " by the permission bits on the lower branch\n");
24913 + root = sb->s_root;
24914 + dir = d_inode(root);
24915 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24916 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24918 + bbot = au_sbbot(sb);
24919 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24921 + h_dir = au_h_iptr(dir, bindex);
24922 + br = au_sbr(sb, bindex);
24924 + if ((br->br_perm & AuBrAttr_ICEX)
24925 + && !h_dir->i_op->listxattr)
24926 + br->br_perm &= ~AuBrAttr_ICEX;
24928 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24929 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24930 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24934 + wbr = br->br_wbr;
24936 + wbr_wh_read_lock(wbr);
24938 + if (!au_br_writable(br->br_perm)) {
24941 + || (!wbr->wbr_whbase
24942 + && !wbr->wbr_plink
24943 + && !wbr->wbr_orph));
24944 + } else if (!au_br_wh_linkable(br->br_perm)) {
24945 + /* skip = (!br->br_whbase && !br->br_orph); */
24946 + skip = (!wbr || !wbr->wbr_whbase);
24947 + if (skip && wbr) {
24949 + skip = !!wbr->wbr_plink;
24951 + skip = !wbr->wbr_plink;
24954 + /* skip = (br->br_whbase && br->br_ohph); */
24955 + skip = (wbr && wbr->wbr_whbase);
24958 + skip = !!wbr->wbr_plink;
24960 + skip = !wbr->wbr_plink;
24964 + wbr_wh_read_unlock(wbr);
24966 + if (can_no_dreval) {
24967 + dentry = br->br_path.dentry;
24968 + spin_lock(&dentry->d_lock);
24969 + if (dentry->d_flags &
24970 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24971 + can_no_dreval = 0;
24972 + spin_unlock(&dentry->d_lock);
24975 + if (au_br_fhsm(br->br_perm)) {
24977 + AuDebugOn(!br->br_fhsm);
24983 + hdir = au_hi(dir, bindex);
24984 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24986 + wbr_wh_write_lock(wbr);
24987 + err = au_wh_init(br, sb);
24989 + wbr_wh_write_unlock(wbr);
24990 + au_hn_inode_unlock(hdir);
24992 + if (!err && do_free) {
24994 + br->br_wbr = NULL;
24998 + if (can_no_dreval)
24999 + au_fset_si(sbinfo, NO_DREVAL);
25001 + au_fclr_si(sbinfo, NO_DREVAL);
25004 + au_fset_si(sbinfo, FHSM);
25005 + for (bindex = bbot; bindex >= 0; bindex--) {
25006 + br = au_sbr(sb, bindex);
25007 + if (au_br_fhsm(br->br_perm)) {
25008 + au_fhsm_set_bottom(sb, bindex);
25013 + au_fclr_si(sbinfo, FHSM);
25014 + au_fhsm_set_bottom(sb, -1);
25020 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
25023 + unsigned int tmp;
25024 + aufs_bindex_t bindex, bbot;
25025 + struct au_opt *opt;
25026 + struct au_opt_xino *opt_xino, xino;
25027 + struct au_sbinfo *sbinfo;
25028 + struct au_branch *br;
25029 + struct inode *dir;
25031 + SiMustWriteLock(sb);
25036 + while (err >= 0 && opt->type != Opt_tail)
25037 + err = au_opt_simple(sb, opt++, opts);
25040 + else if (unlikely(err < 0))
25043 + /* disable xino and udba temporary */
25044 + sbinfo = au_sbi(sb);
25045 + tmp = sbinfo->si_mntflags;
25046 + au_opt_clr(sbinfo->si_mntflags, XINO);
25047 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25050 + while (err >= 0 && opt->type != Opt_tail)
25051 + err = au_opt_br(sb, opt++, opts);
25054 + else if (unlikely(err < 0))
25057 + bbot = au_sbbot(sb);
25058 + if (unlikely(bbot < 0)) {
25060 + pr_err("no branches\n");
25064 + if (au_opt_test(tmp, XINO))
25065 + au_opt_set(sbinfo->si_mntflags, XINO);
25067 + while (!err && opt->type != Opt_tail)
25068 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25069 + if (unlikely(err))
25072 + err = au_opts_verify(sb, sb->s_flags, tmp);
25073 + if (unlikely(err))
25076 + /* restore xino */
25077 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25078 + xino.file = au_xino_def(sb);
25079 + err = PTR_ERR(xino.file);
25080 + if (IS_ERR(xino.file))
25083 + err = au_xino_set(sb, &xino, /*remount*/0);
25085 + if (unlikely(err))
25089 + /* restore udba */
25090 + tmp &= AuOptMask_UDBA;
25091 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25092 + sbinfo->si_mntflags |= tmp;
25093 + bbot = au_sbbot(sb);
25094 + for (bindex = 0; bindex <= bbot; bindex++) {
25095 + br = au_sbr(sb, bindex);
25096 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25097 + if (unlikely(err))
25098 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25100 + /* go on even if err */
25102 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25103 + dir = d_inode(sb->s_root);
25104 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25111 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25114 + unsigned char no_dreval;
25115 + struct inode *dir;
25116 + struct au_opt_xino *opt_xino;
25117 + struct au_opt *opt;
25118 + struct au_sbinfo *sbinfo;
25120 + SiMustWriteLock(sb);
25123 + dir = d_inode(sb->s_root);
25124 + sbinfo = au_sbi(sb);
25127 + while (err >= 0 && opt->type != Opt_tail) {
25128 + err = au_opt_simple(sb, opt, opts);
25130 + err = au_opt_br(sb, opt, opts);
25132 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25138 + /* go on even err */
25140 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25141 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25142 + if (unlikely(rerr && !err))
25145 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25146 + au_fset_opts(opts->flags, REFRESH_IDOP);
25148 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25149 + rerr = au_xib_trunc(sb);
25150 + if (unlikely(rerr && !err))
25154 + /* will be handled by the caller */
25155 + if (!au_ftest_opts(opts->flags, REFRESH)
25156 + && (opts->given_udba
25157 + || au_opt_test(sbinfo->si_mntflags, XINO)
25158 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25160 + au_fset_opts(opts->flags, REFRESH);
25162 + AuDbg("status 0x%x\n", opts->flags);
25166 +/* ---------------------------------------------------------------------- */
25168 +unsigned int au_opt_udba(struct super_block *sb)
25170 + return au_mntflags(sb) & AuOptMask_UDBA;
25172 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25173 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25174 +++ linux/fs/aufs/opts.h 2017-07-29 12:14:25.903042072 +0200
25177 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25179 + * This program, aufs is free software; you can redistribute it and/or modify
25180 + * it under the terms of the GNU General Public License as published by
25181 + * the Free Software Foundation; either version 2 of the License, or
25182 + * (at your option) any later version.
25184 + * This program is distributed in the hope that it will be useful,
25185 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25186 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25187 + * GNU General Public License for more details.
25189 + * You should have received a copy of the GNU General Public License
25190 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25194 + * mount options/flags
25197 +#ifndef __AUFS_OPTS_H__
25198 +#define __AUFS_OPTS_H__
25202 +#include <linux/path.h>
25206 +/* ---------------------------------------------------------------------- */
25209 +#define AuOpt_XINO 1 /* external inode number bitmap
25210 + and translation table */
25211 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25212 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25213 +#define AuOpt_UDBA_REVAL (1 << 3)
25214 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25215 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25216 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25217 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25219 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25220 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25221 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25222 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25223 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25224 +#define AuOpt_DIO (1 << 14) /* direct io */
25226 +#ifndef CONFIG_AUFS_HNOTIFY
25227 +#undef AuOpt_UDBA_HNOTIFY
25228 +#define AuOpt_UDBA_HNOTIFY 0
25230 +#ifndef CONFIG_AUFS_SHWH
25232 +#define AuOpt_SHWH 0
25235 +#define AuOpt_Def (AuOpt_XINO \
25236 + | AuOpt_UDBA_REVAL \
25238 + /* | AuOpt_DIRPERM1 */ \
25239 + | AuOpt_WARN_PERM)
25240 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25241 + | AuOpt_UDBA_REVAL \
25242 + | AuOpt_UDBA_HNOTIFY)
25244 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25245 +#define au_opt_set(flags, name) do { \
25246 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25247 + ((flags) |= AuOpt_##name); \
25249 +#define au_opt_set_udba(flags, name) do { \
25250 + (flags) &= ~AuOptMask_UDBA; \
25251 + ((flags) |= AuOpt_##name); \
25253 +#define au_opt_clr(flags, name) do { \
25254 + ((flags) &= ~AuOpt_##name); \
25257 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25259 +#ifdef CONFIG_PROC_FS
25262 + return mntflags & ~AuOpt_PLINK;
25266 +/* ---------------------------------------------------------------------- */
25268 +/* policies to select one among multiple writable branches */
25270 + AuWbrCreate_TDP, /* top down parent */
25271 + AuWbrCreate_RR, /* round robin */
25272 + AuWbrCreate_MFS, /* most free space */
25273 + AuWbrCreate_MFSV, /* mfs with seconds */
25274 + AuWbrCreate_MFSRR, /* mfs then rr */
25275 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25276 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25277 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25278 + AuWbrCreate_PMFS, /* parent and mfs */
25279 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25280 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25281 + AuWbrCreate_PMFSRRV, /* plus seconds */
25283 + AuWbrCreate_Def = AuWbrCreate_TDP
25287 + AuWbrCopyup_TDP, /* top down parent */
25288 + AuWbrCopyup_BUP, /* bottom up parent */
25289 + AuWbrCopyup_BU, /* bottom up */
25291 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25294 +/* ---------------------------------------------------------------------- */
25296 +struct au_opt_add {
25297 + aufs_bindex_t bindex;
25300 + struct path path;
25303 +struct au_opt_del {
25305 + struct path h_path;
25308 +struct au_opt_mod {
25311 + struct dentry *h_root;
25314 +struct au_opt_xino {
25316 + struct file *file;
25319 +struct au_opt_xino_itrunc {
25320 + aufs_bindex_t bindex;
25323 +struct au_opt_wbr_create {
25326 + unsigned long long mfsrr_watermark;
25332 + struct au_opt_xino xino;
25333 + struct au_opt_xino_itrunc xino_itrunc;
25334 + struct au_opt_add add;
25335 + struct au_opt_del del;
25336 + struct au_opt_mod mod;
25339 + unsigned int rdblk;
25340 + unsigned int rdhash;
25342 + struct au_opt_wbr_create wbr_create;
25344 + unsigned int fhsm_second;
25349 +#define AuOpts_REMOUNT 1
25350 +#define AuOpts_REFRESH (1 << 1)
25351 +#define AuOpts_TRUNC_XIB (1 << 2)
25352 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25353 +#define AuOpts_REFRESH_IDOP (1 << 4)
25354 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25355 +#define au_fset_opts(flags, name) \
25356 + do { (flags) |= AuOpts_##name; } while (0)
25357 +#define au_fclr_opts(flags, name) \
25358 + do { (flags) &= ~AuOpts_##name; } while (0)
25361 + struct au_opt *opt;
25364 + unsigned int given_udba;
25365 + unsigned int flags;
25366 + unsigned long sb_flags;
25369 +/* ---------------------------------------------------------------------- */
25372 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25373 +const char *au_optstr_udba(int udba);
25374 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25375 +const char *au_optstr_wbr_create(int wbr_create);
25377 +void au_opts_free(struct au_opts *opts);
25378 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25379 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25380 + unsigned int pending);
25381 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25382 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25384 +unsigned int au_opt_udba(struct super_block *sb);
25386 +#endif /* __KERNEL__ */
25387 +#endif /* __AUFS_OPTS_H__ */
25388 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25389 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25390 +++ linux/fs/aufs/plink.c 2017-07-29 12:14:25.903042072 +0200
25393 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25395 + * This program, aufs is free software; you can redistribute it and/or modify
25396 + * it under the terms of the GNU General Public License as published by
25397 + * the Free Software Foundation; either version 2 of the License, or
25398 + * (at your option) any later version.
25400 + * This program is distributed in the hope that it will be useful,
25401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25403 + * GNU General Public License for more details.
25405 + * You should have received a copy of the GNU General Public License
25406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25416 + * the pseudo-link maintenance mode.
25417 + * during a user process maintains the pseudo-links,
25418 + * prohibit adding a new plink and branch manipulation.
25422 + * For entry functions which will handle plink, and i_mutex is already held
25424 + * They cannot wait and should return an error at once.
25425 + * Callers has to check the error.
25427 + * For entry functions which will handle plink, but i_mutex is not held
25429 + * They can wait the plink maintenance mode to finish.
25431 + * They behave like F_SETLK and F_SETLKW.
25432 + * If the caller never handle plink, then both flags are unnecessary.
25435 +int au_plink_maint(struct super_block *sb, int flags)
25439 + struct task_struct *parent, *prev;
25440 + struct au_sbinfo *sbi;
25442 + SiMustAnyLock(sb);
25445 + if (!au_opt_test(au_mntflags(sb), PLINK))
25448 + sbi = au_sbi(sb);
25449 + pid = sbi->si_plink_maint_pid;
25450 + if (!pid || pid == current->pid)
25453 + /* todo: it highly depends upon /sbin/mount.aufs */
25455 + parent = current;
25459 + parent = rcu_dereference(parent->real_parent);
25460 + if (parent == prev)
25462 + ppid = task_pid_vnr(parent);
25463 + if (pid == ppid) {
25464 + rcu_read_unlock();
25469 + rcu_read_unlock();
25471 + if (au_ftest_lock(flags, NOPLMW)) {
25472 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25473 + /* AuDebugOn(!lockdep_depth(current)); */
25474 + while (sbi->si_plink_maint_pid) {
25475 + si_read_unlock(sb);
25476 + /* gave up wake_up_bit() */
25477 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25479 + if (au_ftest_lock(flags, FLUSH))
25480 + au_nwt_flush(&sbi->si_nowait);
25481 + si_noflush_read_lock(sb);
25483 + } else if (au_ftest_lock(flags, NOPLM)) {
25484 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25492 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25494 + spin_lock(&sbinfo->si_plink_maint_lock);
25495 + sbinfo->si_plink_maint_pid = 0;
25496 + spin_unlock(&sbinfo->si_plink_maint_lock);
25497 + wake_up_all(&sbinfo->si_plink_wq);
25500 +int au_plink_maint_enter(struct super_block *sb)
25503 + struct au_sbinfo *sbinfo;
25506 + sbinfo = au_sbi(sb);
25507 + /* make sure i am the only one in this fs */
25508 + si_write_lock(sb, AuLock_FLUSH);
25509 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25510 + spin_lock(&sbinfo->si_plink_maint_lock);
25511 + if (!sbinfo->si_plink_maint_pid)
25512 + sbinfo->si_plink_maint_pid = current->pid;
25515 + spin_unlock(&sbinfo->si_plink_maint_lock);
25517 + si_write_unlock(sb);
25522 +/* ---------------------------------------------------------------------- */
25524 +#ifdef CONFIG_AUFS_DEBUG
25525 +void au_plink_list(struct super_block *sb)
25528 + struct au_sbinfo *sbinfo;
25529 + struct hlist_head *plink_hlist;
25530 + struct au_icntnr *icntnr;
25532 + SiMustAnyLock(sb);
25534 + sbinfo = au_sbi(sb);
25535 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25536 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25538 + for (i = 0; i < AuPlink_NHASH; i++) {
25539 + plink_hlist = &sbinfo->si_plink[i].head;
25541 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25542 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25543 + rcu_read_unlock();
25548 +/* is the inode pseudo-linked? */
25549 +int au_plink_test(struct inode *inode)
25552 + struct au_sbinfo *sbinfo;
25553 + struct hlist_head *plink_hlist;
25554 + struct au_icntnr *icntnr;
25556 + sbinfo = au_sbi(inode->i_sb);
25557 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25558 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25559 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25562 + i = au_plink_hash(inode->i_ino);
25563 + plink_hlist = &sbinfo->si_plink[i].head;
25565 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25566 + if (&icntnr->vfs_inode == inode) {
25570 + rcu_read_unlock();
25574 +/* ---------------------------------------------------------------------- */
25577 + * generate a name for plink.
25578 + * the file will be stored under AUFS_WH_PLINKDIR.
25580 +/* 20 is max digits length of ulong 64 */
25581 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25583 +static int plink_name(char *name, int len, struct inode *inode,
25584 + aufs_bindex_t bindex)
25587 + struct inode *h_inode;
25589 + h_inode = au_h_iptr(inode, bindex);
25590 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25594 +struct au_do_plink_lkup_args {
25595 + struct dentry **errp;
25596 + struct qstr *tgtname;
25597 + struct dentry *h_parent;
25598 + struct au_branch *br;
25601 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25602 + struct dentry *h_parent,
25603 + struct au_branch *br)
25605 + struct dentry *h_dentry;
25606 + struct inode *h_inode;
25608 + h_inode = d_inode(h_parent);
25609 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25610 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25611 + inode_unlock(h_inode);
25615 +static void au_call_do_plink_lkup(void *args)
25617 + struct au_do_plink_lkup_args *a = args;
25618 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25621 +/* lookup the plink-ed @inode under the branch at @bindex */
25622 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25624 + struct dentry *h_dentry, *h_parent;
25625 + struct au_branch *br;
25627 + char a[PLINK_NAME_LEN];
25628 + struct qstr tgtname = QSTR_INIT(a, 0);
25630 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25632 + br = au_sbr(inode->i_sb, bindex);
25633 + h_parent = br->br_wbr->wbr_plink;
25634 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25636 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25637 + struct au_do_plink_lkup_args args = {
25638 + .errp = &h_dentry,
25639 + .tgtname = &tgtname,
25640 + .h_parent = h_parent,
25644 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25645 + if (unlikely(wkq_err))
25646 + h_dentry = ERR_PTR(wkq_err);
25648 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25653 +/* create a pseudo-link */
25654 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25655 + struct dentry *h_dentry, struct au_branch *br)
25658 + struct path h_path = {
25659 + .mnt = au_br_mnt(br)
25661 + struct inode *h_dir, *delegated;
25663 + h_dir = d_inode(h_parent);
25664 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25666 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25667 + err = PTR_ERR(h_path.dentry);
25668 + if (IS_ERR(h_path.dentry))
25672 + /* wh.plink dir is not monitored */
25673 + /* todo: is it really safe? */
25674 + if (d_is_positive(h_path.dentry)
25675 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25676 + delegated = NULL;
25677 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25678 + if (unlikely(err == -EWOULDBLOCK)) {
25679 + pr_warn("cannot retry for NFSv4 delegation"
25680 + " for an internal unlink\n");
25683 + dput(h_path.dentry);
25684 + h_path.dentry = NULL;
25688 + if (!err && d_is_negative(h_path.dentry)) {
25689 + delegated = NULL;
25690 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25691 + if (unlikely(err == -EWOULDBLOCK)) {
25692 + pr_warn("cannot retry for NFSv4 delegation"
25693 + " for an internal link\n");
25697 + dput(h_path.dentry);
25700 + inode_unlock(h_dir);
25704 +struct do_whplink_args {
25706 + struct qstr *tgt;
25707 + struct dentry *h_parent;
25708 + struct dentry *h_dentry;
25709 + struct au_branch *br;
25712 +static void call_do_whplink(void *args)
25714 + struct do_whplink_args *a = args;
25715 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25718 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25719 + aufs_bindex_t bindex, struct au_branch *br)
25721 + int err, wkq_err;
25722 + struct au_wbr *wbr;
25723 + struct dentry *h_parent;
25724 + char a[PLINK_NAME_LEN];
25725 + struct qstr tgtname = QSTR_INIT(a, 0);
25727 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25728 + h_parent = wbr->wbr_plink;
25729 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25731 + /* always superio. */
25732 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25733 + struct do_whplink_args args = {
25736 + .h_parent = h_parent,
25737 + .h_dentry = h_dentry,
25740 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25741 + if (unlikely(wkq_err))
25744 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25750 + * create a new pseudo-link for @h_dentry on @bindex.
25751 + * the linked inode is held in aufs @inode.
25753 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25754 + struct dentry *h_dentry)
25756 + struct super_block *sb;
25757 + struct au_sbinfo *sbinfo;
25758 + struct hlist_head *plink_hlist;
25759 + struct au_icntnr *icntnr;
25760 + struct au_sphlhead *sphl;
25761 + int found, err, cnt, i;
25763 + sb = inode->i_sb;
25764 + sbinfo = au_sbi(sb);
25765 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25766 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25768 + found = au_plink_test(inode);
25772 + i = au_plink_hash(inode->i_ino);
25773 + sphl = sbinfo->si_plink + i;
25774 + plink_hlist = &sphl->head;
25777 + spin_lock(&sphl->spin);
25778 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25779 + if (&icntnr->vfs_inode == inode) {
25785 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25786 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25788 + spin_unlock(&sphl->spin);
25790 + cnt = au_sphl_count(sphl);
25791 +#define msg "unexpectedly unblanced or too many pseudo-links"
25792 + if (cnt > AUFS_PLINK_WARN)
25793 + AuWarn1(msg ", %d\n", cnt);
25795 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25796 + if (unlikely(err)) {
25797 + pr_warn("err %d, damaged pseudo link.\n", err);
25798 + au_sphl_del_rcu(&icntnr->plink, sphl);
25799 + iput(&icntnr->vfs_inode);
25802 + iput(&icntnr->vfs_inode);
25805 +/* free all plinks */
25806 +void au_plink_put(struct super_block *sb, int verbose)
25809 + struct au_sbinfo *sbinfo;
25810 + struct hlist_head *plink_hlist;
25811 + struct hlist_node *tmp;
25812 + struct au_icntnr *icntnr;
25814 + SiMustWriteLock(sb);
25816 + sbinfo = au_sbi(sb);
25817 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25818 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25820 + /* no spin_lock since sbinfo is write-locked */
25822 + for (i = 0; i < AuPlink_NHASH; i++) {
25823 + plink_hlist = &sbinfo->si_plink[i].head;
25824 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25825 + pr_warn("pseudo-link is not flushed");
25828 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25829 + iput(&icntnr->vfs_inode);
25830 + INIT_HLIST_HEAD(plink_hlist);
25834 +void au_plink_clean(struct super_block *sb, int verbose)
25836 + struct dentry *root;
25838 + root = sb->s_root;
25839 + aufs_write_lock(root);
25840 + if (au_opt_test(au_mntflags(sb), PLINK))
25841 + au_plink_put(sb, verbose);
25842 + aufs_write_unlock(root);
25845 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25848 + aufs_bindex_t btop, bbot, bindex;
25851 + btop = au_ibtop(inode);
25852 + bbot = au_ibbot(inode);
25854 + for (bindex = btop; bindex <= bbot; bindex++) {
25855 + if (!au_h_iptr(inode, bindex)
25856 + || au_ii_br_id(inode, bindex) != br_id)
25858 + au_set_h_iptr(inode, bindex, NULL, 0);
25863 + for (bindex = btop; bindex <= bbot; bindex++)
25864 + if (au_h_iptr(inode, bindex)) {
25874 +/* free the plinks on a branch specified by @br_id */
25875 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25877 + struct au_sbinfo *sbinfo;
25878 + struct hlist_head *plink_hlist;
25879 + struct hlist_node *tmp;
25880 + struct au_icntnr *icntnr;
25881 + struct inode *inode;
25884 + SiMustWriteLock(sb);
25886 + sbinfo = au_sbi(sb);
25887 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25888 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25890 + /* no spin_lock since sbinfo is write-locked */
25891 + for (i = 0; i < AuPlink_NHASH; i++) {
25892 + plink_hlist = &sbinfo->si_plink[i].head;
25893 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25894 + inode = au_igrab(&icntnr->vfs_inode);
25895 + ii_write_lock_child(inode);
25896 + do_put = au_plink_do_half_refresh(inode, br_id);
25898 + hlist_del(&icntnr->plink);
25901 + ii_write_unlock(inode);
25906 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25907 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25908 +++ linux/fs/aufs/poll.c 2017-07-29 12:14:25.906375514 +0200
25911 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25913 + * This program, aufs is free software; you can redistribute it and/or modify
25914 + * it under the terms of the GNU General Public License as published by
25915 + * the Free Software Foundation; either version 2 of the License, or
25916 + * (at your option) any later version.
25918 + * This program is distributed in the hope that it will be useful,
25919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25921 + * GNU General Public License for more details.
25923 + * You should have received a copy of the GNU General Public License
25924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25929 + * There is only one filesystem which implements ->poll operation, currently.
25934 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25936 + unsigned int mask;
25938 + struct file *h_file;
25939 + struct super_block *sb;
25941 + /* We should pretend an error happened. */
25942 + mask = POLLERR /* | POLLIN | POLLOUT */;
25943 + sb = file->f_path.dentry->d_sb;
25944 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25946 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
25947 + err = PTR_ERR(h_file);
25948 + if (IS_ERR(h_file))
25951 + /* it is not an error if h_file has no operation */
25952 + mask = DEFAULT_POLLMASK;
25953 + if (h_file->f_op->poll)
25954 + mask = h_file->f_op->poll(h_file, wait);
25955 + fput(h_file); /* instead of au_read_post() */
25958 + si_read_unlock(sb);
25959 + AuTraceErr((int)mask);
25962 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25963 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25964 +++ linux/fs/aufs/posix_acl.c 2017-07-29 12:14:25.906375514 +0200
25967 + * Copyright (C) 2014-2017 Junjiro R. Okajima
25969 + * This program, aufs is free software; you can redistribute it and/or modify
25970 + * it under the terms of the GNU General Public License as published by
25971 + * the Free Software Foundation; either version 2 of the License, or
25972 + * (at your option) any later version.
25974 + * This program is distributed in the hope that it will be useful,
25975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25977 + * GNU General Public License for more details.
25979 + * You should have received a copy of the GNU General Public License
25980 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25984 + * posix acl operations
25987 +#include <linux/fs.h>
25990 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25992 + struct posix_acl *acl;
25994 + aufs_bindex_t bindex;
25995 + struct inode *h_inode;
25996 + struct super_block *sb;
25999 + sb = inode->i_sb;
26000 + si_read_lock(sb, AuLock_FLUSH);
26001 + ii_read_lock_child(inode);
26002 + if (!(sb->s_flags & MS_POSIXACL))
26005 + bindex = au_ibtop(inode);
26006 + h_inode = au_h_iptr(inode, bindex);
26007 + if (unlikely(!h_inode
26008 + || ((h_inode->i_mode & S_IFMT)
26009 + != (inode->i_mode & S_IFMT)))) {
26010 + err = au_busy_or_stale();
26011 + acl = ERR_PTR(err);
26015 + /* always topmost only */
26016 + acl = get_acl(h_inode, type);
26017 + if (!IS_ERR_OR_NULL(acl))
26018 + set_cached_acl(inode, type, acl);
26021 + ii_read_unlock(inode);
26022 + si_read_unlock(sb);
26024 + AuTraceErrPtr(acl);
26028 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
26032 + struct dentry *dentry;
26033 + struct au_sxattr arg = {
26034 + .type = AU_ACL_SET,
26041 + IMustLock(inode);
26043 + if (inode->i_ino == AUFS_ROOT_INO)
26044 + dentry = dget(inode->i_sb->s_root);
26046 + dentry = d_find_alias(inode);
26048 + dentry = d_find_any_alias(inode);
26050 + pr_warn("cannot handle this inode, "
26051 + "please report to aufs-users ML\n");
26057 + ssz = au_sxattr(dentry, inode, &arg);
26062 + set_cached_acl(inode, type, acl);
26068 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
26069 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
26070 +++ linux/fs/aufs/procfs.c 2017-07-29 12:14:25.906375514 +0200
26073 + * Copyright (C) 2010-2017 Junjiro R. Okajima
26075 + * This program, aufs is free software; you can redistribute it and/or modify
26076 + * it under the terms of the GNU General Public License as published by
26077 + * the Free Software Foundation; either version 2 of the License, or
26078 + * (at your option) any later version.
26080 + * This program is distributed in the hope that it will be useful,
26081 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26082 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26083 + * GNU General Public License for more details.
26085 + * You should have received a copy of the GNU General Public License
26086 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26090 + * procfs interfaces
26093 +#include <linux/proc_fs.h>
26096 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
26098 + struct au_sbinfo *sbinfo;
26100 + sbinfo = file->private_data;
26102 + au_plink_maint_leave(sbinfo);
26103 + kobject_put(&sbinfo->si_kobj);
26109 +static void au_procfs_plm_write_clean(struct file *file)
26111 + struct au_sbinfo *sbinfo;
26113 + sbinfo = file->private_data;
26115 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
26118 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
26121 + struct super_block *sb;
26122 + struct au_sbinfo *sbinfo;
26125 + if (unlikely(file->private_data))
26129 + /* don't use au_sbilist_lock() here */
26130 + spin_lock(&au_sbilist.spin);
26131 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26132 + if (id == sysaufs_si_id(sbinfo)) {
26133 + kobject_get(&sbinfo->si_kobj);
26134 + sb = sbinfo->si_sb;
26137 + spin_unlock(&au_sbilist.spin);
26140 + if (unlikely(!sb))
26143 + err = au_plink_maint_enter(sb);
26145 + /* keep kobject_get() */
26146 + file->private_data = sbinfo;
26148 + kobject_put(&sbinfo->si_kobj);
26154 + * Accept a valid "si=xxxx" only.
26155 + * Once it is accepted successfully, accept "clean" too.
26157 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26158 + size_t count, loff_t *ppos)
26161 + unsigned long id;
26162 + /* last newline is allowed */
26163 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26166 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26170 + if (unlikely(count > sizeof(buf)))
26173 + err = copy_from_user(buf, ubuf, count);
26174 + if (unlikely(err)) {
26181 + if (!strcmp("clean", buf)) {
26182 + au_procfs_plm_write_clean(file);
26183 + goto out_success;
26184 + } else if (unlikely(strncmp("si=", buf, 3)))
26187 + err = kstrtoul(buf + 3, 16, &id);
26188 + if (unlikely(err))
26191 + err = au_procfs_plm_write_si(file, id);
26192 + if (unlikely(err))
26196 + err = count; /* success */
26201 +static const struct file_operations au_procfs_plm_fop = {
26202 + .write = au_procfs_plm_write,
26203 + .release = au_procfs_plm_release,
26204 + .owner = THIS_MODULE
26207 +/* ---------------------------------------------------------------------- */
26209 +static struct proc_dir_entry *au_procfs_dir;
26211 +void au_procfs_fin(void)
26213 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26214 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26217 +int __init au_procfs_init(void)
26220 + struct proc_dir_entry *entry;
26223 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26224 + if (unlikely(!au_procfs_dir))
26227 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26228 + au_procfs_dir, &au_procfs_plm_fop);
26229 + if (unlikely(!entry))
26233 + goto out; /* success */
26237 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26241 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26242 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26243 +++ linux/fs/aufs/rdu.c 2017-07-29 12:14:25.906375514 +0200
26246 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26248 + * This program, aufs is free software; you can redistribute it and/or modify
26249 + * it under the terms of the GNU General Public License as published by
26250 + * the Free Software Foundation; either version 2 of the License, or
26251 + * (at your option) any later version.
26253 + * This program is distributed in the hope that it will be useful,
26254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26256 + * GNU General Public License for more details.
26258 + * You should have received a copy of the GNU General Public License
26259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26263 + * readdir in userspace.
26266 +#include <linux/compat.h>
26267 +#include <linux/fs_stack.h>
26268 +#include <linux/security.h>
26271 +/* bits for struct aufs_rdu.flags */
26272 +#define AuRdu_CALLED 1
26273 +#define AuRdu_CONT (1 << 1)
26274 +#define AuRdu_FULL (1 << 2)
26275 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26276 +#define au_fset_rdu(flags, name) \
26277 + do { (flags) |= AuRdu_##name; } while (0)
26278 +#define au_fclr_rdu(flags, name) \
26279 + do { (flags) &= ~AuRdu_##name; } while (0)
26281 +struct au_rdu_arg {
26282 + struct dir_context ctx;
26283 + struct aufs_rdu *rdu;
26284 + union au_rdu_ent_ul ent;
26285 + unsigned long end;
26287 + struct super_block *sb;
26291 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26292 + loff_t offset, u64 h_ino, unsigned int d_type)
26295 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26296 + struct aufs_rdu *rdu = arg->rdu;
26297 + struct au_rdu_ent ent;
26301 + au_fset_rdu(rdu->cookie.flags, CALLED);
26302 + len = au_rdu_len(nlen);
26303 + if (arg->ent.ul + len < arg->end) {
26305 + ent.bindex = rdu->cookie.bindex;
26306 + ent.type = d_type;
26308 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26309 + ent.type = DT_UNKNOWN;
26311 + /* unnecessary to support mmap_sem since this is a dir */
26313 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26315 + if (copy_to_user(arg->ent.e->name, name, nlen))
26317 + /* the terminating NULL */
26318 + if (__put_user(0, arg->ent.e->name + nlen))
26321 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26322 + arg->ent.ul += len;
26326 + au_fset_rdu(rdu->cookie.flags, FULL);
26328 + rdu->tail = arg->ent;
26332 + /* AuTraceErr(err); */
26336 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26340 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26342 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26343 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26345 + if (unlikely(offset != cookie->h_pos))
26351 + au_fclr_rdu(cookie->flags, CALLED);
26353 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26357 + && au_ftest_rdu(cookie->flags, CALLED)
26358 + && !au_ftest_rdu(cookie->flags, FULL));
26359 + cookie->h_pos = h_file->f_pos;
26366 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26369 + aufs_bindex_t bbot;
26370 + struct au_rdu_arg arg = {
26372 + .actor = au_rdu_fill
26375 + struct dentry *dentry;
26376 + struct inode *inode;
26377 + struct file *h_file;
26378 + struct au_rdu_cookie *cookie = &rdu->cookie;
26380 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26381 + if (unlikely(err)) {
26387 + rdu->tail = rdu->ent;
26390 + arg.ent = rdu->ent;
26391 + arg.end = arg.ent.ul;
26392 + arg.end += rdu->sz;
26395 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26398 + err = security_file_permission(file, MAY_READ);
26400 + if (unlikely(err))
26403 + dentry = file->f_path.dentry;
26404 + inode = d_inode(dentry);
26405 + inode_lock_shared(inode);
26407 + arg.sb = inode->i_sb;
26408 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26409 + if (unlikely(err))
26411 + err = au_alive_dir(dentry);
26412 + if (unlikely(err))
26414 + /* todo: reval? */
26415 + fi_read_lock(file);
26418 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26419 + && cookie->generation != au_figen(file)))
26424 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26426 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26428 + bbot = au_fbtop(file);
26429 + if (cookie->bindex < bbot)
26430 + cookie->bindex = bbot;
26431 + bbot = au_fbbot_dir(file);
26432 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26433 + for (; !err && cookie->bindex <= bbot;
26434 + cookie->bindex++, cookie->h_pos = 0) {
26435 + h_file = au_hf_dir(file, cookie->bindex);
26439 + au_fclr_rdu(cookie->flags, FULL);
26440 + err = au_rdu_do(h_file, &arg);
26442 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26445 + AuDbg("rent %llu\n", rdu->rent);
26447 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26448 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26449 + au_fset_rdu(cookie->flags, CONT);
26450 + cookie->generation = au_figen(file);
26453 + ii_read_lock_child(inode);
26454 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26455 + ii_read_unlock(inode);
26458 + fi_read_unlock(file);
26460 + si_read_unlock(arg.sb);
26462 + inode_unlock_shared(inode);
26468 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26472 + unsigned long long nent;
26473 + union au_rdu_ent_ul *u;
26474 + struct au_rdu_ent ent;
26475 + struct super_block *sb;
26478 + nent = rdu->nent;
26480 + sb = file->f_path.dentry->d_sb;
26481 + si_read_lock(sb, AuLock_FLUSH);
26482 + while (nent-- > 0) {
26483 + /* unnecessary to support mmap_sem since this is a dir */
26484 + err = copy_from_user(&ent, u->e, sizeof(ent));
26486 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26487 + if (unlikely(err)) {
26493 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26495 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26497 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26499 + if (unlikely(err)) {
26504 + err = __put_user(ino, &u->e->ino);
26505 + if (unlikely(err)) {
26510 + u->ul += au_rdu_len(ent.nlen);
26512 + si_read_unlock(sb);
26517 +/* ---------------------------------------------------------------------- */
26519 +static int au_rdu_verify(struct aufs_rdu *rdu)
26521 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26522 + "%llu, b%d, 0x%x, g%u}\n",
26523 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26525 + rdu->rent, rdu->shwh, rdu->full,
26526 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26527 + rdu->cookie.generation);
26529 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26533 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26537 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26540 + struct aufs_rdu rdu;
26541 + void __user *p = (void __user *)arg;
26543 + err = copy_from_user(&rdu, p, sizeof(rdu));
26544 + if (unlikely(err)) {
26549 + err = au_rdu_verify(&rdu);
26550 + if (unlikely(err))
26554 + case AUFS_CTL_RDU:
26555 + err = au_rdu(file, &rdu);
26556 + if (unlikely(err))
26559 + e = copy_to_user(p, &rdu, sizeof(rdu));
26560 + if (unlikely(e)) {
26565 + case AUFS_CTL_RDU_INO:
26566 + err = au_rdu_ino(file, &rdu);
26570 + /* err = -ENOTTY; */
26579 +#ifdef CONFIG_COMPAT
26580 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26583 + struct aufs_rdu rdu;
26584 + void __user *p = compat_ptr(arg);
26586 + /* todo: get_user()? */
26587 + err = copy_from_user(&rdu, p, sizeof(rdu));
26588 + if (unlikely(err)) {
26593 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26594 + err = au_rdu_verify(&rdu);
26595 + if (unlikely(err))
26599 + case AUFS_CTL_RDU:
26600 + err = au_rdu(file, &rdu);
26601 + if (unlikely(err))
26604 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26605 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26606 + e = copy_to_user(p, &rdu, sizeof(rdu));
26607 + if (unlikely(e)) {
26612 + case AUFS_CTL_RDU_INO:
26613 + err = au_rdu_ino(file, &rdu);
26617 + /* err = -ENOTTY; */
26626 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26627 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26628 +++ linux/fs/aufs/rwsem.h 2017-07-29 12:14:25.906375514 +0200
26631 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26633 + * This program, aufs is free software; you can redistribute it and/or modify
26634 + * it under the terms of the GNU General Public License as published by
26635 + * the Free Software Foundation; either version 2 of the License, or
26636 + * (at your option) any later version.
26638 + * This program is distributed in the hope that it will be useful,
26639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26641 + * GNU General Public License for more details.
26643 + * You should have received a copy of the GNU General Public License
26644 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26648 + * simple read-write semaphore wrappers
26651 +#ifndef __AUFS_RWSEM_H__
26652 +#define __AUFS_RWSEM_H__
26656 +#include "debug.h"
26659 + struct rw_semaphore rwsem;
26660 +#ifdef CONFIG_AUFS_DEBUG
26661 + /* just for debugging, not almighty counter */
26662 + atomic_t rcnt, wcnt;
26666 +#ifdef CONFIG_LOCKDEP
26667 +#define au_lockdep_set_name(rw) \
26668 + lockdep_set_class_and_name(&(rw)->rwsem, \
26669 + /*original key*/(rw)->rwsem.dep_map.key, \
26672 +#define au_lockdep_set_name(rw) do {} while (0)
26675 +#ifdef CONFIG_AUFS_DEBUG
26676 +#define AuDbgCntInit(rw) do { \
26677 + atomic_set(&(rw)->rcnt, 0); \
26678 + atomic_set(&(rw)->wcnt, 0); \
26679 + smp_mb(); /* atomic set */ \
26682 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26683 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26684 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26685 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26686 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26687 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26688 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26690 +#define AuDbgCnt(rw, cnt) 0
26691 +#define AuDbgCntInit(rw) do {} while (0)
26692 +#define AuDbgRcntInc(rw) do {} while (0)
26693 +#define AuDbgRcntDec(rw) do {} while (0)
26694 +#define AuDbgWcntInc(rw) do {} while (0)
26695 +#define AuDbgWcntDec(rw) do {} while (0)
26696 +#endif /* CONFIG_AUFS_DEBUG */
26698 +/* to debug easier, do not make them inlined functions */
26699 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26700 +/* rwsem_is_locked() is unusable */
26701 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26702 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26703 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26704 + && AuDbgCnt(rw, wcnt) <= 0)
26705 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26706 + || AuDbgCnt(rw, wcnt))
26708 +#define au_rw_init(rw) do { \
26709 + AuDbgCntInit(rw); \
26710 + init_rwsem(&(rw)->rwsem); \
26711 + au_lockdep_set_name(rw); \
26714 +#define au_rw_init_wlock(rw) do { \
26715 + au_rw_init(rw); \
26716 + down_write(&(rw)->rwsem); \
26717 + AuDbgWcntInc(rw); \
26720 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26721 + au_rw_init(rw); \
26722 + down_write_nested(&(rw)->rwsem, lsc); \
26723 + AuDbgWcntInc(rw); \
26726 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26728 + down_read(&rw->rwsem);
26729 + AuDbgRcntInc(rw);
26732 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26734 + down_read_nested(&rw->rwsem, lsc);
26735 + AuDbgRcntInc(rw);
26738 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26740 + AuRwMustReadLock(rw);
26741 + AuDbgRcntDec(rw);
26742 + up_read(&rw->rwsem);
26745 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26747 + AuRwMustWriteLock(rw);
26748 + AuDbgRcntInc(rw);
26749 + AuDbgWcntDec(rw);
26750 + downgrade_write(&rw->rwsem);
26753 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26755 + down_write(&rw->rwsem);
26756 + AuDbgWcntInc(rw);
26759 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26760 + unsigned int lsc)
26762 + down_write_nested(&rw->rwsem, lsc);
26763 + AuDbgWcntInc(rw);
26766 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26768 + AuRwMustWriteLock(rw);
26769 + AuDbgWcntDec(rw);
26770 + up_write(&rw->rwsem);
26773 +/* why is not _nested version defined */
26774 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26778 + ret = down_read_trylock(&rw->rwsem);
26780 + AuDbgRcntInc(rw);
26784 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26788 + ret = down_write_trylock(&rw->rwsem);
26790 + AuDbgWcntInc(rw);
26794 +#undef AuDbgCntDec
26795 +#undef AuDbgRcntInc
26796 +#undef AuDbgRcntDec
26797 +#undef AuDbgWcntDec
26799 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26800 +static inline void prefix##_read_lock(param) \
26801 +{ au_rw_read_lock(rwsem); } \
26802 +static inline void prefix##_write_lock(param) \
26803 +{ au_rw_write_lock(rwsem); } \
26804 +static inline int prefix##_read_trylock(param) \
26805 +{ return au_rw_read_trylock(rwsem); } \
26806 +static inline int prefix##_write_trylock(param) \
26807 +{ return au_rw_write_trylock(rwsem); }
26808 +/* why is not _nested version defined */
26809 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26810 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26811 +static inline void prefix##_write_trylock_nestd(param, lsc)
26812 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26814 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26815 +static inline void prefix##_read_unlock(param) \
26816 +{ au_rw_read_unlock(rwsem); } \
26817 +static inline void prefix##_write_unlock(param) \
26818 +{ au_rw_write_unlock(rwsem); } \
26819 +static inline void prefix##_downgrade_lock(param) \
26820 +{ au_rw_dgrade_lock(rwsem); }
26822 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26823 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26824 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26826 +#endif /* __KERNEL__ */
26827 +#endif /* __AUFS_RWSEM_H__ */
26828 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26829 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26830 +++ linux/fs/aufs/sbinfo.c 2017-07-29 12:14:25.906375514 +0200
26833 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26835 + * This program, aufs is free software; you can redistribute it and/or modify
26836 + * it under the terms of the GNU General Public License as published by
26837 + * the Free Software Foundation; either version 2 of the License, or
26838 + * (at your option) any later version.
26840 + * This program is distributed in the hope that it will be useful,
26841 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26842 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26843 + * GNU General Public License for more details.
26845 + * You should have received a copy of the GNU General Public License
26846 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26850 + * superblock private data
26856 + * they are necessary regardless sysfs is disabled.
26858 +void au_si_free(struct kobject *kobj)
26861 + struct au_sbinfo *sbinfo;
26862 + char *locked __maybe_unused; /* debug only */
26864 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26865 + for (i = 0; i < AuPlink_NHASH; i++)
26866 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26867 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26869 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26870 + percpu_counter_destroy(&sbinfo->si_ninodes);
26871 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26872 + percpu_counter_destroy(&sbinfo->si_nfiles);
26874 + au_rw_write_lock(&sbinfo->si_rwsem);
26875 + au_br_free(sbinfo);
26876 + au_rw_write_unlock(&sbinfo->si_rwsem);
26878 + kfree(sbinfo->si_branch);
26879 + mutex_destroy(&sbinfo->si_xib_mtx);
26880 + AuRwDestroy(&sbinfo->si_rwsem);
26885 +int au_si_alloc(struct super_block *sb)
26888 + struct au_sbinfo *sbinfo;
26891 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26892 + if (unlikely(!sbinfo))
26895 + /* will be reallocated separately */
26896 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26897 + if (unlikely(!sbinfo->si_branch))
26900 + err = sysaufs_si_init(sbinfo);
26901 + if (unlikely(err))
26904 + au_nwt_init(&sbinfo->si_nowait);
26905 + au_rw_init_wlock(&sbinfo->si_rwsem);
26907 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26908 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26910 + sbinfo->si_bbot = -1;
26911 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26913 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26914 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26915 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26916 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26918 + au_fhsm_init(sbinfo);
26920 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26922 + sbinfo->si_xino_jiffy = jiffies;
26923 + sbinfo->si_xino_expire
26924 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26925 + mutex_init(&sbinfo->si_xib_mtx);
26926 + sbinfo->si_xino_brid = -1;
26927 + /* leave si_xib_last_pindex and si_xib_next_bit */
26929 + au_sphl_init(&sbinfo->si_aopen);
26931 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26932 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26933 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26934 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26936 + for (i = 0; i < AuPlink_NHASH; i++)
26937 + au_sphl_init(sbinfo->si_plink + i);
26938 + init_waitqueue_head(&sbinfo->si_plink_wq);
26939 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26941 + au_sphl_init(&sbinfo->si_files);
26943 + /* with getattr by default */
26944 + sbinfo->si_iop_array = aufs_iop;
26946 + /* leave other members for sysaufs and si_mnt. */
26947 + sbinfo->si_sb = sb;
26948 + sb->s_fs_info = sbinfo;
26950 + return 0; /* success */
26953 + kfree(sbinfo->si_branch);
26960 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
26963 + struct au_branch **brp;
26965 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26968 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26969 + if (unlikely(!sz))
26970 + sz = sizeof(*brp);
26971 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
26974 + sbinfo->si_branch = brp;
26981 +/* ---------------------------------------------------------------------- */
26983 +unsigned int au_sigen_inc(struct super_block *sb)
26985 + unsigned int gen;
26986 + struct inode *inode;
26988 + SiMustWriteLock(sb);
26990 + gen = ++au_sbi(sb)->si_generation;
26991 + au_update_digen(sb->s_root);
26992 + inode = d_inode(sb->s_root);
26993 + au_update_iigen(inode, /*half*/0);
26994 + inode->i_version++;
26998 +aufs_bindex_t au_new_br_id(struct super_block *sb)
27000 + aufs_bindex_t br_id;
27002 + struct au_sbinfo *sbinfo;
27004 + SiMustWriteLock(sb);
27006 + sbinfo = au_sbi(sb);
27007 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
27008 + br_id = ++sbinfo->si_last_br_id;
27009 + AuDebugOn(br_id < 0);
27010 + if (br_id && au_br_index(sb, br_id) < 0)
27017 +/* ---------------------------------------------------------------------- */
27019 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
27020 +int si_read_lock(struct super_block *sb, int flags)
27025 + if (au_ftest_lock(flags, FLUSH))
27026 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27028 + si_noflush_read_lock(sb);
27029 + err = au_plink_maint(sb, flags);
27030 + if (unlikely(err))
27031 + si_read_unlock(sb);
27036 +int si_write_lock(struct super_block *sb, int flags)
27040 + if (au_ftest_lock(flags, FLUSH))
27041 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27043 + si_noflush_write_lock(sb);
27044 + err = au_plink_maint(sb, flags);
27045 + if (unlikely(err))
27046 + si_write_unlock(sb);
27051 +/* dentry and super_block lock. call at entry point */
27052 +int aufs_read_lock(struct dentry *dentry, int flags)
27055 + struct super_block *sb;
27057 + sb = dentry->d_sb;
27058 + err = si_read_lock(sb, flags);
27059 + if (unlikely(err))
27062 + if (au_ftest_lock(flags, DW))
27063 + di_write_lock_child(dentry);
27065 + di_read_lock_child(dentry, flags);
27067 + if (au_ftest_lock(flags, GEN)) {
27068 + err = au_digen_test(dentry, au_sigen(sb));
27069 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
27070 + AuDebugOn(!err && au_dbrange_test(dentry));
27072 + err = au_dbrange_test(dentry);
27073 + if (unlikely(err))
27074 + aufs_read_unlock(dentry, flags);
27081 +void aufs_read_unlock(struct dentry *dentry, int flags)
27083 + if (au_ftest_lock(flags, DW))
27084 + di_write_unlock(dentry);
27086 + di_read_unlock(dentry, flags);
27087 + si_read_unlock(dentry->d_sb);
27090 +void aufs_write_lock(struct dentry *dentry)
27092 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
27093 + di_write_lock_child(dentry);
27096 +void aufs_write_unlock(struct dentry *dentry)
27098 + di_write_unlock(dentry);
27099 + si_write_unlock(dentry->d_sb);
27102 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
27105 + unsigned int sigen;
27106 + struct super_block *sb;
27109 + err = si_read_lock(sb, flags);
27110 + if (unlikely(err))
27113 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
27115 + if (au_ftest_lock(flags, GEN)) {
27116 + sigen = au_sigen(sb);
27117 + err = au_digen_test(d1, sigen);
27118 + AuDebugOn(!err && au_dbrange_test(d1));
27120 + err = au_digen_test(d2, sigen);
27121 + AuDebugOn(!err && au_dbrange_test(d2));
27123 + if (unlikely(err))
27124 + aufs_read_and_write_unlock2(d1, d2);
27131 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
27133 + di_write_unlock2(d1, d2);
27134 + si_read_unlock(d1->d_sb);
27136 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27137 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27138 +++ linux/fs/aufs/spl.h 2017-07-29 12:14:25.906375514 +0200
27141 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27143 + * This program, aufs is free software; you can redistribute it and/or modify
27144 + * it under the terms of the GNU General Public License as published by
27145 + * the Free Software Foundation; either version 2 of the License, or
27146 + * (at your option) any later version.
27148 + * This program is distributed in the hope that it will be useful,
27149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27151 + * GNU General Public License for more details.
27153 + * You should have received a copy of the GNU General Public License
27154 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27158 + * simple list protected by a spinlock
27161 +#ifndef __AUFS_SPL_H__
27162 +#define __AUFS_SPL_H__
27167 +struct au_splhead {
27169 + struct list_head head;
27172 +static inline void au_spl_init(struct au_splhead *spl)
27174 + spin_lock_init(&spl->spin);
27175 + INIT_LIST_HEAD(&spl->head);
27178 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27180 + spin_lock(&spl->spin);
27181 + list_add(list, &spl->head);
27182 + spin_unlock(&spl->spin);
27185 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27187 + spin_lock(&spl->spin);
27189 + spin_unlock(&spl->spin);
27192 +static inline void au_spl_del_rcu(struct list_head *list,
27193 + struct au_splhead *spl)
27195 + spin_lock(&spl->spin);
27196 + list_del_rcu(list);
27197 + spin_unlock(&spl->spin);
27201 +/* ---------------------------------------------------------------------- */
27203 +struct au_sphlhead {
27205 + struct hlist_head head;
27208 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27210 + spin_lock_init(&sphl->spin);
27211 + INIT_HLIST_HEAD(&sphl->head);
27214 +static inline void au_sphl_add(struct hlist_node *hlist,
27215 + struct au_sphlhead *sphl)
27217 + spin_lock(&sphl->spin);
27218 + hlist_add_head(hlist, &sphl->head);
27219 + spin_unlock(&sphl->spin);
27222 +static inline void au_sphl_del(struct hlist_node *hlist,
27223 + struct au_sphlhead *sphl)
27225 + spin_lock(&sphl->spin);
27226 + hlist_del(hlist);
27227 + spin_unlock(&sphl->spin);
27230 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27231 + struct au_sphlhead *sphl)
27233 + spin_lock(&sphl->spin);
27234 + hlist_del_rcu(hlist);
27235 + spin_unlock(&sphl->spin);
27238 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27240 + unsigned long cnt;
27241 + struct hlist_node *pos;
27244 + spin_lock(&sphl->spin);
27245 + hlist_for_each(pos, &sphl->head)
27247 + spin_unlock(&sphl->spin);
27251 +#endif /* __KERNEL__ */
27252 +#endif /* __AUFS_SPL_H__ */
27253 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27254 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27255 +++ linux/fs/aufs/super.c 2017-07-29 12:14:25.906375514 +0200
27258 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27260 + * This program, aufs is free software; you can redistribute it and/or modify
27261 + * it under the terms of the GNU General Public License as published by
27262 + * the Free Software Foundation; either version 2 of the License, or
27263 + * (at your option) any later version.
27265 + * This program is distributed in the hope that it will be useful,
27266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27268 + * GNU General Public License for more details.
27270 + * You should have received a copy of the GNU General Public License
27271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27275 + * mount and super_block operations
27278 +#include <linux/mm.h>
27279 +#include <linux/seq_file.h>
27280 +#include <linux/statfs.h>
27281 +#include <linux/vmalloc.h>
27285 + * super_operations
27287 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27289 + struct au_icntnr *c;
27291 + c = au_cache_alloc_icntnr();
27293 + au_icntnr_init(c);
27294 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27295 + c->iinfo.ii_hinode = NULL;
27296 + return &c->vfs_inode;
27301 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27303 + struct inode *inode = container_of(head, struct inode, i_rcu);
27305 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27308 +static void aufs_destroy_inode(struct inode *inode)
27310 + if (!au_is_bad_inode(inode))
27311 + au_iinfo_fin(inode);
27312 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27315 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27317 + struct inode *inode;
27320 + inode = iget_locked(sb, ino);
27321 + if (unlikely(!inode)) {
27322 + inode = ERR_PTR(-ENOMEM);
27325 + if (!(inode->i_state & I_NEW))
27328 + err = au_xigen_new(inode);
27330 + err = au_iinfo_init(inode);
27332 + inode->i_version++;
27334 + iget_failed(inode);
27335 + inode = ERR_PTR(err);
27339 + /* never return NULL */
27340 + AuDebugOn(!inode);
27341 + AuTraceErrPtr(inode);
27345 +/* lock free root dinfo */
27346 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27349 + aufs_bindex_t bindex, bbot;
27350 + struct path path;
27351 + struct au_hdentry *hdp;
27352 + struct au_branch *br;
27353 + au_br_perm_str_t perm;
27356 + bbot = au_sbbot(sb);
27358 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27359 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27360 + br = au_sbr(sb, bindex);
27361 + path.mnt = au_br_mnt(br);
27362 + path.dentry = hdp->hd_dentry;
27363 + err = au_seq_path(seq, &path);
27365 + au_optstr_br_perm(&perm, br->br_perm);
27366 + seq_printf(seq, "=%s", perm.a);
27367 + if (bindex != bbot)
27368 + seq_putc(seq, ':');
27371 + if (unlikely(err || seq_has_overflowed(seq)))
27377 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
27378 + const char *append)
27383 + while (*pat != ':')
27386 + strcpy(p, append);
27387 + AuDebugOn(strlen(fmt) >= len);
27390 +static void au_show_wbr_create(struct seq_file *m, int v,
27391 + struct au_sbinfo *sbinfo)
27395 + struct au_wbr_mfs *mfs;
27397 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27399 + seq_puts(m, ",create=");
27400 + pat = au_optstr_wbr_create(v);
27401 + mfs = &sbinfo->si_wbr_mfs;
27403 + case AuWbrCreate_TDP:
27404 + case AuWbrCreate_RR:
27405 + case AuWbrCreate_MFS:
27406 + case AuWbrCreate_PMFS:
27407 + seq_puts(m, pat);
27409 + case AuWbrCreate_MFSRR:
27410 + case AuWbrCreate_TDMFS:
27411 + case AuWbrCreate_PMFSRR:
27412 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
27413 + seq_printf(m, fmt, mfs->mfsrr_watermark);
27415 + case AuWbrCreate_MFSV:
27416 + case AuWbrCreate_PMFSV:
27417 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
27418 + seq_printf(m, fmt,
27419 + jiffies_to_msecs(mfs->mfs_expire)
27422 + case AuWbrCreate_MFSRRV:
27423 + case AuWbrCreate_TDMFSV:
27424 + case AuWbrCreate_PMFSRRV:
27425 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
27426 + seq_printf(m, fmt, mfs->mfsrr_watermark,
27427 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
27434 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27436 +#ifdef CONFIG_SYSFS
27440 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27441 + aufs_bindex_t bindex, brid;
27442 + struct qstr *name;
27444 + struct dentry *d, *h_root;
27446 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27449 + f = au_sbi(sb)->si_xib;
27453 + /* stop printing the default xino path on the first writable branch */
27455 + brid = au_xino_brid(sb);
27457 + bindex = au_br_index(sb, brid);
27458 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27460 + d = f->f_path.dentry;
27461 + name = &d->d_name;
27462 + /* safe ->d_parent because the file is unlinked */
27463 + if (d->d_parent == h_root
27464 + && name->len == len
27465 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27468 + seq_puts(seq, ",xino=");
27469 + err = au_xino_path(seq, f);
27476 +/* seq_file will re-call me in case of too long string */
27477 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27480 + unsigned int mnt_flags, v;
27481 + struct super_block *sb;
27482 + struct au_sbinfo *sbinfo;
27484 +#define AuBool(name, str) do { \
27485 + v = au_opt_test(mnt_flags, name); \
27486 + if (v != au_opt_test(AuOpt_Def, name)) \
27487 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27490 +#define AuStr(name, str) do { \
27491 + v = mnt_flags & AuOptMask_##name; \
27492 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27493 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27496 +#define AuUInt(name, str, val) do { \
27497 + if (val != AUFS_##name##_DEF) \
27498 + seq_printf(m, "," #str "=%u", val); \
27501 + sb = dentry->d_sb;
27502 + if (sb->s_flags & MS_POSIXACL)
27503 + seq_puts(m, ",acl");
27505 + /* lock free root dinfo */
27506 + si_noflush_read_lock(sb);
27507 + sbinfo = au_sbi(sb);
27508 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27510 + mnt_flags = au_mntflags(sb);
27511 + if (au_opt_test(mnt_flags, XINO)) {
27512 + err = au_show_xino(m, sb);
27513 + if (unlikely(err))
27516 + seq_puts(m, ",noxino");
27518 + AuBool(TRUNC_XINO, trunc_xino);
27519 + AuStr(UDBA, udba);
27520 + AuBool(SHWH, shwh);
27521 + AuBool(PLINK, plink);
27522 + AuBool(DIO, dio);
27523 + AuBool(DIRPERM1, dirperm1);
27525 + v = sbinfo->si_wbr_create;
27526 + if (v != AuWbrCreate_Def)
27527 + au_show_wbr_create(m, v, sbinfo);
27529 + v = sbinfo->si_wbr_copyup;
27530 + if (v != AuWbrCopyup_Def)
27531 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27533 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27534 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27535 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27537 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27539 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27540 + AuUInt(RDCACHE, rdcache, v);
27542 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27543 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27545 + au_fhsm_show(m, sbinfo);
27547 + AuBool(SUM, sum);
27548 + /* AuBool(SUM_W, wsum); */
27549 + AuBool(WARN_PERM, warn_perm);
27550 + AuBool(VERBOSE, verbose);
27553 + /* be sure to print "br:" last */
27554 + if (!sysaufs_brs) {
27555 + seq_puts(m, ",br:");
27556 + au_show_brs(m, sb);
27558 + si_read_unlock(sb);
27566 +/* ---------------------------------------------------------------------- */
27568 +/* sum mode which returns the summation for statfs(2) */
27570 +static u64 au_add_till_max(u64 a, u64 b)
27578 + return ULLONG_MAX;
27581 +static u64 au_mul_till_max(u64 a, long mul)
27589 + return ULLONG_MAX;
27592 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27595 + long bsize, factor;
27596 + u64 blocks, bfree, bavail, files, ffree;
27597 + aufs_bindex_t bbot, bindex, i;
27598 + unsigned char shared;
27599 + struct path h_path;
27600 + struct super_block *h_sb;
27603 + bsize = LONG_MAX;
27609 + bbot = au_sbbot(sb);
27610 + for (bindex = 0; bindex <= bbot; bindex++) {
27611 + h_path.mnt = au_sbr_mnt(sb, bindex);
27612 + h_sb = h_path.mnt->mnt_sb;
27614 + for (i = 0; !shared && i < bindex; i++)
27615 + shared = (au_sbr_sb(sb, i) == h_sb);
27619 + /* sb->s_root for NFS is unreliable */
27620 + h_path.dentry = h_path.mnt->mnt_root;
27621 + err = vfs_statfs(&h_path, buf);
27622 + if (unlikely(err))
27625 + if (bsize > buf->f_bsize) {
27627 + * we will reduce bsize, so we have to expand blocks
27628 + * etc. to match them again
27630 + factor = (bsize / buf->f_bsize);
27631 + blocks = au_mul_till_max(blocks, factor);
27632 + bfree = au_mul_till_max(bfree, factor);
27633 + bavail = au_mul_till_max(bavail, factor);
27634 + bsize = buf->f_bsize;
27637 + factor = (buf->f_bsize / bsize);
27638 + blocks = au_add_till_max(blocks,
27639 + au_mul_till_max(buf->f_blocks, factor));
27640 + bfree = au_add_till_max(bfree,
27641 + au_mul_till_max(buf->f_bfree, factor));
27642 + bavail = au_add_till_max(bavail,
27643 + au_mul_till_max(buf->f_bavail, factor));
27644 + files = au_add_till_max(files, buf->f_files);
27645 + ffree = au_add_till_max(ffree, buf->f_ffree);
27648 + buf->f_bsize = bsize;
27649 + buf->f_blocks = blocks;
27650 + buf->f_bfree = bfree;
27651 + buf->f_bavail = bavail;
27652 + buf->f_files = files;
27653 + buf->f_ffree = ffree;
27654 + buf->f_frsize = 0;
27660 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27663 + struct path h_path;
27664 + struct super_block *sb;
27666 + /* lock free root dinfo */
27667 + sb = dentry->d_sb;
27668 + si_noflush_read_lock(sb);
27669 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27670 + /* sb->s_root for NFS is unreliable */
27671 + h_path.mnt = au_sbr_mnt(sb, 0);
27672 + h_path.dentry = h_path.mnt->mnt_root;
27673 + err = vfs_statfs(&h_path, buf);
27675 + err = au_statfs_sum(sb, buf);
27676 + si_read_unlock(sb);
27679 + buf->f_type = AUFS_SUPER_MAGIC;
27680 + buf->f_namelen = AUFS_MAX_NAMELEN;
27681 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27683 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27688 +/* ---------------------------------------------------------------------- */
27690 +static int aufs_sync_fs(struct super_block *sb, int wait)
27693 + aufs_bindex_t bbot, bindex;
27694 + struct au_branch *br;
27695 + struct super_block *h_sb;
27698 + si_noflush_read_lock(sb);
27699 + bbot = au_sbbot(sb);
27700 + for (bindex = 0; bindex <= bbot; bindex++) {
27701 + br = au_sbr(sb, bindex);
27702 + if (!au_br_writable(br->br_perm))
27705 + h_sb = au_sbr_sb(sb, bindex);
27706 + e = vfsub_sync_filesystem(h_sb, wait);
27707 + if (unlikely(e && !err))
27709 + /* go on even if an error happens */
27711 + si_read_unlock(sb);
27716 +/* ---------------------------------------------------------------------- */
27718 +/* final actions when unmounting a file system */
27719 +static void aufs_put_super(struct super_block *sb)
27721 + struct au_sbinfo *sbinfo;
27723 + sbinfo = au_sbi(sb);
27727 + dbgaufs_si_fin(sbinfo);
27728 + kobject_put(&sbinfo->si_kobj);
27731 +/* ---------------------------------------------------------------------- */
27733 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27734 + struct super_block *sb, void *arg)
27737 + unsigned long long n, sz;
27744 + if (*hint > ULLONG_MAX / sizeof(array)) {
27745 + array = ERR_PTR(-EMFILE);
27746 + pr_err("hint %llu\n", *hint);
27750 + sz = sizeof(array) * *hint;
27751 + array = kzalloc(sz, GFP_NOFS);
27752 + if (unlikely(!array))
27753 + array = vzalloc(sz);
27754 + if (unlikely(!array)) {
27755 + array = ERR_PTR(-ENOMEM);
27759 + n = cb(sb, array, *hint, arg);
27760 + AuDebugOn(n > *hint);
27767 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27768 + unsigned long long max __maybe_unused,
27771 + unsigned long long n;
27772 + struct inode **p, *inode;
27773 + struct list_head *head;
27778 + spin_lock(&sb->s_inode_list_lock);
27779 + list_for_each_entry(inode, head, i_sb_list) {
27780 + if (!au_is_bad_inode(inode)
27781 + && au_ii(inode)->ii_btop >= 0) {
27782 + spin_lock(&inode->i_lock);
27783 + if (atomic_read(&inode->i_count)) {
27787 + AuDebugOn(n > max);
27789 + spin_unlock(&inode->i_lock);
27792 + spin_unlock(&sb->s_inode_list_lock);
27797 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27799 + *max = au_ninodes(sb);
27800 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27803 +void au_iarray_free(struct inode **a, unsigned long long max)
27805 + unsigned long long ull;
27807 + for (ull = 0; ull < max; ull++)
27812 +/* ---------------------------------------------------------------------- */
27815 + * refresh dentry and inode at remount time.
27817 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27818 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27819 + struct dentry *parent)
27823 + di_write_lock_child(dentry);
27824 + di_read_lock_parent(parent, AuLock_IR);
27825 + err = au_refresh_dentry(dentry, parent);
27826 + if (!err && dir_flags)
27827 + au_hn_reset(d_inode(dentry), dir_flags);
27828 + di_read_unlock(parent, AuLock_IR);
27829 + di_write_unlock(dentry);
27834 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27835 + struct au_sbinfo *sbinfo,
27836 + const unsigned int dir_flags, unsigned int do_idop)
27839 + struct dentry *parent;
27842 + parent = dget_parent(dentry);
27843 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27844 + if (d_really_is_positive(dentry)) {
27845 + if (!d_is_dir(dentry))
27846 + err = au_do_refresh(dentry, /*dir_flags*/0,
27849 + err = au_do_refresh(dentry, dir_flags, parent);
27850 + if (unlikely(err))
27851 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27854 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27855 + AuDbgDentry(dentry);
27861 + au_refresh_dop(dentry, /*force_reval*/0);
27863 + au_refresh_dop(dentry, /*force_reval*/1);
27869 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27871 + int err, i, j, ndentry, e;
27872 + unsigned int sigen;
27873 + struct au_dcsub_pages dpages;
27874 + struct au_dpage *dpage;
27875 + struct dentry **dentries, *d;
27876 + struct au_sbinfo *sbinfo;
27877 + struct dentry *root = sb->s_root;
27878 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27881 + au_refresh_dop(root, /*force_reval*/0);
27883 + err = au_dpages_init(&dpages, GFP_NOFS);
27884 + if (unlikely(err))
27886 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27887 + if (unlikely(err))
27890 + sigen = au_sigen(sb);
27891 + sbinfo = au_sbi(sb);
27892 + for (i = 0; i < dpages.ndpage; i++) {
27893 + dpage = dpages.dpages + i;
27894 + dentries = dpage->dentries;
27895 + ndentry = dpage->ndentry;
27896 + for (j = 0; j < ndentry; j++) {
27898 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27900 + if (unlikely(e && !err))
27902 + /* go on even err */
27907 + au_dpages_free(&dpages);
27912 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27915 + unsigned int sigen;
27916 + unsigned long long max, ull;
27917 + struct inode *inode, **array;
27919 + array = au_iarray_alloc(sb, &max);
27920 + err = PTR_ERR(array);
27921 + if (IS_ERR(array))
27925 + sigen = au_sigen(sb);
27926 + for (ull = 0; ull < max; ull++) {
27927 + inode = array[ull];
27928 + if (unlikely(!inode))
27932 + ii_write_lock_child(inode);
27933 + if (au_iigen(inode, NULL) != sigen) {
27934 + e = au_refresh_hinode_self(inode);
27935 + if (unlikely(e)) {
27936 + au_refresh_iop(inode, /*force_getattr*/1);
27937 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27940 + /* go on even if err */
27943 + if (!e && do_idop)
27944 + au_refresh_iop(inode, /*force_getattr*/0);
27945 + ii_write_unlock(inode);
27948 + au_iarray_free(array, max);
27954 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27957 + unsigned int udba;
27958 + aufs_bindex_t bindex, bbot;
27959 + struct dentry *root;
27960 + struct inode *inode;
27961 + struct au_branch *br;
27962 + struct au_sbinfo *sbi;
27964 + au_sigen_inc(sb);
27965 + sbi = au_sbi(sb);
27966 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27968 + root = sb->s_root;
27969 + DiMustNoWaiters(root);
27970 + inode = d_inode(root);
27971 + IiMustNoWaiters(inode);
27973 + udba = au_opt_udba(sb);
27974 + bbot = au_sbbot(sb);
27975 + for (bindex = 0; bindex <= bbot; bindex++) {
27976 + br = au_sbr(sb, bindex);
27977 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27978 + if (unlikely(err))
27979 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27981 + /* go on even if err */
27983 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27986 + if (au_ftest_si(sbi, NO_DREVAL)) {
27987 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27988 + sb->s_d_op = &aufs_dop_noreval;
27989 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27990 + sbi->si_iop_array = aufs_iop_nogetattr;
27992 + AuDebugOn(sb->s_d_op == &aufs_dop);
27993 + sb->s_d_op = &aufs_dop;
27994 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27995 + sbi->si_iop_array = aufs_iop;
27997 + pr_info("reset to %pf and %pf\n",
27998 + sb->s_d_op, sbi->si_iop_array);
28001 + di_write_unlock(root);
28002 + err = au_refresh_d(sb, do_idop);
28003 + e = au_refresh_i(sb, do_idop);
28004 + if (unlikely(e && !err))
28006 + /* aufs_write_lock() calls ..._child() */
28007 + di_write_lock_child(root);
28009 + au_cpup_attr_all(inode, /*force*/1);
28011 + if (unlikely(err))
28012 + AuIOErr("refresh failed, ignored, %d\n", err);
28015 +/* stop extra interpretation of errno in mount(8), and strange error messages */
28016 +static int cvt_err(int err)
28030 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
28033 + unsigned int mntflags;
28034 + struct au_opts opts = {
28037 + struct dentry *root;
28038 + struct inode *inode;
28039 + struct au_sbinfo *sbinfo;
28042 + root = sb->s_root;
28043 + if (!data || !*data) {
28044 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28046 + di_write_lock_child(root);
28047 + err = au_opts_verify(sb, *flags, /*pending*/0);
28048 + aufs_write_unlock(root);
28054 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28055 + if (unlikely(!opts.opt))
28057 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28058 + opts.flags = AuOpts_REMOUNT;
28059 + opts.sb_flags = *flags;
28061 + /* parse it before aufs lock */
28062 + err = au_opts_parse(sb, data, &opts);
28063 + if (unlikely(err))
28066 + sbinfo = au_sbi(sb);
28067 + inode = d_inode(root);
28068 + inode_lock(inode);
28069 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28070 + if (unlikely(err))
28072 + di_write_lock_child(root);
28074 + /* au_opts_remount() may return an error */
28075 + err = au_opts_remount(sb, &opts);
28076 + au_opts_free(&opts);
28078 + if (au_ftest_opts(opts.flags, REFRESH))
28079 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
28081 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
28082 + mntflags = au_mntflags(sb);
28083 + do_dx = !!au_opt_test(mntflags, DIO);
28084 + au_dy_arefresh(do_dx);
28087 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
28088 + aufs_write_unlock(root);
28091 + inode_unlock(inode);
28093 + free_page((unsigned long)opts.opt);
28095 + err = cvt_err(err);
28100 +static const struct super_operations aufs_sop = {
28101 + .alloc_inode = aufs_alloc_inode,
28102 + .destroy_inode = aufs_destroy_inode,
28103 + /* always deleting, no clearing */
28104 + .drop_inode = generic_delete_inode,
28105 + .show_options = aufs_show_options,
28106 + .statfs = aufs_statfs,
28107 + .put_super = aufs_put_super,
28108 + .sync_fs = aufs_sync_fs,
28109 + .remount_fs = aufs_remount_fs
28112 +/* ---------------------------------------------------------------------- */
28114 +static int alloc_root(struct super_block *sb)
28117 + struct inode *inode;
28118 + struct dentry *root;
28121 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28122 + err = PTR_ERR(inode);
28123 + if (IS_ERR(inode))
28126 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28127 + inode->i_fop = &aufs_dir_fop;
28128 + inode->i_mode = S_IFDIR;
28129 + set_nlink(inode, 2);
28130 + unlock_new_inode(inode);
28132 + root = d_make_root(inode);
28133 + if (unlikely(!root))
28135 + err = PTR_ERR(root);
28136 + if (IS_ERR(root))
28139 + err = au_di_init(root);
28141 + sb->s_root = root;
28142 + return 0; /* success */
28150 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28151 + int silent __maybe_unused)
28154 + struct au_opts opts = {
28157 + struct au_sbinfo *sbinfo;
28158 + struct dentry *root;
28159 + struct inode *inode;
28160 + char *arg = raw_data;
28162 + if (unlikely(!arg || !*arg)) {
28164 + pr_err("no arg\n");
28169 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28170 + if (unlikely(!opts.opt))
28172 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28173 + opts.sb_flags = sb->s_flags;
28175 + err = au_si_alloc(sb);
28176 + if (unlikely(err))
28178 + sbinfo = au_sbi(sb);
28180 + /* all timestamps always follow the ones on the branch */
28181 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28182 + sb->s_op = &aufs_sop;
28183 + sb->s_d_op = &aufs_dop;
28184 + sb->s_magic = AUFS_SUPER_MAGIC;
28185 + sb->s_maxbytes = 0;
28186 + sb->s_stack_depth = 1;
28187 + au_export_init(sb);
28188 + au_xattr_init(sb);
28190 + err = alloc_root(sb);
28191 + if (unlikely(err)) {
28192 + si_write_unlock(sb);
28195 + root = sb->s_root;
28196 + inode = d_inode(root);
28199 + * actually we can parse options regardless aufs lock here.
28200 + * but at remount time, parsing must be done before aufs lock.
28201 + * so we follow the same rule.
28203 + ii_write_lock_parent(inode);
28204 + aufs_write_unlock(root);
28205 + err = au_opts_parse(sb, arg, &opts);
28206 + if (unlikely(err))
28209 + /* lock vfs_inode first, then aufs. */
28210 + inode_lock(inode);
28211 + aufs_write_lock(root);
28212 + err = au_opts_mount(sb, &opts);
28213 + au_opts_free(&opts);
28214 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28215 + sb->s_d_op = &aufs_dop_noreval;
28216 + pr_info("%pf\n", sb->s_d_op);
28217 + au_refresh_dop(root, /*force_reval*/0);
28218 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28219 + au_refresh_iop(inode, /*force_getattr*/0);
28221 + aufs_write_unlock(root);
28222 + inode_unlock(inode);
28224 + goto out_opts; /* success */
28228 + sb->s_root = NULL;
28230 + dbgaufs_si_fin(sbinfo);
28231 + kobject_put(&sbinfo->si_kobj);
28232 + sb->s_fs_info = NULL;
28234 + free_page((unsigned long)opts.opt);
28237 + err = cvt_err(err);
28242 +/* ---------------------------------------------------------------------- */
28244 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28245 + const char *dev_name __maybe_unused,
28248 + struct dentry *root;
28249 + struct super_block *sb;
28251 + /* all timestamps always follow the ones on the branch */
28252 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28253 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28254 + if (IS_ERR(root))
28258 + si_write_lock(sb, !AuLock_FLUSH);
28259 + sysaufs_brs_add(sb, 0);
28260 + si_write_unlock(sb);
28261 + au_sbilist_add(sb);
28267 +static void aufs_kill_sb(struct super_block *sb)
28269 + struct au_sbinfo *sbinfo;
28271 + sbinfo = au_sbi(sb);
28273 + au_sbilist_del(sb);
28274 + aufs_write_lock(sb->s_root);
28276 + if (sbinfo->si_wbr_create_ops->fin)
28277 + sbinfo->si_wbr_create_ops->fin(sb);
28278 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28279 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28280 + au_remount_refresh(sb, /*do_idop*/0);
28282 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28283 + au_plink_put(sb, /*verbose*/1);
28285 + sbinfo->si_sb = NULL;
28286 + aufs_write_unlock(sb->s_root);
28287 + au_nwt_flush(&sbinfo->si_nowait);
28289 + kill_anon_super(sb);
28292 +struct file_system_type aufs_fs_type = {
28293 + .name = AUFS_FSTYPE,
28294 + /* a race between rename and others */
28295 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28296 + .mount = aufs_mount,
28297 + .kill_sb = aufs_kill_sb,
28298 + /* no need to __module_get() and module_put(). */
28299 + .owner = THIS_MODULE,
28301 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28302 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28303 +++ linux/fs/aufs/super.h 2017-07-29 12:14:25.906375514 +0200
28306 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28308 + * This program, aufs is free software; you can redistribute it and/or modify
28309 + * it under the terms of the GNU General Public License as published by
28310 + * the Free Software Foundation; either version 2 of the License, or
28311 + * (at your option) any later version.
28313 + * This program is distributed in the hope that it will be useful,
28314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28316 + * GNU General Public License for more details.
28318 + * You should have received a copy of the GNU General Public License
28319 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28323 + * super_block operations
28326 +#ifndef __AUFS_SUPER_H__
28327 +#define __AUFS_SUPER_H__
28331 +#include <linux/fs.h>
28332 +#include <linux/kobject.h>
28333 +#include "rwsem.h"
28337 +/* policies to select one among multiple writable branches */
28338 +struct au_wbr_copyup_operations {
28339 + int (*copyup)(struct dentry *dentry);
28342 +#define AuWbr_DIR 1 /* target is a dir */
28343 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28345 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28346 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28347 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28349 +struct au_wbr_create_operations {
28350 + int (*create)(struct dentry *dentry, unsigned int flags);
28351 + int (*init)(struct super_block *sb);
28352 + int (*fin)(struct super_block *sb);
28355 +struct au_wbr_mfs {
28356 + struct mutex mfs_lock; /* protect this structure */
28357 + unsigned long mfs_jiffy;
28358 + unsigned long mfs_expire;
28359 + aufs_bindex_t mfs_bindex;
28361 + unsigned long long mfsrr_bytes;
28362 + unsigned long long mfsrr_watermark;
28365 +#define AuPlink_NHASH 100
28366 +static inline int au_plink_hash(ino_t ino)
28368 + return ino % AuPlink_NHASH;
28371 +/* File-based Hierarchical Storage Management */
28373 +#ifdef CONFIG_AUFS_FHSM
28374 + /* allow only one process who can receive the notification */
28375 + spinlock_t fhsm_spin;
28377 + wait_queue_head_t fhsm_wqh;
28378 + atomic_t fhsm_readable;
28380 + /* these are protected by si_rwsem */
28381 + unsigned long fhsm_expire;
28382 + aufs_bindex_t fhsm_bottom;
28387 +struct au_sbinfo {
28388 + /* nowait tasks in the system-wide workqueue */
28389 + struct au_nowait_tasks si_nowait;
28392 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28393 + * rwsem for au_sbinfo is necessary.
28395 + struct au_rwsem si_rwsem;
28398 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28401 + struct percpu_counter si_ninodes, si_nfiles;
28403 + /* branch management */
28404 + unsigned int si_generation;
28406 + /* see AuSi_ flags */
28407 + unsigned char au_si_status;
28409 + aufs_bindex_t si_bbot;
28411 + /* dirty trick to keep br_id plus */
28412 + unsigned int si_last_br_id :
28413 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28414 + struct au_branch **si_branch;
28416 + /* policy to select a writable branch */
28417 + unsigned char si_wbr_copyup;
28418 + unsigned char si_wbr_create;
28419 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28420 + struct au_wbr_create_operations *si_wbr_create_ops;
28422 + /* round robin */
28423 + atomic_t si_wbr_rr_next;
28425 + /* most free space */
28426 + struct au_wbr_mfs si_wbr_mfs;
28428 + /* File-based Hierarchical Storage Management */
28429 + struct au_fhsm si_fhsm;
28431 + /* mount flags */
28432 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28433 + unsigned int si_mntflags;
28435 + /* external inode number (bitmap and translation table) */
28436 + vfs_readf_t si_xread;
28437 + vfs_writef_t si_xwrite;
28438 + struct file *si_xib;
28439 + struct mutex si_xib_mtx; /* protect xib members */
28440 + unsigned long *si_xib_buf;
28441 + unsigned long si_xib_last_pindex;
28442 + int si_xib_next_bit;
28443 + aufs_bindex_t si_xino_brid;
28444 + unsigned long si_xino_jiffy;
28445 + unsigned long si_xino_expire;
28446 + /* reserved for future use */
28447 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28449 +#ifdef CONFIG_AUFS_EXPORT
28450 + /* i_generation */
28451 + struct file *si_xigen;
28452 + atomic_t si_xigen_next;
28455 + /* dirty trick to suppoer atomic_open */
28456 + struct au_sphlhead si_aopen;
28458 + /* vdir parameters */
28459 + unsigned long si_rdcache; /* max cache time in jiffies */
28460 + unsigned int si_rdblk; /* deblk size */
28461 + unsigned int si_rdhash; /* hash size */
28464 + * If the number of whiteouts are larger than si_dirwh, leave all of
28465 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28466 + * future fsck.aufs or kernel thread will remove them later.
28467 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28469 + unsigned int si_dirwh;
28471 + /* pseudo_link list */
28472 + struct au_sphlhead si_plink[AuPlink_NHASH];
28473 + wait_queue_head_t si_plink_wq;
28474 + spinlock_t si_plink_maint_lock;
28475 + pid_t si_plink_maint_pid;
28478 + struct au_sphlhead si_files;
28480 + /* with/without getattr, brother of sb->s_d_op */
28481 + struct inode_operations *si_iop_array;
28484 + * sysfs and lifetime management.
28485 + * this is not a small structure and it may be a waste of memory in case
28486 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28487 + * but using sysfs is majority.
28489 + struct kobject si_kobj;
28490 +#ifdef CONFIG_DEBUG_FS
28491 + struct dentry *si_dbgaufs;
28492 + struct dentry *si_dbgaufs_plink;
28493 + struct dentry *si_dbgaufs_xib;
28494 +#ifdef CONFIG_AUFS_EXPORT
28495 + struct dentry *si_dbgaufs_xigen;
28499 +#ifdef CONFIG_AUFS_SBILIST
28500 + struct hlist_node si_list;
28503 + /* dirty, necessary for unmounting, sysfs and sysrq */
28504 + struct super_block *si_sb;
28507 +/* sbinfo status flags */
28509 + * set true when refresh_dirs() failed at remount time.
28510 + * then try refreshing dirs at access time again.
28511 + * if it is false, refreshing dirs at access time is unnecesary
28513 +#define AuSi_FAILED_REFRESH_DIR 1
28514 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28515 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28517 +#ifndef CONFIG_AUFS_FHSM
28519 +#define AuSi_FHSM 0
28522 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28523 + unsigned int flag)
28525 + AuRwMustAnyLock(&sbi->si_rwsem);
28526 + return sbi->au_si_status & flag;
28528 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28529 +#define au_fset_si(sbinfo, name) do { \
28530 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28531 + (sbinfo)->au_si_status |= AuSi_##name; \
28533 +#define au_fclr_si(sbinfo, name) do { \
28534 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28535 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28538 +/* ---------------------------------------------------------------------- */
28540 +/* policy to select one among writable branches */
28541 +#define AuWbrCopyup(sbinfo, ...) \
28542 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28543 +#define AuWbrCreate(sbinfo, ...) \
28544 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28546 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28547 +#define AuLock_DW 1 /* write-lock dentry */
28548 +#define AuLock_IR (1 << 1) /* read-lock inode */
28549 +#define AuLock_IW (1 << 2) /* write-lock inode */
28550 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28551 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28552 + /* except RENAME_EXCHANGE */
28553 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28554 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28555 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28556 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28557 +#define au_fset_lock(flags, name) \
28558 + do { (flags) |= AuLock_##name; } while (0)
28559 +#define au_fclr_lock(flags, name) \
28560 + do { (flags) &= ~AuLock_##name; } while (0)
28562 +/* ---------------------------------------------------------------------- */
28565 +extern struct file_system_type aufs_fs_type;
28566 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28567 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28568 + unsigned long long max, void *arg);
28569 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28570 + struct super_block *sb, void *arg);
28571 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28572 +void au_iarray_free(struct inode **a, unsigned long long max);
28575 +void au_si_free(struct kobject *kobj);
28576 +int au_si_alloc(struct super_block *sb);
28577 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28579 +unsigned int au_sigen_inc(struct super_block *sb);
28580 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28582 +int si_read_lock(struct super_block *sb, int flags);
28583 +int si_write_lock(struct super_block *sb, int flags);
28584 +int aufs_read_lock(struct dentry *dentry, int flags);
28585 +void aufs_read_unlock(struct dentry *dentry, int flags);
28586 +void aufs_write_lock(struct dentry *dentry);
28587 +void aufs_write_unlock(struct dentry *dentry);
28588 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28589 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28591 +/* wbr_policy.c */
28592 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28593 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28594 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28595 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28596 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28599 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28601 +#ifdef CONFIG_AUFS_FHSM
28604 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28608 + spin_lock(&fhsm->fhsm_spin);
28609 + pid = fhsm->fhsm_pid;
28610 + spin_unlock(&fhsm->fhsm_spin);
28615 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28616 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28617 +int au_fhsm_fd(struct super_block *sb, int oflags);
28618 +int au_fhsm_br_alloc(struct au_branch *br);
28619 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28620 +void au_fhsm_fin(struct super_block *sb);
28621 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28622 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28623 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28625 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28627 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28628 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28629 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28630 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28631 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28632 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28633 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28634 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28635 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28638 +/* ---------------------------------------------------------------------- */
28640 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28642 + return sb->s_fs_info;
28645 +/* ---------------------------------------------------------------------- */
28647 +#ifdef CONFIG_AUFS_EXPORT
28648 +int au_test_nfsd(void);
28649 +void au_export_init(struct super_block *sb);
28650 +void au_xigen_inc(struct inode *inode);
28651 +int au_xigen_new(struct inode *inode);
28652 +int au_xigen_set(struct super_block *sb, struct file *base);
28653 +void au_xigen_clr(struct super_block *sb);
28655 +static inline int au_busy_or_stale(void)
28657 + if (!au_test_nfsd())
28662 +AuStubInt0(au_test_nfsd, void)
28663 +AuStubVoid(au_export_init, struct super_block *sb)
28664 +AuStubVoid(au_xigen_inc, struct inode *inode)
28665 +AuStubInt0(au_xigen_new, struct inode *inode)
28666 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28667 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28668 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28669 +#endif /* CONFIG_AUFS_EXPORT */
28671 +/* ---------------------------------------------------------------------- */
28673 +#ifdef CONFIG_AUFS_SBILIST
28675 +extern struct au_sphlhead au_sbilist;
28677 +static inline void au_sbilist_init(void)
28679 + au_sphl_init(&au_sbilist);
28682 +static inline void au_sbilist_add(struct super_block *sb)
28684 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28687 +static inline void au_sbilist_del(struct super_block *sb)
28689 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28692 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28693 +static inline void au_sbilist_lock(void)
28695 + spin_lock(&au_sbilist.spin);
28698 +static inline void au_sbilist_unlock(void)
28700 + spin_unlock(&au_sbilist.spin);
28702 +#define AuGFP_SBILIST GFP_ATOMIC
28704 +AuStubVoid(au_sbilist_lock, void)
28705 +AuStubVoid(au_sbilist_unlock, void)
28706 +#define AuGFP_SBILIST GFP_NOFS
28707 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28709 +AuStubVoid(au_sbilist_init, void)
28710 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28711 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28712 +AuStubVoid(au_sbilist_lock, void)
28713 +AuStubVoid(au_sbilist_unlock, void)
28714 +#define AuGFP_SBILIST GFP_NOFS
28717 +/* ---------------------------------------------------------------------- */
28719 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28722 + * This function is a dynamic '__init' function actually,
28723 + * so the tiny check for si_rwsem is unnecessary.
28725 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28726 +#ifdef CONFIG_DEBUG_FS
28727 + sbinfo->si_dbgaufs = NULL;
28728 + sbinfo->si_dbgaufs_plink = NULL;
28729 + sbinfo->si_dbgaufs_xib = NULL;
28730 +#ifdef CONFIG_AUFS_EXPORT
28731 + sbinfo->si_dbgaufs_xigen = NULL;
28736 +/* ---------------------------------------------------------------------- */
28738 +/* current->atomic_flags */
28739 +/* this value should never corrupt the ones defined in linux/sched.h */
28740 +#define PFA_AUFS 7
28742 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
28743 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
28744 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
28746 +static inline int si_pid_test(struct super_block *sb)
28748 + return !!task_test_aufs(current);
28751 +static inline void si_pid_clr(struct super_block *sb)
28753 + AuDebugOn(!task_test_aufs(current));
28754 + task_clear_aufs(current);
28757 +static inline void si_pid_set(struct super_block *sb)
28759 + AuDebugOn(task_test_aufs(current));
28760 + task_set_aufs(current);
28763 +/* ---------------------------------------------------------------------- */
28765 +/* lock superblock. mainly for entry point functions */
28767 + * __si_read_lock, __si_write_lock,
28768 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28770 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28772 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28773 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28774 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28776 +static inline void si_noflush_read_lock(struct super_block *sb)
28778 + __si_read_lock(sb);
28782 +static inline int si_noflush_read_trylock(struct super_block *sb)
28786 + locked = __si_read_trylock(sb);
28792 +static inline void si_noflush_write_lock(struct super_block *sb)
28794 + __si_write_lock(sb);
28798 +static inline int si_noflush_write_trylock(struct super_block *sb)
28802 + locked = __si_write_trylock(sb);
28808 +#if 0 /* reserved */
28809 +static inline int si_read_trylock(struct super_block *sb, int flags)
28811 + if (au_ftest_lock(flags, FLUSH))
28812 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28813 + return si_noflush_read_trylock(sb);
28817 +static inline void si_read_unlock(struct super_block *sb)
28820 + __si_read_unlock(sb);
28823 +#if 0 /* reserved */
28824 +static inline int si_write_trylock(struct super_block *sb, int flags)
28826 + if (au_ftest_lock(flags, FLUSH))
28827 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28828 + return si_noflush_write_trylock(sb);
28832 +static inline void si_write_unlock(struct super_block *sb)
28835 + __si_write_unlock(sb);
28838 +#if 0 /* reserved */
28839 +static inline void si_downgrade_lock(struct super_block *sb)
28841 + __si_downgrade_lock(sb);
28845 +/* ---------------------------------------------------------------------- */
28847 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28849 + SiMustAnyLock(sb);
28850 + return au_sbi(sb)->si_bbot;
28853 +static inline unsigned int au_mntflags(struct super_block *sb)
28855 + SiMustAnyLock(sb);
28856 + return au_sbi(sb)->si_mntflags;
28859 +static inline unsigned int au_sigen(struct super_block *sb)
28861 + SiMustAnyLock(sb);
28862 + return au_sbi(sb)->si_generation;
28865 +static inline unsigned long long au_ninodes(struct super_block *sb)
28867 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28873 +static inline void au_ninodes_inc(struct super_block *sb)
28875 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28878 +static inline void au_ninodes_dec(struct super_block *sb)
28880 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28883 +static inline unsigned long long au_nfiles(struct super_block *sb)
28885 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28891 +static inline void au_nfiles_inc(struct super_block *sb)
28893 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28896 +static inline void au_nfiles_dec(struct super_block *sb)
28898 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28901 +static inline struct au_branch *au_sbr(struct super_block *sb,
28902 + aufs_bindex_t bindex)
28904 + SiMustAnyLock(sb);
28905 + return au_sbi(sb)->si_branch[0 + bindex];
28908 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28910 + SiMustWriteLock(sb);
28911 + au_sbi(sb)->si_xino_brid = brid;
28914 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28916 + SiMustAnyLock(sb);
28917 + return au_sbi(sb)->si_xino_brid;
28920 +#endif /* __KERNEL__ */
28921 +#endif /* __AUFS_SUPER_H__ */
28922 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28923 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28924 +++ linux/fs/aufs/sysaufs.c 2017-07-29 12:14:25.906375514 +0200
28927 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28929 + * This program, aufs is free software; you can redistribute it and/or modify
28930 + * it under the terms of the GNU General Public License as published by
28931 + * the Free Software Foundation; either version 2 of the License, or
28932 + * (at your option) any later version.
28934 + * This program is distributed in the hope that it will be useful,
28935 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28936 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28937 + * GNU General Public License for more details.
28939 + * You should have received a copy of the GNU General Public License
28940 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28944 + * sysfs interface and lifetime management
28945 + * they are necessary regardless sysfs is disabled.
28948 +#include <linux/random.h>
28951 +unsigned long sysaufs_si_mask;
28952 +struct kset *sysaufs_kset;
28954 +#define AuSiAttr(_name) { \
28955 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28956 + .show = sysaufs_si_##_name, \
28959 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28960 +struct attribute *sysaufs_si_attrs[] = {
28961 + &sysaufs_si_attr_xi_path.attr,
28965 +static const struct sysfs_ops au_sbi_ops = {
28966 + .show = sysaufs_si_show
28969 +static struct kobj_type au_sbi_ktype = {
28970 + .release = au_si_free,
28971 + .sysfs_ops = &au_sbi_ops,
28972 + .default_attrs = sysaufs_si_attrs
28975 +/* ---------------------------------------------------------------------- */
28977 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28981 + sbinfo->si_kobj.kset = sysaufs_kset;
28982 + /* cf. sysaufs_name() */
28983 + err = kobject_init_and_add
28984 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28985 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28987 + dbgaufs_si_null(sbinfo);
28989 + err = dbgaufs_si_init(sbinfo);
28990 + if (unlikely(err))
28991 + kobject_put(&sbinfo->si_kobj);
28996 +void sysaufs_fin(void)
28999 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29000 + kset_unregister(sysaufs_kset);
29003 +int __init sysaufs_init(void)
29008 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
29009 + } while (!sysaufs_si_mask);
29012 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
29013 + if (unlikely(!sysaufs_kset))
29015 + err = PTR_ERR(sysaufs_kset);
29016 + if (IS_ERR(sysaufs_kset))
29018 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29019 + if (unlikely(err)) {
29020 + kset_unregister(sysaufs_kset);
29024 + err = dbgaufs_init();
29025 + if (unlikely(err))
29030 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
29031 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
29032 +++ linux/fs/aufs/sysaufs.h 2017-07-29 12:14:25.906375514 +0200
29035 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29037 + * This program, aufs is free software; you can redistribute it and/or modify
29038 + * it under the terms of the GNU General Public License as published by
29039 + * the Free Software Foundation; either version 2 of the License, or
29040 + * (at your option) any later version.
29042 + * This program is distributed in the hope that it will be useful,
29043 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29044 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29045 + * GNU General Public License for more details.
29047 + * You should have received a copy of the GNU General Public License
29048 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29052 + * sysfs interface and mount lifetime management
29055 +#ifndef __SYSAUFS_H__
29056 +#define __SYSAUFS_H__
29060 +#include <linux/sysfs.h>
29061 +#include "module.h"
29063 +struct super_block;
29066 +struct sysaufs_si_attr {
29067 + struct attribute attr;
29068 + int (*show)(struct seq_file *seq, struct super_block *sb);
29071 +/* ---------------------------------------------------------------------- */
29074 +extern unsigned long sysaufs_si_mask;
29075 +extern struct kset *sysaufs_kset;
29076 +extern struct attribute *sysaufs_si_attrs[];
29077 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
29078 +int __init sysaufs_init(void);
29079 +void sysaufs_fin(void);
29081 +/* ---------------------------------------------------------------------- */
29083 +/* some people doesn't like to show a pointer in kernel */
29084 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
29086 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
29089 +#define SysaufsSiNamePrefix "si_"
29090 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29091 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29093 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29094 + sysaufs_si_id(sbinfo));
29098 +#ifdef CONFIG_SYSFS
29100 +extern struct attribute_group *sysaufs_attr_group;
29102 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29103 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29105 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29106 +#ifdef CONFIG_COMPAT
29107 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29110 +void sysaufs_br_init(struct au_branch *br);
29111 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29112 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29114 +#define sysaufs_brs_init() do {} while (0)
29117 +#define sysaufs_attr_group NULL
29119 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29120 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29121 + struct attribute *attr, char *buf)
29122 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29123 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29124 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29126 +static inline void sysaufs_brs_init(void)
29131 +#endif /* CONFIG_SYSFS */
29133 +#endif /* __KERNEL__ */
29134 +#endif /* __SYSAUFS_H__ */
29135 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29136 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29137 +++ linux/fs/aufs/sysfs.c 2017-07-29 12:14:25.906375514 +0200
29140 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29142 + * This program, aufs is free software; you can redistribute it and/or modify
29143 + * it under the terms of the GNU General Public License as published by
29144 + * the Free Software Foundation; either version 2 of the License, or
29145 + * (at your option) any later version.
29147 + * This program is distributed in the hope that it will be useful,
29148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29150 + * GNU General Public License for more details.
29152 + * You should have received a copy of the GNU General Public License
29153 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29157 + * sysfs interface
29160 +#include <linux/compat.h>
29161 +#include <linux/seq_file.h>
29164 +#ifdef CONFIG_AUFS_FS_MODULE
29165 +/* this entry violates the "one line per file" policy of sysfs */
29166 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29170 + static char *conf =
29171 +/* this file is generated at compiling */
29172 +#include "conf.str"
29175 + err = snprintf(buf, PAGE_SIZE, conf);
29176 + if (unlikely(err >= PAGE_SIZE))
29181 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29184 +static struct attribute *au_attr[] = {
29185 +#ifdef CONFIG_AUFS_FS_MODULE
29186 + &au_config_attr.attr,
29188 + NULL, /* need to NULL terminate the list of attributes */
29191 +static struct attribute_group sysaufs_attr_group_body = {
29195 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29197 +/* ---------------------------------------------------------------------- */
29199 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29203 + SiMustAnyLock(sb);
29206 + if (au_opt_test(au_mntflags(sb), XINO)) {
29207 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29208 + seq_putc(seq, '\n');
29214 + * the lifetime of branch is independent from the entry under sysfs.
29215 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29218 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29219 + aufs_bindex_t bindex, int idx)
29222 + struct path path;
29223 + struct dentry *root;
29224 + struct au_branch *br;
29225 + au_br_perm_str_t perm;
29227 + AuDbg("b%d\n", bindex);
29230 + root = sb->s_root;
29231 + di_read_lock_parent(root, !AuLock_IR);
29232 + br = au_sbr(sb, bindex);
29235 + case AuBrSysfs_BR:
29236 + path.mnt = au_br_mnt(br);
29237 + path.dentry = au_h_dptr(root, bindex);
29238 + err = au_seq_path(seq, &path);
29240 + au_optstr_br_perm(&perm, br->br_perm);
29241 + seq_printf(seq, "=%s\n", perm.a);
29244 + case AuBrSysfs_BRID:
29245 + seq_printf(seq, "%d\n", br->br_id);
29248 + di_read_unlock(root, !AuLock_IR);
29249 + if (unlikely(err || seq_has_overflowed(seq)))
29255 +/* ---------------------------------------------------------------------- */
29257 +static struct seq_file *au_seq(char *p, ssize_t len)
29259 + struct seq_file *seq;
29261 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29263 + /* mutex_init(&seq.lock); */
29266 + return seq; /* success */
29269 + seq = ERR_PTR(-ENOMEM);
29273 +#define SysaufsBr_PREFIX "br"
29274 +#define SysaufsBrid_PREFIX "brid"
29276 +/* todo: file size may exceed PAGE_SIZE */
29277 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29283 + aufs_bindex_t bbot;
29284 + struct au_sbinfo *sbinfo;
29285 + struct super_block *sb;
29286 + struct seq_file *seq;
29288 + struct attribute **cattr;
29290 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29291 + sb = sbinfo->si_sb;
29294 + * prevent a race condition between sysfs and aufs.
29295 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29296 + * prohibits maintaining the sysfs entries.
29297 + * hew we acquire read lock after sysfs_get_active_two().
29298 + * on the other hand, the remount process may maintain the sysfs/aufs
29299 + * entries after acquiring write lock.
29300 + * it can cause a deadlock.
29301 + * simply we gave up processing read here.
29304 + if (unlikely(!si_noflush_read_trylock(sb)))
29307 + seq = au_seq(buf, PAGE_SIZE);
29308 + err = PTR_ERR(seq);
29312 + name = (void *)attr->name;
29313 + cattr = sysaufs_si_attrs;
29315 + if (!strcmp(name, (*cattr)->name)) {
29316 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29323 + if (!strncmp(name, SysaufsBrid_PREFIX,
29324 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29325 + idx = AuBrSysfs_BRID;
29326 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29327 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29328 + sizeof(SysaufsBr_PREFIX) - 1)) {
29329 + idx = AuBrSysfs_BR;
29330 + name += sizeof(SysaufsBr_PREFIX) - 1;
29334 + err = kstrtol(name, 10, &l);
29336 + bbot = au_sbbot(sb);
29338 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29345 + err = seq->count;
29346 + /* sysfs limit */
29347 + if (unlikely(err == PAGE_SIZE))
29352 + si_read_unlock(sb);
29357 +/* ---------------------------------------------------------------------- */
29359 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29363 + aufs_bindex_t bindex, bbot;
29366 + struct seq_file *seq;
29367 + struct au_branch *br;
29369 + si_read_lock(sb, AuLock_FLUSH);
29370 + bbot = au_sbbot(sb);
29376 + buf = (void *)__get_free_page(GFP_NOFS);
29377 + if (unlikely(!buf))
29380 + seq = au_seq(buf, PAGE_SIZE);
29381 + err = PTR_ERR(seq);
29385 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29386 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29387 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29388 + if (unlikely(err))
29391 + br = au_sbr(sb, bindex);
29392 + brid = br->br_id;
29393 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29394 + err = __put_user(brid, &arg->id);
29395 + if (unlikely(err))
29398 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29399 + err = __put_user(br->br_perm, &arg->perm);
29400 + if (unlikely(err))
29403 + err = au_seq_path(seq, &br->br_path);
29404 + if (unlikely(err))
29406 + seq_putc(seq, '\0');
29407 + if (!seq_has_overflowed(seq)) {
29408 + err = copy_to_user(arg->path, seq->buf, seq->count);
29410 + if (unlikely(err))
29417 + if (unlikely(err))
29423 + free_page((unsigned long)buf);
29425 + si_read_unlock(sb);
29429 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29431 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29434 +#ifdef CONFIG_COMPAT
29435 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29437 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29441 +/* ---------------------------------------------------------------------- */
29443 +void sysaufs_br_init(struct au_branch *br)
29446 + struct au_brsysfs *br_sysfs;
29447 + struct attribute *attr;
29449 + br_sysfs = br->br_sysfs;
29450 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29451 + attr = &br_sysfs->attr;
29452 + sysfs_attr_init(attr);
29453 + attr->name = br_sysfs->name;
29454 + attr->mode = S_IRUGO;
29459 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29461 + struct au_branch *br;
29462 + struct kobject *kobj;
29463 + struct au_brsysfs *br_sysfs;
29465 + aufs_bindex_t bbot;
29467 + dbgaufs_brs_del(sb, bindex);
29469 + if (!sysaufs_brs)
29472 + kobj = &au_sbi(sb)->si_kobj;
29473 + bbot = au_sbbot(sb);
29474 + for (; bindex <= bbot; bindex++) {
29475 + br = au_sbr(sb, bindex);
29476 + br_sysfs = br->br_sysfs;
29477 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29478 + sysfs_remove_file(kobj, &br_sysfs->attr);
29484 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29487 + aufs_bindex_t bbot;
29488 + struct kobject *kobj;
29489 + struct au_branch *br;
29490 + struct au_brsysfs *br_sysfs;
29492 + dbgaufs_brs_add(sb, bindex);
29494 + if (!sysaufs_brs)
29497 + kobj = &au_sbi(sb)->si_kobj;
29498 + bbot = au_sbbot(sb);
29499 + for (; bindex <= bbot; bindex++) {
29500 + br = au_sbr(sb, bindex);
29501 + br_sysfs = br->br_sysfs;
29502 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29503 + SysaufsBr_PREFIX "%d", bindex);
29504 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29505 + SysaufsBrid_PREFIX "%d", bindex);
29506 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29507 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29508 + if (unlikely(err))
29509 + pr_warn("failed %s under sysfs(%d)\n",
29510 + br_sysfs->name, err);
29515 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29516 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29517 +++ linux/fs/aufs/sysrq.c 2017-07-29 12:14:25.906375514 +0200
29520 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29522 + * This program, aufs is free software; you can redistribute it and/or modify
29523 + * it under the terms of the GNU General Public License as published by
29524 + * the Free Software Foundation; either version 2 of the License, or
29525 + * (at your option) any later version.
29527 + * This program is distributed in the hope that it will be useful,
29528 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29529 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29530 + * GNU General Public License for more details.
29532 + * You should have received a copy of the GNU General Public License
29533 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29537 + * magic sysrq hanlder
29540 +/* #include <linux/sysrq.h> */
29541 +#include <linux/writeback.h>
29544 +/* ---------------------------------------------------------------------- */
29546 +static void sysrq_sb(struct super_block *sb)
29549 + struct au_sbinfo *sbinfo;
29550 + struct file *file;
29551 + struct au_sphlhead *files;
29552 + struct au_finfo *finfo;
29554 + plevel = au_plevel;
29555 + au_plevel = KERN_WARNING;
29557 + /* since we define pr_fmt, call printk directly */
29558 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29560 + sbinfo = au_sbi(sb);
29561 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29562 + pr("superblock\n");
29566 + pr("root dentry\n");
29567 + au_dpri_dentry(sb->s_root);
29568 + pr("root inode\n");
29569 + au_dpri_inode(d_inode(sb->s_root));
29574 + int err, i, j, ndentry;
29575 + struct au_dcsub_pages dpages;
29576 + struct au_dpage *dpage;
29578 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29579 + if (unlikely(err))
29581 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29583 + for (i = 0; i < dpages.ndpage; i++) {
29584 + dpage = dpages.dpages + i;
29585 + ndentry = dpage->ndentry;
29586 + for (j = 0; j < ndentry; j++)
29587 + au_dpri_dentry(dpage->dentries[j]);
29589 + au_dpages_free(&dpages);
29597 + pr("isolated inode\n");
29598 + spin_lock(&sb->s_inode_list_lock);
29599 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29600 + spin_lock(&i->i_lock);
29601 + if (1 || hlist_empty(&i->i_dentry))
29602 + au_dpri_inode(i);
29603 + spin_unlock(&i->i_lock);
29605 + spin_unlock(&sb->s_inode_list_lock);
29609 + files = &au_sbi(sb)->si_files;
29610 + spin_lock(&files->spin);
29611 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29614 + file = finfo->fi_file;
29615 + mode = file_inode(file)->i_mode;
29616 + if (!special_file(mode))
29617 + au_dpri_file(file);
29619 + spin_unlock(&files->spin);
29623 + au_plevel = plevel;
29626 +/* ---------------------------------------------------------------------- */
29628 +/* module parameter */
29629 +static char *aufs_sysrq_key = "a";
29630 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29631 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29633 +static void au_sysrq(int key __maybe_unused)
29635 + struct au_sbinfo *sbinfo;
29638 + au_sbilist_lock();
29639 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29640 + sysrq_sb(sbinfo->si_sb);
29641 + au_sbilist_unlock();
29645 +static struct sysrq_key_op au_sysrq_op = {
29646 + .handler = au_sysrq,
29647 + .help_msg = "Aufs",
29648 + .action_msg = "Aufs",
29649 + .enable_mask = SYSRQ_ENABLE_DUMP
29652 +/* ---------------------------------------------------------------------- */
29654 +int __init au_sysrq_init(void)
29660 + key = *aufs_sysrq_key;
29661 + if ('a' <= key && key <= 'z')
29662 + err = register_sysrq_key(key, &au_sysrq_op);
29663 + if (unlikely(err))
29664 + pr_err("err %d, sysrq=%c\n", err, key);
29668 +void au_sysrq_fin(void)
29672 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29673 + if (unlikely(err))
29674 + pr_err("err %d (ignored)\n", err);
29676 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29677 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29678 +++ linux/fs/aufs/vdir.c 2017-07-29 12:14:25.906375514 +0200
29681 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29683 + * This program, aufs is free software; you can redistribute it and/or modify
29684 + * it under the terms of the GNU General Public License as published by
29685 + * the Free Software Foundation; either version 2 of the License, or
29686 + * (at your option) any later version.
29688 + * This program is distributed in the hope that it will be useful,
29689 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29690 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29691 + * GNU General Public License for more details.
29693 + * You should have received a copy of the GNU General Public License
29694 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29698 + * virtual or vertical directory
29703 +static unsigned int calc_size(int nlen)
29705 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29708 +static int set_deblk_end(union au_vdir_deblk_p *p,
29709 + union au_vdir_deblk_p *deblk_end)
29711 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29712 + p->de->de_str.len = 0;
29716 + return -1; /* error */
29719 +/* returns true or false */
29720 +static int is_deblk_end(union au_vdir_deblk_p *p,
29721 + union au_vdir_deblk_p *deblk_end)
29723 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29724 + return !p->de->de_str.len;
29728 +static unsigned char *last_deblk(struct au_vdir *vdir)
29730 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29733 +/* ---------------------------------------------------------------------- */
29735 +/* estimate the appropriate size for name hash table */
29736 +unsigned int au_rdhash_est(loff_t sz)
29744 + if (sz < AUFS_RDHASH_DEF)
29745 + n = AUFS_RDHASH_DEF;
29746 + /* pr_info("n %u\n", n); */
29751 + * the allocated memory has to be freed by
29752 + * au_nhash_wh_free() or au_nhash_de_free().
29754 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29756 + struct hlist_head *head;
29760 + sz = sizeof(*nhash->nh_head) * num_hash;
29761 + head = kmalloc(sz, gfp);
29763 + nhash->nh_num = num_hash;
29764 + nhash->nh_head = head;
29765 + for (u = 0; u < num_hash; u++)
29766 + INIT_HLIST_HEAD(head++);
29767 + return 0; /* success */
29773 +static void nhash_count(struct hlist_head *head)
29777 + struct hlist_node *pos;
29780 + hlist_for_each(pos, head)
29782 + pr_info("%lu\n", n);
29786 +static void au_nhash_wh_do_free(struct hlist_head *head)
29788 + struct au_vdir_wh *pos;
29789 + struct hlist_node *node;
29791 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29795 +static void au_nhash_de_do_free(struct hlist_head *head)
29797 + struct au_vdir_dehstr *pos;
29798 + struct hlist_node *node;
29800 + hlist_for_each_entry_safe(pos, node, head, hash)
29801 + au_cache_free_vdir_dehstr(pos);
29804 +static void au_nhash_do_free(struct au_nhash *nhash,
29805 + void (*free)(struct hlist_head *head))
29808 + struct hlist_head *head;
29810 + n = nhash->nh_num;
29814 + head = nhash->nh_head;
29815 + while (n-- > 0) {
29816 + nhash_count(head);
29819 + kfree(nhash->nh_head);
29822 +void au_nhash_wh_free(struct au_nhash *whlist)
29824 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29827 +static void au_nhash_de_free(struct au_nhash *delist)
29829 + au_nhash_do_free(delist, au_nhash_de_do_free);
29832 +/* ---------------------------------------------------------------------- */
29834 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29838 + unsigned int u, n;
29839 + struct hlist_head *head;
29840 + struct au_vdir_wh *pos;
29843 + n = whlist->nh_num;
29844 + head = whlist->nh_head;
29845 + for (u = 0; u < n; u++, head++)
29846 + hlist_for_each_entry(pos, head, wh_hash)
29847 + if (pos->wh_bindex == btgt && ++num > limit)
29852 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29853 + unsigned char *name,
29854 + unsigned int len)
29857 + /* const unsigned int magic_bit = 12; */
29859 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29866 + /* v = hash_long(v, magic_bit); */
29867 + v %= nhash->nh_num;
29868 + return nhash->nh_head + v;
29871 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29874 + return str->len == nlen && !memcmp(str->name, name, nlen);
29877 +/* returns found or not */
29878 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29880 + struct hlist_head *head;
29881 + struct au_vdir_wh *pos;
29882 + struct au_vdir_destr *str;
29884 + head = au_name_hash(whlist, name, nlen);
29885 + hlist_for_each_entry(pos, head, wh_hash) {
29886 + str = &pos->wh_str;
29887 + AuDbg("%.*s\n", str->len, str->name);
29888 + if (au_nhash_test_name(str, name, nlen))
29894 +/* returns found(true) or not */
29895 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29897 + struct hlist_head *head;
29898 + struct au_vdir_dehstr *pos;
29899 + struct au_vdir_destr *str;
29901 + head = au_name_hash(delist, name, nlen);
29902 + hlist_for_each_entry(pos, head, hash) {
29904 + AuDbg("%.*s\n", str->len, str->name);
29905 + if (au_nhash_test_name(str, name, nlen))
29911 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29912 + unsigned char d_type)
29914 +#ifdef CONFIG_AUFS_SHWH
29915 + wh->wh_ino = ino;
29916 + wh->wh_type = d_type;
29920 +/* ---------------------------------------------------------------------- */
29922 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29923 + unsigned int d_type, aufs_bindex_t bindex,
29924 + unsigned char shwh)
29927 + struct au_vdir_destr *str;
29928 + struct au_vdir_wh *wh;
29930 + AuDbg("%.*s\n", nlen, name);
29931 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29934 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29935 + if (unlikely(!wh))
29939 + wh->wh_bindex = bindex;
29941 + au_shwh_init_wh(wh, ino, d_type);
29942 + str = &wh->wh_str;
29944 + memcpy(str->name, name, nlen);
29945 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29952 +static int append_deblk(struct au_vdir *vdir)
29955 + unsigned long ul;
29956 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29957 + union au_vdir_deblk_p p, deblk_end;
29958 + unsigned char **o;
29961 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29962 + GFP_NOFS, /*may_shrink*/0);
29963 + if (unlikely(!o))
29966 + vdir->vd_deblk = o;
29967 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29969 + ul = vdir->vd_nblk++;
29970 + vdir->vd_deblk[ul] = p.deblk;
29971 + vdir->vd_last.ul = ul;
29972 + vdir->vd_last.p.deblk = p.deblk;
29973 + deblk_end.deblk = p.deblk + deblk_sz;
29974 + err = set_deblk_end(&p, &deblk_end);
29981 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29982 + unsigned int d_type, struct au_nhash *delist)
29986 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29987 + union au_vdir_deblk_p p, *room, deblk_end;
29988 + struct au_vdir_dehstr *dehstr;
29990 + p.deblk = last_deblk(vdir);
29991 + deblk_end.deblk = p.deblk + deblk_sz;
29992 + room = &vdir->vd_last.p;
29993 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29994 + || !is_deblk_end(room, &deblk_end));
29996 + sz = calc_size(nlen);
29997 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29998 + err = append_deblk(vdir);
29999 + if (unlikely(err))
30002 + p.deblk = last_deblk(vdir);
30003 + deblk_end.deblk = p.deblk + deblk_sz;
30005 + AuDebugOn(room->deblk != p.deblk);
30009 + dehstr = au_cache_alloc_vdir_dehstr();
30010 + if (unlikely(!dehstr))
30013 + dehstr->str = &room->de->de_str;
30014 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
30015 + room->de->de_ino = ino;
30016 + room->de->de_type = d_type;
30017 + room->de->de_str.len = nlen;
30018 + memcpy(room->de->de_str.name, name, nlen);
30021 + room->deblk += sz;
30022 + if (unlikely(set_deblk_end(room, &deblk_end)))
30023 + err = append_deblk(vdir);
30030 +/* ---------------------------------------------------------------------- */
30032 +void au_vdir_free(struct au_vdir *vdir)
30034 + unsigned char **deblk;
30036 + deblk = vdir->vd_deblk;
30037 + while (vdir->vd_nblk--)
30039 + kfree(vdir->vd_deblk);
30040 + au_cache_free_vdir(vdir);
30043 +static struct au_vdir *alloc_vdir(struct file *file)
30045 + struct au_vdir *vdir;
30046 + struct super_block *sb;
30049 + sb = file->f_path.dentry->d_sb;
30050 + SiMustAnyLock(sb);
30053 + vdir = au_cache_alloc_vdir();
30054 + if (unlikely(!vdir))
30057 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
30058 + if (unlikely(!vdir->vd_deblk))
30061 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
30062 + if (!vdir->vd_deblk_sz) {
30063 + /* estimate the appropriate size for deblk */
30064 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
30065 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
30067 + vdir->vd_nblk = 0;
30068 + vdir->vd_version = 0;
30069 + vdir->vd_jiffy = 0;
30070 + err = append_deblk(vdir);
30072 + return vdir; /* success */
30074 + kfree(vdir->vd_deblk);
30077 + au_cache_free_vdir(vdir);
30079 + vdir = ERR_PTR(err);
30083 +static int reinit_vdir(struct au_vdir *vdir)
30086 + union au_vdir_deblk_p p, deblk_end;
30088 + while (vdir->vd_nblk > 1) {
30089 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30090 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30093 + p.deblk = vdir->vd_deblk[0];
30094 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30095 + err = set_deblk_end(&p, &deblk_end);
30096 + /* keep vd_dblk_sz */
30097 + vdir->vd_last.ul = 0;
30098 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30099 + vdir->vd_version = 0;
30100 + vdir->vd_jiffy = 0;
30105 +/* ---------------------------------------------------------------------- */
30107 +#define AuFillVdir_CALLED 1
30108 +#define AuFillVdir_WHABLE (1 << 1)
30109 +#define AuFillVdir_SHWH (1 << 2)
30110 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30111 +#define au_fset_fillvdir(flags, name) \
30112 + do { (flags) |= AuFillVdir_##name; } while (0)
30113 +#define au_fclr_fillvdir(flags, name) \
30114 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30116 +#ifndef CONFIG_AUFS_SHWH
30117 +#undef AuFillVdir_SHWH
30118 +#define AuFillVdir_SHWH 0
30121 +struct fillvdir_arg {
30122 + struct dir_context ctx;
30123 + struct file *file;
30124 + struct au_vdir *vdir;
30125 + struct au_nhash delist;
30126 + struct au_nhash whlist;
30127 + aufs_bindex_t bindex;
30128 + unsigned int flags;
30132 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30133 + loff_t offset __maybe_unused, u64 h_ino,
30134 + unsigned int d_type)
30136 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30137 + char *name = (void *)__name;
30138 + struct super_block *sb;
30140 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30143 + sb = arg->file->f_path.dentry->d_sb;
30144 + au_fset_fillvdir(arg->flags, CALLED);
30146 + if (nlen <= AUFS_WH_PFX_LEN
30147 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30148 + if (test_known(&arg->delist, name, nlen)
30149 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30150 + goto out; /* already exists or whiteouted */
30152 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30154 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30155 + d_type = DT_UNKNOWN;
30156 + arg->err = append_de(arg->vdir, name, nlen, ino,
30157 + d_type, &arg->delist);
30159 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30160 + name += AUFS_WH_PFX_LEN;
30161 + nlen -= AUFS_WH_PFX_LEN;
30162 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30163 + goto out; /* already whiteouted */
30166 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30169 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30170 + d_type = DT_UNKNOWN;
30171 + arg->err = au_nhash_append_wh
30172 + (&arg->whlist, name, nlen, ino, d_type,
30173 + arg->bindex, shwh);
30179 + arg->vdir->vd_jiffy = jiffies;
30181 + AuTraceErr(arg->err);
30185 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30186 + struct au_nhash *whlist, struct au_nhash *delist)
30188 +#ifdef CONFIG_AUFS_SHWH
30190 + unsigned int nh, u;
30191 + struct hlist_head *head;
30192 + struct au_vdir_wh *pos;
30193 + struct hlist_node *n;
30195 + struct au_vdir_destr *destr;
30197 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30200 + o = p = (void *)__get_free_page(GFP_NOFS);
30201 + if (unlikely(!p))
30205 + nh = whlist->nh_num;
30206 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30207 + p += AUFS_WH_PFX_LEN;
30208 + for (u = 0; u < nh; u++) {
30209 + head = whlist->nh_head + u;
30210 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30211 + destr = &pos->wh_str;
30212 + memcpy(p, destr->name, destr->len);
30213 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30214 + pos->wh_ino, pos->wh_type, delist);
30215 + if (unlikely(err))
30220 + free_page((unsigned long)o);
30230 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30233 + unsigned int rdhash;
30235 + aufs_bindex_t bbot, bindex, btop;
30236 + unsigned char shwh;
30237 + struct file *hf, *file;
30238 + struct super_block *sb;
30240 + file = arg->file;
30241 + sb = file->f_path.dentry->d_sb;
30242 + SiMustAnyLock(sb);
30244 + rdhash = au_sbi(sb)->si_rdhash;
30246 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30247 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30248 + if (unlikely(err))
30250 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30251 + if (unlikely(err))
30257 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30259 + au_fset_fillvdir(arg->flags, SHWH);
30261 + btop = au_fbtop(file);
30262 + bbot = au_fbbot_dir(file);
30263 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30264 + hf = au_hf_dir(file, bindex);
30268 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30270 + if (unlikely(offset))
30273 + arg->bindex = bindex;
30274 + au_fclr_fillvdir(arg->flags, WHABLE);
30276 + || (bindex != bbot
30277 + && au_br_whable(au_sbr_perm(sb, bindex))))
30278 + au_fset_fillvdir(arg->flags, WHABLE);
30281 + au_fclr_fillvdir(arg->flags, CALLED);
30283 + err = vfsub_iterate_dir(hf, &arg->ctx);
30286 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30289 + * dir_relax() may be good for concurrency, but aufs should not
30290 + * use it since it will cause a lockdep problem.
30294 + if (!err && shwh)
30295 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30297 + au_nhash_wh_free(&arg->whlist);
30300 + au_nhash_de_free(&arg->delist);
30305 +static int read_vdir(struct file *file, int may_read)
30308 + unsigned long expire;
30309 + unsigned char do_read;
30310 + struct fillvdir_arg arg = {
30312 + .actor = fillvdir
30315 + struct inode *inode;
30316 + struct au_vdir *vdir, *allocated;
30319 + inode = file_inode(file);
30320 + IMustLock(inode);
30321 + IiMustWriteLock(inode);
30322 + SiMustAnyLock(inode->i_sb);
30324 + allocated = NULL;
30326 + expire = au_sbi(inode->i_sb)->si_rdcache;
30327 + vdir = au_ivdir(inode);
30330 + vdir = alloc_vdir(file);
30331 + err = PTR_ERR(vdir);
30332 + if (IS_ERR(vdir))
30335 + allocated = vdir;
30336 + } else if (may_read
30337 + && (inode->i_version != vdir->vd_version
30338 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30340 + err = reinit_vdir(vdir);
30341 + if (unlikely(err))
30346 + return 0; /* success */
30350 + err = au_do_read_vdir(&arg);
30352 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30353 + vdir->vd_version = inode->i_version;
30354 + vdir->vd_last.ul = 0;
30355 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30357 + au_set_ivdir(inode, allocated);
30358 + } else if (allocated)
30359 + au_vdir_free(allocated);
30365 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30368 + unsigned long ul, n;
30369 + const unsigned int deblk_sz = src->vd_deblk_sz;
30371 + AuDebugOn(tgt->vd_nblk != 1);
30374 + if (tgt->vd_nblk < src->vd_nblk) {
30375 + unsigned char **p;
30377 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30378 + GFP_NOFS, /*may_shrink*/0);
30379 + if (unlikely(!p))
30381 + tgt->vd_deblk = p;
30384 + if (tgt->vd_deblk_sz != deblk_sz) {
30385 + unsigned char *p;
30387 + tgt->vd_deblk_sz = deblk_sz;
30388 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30389 + /*may_shrink*/1);
30390 + if (unlikely(!p))
30392 + tgt->vd_deblk[0] = p;
30394 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30395 + tgt->vd_version = src->vd_version;
30396 + tgt->vd_jiffy = src->vd_jiffy;
30398 + n = src->vd_nblk;
30399 + for (ul = 1; ul < n; ul++) {
30400 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30402 + if (unlikely(!tgt->vd_deblk[ul]))
30406 + tgt->vd_nblk = n;
30407 + tgt->vd_last.ul = tgt->vd_last.ul;
30408 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30409 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30410 + - src->vd_deblk[src->vd_last.ul];
30412 + return 0; /* success */
30415 + rerr = reinit_vdir(tgt);
30420 +int au_vdir_init(struct file *file)
30423 + struct inode *inode;
30424 + struct au_vdir *vdir_cache, *allocated;
30426 + /* test file->f_pos here instead of ctx->pos */
30427 + err = read_vdir(file, !file->f_pos);
30428 + if (unlikely(err))
30431 + allocated = NULL;
30432 + vdir_cache = au_fvdir_cache(file);
30433 + if (!vdir_cache) {
30434 + vdir_cache = alloc_vdir(file);
30435 + err = PTR_ERR(vdir_cache);
30436 + if (IS_ERR(vdir_cache))
30438 + allocated = vdir_cache;
30439 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30440 + /* test file->f_pos here instead of ctx->pos */
30441 + err = reinit_vdir(vdir_cache);
30442 + if (unlikely(err))
30445 + return 0; /* success */
30447 + inode = file_inode(file);
30448 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30450 + file->f_version = inode->i_version;
30452 + au_set_fvdir_cache(file, allocated);
30453 + } else if (allocated)
30454 + au_vdir_free(allocated);
30460 +static loff_t calc_offset(struct au_vdir *vdir)
30463 + union au_vdir_deblk_p p;
30465 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30466 + offset = vdir->vd_last.p.deblk - p.deblk;
30467 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30471 +/* returns true or false */
30472 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30475 + unsigned int deblk_sz;
30476 + unsigned long ul, n;
30478 + union au_vdir_deblk_p p, deblk_end;
30479 + struct au_vdir *vdir_cache;
30482 + vdir_cache = au_fvdir_cache(file);
30483 + offset = calc_offset(vdir_cache);
30484 + AuDbg("offset %lld\n", offset);
30485 + if (ctx->pos == offset)
30488 + vdir_cache->vd_last.ul = 0;
30489 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30494 + deblk_sz = vdir_cache->vd_deblk_sz;
30495 + ul = div64_u64(ctx->pos, deblk_sz);
30496 + AuDbg("ul %lu\n", ul);
30497 + if (ul >= vdir_cache->vd_nblk)
30500 + n = vdir_cache->vd_nblk;
30501 + for (; ul < n; ul++) {
30502 + p.deblk = vdir_cache->vd_deblk[ul];
30503 + deblk_end.deblk = p.deblk + deblk_sz;
30505 + offset *= deblk_sz;
30506 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30509 + l = calc_size(p.de->de_str.len);
30513 + if (!is_deblk_end(&p, &deblk_end)) {
30515 + vdir_cache->vd_last.ul = ul;
30516 + vdir_cache->vd_last.p = p;
30523 + AuTraceErr(!valid);
30527 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30529 + unsigned int l, deblk_sz;
30530 + union au_vdir_deblk_p deblk_end;
30531 + struct au_vdir *vdir_cache;
30532 + struct au_vdir_de *de;
30534 + vdir_cache = au_fvdir_cache(file);
30535 + if (!seek_vdir(file, ctx))
30538 + deblk_sz = vdir_cache->vd_deblk_sz;
30540 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30541 + deblk_end.deblk += deblk_sz;
30542 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30543 + de = vdir_cache->vd_last.p.de;
30544 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30545 + de->de_str.len, de->de_str.name, ctx->pos,
30546 + (unsigned long)de->de_ino, de->de_type);
30547 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30548 + de->de_str.len, de->de_ino,
30550 + /* todo: ignore the error caused by udba? */
30551 + /* return err; */
30555 + l = calc_size(de->de_str.len);
30556 + vdir_cache->vd_last.p.deblk += l;
30559 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30560 + vdir_cache->vd_last.ul++;
30561 + vdir_cache->vd_last.p.deblk
30562 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30563 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30572 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30573 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30574 +++ linux/fs/aufs/vfsub.c 2017-07-29 12:14:25.906375514 +0200
30577 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30579 + * This program, aufs is free software; you can redistribute it and/or modify
30580 + * it under the terms of the GNU General Public License as published by
30581 + * the Free Software Foundation; either version 2 of the License, or
30582 + * (at your option) any later version.
30584 + * This program is distributed in the hope that it will be useful,
30585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30587 + * GNU General Public License for more details.
30589 + * You should have received a copy of the GNU General Public License
30590 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30594 + * sub-routines for VFS
30597 +#include <linux/namei.h>
30598 +#include <linux/nsproxy.h>
30599 +#include <linux/security.h>
30600 +#include <linux/splice.h>
30601 +#ifdef CONFIG_AUFS_BR_FUSE
30602 +#include "../fs/mount.h"
30606 +#ifdef CONFIG_AUFS_BR_FUSE
30607 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30609 + struct nsproxy *ns;
30611 + if (!au_test_fuse(h_sb) || !au_userns)
30614 + ns = current->nsproxy;
30615 + /* no {get,put}_nsproxy(ns) */
30616 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30620 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
30625 + down_read(&h_sb->s_umount);
30626 + err = __sync_filesystem(h_sb, wait);
30627 + up_read(&h_sb->s_umount);
30633 +/* ---------------------------------------------------------------------- */
30635 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30639 + struct super_block *h_sb;
30641 + /* for remote fs, leave work for its getattr or d_revalidate */
30642 + /* for bad i_attr fs, handle them in aufs_getattr() */
30643 + /* still some fs may acquire i_mutex. we need to skip them */
30647 + h_sb = h_path->dentry->d_sb;
30648 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30650 + err = vfsub_getattr(h_path, &st);
30655 +/* ---------------------------------------------------------------------- */
30657 +struct file *vfsub_dentry_open(struct path *path, int flags)
30659 + struct file *file;
30661 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30663 + if (!IS_ERR_OR_NULL(file)
30664 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30665 + i_readcount_inc(d_inode(path->dentry));
30670 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30672 + struct file *file;
30675 + file = filp_open(path,
30676 + oflags /* | __FMODE_NONOTIFY */,
30679 + if (IS_ERR(file))
30681 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30688 + * Ideally this function should call VFS:do_last() in order to keep all its
30689 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30690 + * structure such as nameidata. This is a second (or third) best approach.
30691 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30693 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30694 + struct vfsub_aopen_args *args, struct au_branch *br)
30697 + struct file *file = args->file;
30698 + /* copied from linux/fs/namei.c:atomic_open() */
30699 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30702 + AuDebugOn(!dir->i_op->atomic_open);
30704 + err = au_br_test_oflag(args->open_flag, br);
30705 + if (unlikely(err))
30708 + args->file->f_path.dentry = DENTRY_NOT_SET;
30709 + args->file->f_path.mnt = au_br_mnt(br);
30710 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30711 + args->create_mode, args->opened);
30713 + /* some filesystems don't set FILE_CREATED while succeeded? */
30714 + if (*args->opened & FILE_CREATED)
30715 + fsnotify_create(dir, dentry);
30721 + /* todo: call VFS:may_open() here */
30722 + err = open_check_o_direct(file);
30723 + /* todo: ima_file_check() too? */
30724 + if (!err && (args->open_flag & __FMODE_EXEC))
30725 + err = deny_write_access(file);
30726 + if (unlikely(err))
30727 + /* note that the file is created and still opened */
30732 + fsnotify_open(file);
30738 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30742 + err = kern_path(name, flags, path);
30743 + if (!err && d_is_positive(path->dentry))
30744 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30748 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30749 + struct dentry *parent, int len)
30751 + struct path path = {
30755 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30756 + if (IS_ERR(path.dentry))
30758 + if (d_is_positive(path.dentry))
30759 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30762 + AuTraceErrPtr(path.dentry);
30763 + return path.dentry;
30766 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30769 + struct path path = {
30773 + /* VFS checks it too, but by WARN_ON_ONCE() */
30774 + IMustLock(d_inode(parent));
30776 + path.dentry = lookup_one_len(name, parent, len);
30777 + if (IS_ERR(path.dentry))
30779 + if (d_is_positive(path.dentry))
30780 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30783 + AuTraceErrPtr(path.dentry);
30784 + return path.dentry;
30787 +void vfsub_call_lkup_one(void *args)
30789 + struct vfsub_lkup_one_args *a = args;
30790 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30793 +/* ---------------------------------------------------------------------- */
30795 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30796 + struct dentry *d2, struct au_hinode *hdir2)
30798 + struct dentry *d;
30801 + d = lock_rename(d1, d2);
30803 + au_hn_suspend(hdir1);
30804 + if (hdir1 != hdir2)
30805 + au_hn_suspend(hdir2);
30810 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30811 + struct dentry *d2, struct au_hinode *hdir2)
30813 + au_hn_resume(hdir1);
30814 + if (hdir1 != hdir2)
30815 + au_hn_resume(hdir2);
30817 + unlock_rename(d1, d2);
30821 +/* ---------------------------------------------------------------------- */
30823 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30826 + struct dentry *d;
30830 + d = path->dentry;
30831 + path->dentry = d->d_parent;
30832 + err = security_path_mknod(path, d, mode, 0);
30833 + path->dentry = d;
30834 + if (unlikely(err))
30838 + err = vfs_create(dir, path->dentry, mode, want_excl);
30841 + struct path tmp = *path;
30844 + vfsub_update_h_iattr(&tmp, &did);
30846 + tmp.dentry = path->dentry->d_parent;
30847 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30856 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30859 + struct dentry *d;
30863 + d = path->dentry;
30864 + path->dentry = d->d_parent;
30865 + err = security_path_symlink(path, d, symname);
30866 + path->dentry = d;
30867 + if (unlikely(err))
30871 + err = vfs_symlink(dir, path->dentry, symname);
30874 + struct path tmp = *path;
30877 + vfsub_update_h_iattr(&tmp, &did);
30879 + tmp.dentry = path->dentry->d_parent;
30880 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30889 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30892 + struct dentry *d;
30896 + d = path->dentry;
30897 + path->dentry = d->d_parent;
30898 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30899 + path->dentry = d;
30900 + if (unlikely(err))
30904 + err = vfs_mknod(dir, path->dentry, mode, dev);
30907 + struct path tmp = *path;
30910 + vfsub_update_h_iattr(&tmp, &did);
30912 + tmp.dentry = path->dentry->d_parent;
30913 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30922 +static int au_test_nlink(struct inode *inode)
30924 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30926 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30927 + || inode->i_nlink < link_max)
30932 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30933 + struct inode **delegated_inode)
30936 + struct dentry *d;
30940 + err = au_test_nlink(d_inode(src_dentry));
30941 + if (unlikely(err))
30944 + /* we don't call may_linkat() */
30945 + d = path->dentry;
30946 + path->dentry = d->d_parent;
30947 + err = security_path_link(src_dentry, path, d);
30948 + path->dentry = d;
30949 + if (unlikely(err))
30953 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30956 + struct path tmp = *path;
30959 + /* fuse has different memory inode for the same inumber */
30960 + vfsub_update_h_iattr(&tmp, &did);
30962 + tmp.dentry = path->dentry->d_parent;
30963 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30964 + tmp.dentry = src_dentry;
30965 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30974 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30975 + struct inode *dir, struct path *path,
30976 + struct inode **delegated_inode, unsigned int flags)
30979 + struct path tmp = {
30982 + struct dentry *d;
30985 + IMustLock(src_dir);
30987 + d = path->dentry;
30988 + path->dentry = d->d_parent;
30989 + tmp.dentry = src_dentry->d_parent;
30990 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30991 + path->dentry = d;
30992 + if (unlikely(err))
30996 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30997 + delegated_inode, flags);
31002 + tmp.dentry = d->d_parent;
31003 + vfsub_update_h_iattr(&tmp, &did);
31005 + tmp.dentry = src_dentry;
31006 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31007 + tmp.dentry = src_dentry->d_parent;
31008 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31017 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
31020 + struct dentry *d;
31024 + d = path->dentry;
31025 + path->dentry = d->d_parent;
31026 + err = security_path_mkdir(path, d, mode);
31027 + path->dentry = d;
31028 + if (unlikely(err))
31032 + err = vfs_mkdir(dir, path->dentry, mode);
31035 + struct path tmp = *path;
31038 + vfsub_update_h_iattr(&tmp, &did);
31040 + tmp.dentry = path->dentry->d_parent;
31041 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31050 +int vfsub_rmdir(struct inode *dir, struct path *path)
31053 + struct dentry *d;
31057 + d = path->dentry;
31058 + path->dentry = d->d_parent;
31059 + err = security_path_rmdir(path, d);
31060 + path->dentry = d;
31061 + if (unlikely(err))
31065 + err = vfs_rmdir(dir, path->dentry);
31068 + struct path tmp = {
31069 + .dentry = path->dentry->d_parent,
31073 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31080 +/* ---------------------------------------------------------------------- */
31082 +/* todo: support mmap_sem? */
31083 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31089 + err = vfs_read(file, ubuf, count, ppos);
31092 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31096 +/* todo: kernel_read()? */
31097 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31101 + mm_segment_t oldfs;
31108 + oldfs = get_fs();
31109 + set_fs(KERNEL_DS);
31110 + err = vfsub_read_u(file, buf.u, count, ppos);
31115 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31121 + err = vfs_write(file, ubuf, count, ppos);
31124 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31128 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31131 + mm_segment_t oldfs;
31134 + const char __user *u;
31138 + oldfs = get_fs();
31139 + set_fs(KERNEL_DS);
31140 + err = vfsub_write_u(file, buf.u, count, ppos);
31145 +int vfsub_flush(struct file *file, fl_owner_t id)
31150 + if (file->f_op->flush) {
31151 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31152 + err = file->f_op->flush(file, id);
31155 + err = file->f_op->flush(file, id);
31159 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31165 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31169 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31172 + err = iterate_dir(file, ctx);
31175 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31180 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31181 + struct pipe_inode_info *pipe, size_t len,
31182 + unsigned int flags)
31187 + err = do_splice_to(in, ppos, pipe, len, flags);
31189 + file_accessed(in);
31191 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31195 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31196 + loff_t *ppos, size_t len, unsigned int flags)
31201 + err = do_splice_from(pipe, out, ppos, len, flags);
31204 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31208 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31212 + /* file can be NULL */
31214 + err = vfs_fsync(file, datasync);
31218 + AuDebugOn(!file);
31219 + path = &file->f_path;
31221 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31226 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31227 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31228 + struct file *h_file)
31231 + struct inode *h_inode;
31232 + struct super_block *h_sb;
31235 + err = vfsub_truncate(h_path, length);
31239 + h_inode = d_inode(h_path->dentry);
31240 + h_sb = h_inode->i_sb;
31242 + sb_start_write(h_sb);
31244 + err = locks_verify_truncate(h_inode, h_file, length);
31246 + err = security_path_truncate(h_path);
31249 + err = do_truncate(h_path->dentry, length, attr, h_file);
31253 + sb_end_write(h_sb);
31260 +/* ---------------------------------------------------------------------- */
31262 +struct au_vfsub_mkdir_args {
31264 + struct inode *dir;
31265 + struct path *path;
31269 +static void au_call_vfsub_mkdir(void *args)
31271 + struct au_vfsub_mkdir_args *a = args;
31272 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31275 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31277 + int err, do_sio, wkq_err;
31279 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31282 + err = vfsub_mkdir(dir, path, mode);
31285 + struct au_vfsub_mkdir_args args = {
31291 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31292 + if (unlikely(wkq_err))
31299 +struct au_vfsub_rmdir_args {
31301 + struct inode *dir;
31302 + struct path *path;
31305 +static void au_call_vfsub_rmdir(void *args)
31307 + struct au_vfsub_rmdir_args *a = args;
31308 + *a->errp = vfsub_rmdir(a->dir, a->path);
31311 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31313 + int err, do_sio, wkq_err;
31315 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31318 + err = vfsub_rmdir(dir, path);
31321 + struct au_vfsub_rmdir_args args = {
31326 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31327 + if (unlikely(wkq_err))
31334 +/* ---------------------------------------------------------------------- */
31336 +struct notify_change_args {
31338 + struct path *path;
31339 + struct iattr *ia;
31340 + struct inode **delegated_inode;
31343 +static void call_notify_change(void *args)
31345 + struct notify_change_args *a = args;
31346 + struct inode *h_inode;
31348 + h_inode = d_inode(a->path->dentry);
31349 + IMustLock(h_inode);
31351 + *a->errp = -EPERM;
31352 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31354 + *a->errp = notify_change(a->path->dentry, a->ia,
31355 + a->delegated_inode);
31358 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31360 + AuTraceErr(*a->errp);
31363 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31364 + struct inode **delegated_inode)
31367 + struct notify_change_args args = {
31371 + .delegated_inode = delegated_inode
31374 + call_notify_change(&args);
31379 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31380 + struct inode **delegated_inode)
31382 + int err, wkq_err;
31383 + struct notify_change_args args = {
31387 + .delegated_inode = delegated_inode
31390 + wkq_err = au_wkq_wait(call_notify_change, &args);
31391 + if (unlikely(wkq_err))
31397 +/* ---------------------------------------------------------------------- */
31399 +struct unlink_args {
31401 + struct inode *dir;
31402 + struct path *path;
31403 + struct inode **delegated_inode;
31406 +static void call_unlink(void *args)
31408 + struct unlink_args *a = args;
31409 + struct dentry *d = a->path->dentry;
31410 + struct inode *h_inode;
31411 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31412 + && au_dcount(d) == 1);
31414 + IMustLock(a->dir);
31416 + a->path->dentry = d->d_parent;
31417 + *a->errp = security_path_unlink(a->path, d);
31418 + a->path->dentry = d;
31419 + if (unlikely(*a->errp))
31422 + if (!stop_sillyrename)
31425 + if (d_is_positive(d)) {
31426 + h_inode = d_inode(d);
31431 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31434 + struct path tmp = {
31435 + .dentry = d->d_parent,
31436 + .mnt = a->path->mnt
31438 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31441 + if (!stop_sillyrename)
31446 + AuTraceErr(*a->errp);
31450 + * @dir: must be locked.
31451 + * @dentry: target dentry.
31453 +int vfsub_unlink(struct inode *dir, struct path *path,
31454 + struct inode **delegated_inode, int force)
31457 + struct unlink_args args = {
31461 + .delegated_inode = delegated_inode
31465 + call_unlink(&args);
31469 + wkq_err = au_wkq_wait(call_unlink, &args);
31470 + if (unlikely(wkq_err))
31476 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31477 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31478 +++ linux/fs/aufs/vfsub.h 2017-07-29 12:14:25.906375514 +0200
31481 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31483 + * This program, aufs is free software; you can redistribute it and/or modify
31484 + * it under the terms of the GNU General Public License as published by
31485 + * the Free Software Foundation; either version 2 of the License, or
31486 + * (at your option) any later version.
31488 + * This program is distributed in the hope that it will be useful,
31489 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31491 + * GNU General Public License for more details.
31493 + * You should have received a copy of the GNU General Public License
31494 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31498 + * sub-routines for VFS
31501 +#ifndef __AUFS_VFSUB_H__
31502 +#define __AUFS_VFSUB_H__
31506 +#include <linux/fs.h>
31507 +#include <linux/mount.h>
31508 +#include <linux/posix_acl.h>
31509 +#include <linux/xattr.h>
31510 +#include "debug.h"
31512 +/* copied from linux/fs/internal.h */
31513 +/* todo: BAD approach!! */
31514 +extern void __mnt_drop_write(struct vfsmount *);
31515 +extern int open_check_o_direct(struct file *f);
31517 +/* ---------------------------------------------------------------------- */
31519 +/* lock subclass for lower inode */
31520 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31521 +/* reduce? gave up. */
31523 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31524 + AuLsc_I_PARENT, /* lower inode, parent first */
31525 + AuLsc_I_PARENT2, /* copyup dirs */
31526 + AuLsc_I_PARENT3, /* copyup wh */
31532 +/* to debug easier, do not make them inlined functions */
31533 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31534 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31536 +/* ---------------------------------------------------------------------- */
31538 +static inline void vfsub_drop_nlink(struct inode *inode)
31540 + AuDebugOn(!inode->i_nlink);
31541 + drop_nlink(inode);
31544 +static inline void vfsub_dead_dir(struct inode *inode)
31546 + AuDebugOn(!S_ISDIR(inode->i_mode));
31547 + inode->i_flags |= S_DEAD;
31548 + clear_nlink(inode);
31551 +static inline int vfsub_native_ro(struct inode *inode)
31553 + return (inode->i_sb->s_flags & MS_RDONLY)
31554 + || IS_RDONLY(inode)
31555 + /* || IS_APPEND(inode) */
31556 + || IS_IMMUTABLE(inode);
31559 +#ifdef CONFIG_AUFS_BR_FUSE
31560 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31562 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31565 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
31567 +/* ---------------------------------------------------------------------- */
31569 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31570 +struct file *vfsub_dentry_open(struct path *path, int flags);
31571 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31572 +struct vfsub_aopen_args {
31573 + struct file *file;
31574 + unsigned int open_flag;
31575 + umode_t create_mode;
31579 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31580 + struct vfsub_aopen_args *args, struct au_branch *br);
31581 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31583 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31584 + struct dentry *parent, int len);
31585 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31588 +struct vfsub_lkup_one_args {
31589 + struct dentry **errp;
31590 + struct qstr *name;
31591 + struct dentry *parent;
31594 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31595 + struct dentry *parent)
31597 + return vfsub_lookup_one_len(name->name, parent, name->len);
31600 +void vfsub_call_lkup_one(void *args);
31602 +/* ---------------------------------------------------------------------- */
31604 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31609 + err = mnt_want_write(mnt);
31614 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31617 + mnt_drop_write(mnt);
31621 +#if 0 /* reserved */
31622 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31625 + mnt_drop_write_file(file);
31630 +/* ---------------------------------------------------------------------- */
31633 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31634 + struct dentry *d2, struct au_hinode *hdir2);
31635 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31636 + struct dentry *d2, struct au_hinode *hdir2);
31638 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31640 +int vfsub_symlink(struct inode *dir, struct path *path,
31641 + const char *symname);
31642 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31643 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31644 + struct path *path, struct inode **delegated_inode);
31645 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31646 + struct inode *hdir, struct path *path,
31647 + struct inode **delegated_inode, unsigned int flags);
31648 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31649 +int vfsub_rmdir(struct inode *dir, struct path *path);
31651 +/* ---------------------------------------------------------------------- */
31653 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31655 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31657 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31659 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31661 +int vfsub_flush(struct file *file, fl_owner_t id);
31662 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31664 +static inline loff_t vfsub_f_size_read(struct file *file)
31666 + return i_size_read(file_inode(file));
31669 +static inline unsigned int vfsub_file_flags(struct file *file)
31671 + unsigned int flags;
31673 + spin_lock(&file->f_lock);
31674 + flags = file->f_flags;
31675 + spin_unlock(&file->f_lock);
31680 +static inline int vfsub_file_execed(struct file *file)
31682 + /* todo: direct access f_flags */
31683 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31686 +#if 0 /* reserved */
31687 +static inline void vfsub_file_accessed(struct file *h_file)
31689 + file_accessed(h_file);
31690 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31694 +#if 0 /* reserved */
31695 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31696 + struct dentry *h_dentry)
31698 + struct path h_path = {
31699 + .dentry = h_dentry,
31702 + touch_atime(&h_path);
31703 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31707 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31710 + return update_time(h_inode, ts, flags);
31711 + /* no vfsub_update_h_iattr() since we don't have struct path */
31714 +#ifdef CONFIG_FS_POSIX_ACL
31715 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31719 + err = posix_acl_chmod(h_inode, h_mode);
31720 + if (err == -EOPNOTSUPP)
31725 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31728 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31729 + struct pipe_inode_info *pipe, size_t len,
31730 + unsigned int flags);
31731 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31732 + loff_t *ppos, size_t len, unsigned int flags);
31734 +static inline long vfsub_truncate(struct path *path, loff_t length)
31739 + err = vfs_truncate(path, length);
31744 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31745 + struct file *h_file);
31746 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31749 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
31752 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
31758 + err = vfs_clone_file_range(src, 0, dst, 0, len);
31764 +/* copy_file_range(2) is a systemcall */
31765 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
31766 + struct file *dst, loff_t dst_pos,
31767 + size_t len, unsigned int flags)
31772 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
31778 +/* ---------------------------------------------------------------------- */
31780 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31785 + err = vfs_llseek(file, offset, origin);
31790 +/* ---------------------------------------------------------------------- */
31792 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31793 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31794 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31795 + struct inode **delegated_inode);
31796 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31797 + struct inode **delegated_inode);
31798 +int vfsub_unlink(struct inode *dir, struct path *path,
31799 + struct inode **delegated_inode, int force);
31801 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
31803 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
31806 +/* ---------------------------------------------------------------------- */
31808 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31809 + const void *value, size_t size, int flags)
31814 + err = vfs_setxattr(dentry, name, value, size, flags);
31820 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31825 + err = vfs_removexattr(dentry, name);
31831 +#endif /* __KERNEL__ */
31832 +#endif /* __AUFS_VFSUB_H__ */
31833 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31834 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31835 +++ linux/fs/aufs/wbr_policy.c 2017-07-29 12:14:25.906375514 +0200
31838 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31840 + * This program, aufs is free software; you can redistribute it and/or modify
31841 + * it under the terms of the GNU General Public License as published by
31842 + * the Free Software Foundation; either version 2 of the License, or
31843 + * (at your option) any later version.
31845 + * This program is distributed in the hope that it will be useful,
31846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31848 + * GNU General Public License for more details.
31850 + * You should have received a copy of the GNU General Public License
31851 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31855 + * policies for selecting one among multiple writable branches
31858 +#include <linux/statfs.h>
31861 +/* subset of cpup_attr() */
31862 +static noinline_for_stack
31863 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31867 + struct inode *h_isrc;
31869 + h_isrc = d_inode(h_src);
31870 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31871 + ia.ia_mode = h_isrc->i_mode;
31872 + ia.ia_uid = h_isrc->i_uid;
31873 + ia.ia_gid = h_isrc->i_gid;
31874 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31875 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31876 + /* no delegation since it is just created */
31877 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31879 + /* is this nfs only? */
31880 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31881 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31882 + ia.ia_mode = h_isrc->i_mode;
31883 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31889 +#define AuCpdown_PARENT_OPQ 1
31890 +#define AuCpdown_WHED (1 << 1)
31891 +#define AuCpdown_MADE_DIR (1 << 2)
31892 +#define AuCpdown_DIROPQ (1 << 3)
31893 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31894 +#define au_fset_cpdown(flags, name) \
31895 + do { (flags) |= AuCpdown_##name; } while (0)
31896 +#define au_fclr_cpdown(flags, name) \
31897 + do { (flags) &= ~AuCpdown_##name; } while (0)
31899 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31900 + unsigned int *flags)
31903 + struct dentry *opq_dentry;
31905 + opq_dentry = au_diropq_create(dentry, bdst);
31906 + err = PTR_ERR(opq_dentry);
31907 + if (IS_ERR(opq_dentry))
31909 + dput(opq_dentry);
31910 + au_fset_cpdown(*flags, DIROPQ);
31916 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31917 + struct inode *dir, aufs_bindex_t bdst)
31920 + struct path h_path;
31921 + struct au_branch *br;
31923 + br = au_sbr(dentry->d_sb, bdst);
31924 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31925 + err = PTR_ERR(h_path.dentry);
31926 + if (IS_ERR(h_path.dentry))
31930 + if (d_is_positive(h_path.dentry)) {
31931 + h_path.mnt = au_br_mnt(br);
31932 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31935 + dput(h_path.dentry);
31941 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31942 + struct au_pin *pin,
31943 + struct dentry *h_parent, void *arg)
31946 + aufs_bindex_t bopq, btop;
31947 + struct path h_path;
31948 + struct dentry *parent;
31949 + struct inode *h_dir, *h_inode, *inode, *dir;
31950 + unsigned int *flags = arg;
31952 + btop = au_dbtop(dentry);
31953 + /* dentry is di-locked */
31954 + parent = dget_parent(dentry);
31955 + dir = d_inode(parent);
31956 + h_dir = d_inode(h_parent);
31957 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31958 + IMustLock(h_dir);
31960 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31961 + if (unlikely(err < 0))
31963 + h_path.dentry = au_h_dptr(dentry, bdst);
31964 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31965 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31966 + S_IRWXU | S_IRUGO | S_IXUGO);
31967 + if (unlikely(err))
31969 + au_fset_cpdown(*flags, MADE_DIR);
31971 + bopq = au_dbdiropq(dentry);
31972 + au_fclr_cpdown(*flags, WHED);
31973 + au_fclr_cpdown(*flags, DIROPQ);
31974 + if (au_dbwh(dentry) == bdst)
31975 + au_fset_cpdown(*flags, WHED);
31976 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31977 + au_fset_cpdown(*flags, PARENT_OPQ);
31978 + h_inode = d_inode(h_path.dentry);
31979 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31980 + if (au_ftest_cpdown(*flags, WHED)) {
31981 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31982 + if (unlikely(err)) {
31983 + inode_unlock(h_inode);
31988 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31989 + inode_unlock(h_inode);
31990 + if (unlikely(err))
31993 + if (au_ftest_cpdown(*flags, WHED)) {
31994 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31995 + if (unlikely(err))
31999 + inode = d_inode(dentry);
32000 + if (au_ibbot(inode) < bdst)
32001 + au_set_ibbot(inode, bdst);
32002 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
32003 + au_hi_flags(inode, /*isdir*/1));
32004 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
32005 + goto out; /* success */
32009 + if (au_ftest_cpdown(*flags, DIROPQ)) {
32010 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
32011 + rerr = au_diropq_remove(dentry, bdst);
32012 + inode_unlock(h_inode);
32013 + if (unlikely(rerr)) {
32014 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
32015 + dentry, bdst, rerr);
32021 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
32022 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
32023 + if (unlikely(rerr)) {
32024 + AuIOErr("failed removing %pd b%d (%d)\n",
32025 + dentry, bdst, rerr);
32030 + au_set_h_dptr(dentry, bdst, NULL);
32031 + if (au_dbbot(dentry) == bdst)
32032 + au_update_dbbot(dentry);
32038 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
32041 + unsigned int flags;
32044 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
32049 +/* ---------------------------------------------------------------------- */
32051 +/* policies for create */
32053 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
32055 + int err, i, j, ndentry;
32056 + aufs_bindex_t bopq;
32057 + struct au_dcsub_pages dpages;
32058 + struct au_dpage *dpage;
32059 + struct dentry **dentries, *parent, *d;
32061 + err = au_dpages_init(&dpages, GFP_NOFS);
32062 + if (unlikely(err))
32064 + parent = dget_parent(dentry);
32065 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
32066 + if (unlikely(err))
32070 + for (i = 0; i < dpages.ndpage; i++) {
32071 + dpage = dpages.dpages + i;
32072 + dentries = dpage->dentries;
32073 + ndentry = dpage->ndentry;
32074 + for (j = 0; j < ndentry; j++) {
32076 + di_read_lock_parent2(d, !AuLock_IR);
32077 + bopq = au_dbdiropq(d);
32078 + di_read_unlock(d, !AuLock_IR);
32079 + if (bopq >= 0 && bopq < err)
32086 + au_dpages_free(&dpages);
32091 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32093 + for (; bindex >= 0; bindex--)
32094 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32099 +/* top down parent */
32100 +static int au_wbr_create_tdp(struct dentry *dentry,
32101 + unsigned int flags __maybe_unused)
32104 + aufs_bindex_t btop, bindex;
32105 + struct super_block *sb;
32106 + struct dentry *parent, *h_parent;
32108 + sb = dentry->d_sb;
32109 + btop = au_dbtop(dentry);
32111 + if (!au_br_rdonly(au_sbr(sb, btop)))
32115 + parent = dget_parent(dentry);
32116 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32117 + h_parent = au_h_dptr(parent, bindex);
32118 + if (!h_parent || d_is_negative(h_parent))
32121 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32128 + /* bottom up here */
32129 + if (unlikely(err < 0)) {
32130 + err = au_wbr_bu(sb, btop - 1);
32132 + err = au_wbr_nonopq(dentry, err);
32136 + AuDbg("b%d\n", err);
32140 +/* ---------------------------------------------------------------------- */
32142 +/* an exception for the policy other than tdp */
32143 +static int au_wbr_create_exp(struct dentry *dentry)
32146 + aufs_bindex_t bwh, bdiropq;
32147 + struct dentry *parent;
32150 + bwh = au_dbwh(dentry);
32151 + parent = dget_parent(dentry);
32152 + bdiropq = au_dbdiropq(parent);
32154 + if (bdiropq >= 0)
32155 + err = min(bdiropq, bwh);
32158 + AuDbg("%d\n", err);
32159 + } else if (bdiropq >= 0) {
32161 + AuDbg("%d\n", err);
32166 + err = au_wbr_nonopq(dentry, err);
32168 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32171 + AuDbg("%d\n", err);
32175 +/* ---------------------------------------------------------------------- */
32178 +static int au_wbr_create_init_rr(struct super_block *sb)
32182 + err = au_wbr_bu(sb, au_sbbot(sb));
32183 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32186 + AuDbg("b%d\n", err);
32190 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32194 + aufs_bindex_t bindex, bbot;
32195 + struct super_block *sb;
32198 + err = au_wbr_create_exp(dentry);
32202 + sb = dentry->d_sb;
32203 + next = &au_sbi(sb)->si_wbr_rr_next;
32204 + bbot = au_sbbot(sb);
32206 + for (bindex = 0; bindex <= bbot; bindex++) {
32207 + if (!au_ftest_wbr(flags, DIR)) {
32208 + err = atomic_dec_return(next) + 1;
32209 + /* modulo for 0 is meaningless */
32210 + if (unlikely(!err))
32211 + err = atomic_dec_return(next) + 1;
32213 + err = atomic_read(next);
32214 + AuDbg("%d\n", err);
32217 + AuDbg("%d\n", err);
32218 + if (!au_br_rdonly(au_sbr(sb, err)))
32224 + err = au_wbr_nonopq(dentry, err);
32227 + AuDbg("%d\n", err);
32231 +/* ---------------------------------------------------------------------- */
32233 +/* most free space */
32234 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32236 + struct super_block *sb;
32237 + struct au_branch *br;
32238 + struct au_wbr_mfs *mfs;
32239 + struct dentry *h_parent;
32240 + aufs_bindex_t bindex, bbot;
32242 + unsigned long long b, bavail;
32243 + struct path h_path;
32244 + /* reduce the stack usage */
32245 + struct kstatfs *st;
32247 + st = kmalloc(sizeof(*st), GFP_NOFS);
32248 + if (unlikely(!st)) {
32249 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32254 + sb = dentry->d_sb;
32255 + mfs = &au_sbi(sb)->si_wbr_mfs;
32256 + MtxMustLock(&mfs->mfs_lock);
32257 + mfs->mfs_bindex = -EROFS;
32258 + mfs->mfsrr_bytes = 0;
32261 + bbot = au_sbbot(sb);
32263 + bindex = au_dbtop(parent);
32264 + bbot = au_dbtaildir(parent);
32267 + for (; bindex <= bbot; bindex++) {
32269 + h_parent = au_h_dptr(parent, bindex);
32270 + if (!h_parent || d_is_negative(h_parent))
32273 + br = au_sbr(sb, bindex);
32274 + if (au_br_rdonly(br))
32277 + /* sb->s_root for NFS is unreliable */
32278 + h_path.mnt = au_br_mnt(br);
32279 + h_path.dentry = h_path.mnt->mnt_root;
32280 + err = vfs_statfs(&h_path, st);
32281 + if (unlikely(err)) {
32282 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32286 + /* when the available size is equal, select the lower one */
32287 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32288 + || sizeof(b) < sizeof(st->f_bsize));
32289 + b = st->f_bavail * st->f_bsize;
32290 + br->br_wbr->wbr_bytes = b;
32291 + if (b >= bavail) {
32293 + mfs->mfs_bindex = bindex;
32294 + mfs->mfs_jiffy = jiffies;
32298 + mfs->mfsrr_bytes = bavail;
32299 + AuDbg("b%d\n", mfs->mfs_bindex);
32303 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32306 + struct dentry *parent;
32307 + struct super_block *sb;
32308 + struct au_wbr_mfs *mfs;
32310 + err = au_wbr_create_exp(dentry);
32314 + sb = dentry->d_sb;
32316 + if (au_ftest_wbr(flags, PARENT))
32317 + parent = dget_parent(dentry);
32318 + mfs = &au_sbi(sb)->si_wbr_mfs;
32319 + mutex_lock(&mfs->mfs_lock);
32320 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32321 + || mfs->mfs_bindex < 0
32322 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32323 + au_mfs(dentry, parent);
32324 + mutex_unlock(&mfs->mfs_lock);
32325 + err = mfs->mfs_bindex;
32329 + err = au_wbr_nonopq(dentry, err);
32332 + AuDbg("b%d\n", err);
32336 +static int au_wbr_create_init_mfs(struct super_block *sb)
32338 + struct au_wbr_mfs *mfs;
32340 + mfs = &au_sbi(sb)->si_wbr_mfs;
32341 + mutex_init(&mfs->mfs_lock);
32342 + mfs->mfs_jiffy = 0;
32343 + mfs->mfs_bindex = -EROFS;
32348 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32350 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32354 +/* ---------------------------------------------------------------------- */
32356 +/* top down regardless parent, and then mfs */
32357 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32358 + unsigned int flags __maybe_unused)
32361 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32362 + unsigned long long watermark;
32363 + struct super_block *sb;
32364 + struct au_wbr_mfs *mfs;
32365 + struct au_branch *br;
32366 + struct dentry *parent;
32368 + sb = dentry->d_sb;
32369 + mfs = &au_sbi(sb)->si_wbr_mfs;
32370 + mutex_lock(&mfs->mfs_lock);
32371 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32372 + || mfs->mfs_bindex < 0)
32373 + au_mfs(dentry, /*parent*/NULL);
32374 + watermark = mfs->mfsrr_watermark;
32375 + bmfs = mfs->mfs_bindex;
32376 + mutex_unlock(&mfs->mfs_lock);
32378 + /* another style of au_wbr_create_exp() */
32379 + bwh = au_dbwh(dentry);
32380 + parent = dget_parent(dentry);
32381 + btail = au_dbtaildir(parent);
32382 + if (bwh >= 0 && bwh < btail)
32385 + err = au_wbr_nonopq(dentry, btail);
32386 + if (unlikely(err < 0))
32390 + for (bindex = 0; bindex <= btail; bindex++) {
32391 + br = au_sbr(sb, bindex);
32392 + if (au_br_rdonly(br))
32394 + if (br->br_wbr->wbr_bytes > watermark) {
32405 + AuDbg("b%d\n", err);
32409 +/* ---------------------------------------------------------------------- */
32411 +/* most free space and then round robin */
32412 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32415 + struct au_wbr_mfs *mfs;
32417 + err = au_wbr_create_mfs(dentry, flags);
32419 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32420 + mutex_lock(&mfs->mfs_lock);
32421 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32422 + err = au_wbr_create_rr(dentry, flags);
32423 + mutex_unlock(&mfs->mfs_lock);
32426 + AuDbg("b%d\n", err);
32430 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32434 + au_wbr_create_init_mfs(sb); /* ignore */
32435 + err = au_wbr_create_init_rr(sb);
32440 +/* ---------------------------------------------------------------------- */
32442 +/* top down parent and most free space */
32443 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32446 + unsigned long long b;
32447 + aufs_bindex_t bindex, btop, bbot;
32448 + struct super_block *sb;
32449 + struct dentry *parent, *h_parent;
32450 + struct au_branch *br;
32452 + err = au_wbr_create_tdp(dentry, flags);
32453 + if (unlikely(err < 0))
32455 + parent = dget_parent(dentry);
32456 + btop = au_dbtop(parent);
32457 + bbot = au_dbtaildir(parent);
32458 + if (btop == bbot)
32459 + goto out_parent; /* success */
32461 + e2 = au_wbr_create_mfs(dentry, flags);
32463 + goto out_parent; /* success */
32465 + /* when the available size is equal, select upper one */
32466 + sb = dentry->d_sb;
32467 + br = au_sbr(sb, err);
32468 + b = br->br_wbr->wbr_bytes;
32469 + AuDbg("b%d, %llu\n", err, b);
32471 + for (bindex = btop; bindex <= bbot; bindex++) {
32472 + h_parent = au_h_dptr(parent, bindex);
32473 + if (!h_parent || d_is_negative(h_parent))
32476 + br = au_sbr(sb, bindex);
32477 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32478 + b = br->br_wbr->wbr_bytes;
32480 + AuDbg("b%d, %llu\n", err, b);
32485 + err = au_wbr_nonopq(dentry, err);
32490 + AuDbg("b%d\n", err);
32494 +/* ---------------------------------------------------------------------- */
32497 + * - top down parent
32498 + * - most free space with parent
32499 + * - most free space round-robin regardless parent
32501 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32504 + unsigned long long watermark;
32505 + struct super_block *sb;
32506 + struct au_branch *br;
32507 + struct au_wbr_mfs *mfs;
32509 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32510 + if (unlikely(err < 0))
32513 + sb = dentry->d_sb;
32514 + br = au_sbr(sb, err);
32515 + mfs = &au_sbi(sb)->si_wbr_mfs;
32516 + mutex_lock(&mfs->mfs_lock);
32517 + watermark = mfs->mfsrr_watermark;
32518 + mutex_unlock(&mfs->mfs_lock);
32519 + if (br->br_wbr->wbr_bytes < watermark)
32520 + /* regardless the parent dir */
32521 + err = au_wbr_create_mfsrr(dentry, flags);
32524 + AuDbg("b%d\n", err);
32528 +/* ---------------------------------------------------------------------- */
32530 +/* policies for copyup */
32532 +/* top down parent */
32533 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32535 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32538 +/* bottom up parent */
32539 +static int au_wbr_copyup_bup(struct dentry *dentry)
32542 + aufs_bindex_t bindex, btop;
32543 + struct dentry *parent, *h_parent;
32544 + struct super_block *sb;
32547 + sb = dentry->d_sb;
32548 + parent = dget_parent(dentry);
32549 + btop = au_dbtop(parent);
32550 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32551 + h_parent = au_h_dptr(parent, bindex);
32552 + if (!h_parent || d_is_negative(h_parent))
32555 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32562 + /* bottom up here */
32563 + if (unlikely(err < 0))
32564 + err = au_wbr_bu(sb, btop - 1);
32566 + AuDbg("b%d\n", err);
32571 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32575 + err = au_wbr_bu(dentry->d_sb, btop);
32576 + AuDbg("b%d\n", err);
32578 + err = au_wbr_nonopq(dentry, err);
32580 + AuDbg("b%d\n", err);
32584 +static int au_wbr_copyup_bu(struct dentry *dentry)
32587 + aufs_bindex_t btop;
32589 + btop = au_dbtop(dentry);
32590 + err = au_wbr_do_copyup_bu(dentry, btop);
32594 +/* ---------------------------------------------------------------------- */
32596 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32597 + [AuWbrCopyup_TDP] = {
32598 + .copyup = au_wbr_copyup_tdp
32600 + [AuWbrCopyup_BUP] = {
32601 + .copyup = au_wbr_copyup_bup
32603 + [AuWbrCopyup_BU] = {
32604 + .copyup = au_wbr_copyup_bu
32608 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32609 + [AuWbrCreate_TDP] = {
32610 + .create = au_wbr_create_tdp
32612 + [AuWbrCreate_RR] = {
32613 + .create = au_wbr_create_rr,
32614 + .init = au_wbr_create_init_rr
32616 + [AuWbrCreate_MFS] = {
32617 + .create = au_wbr_create_mfs,
32618 + .init = au_wbr_create_init_mfs,
32619 + .fin = au_wbr_create_fin_mfs
32621 + [AuWbrCreate_MFSV] = {
32622 + .create = au_wbr_create_mfs,
32623 + .init = au_wbr_create_init_mfs,
32624 + .fin = au_wbr_create_fin_mfs
32626 + [AuWbrCreate_MFSRR] = {
32627 + .create = au_wbr_create_mfsrr,
32628 + .init = au_wbr_create_init_mfsrr,
32629 + .fin = au_wbr_create_fin_mfs
32631 + [AuWbrCreate_MFSRRV] = {
32632 + .create = au_wbr_create_mfsrr,
32633 + .init = au_wbr_create_init_mfsrr,
32634 + .fin = au_wbr_create_fin_mfs
32636 + [AuWbrCreate_TDMFS] = {
32637 + .create = au_wbr_create_tdmfs,
32638 + .init = au_wbr_create_init_mfs,
32639 + .fin = au_wbr_create_fin_mfs
32641 + [AuWbrCreate_TDMFSV] = {
32642 + .create = au_wbr_create_tdmfs,
32643 + .init = au_wbr_create_init_mfs,
32644 + .fin = au_wbr_create_fin_mfs
32646 + [AuWbrCreate_PMFS] = {
32647 + .create = au_wbr_create_pmfs,
32648 + .init = au_wbr_create_init_mfs,
32649 + .fin = au_wbr_create_fin_mfs
32651 + [AuWbrCreate_PMFSV] = {
32652 + .create = au_wbr_create_pmfs,
32653 + .init = au_wbr_create_init_mfs,
32654 + .fin = au_wbr_create_fin_mfs
32656 + [AuWbrCreate_PMFSRR] = {
32657 + .create = au_wbr_create_pmfsrr,
32658 + .init = au_wbr_create_init_mfsrr,
32659 + .fin = au_wbr_create_fin_mfs
32661 + [AuWbrCreate_PMFSRRV] = {
32662 + .create = au_wbr_create_pmfsrr,
32663 + .init = au_wbr_create_init_mfsrr,
32664 + .fin = au_wbr_create_fin_mfs
32667 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32668 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32669 +++ linux/fs/aufs/whout.c 2017-07-29 12:14:25.906375514 +0200
32672 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32674 + * This program, aufs is free software; you can redistribute it and/or modify
32675 + * it under the terms of the GNU General Public License as published by
32676 + * the Free Software Foundation; either version 2 of the License, or
32677 + * (at your option) any later version.
32679 + * This program is distributed in the hope that it will be useful,
32680 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32681 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32682 + * GNU General Public License for more details.
32684 + * You should have received a copy of the GNU General Public License
32685 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32689 + * whiteout for logical deletion and opaque directory
32694 +#define WH_MASK S_IRUGO
32697 + * If a directory contains this file, then it is opaque. We start with the
32698 + * .wh. flag so that it is blocked by lookup.
32700 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32701 + sizeof(AUFS_WH_DIROPQ) - 1);
32704 + * generate whiteout name, which is NOT terminated by NULL.
32705 + * @name: original d_name.name
32706 + * @len: original d_name.len
32707 + * @wh: whiteout qstr
32708 + * returns zero when succeeds, otherwise error.
32709 + * succeeded value as wh->name should be freed by kfree().
32711 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32715 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32716 + return -ENAMETOOLONG;
32718 + wh->len = name->len + AUFS_WH_PFX_LEN;
32719 + p = kmalloc(wh->len, GFP_NOFS);
32722 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32723 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32730 +/* ---------------------------------------------------------------------- */
32733 + * test if the @wh_name exists under @h_parent.
32734 + * @try_sio specifies the necessary of super-io.
32736 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32739 + struct dentry *wh_dentry;
32742 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32744 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32745 + err = PTR_ERR(wh_dentry);
32746 + if (IS_ERR(wh_dentry)) {
32747 + if (err == -ENAMETOOLONG)
32753 + if (d_is_negative(wh_dentry))
32754 + goto out_wh; /* success */
32757 + if (d_is_reg(wh_dentry))
32758 + goto out_wh; /* success */
32761 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32762 + wh_dentry, d_inode(wh_dentry)->i_mode);
32771 + * test if the @h_dentry sets opaque or not.
32773 +int au_diropq_test(struct dentry *h_dentry)
32776 + struct inode *h_dir;
32778 + h_dir = d_inode(h_dentry);
32779 + err = au_wh_test(h_dentry, &diropq_name,
32780 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32785 + * returns a negative dentry whose name is unique and temporary.
32787 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32788 + struct qstr *prefix)
32790 + struct dentry *dentry;
32792 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32794 + /* strict atomic_t is unnecessary here */
32795 + static unsigned short cnt;
32798 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32801 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32802 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32803 + dentry = ERR_PTR(-ENAMETOOLONG);
32804 + if (unlikely(qs.len > NAME_MAX))
32806 + dentry = ERR_PTR(-ENOMEM);
32807 + name = kmalloc(qs.len + 1, GFP_NOFS);
32808 + if (unlikely(!name))
32812 + /* doubly whiteout-ed */
32813 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32814 + p = name + AUFS_WH_PFX_LEN * 2;
32815 + memcpy(p, prefix->name, prefix->len);
32816 + p += prefix->len;
32818 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32821 + for (i = 0; i < 3; i++) {
32822 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32823 + dentry = au_sio_lkup_one(&qs, h_parent);
32824 + if (IS_ERR(dentry) || d_is_negative(dentry))
32828 + /* pr_warn("could not get random name\n"); */
32829 + dentry = ERR_PTR(-EEXIST);
32830 + AuDbg("%.*s\n", AuLNPair(&qs));
32834 + if (name != defname)
32837 + AuTraceErrPtr(dentry);
32842 + * rename the @h_dentry on @br to the whiteouted temporary name.
32844 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32847 + struct path h_path = {
32848 + .mnt = au_br_mnt(br)
32850 + struct inode *h_dir, *delegated;
32851 + struct dentry *h_parent;
32853 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32854 + h_dir = d_inode(h_parent);
32855 + IMustLock(h_dir);
32857 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32858 + err = PTR_ERR(h_path.dentry);
32859 + if (IS_ERR(h_path.dentry))
32862 + /* under the same dir, no need to lock_rename() */
32863 + delegated = NULL;
32864 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
32867 + if (unlikely(err == -EWOULDBLOCK)) {
32868 + pr_warn("cannot retry for NFSv4 delegation"
32869 + " for an internal rename\n");
32872 + dput(h_path.dentry);
32879 +/* ---------------------------------------------------------------------- */
32881 + * functions for removing a whiteout
32884 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32887 + struct inode *delegated;
32890 + * forces superio when the dir has a sticky bit.
32891 + * this may be a violation of unix fs semantics.
32893 + force = (h_dir->i_mode & S_ISVTX)
32894 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32895 + delegated = NULL;
32896 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32897 + if (unlikely(err == -EWOULDBLOCK)) {
32898 + pr_warn("cannot retry for NFSv4 delegation"
32899 + " for an internal unlink\n");
32905 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32906 + struct dentry *dentry)
32910 + err = do_unlink_wh(h_dir, h_path);
32911 + if (!err && dentry)
32912 + au_set_dbwh(dentry, -1);
32917 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32918 + struct au_branch *br)
32921 + struct path h_path = {
32922 + .mnt = au_br_mnt(br)
32926 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32927 + if (IS_ERR(h_path.dentry))
32928 + err = PTR_ERR(h_path.dentry);
32930 + if (d_is_reg(h_path.dentry))
32931 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32932 + dput(h_path.dentry);
32938 +/* ---------------------------------------------------------------------- */
32940 + * initialize/clean whiteout for a branch
32943 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32947 + struct inode *delegated;
32949 + if (d_is_negative(whpath->dentry))
32953 + err = vfsub_rmdir(h_dir, whpath);
32955 + delegated = NULL;
32956 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32957 + if (unlikely(err == -EWOULDBLOCK)) {
32958 + pr_warn("cannot retry for NFSv4 delegation"
32959 + " for an internal unlink\n");
32963 + if (unlikely(err))
32964 + pr_warn("failed removing %pd (%d), ignored.\n",
32965 + whpath->dentry, err);
32968 +static int test_linkable(struct dentry *h_root)
32970 + struct inode *h_dir = d_inode(h_root);
32972 + if (h_dir->i_op->link)
32975 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32976 + h_root, au_sbtype(h_root->d_sb));
32980 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32981 +static int au_whdir(struct inode *h_dir, struct path *path)
32986 + if (d_is_negative(path->dentry)) {
32987 + int mode = S_IRWXU;
32989 + if (au_test_nfs(path->dentry->d_sb))
32991 + err = vfsub_mkdir(h_dir, path, mode);
32992 + } else if (d_is_dir(path->dentry))
32995 + pr_err("unknown %pd exists\n", path->dentry);
33000 +struct au_wh_base {
33001 + const struct qstr *name;
33002 + struct dentry *dentry;
33005 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
33006 + struct path *h_path)
33008 + h_path->dentry = base[AuBrWh_BASE].dentry;
33009 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33010 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33011 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33012 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33013 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33017 + * returns tri-state,
33018 + * minus: error, caller should print the message
33020 + * plus: error, caller should NOT print the message
33022 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
33023 + int do_plink, struct au_wh_base base[],
33024 + struct path *h_path)
33027 + struct inode *h_dir;
33029 + h_dir = d_inode(h_root);
33030 + h_path->dentry = base[AuBrWh_BASE].dentry;
33031 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33032 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33034 + err = test_linkable(h_root);
33035 + if (unlikely(err)) {
33040 + err = au_whdir(h_dir, h_path);
33041 + if (unlikely(err))
33043 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33045 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33046 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33047 + err = au_whdir(h_dir, h_path);
33048 + if (unlikely(err))
33050 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33057 + * for the moment, aufs supports the branch filesystem which does not support
33058 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
33059 + * copyup failed. finally, such filesystem will not be used as the writable
33062 + * returns tri-state, see above.
33064 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
33065 + int do_plink, struct au_wh_base base[],
33066 + struct path *h_path)
33069 + struct inode *h_dir;
33071 + WbrWhMustWriteLock(wbr);
33073 + err = test_linkable(h_root);
33074 + if (unlikely(err)) {
33080 + * todo: should this create be done in /sbin/mount.aufs helper?
33083 + h_dir = d_inode(h_root);
33084 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33085 + h_path->dentry = base[AuBrWh_BASE].dentry;
33086 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33087 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33090 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33091 + if (unlikely(err))
33094 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33096 + err = au_whdir(h_dir, h_path);
33097 + if (unlikely(err))
33099 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33101 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33102 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33104 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33105 + err = au_whdir(h_dir, h_path);
33106 + if (unlikely(err))
33108 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33115 + * initialize the whiteout base file/dir for @br.
33117 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33120 + const unsigned char do_plink
33121 + = !!au_opt_test(au_mntflags(sb), PLINK);
33122 + struct inode *h_dir;
33123 + struct path path = br->br_path;
33124 + struct dentry *h_root = path.dentry;
33125 + struct au_wbr *wbr = br->br_wbr;
33126 + static const struct qstr base_name[] = {
33127 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33128 + sizeof(AUFS_BASE_NAME) - 1),
33129 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33130 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33131 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33132 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33134 + struct au_wh_base base[] = {
33135 + [AuBrWh_BASE] = {
33136 + .name = base_name + AuBrWh_BASE,
33139 + [AuBrWh_PLINK] = {
33140 + .name = base_name + AuBrWh_PLINK,
33143 + [AuBrWh_ORPH] = {
33144 + .name = base_name + AuBrWh_ORPH,
33150 + WbrWhMustWriteLock(wbr);
33152 + for (i = 0; i < AuBrWh_Last; i++) {
33153 + /* doubly whiteouted */
33154 + struct dentry *d;
33156 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33157 + err = PTR_ERR(d);
33161 + base[i].dentry = d;
33163 + && wbr->wbr_wh[i]
33164 + && wbr->wbr_wh[i] != base[i].dentry);
33168 + for (i = 0; i < AuBrWh_Last; i++) {
33169 + dput(wbr->wbr_wh[i]);
33170 + wbr->wbr_wh[i] = NULL;
33174 + if (!au_br_writable(br->br_perm)) {
33175 + h_dir = d_inode(h_root);
33176 + au_wh_init_ro(h_dir, base, &path);
33177 + } else if (!au_br_wh_linkable(br->br_perm)) {
33178 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33184 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33190 + goto out; /* success */
33193 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33194 + err, h_root, au_sbtype(h_root->d_sb));
33196 + for (i = 0; i < AuBrWh_Last; i++)
33197 + dput(base[i].dentry);
33201 +/* ---------------------------------------------------------------------- */
33203 + * whiteouts are all hard-linked usually.
33204 + * when its link count reaches a ceiling, we create a new whiteout base
33205 + * asynchronously.
33208 +struct reinit_br_wh {
33209 + struct super_block *sb;
33210 + struct au_branch *br;
33213 +static void reinit_br_wh(void *arg)
33216 + aufs_bindex_t bindex;
33217 + struct path h_path;
33218 + struct reinit_br_wh *a = arg;
33219 + struct au_wbr *wbr;
33220 + struct inode *dir, *delegated;
33221 + struct dentry *h_root;
33222 + struct au_hinode *hdir;
33225 + wbr = a->br->br_wbr;
33226 + /* big aufs lock */
33227 + si_noflush_write_lock(a->sb);
33228 + if (!au_br_writable(a->br->br_perm))
33230 + bindex = au_br_index(a->sb, a->br->br_id);
33231 + if (unlikely(bindex < 0))
33234 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33235 + dir = d_inode(a->sb->s_root);
33236 + hdir = au_hi(dir, bindex);
33237 + h_root = au_h_dptr(a->sb->s_root, bindex);
33238 + AuDebugOn(h_root != au_br_dentry(a->br));
33240 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33241 + wbr_wh_write_lock(wbr);
33242 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33245 + h_path.dentry = wbr->wbr_whbase;
33246 + h_path.mnt = au_br_mnt(a->br);
33247 + delegated = NULL;
33248 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33250 + if (unlikely(err == -EWOULDBLOCK)) {
33251 + pr_warn("cannot retry for NFSv4 delegation"
33252 + " for an internal unlink\n");
33256 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33259 + dput(wbr->wbr_whbase);
33260 + wbr->wbr_whbase = NULL;
33262 + err = au_wh_init(a->br, a->sb);
33263 + wbr_wh_write_unlock(wbr);
33264 + au_hn_inode_unlock(hdir);
33265 + di_read_unlock(a->sb->s_root, AuLock_IR);
33267 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33271 + atomic_dec(&wbr->wbr_wh_running);
33272 + au_br_put(a->br);
33273 + si_write_unlock(a->sb);
33274 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33276 + if (unlikely(err))
33277 + AuIOErr("err %d\n", err);
33280 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33282 + int do_dec, wkq_err;
33283 + struct reinit_br_wh *arg;
33286 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33289 + /* ignore ENOMEM */
33290 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33293 + * dec(wh_running), kfree(arg) and dec(br_count)
33294 + * in reinit function
33299 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33300 + if (unlikely(wkq_err)) {
33301 + atomic_dec(&br->br_wbr->wbr_wh_running);
33310 + atomic_dec(&br->br_wbr->wbr_wh_running);
33313 +/* ---------------------------------------------------------------------- */
33316 + * create the whiteout @wh.
33318 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33319 + struct dentry *wh)
33322 + struct path h_path = {
33325 + struct au_branch *br;
33326 + struct au_wbr *wbr;
33327 + struct dentry *h_parent;
33328 + struct inode *h_dir, *delegated;
33330 + h_parent = wh->d_parent; /* dir inode is locked */
33331 + h_dir = d_inode(h_parent);
33332 + IMustLock(h_dir);
33334 + br = au_sbr(sb, bindex);
33335 + h_path.mnt = au_br_mnt(br);
33336 + wbr = br->br_wbr;
33337 + wbr_wh_read_lock(wbr);
33338 + if (wbr->wbr_whbase) {
33339 + delegated = NULL;
33340 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33341 + if (unlikely(err == -EWOULDBLOCK)) {
33342 + pr_warn("cannot retry for NFSv4 delegation"
33343 + " for an internal link\n");
33346 + if (!err || err != -EMLINK)
33349 + /* link count full. re-initialize br_whbase. */
33350 + kick_reinit_br_wh(sb, br);
33353 + /* return this error in this context */
33354 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33356 + au_fhsm_wrote(sb, bindex, /*force*/0);
33359 + wbr_wh_read_unlock(wbr);
33363 +/* ---------------------------------------------------------------------- */
33366 + * create or remove the diropq.
33368 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33369 + unsigned int flags)
33371 + struct dentry *opq_dentry, *h_dentry;
33372 + struct super_block *sb;
33373 + struct au_branch *br;
33376 + sb = dentry->d_sb;
33377 + br = au_sbr(sb, bindex);
33378 + h_dentry = au_h_dptr(dentry, bindex);
33379 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33380 + if (IS_ERR(opq_dentry))
33383 + if (au_ftest_diropq(flags, CREATE)) {
33384 + err = link_or_create_wh(sb, bindex, opq_dentry);
33386 + au_set_dbdiropq(dentry, bindex);
33387 + goto out; /* success */
33390 + struct path tmp = {
33391 + .dentry = opq_dentry,
33392 + .mnt = au_br_mnt(br)
33394 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33396 + au_set_dbdiropq(dentry, -1);
33398 + dput(opq_dentry);
33399 + opq_dentry = ERR_PTR(err);
33402 + return opq_dentry;
33405 +struct do_diropq_args {
33406 + struct dentry **errp;
33407 + struct dentry *dentry;
33408 + aufs_bindex_t bindex;
33409 + unsigned int flags;
33412 +static void call_do_diropq(void *args)
33414 + struct do_diropq_args *a = args;
33415 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33418 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33419 + unsigned int flags)
33421 + struct dentry *diropq, *h_dentry;
33423 + h_dentry = au_h_dptr(dentry, bindex);
33424 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33425 + diropq = do_diropq(dentry, bindex, flags);
33428 + struct do_diropq_args args = {
33430 + .dentry = dentry,
33431 + .bindex = bindex,
33435 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33436 + if (unlikely(wkq_err))
33437 + diropq = ERR_PTR(wkq_err);
33443 +/* ---------------------------------------------------------------------- */
33446 + * lookup whiteout dentry.
33447 + * @h_parent: lower parent dentry which must exist and be locked
33448 + * @base_name: name of dentry which will be whiteouted
33449 + * returns dentry for whiteout.
33451 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33452 + struct au_branch *br)
33455 + struct qstr wh_name;
33456 + struct dentry *wh_dentry;
33458 + err = au_wh_name_alloc(&wh_name, base_name);
33459 + wh_dentry = ERR_PTR(err);
33461 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33462 + kfree(wh_name.name);
33464 + return wh_dentry;
33468 + * link/create a whiteout for @dentry on @bindex.
33470 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33471 + struct dentry *h_parent)
33473 + struct dentry *wh_dentry;
33474 + struct super_block *sb;
33477 + sb = dentry->d_sb;
33478 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33479 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33480 + err = link_or_create_wh(sb, bindex, wh_dentry);
33482 + au_set_dbwh(dentry, bindex);
33483 + au_fhsm_wrote(sb, bindex, /*force*/0);
33486 + wh_dentry = ERR_PTR(err);
33490 + return wh_dentry;
33493 +/* ---------------------------------------------------------------------- */
33495 +/* Delete all whiteouts in this directory on branch bindex. */
33496 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33497 + aufs_bindex_t bindex, struct au_branch *br)
33500 + unsigned long ul, n;
33501 + struct qstr wh_name;
33503 + struct hlist_head *head;
33504 + struct au_vdir_wh *pos;
33505 + struct au_vdir_destr *str;
33508 + p = (void *)__get_free_page(GFP_NOFS);
33509 + wh_name.name = p;
33510 + if (unlikely(!wh_name.name))
33514 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33515 + p += AUFS_WH_PFX_LEN;
33516 + n = whlist->nh_num;
33517 + head = whlist->nh_head;
33518 + for (ul = 0; !err && ul < n; ul++, head++) {
33519 + hlist_for_each_entry(pos, head, wh_hash) {
33520 + if (pos->wh_bindex != bindex)
33523 + str = &pos->wh_str;
33524 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33525 + memcpy(p, str->name, str->len);
33526 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33527 + err = unlink_wh_name(h_dentry, &wh_name, br);
33532 + AuIOErr("whiteout name too long %.*s\n",
33533 + str->len, str->name);
33538 + free_page((unsigned long)wh_name.name);
33544 +struct del_wh_children_args {
33546 + struct dentry *h_dentry;
33547 + struct au_nhash *whlist;
33548 + aufs_bindex_t bindex;
33549 + struct au_branch *br;
33552 +static void call_del_wh_children(void *args)
33554 + struct del_wh_children_args *a = args;
33555 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33558 +/* ---------------------------------------------------------------------- */
33560 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33562 + struct au_whtmp_rmdir *whtmp;
33564 + unsigned int rdhash;
33566 + SiMustAnyLock(sb);
33568 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33569 + if (unlikely(!whtmp)) {
33570 + whtmp = ERR_PTR(-ENOMEM);
33574 + /* no estimation for dir size */
33575 + rdhash = au_sbi(sb)->si_rdhash;
33577 + rdhash = AUFS_RDHASH_DEF;
33578 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33579 + if (unlikely(err)) {
33581 + whtmp = ERR_PTR(err);
33588 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33591 + au_br_put(whtmp->br);
33592 + dput(whtmp->wh_dentry);
33593 + iput(whtmp->dir);
33594 + au_nhash_wh_free(&whtmp->whlist);
33599 + * rmdir the whiteouted temporary named dir @h_dentry.
33600 + * @whlist: whiteouted children.
33602 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33603 + struct dentry *wh_dentry, struct au_nhash *whlist)
33606 + unsigned int h_nlink;
33607 + struct path h_tmp;
33608 + struct inode *wh_inode, *h_dir;
33609 + struct au_branch *br;
33611 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33612 + IMustLock(h_dir);
33614 + br = au_sbr(dir->i_sb, bindex);
33615 + wh_inode = d_inode(wh_dentry);
33616 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33619 + * someone else might change some whiteouts while we were sleeping.
33620 + * it means this whlist may have an obsoleted entry.
33622 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33623 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33626 + struct del_wh_children_args args = {
33628 + .h_dentry = wh_dentry,
33629 + .whlist = whlist,
33630 + .bindex = bindex,
33634 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33635 + if (unlikely(wkq_err))
33638 + inode_unlock(wh_inode);
33641 + h_tmp.dentry = wh_dentry;
33642 + h_tmp.mnt = au_br_mnt(br);
33643 + h_nlink = h_dir->i_nlink;
33644 + err = vfsub_rmdir(h_dir, &h_tmp);
33645 + /* some fs doesn't change the parent nlink in some cases */
33646 + h_nlink -= h_dir->i_nlink;
33650 + if (au_ibtop(dir) == bindex) {
33651 + /* todo: dir->i_mutex is necessary */
33652 + au_cpup_attr_timesizes(dir);
33654 + vfsub_drop_nlink(dir);
33656 + return 0; /* success */
33659 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33663 +static void call_rmdir_whtmp(void *args)
33666 + aufs_bindex_t bindex;
33667 + struct au_whtmp_rmdir *a = args;
33668 + struct super_block *sb;
33669 + struct dentry *h_parent;
33670 + struct inode *h_dir;
33671 + struct au_hinode *hdir;
33673 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33674 + /* inode_lock(a->dir); */
33676 + sb = a->dir->i_sb;
33677 + si_read_lock(sb, !AuLock_FLUSH);
33678 + if (!au_br_writable(a->br->br_perm))
33680 + bindex = au_br_index(sb, a->br->br_id);
33681 + if (unlikely(bindex < 0))
33685 + ii_write_lock_parent(a->dir);
33686 + h_parent = dget_parent(a->wh_dentry);
33687 + h_dir = d_inode(h_parent);
33688 + hdir = au_hi(a->dir, bindex);
33689 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33690 + if (unlikely(err))
33692 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33693 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33696 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33697 + au_hn_inode_unlock(hdir);
33698 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33702 + ii_write_unlock(a->dir);
33704 + /* inode_unlock(a->dir); */
33705 + au_whtmp_rmdir_free(a);
33706 + si_read_unlock(sb);
33707 + au_nwt_done(&au_sbi(sb)->si_nowait);
33708 + if (unlikely(err))
33709 + AuIOErr("err %d\n", err);
33712 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33713 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33716 + struct super_block *sb;
33720 + /* all post-process will be done in do_rmdir_whtmp(). */
33722 + args->dir = au_igrab(dir);
33723 + args->br = au_sbr(sb, bindex);
33724 + au_br_get(args->br);
33725 + args->wh_dentry = dget(wh_dentry);
33726 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33727 + if (unlikely(wkq_err)) {
33728 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33729 + au_whtmp_rmdir_free(args);
33732 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33733 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33734 +++ linux/fs/aufs/whout.h 2017-07-29 12:14:25.906375514 +0200
33737 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33739 + * This program, aufs is free software; you can redistribute it and/or modify
33740 + * it under the terms of the GNU General Public License as published by
33741 + * the Free Software Foundation; either version 2 of the License, or
33742 + * (at your option) any later version.
33744 + * This program is distributed in the hope that it will be useful,
33745 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33746 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33747 + * GNU General Public License for more details.
33749 + * You should have received a copy of the GNU General Public License
33750 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33754 + * whiteout for logical deletion and opaque directory
33757 +#ifndef __AUFS_WHOUT_H__
33758 +#define __AUFS_WHOUT_H__
33765 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33766 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33767 +int au_diropq_test(struct dentry *h_dentry);
33768 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33769 + struct qstr *prefix);
33770 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33771 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33772 + struct dentry *dentry);
33773 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33775 +/* diropq flags */
33776 +#define AuDiropq_CREATE 1
33777 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33778 +#define au_fset_diropq(flags, name) \
33779 + do { (flags) |= AuDiropq_##name; } while (0)
33780 +#define au_fclr_diropq(flags, name) \
33781 + do { (flags) &= ~AuDiropq_##name; } while (0)
33783 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33784 + unsigned int flags);
33785 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33786 + struct au_branch *br);
33787 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33788 + struct dentry *h_parent);
33790 +/* real rmdir for the whiteout-ed dir */
33791 +struct au_whtmp_rmdir {
33792 + struct inode *dir;
33793 + struct au_branch *br;
33794 + struct dentry *wh_dentry;
33795 + struct au_nhash whlist;
33798 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33799 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33800 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33801 + struct dentry *wh_dentry, struct au_nhash *whlist);
33802 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33803 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33805 +/* ---------------------------------------------------------------------- */
33807 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33808 + aufs_bindex_t bindex)
33810 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33813 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33815 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33818 +#endif /* __KERNEL__ */
33819 +#endif /* __AUFS_WHOUT_H__ */
33820 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33821 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33822 +++ linux/fs/aufs/wkq.c 2017-07-29 12:14:25.906375514 +0200
33825 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33827 + * This program, aufs is free software; you can redistribute it and/or modify
33828 + * it under the terms of the GNU General Public License as published by
33829 + * the Free Software Foundation; either version 2 of the License, or
33830 + * (at your option) any later version.
33832 + * This program is distributed in the hope that it will be useful,
33833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33835 + * GNU General Public License for more details.
33837 + * You should have received a copy of the GNU General Public License
33838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33842 + * workqueue for asynchronous/super-io operations
33843 + * todo: try new dredential scheme
33846 +#include <linux/module.h>
33849 +/* internal workqueue named AUFS_WKQ_NAME */
33851 +static struct workqueue_struct *au_wkq;
33853 +struct au_wkinfo {
33854 + struct work_struct wk;
33855 + struct kobject *kobj;
33857 + unsigned int flags; /* see wkq.h */
33859 + au_wkq_func_t func;
33862 + struct completion *comp;
33865 +/* ---------------------------------------------------------------------- */
33867 +static void wkq_func(struct work_struct *wk)
33869 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33871 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33872 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33874 + wkinfo->func(wkinfo->args);
33875 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33876 + complete(wkinfo->comp);
33878 + kobject_put(wkinfo->kobj);
33879 + module_put(THIS_MODULE); /* todo: ?? */
33885 + * Since struct completion is large, try allocating it dynamically.
33887 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33888 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33890 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33892 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33894 + init_completion(*comp);
33895 + wkinfo->comp = *comp;
33901 +static void au_wkq_comp_free(struct completion *comp)
33909 +#define AuWkqCompDeclare(name) \
33910 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33911 + struct completion *comp = &_ ## name
33913 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33915 + wkinfo->comp = *comp;
33919 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33923 +#endif /* 4KSTACKS */
33925 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33927 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33928 + if (au_wkq_test()) {
33929 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33930 + " due to a dead dir by UDBA?\n");
33931 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33934 + au_dbg_verify_kthread();
33936 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33937 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33938 + queue_work(au_wkq, &wkinfo->wk);
33940 + INIT_WORK(&wkinfo->wk, wkq_func);
33941 + schedule_work(&wkinfo->wk);
33946 + * Be careful. It is easy to make deadlock happen.
33947 + * processA: lock, wkq and wait
33948 + * processB: wkq and wait, lock in wkq
33951 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33954 + AuWkqCompDeclare(comp);
33955 + struct au_wkinfo wkinfo = {
33961 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33963 + au_wkq_run(&wkinfo);
33964 + /* no timeout, no interrupt */
33965 + wait_for_completion(wkinfo.comp);
33966 + au_wkq_comp_free(comp);
33967 + destroy_work_on_stack(&wkinfo.wk);
33975 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33976 + * problem in a concurrent umounting.
33978 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33979 + unsigned int flags)
33982 + struct au_wkinfo *wkinfo;
33984 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33987 + * wkq_func() must free this wkinfo.
33988 + * it highly depends upon the implementation of workqueue.
33991 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33993 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33994 + wkinfo->flags = flags & ~AuWkq_WAIT;
33995 + wkinfo->func = func;
33996 + wkinfo->args = args;
33997 + wkinfo->comp = NULL;
33998 + kobject_get(wkinfo->kobj);
33999 + __module_get(THIS_MODULE); /* todo: ?? */
34001 + au_wkq_run(wkinfo);
34004 + au_nwt_done(&au_sbi(sb)->si_nowait);
34010 +/* ---------------------------------------------------------------------- */
34012 +void au_nwt_init(struct au_nowait_tasks *nwt)
34014 + atomic_set(&nwt->nw_len, 0);
34015 + /* smp_mb(); */ /* atomic_set */
34016 + init_waitqueue_head(&nwt->nw_wq);
34019 +void au_wkq_fin(void)
34021 + destroy_workqueue(au_wkq);
34024 +int __init au_wkq_init(void)
34029 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
34030 + if (IS_ERR(au_wkq))
34031 + err = PTR_ERR(au_wkq);
34032 + else if (!au_wkq)
34037 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
34038 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
34039 +++ linux/fs/aufs/wkq.h 2017-07-29 12:14:25.906375514 +0200
34042 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34044 + * This program, aufs is free software; you can redistribute it and/or modify
34045 + * it under the terms of the GNU General Public License as published by
34046 + * the Free Software Foundation; either version 2 of the License, or
34047 + * (at your option) any later version.
34049 + * This program is distributed in the hope that it will be useful,
34050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34052 + * GNU General Public License for more details.
34054 + * You should have received a copy of the GNU General Public License
34055 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34059 + * workqueue for asynchronous/super-io operations
34060 + * todo: try new credentials management scheme
34063 +#ifndef __AUFS_WKQ_H__
34064 +#define __AUFS_WKQ_H__
34068 +#include <linux/percpu_counter.h>
34070 +struct super_block;
34072 +/* ---------------------------------------------------------------------- */
34075 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34077 +struct au_nowait_tasks {
34079 + wait_queue_head_t nw_wq;
34082 +/* ---------------------------------------------------------------------- */
34084 +typedef void (*au_wkq_func_t)(void *args);
34087 +#define AuWkq_WAIT 1
34088 +#define AuWkq_NEST (1 << 1)
34089 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34090 +#define au_fset_wkq(flags, name) \
34091 + do { (flags) |= AuWkq_##name; } while (0)
34092 +#define au_fclr_wkq(flags, name) \
34093 + do { (flags) &= ~AuWkq_##name; } while (0)
34095 +#ifndef CONFIG_AUFS_HNOTIFY
34097 +#define AuWkq_NEST 0
34101 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34102 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34103 + unsigned int flags);
34104 +void au_nwt_init(struct au_nowait_tasks *nwt);
34105 +int __init au_wkq_init(void);
34106 +void au_wkq_fin(void);
34108 +/* ---------------------------------------------------------------------- */
34110 +static inline int au_wkq_test(void)
34112 + return current->flags & PF_WQ_WORKER;
34115 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34117 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34120 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34122 + if (atomic_dec_and_test(&nwt->nw_len))
34123 + wake_up_all(&nwt->nw_wq);
34126 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34128 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34132 +#endif /* __KERNEL__ */
34133 +#endif /* __AUFS_WKQ_H__ */
34134 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34135 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34136 +++ linux/fs/aufs/xattr.c 2017-07-29 12:14:25.906375514 +0200
34139 + * Copyright (C) 2014-2017 Junjiro R. Okajima
34141 + * This program, aufs is free software; you can redistribute it and/or modify
34142 + * it under the terms of the GNU General Public License as published by
34143 + * the Free Software Foundation; either version 2 of the License, or
34144 + * (at your option) any later version.
34146 + * This program is distributed in the hope that it will be useful,
34147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34149 + * GNU General Public License for more details.
34151 + * You should have received a copy of the GNU General Public License
34152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34156 + * handling xattr functions
34159 +#include <linux/fs.h>
34160 +#include <linux/posix_acl_xattr.h>
34161 +#include <linux/xattr.h>
34164 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34166 + if (!ignore_flags)
34174 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34179 +#define cmp(brattr, prefix) do { \
34180 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34181 + XATTR_##prefix##_PREFIX_LEN)) { \
34182 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34188 + cmp(SEC, SECURITY);
34189 + cmp(SYS, SYSTEM);
34190 + cmp(TR, TRUSTED);
34194 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34201 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34203 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34204 + char *name, char **buf, unsigned int ignore_flags,
34205 + unsigned int verbose)
34209 + struct inode *h_idst;
34211 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34213 + if (unlikely(err <= 0)) {
34214 + if (err == -ENODATA
34215 + || (err == -EOPNOTSUPP
34216 + && ((ignore_flags & au_xattr_out_of_list)
34217 + || (au_test_nfs_noacl(d_inode(h_src))
34218 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34220 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34223 + if (err && (verbose || au_debug_test()))
34224 + pr_err("%s, err %d\n", name, err);
34228 + /* unlock it temporary */
34229 + h_idst = d_inode(h_dst);
34230 + inode_unlock(h_idst);
34231 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34232 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34233 + if (unlikely(err)) {
34234 + if (verbose || au_debug_test())
34235 + pr_err("%s, err %d\n", name, err);
34236 + err = au_xattr_ignore(err, name, ignore_flags);
34243 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34244 + unsigned int verbose)
34246 + int err, unlocked, acl_access, acl_default;
34248 + struct inode *h_isrc, *h_idst;
34249 + char *value, *p, *o, *e;
34251 + /* try stopping to update the source inode while we are referencing */
34252 + /* there should not be the parent-child relationship between them */
34253 + h_isrc = d_inode(h_src);
34254 + h_idst = d_inode(h_dst);
34255 + inode_unlock(h_idst);
34256 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34257 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34260 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34261 + ssz = vfs_listxattr(h_src, NULL, 0);
34263 + if (unlikely(err < 0)) {
34265 + if (err == -ENODATA
34266 + || err == -EOPNOTSUPP)
34267 + err = 0; /* ignore */
34276 + p = kmalloc(ssz, GFP_NOFS);
34278 + if (unlikely(!p))
34280 + err = vfs_listxattr(h_src, p, ssz);
34282 + inode_unlock(h_isrc);
34284 + AuDbg("err %d, ssz %zd\n", err, ssz);
34285 + if (unlikely(err < 0))
34293 + while (!err && p < e) {
34294 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34295 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34296 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34297 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34299 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34301 + p += strlen(p) + 1;
34304 + ignore_flags |= au_xattr_out_of_list;
34305 + if (!err && !acl_access) {
34306 + err = au_do_cpup_xattr(h_dst, h_src,
34307 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34308 + ignore_flags, verbose);
34311 + if (!err && !acl_default) {
34312 + err = au_do_cpup_xattr(h_dst, h_src,
34313 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34314 + ignore_flags, verbose);
34326 + inode_unlock(h_isrc);
34331 +/* ---------------------------------------------------------------------- */
34333 +static int au_smack_reentering(struct super_block *sb)
34335 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
34337 + * as a part of lookup, smack_d_instantiate() is called, and it calls
34338 + * i_op->getxattr(). ouch.
34340 + return si_pid_test(sb);
34351 +struct au_lgxattr {
34359 + const char *name;
34366 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34370 + struct path h_path;
34371 + struct super_block *sb;
34373 + sb = dentry->d_sb;
34374 + reenter = au_smack_reentering(sb);
34376 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34377 + if (unlikely(err))
34380 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
34381 + if (unlikely(err))
34383 + if (unlikely(!h_path.dentry))
34384 + /* illegally overlapped or something */
34385 + goto out_di; /* pretending success */
34387 + /* always topmost entry only */
34388 + switch (arg->type) {
34389 + case AU_XATTR_LIST:
34390 + err = vfs_listxattr(h_path.dentry,
34391 + arg->u.list.list, arg->u.list.size);
34393 + case AU_XATTR_GET:
34394 + AuDebugOn(d_is_negative(h_path.dentry));
34395 + err = vfs_getxattr(h_path.dentry,
34396 + arg->u.get.name, arg->u.get.value,
34397 + arg->u.get.size);
34403 + di_read_unlock(dentry, AuLock_IR);
34406 + si_read_unlock(sb);
34412 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34414 + struct au_lgxattr arg = {
34415 + .type = AU_XATTR_LIST,
34422 + return au_lgxattr(dentry, &arg);
34425 +static ssize_t au_getxattr(struct dentry *dentry,
34426 + struct inode *inode __maybe_unused,
34427 + const char *name, void *value, size_t size)
34429 + struct au_lgxattr arg = {
34430 + .type = AU_XATTR_GET,
34438 + return au_lgxattr(dentry, &arg);
34441 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34442 + const char *name, const void *value, size_t size,
34445 + struct au_sxattr arg = {
34446 + .type = AU_XATTR_SET,
34455 + return au_sxattr(dentry, inode, &arg);
34458 +/* ---------------------------------------------------------------------- */
34460 +static int au_xattr_get(const struct xattr_handler *handler,
34461 + struct dentry *dentry, struct inode *inode,
34462 + const char *name, void *buffer, size_t size)
34464 + return au_getxattr(dentry, inode, name, buffer, size);
34467 +static int au_xattr_set(const struct xattr_handler *handler,
34468 + struct dentry *dentry, struct inode *inode,
34469 + const char *name, const void *value, size_t size,
34472 + return au_setxattr(dentry, inode, name, value, size, flags);
34475 +static const struct xattr_handler au_xattr_handler = {
34478 + .get = au_xattr_get,
34479 + .set = au_xattr_set
34482 +static const struct xattr_handler *au_xattr_handlers[] = {
34483 +#ifdef CONFIG_FS_POSIX_ACL
34484 + &posix_acl_access_xattr_handler,
34485 + &posix_acl_default_xattr_handler,
34487 + &au_xattr_handler, /* must be last */
34491 +void au_xattr_init(struct super_block *sb)
34493 + sb->s_xattr = au_xattr_handlers;
34495 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34496 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34497 +++ linux/fs/aufs/xino.c 2017-07-29 12:14:25.906375514 +0200
34500 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34502 + * This program, aufs is free software; you can redistribute it and/or modify
34503 + * it under the terms of the GNU General Public License as published by
34504 + * the Free Software Foundation; either version 2 of the License, or
34505 + * (at your option) any later version.
34507 + * This program is distributed in the hope that it will be useful,
34508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34510 + * GNU General Public License for more details.
34512 + * You should have received a copy of the GNU General Public License
34513 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34517 + * external inode number translation table and bitmap
34520 +#include <linux/seq_file.h>
34521 +#include <linux/statfs.h>
34524 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34525 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34529 + mm_segment_t oldfs;
34536 + oldfs = get_fs();
34537 + set_fs(KERNEL_DS);
34539 + /* todo: signal_pending? */
34540 + err = func(file, buf.u, size, pos);
34541 + } while (err == -EAGAIN || err == -EINTR);
34544 +#if 0 /* reserved for future use */
34546 + fsnotify_access(file->f_path.dentry);
34552 +/* ---------------------------------------------------------------------- */
34554 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34555 + size_t size, loff_t *pos);
34557 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34558 + size_t size, loff_t *pos)
34561 + mm_segment_t oldfs;
34564 + const char __user *u;
34567 + const int prevent_endless = 10;
34571 + oldfs = get_fs();
34572 + set_fs(KERNEL_DS);
34574 + err = func(file, buf.u, size, pos);
34575 + if (err == -EINTR
34576 + && !au_wkq_test()
34577 + && fatal_signal_pending(current)) {
34579 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34580 + BUG_ON(err == -EINTR);
34581 + oldfs = get_fs();
34582 + set_fs(KERNEL_DS);
34584 + } while (i++ < prevent_endless
34585 + && (err == -EAGAIN || err == -EINTR));
34588 +#if 0 /* reserved for future use */
34590 + fsnotify_modify(file->f_path.dentry);
34596 +struct do_xino_fwrite_args {
34598 + vfs_writef_t func;
34599 + struct file *file;
34605 +static void call_do_xino_fwrite(void *args)
34607 + struct do_xino_fwrite_args *a = args;
34608 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34611 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34612 + size_t size, loff_t *pos)
34616 + struct do_xino_fwrite_args args = {
34626 + * it breaks RLIMIT_FSIZE and normal user's limit,
34627 + * users should care about quota and real 'filesystem full.'
34629 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34630 + if (unlikely(wkq_err))
34636 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34637 + size_t size, loff_t *pos)
34641 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34643 + err = do_xino_fwrite(func, file, buf, size, pos);
34646 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34651 +/* ---------------------------------------------------------------------- */
34654 + * create a new xinofile at the same place/path as @base_file.
34656 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34658 + struct file *file;
34659 + struct dentry *base, *parent;
34660 + struct inode *dir, *delegated;
34661 + struct qstr *name;
34662 + struct path path;
34665 + base = base_file->f_path.dentry;
34666 + parent = base->d_parent; /* dir inode is locked */
34667 + dir = d_inode(parent);
34670 + file = ERR_PTR(-EINVAL);
34671 + name = &base->d_name;
34672 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34673 + if (IS_ERR(path.dentry)) {
34674 + file = (void *)path.dentry;
34675 + pr_err("%pd lookup err %ld\n",
34676 + base, PTR_ERR(path.dentry));
34680 + /* no need to mnt_want_write() since we call dentry_open() later */
34681 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34682 + if (unlikely(err)) {
34683 + file = ERR_PTR(err);
34684 + pr_err("%pd create err %d\n", base, err);
34688 + path.mnt = base_file->f_path.mnt;
34689 + file = vfsub_dentry_open(&path,
34690 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34691 + /* | __FMODE_NONOTIFY */);
34692 + if (IS_ERR(file)) {
34693 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34697 + delegated = NULL;
34698 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34699 + if (unlikely(err == -EWOULDBLOCK)) {
34700 + pr_warn("cannot retry for NFSv4 delegation"
34701 + " for an internal unlink\n");
34704 + if (unlikely(err)) {
34705 + pr_err("%pd unlink err %d\n", base, err);
34710 + /* no one can touch copy_src xino */
34711 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34712 + if (unlikely(err)) {
34713 + pr_err("%pd copy err %d\n", base, err);
34717 + goto out_dput; /* success */
34721 + file = ERR_PTR(err);
34723 + dput(path.dentry);
34728 +struct au_xino_lock_dir {
34729 + struct au_hinode *hdir;
34730 + struct dentry *parent;
34731 + struct inode *dir;
34734 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34735 + struct au_xino_lock_dir *ldir)
34737 + aufs_bindex_t brid, bindex;
34739 + ldir->hdir = NULL;
34741 + brid = au_xino_brid(sb);
34743 + bindex = au_br_index(sb, brid);
34744 + if (bindex >= 0) {
34745 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34746 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34748 + ldir->parent = dget_parent(xino->f_path.dentry);
34749 + ldir->dir = d_inode(ldir->parent);
34750 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34754 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34757 + au_hn_inode_unlock(ldir->hdir);
34759 + inode_unlock(ldir->dir);
34760 + dput(ldir->parent);
34764 +/* ---------------------------------------------------------------------- */
34766 +/* trucate xino files asynchronously */
34768 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34771 + unsigned long jiffy;
34773 + aufs_bindex_t bi, bbot;
34774 + struct kstatfs *st;
34775 + struct au_branch *br;
34776 + struct file *new_xino, *file;
34777 + struct super_block *h_sb;
34778 + struct au_xino_lock_dir ldir;
34781 + st = kmalloc(sizeof(*st), GFP_NOFS);
34782 + if (unlikely(!st))
34786 + bbot = au_sbbot(sb);
34787 + if (unlikely(bindex < 0 || bbot < bindex))
34789 + br = au_sbr(sb, bindex);
34790 + file = br->br_xino.xi_file;
34794 + err = vfs_statfs(&file->f_path, st);
34795 + if (unlikely(err))
34796 + AuErr1("statfs err %d, ignored\n", err);
34798 + blocks = file_inode(file)->i_blocks;
34799 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34800 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34802 + au_xino_lock_dir(sb, file, &ldir);
34803 + /* mnt_want_write() is unnecessary here */
34804 + new_xino = au_xino_create2(file, file);
34805 + au_xino_unlock_dir(&ldir);
34806 + err = PTR_ERR(new_xino);
34807 + if (IS_ERR(new_xino)) {
34808 + pr_err("err %d, ignored\n", err);
34813 + br->br_xino.xi_file = new_xino;
34815 + h_sb = au_br_sb(br);
34816 + for (bi = 0; bi <= bbot; bi++) {
34817 + if (unlikely(bi == bindex))
34819 + br = au_sbr(sb, bi);
34820 + if (au_br_sb(br) != h_sb)
34823 + fput(br->br_xino.xi_file);
34824 + br->br_xino.xi_file = new_xino;
34825 + get_file(new_xino);
34828 + err = vfs_statfs(&new_xino->f_path, st);
34830 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34831 + bindex, (u64)file_inode(new_xino)->i_blocks,
34832 + st->f_bfree, st->f_blocks);
34833 + if (file_inode(new_xino)->i_blocks < blocks)
34834 + au_sbi(sb)->si_xino_jiffy = jiffy;
34836 + AuErr1("statfs err %d, ignored\n", err);
34844 +struct xino_do_trunc_args {
34845 + struct super_block *sb;
34846 + struct au_branch *br;
34849 +static void xino_do_trunc(void *_args)
34851 + struct xino_do_trunc_args *args = _args;
34852 + struct super_block *sb;
34853 + struct au_branch *br;
34854 + struct inode *dir;
34856 + aufs_bindex_t bindex;
34860 + dir = d_inode(sb->s_root);
34863 + si_noflush_write_lock(sb);
34864 + ii_read_lock_parent(dir);
34865 + bindex = au_br_index(sb, br->br_id);
34866 + err = au_xino_trunc(sb, bindex);
34867 + ii_read_unlock(dir);
34868 + if (unlikely(err))
34869 + pr_warn("err b%d, (%d)\n", bindex, err);
34870 + atomic_dec(&br->br_xino_running);
34872 + si_write_unlock(sb);
34873 + au_nwt_done(&au_sbi(sb)->si_nowait);
34877 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34880 + struct kstatfs st;
34881 + struct au_sbinfo *sbinfo;
34883 + /* todo: si_xino_expire and the ratio should be customizable */
34884 + sbinfo = au_sbi(sb);
34885 + if (time_before(jiffies,
34886 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34889 + /* truncation border */
34890 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34891 + if (unlikely(err)) {
34892 + AuErr1("statfs err %d, ignored\n", err);
34895 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34901 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34903 + struct xino_do_trunc_args *args;
34906 + if (!xino_trunc_test(sb, br))
34909 + if (atomic_inc_return(&br->br_xino_running) > 1)
34912 + /* lock and kfree() will be called in trunc_xino() */
34913 + args = kmalloc(sizeof(*args), GFP_NOFS);
34914 + if (unlikely(!args)) {
34915 + AuErr1("no memory\n");
34922 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34924 + return; /* success */
34926 + pr_err("wkq %d\n", wkq_err);
34931 + atomic_dec(&br->br_xino_running);
34934 +/* ---------------------------------------------------------------------- */
34936 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34937 + ino_t h_ino, ino_t ino)
34943 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34944 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34947 + pos *= sizeof(ino);
34948 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34949 + if (sz == sizeof(ino))
34950 + return 0; /* success */
34952 + AuIOErr("write failed (%zd)\n", sz);
34957 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34958 + * at the position of @h_ino.
34959 + * even if @ino is zero, it is written to the xinofile and means no entry.
34960 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34961 + * try truncating it.
34963 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34967 + unsigned int mnt_flags;
34968 + struct au_branch *br;
34970 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34971 + || ((loff_t)-1) > 0);
34972 + SiMustAnyLock(sb);
34974 + mnt_flags = au_mntflags(sb);
34975 + if (!au_opt_test(mnt_flags, XINO))
34978 + br = au_sbr(sb, bindex);
34979 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34982 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34983 + && au_test_fs_trunc_xino(au_br_sb(br)))
34984 + xino_try_trunc(sb, br);
34985 + return 0; /* success */
34988 + AuIOErr("write failed (%d)\n", err);
34992 +/* ---------------------------------------------------------------------- */
34994 +/* aufs inode number bitmap */
34996 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34997 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
35001 + AuDebugOn(bit < 0 || page_bits <= bit);
35002 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
35006 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
35008 + AuDebugOn(ino < AUFS_FIRST_INO);
35009 + ino -= AUFS_FIRST_INO;
35010 + *pindex = ino / page_bits;
35011 + *bit = ino % page_bits;
35014 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
35019 + struct au_sbinfo *sbinfo;
35020 + struct file *xib;
35021 + unsigned long *p;
35023 + sbinfo = au_sbi(sb);
35024 + MtxMustLock(&sbinfo->si_xib_mtx);
35025 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
35026 + || !au_opt_test(sbinfo->si_mntflags, XINO));
35028 + if (pindex == sbinfo->si_xib_last_pindex)
35031 + xib = sbinfo->si_xib;
35032 + p = sbinfo->si_xib_buf;
35033 + pos = sbinfo->si_xib_last_pindex;
35034 + pos *= PAGE_SIZE;
35035 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35036 + if (unlikely(sz != PAGE_SIZE))
35040 + pos *= PAGE_SIZE;
35041 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
35042 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
35044 + memset(p, 0, PAGE_SIZE);
35045 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35047 + if (sz == PAGE_SIZE) {
35048 + sbinfo->si_xib_last_pindex = pindex;
35049 + return 0; /* success */
35053 + AuIOErr1("write failed (%zd)\n", sz);
35060 +/* ---------------------------------------------------------------------- */
35062 +static void au_xib_clear_bit(struct inode *inode)
35065 + unsigned long pindex;
35066 + struct super_block *sb;
35067 + struct au_sbinfo *sbinfo;
35069 + AuDebugOn(inode->i_nlink);
35071 + sb = inode->i_sb;
35072 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35073 + AuDebugOn(page_bits <= bit);
35074 + sbinfo = au_sbi(sb);
35075 + mutex_lock(&sbinfo->si_xib_mtx);
35076 + err = xib_pindex(sb, pindex);
35078 + clear_bit(bit, sbinfo->si_xib_buf);
35079 + sbinfo->si_xib_next_bit = bit;
35081 + mutex_unlock(&sbinfo->si_xib_mtx);
35084 +/* for s_op->delete_inode() */
35085 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35088 + unsigned int mnt_flags;
35089 + aufs_bindex_t bindex, bbot, bi;
35090 + unsigned char try_trunc;
35091 + struct au_iinfo *iinfo;
35092 + struct super_block *sb;
35093 + struct au_hinode *hi;
35094 + struct inode *h_inode;
35095 + struct au_branch *br;
35096 + vfs_writef_t xwrite;
35098 + AuDebugOn(au_is_bad_inode(inode));
35100 + sb = inode->i_sb;
35101 + mnt_flags = au_mntflags(sb);
35102 + if (!au_opt_test(mnt_flags, XINO)
35103 + || inode->i_ino == AUFS_ROOT_INO)
35107 + au_xigen_inc(inode);
35108 + au_xib_clear_bit(inode);
35111 + iinfo = au_ii(inode);
35112 + bindex = iinfo->ii_btop;
35116 + xwrite = au_sbi(sb)->si_xwrite;
35117 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35118 + hi = au_hinode(iinfo, bindex);
35119 + bbot = iinfo->ii_bbot;
35120 + for (; bindex <= bbot; bindex++, hi++) {
35121 + h_inode = hi->hi_inode;
35123 + || (!unlinked && h_inode->i_nlink))
35126 + /* inode may not be revalidated */
35127 + bi = au_br_index(sb, hi->hi_id);
35131 + br = au_sbr(sb, bi);
35132 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35133 + h_inode->i_ino, /*ino*/0);
35134 + if (!err && try_trunc
35135 + && au_test_fs_trunc_xino(au_br_sb(br)))
35136 + xino_try_trunc(sb, br);
35140 +/* get an unused inode number from bitmap */
35141 +ino_t au_xino_new_ino(struct super_block *sb)
35144 + unsigned long *p, pindex, ul, pend;
35145 + struct au_sbinfo *sbinfo;
35146 + struct file *file;
35147 + int free_bit, err;
35149 + if (!au_opt_test(au_mntflags(sb), XINO))
35150 + return iunique(sb, AUFS_FIRST_INO);
35152 + sbinfo = au_sbi(sb);
35153 + mutex_lock(&sbinfo->si_xib_mtx);
35154 + p = sbinfo->si_xib_buf;
35155 + free_bit = sbinfo->si_xib_next_bit;
35156 + if (free_bit < page_bits && !test_bit(free_bit, p))
35157 + goto out; /* success */
35158 + free_bit = find_first_zero_bit(p, page_bits);
35159 + if (free_bit < page_bits)
35160 + goto out; /* success */
35162 + pindex = sbinfo->si_xib_last_pindex;
35163 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35164 + err = xib_pindex(sb, ul);
35165 + if (unlikely(err))
35167 + free_bit = find_first_zero_bit(p, page_bits);
35168 + if (free_bit < page_bits)
35169 + goto out; /* success */
35172 + file = sbinfo->si_xib;
35173 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35174 + for (ul = pindex + 1; ul <= pend; ul++) {
35175 + err = xib_pindex(sb, ul);
35176 + if (unlikely(err))
35178 + free_bit = find_first_zero_bit(p, page_bits);
35179 + if (free_bit < page_bits)
35180 + goto out; /* success */
35185 + set_bit(free_bit, p);
35186 + sbinfo->si_xib_next_bit = free_bit + 1;
35187 + pindex = sbinfo->si_xib_last_pindex;
35188 + mutex_unlock(&sbinfo->si_xib_mtx);
35189 + ino = xib_calc_ino(pindex, free_bit);
35190 + AuDbg("i%lu\n", (unsigned long)ino);
35193 + mutex_unlock(&sbinfo->si_xib_mtx);
35199 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35200 + * at the position of @h_ino.
35201 + * if @ino does not exist and @do_new is true, get new one.
35203 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35209 + struct file *file;
35210 + struct au_sbinfo *sbinfo;
35213 + if (!au_opt_test(au_mntflags(sb), XINO))
35214 + return 0; /* no xino */
35217 + sbinfo = au_sbi(sb);
35219 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35220 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35223 + pos *= sizeof(*ino);
35225 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35226 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35227 + return 0; /* no ino */
35229 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35230 + if (sz == sizeof(*ino))
35231 + return 0; /* success */
35234 + if (unlikely(sz >= 0)) {
35236 + AuIOErr("xino read error (%zd)\n", sz);
35242 +/* ---------------------------------------------------------------------- */
35244 +/* create and set a new xino file */
35246 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35248 + struct file *file;
35249 + struct dentry *h_parent, *d;
35250 + struct inode *h_dir, *inode;
35254 + * at mount-time, and the xino file is the default path,
35255 + * hnotify is disabled so we have no notify events to ignore.
35256 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35258 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35259 + /* | __FMODE_NONOTIFY */,
35260 + S_IRUGO | S_IWUGO);
35261 + if (IS_ERR(file)) {
35263 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35267 + /* keep file count */
35269 + inode = file_inode(file);
35270 + h_parent = dget_parent(file->f_path.dentry);
35271 + h_dir = d_inode(h_parent);
35272 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35273 + /* mnt_want_write() is unnecessary here */
35274 + /* no delegation since it is just created */
35275 + if (inode->i_nlink)
35276 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35278 + inode_unlock(h_dir);
35280 + if (unlikely(err)) {
35282 + pr_err("unlink %s(%d)\n", fname, err);
35287 + d = file->f_path.dentry;
35288 + if (unlikely(sb == d->d_sb)) {
35290 + pr_err("%s must be outside\n", fname);
35293 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35295 + pr_err("xino doesn't support %s(%s)\n",
35296 + fname, au_sbtype(d->d_sb));
35299 + return file; /* success */
35303 + file = ERR_PTR(err);
35308 + * find another branch who is on the same filesystem of the specified
35309 + * branch{@btgt}. search until @bbot.
35311 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35312 + aufs_bindex_t bbot)
35314 + aufs_bindex_t bindex;
35315 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35317 + for (bindex = 0; bindex < btgt; bindex++)
35318 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35320 + for (bindex++; bindex <= bbot; bindex++)
35321 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35326 +/* ---------------------------------------------------------------------- */
35329 + * initialize the xinofile for the specified branch @br
35330 + * at the place/path where @base_file indicates.
35331 + * test whether another branch is on the same filesystem or not,
35332 + * if @do_test is true.
35334 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35335 + struct file *base_file, int do_test)
35339 + aufs_bindex_t bbot, bindex;
35340 + struct au_branch *shared_br, *b;
35341 + struct file *file;
35342 + struct super_block *tgt_sb;
35344 + shared_br = NULL;
35345 + bbot = au_sbbot(sb);
35347 + tgt_sb = au_br_sb(br);
35348 + for (bindex = 0; bindex <= bbot; bindex++) {
35349 + b = au_sbr(sb, bindex);
35350 + if (tgt_sb == au_br_sb(b)) {
35357 + if (!shared_br || !shared_br->br_xino.xi_file) {
35358 + struct au_xino_lock_dir ldir;
35360 + au_xino_lock_dir(sb, base_file, &ldir);
35361 + /* mnt_want_write() is unnecessary here */
35362 + file = au_xino_create2(base_file, NULL);
35363 + au_xino_unlock_dir(&ldir);
35364 + err = PTR_ERR(file);
35365 + if (IS_ERR(file))
35367 + br->br_xino.xi_file = file;
35369 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35370 + get_file(br->br_xino.xi_file);
35373 + ino = AUFS_ROOT_INO;
35374 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35376 + if (unlikely(err)) {
35377 + fput(br->br_xino.xi_file);
35378 + br->br_xino.xi_file = NULL;
35385 +/* ---------------------------------------------------------------------- */
35387 +/* trucate a xino bitmap file */
35390 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35394 + unsigned long pindex;
35395 + loff_t pos, pend;
35396 + struct au_sbinfo *sbinfo;
35397 + vfs_readf_t func;
35399 + unsigned long *p;
35402 + sbinfo = au_sbi(sb);
35403 + MtxMustLock(&sbinfo->si_xib_mtx);
35404 + p = sbinfo->si_xib_buf;
35405 + func = sbinfo->si_xread;
35406 + pend = vfsub_f_size_read(file);
35408 + while (pos < pend) {
35409 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35411 + if (unlikely(sz <= 0))
35415 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35416 + if (unlikely(*ino < AUFS_FIRST_INO))
35419 + xib_calc_bit(*ino, &pindex, &bit);
35420 + AuDebugOn(page_bits <= bit);
35421 + err = xib_pindex(sb, pindex);
35433 +static int xib_restore(struct super_block *sb)
35436 + aufs_bindex_t bindex, bbot;
35440 + page = (void *)__get_free_page(GFP_NOFS);
35441 + if (unlikely(!page))
35445 + bbot = au_sbbot(sb);
35446 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35447 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35448 + err = do_xib_restore
35449 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35451 + AuDbg("b%d\n", bindex);
35452 + free_page((unsigned long)page);
35458 +int au_xib_trunc(struct super_block *sb)
35463 + struct au_xino_lock_dir ldir;
35464 + struct au_sbinfo *sbinfo;
35465 + unsigned long *p;
35466 + struct file *file;
35468 + SiMustWriteLock(sb);
35471 + sbinfo = au_sbi(sb);
35472 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35475 + file = sbinfo->si_xib;
35476 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35479 + au_xino_lock_dir(sb, file, &ldir);
35480 + /* mnt_want_write() is unnecessary here */
35481 + file = au_xino_create2(sbinfo->si_xib, NULL);
35482 + au_xino_unlock_dir(&ldir);
35483 + err = PTR_ERR(file);
35484 + if (IS_ERR(file))
35486 + fput(sbinfo->si_xib);
35487 + sbinfo->si_xib = file;
35489 + p = sbinfo->si_xib_buf;
35490 + memset(p, 0, PAGE_SIZE);
35492 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35493 + if (unlikely(sz != PAGE_SIZE)) {
35495 + AuIOErr("err %d\n", err);
35501 + mutex_lock(&sbinfo->si_xib_mtx);
35502 + /* mnt_want_write() is unnecessary here */
35503 + err = xib_restore(sb);
35504 + mutex_unlock(&sbinfo->si_xib_mtx);
35510 +/* ---------------------------------------------------------------------- */
35513 + * xino mount option handlers
35517 +static void xino_clear_xib(struct super_block *sb)
35519 + struct au_sbinfo *sbinfo;
35521 + SiMustWriteLock(sb);
35523 + sbinfo = au_sbi(sb);
35524 + sbinfo->si_xread = NULL;
35525 + sbinfo->si_xwrite = NULL;
35526 + if (sbinfo->si_xib)
35527 + fput(sbinfo->si_xib);
35528 + sbinfo->si_xib = NULL;
35529 + if (sbinfo->si_xib_buf)
35530 + free_page((unsigned long)sbinfo->si_xib_buf);
35531 + sbinfo->si_xib_buf = NULL;
35534 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35538 + struct au_sbinfo *sbinfo;
35539 + struct file *file;
35541 + SiMustWriteLock(sb);
35543 + sbinfo = au_sbi(sb);
35544 + file = au_xino_create2(base, sbinfo->si_xib);
35545 + err = PTR_ERR(file);
35546 + if (IS_ERR(file))
35548 + if (sbinfo->si_xib)
35549 + fput(sbinfo->si_xib);
35550 + sbinfo->si_xib = file;
35551 + sbinfo->si_xread = vfs_readf(file);
35552 + sbinfo->si_xwrite = vfs_writef(file);
35555 + if (!sbinfo->si_xib_buf)
35556 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35557 + if (unlikely(!sbinfo->si_xib_buf))
35560 + sbinfo->si_xib_last_pindex = 0;
35561 + sbinfo->si_xib_next_bit = 0;
35562 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35564 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35565 + PAGE_SIZE, &pos);
35566 + if (unlikely(err != PAGE_SIZE))
35570 + goto out; /* success */
35573 + if (sbinfo->si_xib_buf)
35574 + free_page((unsigned long)sbinfo->si_xib_buf);
35575 + sbinfo->si_xib_buf = NULL;
35579 + fput(sbinfo->si_xib);
35580 + sbinfo->si_xib = NULL;
35581 + sbinfo->si_xread = NULL;
35582 + sbinfo->si_xwrite = NULL;
35587 +/* xino for each branch */
35588 +static void xino_clear_br(struct super_block *sb)
35590 + aufs_bindex_t bindex, bbot;
35591 + struct au_branch *br;
35593 + bbot = au_sbbot(sb);
35594 + for (bindex = 0; bindex <= bbot; bindex++) {
35595 + br = au_sbr(sb, bindex);
35596 + if (!br || !br->br_xino.xi_file)
35599 + fput(br->br_xino.xi_file);
35600 + br->br_xino.xi_file = NULL;
35604 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35608 + aufs_bindex_t bindex, bbot, bshared;
35610 + struct file *old, *new;
35612 + struct au_branch *br;
35613 + struct inode *inode;
35614 + vfs_writef_t writef;
35616 + SiMustWriteLock(sb);
35619 + bbot = au_sbbot(sb);
35620 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35621 + if (unlikely(!fpair))
35624 + inode = d_inode(sb->s_root);
35625 + ino = AUFS_ROOT_INO;
35626 + writef = au_sbi(sb)->si_xwrite;
35627 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35628 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35629 + if (bshared >= 0) {
35630 + /* shared xino */
35631 + *p = fpair[bshared];
35632 + get_file(p->new);
35637 + br = au_sbr(sb, bindex);
35638 + p->old = br->br_xino.xi_file;
35639 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35640 + err = PTR_ERR(p->new);
35641 + if (IS_ERR(p->new)) {
35647 + err = au_xino_do_write(writef, p->new,
35648 + au_h_iptr(inode, bindex)->i_ino, ino);
35649 + if (unlikely(err))
35653 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35654 + br = au_sbr(sb, bindex);
35655 + if (br->br_xino.xi_file)
35656 + fput(br->br_xino.xi_file);
35657 + get_file(p->new);
35658 + br->br_xino.xi_file = p->new;
35662 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35672 +void au_xino_clr(struct super_block *sb)
35674 + struct au_sbinfo *sbinfo;
35676 + au_xigen_clr(sb);
35677 + xino_clear_xib(sb);
35678 + xino_clear_br(sb);
35679 + sbinfo = au_sbi(sb);
35680 + /* lvalue, do not call au_mntflags() */
35681 + au_opt_clr(sbinfo->si_mntflags, XINO);
35684 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35687 + struct dentry *parent, *cur_parent;
35688 + struct qstr *dname, *cur_name;
35689 + struct file *cur_xino;
35690 + struct inode *dir;
35691 + struct au_sbinfo *sbinfo;
35693 + SiMustWriteLock(sb);
35696 + sbinfo = au_sbi(sb);
35697 + parent = dget_parent(xino->file->f_path.dentry);
35700 + dname = &xino->file->f_path.dentry->d_name;
35701 + cur_xino = sbinfo->si_xib;
35703 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35704 + cur_name = &cur_xino->f_path.dentry->d_name;
35705 + skip = (cur_parent == parent
35706 + && au_qstreq(dname, cur_name));
35707 + dput(cur_parent);
35713 + au_opt_set(sbinfo->si_mntflags, XINO);
35714 + dir = d_inode(parent);
35715 + inode_lock_nested(dir, AuLsc_I_PARENT);
35716 + /* mnt_want_write() is unnecessary here */
35717 + err = au_xino_set_xib(sb, xino->file);
35719 + err = au_xigen_set(sb, xino->file);
35721 + err = au_xino_set_br(sb, xino->file);
35722 + inode_unlock(dir);
35724 + goto out; /* success */
35727 + AuIOErr("failed creating xino(%d).\n", err);
35728 + au_xigen_clr(sb);
35729 + xino_clear_xib(sb);
35736 +/* ---------------------------------------------------------------------- */
35739 + * create a xinofile at the default place/path.
35741 +struct file *au_xino_def(struct super_block *sb)
35743 + struct file *file;
35745 + struct au_branch *br;
35746 + struct super_block *h_sb;
35747 + struct path path;
35748 + aufs_bindex_t bbot, bindex, bwr;
35751 + bbot = au_sbbot(sb);
35753 + for (bindex = 0; bindex <= bbot; bindex++) {
35754 + br = au_sbr(sb, bindex);
35755 + if (au_br_writable(br->br_perm)
35756 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35763 + file = ERR_PTR(-ENOMEM);
35764 + page = (void *)__get_free_page(GFP_NOFS);
35765 + if (unlikely(!page))
35767 + path.mnt = au_br_mnt(br);
35768 + path.dentry = au_h_dptr(sb->s_root, bwr);
35769 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35770 + file = (void *)p;
35771 + if (!IS_ERR(p)) {
35772 + strcat(p, "/" AUFS_XINO_FNAME);
35773 + AuDbg("%s\n", p);
35774 + file = au_xino_create(sb, p, /*silent*/0);
35775 + if (!IS_ERR(file))
35776 + au_xino_brid_set(sb, br->br_id);
35778 + free_page((unsigned long)page);
35780 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35781 + if (IS_ERR(file))
35783 + h_sb = file->f_path.dentry->d_sb;
35784 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35785 + pr_err("xino doesn't support %s(%s)\n",
35786 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35788 + file = ERR_PTR(-EINVAL);
35790 + if (!IS_ERR(file))
35791 + au_xino_brid_set(sb, -1);
35798 +/* ---------------------------------------------------------------------- */
35800 +int au_xino_path(struct seq_file *seq, struct file *file)
35804 + err = au_seq_path(seq, &file->f_path);
35805 + if (unlikely(err))
35808 +#define Deleted "\\040(deleted)"
35809 + seq->count -= sizeof(Deleted) - 1;
35810 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35811 + sizeof(Deleted) - 1));
35818 +/* ---------------------------------------------------------------------- */
35820 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
35821 + ino_t h_ino, int idx)
35823 + struct au_xino_file *xino;
35825 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
35826 + xino = &au_sbr(sb, bindex)->br_xino;
35827 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
35829 + spin_lock(&xino->xi_nondir.spin);
35830 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
35831 + xino->xi_nondir.array[idx] = 0;
35832 + spin_unlock(&xino->xi_nondir.spin);
35833 + wake_up_all(&xino->xi_nondir.wqh);
35836 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
35838 + int found, total, i;
35841 + total = xino->xi_nondir.total;
35842 + for (i = 0; i < total; i++) {
35843 + if (xino->xi_nondir.array[i] != h_ino)
35852 +static int au_xinondir_expand(struct au_xino_file *xino)
35857 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
35860 + sz = xino->xi_nondir.total * sizeof(ino_t);
35861 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
35863 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
35864 + /*may_shrink*/0);
35866 + xino->xi_nondir.array = p;
35867 + xino->xi_nondir.total <<= 1;
35868 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
35876 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35879 + int err, found, empty;
35880 + struct au_xino_file *xino;
35884 + if (!au_opt_test(au_mntflags(sb), XINO))
35885 + goto out; /* no xino */
35887 + xino = &au_sbr(sb, bindex)->br_xino;
35890 + spin_lock(&xino->xi_nondir.spin);
35891 + found = au_xinondir_find(xino, h_ino);
35892 + if (found == -1) {
35893 + empty = au_xinondir_find(xino, /*h_ino*/0);
35894 + if (empty == -1) {
35895 + empty = xino->xi_nondir.total;
35896 + err = au_xinondir_expand(xino);
35897 + if (unlikely(err))
35900 + xino->xi_nondir.array[empty] = h_ino;
35903 + spin_unlock(&xino->xi_nondir.spin);
35904 + wait_event(xino->xi_nondir.wqh,
35905 + xino->xi_nondir.array[found] != h_ino);
35910 + spin_unlock(&xino->xi_nondir.spin);
35914 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35915 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35916 +++ linux/include/uapi/linux/aufs_type.h 2017-07-31 10:27:18.853311720 +0200
35919 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35921 + * This program, aufs is free software; you can redistribute it and/or modify
35922 + * it under the terms of the GNU General Public License as published by
35923 + * the Free Software Foundation; either version 2 of the License, or
35924 + * (at your option) any later version.
35926 + * This program is distributed in the hope that it will be useful,
35927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35929 + * GNU General Public License for more details.
35931 + * You should have received a copy of the GNU General Public License
35932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35935 +#ifndef __AUFS_TYPE_H__
35936 +#define __AUFS_TYPE_H__
35938 +#define AUFS_NAME "aufs"
35942 + * define it before including all other headers.
35943 + * sched.h may use pr_* macros before defining "current", so define the
35944 + * no-current version first, and re-define later.
35946 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35947 +#include <linux/sched.h>
35949 +#define pr_fmt(fmt) \
35950 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35951 + (int)sizeof(current->comm), current->comm, current->pid
35953 +#include <stdint.h>
35954 +#include <sys/types.h>
35955 +#endif /* __KERNEL__ */
35957 +#include <linux/limits.h>
35959 +#define AUFS_VERSION "4.x-rcN-20170703"
35961 +/* todo? move this to linux-2.6.19/include/magic.h */
35962 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35964 +/* ---------------------------------------------------------------------- */
35966 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35967 +typedef int8_t aufs_bindex_t;
35968 +#define AUFS_BRANCH_MAX 127
35970 +typedef int16_t aufs_bindex_t;
35971 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35972 +#define AUFS_BRANCH_MAX 511
35973 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35974 +#define AUFS_BRANCH_MAX 1023
35975 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35976 +#define AUFS_BRANCH_MAX 32767
35981 +#ifndef AUFS_BRANCH_MAX
35982 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35984 +#endif /* __KERNEL__ */
35986 +/* ---------------------------------------------------------------------- */
35988 +#define AUFS_FSTYPE AUFS_NAME
35990 +#define AUFS_ROOT_INO 2
35991 +#define AUFS_FIRST_INO 11
35993 +#define AUFS_WH_PFX ".wh."
35994 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35995 +#define AUFS_WH_TMP_LEN 4
35996 +/* a limit for rmdir/rename a dir and copyup */
35997 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35998 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
36000 + - AUFS_WH_TMP_LEN) /* hex */
36001 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
36002 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
36003 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
36004 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
36005 +#define AUFS_DIRWH_DEF 3
36006 +#define AUFS_RDCACHE_DEF 10 /* seconds */
36007 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
36008 +#define AUFS_RDBLK_DEF 512 /* bytes */
36009 +#define AUFS_RDHASH_DEF 32
36010 +#define AUFS_WKQ_NAME AUFS_NAME "d"
36011 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
36012 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
36013 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
36014 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
36016 +/* pseudo-link maintenace under /proc */
36017 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
36018 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
36019 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
36021 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
36022 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
36024 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
36025 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
36026 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
36028 +/* doubly whiteouted */
36029 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
36030 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
36031 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
36033 +/* branch permissions and attributes */
36034 +#define AUFS_BRPERM_RW "rw"
36035 +#define AUFS_BRPERM_RO "ro"
36036 +#define AUFS_BRPERM_RR "rr"
36037 +#define AUFS_BRATTR_COO_REG "coo_reg"
36038 +#define AUFS_BRATTR_COO_ALL "coo_all"
36039 +#define AUFS_BRATTR_FHSM "fhsm"
36040 +#define AUFS_BRATTR_UNPIN "unpin"
36041 +#define AUFS_BRATTR_ICEX "icex"
36042 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
36043 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
36044 +#define AUFS_BRATTR_ICEX_TR "icextr"
36045 +#define AUFS_BRATTR_ICEX_USR "icexusr"
36046 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
36047 +#define AUFS_BRRATTR_WH "wh"
36048 +#define AUFS_BRWATTR_NLWH "nolwh"
36049 +#define AUFS_BRWATTR_MOO "moo"
36051 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
36052 +#define AuBrPerm_RO (1 << 1) /* readonly */
36053 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
36054 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
36056 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
36057 +#define AuBrAttr_COO_ALL (1 << 4)
36058 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
36060 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
36061 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
36062 + branch. meaningless since
36063 + linux-3.18-rc1 */
36065 +/* ignore error in copying XATTR */
36066 +#define AuBrAttr_ICEX_SEC (1 << 7)
36067 +#define AuBrAttr_ICEX_SYS (1 << 8)
36068 +#define AuBrAttr_ICEX_TR (1 << 9)
36069 +#define AuBrAttr_ICEX_USR (1 << 10)
36070 +#define AuBrAttr_ICEX_OTH (1 << 11)
36071 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
36072 + | AuBrAttr_ICEX_SYS \
36073 + | AuBrAttr_ICEX_TR \
36074 + | AuBrAttr_ICEX_USR \
36075 + | AuBrAttr_ICEX_OTH)
36077 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
36078 +#define AuBrRAttr_Mask AuBrRAttr_WH
36080 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
36081 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
36082 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
36084 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
36086 +/* #warning test userspace */
36088 +#ifndef CONFIG_AUFS_FHSM
36089 +#undef AuBrAttr_FHSM
36090 +#define AuBrAttr_FHSM 0
36092 +#ifndef CONFIG_AUFS_XATTR
36093 +#undef AuBrAttr_ICEX
36094 +#define AuBrAttr_ICEX 0
36095 +#undef AuBrAttr_ICEX_SEC
36096 +#define AuBrAttr_ICEX_SEC 0
36097 +#undef AuBrAttr_ICEX_SYS
36098 +#define AuBrAttr_ICEX_SYS 0
36099 +#undef AuBrAttr_ICEX_TR
36100 +#define AuBrAttr_ICEX_TR 0
36101 +#undef AuBrAttr_ICEX_USR
36102 +#define AuBrAttr_ICEX_USR 0
36103 +#undef AuBrAttr_ICEX_OTH
36104 +#define AuBrAttr_ICEX_OTH 0
36108 +/* the longest combination */
36109 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
36110 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
36111 + "+" AUFS_BRATTR_COO_REG \
36112 + "+" AUFS_BRATTR_FHSM \
36113 + "+" AUFS_BRATTR_UNPIN \
36114 + "+" AUFS_BRATTR_ICEX_SEC \
36115 + "+" AUFS_BRATTR_ICEX_SYS \
36116 + "+" AUFS_BRATTR_ICEX_USR \
36117 + "+" AUFS_BRATTR_ICEX_OTH \
36118 + "+" AUFS_BRWATTR_NLWH)
36121 + char a[AuBrPermStrSz];
36122 +} au_br_perm_str_t;
36124 +static inline int au_br_writable(int brperm)
36126 + return brperm & AuBrPerm_RW;
36129 +static inline int au_br_whable(int brperm)
36131 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
36134 +static inline int au_br_wh_linkable(int brperm)
36136 + return !(brperm & AuBrWAttr_NoLinkWH);
36139 +static inline int au_br_cmoo(int brperm)
36141 + return brperm & AuBrAttr_CMOO_Mask;
36144 +static inline int au_br_fhsm(int brperm)
36146 + return brperm & AuBrAttr_FHSM;
36149 +/* ---------------------------------------------------------------------- */
36153 + /* readdir in userspace */
36157 + AuCtl_WBR_FD, /* pathconf wrapper */
36158 + AuCtl_IBUSY, /* busy inode */
36159 + AuCtl_MVDOWN, /* move-down */
36160 + AuCtl_BR, /* info about branches */
36161 + AuCtl_FHSM_FD /* connection for fhsm */
36164 +/* borrowed from linux/include/linux/kernel.h */
36166 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36167 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36170 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36172 +#define __aligned(x) __attribute__((aligned(x)))
36177 +#define __packed __attribute__((packed))
36181 +struct au_rdu_cookie {
36186 + uint32_t generation;
36189 +struct au_rdu_ent {
36198 +static inline int au_rdu_len(int nlen)
36200 + /* include the terminating NULL */
36201 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36202 + sizeof(uint64_t));
36205 +union au_rdu_ent_ul {
36206 + struct au_rdu_ent __user *e;
36218 + uint64_t sz; /* AuCtl_RDU */
36219 + uint64_t nent; /* AuCtl_RDU_INO */
36221 + union au_rdu_ent_ul ent;
36222 + uint16_t verify[AufsCtlRduV_End];
36224 + /* input/output */
36228 + union au_rdu_ent_ul tail;
36229 + /* number of entries which were added in a single call */
36234 + struct au_rdu_cookie cookie;
36237 +/* ---------------------------------------------------------------------- */
36239 +struct aufs_wbr_fd {
36244 +/* ---------------------------------------------------------------------- */
36246 +struct aufs_ibusy {
36247 + uint64_t ino, h_ino;
36251 +/* ---------------------------------------------------------------------- */
36253 +/* error code for move-down */
36254 +/* the actual message strings are implemented in aufs-util.git */
36256 + EAU_MVDOWN_OPAQUE = 1,
36257 + EAU_MVDOWN_WHITEOUT,
36258 + EAU_MVDOWN_UPPER,
36259 + EAU_MVDOWN_BOTTOM,
36260 + EAU_MVDOWN_NOUPPER,
36261 + EAU_MVDOWN_NOLOWERBR,
36265 +/* flags for move-down */
36266 +#define AUFS_MVDOWN_DMSG 1
36267 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36268 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36269 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36270 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36271 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36272 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36273 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36274 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36275 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36276 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36277 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36278 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36280 +/* index for move-down */
36282 + AUFS_MVDOWN_UPPER,
36283 + AUFS_MVDOWN_LOWER,
36284 + AUFS_MVDOWN_NARRAY
36288 + * additional info of move-down
36289 + * number of free blocks and inodes.
36290 + * subset of struct kstatfs, but smaller and always 64bit.
36292 +struct aufs_stfs {
36293 + uint64_t f_blocks;
36294 + uint64_t f_bavail;
36295 + uint64_t f_files;
36296 + uint64_t f_ffree;
36299 +struct aufs_stbr {
36300 + int16_t brid; /* optional input */
36301 + int16_t bindex; /* output */
36302 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36305 +struct aufs_mvdown {
36306 + uint32_t flags; /* input/output */
36307 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36308 + int8_t au_errno; /* output */
36311 +/* ---------------------------------------------------------------------- */
36313 +union aufs_brinfo {
36314 + /* PATH_MAX may differ between kernel-space and user-space */
36315 + char _spacer[4096];
36323 +/* ---------------------------------------------------------------------- */
36325 +#define AuCtlType 'A'
36326 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36327 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36328 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36329 + struct aufs_wbr_fd)
36330 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36331 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36332 + struct aufs_mvdown)
36333 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36334 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36336 +#endif /* __AUFS_TYPE_H__ */
36337 aufs4.x-rcN loopback patch
36339 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36340 index 6b8a6a4c..a80416e 100644
36341 --- a/drivers/block/loop.c
36342 +++ b/drivers/block/loop.c
36343 @@ -547,7 +547,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36346 struct switch_request {
36347 - struct file *file;
36348 + struct file *file, *virt_file;
36349 struct completion wait;
36352 @@ -573,6 +573,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36353 mapping = file->f_mapping;
36354 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36355 lo->lo_backing_file = file;
36356 + lo->lo_backing_virt_file = p->virt_file;
36357 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36358 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36359 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36360 @@ -585,11 +586,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36361 * First it needs to flush existing IO, it does this by sending a magic
36362 * BIO down the pipe. The completion of this BIO does the actual switch.
36364 -static int loop_switch(struct loop_device *lo, struct file *file)
36365 +static int loop_switch(struct loop_device *lo, struct file *file,
36366 + struct file *virt_file)
36368 struct switch_request w;
36371 + w.virt_file = virt_file;
36373 /* freeze queue and wait for completion of scheduled requests */
36374 blk_mq_freeze_queue(lo->lo_queue);
36375 @@ -614,6 +617,15 @@ static int loop_flush(struct loop_device *lo)
36376 return loop_switch(lo, NULL);
36379 +static struct file *loop_real_file(struct file *file)
36381 + struct file *f = NULL;
36383 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36384 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36388 static void loop_reread_partitions(struct loop_device *lo,
36389 struct block_device *bdev)
36391 @@ -648,6 +660,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36394 struct file *file, *old_file;
36395 + struct file *f, *virt_file = NULL, *old_virt_file;
36396 struct inode *inode;
36399 @@ -664,9 +677,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36403 + f = loop_real_file(file);
36405 + virt_file = file;
36410 inode = file->f_mapping->host;
36411 old_file = lo->lo_backing_file;
36412 + old_virt_file = lo->lo_backing_virt_file;
36416 @@ -678,17 +698,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36419 /* and ... switch */
36420 - error = loop_switch(lo, file);
36421 + error = loop_switch(lo, file, virt_file);
36426 + if (old_virt_file)
36427 + fput(old_virt_file);
36428 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36429 loop_reread_partitions(lo, bdev);
36439 @@ -875,7 +899,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36440 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36441 struct block_device *bdev, unsigned int arg)
36443 - struct file *file, *f;
36444 + struct file *file, *f, *virt_file = NULL;
36445 struct inode *inode;
36446 struct address_space *mapping;
36447 unsigned lo_blocksize;
36448 @@ -890,6 +914,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36452 + f = loop_real_file(file);
36454 + virt_file = file;
36460 if (lo->lo_state != Lo_unbound)
36461 @@ -942,6 +972,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36462 lo->lo_device = bdev;
36463 lo->lo_flags = lo_flags;
36464 lo->lo_backing_file = file;
36465 + lo->lo_backing_virt_file = virt_file;
36466 lo->transfer = NULL;
36468 lo->lo_sizelimit = 0;
36469 @@ -974,6 +1005,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36476 /* This is safe: open() is still holding a reference. */
36477 module_put(THIS_MODULE);
36478 @@ -1020,6 +1053,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36479 static int loop_clr_fd(struct loop_device *lo)
36481 struct file *filp = lo->lo_backing_file;
36482 + struct file *virt_filp = lo->lo_backing_virt_file;
36483 gfp_t gfp = lo->old_gfp_mask;
36484 struct block_device *bdev = lo->lo_device;
36486 @@ -1051,6 +1085,7 @@ static int loop_clr_fd(struct loop_device *lo)
36487 spin_lock_irq(&lo->lo_lock);
36488 lo->lo_state = Lo_rundown;
36489 lo->lo_backing_file = NULL;
36490 + lo->lo_backing_virt_file = NULL;
36491 spin_unlock_irq(&lo->lo_lock);
36493 loop_release_xfer(lo);
36494 @@ -1095,6 +1130,8 @@ static int loop_clr_fd(struct loop_device *lo)
36495 * bd_mutex which is usually taken before lo_ctl_mutex.
36503 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36504 index fecd3f9..6b3a7c9 100644
36505 --- a/drivers/block/loop.h
36506 +++ b/drivers/block/loop.h
36507 @@ -46,7 +46,7 @@ struct loop_device {
36508 int (*ioctl)(struct loop_device *, int cmd,
36509 unsigned long arg);
36511 - struct file * lo_backing_file;
36512 + struct file * lo_backing_file, *lo_backing_virt_file;
36513 struct block_device *lo_device;
36514 unsigned lo_blocksize;
36516 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36517 index 870717e..ea7fee0 100644
36518 --- a/fs/aufs/f_op.c
36519 +++ b/fs/aufs/f_op.c
36520 @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36521 if (IS_ERR(h_file))
36524 - if (au_test_loopback_kthread()) {
36525 + if (0 && au_test_loopback_kthread()) {
36526 au_warn_loopback(h_file->f_path.dentry->d_sb);
36527 if (file->f_mapping != h_file->f_mapping) {
36528 file->f_mapping = h_file->f_mapping;
36529 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36530 index e35f015..b37f1ae 100644
36531 --- a/fs/aufs/loop.c
36532 +++ b/fs/aufs/loop.c
36533 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36534 symbol_put(loop_backing_file);
36535 kfree(au_warn_loopback_array);
36538 +/* ---------------------------------------------------------------------- */
36540 +/* support the loopback block device insude aufs */
36542 +struct file *aufs_real_loop(struct file *file)
36546 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36547 + fi_read_lock(file);
36548 + f = au_hf_top(file);
36549 + fi_read_unlock(file);
36553 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36554 index e2df495..36e5052 100644
36555 --- a/fs/aufs/loop.h
36556 +++ b/fs/aufs/loop.h
36557 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36559 int au_loopback_init(void);
36560 void au_loopback_fin(void);
36562 +struct file *aufs_real_loop(struct file *file);
36564 +AuStub(struct file *, loop_backing_file, return NULL)
36566 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36567 struct dentry *h_adding)
36568 AuStubInt0(au_test_loopback_kthread, void)
36569 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36571 AuStubInt0(au_loopback_init, void)
36572 AuStubVoid(au_loopback_fin, void)
36574 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36575 #endif /* BLK_DEV_LOOP */
36577 #endif /* __KERNEL__ */
36578 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36579 index 5455fb1..8b9df60 100644
36580 --- a/fs/aufs/super.c
36581 +++ b/fs/aufs/super.c
36582 @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = {
36583 .statfs = aufs_statfs,
36584 .put_super = aufs_put_super,
36585 .sync_fs = aufs_sync_fs,
36586 - .remount_fs = aufs_remount_fs
36587 + .remount_fs = aufs_remount_fs,
36588 +#ifdef CONFIG_AUFS_BDEV_LOOP
36589 + .real_loop = aufs_real_loop
36593 /* ---------------------------------------------------------------------- */
36594 diff --git a/include/linux/fs.h b/include/linux/fs.h
36595 index 22d2910..d8db3fb 100644
36596 --- a/include/linux/fs.h
36597 +++ b/include/linux/fs.h
36598 @@ -1811,6 +1811,10 @@ struct super_operations {
36599 struct shrink_control *);
36600 long (*free_cached_objects)(struct super_block *,
36601 struct shrink_control *);
36602 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36604 + struct file *(*real_loop)(struct file *);
36609 --- linux-4.12/drivers/block/loop.c~ 2017-07-31 10:28:05.000000000 +0200
36610 +++ linux-4.12/drivers/block/loop.c 2017-07-31 10:30:00.818087749 +0200
36611 @@ -614,7 +614,7 @@ static int loop_flush(struct loop_device
36612 /* loop not yet configured, no running thread, nothing to flush */
36613 if (lo->lo_state != Lo_bound)
36615 - return loop_switch(lo, NULL);
36616 + return loop_switch(lo, NULL, NULL);
36619 static struct file *loop_real_file(struct file *file)