1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 83eab52..31f16c4 100644
7 @@ -248,6 +248,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 7bbaca9..a026491 100644
19 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index f330ba4..67d88cd 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -59,6 +59,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
36 aufs4.x-rcN base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 107c10e..dd8df20 100644
42 @@ -2308,6 +2308,19 @@ F: include/linux/audit.h
43 F: include/uapi/linux/audit.h
46 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
47 +M: "J. R. Okajima" <hooanon05g@gmail.com>
48 +L: linux-unionfs@vger.kernel.org
49 +L: aufs-users@lists.sourceforge.net (members only)
50 +W: http://aufs.sourceforge.net
51 +T: git://github.com/sfjro/aufs4-linux.git
53 +F: Documentation/filesystems/aufs/
54 +F: Documentation/ABI/testing/debugfs-aufs
55 +F: Documentation/ABI/testing/sysfs-aufs
57 +F: include/uapi/linux/aufs_type.h
59 AUXILIARY DISPLAY DRIVERS
60 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
61 W: http://miguelojeda.es/auxdisplay.htm
62 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
63 index f347285..b63f68b 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -701,6 +701,24 @@ static inline int is_loop_device(struct file *file)
67 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
72 + * no get/put for file.
74 +struct file *loop_backing_file(struct super_block *sb)
77 + struct loop_device *l;
80 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
81 + l = sb->s_bdev->bd_disk->private_data;
82 + ret = l->lo_backing_file;
86 +EXPORT_SYMBOL_GPL(loop_backing_file);
88 /* loop sysfs attributes */
90 static ssize_t loop_attr_show(struct device *dev, char *page,
91 diff --git a/fs/dcache.c b/fs/dcache.c
92 index 95d71ed..8ca5f09 100644
95 @@ -1164,7 +1164,7 @@ enum d_walk_ret {
97 * The @enter() and @finish() callbacks are called with d_lock held.
99 -static void d_walk(struct dentry *parent, void *data,
100 +void d_walk(struct dentry *parent, void *data,
101 enum d_walk_ret (*enter)(void *, struct dentry *),
102 void (*finish)(void *))
104 diff --git a/fs/fcntl.c b/fs/fcntl.c
105 index e1c54f2..9f07008 100644
110 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
112 -static int setfl(int fd, struct file * filp, unsigned long arg)
113 +int setfl(int fd, struct file * filp, unsigned long arg)
115 struct inode * inode = file_inode(filp);
117 @@ -60,6 +60,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
119 if (filp->f_op->check_flags)
120 error = filp->f_op->check_flags(arg);
121 + if (!error && filp->f_op->setfl)
122 + error = filp->f_op->setfl(filp, arg);
126 diff --git a/fs/inode.c b/fs/inode.c
127 index 88110fd..9a9ba3a 100644
130 @@ -1642,7 +1642,7 @@ EXPORT_SYMBOL(generic_update_time);
131 * This does the actual work of updating an inodes time or version. Must have
132 * had called mnt_want_write() before calling this.
134 -static int update_time(struct inode *inode, struct timespec *time, int flags)
135 +int update_time(struct inode *inode, struct timespec *time, int flags)
137 int (*update_time)(struct inode *, struct timespec *, int);
139 diff --git a/fs/read_write.c b/fs/read_write.c
140 index 5816d4c..670b365 100644
141 --- a/fs/read_write.c
142 +++ b/fs/read_write.c
143 @@ -515,6 +515,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
145 EXPORT_SYMBOL(__vfs_write);
147 +vfs_readf_t vfs_readf(struct file *file)
149 + const struct file_operations *fop = file->f_op;
153 + if (fop->read_iter)
154 + return new_sync_read;
155 + return ERR_PTR(-ENOSYS);
158 +vfs_writef_t vfs_writef(struct file *file)
160 + const struct file_operations *fop = file->f_op;
164 + if (fop->write_iter)
165 + return new_sync_write;
166 + return ERR_PTR(-ENOSYS);
169 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
172 diff --git a/fs/splice.c b/fs/splice.c
173 index 873d831..7899532 100644
176 @@ -856,8 +856,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
178 * Attempt to initiate a splice from pipe to file.
180 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
181 - loff_t *ppos, size_t len, unsigned int flags)
182 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
183 + loff_t *ppos, size_t len, unsigned int flags)
185 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
186 loff_t *, size_t, unsigned int);
187 @@ -873,9 +873,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
189 * Attempt to initiate a splice from a file to a pipe.
191 -static long do_splice_to(struct file *in, loff_t *ppos,
192 - struct pipe_inode_info *pipe, size_t len,
193 - unsigned int flags)
194 +long do_splice_to(struct file *in, loff_t *ppos,
195 + struct pipe_inode_info *pipe, size_t len,
196 + unsigned int flags)
198 ssize_t (*splice_read)(struct file *, loff_t *,
199 struct pipe_inode_info *, size_t, unsigned int);
200 diff --git a/fs/sync.c b/fs/sync.c
201 index 2a54c1f..7a5fa3f 100644
205 * wait == 1 case since in that case write_inode() functions do
206 * sync_dirty_buffer() and thus effectively write one block at a time.
208 -static int __sync_filesystem(struct super_block *sb, int wait)
209 +int __sync_filesystem(struct super_block *sb, int wait)
213 diff --git a/include/linux/file.h b/include/linux/file.h
214 index 61eb82c..e700888 100644
215 --- a/include/linux/file.h
216 +++ b/include/linux/file.h
217 @@ -19,6 +19,7 @@ struct dentry;
219 extern struct file *alloc_file(const struct path *, fmode_t mode,
220 const struct file_operations *fop);
221 +extern struct file *get_empty_filp(void);
223 static inline void fput_light(struct file *file, int fput_needed)
225 diff --git a/include/linux/fs.h b/include/linux/fs.h
226 index 2ba0743..d1c583b 100644
227 --- a/include/linux/fs.h
228 +++ b/include/linux/fs.h
229 @@ -1240,6 +1240,7 @@ extern void fasync_free(struct fasync_struct *);
230 /* can be called from interrupts */
231 extern void kill_fasync(struct fasync_struct **, int, int);
233 +extern int setfl(int fd, struct file * filp, unsigned long arg);
234 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
235 extern void f_setown(struct file *filp, unsigned long arg, int force);
236 extern void f_delown(struct file *filp);
237 @@ -1664,6 +1665,7 @@ struct file_operations {
238 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
239 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
240 int (*check_flags)(int);
241 + int (*setfl)(struct file *, unsigned long);
242 int (*flock) (struct file *, int, struct file_lock *);
243 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
244 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
245 @@ -1717,6 +1719,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
246 struct iovec *fast_pointer,
247 struct iovec **ret_pointer);
249 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
250 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
252 +vfs_readf_t vfs_readf(struct file *file);
253 +vfs_writef_t vfs_writef(struct file *file);
255 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
256 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
257 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
258 @@ -2108,6 +2116,7 @@ extern int current_umask(void);
259 extern void ihold(struct inode * inode);
260 extern void iput(struct inode *);
261 extern int generic_update_time(struct inode *, struct timespec *, int);
262 +extern int update_time(struct inode *, struct timespec *, int);
265 extern struct kobject *fs_kobj;
266 @@ -2387,6 +2396,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
270 +extern int __sync_filesystem(struct super_block *, int);
271 extern int sync_filesystem(struct super_block *);
272 extern const struct file_operations def_blk_fops;
273 extern const struct file_operations def_chr_fops;
274 diff --git a/include/linux/splice.h b/include/linux/splice.h
275 index 00a2116..1f0a4a2 100644
276 --- a/include/linux/splice.h
277 +++ b/include/linux/splice.h
278 @@ -86,4 +86,10 @@ extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
280 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
281 extern const struct pipe_buf_operations default_pipe_buf_ops;
283 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
284 + loff_t *ppos, size_t len, unsigned int flags);
285 +extern long do_splice_to(struct file *in, loff_t *ppos,
286 + struct pipe_inode_info *pipe, size_t len,
287 + unsigned int flags);
289 aufs4.x-rcN mmap patch
291 diff --git a/fs/proc/base.c b/fs/proc/base.c
292 index 87c9a9a..a0196f0 100644
295 @@ -1958,7 +1958,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
296 down_read(&mm->mmap_sem);
297 vma = find_exact_vma(mm, vm_start, vm_end);
298 if (vma && vma->vm_file) {
299 - *path = vma->vm_file->f_path;
300 + *path = vma_pr_or_file(vma)->f_path;
304 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
305 index 7563437..7c0dc0f 100644
306 --- a/fs/proc/nommu.c
307 +++ b/fs/proc/nommu.c
308 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
309 file = region->vm_file;
312 - struct inode *inode = file_inode(region->vm_file);
313 + struct inode *inode;
315 + file = vmr_pr_or_file(region);
316 + inode = file_inode(file);
317 dev = inode->i_sb->s_dev;
320 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
321 index 8f96a49..0d10404 100644
322 --- a/fs/proc/task_mmu.c
323 +++ b/fs/proc/task_mmu.c
324 @@ -291,7 +291,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
325 const char *name = NULL;
328 - struct inode *inode = file_inode(vma->vm_file);
329 + struct inode *inode;
331 + file = vma_pr_or_file(vma);
332 + inode = file_inode(file);
333 dev = inode->i_sb->s_dev;
335 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
336 @@ -1628,7 +1631,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
337 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
338 struct vm_area_struct *vma = v;
339 struct numa_maps *md = &numa_priv->md;
340 - struct file *file = vma->vm_file;
341 + struct file *file = vma_pr_or_file(vma);
342 struct mm_struct *mm = vma->vm_mm;
343 struct mm_walk walk = {
344 .hugetlb_entry = gather_hugetlb_stats,
345 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
346 index 3717562..6a328f1 100644
347 --- a/fs/proc/task_nommu.c
348 +++ b/fs/proc/task_nommu.c
349 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
353 - struct inode *inode = file_inode(vma->vm_file);
354 + struct inode *inode;
356 + file = vma_pr_or_file(vma);
357 + inode = file_inode(file);
358 dev = inode->i_sb->s_dev;
360 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
361 diff --git a/include/linux/mm.h b/include/linux/mm.h
362 index b84615b..3978a35 100644
363 --- a/include/linux/mm.h
364 +++ b/include/linux/mm.h
365 @@ -1257,6 +1257,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
369 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
370 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
372 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
373 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
375 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
377 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
379 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
380 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
383 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
384 +extern void vmr_do_fput(struct vm_region *, const char[], int);
386 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
388 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
389 +#endif /* !CONFIG_MMU */
391 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
392 unsigned int gup_flags);
393 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
394 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
395 index 808751d..66fc765 100644
396 --- a/include/linux/mm_types.h
397 +++ b/include/linux/mm_types.h
398 @@ -275,6 +275,7 @@ struct vm_region {
399 unsigned long vm_top; /* region allocated to here */
400 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
401 struct file *vm_file; /* the backing file or NULL */
402 + struct file *vm_prfile; /* the virtual backing file or NULL */
404 int vm_usage; /* region usage count (access under nommu_region_sem) */
405 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
406 @@ -349,6 +350,7 @@ struct vm_area_struct {
407 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
409 struct file * vm_file; /* File we map to (can be NULL). */
410 + struct file *vm_prfile; /* shadow of vm_file */
411 void * vm_private_data; /* was vm_pte (shared mem) */
414 diff --git a/kernel/fork.c b/kernel/fork.c
415 index 11c5c8a..48e7ef7 100644
418 @@ -626,7 +626,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
419 struct inode *inode = file_inode(file);
420 struct address_space *mapping = file->f_mapping;
424 if (tmp->vm_flags & VM_DENYWRITE)
425 atomic_dec(&inode->i_writecount);
426 i_mmap_lock_write(mapping);
427 diff --git a/mm/Makefile b/mm/Makefile
428 index 295bd7a..14fa1c8 100644
431 @@ -37,7 +37,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
432 mm_init.o mmu_context.o percpu.o slab_common.o \
433 compaction.o vmacache.o \
434 interval_tree.o list_lru.o workingset.o \
436 + prfile.o debug.o $(mmu-y)
440 diff --git a/mm/filemap.c b/mm/filemap.c
441 index 3f9afde..bb050b0 100644
444 @@ -2397,7 +2397,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
445 int ret = VM_FAULT_LOCKED;
447 sb_start_pagefault(inode->i_sb);
448 - file_update_time(vma->vm_file);
449 + vma_file_update_time(vma);
451 if (page->mapping != inode->i_mapping) {
453 diff --git a/mm/mmap.c b/mm/mmap.c
454 index dc4291d..4b3a2aa 100644
457 @@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
458 if (vma->vm_ops && vma->vm_ops->close)
459 vma->vm_ops->close(vma);
461 - fput(vma->vm_file);
463 mpol_put(vma_policy(vma));
464 kmem_cache_free(vm_area_cachep, vma);
466 @@ -879,7 +879,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
469 uprobe_munmap(next, next->vm_start, next->vm_end);
474 anon_vma_merge(vma, next);
475 @@ -1727,8 +1727,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
483 /* Undo any partial mapping done by a device driver. */
484 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
485 @@ -2533,7 +2533,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
489 - get_file(new->vm_file);
492 if (new->vm_ops && new->vm_ops->open)
493 new->vm_ops->open(new);
494 @@ -2552,7 +2552,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
495 if (new->vm_ops && new->vm_ops->close)
496 new->vm_ops->close(new);
498 - fput(new->vm_file);
500 unlink_anon_vmas(new);
502 mpol_put(vma_policy(new));
503 @@ -2703,7 +2703,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
504 struct vm_area_struct *vma;
505 unsigned long populate = 0;
506 unsigned long ret = -EINVAL;
508 + struct file *file, *prfile;
510 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
511 current->comm, current->pid);
512 @@ -2778,10 +2778,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
516 - file = get_file(vma->vm_file);
518 + file = vma->vm_file;
519 + prfile = vma->vm_prfile;
520 ret = do_mmap_pgoff(vma->vm_file, start, size,
521 prot, flags, pgoff, &populate);
522 + if (!IS_ERR_VALUE(ret) && file && prfile) {
523 + struct vm_area_struct *new_vma;
525 + new_vma = find_vma(mm, ret);
526 + if (!new_vma->vm_prfile)
527 + new_vma->vm_prfile = prfile;
528 + if (new_vma != vma)
532 + * two fput()s instead of vma_fput(vma),
533 + * coz vma may not be available anymore.
539 up_write(&mm->mmap_sem);
541 @@ -3056,7 +3073,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
542 if (anon_vma_clone(new_vma, vma))
543 goto out_free_mempol;
544 if (new_vma->vm_file)
545 - get_file(new_vma->vm_file);
546 + vma_get_file(new_vma);
547 if (new_vma->vm_ops && new_vma->vm_ops->open)
548 new_vma->vm_ops->open(new_vma);
549 vma_link(mm, new_vma, prev, rb_link, rb_parent);
550 diff --git a/mm/nommu.c b/mm/nommu.c
551 index 24f9f5f..ac0d37a 100644
554 @@ -636,7 +636,7 @@ static void __put_nommu_region(struct vm_region *region)
555 up_write(&nommu_region_sem);
558 - fput(region->vm_file);
561 /* IO memory and memory shared directly out of the pagecache
562 * from ramfs/tmpfs mustn't be released here */
563 @@ -794,7 +794,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
564 if (vma->vm_ops && vma->vm_ops->close)
565 vma->vm_ops->close(vma);
567 - fput(vma->vm_file);
569 put_nommu_region(vma->vm_region);
570 kmem_cache_free(vm_area_cachep, vma);
572 @@ -1320,7 +1320,7 @@ unsigned long do_mmap(struct file *file,
573 goto error_just_free;
576 - fput(region->vm_file);
578 kmem_cache_free(vm_region_jar, region);
581 @@ -1395,10 +1395,10 @@ unsigned long do_mmap(struct file *file,
582 up_write(&nommu_region_sem);
585 - fput(region->vm_file);
587 kmem_cache_free(vm_region_jar, region);
589 - fput(vma->vm_file);
591 kmem_cache_free(vm_area_cachep, vma);
594 diff --git a/mm/prfile.c b/mm/prfile.c
596 index 0000000..b323b8a
601 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
602 + * in /proc/PID/maps.
603 + * Call these functions via macros defined in linux/mm.h.
605 + * See Documentation/filesystems/aufs/design/06mmap.txt
607 + * Copyright (c) 2014 Junjro R. Okajima
608 + * Copyright (c) 2014 Ian Campbell
611 +#include <linux/mm.h>
612 +#include <linux/file.h>
613 +#include <linux/fs.h>
615 +/* #define PRFILE_TRACE */
616 +static inline void prfile_trace(struct file *f, struct file *pr,
617 + const char func[], int line, const char func2[])
621 + pr_info("%s:%d: %s, %s\n", func, line, func2,
622 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
626 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
629 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
631 + prfile_trace(f, pr, func, line, __func__);
632 + file_update_time(f);
634 + file_update_time(pr);
637 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
643 + return (f && pr) ? pr : f;
646 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
648 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
650 + prfile_trace(f, pr, func, line, __func__);
656 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
658 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
660 + prfile_trace(f, pr, func, line, __func__);
667 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
670 + struct file *f = region->vm_file, *pr = region->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
673 + return (f && pr) ? pr : f;
676 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
678 + struct file *f = region->vm_file, *pr = region->vm_prfile;
680 + prfile_trace(f, pr, func, line, __func__);
685 +#endif /* !CONFIG_MMU */
686 aufs4.x-rcN standalone patch
688 diff --git a/fs/dcache.c b/fs/dcache.c
689 index 8ca5f09..b1ff5be 100644
692 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
696 +EXPORT_SYMBOL_GPL(d_walk);
699 struct vfsmount *mnt;
700 @@ -2864,6 +2865,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
702 write_sequnlock(&rename_lock);
704 +EXPORT_SYMBOL_GPL(d_exchange);
707 * d_ancestor - search for an ancestor
708 diff --git a/fs/exec.c b/fs/exec.c
709 index e579466..2566b16 100644
712 @@ -104,6 +104,7 @@ bool path_noexec(const struct path *path)
713 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
714 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
716 +EXPORT_SYMBOL_GPL(path_noexec);
720 diff --git a/fs/fcntl.c b/fs/fcntl.c
721 index 9f07008..d60b682 100644
724 @@ -82,6 +82,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
728 +EXPORT_SYMBOL_GPL(setfl);
730 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
732 diff --git a/fs/file_table.c b/fs/file_table.c
733 index 6d982b5..9a3c6c8 100644
734 --- a/fs/file_table.c
735 +++ b/fs/file_table.c
736 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
738 return ERR_PTR(-ENFILE);
740 +EXPORT_SYMBOL_GPL(get_empty_filp);
743 * alloc_file - allocate and initialize a 'struct file'
744 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
748 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
750 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
752 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
756 +EXPORT_SYMBOL_GPL(__fput_sync);
758 void put_filp(struct file *file)
760 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
764 +EXPORT_SYMBOL_GPL(put_filp);
766 void __init files_init(void)
768 diff --git a/fs/inode.c b/fs/inode.c
769 index 9a9ba3a..a3a18d8 100644
772 @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
774 return update_time(inode, time, flags);
776 +EXPORT_SYMBOL_GPL(update_time);
779 * touch_atime - update the access time
780 diff --git a/fs/namespace.c b/fs/namespace.c
781 index 487ba30..642069d 100644
784 @@ -462,6 +462,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
785 mnt_dec_writers(real_mount(mnt));
788 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
791 * mnt_drop_write - give up write access to a mount
792 @@ -1872,6 +1873,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
796 +EXPORT_SYMBOL_GPL(iterate_mounts);
798 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
800 diff --git a/fs/notify/group.c b/fs/notify/group.c
801 index fbe3cbe..bdfc61e 100644
802 --- a/fs/notify/group.c
803 +++ b/fs/notify/group.c
805 #include <linux/srcu.h>
806 #include <linux/rculist.h>
807 #include <linux/wait.h>
808 +#include <linux/module.h>
810 #include <linux/fsnotify_backend.h>
811 #include "fsnotify.h"
812 @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
814 atomic_inc(&group->refcnt);
816 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
819 * Drop a reference to a group. Free it if it's through.
820 @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
821 if (atomic_dec_and_test(&group->refcnt))
822 fsnotify_final_destroy_group(group);
824 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
827 * Create a new fsnotify_group and hold a reference for the group returned.
828 @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
832 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
834 int fsnotify_fasync(int fd, struct file *file, int on)
836 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
837 index 6043306..fdb50e4 100644
838 --- a/fs/notify/mark.c
839 +++ b/fs/notify/mark.c
840 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
841 mark->free_mark(mark);
844 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
846 /* Calculate mask of events for a list of marks */
847 u32 fsnotify_recalc_mask(struct hlist_head *head)
848 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
849 mutex_unlock(&group->mark_mutex);
850 fsnotify_free_mark(mark);
852 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
854 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
856 @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
860 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
862 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
863 struct inode *inode, struct vfsmount *mnt, int allow_dups)
864 @@ -521,6 +524,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
865 atomic_set(&mark->refcnt, 1);
866 mark->free_mark = free_mark;
868 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
871 * Destroy all marks in destroy_list, waits for SRCU period to finish before
872 diff --git a/fs/open.c b/fs/open.c
873 index 9921f70..80d94c0 100644
876 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
877 inode_unlock(dentry->d_inode);
880 +EXPORT_SYMBOL_GPL(do_truncate);
882 long vfs_truncate(const struct path *path, loff_t length)
884 @@ -695,6 +696,7 @@ int open_check_o_direct(struct file *f)
888 +EXPORT_SYMBOL_GPL(open_check_o_direct);
890 static int do_dentry_open(struct file *f,
892 diff --git a/fs/read_write.c b/fs/read_write.c
893 index 670b365..f9f8bb1 100644
894 --- a/fs/read_write.c
895 +++ b/fs/read_write.c
896 @@ -525,6 +525,7 @@ vfs_readf_t vfs_readf(struct file *file)
897 return new_sync_read;
898 return ERR_PTR(-ENOSYS);
900 +EXPORT_SYMBOL_GPL(vfs_readf);
902 vfs_writef_t vfs_writef(struct file *file)
904 @@ -536,6 +537,7 @@ vfs_writef_t vfs_writef(struct file *file)
905 return new_sync_write;
906 return ERR_PTR(-ENOSYS);
908 +EXPORT_SYMBOL_GPL(vfs_writef);
910 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
912 diff --git a/fs/splice.c b/fs/splice.c
913 index 7899532..c0df111 100644
916 @@ -869,6 +869,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
918 return splice_write(pipe, out, ppos, len, flags);
920 +EXPORT_SYMBOL_GPL(do_splice_from);
923 * Attempt to initiate a splice from a file to a pipe.
924 @@ -898,6 +899,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
926 return splice_read(in, ppos, pipe, len, flags);
928 +EXPORT_SYMBOL_GPL(do_splice_to);
931 * splice_direct_to_actor - splices data directly between two non-pipes
932 diff --git a/fs/sync.c b/fs/sync.c
933 index 7a5fa3f..c9b9d46 100644
936 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
937 sb->s_op->sync_fs(sb, wait);
938 return __sync_blockdev(sb->s_bdev, wait);
940 +EXPORT_SYMBOL_GPL(__sync_filesystem);
943 * Write out and wait upon all dirty data associated with this
944 diff --git a/fs/xattr.c b/fs/xattr.c
945 index 7e3317c..88910fe 100644
948 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
949 *xattr_value = value;
952 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
955 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
956 diff --git a/kernel/task_work.c b/kernel/task_work.c
957 index d513051..e056d54 100644
958 --- a/kernel/task_work.c
959 +++ b/kernel/task_work.c
960 @@ -119,3 +119,4 @@ void task_work_run(void)
964 +EXPORT_SYMBOL_GPL(task_work_run);
965 diff --git a/security/commoncap.c b/security/commoncap.c
966 index 8df676f..6b5cc07 100644
967 --- a/security/commoncap.c
968 +++ b/security/commoncap.c
969 @@ -1061,12 +1061,14 @@ int cap_mmap_addr(unsigned long addr)
973 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
975 int cap_mmap_file(struct file *file, unsigned long reqprot,
976 unsigned long prot, unsigned long flags)
980 +EXPORT_SYMBOL_GPL(cap_mmap_file);
982 #ifdef CONFIG_SECURITY
984 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
985 index 03c1652..f88c84b 100644
986 --- a/security/device_cgroup.c
987 +++ b/security/device_cgroup.c
989 #include <linux/device_cgroup.h>
990 #include <linux/cgroup.h>
991 #include <linux/ctype.h>
992 +#include <linux/export.h>
993 #include <linux/list.h>
994 #include <linux/uaccess.h>
995 #include <linux/seq_file.h>
996 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
997 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
1000 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
1002 int devcgroup_inode_mknod(int mode, dev_t dev)
1004 diff --git a/security/security.c b/security/security.c
1005 index f825304..8dd441d 100644
1006 --- a/security/security.c
1007 +++ b/security/security.c
1008 @@ -443,6 +443,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1010 return call_int_hook(path_rmdir, 0, dir, dentry);
1012 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1014 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1016 @@ -459,6 +460,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1018 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1020 +EXPORT_SYMBOL_GPL(security_path_symlink);
1022 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1023 struct dentry *new_dentry)
1024 @@ -467,6 +469,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1026 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1028 +EXPORT_SYMBOL_GPL(security_path_link);
1030 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1031 const struct path *new_dir, struct dentry *new_dentry,
1032 @@ -494,6 +497,7 @@ int security_path_truncate(const struct path *path)
1034 return call_int_hook(path_truncate, 0, path);
1036 +EXPORT_SYMBOL_GPL(security_path_truncate);
1038 int security_path_chmod(const struct path *path, umode_t mode)
1040 @@ -501,6 +505,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1042 return call_int_hook(path_chmod, 0, path, mode);
1044 +EXPORT_SYMBOL_GPL(security_path_chmod);
1046 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1048 @@ -508,6 +513,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1050 return call_int_hook(path_chown, 0, path, uid, gid);
1052 +EXPORT_SYMBOL_GPL(security_path_chown);
1054 int security_path_chroot(const struct path *path)
1056 @@ -593,6 +599,7 @@ int security_inode_readlink(struct dentry *dentry)
1058 return call_int_hook(inode_readlink, 0, dentry);
1060 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1062 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1064 @@ -608,6 +615,7 @@ int security_inode_permission(struct inode *inode, int mask)
1066 return call_int_hook(inode_permission, 0, inode, mask);
1068 +EXPORT_SYMBOL_GPL(security_inode_permission);
1070 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1072 @@ -779,6 +787,7 @@ int security_file_permission(struct file *file, int mask)
1074 return fsnotify_perm(file, mask);
1076 +EXPORT_SYMBOL_GPL(security_file_permission);
1078 int security_file_alloc(struct file *file)
1080 @@ -838,6 +847,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1082 return ima_file_mmap(file, prot);
1084 +EXPORT_SYMBOL_GPL(security_mmap_file);
1086 int security_mmap_addr(unsigned long addr)
1088 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1089 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1090 +++ linux/Documentation/ABI/testing/debugfs-aufs 2016-10-09 16:55:36.476034536 +0200
1092 +What: /debug/aufs/si_<id>/
1094 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1096 + Under /debug/aufs, a directory named si_<id> is created
1097 + per aufs mount, where <id> is a unique id generated
1100 +What: /debug/aufs/si_<id>/plink
1102 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1104 + It has three lines and shows the information about the
1105 + pseudo-link. The first line is a single number
1106 + representing a number of buckets. The second line is a
1107 + number of pseudo-links per buckets (separated by a
1108 + blank). The last line is a single number representing a
1109 + total number of psedo-links.
1110 + When the aufs mount option 'noplink' is specified, it
1111 + will show "1\n0\n0\n".
1113 +What: /debug/aufs/si_<id>/xib
1115 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1117 + It shows the consumed blocks by xib (External Inode Number
1118 + Bitmap), its block size and file size.
1119 + When the aufs mount option 'noxino' is specified, it
1120 + will be empty. About XINO files, see the aufs manual.
1122 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1124 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1126 + It shows the consumed blocks by xino (External Inode Number
1127 + Translation Table), its link count, block size and file
1129 + When the aufs mount option 'noxino' is specified, it
1130 + will be empty. About XINO files, see the aufs manual.
1132 +What: /debug/aufs/si_<id>/xigen
1134 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1136 + It shows the consumed blocks by xigen (External Inode
1137 + Generation Table), its block size and file size.
1138 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1140 + When the aufs mount option 'noxino' is specified, it
1141 + will be empty. About XINO files, see the aufs manual.
1142 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1143 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1144 +++ linux/Documentation/ABI/testing/sysfs-aufs 2016-10-09 16:55:36.476034536 +0200
1146 +What: /sys/fs/aufs/si_<id>/
1148 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1150 + Under /sys/fs/aufs, a directory named si_<id> is created
1151 + per aufs mount, where <id> is a unique id generated
1154 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1156 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1158 + It shows the abolute path of a member directory (which
1159 + is called branch) in aufs, and its permission.
1161 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1163 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1165 + It shows the id of a member directory (which is called
1168 +What: /sys/fs/aufs/si_<id>/xi_path
1170 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1172 + It shows the abolute path of XINO (External Inode Number
1173 + Bitmap, Translation Table and Generation Table) file
1174 + even if it is the default path.
1175 + When the aufs mount option 'noxino' is specified, it
1176 + will be empty. About XINO files, see the aufs manual.
1177 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1178 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1179 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-03-02 14:24:13.850255360 +0100
1182 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1184 +# This program is free software; you can redistribute it and/or modify
1185 +# it under the terms of the GNU General Public License as published by
1186 +# the Free Software Foundation; either version 2 of the License, or
1187 +# (at your option) any later version.
1189 +# This program is distributed in the hope that it will be useful,
1190 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1191 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1192 +# GNU General Public License for more details.
1194 +# You should have received a copy of the GNU General Public License
1195 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1198 +----------------------------------------
1200 +aufs [ei ju: ef es] | [a u f s]
1201 +1. abbrev. for "advanced multi-layered unification filesystem".
1202 +2. abbrev. for "another unionfs".
1203 +3. abbrev. for "auf das" in German which means "on the" in English.
1204 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1205 + But "Filesystem aufs Filesystem" is hard to understand.
1207 +AUFS is a filesystem with features:
1208 +- multi layered stackable unification filesystem, the member directory
1209 + is called as a branch.
1210 +- branch permission and attribute, 'readonly', 'real-readonly',
1211 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1213 +- internal "file copy-on-write".
1214 +- logical deletion, whiteout.
1215 +- dynamic branch manipulation, adding, deleting and changing permission.
1216 +- allow bypassing aufs, user's direct branch access.
1217 +- external inode number translation table and bitmap which maintains the
1218 + persistent aufs inode number.
1219 +- seekable directory, including NFS readdir.
1220 +- file mapping, mmap and sharing pages.
1221 +- pseudo-link, hardlink over branches.
1222 +- loopback mounted filesystem as a branch.
1223 +- several policies to select one among multiple writable branches.
1224 +- revert a single systemcall when an error occurs in aufs.
1228 +Multi Layered Stackable Unification Filesystem
1229 +----------------------------------------------------------------------
1230 +Most people already knows what it is.
1231 +It is a filesystem which unifies several directories and provides a
1232 +merged single directory. When users access a file, the access will be
1233 +passed/re-directed/converted (sorry, I am not sure which English word is
1234 +correct) to the real file on the member filesystem. The member
1235 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1236 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1237 +readonly branch is handled by creating 'whiteout' on the upper writable
1240 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1241 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1242 +different approaches to implement the merged-view.
1243 +The former tries putting it into VFS, and the latter implements as a
1244 +separate filesystem.
1245 +(If I misunderstand about these implementations, please let me know and
1246 +I shall correct it. Because it is a long time ago when I read their
1247 +source files last time).
1249 +UnionMount's approach will be able to small, but may be hard to share
1250 +branches between several UnionMount since the whiteout in it is
1251 +implemented in the inode on branch filesystem and always
1252 +shared. According to Bharata's post, readdir does not seems to be
1254 +There are several missing features known in this implementations such as
1255 +- for users, the inode number may change silently. eg. copy-up.
1256 +- link(2) may break by copy-up.
1257 +- read(2) may get an obsoleted filedata (fstat(2) too).
1258 +- fcntl(F_SETLK) may be broken by copy-up.
1259 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1262 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1263 +merged into mainline. This is another implementation of UnionMount as a
1264 +separated filesystem. All the limitations and known problems which
1265 +UnionMount are equally inherited to "overlay" filesystem.
1267 +Unionfs has a longer history. When I started implementing a stackable
1268 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1269 +inode, dentry and file objects and they have an array pointing lower
1270 +same kind objects. After contributing many patches for Unionfs, I
1271 +re-started my project AUFS (Jun 2006).
1273 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1274 +implemented my own ideas, approaches and enhancements and it became
1275 +totally different one.
1277 +Comparing DM snapshot and fs based implementation
1278 +- the number of bytes to be copied between devices is much smaller.
1279 +- the type of filesystem must be one and only.
1280 +- the fs must be writable, no readonly fs, even for the lower original
1281 + device. so the compression fs will not be usable. but if we use
1282 + loopback mount, we may address this issue.
1284 + mount /cdrom/squashfs.img /sq
1285 + losetup /sq/ext2.img
1286 + losetup /somewhere/cow
1287 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1288 +- it will be difficult (or needs more operations) to extract the
1289 + difference between the original device and COW.
1290 +- DM snapshot-merge may help a lot when users try merging. in the
1291 + fs-layer union, users will use rsync(1).
1293 +You may want to read my old paper "Filesystems in LiveCD"
1294 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1297 +Several characters/aspects/persona of aufs
1298 +----------------------------------------------------------------------
1300 +Aufs has several characters, aspects or persona.
1301 +1. a filesystem, callee of VFS helper
1302 +2. sub-VFS, caller of VFS helper for branches
1303 +3. a virtual filesystem which maintains persistent inode number
1304 +4. reader/writer of files on branches such like an application
1306 +1. Callee of VFS Helper
1307 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1308 +unlink(2) from an application reaches sys_unlink() kernel function and
1309 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1310 +calls filesystem specific unlink operation. Actually aufs implements the
1311 +unlink operation but it behaves like a redirector.
1313 +2. Caller of VFS Helper for Branches
1314 +aufs_unlink() passes the unlink request to the branch filesystem as if
1315 +it were called from VFS. So the called unlink operation of the branch
1316 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1317 +every necessary pre/post operation for the branch filesystem.
1318 +- acquire the lock for the parent dir on a branch
1319 +- lookup in a branch
1320 +- revalidate dentry on a branch
1321 +- mnt_want_write() for a branch
1322 +- vfs_unlink() for a branch
1323 +- mnt_drop_write() for a branch
1324 +- release the lock on a branch
1326 +3. Persistent Inode Number
1327 +One of the most important issue for a filesystem is to maintain inode
1328 +numbers. This is particularly important to support exporting a
1329 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1330 +backend block device for its own. But some storage is necessary to
1331 +keep and maintain the inode numbers. It may be a large space and may not
1332 +suit to keep in memory. Aufs rents some space from its first writable
1333 +branch filesystem (by default) and creates file(s) on it. These files
1334 +are created by aufs internally and removed soon (currently) keeping
1336 +Note: Because these files are removed, they are totally gone after
1337 + unmounting aufs. It means the inode numbers are not persistent
1338 + across unmount or reboot. I have a plan to make them really
1339 + persistent which will be important for aufs on NFS server.
1341 +4. Read/Write Files Internally (copy-on-write)
1342 +Because a branch can be readonly, when you write a file on it, aufs will
1343 +"copy-up" it to the upper writable branch internally. And then write the
1344 +originally requested thing to the file. Generally kernel doesn't
1345 +open/read/write file actively. In aufs, even a single write may cause a
1346 +internal "file copy". This behaviour is very similar to cp(1) command.
1348 +Some people may think it is better to pass such work to user space
1349 +helper, instead of doing in kernel space. Actually I am still thinking
1350 +about it. But currently I have implemented it in kernel space.
1351 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1352 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1353 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2017-03-02 14:24:13.850255360 +0100
1356 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1358 +# This program is free software; you can redistribute it and/or modify
1359 +# it under the terms of the GNU General Public License as published by
1360 +# the Free Software Foundation; either version 2 of the License, or
1361 +# (at your option) any later version.
1363 +# This program is distributed in the hope that it will be useful,
1364 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1365 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1366 +# GNU General Public License for more details.
1368 +# You should have received a copy of the GNU General Public License
1369 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1371 +Basic Aufs Internal Structure
1373 +Superblock/Inode/Dentry/File Objects
1374 +----------------------------------------------------------------------
1375 +As like an ordinary filesystem, aufs has its own
1376 +superblock/inode/dentry/file objects. All these objects have a
1377 +dynamically allocated array and store the same kind of pointers to the
1378 +lower filesystem, branch.
1379 +For example, when you build a union with one readwrite branch and one
1380 +readonly, mounted /au, /rw and /ro respectively.
1382 +- /ro/fileA exists but /rw/fileA
1384 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1385 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1386 +- [0] = NULL (because /rw/fileA doesn't exist)
1389 +This style of an array is essentially same to the aufs
1390 +superblock/inode/dentry/file objects.
1392 +Because aufs supports manipulating branches, ie. add/delete/change
1393 +branches dynamically, these objects has its own generation. When
1394 +branches are changed, the generation in aufs superblock is
1395 +incremented. And a generation in other object are compared when it is
1396 +accessed. When a generation in other objects are obsoleted, aufs
1397 +refreshes the internal array.
1401 +----------------------------------------------------------------------
1402 +Additionally aufs superblock has some data for policies to select one
1403 +among multiple writable branches, XIB files, pseudo-links and kobject.
1404 +See below in detail.
1405 +About the policies which supports copy-down a directory, see
1406 +wbr_policy.txt too.
1409 +Branch and XINO(External Inode Number Translation Table)
1410 +----------------------------------------------------------------------
1411 +Every branch has its own xino (external inode number translation table)
1412 +file. The xino file is created and unlinked by aufs internally. When two
1413 +members of a union exist on the same filesystem, they share the single
1415 +The struct of a xino file is simple, just a sequence of aufs inode
1416 +numbers which is indexed by the lower inode number.
1417 +In the above sample, assume the inode number of /ro/fileA is i111 and
1418 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1419 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1421 +When the inode numbers are not contiguous, the xino file will be sparse
1422 +which has a hole in it and doesn't consume as much disk space as it
1423 +might appear. If your branch filesystem consumes disk space for such
1424 +holes, then you should specify 'xino=' option at mounting aufs.
1426 +Aufs has a mount option to free the disk blocks for such holes in XINO
1427 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1428 +meet a problem of disk shortage due to XINO files, then you should try
1429 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1430 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1431 +the holes in XINO files.
1433 +Also a writable branch has three kinds of "whiteout bases". All these
1434 +are existed when the branch is joined to aufs, and their names are
1435 +whiteout-ed doubly, so that users will never see their names in aufs
1437 +1. a regular file which will be hardlinked to all whiteouts.
1438 +2. a directory to store a pseudo-link.
1439 +3. a directory to store an "orphan"-ed file temporary.
1442 + When you remove a file on a readonly branch, aufs handles it as a
1443 + logical deletion and creates a whiteout on the upper writable branch
1444 + as a hardlink of this file in order not to consume inode on the
1447 + See below, Pseudo-link.
1449 + When "fileC" exists on the lower readonly branch only and it is
1450 + opened and removed with its parent dir, and then user writes
1451 + something into it, then aufs copies-up fileC to this
1452 + directory. Because there is no other dir to store fileC. After
1453 + creating a file under this dir, the file is unlinked.
1455 +Because aufs supports manipulating branches, ie. add/delete/change
1456 +dynamically, a branch has its own id. When the branch order changes,
1457 +aufs finds the new index by searching the branch id.
1461 +----------------------------------------------------------------------
1462 +Assume "fileA" exists on the lower readonly branch only and it is
1463 +hardlinked to "fileB" on the branch. When you write something to fileA,
1464 +aufs copies-up it to the upper writable branch. Additionally aufs
1465 +creates a hardlink under the Pseudo-link Directory of the writable
1466 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1467 +simple list. If fileB is read after unlinking fileA, aufs returns
1468 +filedata from the pseudo-link instead of the lower readonly
1469 +branch. Because the pseudo-link is based upon the inode, to keep the
1470 +inode number by xino (see above) is essentially necessary.
1472 +All the hardlinks under the Pseudo-link Directory of the writable branch
1473 +should be restored in a proper location later. Aufs provides a utility
1474 +to do this. The userspace helpers executed at remounting and unmounting
1476 +During this utility is running, it puts aufs into the pseudo-link
1477 +maintenance mode. In this mode, only the process which began the
1478 +maintenance mode (and its child processes) is allowed to operate in
1479 +aufs. Some other processes which are not related to the pseudo-link will
1480 +be allowed to run too, but the rest have to return an error or wait
1481 +until the maintenance mode ends. If a process already acquires an inode
1482 +mutex (in VFS), it has to return an error.
1485 +XIB(external inode number bitmap)
1486 +----------------------------------------------------------------------
1487 +Addition to the xino file per a branch, aufs has an external inode number
1488 +bitmap in a superblock object. It is also an internal file such like a
1490 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1492 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1494 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1495 +reduce the number of consumed disk blocks for these files.
1498 +Virtual or Vertical Dir, and Readdir in Userspace
1499 +----------------------------------------------------------------------
1500 +In order to support multiple layers (branches), aufs readdir operation
1501 +constructs a virtual dir block on memory. For readdir, aufs calls
1502 +vfs_readdir() internally for each dir on branches, merges their entries
1503 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1504 +object. So the file object has its entry list until it is closed. The
1505 +entry list will be updated when the file position is zero and becomes
1506 +obsoleted. This decision is made in aufs automatically.
1508 +The dynamically allocated memory block for the name of entries has a
1509 +unit of 512 bytes (by default) and stores the names contiguously (no
1510 +padding). Another block for each entry is handled by kmem_cache too.
1511 +During building dir blocks, aufs creates hash list and judging whether
1512 +the entry is whiteouted by its upper branch or already listed.
1513 +The merged result is cached in the corresponding inode object and
1514 +maintained by a customizable life-time option.
1516 +Some people may call it can be a security hole or invite DoS attack
1517 +since the opened and once readdir-ed dir (file object) holds its entry
1518 +list and becomes a pressure for system memory. But I'd say it is similar
1519 +to files under /proc or /sys. The virtual files in them also holds a
1520 +memory page (generally) while they are opened. When an idea to reduce
1521 +memory for them is introduced, it will be applied to aufs too.
1522 +For those who really hate this situation, I've developed readdir(3)
1523 +library which operates this merging in userspace. You just need to set
1524 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1525 +kernel space for readdir(3).
1529 +----------------------------------------------------------------------
1530 +Aufs sometimes requires privilege access to a branch. For instance,
1531 +in copy-up/down operation. When a user process is going to make changes
1532 +to a file which exists in the lower readonly branch only, and the mode
1533 +of one of ancestor directories may not be writable by a user
1534 +process. Here aufs copy-up the file with its ancestors and they may
1535 +require privilege to set its owner/group/mode/etc.
1536 +This is a typical case of a application character of aufs (see
1539 +Aufs uses workqueue synchronously for this case. It creates its own
1540 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1541 +passes the request to call mkdir or write (for example), and wait for
1542 +its completion. This approach solves a problem of a signal handler
1544 +If aufs didn't adopt the workqueue and changed the privilege of the
1545 +process, then the process may receive the unexpected SIGXFSZ or other
1548 +Also aufs uses the system global workqueue ("events" kernel thread) too
1549 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1550 +whiteout base and etc. This is unrelated to a privilege.
1551 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1552 +superblock at the beginning, at the same time waits for the completion
1553 +of all queued asynchronous tasks.
1557 +----------------------------------------------------------------------
1558 +The whiteout in aufs is very similar to Unionfs's. That is represented
1559 +by its filename. UnionMount takes an approach of a file mode, but I am
1560 +afraid several utilities (find(1) or something) will have to support it.
1562 +Basically the whiteout represents "logical deletion" which stops aufs to
1563 +lookup further, but also it represents "dir is opaque" which also stop
1566 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1567 +In order to make several functions in a single systemcall to be
1568 +revertible, aufs adopts an approach to rename a directory to a temporary
1569 +unique whiteouted name.
1570 +For example, in rename(2) dir where the target dir already existed, aufs
1571 +renames the target dir to a temporary unique whiteouted name before the
1572 +actual rename on a branch, and then handles other actions (make it opaque,
1573 +update the attributes, etc). If an error happens in these actions, aufs
1574 +simply renames the whiteouted name back and returns an error. If all are
1575 +succeeded, aufs registers a function to remove the whiteouted unique
1576 +temporary name completely and asynchronously to the system global
1581 +----------------------------------------------------------------------
1582 +It is a well-known feature or concept.
1583 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1584 +internally and makes change to the new file on the upper writable branch.
1585 +When the trigger systemcall does not update the timestamps of the parent
1586 +dir, aufs reverts it after copy-up.
1589 +Move-down (aufs3.9 and later)
1590 +----------------------------------------------------------------------
1591 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1592 +the lower readonly branch to the upper writable branch when a user
1593 +changes something about the file.
1594 +"Move-down" is an opposite action of copy-up. Basically this action is
1595 +ran manually instead of automatically and internally.
1596 +For desgin and implementation, aufs has to consider these issues.
1597 +- whiteout for the file may exist on the lower branch.
1598 +- ancestor directories may not exist on the lower branch.
1599 +- diropq for the ancestor directories may exist on the upper branch.
1600 +- free space on the lower branch will reduce.
1601 +- another access to the file may happen during moving-down, including
1602 + UDBA (see "Revalidate Dentry and UDBA").
1603 +- the file should not be hard-linked nor pseudo-linked. they should be
1604 + handled by auplink utility later.
1606 +Sometimes users want to move-down a file from the upper writable branch
1607 +to the lower readonly or writable branch. For instance,
1608 +- the free space of the upper writable branch is going to run out.
1609 +- create a new intermediate branch between the upper and lower branch.
1612 +For this purpose, use "aumvdown" command in aufs-util.git.
1613 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1614 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1615 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2017-03-02 14:24:13.850255360 +0100
1618 +# Copyright (C) 2015-2017 Junjiro R. Okajima
1620 +# This program is free software; you can redistribute it and/or modify
1621 +# it under the terms of the GNU General Public License as published by
1622 +# the Free Software Foundation; either version 2 of the License, or
1623 +# (at your option) any later version.
1625 +# This program is distributed in the hope that it will be useful,
1626 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1627 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1628 +# GNU General Public License for more details.
1630 +# You should have received a copy of the GNU General Public License
1631 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1633 +Support for a branch who has its ->atomic_open()
1634 +----------------------------------------------------------------------
1635 +The filesystems who implement its ->atomic_open() are not majority. For
1636 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1637 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1638 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1639 +sure whether all filesystems who have ->atomic_open() behave like this,
1640 +but NFSv4 surely returns the error.
1642 +In order to support ->atomic_open() for aufs, there are a few
1645 +A. Introduce aufs_atomic_open()
1646 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1648 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1649 + an aufs user Pip Cet's approach
1650 + - calls aufs_create(), VFS finish_open() and notify_change().
1651 + - pass fake-mode to finish_open(), and then correct the mode by
1653 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1654 + - no aufs_atomic_open().
1655 + - aufs_lookup() registers the TID to an aufs internal object.
1656 + - aufs_create() does nothing when the matching TID is registered, but
1657 + registers the mode.
1658 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1659 + TID is registered.
1660 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1662 + - no aufs_atomic_open().
1663 + - aufs_create() registers the TID to an internal object. this info
1664 + represents "this process created this file just now."
1665 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1666 + registered TID and re-try open() with superuser's credential.
1668 +Pros and cons for each approach.
1671 + - straightforward but highly depends upon VFS internal.
1672 + - the atomic behavaiour is kept.
1673 + - some of parameters such as nameidata are hard to reproduce for
1677 + - easy to implement.
1678 + - the atomic behavaiour is lost.
1680 + - the atomic behavaiour is kept.
1681 + - dirty and tricky.
1682 + - VFS checks whether the file is created correctly after calling
1683 + ->create(), which means this approach doesn't work.
1685 + - easy to implement.
1686 + - the atomic behavaiour is lost.
1687 + - to open a file with superuser's credential and give it to a user
1688 + process is a bad idea, since the file object keeps the credential
1689 + in it. It may affect LSM or something. This approach doesn't work
1692 +The approach A is ideal, but it hard to implement. So here is a
1693 +variation of A, which is to be implemented.
1695 +A-1. Introduce aufs_atomic_open()
1696 + - calls branch fs ->atomic_open() if exists. otherwise calls
1697 + vfs_create() and finish_open().
1698 + - the demerit is that the several checks after branch fs
1699 + ->atomic_open() are lost. in the ordinary case, the checks are
1700 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1701 + be implemented in aufs, but not all I am afraid.
1702 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1703 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1704 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2017-03-02 14:24:13.850255360 +0100
1707 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1709 +# This program is free software; you can redistribute it and/or modify
1710 +# it under the terms of the GNU General Public License as published by
1711 +# the Free Software Foundation; either version 2 of the License, or
1712 +# (at your option) any later version.
1714 +# This program is distributed in the hope that it will be useful,
1715 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1716 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717 +# GNU General Public License for more details.
1719 +# You should have received a copy of the GNU General Public License
1720 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1723 +----------------------------------------------------------------------
1724 +Since aufs has a character of sub-VFS (see Introduction), it operates
1725 +lookup for branches as VFS does. It may be a heavy work. But almost all
1726 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1727 +directly connected to its parent. Digging down the directory hierarchy
1728 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1731 +When a branch is a remote filesystem, aufs basically relies upon its
1732 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1734 +For d_revalidate, aufs implements three levels of revalidate tests. See
1735 +"Revalidate Dentry and UDBA" in detail.
1738 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1739 +----------------------------------------------------------------------
1740 +Let's try case study.
1741 +- aufs has two branches, upper readwrite and lower readonly.
1743 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1744 +- user invoked "chmod a+rx /au/dirA"
1745 +- the internal copy-up is activated and "/rw/dirA" is created and its
1746 + permission bits are set to world readable.
1747 +- then "/au/dirA" becomes world readable?
1749 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1750 +or it may be a natively readonly filesystem. If aufs respects the lower
1751 +branch, it should not respond readdir request from other users. But user
1752 +allowed it by chmod. Should really aufs rejects showing the entries
1755 +To be honest, I don't have a good solution for this case. So aufs
1756 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1758 +When dirperm1 is specified, aufs checks only the highest one for the
1759 +directory permission, and shows the entries. Otherwise, as usual, checks
1760 +every dir existing on all branches and rejects the request.
1762 +As a side effect, dirperm1 option improves the performance of aufs
1763 +because the number of permission check is reduced when the number of
1767 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1768 +----------------------------------------------------------------------
1769 +Generally VFS helpers re-validate a dentry as a part of lookup.
1770 +0. digging down the directory hierarchy.
1771 +1. lock the parent dir by its i_mutex.
1772 +2. lookup the final (child) entry.
1774 +4. call the actual operation (create, unlink, etc.)
1775 +5. unlock the parent dir
1777 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1778 +called. Actually aufs implements it and checks the dentry on a branch is
1780 +But it is not enough. Because aufs has to release the lock for the
1781 +parent dir on a branch at the end of ->lookup() (step 2) and
1782 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1784 +If the file on a branch is changed directly, eg. bypassing aufs, after
1785 +aufs released the lock, then the subsequent operation may cause
1786 +something unpleasant result.
1788 +This situation is a result of VFS architecture, ->lookup() and
1789 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1790 +design from VFS's point of view. It is just not suitable for sub-VFS
1793 +Aufs supports such case by three level of revalidation which is
1794 +selectable by user.
1795 +1. Simple Revalidate
1796 + Addition to the native flow in VFS's, confirm the child-parent
1797 + relationship on the branch just after locking the parent dir on the
1798 + branch in the "actual operation" (step 4). When this validation
1799 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1800 + checks the validation of the dentry on branches.
1801 +2. Monitor Changes Internally by Inotify/Fsnotify
1802 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1803 + the dentry on the branch, and returns EBUSY if it finds different
1805 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1806 + during it is in cache. When the event is notified, aufs registers a
1807 + function to kernel 'events' thread by schedule_work(). And the
1808 + function sets some special status to the cached aufs dentry and inode
1809 + private data. If they are not cached, then aufs has nothing to
1810 + do. When the same file is accessed through aufs (step 0-3) later,
1811 + aufs will detect the status and refresh all necessary data.
1812 + In this mode, aufs has to ignore the event which is fired by aufs
1814 +3. No Extra Validation
1815 + This is the simplest test and doesn't add any additional revalidation
1816 + test, and skip the revalidation in step 4. It is useful and improves
1817 + aufs performance when system surely hide the aufs branches from user,
1818 + by over-mounting something (or another method).
1819 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1820 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1821 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2017-03-02 14:24:13.850255360 +0100
1824 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1826 +# This program is free software; you can redistribute it and/or modify
1827 +# it under the terms of the GNU General Public License as published by
1828 +# the Free Software Foundation; either version 2 of the License, or
1829 +# (at your option) any later version.
1831 +# This program is distributed in the hope that it will be useful,
1832 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1833 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1834 +# GNU General Public License for more details.
1836 +# You should have received a copy of the GNU General Public License
1837 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1839 +Branch Manipulation
1841 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1842 +and changing its permission/attribute, there are a lot of works to do.
1846 +----------------------------------------------------------------------
1847 +o Confirm the adding dir exists outside of aufs, including loopback
1848 + mount, and its various attributes.
1849 +o Initialize the xino file and whiteout bases if necessary.
1852 +o Check the owner/group/mode of the directory
1853 + When the owner/group/mode of the adding directory differs from the
1854 + existing branch, aufs issues a warning because it may impose a
1856 + For example, when a upper writable branch has a world writable empty
1857 + top directory, a malicious user can create any files on the writable
1858 + branch directly, like copy-up and modify manually. If something like
1859 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1860 + writable branch, and the writable branch is world-writable, then a
1861 + malicious guy may create /etc/passwd on the writable branch directly
1862 + and the infected file will be valid in aufs.
1863 + I am afraid it can be a security issue, but aufs can do nothing except
1864 + producing a warning.
1868 +----------------------------------------------------------------------
1869 +o Confirm the deleting branch is not busy
1870 + To be general, there is one merit to adopt "remount" interface to
1871 + manipulate branches. It is to discard caches. At deleting a branch,
1872 + aufs checks the still cached (and connected) dentries and inodes. If
1873 + there are any, then they are all in-use. An inode without its
1874 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1876 + For the cached one, aufs checks whether the same named entry exists on
1878 + If the cached one is a directory, because aufs provides a merged view
1879 + to users, as long as one dir is left on any branch aufs can show the
1880 + dir to users. In this case, the branch can be removed from aufs.
1881 + Otherwise aufs rejects deleting the branch.
1883 + If any file on the deleting branch is opened by aufs, then aufs
1887 +Modify the Permission of a Branch
1888 +----------------------------------------------------------------------
1889 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1892 +o rw --> ro: Confirm the modifying branch is not busy
1893 + Aufs rejects the request if any of these conditions are true.
1894 + - a file on the branch is mmap-ed.
1895 + - a regular file on the branch is opened for write and there is no
1896 + same named entry on the upper branch.
1897 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1898 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1899 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2017-03-02 14:24:13.850255360 +0100
1902 +# Copyright (C) 2005-2017 Junjiro R. Okajima
1904 +# This program is free software; you can redistribute it and/or modify
1905 +# it under the terms of the GNU General Public License as published by
1906 +# the Free Software Foundation; either version 2 of the License, or
1907 +# (at your option) any later version.
1909 +# This program is distributed in the hope that it will be useful,
1910 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1911 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1912 +# GNU General Public License for more details.
1914 +# You should have received a copy of the GNU General Public License
1915 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1917 +Policies to Select One among Multiple Writable Branches
1918 +----------------------------------------------------------------------
1919 +When the number of writable branch is more than one, aufs has to decide
1920 +the target branch for file creation or copy-up. By default, the highest
1921 +writable branch which has the parent (or ancestor) dir of the target
1922 +file is chosen (top-down-parent policy).
1923 +By user's request, aufs implements some other policies to select the
1924 +writable branch, for file creation several policies, round-robin,
1925 +most-free-space, and other policies. For copy-up, top-down-parent,
1926 +bottom-up-parent, bottom-up and others.
1928 +As expected, the round-robin policy selects the branch in circular. When
1929 +you have two writable branches and creates 10 new files, 5 files will be
1930 +created for each branch. mkdir(2) systemcall is an exception. When you
1931 +create 10 new directories, all will be created on the same branch.
1932 +And the most-free-space policy selects the one which has most free
1933 +space among the writable branches. The amount of free space will be
1934 +checked by aufs internally, and users can specify its time interval.
1936 +The policies for copy-up is more simple,
1937 +top-down-parent is equivalent to the same named on in create policy,
1938 +bottom-up-parent selects the writable branch where the parent dir
1939 +exists and the nearest upper one from the copyup-source,
1940 +bottom-up selects the nearest upper writable branch from the
1941 +copyup-source, regardless the existence of the parent dir.
1943 +There are some rules or exceptions to apply these policies.
1944 +- If there is a readonly branch above the policy-selected branch and
1945 + the parent dir is marked as opaque (a variation of whiteout), or the
1946 + target (creating) file is whiteout-ed on the upper readonly branch,
1947 + then the result of the policy is ignored and the target file will be
1948 + created on the nearest upper writable branch than the readonly branch.
1949 +- If there is a writable branch above the policy-selected branch and
1950 + the parent dir is marked as opaque or the target file is whiteouted
1951 + on the branch, then the result of the policy is ignored and the target
1952 + file will be created on the highest one among the upper writable
1953 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1955 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1956 + They try selecting the branch where the source exists as possible
1957 + since copyup a large file will take long time. If it can't be,
1958 + ie. the branch where the source exists is readonly, then they will
1959 + follow the copyup policy.
1960 +- There is an exception for rename(2) when the target exists.
1961 + If the rename target exists, aufs compares the index of the branches
1962 + where the source and the target exists and selects the higher
1963 + one. If the selected branch is readonly, then aufs follows the
1965 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1966 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1967 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2017-03-02 14:24:13.850255360 +0100
1970 +# Copyright (C) 2011-2017 Junjiro R. Okajima
1972 +# This program is free software; you can redistribute it and/or modify
1973 +# it under the terms of the GNU General Public License as published by
1974 +# the Free Software Foundation; either version 2 of the License, or
1975 +# (at your option) any later version.
1977 +# This program is distributed in the hope that it will be useful,
1978 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1979 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1980 +# GNU General Public License for more details.
1982 +# You should have received a copy of the GNU General Public License
1983 +# along with this program; if not, write to the Free Software
1984 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1987 +File-based Hierarchical Storage Management (FHSM)
1988 +----------------------------------------------------------------------
1989 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1990 +storage world. Aufs provides this feature as file-based with multiple
1991 +writable branches, based upon the principle of "Colder, the Lower".
1992 +Here the word "colder" means that the less used files, and "lower" means
1993 +that the position in the order of the stacked branches vertically.
1994 +These multiple writable branches are prioritized, ie. the topmost one
1995 +should be the fastest drive and be used heavily.
1997 +o Characters in aufs FHSM story
1998 +- aufs itself and a new branch attribute.
1999 +- a new ioctl interface to move-down and to establish a connection with
2000 + the daemon ("move-down" is a converse of "copy-up").
2001 +- userspace tool and daemon.
2003 +The userspace daemon establishes a connection with aufs and waits for
2004 +the notification. The notified information is very similar to struct
2005 +statfs containing the number of consumed blocks and inodes.
2006 +When the consumed blocks/inodes of a branch exceeds the user-specified
2007 +upper watermark, the daemon activates its move-down process until the
2008 +consumed blocks/inodes reaches the user-specified lower watermark.
2010 +The actual move-down is done by aufs based upon the request from
2011 +user-space since we need to maintain the inode number and the internal
2012 +pointer arrays in aufs.
2014 +Currently aufs FHSM handles the regular files only. Additionally they
2015 +must not be hard-linked nor pseudo-linked.
2018 +o Cowork of aufs and the user-space daemon
2019 + During the userspace daemon established the connection, aufs sends a
2020 + small notification to it whenever aufs writes something into the
2021 + writable branch. But it may cost high since aufs issues statfs(2)
2022 + internally. So user can specify a new option to cache the
2023 + info. Actually the notification is controlled by these factors.
2024 + + the specified cache time.
2025 + + classified as "force" by aufs internally.
2026 + Until the specified time expires, aufs doesn't send the info
2027 + except the forced cases. When aufs decide forcing, the info is always
2028 + notified to userspace.
2029 + For example, the number of free inodes is generally large enough and
2030 + the shortage of it happens rarely. So aufs doesn't force the
2031 + notification when creating a new file, directory and others. This is
2032 + the typical case which aufs doesn't force.
2033 + When aufs writes the actual filedata and the files consumes any of new
2034 + blocks, the aufs forces notifying.
2037 +o Interfaces in aufs
2038 +- New branch attribute.
2040 + Specifies that the branch is managed by FHSM feature. In other word,
2041 + participant in the FHSM.
2042 + When nofhsm is set to the branch, it will not be the source/target
2043 + branch of the move-down operation. This attribute is set
2044 + independently from coo and moo attributes, and if you want full
2045 + FHSM, you should specify them as well.
2046 +- New mount option.
2048 + Specifies a second to suppress many less important info to be
2051 + + AUFS_CTL_FHSM_FD
2052 + create a new file descriptor which userspace can read the notification
2053 + (a subset of struct statfs) from aufs.
2054 +- Module parameter 'brs'
2055 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2057 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2058 + When there are two or more branches with fhsm attributes,
2059 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2060 + terminates it. As a result of remounting and branch-manipulation, the
2061 + number of branches with fhsm attribute can be one. In this case,
2062 + /sbin/mount.aufs will terminate the user-space daemon.
2065 +Finally the operation is done as these steps in kernel-space.
2067 + + no one else is using the file.
2068 + + the file is not hard-linked.
2069 + + the file is not pseudo-linked.
2070 + + the file is a regular file.
2071 + + the parent dir is not opaqued.
2072 +- find the target writable branch.
2073 +- make sure the file is not whiteout-ed by the upper (than the target)
2075 +- make the parent dir on the target branch.
2076 +- mutex lock the inode on the branch.
2077 +- unlink the whiteout on the target branch (if exists).
2078 +- lookup and create the whiteout-ed temporary name on the target branch.
2079 +- copy the file as the whiteout-ed temporary name on the target branch.
2080 +- rename the whiteout-ed temporary name to the original name.
2081 +- unlink the file on the source branch.
2082 +- maintain the internal pointer array and the external inode number
2084 +- maintain the timestamps and other attributes of the parent dir and the
2087 +And of course, in every step, an error may happen. So the operation
2088 +should restore the original file state after an error happens.
2089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2090 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2091 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2017-03-02 14:24:13.853588785 +0100
2094 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2096 +# This program is free software; you can redistribute it and/or modify
2097 +# it under the terms of the GNU General Public License as published by
2098 +# the Free Software Foundation; either version 2 of the License, or
2099 +# (at your option) any later version.
2101 +# This program is distributed in the hope that it will be useful,
2102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2104 +# GNU General Public License for more details.
2106 +# You should have received a copy of the GNU General Public License
2107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2109 +mmap(2) -- File Memory Mapping
2110 +----------------------------------------------------------------------
2111 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2112 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2114 +This approach is simple and good, but there is one problem.
2115 +Under /proc, several entries show the mmapped files by its path (with
2116 +device and inode number), and the printed path will be the path on the
2117 +branch fs's instead of virtual aufs's.
2118 +This is not a problem in most cases, but some utilities lsof(1) (and its
2119 +user) may expect the path on aufs.
2121 +To address this issue, aufs adds a new member called vm_prfile in struct
2122 +vm_area_struct (and struct vm_region). The original vm_file points to
2123 +the file on the branch fs in order to handle everything correctly as
2124 +usual. The new vm_prfile points to a virtual file in aufs, and the
2125 +show-functions in procfs refers to vm_prfile if it is set.
2126 +Also we need to maintain several other places where touching vm_file
2128 +- fork()/clone() copies vma and the reference count of vm_file is
2130 +- merging vma maintains the ref count too.
2132 +This is not a good approach. It just fakes the printed path. But it
2133 +leaves all behaviour around f_mapping unchanged. This is surely an
2135 +Actually aufs had adopted another complicated approach which calls
2136 +generic_file_mmap() and handles struct vm_operations_struct. In this
2137 +approach, aufs met a hard problem and I could not solve it without
2138 +switching the approach.
2140 +There may be one more another approach which is
2141 +- bind-mount the branch-root onto the aufs-root internally
2142 +- grab the new vfsmount (ie. struct mount)
2143 +- lazy-umount the branch-root internally
2144 +- in open(2) the aufs-file, open the branch-file with the hidden
2145 + vfsmount (instead of the original branch's vfsmount)
2146 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2147 + but it may be possible from userspace by the mount helper.
2149 +Adding the internal hidden vfsmount and using it in opening a file, the
2150 +file path under /proc will be printed correctly. This approach looks
2151 +smarter, but is not possible I am afraid.
2152 +- aufs-root may be bind-mount later. when it happens, another hidden
2153 + vfsmount will be required.
2154 +- it is hard to get the chance to bind-mount and lazy-umount
2155 + + in kernel-space, FS can have vfsmount in open(2) via
2156 + file->f_path, and aufs can know its vfsmount. But several locks are
2157 + already acquired, and if aufs tries to bind-mount and lazy-umount
2158 + here, then it may cause a deadlock.
2159 + + in user-space, bind-mount doesn't invoke the mount helper.
2160 +- since /proc shows dev and ino, aufs has to give vma these info. it
2161 + means a new member vm_prinode will be necessary. this is essentially
2162 + equivalent to vm_prfile described above.
2164 +I have to give up this "looks-smater" approach.
2165 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2166 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2167 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2017-03-02 14:24:13.853588785 +0100
2170 +# Copyright (C) 2014-2017 Junjiro R. Okajima
2172 +# This program is free software; you can redistribute it and/or modify
2173 +# it under the terms of the GNU General Public License as published by
2174 +# the Free Software Foundation; either version 2 of the License, or
2175 +# (at your option) any later version.
2177 +# This program is distributed in the hope that it will be useful,
2178 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2179 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180 +# GNU General Public License for more details.
2182 +# You should have received a copy of the GNU General Public License
2183 +# along with this program; if not, write to the Free Software
2184 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2187 +Listing XATTR/EA and getting the value
2188 +----------------------------------------------------------------------
2189 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2190 +shows the values from the topmost existing file. This behaviour is good
2191 +for the non-dir entries since the bahaviour exactly matches the shown
2192 +information. But for the directories, aufs considers all the same named
2193 +entries on the lower branches. Which means, if one of the lower entry
2194 +rejects readdir call, then aufs returns an error even if the topmost
2195 +entry allows it. This behaviour is necessary to respect the branch fs's
2196 +security, but can make users confused since the user-visible standard
2197 +attributes don't match the behaviour.
2198 +To address this issue, aufs has a mount option called dirperm1 which
2199 +checks the permission for the topmost entry only, and ignores the lower
2200 +entry's permission.
2202 +A similar issue can happen around XATTR.
2203 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2204 +always set. Otherwise these very unpleasant situation would happen.
2205 +- listxattr(2) may return the duplicated entries.
2206 +- users may not be able to remove or reset the XATTR forever,
2209 +XATTR/EA support in the internal (copy,move)-(up,down)
2210 +----------------------------------------------------------------------
2211 +Generally the extended attributes of inode are categorized as these.
2212 +- "security" for LSM and capability.
2213 +- "system" for posix ACL, 'acl' mount option is required for the branch
2215 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2216 +- "user" for userspace, 'user_xattr' mount option is required for the
2217 + branch fs generally.
2219 +Moreover there are some other categories. Aufs handles these rather
2220 +unpopular categories as the ordinary ones, ie. there is no special
2221 +condition nor exception.
2223 +In copy-up, the support for XATTR on the dst branch may differ from the
2224 +src branch. In this case, the copy-up operation will get an error and
2225 +the original user operation which triggered the copy-up will fail. It
2226 +can happen that even all copy-up will fail.
2227 +When both of src and dst branches support XATTR and if an error occurs
2228 +during copying XATTR, then the copy-up should fail obviously. That is a
2229 +good reason and aufs should return an error to userspace. But when only
2230 +the src branch support that XATTR, aufs should not return an error.
2231 +For example, the src branch supports ACL but the dst branch doesn't
2232 +because the dst branch may natively un-support it or temporary
2233 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2234 +may NOT return an error even if the XATTR is not supported. It is
2235 +totally up to the branch fs.
2237 +Anyway when the aufs internal copy-up gets an error from the dst branch
2238 +fs, then aufs tries removing the just copied entry and returns the error
2239 +to the userspace. The worst case of this situation will be all copy-up
2242 +For the copy-up operation, there two basic approaches.
2243 +- copy the specified XATTR only (by category above), and return the
2244 + error unconditionally if it happens.
2245 +- copy all XATTR, and ignore the error on the specified category only.
2247 +In order to support XATTR and to implement the correct behaviour, aufs
2248 +chooses the latter approach and introduces some new branch attributes,
2249 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2250 +They correspond to the XATTR namespaces (see above). Additionally, to be
2251 +convenient, "icex" is also provided which means all "icex*" attributes
2252 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2254 +The meaning of these attributes is to ignore the error from setting
2255 +XATTR on that branch.
2256 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2257 +error from the dst branch according to the specified attributes.
2259 +Some XATTR may have its default value. The default value may come from
2260 +the parent dir or the environment. If the default value is set at the
2261 +file creating-time, it will be overwritten by copy-up.
2262 +Some contradiction may happen I am afraid.
2263 +Do we need another attribute to stop copying XATTR? I am unsure. For
2264 +now, aufs implements the branch attributes to ignore the error.
2265 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2266 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2267 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2017-03-02 14:24:13.853588785 +0100
2270 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2272 +# This program is free software; you can redistribute it and/or modify
2273 +# it under the terms of the GNU General Public License as published by
2274 +# the Free Software Foundation; either version 2 of the License, or
2275 +# (at your option) any later version.
2277 +# This program is distributed in the hope that it will be useful,
2278 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2279 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2280 +# GNU General Public License for more details.
2282 +# You should have received a copy of the GNU General Public License
2283 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2285 +Export Aufs via NFS
2286 +----------------------------------------------------------------------
2287 +Here is an approach.
2288 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2290 +- iget_locked(): initialize aufs inode generation for a new inode, and
2291 + store it in xigen file.
2292 +- destroy_inode(): increment aufs inode generation and store it in xigen
2293 + file. it is necessary even if it is not unlinked, because any data of
2294 + inode may be changed by UDBA.
2295 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2296 + build file handle by
2297 + + branch id (4 bytes)
2298 + + superblock generation (4 bytes)
2299 + + inode number (4 or 8 bytes)
2300 + + parent dir inode number (4 or 8 bytes)
2301 + + inode generation (4 bytes))
2302 + + return value of exportfs_encode_fh() for the parent on a branch (4
2304 + + file handle for a branch (by exportfs_encode_fh())
2306 + + find the index of a branch from its id in handle, and check it is
2307 + still exist in aufs.
2308 + + 1st level: get the inode number from handle and search it in cache.
2309 + + 2nd level: if not found in cache, get the parent inode number from
2310 + the handle and search it in cache. and then open the found parent
2311 + dir, find the matching inode number by vfs_readdir() and get its
2312 + name, and call lookup_one_len() for the target dentry.
2313 + + 3rd level: if the parent dir is not cached, call
2314 + exportfs_decode_fh() for a branch and get the parent on a branch,
2315 + build a pathname of it, convert it a pathname in aufs, call
2316 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2318 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2319 + for every branch, but not itself. to get this, (currently) aufs
2320 + searches in current->nsproxy->mnt_ns list. it may not be a good
2321 + idea, but I didn't get other approach.
2322 + + test the generation of the gotten inode.
2323 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2324 + convert it into ESTALE for NFSD.
2325 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2326 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2327 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2328 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2329 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2017-03-02 14:24:13.853588785 +0100
2332 +# Copyright (C) 2005-2017 Junjiro R. Okajima
2334 +# This program is free software; you can redistribute it and/or modify
2335 +# it under the terms of the GNU General Public License as published by
2336 +# the Free Software Foundation; either version 2 of the License, or
2337 +# (at your option) any later version.
2339 +# This program is distributed in the hope that it will be useful,
2340 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2341 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2342 +# GNU General Public License for more details.
2344 +# You should have received a copy of the GNU General Public License
2345 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2347 +Show Whiteout Mode (shwh)
2348 +----------------------------------------------------------------------
2349 +Generally aufs hides the name of whiteouts. But in some cases, to show
2350 +them is very useful for users. For instance, creating a new middle layer
2351 +(branch) by merging existing layers.
2353 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2354 +When you have three branches,
2355 +- Bottom: 'system', squashfs (underlying base system), read-only
2356 +- Middle: 'mods', squashfs, read-only
2357 +- Top: 'overlay', ram (tmpfs), read-write
2359 +The top layer is loaded at boot time and saved at shutdown, to preserve
2360 +the changes made to the system during the session.
2361 +When larger changes have been made, or smaller changes have accumulated,
2362 +the size of the saved top layer data grows. At this point, it would be
2363 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2364 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2365 +restoring save and load speed.
2367 +This merging is simplified by the use of another aufs mount, of just the
2368 +two overlay branches using the 'shwh' option.
2369 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2370 + aufs /livesys/merge_union
2372 +A merged view of these two branches is then available at
2373 +/livesys/merge_union, and the new feature is that the whiteouts are
2375 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2376 +writing to all branches. Also the default mode for all branches is 'ro'.
2377 +It is now possible to save the combined contents of the two overlay
2378 +branches to a new squashfs, e.g.:
2379 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2381 +This new squashfs archive can be stored on the boot device and the
2382 +initramfs will use it to replace the old one at the next boot.
2383 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2384 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2385 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2017-03-02 14:24:13.853588785 +0100
2388 +# Copyright (C) 2010-2017 Junjiro R. Okajima
2390 +# This program is free software; you can redistribute it and/or modify
2391 +# it under the terms of the GNU General Public License as published by
2392 +# the Free Software Foundation; either version 2 of the License, or
2393 +# (at your option) any later version.
2395 +# This program is distributed in the hope that it will be useful,
2396 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2397 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2398 +# GNU General Public License for more details.
2400 +# You should have received a copy of the GNU General Public License
2401 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2403 +Dynamically customizable FS operations
2404 +----------------------------------------------------------------------
2405 +Generally FS operations (struct inode_operations, struct
2406 +address_space_operations, struct file_operations, etc.) are defined as
2407 +"static const", but it never means that FS have only one set of
2408 +operation. Some FS have multiple sets of them. For instance, ext2 has
2409 +three sets, one for XIP, for NOBH, and for normal.
2410 +Since aufs overrides and redirects these operations, sometimes aufs has
2411 +to change its behaviour according to the branch FS type. More importantly
2412 +VFS acts differently if a function (member in the struct) is set or
2413 +not. It means aufs should have several sets of operations and select one
2414 +among them according to the branch FS definition.
2416 +In order to solve this problem and not to affect the behaviour of VFS,
2417 +aufs defines these operations dynamically. For instance, aufs defines
2418 +dummy direct_IO function for struct address_space_operations, but it may
2419 +not be set to the address_space_operations actually. When the branch FS
2420 +doesn't have it, aufs doesn't set it to its address_space_operations
2421 +while the function definition itself is still alive. So the behaviour
2422 +itself will not change, and it will return an error when direct_IO is
2425 +The lifetime of these dynamically generated operation object is
2426 +maintained by aufs branch object. When the branch is removed from aufs,
2427 +the reference counter of the object is decremented. When it reaches
2428 +zero, the dynamically generated operation object will be freed.
2430 +This approach is designed to support AIO (io_submit), Direct I/O and
2432 +Currently this approach is applied to address_space_operations for
2433 +regular files only.
2434 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2435 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2436 +++ linux/Documentation/filesystems/aufs/README 2016-12-17 12:28:17.595211562 +0100
2439 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2445 +----------------------------------------
2446 +In the early days, aufs was entirely re-designed and re-implemented
2447 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2448 +improvements and implementations, it becomes totally different from
2449 +Unionfs while keeping the basic features.
2450 +Recently, Unionfs Version 2.x series begin taking some of the same
2451 +approaches to aufs1's.
2452 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2453 +University and his team.
2455 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2456 +If you want older kernel version support, try aufs2-2.6.git or
2457 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2459 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2460 + According to Christoph Hellwig, linux rejects all union-type
2461 + filesystems but UnionMount.
2462 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2464 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2465 + UnionMount, and he pointed out an issue around a directory mutex
2466 + lock and aufs addressed it. But it is still unsure whether aufs will
2467 + be merged (or any other union solution).
2468 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2472 +----------------------------------------
2473 +- unite several directories into a single virtual filesystem. The member
2474 + directory is called as a branch.
2475 +- you can specify the permission flags to the branch, which are 'readonly',
2476 + 'readwrite' and 'whiteout-able.'
2477 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2478 + readonly branch are modifiable logically.
2479 +- dynamic branch manipulation, add, del.
2482 +Also there are many enhancements in aufs, such as:
2483 +- test only the highest one for the directory permission (dirperm1)
2484 +- copyup on open (coo=)
2485 +- 'move' policy for copy-up between two writable branches, after
2486 + checking free space.
2488 +- readdir(3) in userspace.
2489 +- keep inode number by external inode number table
2490 +- keep the timestamps of file/dir in internal copyup operation
2491 +- seekable directory, supporting NFS readdir.
2492 +- whiteout is hardlinked in order to reduce the consumption of inodes
2494 +- do not copyup, nor create a whiteout when it is unnecessary
2495 +- revert a single systemcall when an error occurs in aufs
2496 +- remount interface instead of ioctl
2497 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2498 +- loopback mounted filesystem as a branch
2499 +- kernel thread for removing the dir who has a plenty of whiteouts
2500 +- support copyup sparse file (a file which has a 'hole' in it)
2501 +- default permission flags for branches
2502 +- selectable permission flags for ro branch, whether whiteout can
2505 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2506 +- support multiple writable branches, some policies to select one
2507 + among multiple writable branches.
2508 +- a new semantics for link(2) and rename(2) to support multiple
2509 + writable branches.
2510 +- no glibc changes are required.
2511 +- pseudo hardlink (hardlink over branches)
2512 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2513 + including NFS or remote filesystem branch.
2514 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2517 +Currently these features are dropped temporary from aufs4.
2518 +See design/08plan.txt in detail.
2519 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2521 +- statistics of aufs thread (/sys/fs/aufs/stat)
2523 +Features or just an idea in the future (see also design/*.txt),
2524 +- reorder the branch index without del/re-add.
2525 +- permanent xino files for NFSD
2526 +- an option for refreshing the opened files after add/del branches
2527 +- light version, without branch manipulation. (unnecessary?)
2528 +- copyup in userspace
2529 +- inotify in userspace
2534 +----------------------------------------
2535 +There are three GIT trees for aufs4, aufs4-linux.git,
2536 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2538 +While the aufs-util is always necessary, you need either of aufs4-linux
2539 +or aufs4-standalone.
2541 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2542 +git://git.kernel.org/.../torvalds/linux.git.
2543 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2544 +build aufs4 as an external kernel module.
2545 +Several extra patches are not included in this tree. Only
2546 +aufs4-standalone tree contains them. They are described in the later
2547 +section "Configuration and Compilation."
2549 +On the other hand, the aufs4-standalone tree has only aufs source files
2550 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2551 +But you need to apply all aufs patches manually.
2553 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2554 +represents the linux kernel version, "linux-4.x". For instance,
2555 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2556 +"aufs4.x-rcN" branch.
2559 +$ git clone --reference /your/linux/git/tree \
2560 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2561 +- if you don't have linux GIT tree, then remove "--reference ..."
2562 +$ cd aufs4-linux.git
2563 +$ git checkout origin/aufs4.0
2565 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2566 +leave the patch-work to GIT.
2567 +$ cd /your/linux/git/tree
2568 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2570 +$ git checkout -b my4.0 v4.0
2571 +$ (add your local change...)
2572 +$ git pull aufs4 aufs4.0
2573 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2574 +- you may need to solve some conflicts between your_changes and
2575 + aufs4.0. in this case, git-rerere is recommended so that you can
2576 + solve the similar conflicts automatically when you upgrade to 4.1 or
2577 + later in the future.
2579 +o aufs4-standalone tree
2580 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2581 +$ cd aufs4-standalone.git
2582 +$ git checkout origin/aufs4.0
2585 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2586 +- note that the public aufs-util.git is on SourceForge instead of
2589 +$ git checkout origin/aufs4.0
2591 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2592 +The minor version number, 'x' in '4.x', of aufs may not always
2593 +follow the minor version number of the kernel.
2594 +Because changes in the kernel that cause the use of a new
2595 +minor version number do not always require changes to aufs-util.
2597 +Since aufs-util has its own minor version number, you may not be
2598 +able to find a GIT branch in aufs-util for your kernel's
2599 +exact minor version number.
2600 +In this case, you should git-checkout the branch for the
2601 +nearest lower number.
2603 +For (an unreleased) example:
2604 +If you are using "linux-4.10" and the "aufs4.10" branch
2605 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2606 +or something numerically smaller is the branch for your kernel.
2608 +Also you can view all branches by
2612 +3. Configuration and Compilation
2613 +----------------------------------------
2614 +Make sure you have git-checkout'ed the correct branch.
2616 +For aufs4-linux tree,
2617 +- enable CONFIG_AUFS_FS.
2618 +- set other aufs configurations if necessary.
2620 +For aufs4-standalone tree,
2621 +There are several ways to build.
2624 +- apply ./aufs4-kbuild.patch to your kernel source files.
2625 +- apply ./aufs4-base.patch too.
2626 +- apply ./aufs4-mmap.patch too.
2627 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2628 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2629 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2630 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2631 +- enable CONFIG_AUFS_FS, you can select either
2633 +- and build your kernel as usual.
2634 +- install the built kernel.
2635 + Note: Since linux-3.9, every filesystem module requires an alias
2636 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2637 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2638 +- install the header files too by "make headers_install" to the
2639 + directory where you specify. By default, it is $PWD/usr.
2640 + "make help" shows a brief note for headers_install.
2641 +- and reboot your system.
2644 +- module only (CONFIG_AUFS_FS=m).
2645 +- apply ./aufs4-base.patch to your kernel source files.
2646 +- apply ./aufs4-mmap.patch too.
2647 +- apply ./aufs4-standalone.patch too.
2648 +- build your kernel, don't forget "make headers_install", and reboot.
2649 +- edit ./config.mk and set other aufs configurations if necessary.
2650 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2651 + every aufs configurations.
2652 +- build the module by simple "make".
2653 + Note: Since linux-3.9, every filesystem module requires an alias
2654 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2655 + modules.aliases file.
2656 +- you can specify ${KDIR} make variable which points to your kernel
2658 +- install the files
2659 + + run "make install" to install the aufs module, or copy the built
2660 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2661 + + run "make install_headers" (instead of headers_install) to install
2662 + the modified aufs header file (you can specify DESTDIR which is
2663 + available in aufs standalone version's Makefile only), or copy
2664 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2665 + you like manually. By default, the target directory is $PWD/usr.
2666 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2667 + kernel source tree.
2669 +Note: The header file aufs_type.h is necessary to build aufs-util
2670 + as well as "make headers_install" in the kernel source tree.
2671 + headers_install is subject to be forgotten, but it is essentially
2672 + necessary, not only for building aufs-util.
2673 + You may not meet problems without headers_install in some older
2677 +- read README in aufs-util, build and install it
2678 +- note that your distribution may contain an obsoleted version of
2679 + aufs_type.h in /usr/include/linux or something. When you build aufs
2680 + utilities, make sure that your compiler refers the correct aufs header
2681 + file which is built by "make headers_install."
2682 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2683 + then run "make install_ulib" too. And refer to the aufs manual in
2686 +There several other patches in aufs4-standalone.git. They are all
2687 +optional. When you meet some problems, they will help you.
2688 +- aufs4-loopback.patch
2689 + Supports a nested loopback mount in a branch-fs. This patch is
2690 + unnecessary until aufs produces a message like "you may want to try
2691 + another patch for loopback file".
2693 + Modifies a system global kernel internal function get_next_ino() in
2694 + order to stop assigning 0 for an inode-number. Not directly related to
2695 + aufs, but recommended generally.
2697 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2698 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2699 + duplication of inode number, which is important for backup tools and
2700 + other utilities. When you find aufs XINO files for tmpfs branch
2701 + growing too much, try this patch.
2702 +- lockdep-debug.patch
2703 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2704 + also a caller of VFS functions for branch filesystems, subclassing of
2705 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2706 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2707 + need to apply this debug patch to expand several constant values.
2708 + If don't know what LOCKDEP, then you don't have apply this patch.
2712 +----------------------------------------
2713 +At first, make sure aufs-util are installed, and please read the aufs
2714 +manual, aufs.5 in aufs-util.git tree.
2718 +$ mkdir /tmp/rw /tmp/aufs
2719 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2721 +Here is another example. The result is equivalent.
2722 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2724 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2725 +# mount -o remount,append:${HOME} /tmp/aufs
2727 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2728 +you modify a file under /tmp/aufs, the one on your home directory is
2729 +not affected, instead the same named file will be newly created under
2730 +/tmp/rw. And all of your modification to a file will be applied to
2731 +the one under /tmp/rw. This is called the file based Copy on Write
2733 +Aufs mount options are described in aufs.5.
2734 +If you run chroot or something and make your aufs as a root directory,
2735 +then you need to customize the shutdown script. See the aufs manual in
2738 +Additionally, there are some sample usages of aufs which are a
2739 +diskless system with network booting, and LiveCD over NFS.
2740 +See sample dir in CVS tree on SourceForge.
2744 +----------------------------------------
2745 +When you have any problems or strange behaviour in aufs, please let me
2747 +- /proc/mounts (instead of the output of mount(8))
2748 +- /sys/module/aufs/*
2749 +- /sys/fs/aufs/* (if you have them)
2750 +- /debug/aufs/* (if you have them)
2751 +- linux kernel version
2752 + if your kernel is not plain, for example modified by distributor,
2753 + the url where i can download its source is necessary too.
2754 +- aufs version which was printed at loading the module or booting the
2755 + system, instead of the date you downloaded.
2756 +- configuration (define/undefine CONFIG_AUFS_xxx)
2757 +- kernel configuration or /proc/config.gz (if you have it)
2758 +- behaviour which you think to be incorrect
2759 +- actual operation, reproducible one is better
2760 +- mailto: aufs-users at lists.sourceforge.net
2762 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2763 +and Feature Requests) on SourceForge. Please join and write to
2767 +6. Acknowledgements
2768 +----------------------------------------
2769 +Thanks to everyone who have tried and are using aufs, whoever
2770 +have reported a bug or any feedback.
2772 +Especially donators:
2773 +Tomas Matejicek(slax.org) made a donation (much more than once).
2774 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2775 + scripts) is making "doubling" donations.
2776 + Unfortunately I cannot list all of the donators, but I really
2778 + It ends Aug 2010, but the ordinary donation URL is still available.
2779 + <http://sourceforge.net/donate/index.php?group_id=167503>
2780 +Dai Itasaka made a donation (2007/8).
2781 +Chuck Smith made a donation (2008/4, 10 and 12).
2782 +Henk Schoneveld made a donation (2008/9).
2783 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2784 +Francois Dupoux made a donation (2008/11).
2785 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2786 + aufs2 GIT tree (2009/2).
2787 +William Grant made a donation (2009/3).
2788 +Patrick Lane made a donation (2009/4).
2789 +The Mail Archive (mail-archive.com) made donations (2009/5).
2790 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2791 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2792 +Pavel Pronskiy made a donation (2011/2).
2793 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2794 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2795 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2797 +Sam Liddicott made a donation (2011/9).
2798 +Era Scarecrow made a donation (2013/4).
2799 +Bor Ratajc made a donation (2013/4).
2800 +Alessandro Gorreta made a donation (2013/4).
2801 +POIRETTE Marc made a donation (2013/4).
2802 +Alessandro Gorreta made a donation (2013/4).
2803 +lauri kasvandik made a donation (2013/5).
2804 +"pemasu from Finland" made a donation (2013/7).
2805 +The Parted Magic Project made a donation (2013/9 and 11).
2806 +Pavel Barta made a donation (2013/10).
2807 +Nikolay Pertsev made a donation (2014/5).
2808 +James B made a donation (2014/7 and 2015/7).
2809 +Stefano Di Biase made a donation (2014/8).
2810 +Daniel Epellei made a donation (2015/1).
2811 +OmegaPhil made a donation (2016/1).
2812 +Tomasz Szewczyk made a donation (2016/4).
2813 +James Burry made a donation (2016/12).
2815 +Thank you very much.
2816 +Donations are always, including future donations, very important and
2817 +helpful for me to keep on developing aufs.
2821 +----------------------------------------
2822 +If you are an experienced user, no explanation is needed. Aufs is
2823 +just a linux filesystem.
2828 +# Local variables: ;
2831 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2832 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2833 +++ linux/fs/aufs/aufs.h 2017-03-02 14:24:13.853588785 +0100
2836 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2838 + * This program, aufs is free software; you can redistribute it and/or modify
2839 + * it under the terms of the GNU General Public License as published by
2840 + * the Free Software Foundation; either version 2 of the License, or
2841 + * (at your option) any later version.
2843 + * This program is distributed in the hope that it will be useful,
2844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846 + * GNU General Public License for more details.
2848 + * You should have received a copy of the GNU General Public License
2849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2853 + * all header files
2861 +#define AuStub(type, name, body, ...) \
2862 + static inline type name(__VA_ARGS__) { body; }
2864 +#define AuStubVoid(name, ...) \
2865 + AuStub(void, name, , __VA_ARGS__)
2866 +#define AuStubInt0(name, ...) \
2867 + AuStub(int, name, return 0, __VA_ARGS__)
2871 +#include "branch.h"
2874 +#include "dbgaufs.h"
2875 +#include "dentry.h"
2879 +#include "fstype.h"
2882 +#include "module.h"
2887 +#include "sysaufs.h"
2892 +#endif /* __KERNEL__ */
2893 +#endif /* __AUFS_H__ */
2894 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2895 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2896 +++ linux/fs/aufs/branch.c 2017-03-02 14:24:13.853588785 +0100
2899 + * Copyright (C) 2005-2017 Junjiro R. Okajima
2901 + * This program, aufs is free software; you can redistribute it and/or modify
2902 + * it under the terms of the GNU General Public License as published by
2903 + * the Free Software Foundation; either version 2 of the License, or
2904 + * (at your option) any later version.
2906 + * This program is distributed in the hope that it will be useful,
2907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2909 + * GNU General Public License for more details.
2911 + * You should have received a copy of the GNU General Public License
2912 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2916 + * branch management
2919 +#include <linux/compat.h>
2920 +#include <linux/statfs.h>
2924 + * free a single branch
2926 +static void au_br_do_free(struct au_branch *br)
2929 + struct au_wbr *wbr;
2930 + struct au_dykey **key;
2932 + au_hnotify_fin_br(br);
2934 + if (br->br_xino.xi_file)
2935 + fput(br->br_xino.xi_file);
2936 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2938 + AuDebugOn(au_br_count(br));
2939 + au_br_count_fin(br);
2943 + for (i = 0; i < AuBrWh_Last; i++)
2944 + dput(wbr->wbr_wh[i]);
2945 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2946 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2949 + if (br->br_fhsm) {
2950 + au_br_fhsm_fin(br->br_fhsm);
2951 + au_delayed_kfree(br->br_fhsm);
2954 + key = br->br_dykey;
2955 + for (i = 0; i < AuBrDynOp; i++, key++)
2961 + /* recursive lock, s_umount of branch's */
2963 + path_put(&br->br_path);
2966 + au_delayed_kfree(wbr);
2967 + au_delayed_kfree(br);
2971 + * frees all branches
2973 +void au_br_free(struct au_sbinfo *sbinfo)
2975 + aufs_bindex_t bmax;
2976 + struct au_branch **br;
2978 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2980 + bmax = sbinfo->si_bbot + 1;
2981 + br = sbinfo->si_branch;
2983 + au_br_do_free(*br++);
2987 + * find the index of a branch which is specified by @br_id.
2989 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2991 + aufs_bindex_t bindex, bbot;
2993 + bbot = au_sbbot(sb);
2994 + for (bindex = 0; bindex <= bbot; bindex++)
2995 + if (au_sbr_id(sb, bindex) == br_id)
3000 +/* ---------------------------------------------------------------------- */
3006 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3007 + struct dentry *h_root)
3009 + if (unlikely(h_adding == h_root
3010 + || au_test_loopback_overlap(sb, h_adding)))
3012 + if (h_adding->d_sb != h_root->d_sb)
3014 + return au_test_subdir(h_adding, h_root)
3015 + || au_test_subdir(h_root, h_adding);
3019 + * returns a newly allocated branch. @new_nbranch is a number of branches
3020 + * after adding a branch.
3022 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3025 + struct au_branch *add_branch;
3026 + struct dentry *root;
3027 + struct inode *inode;
3031 + root = sb->s_root;
3032 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3033 + if (unlikely(!add_branch))
3036 + err = au_hnotify_init_br(add_branch, perm);
3037 + if (unlikely(err))
3040 + if (au_br_writable(perm)) {
3041 + /* may be freed separately at changing the branch permission */
3042 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3044 + if (unlikely(!add_branch->br_wbr))
3048 + if (au_br_fhsm(perm)) {
3049 + err = au_fhsm_br_alloc(add_branch);
3050 + if (unlikely(err))
3054 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3056 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3058 + inode = d_inode(root);
3059 + err = au_hinode_realloc(au_ii(inode), new_nbranch, /*may_shrink*/0);
3062 + return add_branch; /* success */
3065 + if (add_branch->br_wbr)
3066 + au_delayed_kfree(add_branch->br_wbr);
3068 + au_hnotify_fin_br(add_branch);
3070 + au_delayed_kfree(add_branch);
3072 + return ERR_PTR(err);
3076 + * test if the branch permission is legal or not.
3078 +static int test_br(struct inode *inode, int brperm, char *path)
3082 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3087 + pr_err("write permission for readonly mount or inode, %s\n", path);
3095 + * 0: success, the caller will add it
3096 + * plus: success, it is already unified, the caller should ignore it
3099 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3102 + aufs_bindex_t bbot, bindex;
3103 + struct dentry *root, *h_dentry;
3104 + struct inode *inode, *h_inode;
3106 + root = sb->s_root;
3107 + bbot = au_sbbot(sb);
3108 + if (unlikely(bbot >= 0
3109 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3113 + pr_err("%s duplicated\n", add->pathname);
3118 + err = -ENOSPC; /* -E2BIG; */
3119 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3120 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3121 + pr_err("number of branches exceeded %s\n", add->pathname);
3126 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3127 + pr_err("bad index %d\n", add->bindex);
3131 + inode = d_inode(add->path.dentry);
3133 + if (unlikely(!inode->i_nlink)) {
3134 + pr_err("no existence %s\n", add->pathname);
3139 + if (unlikely(inode->i_sb == sb)) {
3140 + pr_err("%s must be outside\n", add->pathname);
3144 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3145 + pr_err("unsupported filesystem, %s (%s)\n",
3146 + add->pathname, au_sbtype(inode->i_sb));
3150 + if (unlikely(inode->i_sb->s_stack_depth)) {
3151 + pr_err("already stacked, %s (%s)\n",
3152 + add->pathname, au_sbtype(inode->i_sb));
3156 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3157 + if (unlikely(err))
3161 + return 0; /* success */
3164 + for (bindex = 0; bindex <= bbot; bindex++)
3165 + if (unlikely(test_overlap(sb, add->path.dentry,
3166 + au_h_dptr(root, bindex)))) {
3167 + pr_err("%s is overlapped\n", add->pathname);
3172 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3173 + h_dentry = au_h_dptr(root, 0);
3174 + h_inode = d_inode(h_dentry);
3175 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3176 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3177 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3178 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3180 + i_uid_read(inode), i_gid_read(inode),
3181 + (inode->i_mode & S_IALLUGO),
3182 + i_uid_read(h_inode), i_gid_read(h_inode),
3183 + (h_inode->i_mode & S_IALLUGO));
3191 + * initialize or clean the whiteouts for an adding branch
3193 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3196 + int err, old_perm;
3197 + aufs_bindex_t bindex;
3198 + struct inode *h_inode;
3199 + struct au_wbr *wbr;
3200 + struct au_hinode *hdir;
3201 + struct dentry *h_dentry;
3203 + err = vfsub_mnt_want_write(au_br_mnt(br));
3204 + if (unlikely(err))
3208 + old_perm = br->br_perm;
3209 + br->br_perm = new_perm;
3212 + bindex = au_br_index(sb, br->br_id);
3213 + if (0 <= bindex) {
3214 + hdir = au_hi(d_inode(sb->s_root), bindex);
3215 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3217 + h_dentry = au_br_dentry(br);
3218 + h_inode = d_inode(h_dentry);
3219 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3222 + err = au_wh_init(br, sb);
3224 + wbr_wh_write_lock(wbr);
3225 + err = au_wh_init(br, sb);
3226 + wbr_wh_write_unlock(wbr);
3229 + au_hn_inode_unlock(hdir);
3231 + inode_unlock(h_inode);
3232 + vfsub_mnt_drop_write(au_br_mnt(br));
3233 + br->br_perm = old_perm;
3235 + if (!err && wbr && !au_br_writable(new_perm)) {
3236 + au_delayed_kfree(wbr);
3237 + br->br_wbr = NULL;
3244 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3248 + struct kstatfs kst;
3249 + struct au_wbr *wbr;
3252 + au_rw_init(&wbr->wbr_wh_rwsem);
3253 + atomic_set(&wbr->wbr_wh_running, 0);
3256 + * a limit for rmdir/rename a dir
3257 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3259 + err = vfs_statfs(&br->br_path, &kst);
3260 + if (unlikely(err))
3263 + if (kst.f_namelen >= NAME_MAX)
3264 + err = au_br_init_wh(sb, br, perm);
3266 + pr_err("%pd(%s), unsupported namelen %ld\n",
3268 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3274 +/* initialize a new branch */
3275 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3276 + struct au_opt_add *add)
3279 + struct inode *h_inode;
3282 + mutex_init(&br->br_xino.xi_nondir_mtx);
3283 + br->br_perm = add->perm;
3284 + br->br_path = add->path; /* set first, path_get() later */
3285 + spin_lock_init(&br->br_dykey_lock);
3286 + au_br_count_init(br);
3287 + atomic_set(&br->br_xino_running, 0);
3288 + br->br_id = au_new_br_id(sb);
3289 + AuDebugOn(br->br_id < 0);
3291 + if (au_br_writable(add->perm)) {
3292 + err = au_wbr_init(br, sb, add->perm);
3293 + if (unlikely(err))
3297 + if (au_opt_test(au_mntflags(sb), XINO)) {
3298 + h_inode = d_inode(add->path.dentry);
3299 + err = au_xino_br(sb, br, h_inode->i_ino,
3300 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3301 + if (unlikely(err)) {
3302 + AuDebugOn(br->br_xino.xi_file);
3307 + sysaufs_br_init(br);
3308 + path_get(&br->br_path);
3309 + goto out; /* success */
3312 + memset(&br->br_path, 0, sizeof(br->br_path));
3317 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3318 + struct au_branch *br, aufs_bindex_t bbot,
3319 + aufs_bindex_t amount)
3321 + struct au_branch **brp;
3323 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3325 + brp = sbinfo->si_branch + bindex;
3326 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3328 + sbinfo->si_bbot++;
3329 + if (unlikely(bbot < 0))
3330 + sbinfo->si_bbot = 0;
3333 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3334 + aufs_bindex_t bbot, aufs_bindex_t amount)
3336 + struct au_hdentry *hdp;
3338 + AuRwMustWriteLock(&dinfo->di_rwsem);
3340 + hdp = au_hdentry(dinfo, bindex);
3341 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3342 + au_h_dentry_init(hdp);
3344 + if (unlikely(bbot < 0))
3345 + dinfo->di_btop = 0;
3348 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3349 + aufs_bindex_t bbot, aufs_bindex_t amount)
3351 + struct au_hinode *hip;
3353 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3355 + hip = au_hinode(iinfo, bindex);
3356 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3357 + au_hinode_init(hip);
3359 + if (unlikely(bbot < 0))
3360 + iinfo->ii_btop = 0;
3363 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3364 + aufs_bindex_t bindex)
3366 + struct dentry *root, *h_dentry;
3367 + struct inode *root_inode, *h_inode;
3368 + aufs_bindex_t bbot, amount;
3370 + root = sb->s_root;
3371 + root_inode = d_inode(root);
3372 + bbot = au_sbbot(sb);
3373 + amount = bbot + 1 - bindex;
3374 + h_dentry = au_br_dentry(br);
3375 + au_sbilist_lock();
3376 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3377 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3378 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3379 + au_set_h_dptr(root, bindex, dget(h_dentry));
3380 + h_inode = d_inode(h_dentry);
3381 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3382 + au_sbilist_unlock();
3385 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3388 + aufs_bindex_t bbot, add_bindex;
3389 + struct dentry *root, *h_dentry;
3390 + struct inode *root_inode;
3391 + struct au_branch *add_branch;
3393 + root = sb->s_root;
3394 + root_inode = d_inode(root);
3395 + IMustLock(root_inode);
3396 + IiMustWriteLock(root_inode);
3397 + err = test_add(sb, add, remount);
3398 + if (unlikely(err < 0))
3402 + goto out; /* success */
3405 + bbot = au_sbbot(sb);
3406 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3407 + err = PTR_ERR(add_branch);
3408 + if (IS_ERR(add_branch))
3411 + err = au_br_init(add_branch, sb, add);
3412 + if (unlikely(err)) {
3413 + au_br_do_free(add_branch);
3417 + add_bindex = add->bindex;
3419 + au_br_do_add(sb, add_branch, add_bindex);
3421 + sysaufs_brs_del(sb, add_bindex);
3422 + au_br_do_add(sb, add_branch, add_bindex);
3423 + sysaufs_brs_add(sb, add_bindex);
3426 + h_dentry = add->path.dentry;
3427 + if (!add_bindex) {
3428 + au_cpup_attr_all(root_inode, /*force*/1);
3429 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3431 + au_add_nlink(root_inode, d_inode(h_dentry));
3434 + * this test/set prevents aufs from handling unnecesary notify events
3435 + * of xino files, in case of re-adding a writable branch which was
3436 + * once detached from aufs.
3438 + if (au_xino_brid(sb) < 0
3439 + && au_br_writable(add_branch->br_perm)
3440 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3441 + && add_branch->br_xino.xi_file
3442 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3443 + au_xino_brid_set(sb, add_branch->br_id);
3449 +/* ---------------------------------------------------------------------- */
3451 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3452 + unsigned long long max __maybe_unused,
3455 + unsigned long long n;
3456 + struct file **p, *f;
3457 + struct au_sphlhead *files;
3458 + struct au_finfo *finfo;
3462 + files = &au_sbi(sb)->si_files;
3463 + spin_lock(&files->spin);
3464 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3465 + f = finfo->fi_file;
3467 + && !special_file(file_inode(f)->i_mode)) {
3471 + AuDebugOn(n > max);
3474 + spin_unlock(&files->spin);
3479 +static struct file **au_farray_alloc(struct super_block *sb,
3480 + unsigned long long *max)
3482 + *max = au_nfiles(sb);
3483 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3486 +static void au_farray_free(struct file **a, unsigned long long max)
3488 + unsigned long long ull;
3490 + for (ull = 0; ull < max; ull++)
3496 +/* ---------------------------------------------------------------------- */
3502 +/* to show the line number, do not make it inlined function */
3503 +#define AuVerbose(do_info, fmt, ...) do { \
3505 + pr_info(fmt, ##__VA_ARGS__); \
3508 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3509 + aufs_bindex_t bbot)
3511 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3514 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3515 + aufs_bindex_t bbot)
3517 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3521 + * test if the branch is deletable or not.
3523 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3524 + unsigned int sigen, const unsigned int verbose)
3526 + int err, i, j, ndentry;
3527 + aufs_bindex_t btop, bbot;
3528 + struct au_dcsub_pages dpages;
3529 + struct au_dpage *dpage;
3532 + err = au_dpages_init(&dpages, GFP_NOFS);
3533 + if (unlikely(err))
3535 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3536 + if (unlikely(err))
3539 + for (i = 0; !err && i < dpages.ndpage; i++) {
3540 + dpage = dpages.dpages + i;
3541 + ndentry = dpage->ndentry;
3542 + for (j = 0; !err && j < ndentry; j++) {
3543 + d = dpage->dentries[j];
3544 + AuDebugOn(au_dcount(d) <= 0);
3545 + if (!au_digen_test(d, sigen)) {
3546 + di_read_lock_child(d, AuLock_IR);
3547 + if (unlikely(au_dbrange_test(d))) {
3548 + di_read_unlock(d, AuLock_IR);
3552 + di_write_lock_child(d);
3553 + if (unlikely(au_dbrange_test(d))) {
3554 + di_write_unlock(d);
3557 + err = au_reval_dpath(d, sigen);
3559 + di_downgrade_lock(d, AuLock_IR);
3561 + di_write_unlock(d);
3566 + /* AuDbgDentry(d); */
3567 + btop = au_dbtop(d);
3568 + bbot = au_dbbot(d);
3569 + if (btop <= bindex
3571 + && au_h_dptr(d, bindex)
3572 + && au_test_dbusy(d, btop, bbot)) {
3574 + AuVerbose(verbose, "busy %pd\n", d);
3577 + di_read_unlock(d, AuLock_IR);
3582 + au_dpages_free(&dpages);
3587 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3588 + unsigned int sigen, const unsigned int verbose)
3591 + unsigned long long max, ull;
3592 + struct inode *i, **array;
3593 + aufs_bindex_t btop, bbot;
3595 + array = au_iarray_alloc(sb, &max);
3596 + err = PTR_ERR(array);
3597 + if (IS_ERR(array))
3601 + AuDbg("b%d\n", bindex);
3602 + for (ull = 0; !err && ull < max; ull++) {
3606 + if (i->i_ino == AUFS_ROOT_INO)
3609 + /* AuDbgInode(i); */
3610 + if (au_iigen(i, NULL) == sigen)
3611 + ii_read_lock_child(i);
3613 + ii_write_lock_child(i);
3614 + err = au_refresh_hinode_self(i);
3617 + ii_downgrade_lock(i);
3619 + ii_write_unlock(i);
3624 + btop = au_ibtop(i);
3625 + bbot = au_ibbot(i);
3626 + if (btop <= bindex
3628 + && au_h_iptr(i, bindex)
3629 + && au_test_ibusy(i, btop, bbot)) {
3631 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3634 + ii_read_unlock(i);
3636 + au_iarray_free(array, max);
3642 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3643 + const unsigned int verbose)
3646 + unsigned int sigen;
3648 + sigen = au_sigen(root->d_sb);
3649 + DiMustNoWaiters(root);
3650 + IiMustNoWaiters(d_inode(root));
3651 + di_write_unlock(root);
3652 + err = test_dentry_busy(root, bindex, sigen, verbose);
3654 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3655 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3660 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3661 + struct file **to_free, int *idx)
3664 + unsigned char matched, root;
3665 + aufs_bindex_t bindex, bbot;
3666 + struct au_fidir *fidir;
3667 + struct au_hfile *hfile;
3670 + root = IS_ROOT(file->f_path.dentry);
3673 + to_free[*idx] = file;
3679 + fidir = au_fi(file)->fi_hdir;
3680 + AuDebugOn(!fidir);
3681 + bbot = au_fbbot_dir(file);
3682 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3683 + hfile = fidir->fd_hfile + bindex;
3684 + if (!hfile->hf_file)
3687 + if (hfile->hf_br->br_id == br_id) {
3699 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3700 + struct file **to_free, int opened)
3703 + unsigned long long ull, max;
3704 + aufs_bindex_t btop;
3705 + struct file *file, **array;
3706 + struct dentry *root;
3707 + struct au_hfile *hfile;
3709 + array = au_farray_alloc(sb, &max);
3710 + err = PTR_ERR(array);
3711 + if (IS_ERR(array))
3716 + root = sb->s_root;
3717 + di_write_unlock(root);
3718 + for (ull = 0; ull < max; ull++) {
3719 + file = array[ull];
3720 + if (unlikely(!file))
3723 + /* AuDbg("%pD\n", file); */
3724 + fi_read_lock(file);
3725 + btop = au_fbtop(file);
3726 + if (!d_is_dir(file->f_path.dentry)) {
3727 + hfile = &au_fi(file)->fi_htop;
3728 + if (hfile->hf_br->br_id == br_id)
3731 + err = test_dir_busy(file, br_id, to_free, &idx);
3732 + fi_read_unlock(file);
3733 + if (unlikely(err))
3736 + di_write_lock_child(root);
3737 + au_farray_free(array, max);
3738 + AuDebugOn(idx > opened);
3744 +static void br_del_file(struct file **to_free, unsigned long long opened,
3745 + aufs_bindex_t br_id)
3747 + unsigned long long ull;
3748 + aufs_bindex_t bindex, btop, bbot, bfound;
3749 + struct file *file;
3750 + struct au_fidir *fidir;
3751 + struct au_hfile *hfile;
3753 + for (ull = 0; ull < opened; ull++) {
3754 + file = to_free[ull];
3755 + if (unlikely(!file))
3758 + /* AuDbg("%pD\n", file); */
3759 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3761 + fidir = au_fi(file)->fi_hdir;
3762 + AuDebugOn(!fidir);
3763 + fi_write_lock(file);
3764 + btop = au_fbtop(file);
3765 + bbot = au_fbbot_dir(file);
3766 + for (bindex = btop; bindex <= bbot; bindex++) {
3767 + hfile = fidir->fd_hfile + bindex;
3768 + if (!hfile->hf_file)
3771 + if (hfile->hf_br->br_id == br_id) {
3776 + AuDebugOn(bfound < 0);
3777 + au_set_h_fptr(file, bfound, NULL);
3778 + if (bfound == btop) {
3779 + for (btop++; btop <= bbot; btop++)
3780 + if (au_hf_dir(file, btop)) {
3781 + au_set_fbtop(file, btop);
3785 + fi_write_unlock(file);
3789 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3790 + const aufs_bindex_t bindex,
3791 + const aufs_bindex_t bbot)
3793 + struct au_branch **brp, **p;
3795 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3797 + brp = sbinfo->si_branch + bindex;
3798 + if (bindex < bbot)
3799 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3800 + sbinfo->si_branch[0 + bbot] = NULL;
3801 + sbinfo->si_bbot--;
3803 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3806 + sbinfo->si_branch = p;
3807 + /* harmless error */
3810 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3811 + const aufs_bindex_t bbot)
3813 + struct au_hdentry *hdp, *p;
3815 + AuRwMustWriteLock(&dinfo->di_rwsem);
3817 + hdp = au_hdentry(dinfo, bindex);
3818 + if (bindex < bbot)
3819 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3820 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3823 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3826 + dinfo->di_hdentry = p;
3827 + /* harmless error */
3830 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3831 + const aufs_bindex_t bbot)
3833 + struct au_hinode *hip, *p;
3835 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3837 + hip = au_hinode(iinfo, bindex);
3838 + if (bindex < bbot)
3839 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3840 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3843 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3846 + iinfo->ii_hinode = p;
3847 + /* harmless error */
3850 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3851 + struct au_branch *br)
3853 + aufs_bindex_t bbot;
3854 + struct au_sbinfo *sbinfo;
3855 + struct dentry *root, *h_root;
3856 + struct inode *inode, *h_inode;
3857 + struct au_hinode *hinode;
3859 + SiMustWriteLock(sb);
3861 + root = sb->s_root;
3862 + inode = d_inode(root);
3863 + sbinfo = au_sbi(sb);
3864 + bbot = sbinfo->si_bbot;
3866 + h_root = au_h_dptr(root, bindex);
3867 + hinode = au_hi(inode, bindex);
3868 + h_inode = au_igrab(hinode->hi_inode);
3871 + au_sbilist_lock();
3872 + au_br_do_del_brp(sbinfo, bindex, bbot);
3873 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3874 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3875 + au_sbilist_unlock();
3879 + au_br_do_free(br);
3882 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3883 + unsigned long long max, void *arg)
3888 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3891 + unsigned long long opened;
3892 + unsigned int mnt_flags;
3893 + aufs_bindex_t bindex, bbot, br_id;
3894 + unsigned char do_wh, verbose;
3895 + struct au_branch *br;
3896 + struct au_wbr *wbr;
3897 + struct dentry *root;
3898 + struct file **to_free;
3903 + root = sb->s_root;
3904 + bindex = au_find_dbindex(root, del->h_path.dentry);
3907 + goto out; /* success */
3909 + pr_err("%s no such branch\n", del->pathname);
3912 + AuDbg("bindex b%d\n", bindex);
3915 + mnt_flags = au_mntflags(sb);
3916 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3917 + bbot = au_sbbot(sb);
3918 + if (unlikely(!bbot)) {
3919 + AuVerbose(verbose, "no more branches left\n");
3922 + br = au_sbr(sb, bindex);
3923 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3925 + br_id = br->br_id;
3926 + opened = au_br_count(br);
3927 + if (unlikely(opened)) {
3928 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3929 + err = PTR_ERR(to_free);
3930 + if (IS_ERR(to_free))
3933 + err = test_file_busy(sb, br_id, to_free, opened);
3934 + if (unlikely(err)) {
3935 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3941 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3943 + /* instead of WbrWhMustWriteLock(wbr) */
3944 + SiMustWriteLock(sb);
3945 + for (i = 0; i < AuBrWh_Last; i++) {
3946 + dput(wbr->wbr_wh[i]);
3947 + wbr->wbr_wh[i] = NULL;
3951 + err = test_children_busy(root, bindex, verbose);
3952 + if (unlikely(err)) {
3961 + * now we confirmed the branch is deletable.
3962 + * let's free the remaining opened dirs on the branch.
3964 + di_write_unlock(root);
3965 + br_del_file(to_free, opened, br_id);
3966 + di_write_lock_child(root);
3970 + au_br_do_del(sb, bindex, br);
3972 + sysaufs_brs_del(sb, bindex);
3973 + au_br_do_del(sb, bindex, br);
3974 + sysaufs_brs_add(sb, bindex);
3978 + au_cpup_attr_all(d_inode(root), /*force*/1);
3979 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3981 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3982 + if (au_opt_test(mnt_flags, PLINK))
3983 + au_plink_half_refresh(sb, br_id);
3985 + if (au_xino_brid(sb) == br_id)
3986 + au_xino_brid_set(sb, -1);
3987 + goto out; /* success */
3991 + rerr = au_br_init_wh(sb, br, br->br_perm);
3993 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3994 + del->pathname, rerr);
3997 + au_farray_free(to_free, opened);
4001 +/* ---------------------------------------------------------------------- */
4003 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4006 + aufs_bindex_t btop, bbot;
4007 + struct aufs_ibusy ibusy;
4008 + struct inode *inode, *h_inode;
4011 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4014 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4016 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4017 + if (unlikely(err)) {
4024 + si_read_lock(sb, AuLock_FLUSH);
4025 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4029 + ibusy.h_ino = 0; /* invalid */
4030 + inode = ilookup(sb, ibusy.ino);
4032 + || inode->i_ino == AUFS_ROOT_INO
4033 + || au_is_bad_inode(inode))
4036 + ii_read_lock_child(inode);
4037 + btop = au_ibtop(inode);
4038 + bbot = au_ibbot(inode);
4039 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4040 + h_inode = au_h_iptr(inode, ibusy.bindex);
4041 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4042 + ibusy.h_ino = h_inode->i_ino;
4044 + ii_read_unlock(inode);
4048 + si_read_unlock(sb);
4050 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4051 + if (unlikely(err)) {
4060 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4062 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4065 +#ifdef CONFIG_COMPAT
4066 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4068 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4072 +/* ---------------------------------------------------------------------- */
4075 + * change a branch permission
4078 +static void au_warn_ima(void)
4081 + /* since it doesn't support mark_files_ro() */
4082 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4086 +static int do_need_sigen_inc(int a, int b)
4088 + return au_br_whable(a) && !au_br_whable(b);
4091 +static int need_sigen_inc(int old, int new)
4093 + return do_need_sigen_inc(old, new)
4094 + || do_need_sigen_inc(new, old);
4097 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4100 + unsigned int mnt_flags;
4101 + unsigned long long ull, max;
4102 + aufs_bindex_t br_id;
4103 + unsigned char verbose, writer;
4104 + struct file *file, *hf, **array;
4105 + struct au_hfile *hfile;
4107 + mnt_flags = au_mntflags(sb);
4108 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4110 + array = au_farray_alloc(sb, &max);
4111 + err = PTR_ERR(array);
4112 + if (IS_ERR(array))
4116 + br_id = au_sbr_id(sb, bindex);
4117 + for (ull = 0; ull < max; ull++) {
4118 + file = array[ull];
4119 + if (unlikely(!file))
4122 + /* AuDbg("%pD\n", file); */
4123 + fi_read_lock(file);
4124 + if (unlikely(au_test_mmapped(file))) {
4126 + AuVerbose(verbose, "mmapped %pD\n", file);
4128 + FiMustNoWaiters(file);
4129 + fi_read_unlock(file);
4133 + hfile = &au_fi(file)->fi_htop;
4134 + hf = hfile->hf_file;
4135 + if (!d_is_reg(file->f_path.dentry)
4136 + || !(file->f_mode & FMODE_WRITE)
4137 + || hfile->hf_br->br_id != br_id
4138 + || !(hf->f_mode & FMODE_WRITE))
4139 + array[ull] = NULL;
4145 + FiMustNoWaiters(file);
4146 + fi_read_unlock(file);
4154 + for (ull = 0; ull < max; ull++) {
4155 + file = array[ull];
4159 + /* todo: already flushed? */
4161 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4162 + * approach which resets f_mode and calls mnt_drop_write() and
4163 + * file_release_write() for each file, because the branch
4164 + * attribute in aufs world is totally different from the native
4167 + /* fi_read_lock(file); */
4168 + hfile = &au_fi(file)->fi_htop;
4169 + hf = hfile->hf_file;
4170 + /* fi_read_unlock(file); */
4171 + spin_lock(&hf->f_lock);
4172 + writer = !!(hf->f_mode & FMODE_WRITER);
4173 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4174 + spin_unlock(&hf->f_lock);
4176 + put_write_access(file_inode(hf));
4177 + __mnt_drop_write(hf->f_path.mnt);
4182 + au_farray_free(array, max);
4188 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4192 + aufs_bindex_t bindex;
4193 + struct dentry *root;
4194 + struct au_branch *br;
4195 + struct au_br_fhsm *bf;
4197 + root = sb->s_root;
4198 + bindex = au_find_dbindex(root, mod->h_root);
4201 + return 0; /* success */
4203 + pr_err("%s no such branch\n", mod->path);
4206 + AuDbg("bindex b%d\n", bindex);
4208 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4209 + if (unlikely(err))
4212 + br = au_sbr(sb, bindex);
4213 + AuDebugOn(mod->h_root != au_br_dentry(br));
4214 + if (br->br_perm == mod->perm)
4215 + return 0; /* success */
4217 + /* pre-allocate for non-fhsm --> fhsm */
4219 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4220 + err = au_fhsm_br_alloc(br);
4221 + if (unlikely(err))
4224 + br->br_fhsm = NULL;
4227 + if (au_br_writable(br->br_perm)) {
4228 + /* remove whiteout base */
4229 + err = au_br_init_wh(sb, br, mod->perm);
4230 + if (unlikely(err))
4233 + if (!au_br_writable(mod->perm)) {
4234 + /* rw --> ro, file might be mmapped */
4235 + DiMustNoWaiters(root);
4236 + IiMustNoWaiters(d_inode(root));
4237 + di_write_unlock(root);
4238 + err = au_br_mod_files_ro(sb, bindex);
4239 + /* aufs_write_lock() calls ..._child() */
4240 + di_write_lock_child(root);
4242 + if (unlikely(err)) {
4244 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4247 + rerr = au_wbr_init(br, sb, br->br_perm);
4248 + if (unlikely(rerr)) {
4249 + AuIOErr("nested error %d (%d)\n",
4251 + br->br_perm = mod->perm;
4255 + } else if (au_br_writable(mod->perm)) {
4258 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4260 + err = au_wbr_init(br, sb, mod->perm);
4261 + if (unlikely(err)) {
4262 + au_delayed_kfree(br->br_wbr);
4263 + br->br_wbr = NULL;
4267 + if (unlikely(err))
4270 + if (au_br_fhsm(br->br_perm)) {
4271 + if (!au_br_fhsm(mod->perm)) {
4272 + /* fhsm --> non-fhsm */
4273 + au_br_fhsm_fin(br->br_fhsm);
4274 + au_delayed_kfree(br->br_fhsm);
4275 + br->br_fhsm = NULL;
4277 + } else if (au_br_fhsm(mod->perm))
4278 + /* non-fhsm --> fhsm */
4281 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4282 + br->br_perm = mod->perm;
4283 + goto out; /* success */
4287 + au_delayed_kfree(bf);
4293 +/* ---------------------------------------------------------------------- */
4295 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4298 + struct kstatfs kstfs;
4300 + err = vfs_statfs(&br->br_path, &kstfs);
4302 + stfs->f_blocks = kstfs.f_blocks;
4303 + stfs->f_bavail = kstfs.f_bavail;
4304 + stfs->f_files = kstfs.f_files;
4305 + stfs->f_ffree = kstfs.f_ffree;
4310 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4311 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4312 +++ linux/fs/aufs/branch.h 2017-03-02 14:24:13.853588785 +0100
4315 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4317 + * This program, aufs is free software; you can redistribute it and/or modify
4318 + * it under the terms of the GNU General Public License as published by
4319 + * the Free Software Foundation; either version 2 of the License, or
4320 + * (at your option) any later version.
4322 + * This program is distributed in the hope that it will be useful,
4323 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4325 + * GNU General Public License for more details.
4327 + * You should have received a copy of the GNU General Public License
4328 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4332 + * branch filesystems and xino for them
4335 +#ifndef __AUFS_BRANCH_H__
4336 +#define __AUFS_BRANCH_H__
4340 +#include <linux/mount.h>
4345 +/* ---------------------------------------------------------------------- */
4348 +struct au_xino_file {
4349 + struct file *xi_file;
4350 + struct mutex xi_nondir_mtx;
4352 + /* todo: make xino files an array to support huge inode number */
4354 +#ifdef CONFIG_DEBUG_FS
4355 + struct dentry *xi_dbgaufs;
4359 +/* File-based Hierarchical Storage Management */
4360 +struct au_br_fhsm {
4361 +#ifdef CONFIG_AUFS_FHSM
4362 + struct mutex bf_lock;
4363 + unsigned long bf_jiffy;
4364 + struct aufs_stfs bf_stfs;
4369 +/* members for writable branch only */
4370 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4372 + struct au_rwsem wbr_wh_rwsem;
4373 + struct dentry *wbr_wh[AuBrWh_Last];
4374 + atomic_t wbr_wh_running;
4375 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4376 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4377 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4380 + unsigned long long wbr_bytes;
4383 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4384 +#define AuBrDynOp (AuDyLast * 4)
4386 +#ifdef CONFIG_AUFS_HFSNOTIFY
4387 +/* support for asynchronous destruction */
4388 +struct au_br_hfsnotify {
4389 + struct fsnotify_group *hfsn_group;
4393 +/* sysfs entries */
4394 +struct au_brsysfs {
4396 + struct attribute attr;
4405 +/* protected by superblock rwsem */
4407 + struct au_xino_file br_xino;
4409 + aufs_bindex_t br_id;
4412 + struct path br_path;
4413 + spinlock_t br_dykey_lock;
4414 + struct au_dykey *br_dykey[AuBrDynOp];
4415 + struct percpu_counter br_count;
4417 + struct au_wbr *br_wbr;
4418 + struct au_br_fhsm *br_fhsm;
4420 + /* xino truncation */
4421 + atomic_t br_xino_running;
4423 +#ifdef CONFIG_AUFS_HFSNOTIFY
4424 + struct au_br_hfsnotify *br_hfsn;
4427 +#ifdef CONFIG_SYSFS
4428 + /* entries under sysfs per mount-point */
4429 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4433 +/* ---------------------------------------------------------------------- */
4435 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4437 + return br->br_path.mnt;
4440 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4442 + return br->br_path.dentry;
4445 +static inline struct super_block *au_br_sb(struct au_branch *br)
4447 + return au_br_mnt(br)->mnt_sb;
4450 +static inline void au_br_get(struct au_branch *br)
4452 + percpu_counter_inc(&br->br_count);
4455 +static inline void au_br_put(struct au_branch *br)
4457 + percpu_counter_dec(&br->br_count);
4460 +static inline s64 au_br_count(struct au_branch *br)
4462 + return percpu_counter_sum(&br->br_count);
4465 +static inline void au_br_count_init(struct au_branch *br)
4467 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4470 +static inline void au_br_count_fin(struct au_branch *br)
4472 + percpu_counter_destroy(&br->br_count);
4475 +static inline int au_br_rdonly(struct au_branch *br)
4477 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4478 + || !au_br_writable(br->br_perm))
4482 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4484 +#ifdef CONFIG_AUFS_HNOTIFY
4485 + return !(brperm & AuBrPerm_RR);
4491 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4493 + int err, exec_flag;
4496 + exec_flag = oflag & __FMODE_EXEC;
4497 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4503 +/* ---------------------------------------------------------------------- */
4507 +void au_br_free(struct au_sbinfo *sinfo);
4508 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4510 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4512 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4513 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4514 +#ifdef CONFIG_COMPAT
4515 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4518 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4521 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4524 +static const loff_t au_loff_max = LLONG_MAX;
4526 +int au_xib_trunc(struct super_block *sb);
4527 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4529 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4530 + size_t size, loff_t *pos);
4531 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4532 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4533 +ino_t au_xino_new_ino(struct super_block *sb);
4534 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4535 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4537 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4539 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4540 + struct file *base_file, int do_test);
4541 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4543 +struct au_opt_xino;
4544 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4545 +void au_xino_clr(struct super_block *sb);
4546 +struct file *au_xino_def(struct super_block *sb);
4547 +int au_xino_path(struct seq_file *seq, struct file *file);
4549 +/* ---------------------------------------------------------------------- */
4551 +/* Superblock to branch */
4553 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4555 + return au_sbr(sb, bindex)->br_id;
4559 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4561 + return au_br_mnt(au_sbr(sb, bindex));
4565 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4567 + return au_br_sb(au_sbr(sb, bindex));
4570 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4572 + au_br_get(au_sbr(sb, bindex));
4575 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4577 + au_br_put(au_sbr(sb, bindex));
4580 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4582 + return au_sbr(sb, bindex)->br_perm;
4585 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4587 + return au_br_whable(au_sbr_perm(sb, bindex));
4590 +/* ---------------------------------------------------------------------- */
4593 + * wbr_wh_read_lock, wbr_wh_write_lock
4594 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4596 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4598 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4599 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4600 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4602 +/* ---------------------------------------------------------------------- */
4604 +#ifdef CONFIG_AUFS_FHSM
4605 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4607 + mutex_init(&brfhsm->bf_lock);
4608 + brfhsm->bf_jiffy = 0;
4609 + brfhsm->bf_readable = 0;
4612 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4614 + mutex_destroy(&brfhsm->bf_lock);
4617 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4618 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4621 +#endif /* __KERNEL__ */
4622 +#endif /* __AUFS_BRANCH_H__ */
4623 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4624 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4625 +++ linux/fs/aufs/conf.mk 2016-10-09 16:55:36.486034798 +0200
4628 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4632 +AuConfStr += ${1}=${${1}}
4636 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4638 + HNOTIFY HFSNOTIFY \
4649 +$(foreach i, ${AuConfAll}, \
4650 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4652 +AuConfName = ${obj}/conf.str
4653 +${AuConfName}.tmp: FORCE
4654 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4655 +${AuConfName}: ${AuConfName}.tmp
4656 + @diff -q $< $@ > /dev/null 2>&1 || { \
4657 + echo ' GEN ' $@; \
4661 +clean-files += ${AuConfName} ${AuConfName}.tmp
4662 +${obj}/sysfs.o: ${AuConfName}
4664 +-include ${srctree}/${src}/conf_priv.mk
4665 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4666 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4667 +++ linux/fs/aufs/cpup.c 2017-03-02 14:24:13.856922210 +0100
4670 + * Copyright (C) 2005-2017 Junjiro R. Okajima
4672 + * This program, aufs is free software; you can redistribute it and/or modify
4673 + * it under the terms of the GNU General Public License as published by
4674 + * the Free Software Foundation; either version 2 of the License, or
4675 + * (at your option) any later version.
4677 + * This program is distributed in the hope that it will be useful,
4678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4680 + * GNU General Public License for more details.
4682 + * You should have received a copy of the GNU General Public License
4683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4687 + * copy-up functions, see wbr_policy.c for copy-down
4690 +#include <linux/fs_stack.h>
4691 +#include <linux/mm.h>
4692 +#include <linux/task_work.h>
4695 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4697 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4698 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4700 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4702 + dst->i_flags |= iflags & ~mask;
4703 + if (au_test_fs_notime(dst->i_sb))
4704 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4707 +void au_cpup_attr_timesizes(struct inode *inode)
4709 + struct inode *h_inode;
4711 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4712 + fsstack_copy_attr_times(inode, h_inode);
4713 + fsstack_copy_inode_size(inode, h_inode);
4716 +void au_cpup_attr_nlink(struct inode *inode, int force)
4718 + struct inode *h_inode;
4719 + struct super_block *sb;
4720 + aufs_bindex_t bindex, bbot;
4723 + bindex = au_ibtop(inode);
4724 + h_inode = au_h_iptr(inode, bindex);
4726 + && !S_ISDIR(h_inode->i_mode)
4727 + && au_opt_test(au_mntflags(sb), PLINK)
4728 + && au_plink_test(inode))
4732 + * 0 can happen in revalidating.
4733 + * h_inode->i_mutex may not be held here, but it is harmless since once
4734 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4736 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4737 + * the incorrect link count.
4739 + set_nlink(inode, h_inode->i_nlink);
4742 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4743 + * it may includes whplink directory.
4745 + if (S_ISDIR(h_inode->i_mode)) {
4746 + bbot = au_ibbot(inode);
4747 + for (bindex++; bindex <= bbot; bindex++) {
4748 + h_inode = au_h_iptr(inode, bindex);
4750 + au_add_nlink(inode, h_inode);
4755 +void au_cpup_attr_changeable(struct inode *inode)
4757 + struct inode *h_inode;
4759 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4760 + inode->i_mode = h_inode->i_mode;
4761 + inode->i_uid = h_inode->i_uid;
4762 + inode->i_gid = h_inode->i_gid;
4763 + au_cpup_attr_timesizes(inode);
4764 + au_cpup_attr_flags(inode, h_inode->i_flags);
4767 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4769 + struct au_iinfo *iinfo = au_ii(inode);
4771 + IiMustWriteLock(inode);
4773 + iinfo->ii_higen = h_inode->i_generation;
4774 + iinfo->ii_hsb1 = h_inode->i_sb;
4777 +void au_cpup_attr_all(struct inode *inode, int force)
4779 + struct inode *h_inode;
4781 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4782 + au_cpup_attr_changeable(inode);
4783 + if (inode->i_nlink > 0)
4784 + au_cpup_attr_nlink(inode, force);
4785 + inode->i_rdev = h_inode->i_rdev;
4786 + inode->i_blkbits = h_inode->i_blkbits;
4787 + au_cpup_igen(inode, h_inode);
4790 +/* ---------------------------------------------------------------------- */
4792 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4794 +/* keep the timestamps of the parent dir when cpup */
4795 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4796 + struct path *h_path)
4798 + struct inode *h_inode;
4800 + dt->dt_dentry = dentry;
4801 + dt->dt_h_path = *h_path;
4802 + h_inode = d_inode(h_path->dentry);
4803 + dt->dt_atime = h_inode->i_atime;
4804 + dt->dt_mtime = h_inode->i_mtime;
4808 +void au_dtime_revert(struct au_dtime *dt)
4810 + struct iattr attr;
4813 + attr.ia_atime = dt->dt_atime;
4814 + attr.ia_mtime = dt->dt_mtime;
4815 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4816 + | ATTR_ATIME | ATTR_ATIME_SET;
4818 + /* no delegation since this is a directory */
4819 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4820 + if (unlikely(err))
4821 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4824 +/* ---------------------------------------------------------------------- */
4826 +/* internal use only */
4827 +struct au_cpup_reg_attr {
4830 + unsigned int iflags; /* inode->i_flags */
4833 +static noinline_for_stack
4834 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4835 + struct au_cpup_reg_attr *h_src_attr)
4837 + int err, sbits, icex;
4838 + unsigned int mnt_flags;
4839 + unsigned char verbose;
4841 + struct path h_path;
4842 + struct inode *h_isrc, *h_idst;
4843 + struct kstat *h_st;
4844 + struct au_branch *br;
4846 + h_path.dentry = au_h_dptr(dst, bindex);
4847 + h_idst = d_inode(h_path.dentry);
4848 + br = au_sbr(dst->d_sb, bindex);
4849 + h_path.mnt = au_br_mnt(br);
4850 + h_isrc = d_inode(h_src);
4851 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4852 + | ATTR_ATIME | ATTR_MTIME
4853 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4854 + if (h_src_attr && h_src_attr->valid) {
4855 + h_st = &h_src_attr->st;
4856 + ia.ia_uid = h_st->uid;
4857 + ia.ia_gid = h_st->gid;
4858 + ia.ia_atime = h_st->atime;
4859 + ia.ia_mtime = h_st->mtime;
4860 + if (h_idst->i_mode != h_st->mode
4861 + && !S_ISLNK(h_idst->i_mode)) {
4862 + ia.ia_valid |= ATTR_MODE;
4863 + ia.ia_mode = h_st->mode;
4865 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4866 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4868 + ia.ia_uid = h_isrc->i_uid;
4869 + ia.ia_gid = h_isrc->i_gid;
4870 + ia.ia_atime = h_isrc->i_atime;
4871 + ia.ia_mtime = h_isrc->i_mtime;
4872 + if (h_idst->i_mode != h_isrc->i_mode
4873 + && !S_ISLNK(h_idst->i_mode)) {
4874 + ia.ia_valid |= ATTR_MODE;
4875 + ia.ia_mode = h_isrc->i_mode;
4877 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4878 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4880 + /* no delegation since it is just created */
4881 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4883 + /* is this nfs only? */
4884 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4885 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4886 + ia.ia_mode = h_isrc->i_mode;
4887 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4890 + icex = br->br_perm & AuBrAttr_ICEX;
4892 + mnt_flags = au_mntflags(dst->d_sb);
4893 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4894 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4900 +/* ---------------------------------------------------------------------- */
4902 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4903 + char *buf, unsigned long blksize)
4906 + size_t sz, rbytes, wbytes;
4907 + unsigned char all_zero;
4909 + struct inode *h_inode;
4910 + /* reduce stack usage */
4913 + zp = page_address(ZERO_PAGE(0));
4914 + if (unlikely(!zp))
4915 + return -ENOMEM; /* possible? */
4920 + AuDbg("len %lld\n", len);
4922 + if (len < blksize)
4926 + /* todo: signal_pending? */
4927 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4928 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4931 + if (unlikely(err < 0))
4935 + if (len >= rbytes && rbytes == blksize)
4936 + all_zero = !memcmp(buf, zp, rbytes);
4943 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4945 + /* todo: signal_pending? */
4946 + if (unlikely(err == -EAGAIN || err == -EINTR))
4948 + if (unlikely(err < 0))
4953 + if (unlikely(err < 0))
4959 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4961 + if (unlikely(res < 0))
4968 + /* the last block may be a hole */
4969 + if (!err && all_zero) {
4970 + AuLabel(last hole);
4973 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4974 + /* nfs requires this step to make last hole */
4975 + /* is this only nfs? */
4977 + /* todo: signal_pending? */
4978 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4979 + } while (err == -EAGAIN || err == -EINTR);
4986 + ia->ia_size = dst->f_pos;
4987 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4988 + ia->ia_file = dst;
4989 + h_inode = file_inode(dst);
4990 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
4991 + /* no delegation since it is just created */
4992 + err = vfsub_notify_change(&dst->f_path, ia,
4993 + /*delegated*/NULL);
4994 + inode_unlock(h_inode);
5001 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5004 + unsigned long blksize;
5005 + unsigned char do_kfree;
5009 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5010 + if (!blksize || PAGE_SIZE < blksize)
5011 + blksize = PAGE_SIZE;
5012 + AuDbg("blksize %lu\n", blksize);
5013 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5015 + buf = kmalloc(blksize, GFP_NOFS);
5017 + buf = (void *)__get_free_page(GFP_NOFS);
5018 + if (unlikely(!buf))
5021 + if (len > (1 << 22))
5022 + AuDbg("copying a large file %lld\n", (long long)len);
5026 + err = au_do_copy_file(dst, src, len, buf, blksize);
5028 + au_delayed_kfree(buf);
5030 + au_delayed_free_page((unsigned long)buf);
5037 + * to support a sparse file which is opened with O_APPEND,
5038 + * we need to close the file.
5040 +static int au_cp_regular(struct au_cp_generic *cpg)
5043 + enum { SRC, DST };
5045 + aufs_bindex_t bindex;
5046 + unsigned int flags;
5047 + struct dentry *dentry;
5049 + struct file *file;
5053 + .bindex = cpg->bsrc,
5054 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5058 + .bindex = cpg->bdst,
5059 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5060 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5061 + .label = &&out_src
5064 + struct super_block *sb;
5065 + struct inode *h_src_inode;
5066 + struct task_struct *tsk = current;
5068 + /* bsrc branch can be ro/rw. */
5069 + sb = cpg->dentry->d_sb;
5071 + for (i = 0; i < 2; i++, f++) {
5072 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5073 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5074 + /*file*/NULL, f->force_wr);
5075 + err = PTR_ERR(f->file);
5076 + if (IS_ERR(f->file))
5080 + /* try stopping to update while we copyup */
5081 + h_src_inode = d_inode(file[SRC].dentry);
5082 + if (!au_test_nfs(h_src_inode->i_sb))
5083 + IMustLock(h_src_inode);
5084 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5086 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5087 + if (tsk->flags & PF_KTHREAD)
5088 + __fput_sync(file[DST].file);
5090 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5092 + fput(file[DST].file);
5095 + * we have to call both since we don't know which place the file
5099 + flush_delayed_fput();
5101 + au_sbr_put(sb, file[DST].bindex);
5104 + fput(file[SRC].file);
5105 + au_sbr_put(sb, file[SRC].bindex);
5110 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5111 + struct au_cpup_reg_attr *h_src_attr)
5115 + struct path h_path;
5116 + struct inode *h_src_inode, *h_dst_inode;
5119 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5120 + l = i_size_read(h_src_inode);
5121 + if (cpg->len == -1 || l < cpg->len)
5124 + /* try stopping to update while we are referencing */
5125 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5126 + au_pin_hdir_unlock(cpg->pin);
5128 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5129 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5130 + h_src_attr->iflags = h_src_inode->i_flags;
5131 + if (!au_test_nfs(h_src_inode->i_sb))
5132 + err = vfs_getattr(&h_path, &h_src_attr->st);
5134 + inode_unlock(h_src_inode);
5135 + err = vfs_getattr(&h_path, &h_src_attr->st);
5136 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5138 + if (unlikely(err)) {
5139 + inode_unlock(h_src_inode);
5142 + h_src_attr->valid = 1;
5143 + if (!au_test_nfs(h_src_inode->i_sb)) {
5144 + err = au_cp_regular(cpg);
5145 + inode_unlock(h_src_inode);
5147 + inode_unlock(h_src_inode);
5148 + err = au_cp_regular(cpg);
5150 + rerr = au_pin_hdir_relock(cpg->pin);
5154 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5155 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5156 + h_dst_inode = d_inode(h_path.dentry);
5157 + spin_lock(&h_dst_inode->i_lock);
5158 + h_dst_inode->i_state |= I_LINKABLE;
5159 + spin_unlock(&h_dst_inode->i_lock);
5166 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5167 + struct inode *h_dir)
5170 + mm_segment_t old_fs;
5177 + sym.k = (void *)__get_free_page(GFP_NOFS);
5178 + if (unlikely(!sym.k))
5181 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5182 + old_fs = get_fs();
5183 + set_fs(KERNEL_DS);
5184 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5189 + sym.k[symlen] = 0;
5190 + err = vfsub_symlink(h_dir, h_path, sym.k);
5192 + au_delayed_free_page((unsigned long)sym.k);
5199 + * regardless 'acl' option, reset all ACL.
5200 + * All ACL will be copied up later from the original entry on the lower branch.
5202 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5205 + struct dentry *h_dentry;
5206 + struct inode *h_inode;
5208 + h_dentry = h_path->dentry;
5209 + h_inode = d_inode(h_dentry);
5210 + /* forget_all_cached_acls(h_inode)); */
5211 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5213 + if (err == -EOPNOTSUPP)
5216 + err = vfsub_acl_chmod(h_inode, mode);
5222 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5223 + struct inode *h_dir, struct path *h_path)
5226 + struct inode *dir, *inode;
5228 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5230 + if (err == -EOPNOTSUPP)
5232 + if (unlikely(err))
5236 + * strange behaviour from the users view,
5237 + * particularry setattr case
5239 + dir = d_inode(dst_parent);
5240 + if (au_ibtop(dir) == cpg->bdst)
5241 + au_cpup_attr_nlink(dir, /*force*/1);
5242 + inode = d_inode(cpg->dentry);
5243 + au_cpup_attr_nlink(inode, /*force*/1);
5249 +static noinline_for_stack
5250 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5251 + struct au_cpup_reg_attr *h_src_attr)
5255 + unsigned int mnt_flags;
5256 + unsigned char isdir, isreg, force;
5257 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5258 + struct au_dtime dt;
5259 + struct path h_path;
5260 + struct dentry *h_src, *h_dst, *h_parent;
5261 + struct inode *h_inode, *h_dir;
5262 + struct super_block *sb;
5264 + /* bsrc branch can be ro/rw. */
5265 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5266 + h_inode = d_inode(h_src);
5267 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5269 + /* try stopping to be referenced while we are creating */
5270 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5271 + if (au_ftest_cpup(cpg->flags, RENAME))
5272 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5273 + AUFS_WH_PFX_LEN));
5274 + h_parent = h_dst->d_parent; /* dir inode is locked */
5275 + h_dir = d_inode(h_parent);
5277 + AuDebugOn(h_parent != h_dst->d_parent);
5279 + sb = cpg->dentry->d_sb;
5280 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5282 + h_path.dentry = h_parent;
5283 + au_dtime_store(&dt, dst_parent, &h_path);
5285 + h_path.dentry = h_dst;
5289 + mode = h_inode->i_mode;
5290 + switch (mode & S_IFMT) {
5293 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5294 + /*want_excl*/true);
5296 + err = au_do_cpup_regular(cpg, h_src_attr);
5300 + err = vfsub_mkdir(h_dir, &h_path, mode);
5302 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5305 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5309 + AuDebugOn(!capable(CAP_MKNOD));
5313 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5316 + AuIOErr("Unknown inode type 0%o\n", mode);
5320 + err = au_reset_acl(h_dir, &h_path, mode);
5322 + mnt_flags = au_mntflags(sb);
5323 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5325 + && au_opt_test(mnt_flags, XINO)
5326 + && (h_inode->i_nlink == 1
5327 + || (h_inode->i_state & I_LINKABLE))
5328 + /* todo: unnecessary? */
5329 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5330 + && cpg->bdst < cpg->bsrc
5331 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5332 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5333 + /* ignore this error */
5338 + force = !!cpg->len;
5339 + if (cpg->len == -1)
5340 + force = !!i_size_read(h_inode);
5342 + au_fhsm_wrote(sb, cpg->bdst, force);
5346 + au_dtime_revert(&dt);
5350 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5353 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5354 + struct inode *h_dir;
5355 + aufs_bindex_t bdst;
5357 + dentry = cpg->dentry;
5359 + h_dentry = au_h_dptr(dentry, bdst);
5360 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5362 + au_set_h_dptr(dentry, bdst, NULL);
5363 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5365 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5366 + au_set_h_dptr(dentry, bdst, h_dentry);
5369 + parent = dget_parent(dentry);
5370 + h_parent = au_h_dptr(parent, bdst);
5372 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5373 + if (IS_ERR(h_path->dentry))
5374 + err = PTR_ERR(h_path->dentry);
5376 + if (unlikely(err))
5379 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5380 + h_dir = d_inode(h_parent);
5382 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5383 + /* no delegation since it is just created */
5384 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5386 + dput(h_path->dentry);
5393 + * copyup the @dentry from @bsrc to @bdst.
5394 + * the caller must set the both of lower dentries.
5395 + * @len is for truncating when it is -1 copyup the entire file.
5396 + * in link/rename cases, @dst_parent may be different from the real one.
5397 + * basic->bsrc can be larger than basic->bdst.
5398 + * aufs doesn't touch the credential so
5399 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5401 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5404 + aufs_bindex_t old_ibtop;
5405 + unsigned char isdir, plink;
5406 + struct dentry *h_src, *h_dst, *h_parent;
5407 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5408 + struct super_block *sb;
5409 + struct au_branch *br;
5410 + /* to reuduce stack size */
5412 + struct au_dtime dt;
5413 + struct path h_path;
5414 + struct au_cpup_reg_attr h_src_attr;
5418 + a = kmalloc(sizeof(*a), GFP_NOFS);
5421 + a->h_src_attr.valid = 0;
5423 + sb = cpg->dentry->d_sb;
5424 + br = au_sbr(sb, cpg->bdst);
5425 + a->h_path.mnt = au_br_mnt(br);
5426 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5427 + h_parent = h_dst->d_parent; /* dir inode is locked */
5428 + h_dir = d_inode(h_parent);
5431 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5432 + inode = d_inode(cpg->dentry);
5435 + dst_parent = dget_parent(cpg->dentry);
5439 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5440 + dst_inode = au_h_iptr(inode, cpg->bdst);
5442 + if (unlikely(!plink)) {
5444 + AuIOErr("hi%lu(i%lu) exists on b%d "
5445 + "but plink is disabled\n",
5446 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5450 + if (dst_inode->i_nlink) {
5451 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5453 + h_src = au_plink_lkup(inode, cpg->bdst);
5454 + err = PTR_ERR(h_src);
5455 + if (IS_ERR(h_src))
5457 + if (unlikely(d_is_negative(h_src))) {
5459 + AuIOErr("i%lu exists on b%d "
5460 + "but not pseudo-linked\n",
5461 + inode->i_ino, cpg->bdst);
5467 + a->h_path.dentry = h_parent;
5468 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5471 + a->h_path.dentry = h_dst;
5473 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5474 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5475 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5477 + au_dtime_revert(&a->dt);
5478 + if (unlikely(err == -EWOULDBLOCK)) {
5479 + pr_warn("cannot retry for NFSv4 delegation"
5480 + " for an internal link\n");
5486 + /* todo: cpup_wh_file? */
5488 + au_update_ibrange(inode, /*do_put_zero*/1);
5491 + isdir = S_ISDIR(inode->i_mode);
5492 + old_ibtop = au_ibtop(inode);
5493 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5494 + if (unlikely(err))
5496 + dst_inode = d_inode(h_dst);
5497 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5498 + /* todo: necessary? */
5499 + /* au_pin_hdir_unlock(cpg->pin); */
5501 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5502 + if (unlikely(err)) {
5503 + /* todo: necessary? */
5504 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5505 + inode_unlock(dst_inode);
5509 + if (cpg->bdst < old_ibtop) {
5510 + if (S_ISREG(inode->i_mode)) {
5511 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5512 + if (unlikely(err)) {
5513 + /* ignore an error */
5514 + /* au_pin_hdir_relock(cpg->pin); */
5515 + inode_unlock(dst_inode);
5519 + au_set_ibtop(inode, cpg->bdst);
5521 + au_set_ibbot(inode, cpg->bdst);
5522 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5523 + au_hi_flags(inode, isdir));
5525 + /* todo: necessary? */
5526 + /* err = au_pin_hdir_relock(cpg->pin); */
5527 + inode_unlock(dst_inode);
5528 + if (unlikely(err))
5531 + src_inode = d_inode(h_src);
5533 + && (src_inode->i_nlink > 1
5534 + || src_inode->i_state & I_LINKABLE)
5536 + au_plink_append(inode, cpg->bdst, h_dst);
5538 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5539 + a->h_path.dentry = h_dst;
5540 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5543 + goto out_parent; /* success */
5547 + a->h_path.dentry = h_parent;
5548 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5549 + a->h_path.dentry = h_dst;
5551 + if (d_is_positive(h_dst)) {
5553 + /* no delegation since it is just created */
5554 + rerr = vfsub_unlink(h_dir, &a->h_path,
5555 + /*delegated*/NULL, /*force*/0);
5557 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5559 + au_dtime_revert(&a->dt);
5561 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5566 + au_delayed_kfree(a);
5571 +#if 0 /* reserved */
5572 +struct au_cpup_single_args {
5574 + struct au_cp_generic *cpg;
5575 + struct dentry *dst_parent;
5578 +static void au_call_cpup_single(void *args)
5580 + struct au_cpup_single_args *a = args;
5582 + au_pin_hdir_acquire_nest(a->cpg->pin);
5583 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5584 + au_pin_hdir_release(a->cpg->pin);
5589 + * prevent SIGXFSZ in copy-up.
5590 + * testing CAP_MKNOD is for generic fs,
5591 + * but CAP_FSETID is for xfs only, currently.
5593 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5596 + struct super_block *sb;
5597 + struct inode *h_dir;
5600 + sb = au_pinned_parent(pin)->d_sb;
5601 + if (!au_wkq_test()
5602 + && (!au_sbi(sb)->si_plink_maint_pid
5603 + || au_plink_maint(sb, AuLock_NOPLM))) {
5604 + switch (mode & S_IFMT) {
5606 + /* no condition about RLIMIT_FSIZE and the file size */
5611 + do_sio = !capable(CAP_MKNOD);
5615 + do_sio = ((mode & (S_ISUID | S_ISGID))
5616 + && !capable(CAP_FSETID));
5617 + /* this workaround may be removed in the future */
5619 + h_dir = au_pinned_h_dir(pin);
5620 + do_sio = h_dir->i_mode & S_ISVTX;
5627 +#if 0 /* reserved */
5628 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5631 + struct dentry *h_dentry;
5633 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5634 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5635 + err = au_cpup_single(cpg, dst_parent);
5637 + struct au_cpup_single_args args = {
5640 + .dst_parent = dst_parent
5642 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5643 + if (unlikely(wkq_err))
5652 + * copyup the @dentry from the first active lower branch to @bdst,
5653 + * using au_cpup_single().
5655 +static int au_cpup_simple(struct au_cp_generic *cpg)
5658 + unsigned int flags_orig;
5659 + struct dentry *dentry;
5661 + AuDebugOn(cpg->bsrc < 0);
5663 + dentry = cpg->dentry;
5664 + DiMustWriteLock(dentry);
5666 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5668 + flags_orig = cpg->flags;
5669 + au_fset_cpup(cpg->flags, RENAME);
5670 + err = au_cpup_single(cpg, NULL);
5671 + cpg->flags = flags_orig;
5673 + return 0; /* success */
5676 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5677 + au_set_dbtop(dentry, cpg->bsrc);
5683 +struct au_cpup_simple_args {
5685 + struct au_cp_generic *cpg;
5688 +static void au_call_cpup_simple(void *args)
5690 + struct au_cpup_simple_args *a = args;
5692 + au_pin_hdir_acquire_nest(a->cpg->pin);
5693 + *a->errp = au_cpup_simple(a->cpg);
5694 + au_pin_hdir_release(a->cpg->pin);
5697 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5700 + struct dentry *dentry, *parent;
5701 + struct file *h_file;
5702 + struct inode *h_dir;
5704 + dentry = cpg->dentry;
5706 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5707 + AuDebugOn(cpg->bsrc < 0);
5708 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5709 + err = PTR_ERR(h_file);
5710 + if (IS_ERR(h_file))
5714 + parent = dget_parent(dentry);
5715 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5716 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5717 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5718 + err = au_cpup_simple(cpg);
5720 + struct au_cpup_simple_args args = {
5724 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5725 + if (unlikely(wkq_err))
5731 + au_h_open_post(dentry, cpg->bsrc, h_file);
5737 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5739 + aufs_bindex_t bsrc, bbot;
5740 + struct dentry *dentry, *h_dentry;
5742 + if (cpg->bsrc < 0) {
5743 + dentry = cpg->dentry;
5744 + bbot = au_dbbot(dentry);
5745 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5746 + h_dentry = au_h_dptr(dentry, bsrc);
5748 + AuDebugOn(d_is_negative(h_dentry));
5752 + AuDebugOn(bsrc > bbot);
5755 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5756 + return au_do_sio_cpup_simple(cpg);
5759 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5761 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5762 + return au_do_sio_cpup_simple(cpg);
5765 +/* ---------------------------------------------------------------------- */
5768 + * copyup the deleted file for writing.
5770 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5771 + struct file *file)
5774 + unsigned int flags_orig;
5775 + aufs_bindex_t bsrc_orig;
5776 + struct au_dinfo *dinfo;
5778 + struct au_hdentry *hd;
5779 + struct dentry *h_dentry;
5782 + dinfo = au_di(cpg->dentry);
5783 + AuRwMustWriteLock(&dinfo->di_rwsem);
5785 + bsrc_orig = cpg->bsrc;
5786 + cpg->bsrc = dinfo->di_btop;
5787 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5788 + hdst.h_dentry = hdst.hd->hd_dentry;
5789 + hdst.hd->hd_dentry = wh_dentry;
5790 + dinfo->di_btop = cpg->bdst;
5792 + hsrc.h_dentry = NULL;
5794 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5795 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5796 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5798 + flags_orig = cpg->flags;
5799 + cpg->flags = !AuCpup_DTIME;
5800 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5801 + cpg->flags = flags_orig;
5804 + err = au_reopen_nondir(file);
5805 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5807 + hdst.hd->hd_dentry = hdst.h_dentry;
5808 + dinfo->di_btop = cpg->bsrc;
5809 + cpg->bsrc = bsrc_orig;
5814 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5817 + aufs_bindex_t bdst;
5818 + struct au_dtime dt;
5819 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5820 + struct au_branch *br;
5821 + struct path h_path;
5823 + dentry = cpg->dentry;
5825 + br = au_sbr(dentry->d_sb, bdst);
5826 + parent = dget_parent(dentry);
5827 + h_parent = au_h_dptr(parent, bdst);
5828 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5829 + err = PTR_ERR(wh_dentry);
5830 + if (IS_ERR(wh_dentry))
5833 + h_path.dentry = h_parent;
5834 + h_path.mnt = au_br_mnt(br);
5835 + au_dtime_store(&dt, parent, &h_path);
5836 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5837 + if (unlikely(err))
5841 + h_path.dentry = wh_dentry;
5842 + if (!d_is_dir(wh_dentry)) {
5843 + /* no delegation since it is just created */
5844 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5845 + /*delegated*/NULL, /*force*/0);
5847 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5848 + if (unlikely(err)) {
5849 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5853 + au_dtime_revert(&dt);
5854 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5863 +struct au_cpup_wh_args {
5865 + struct au_cp_generic *cpg;
5866 + struct file *file;
5869 +static void au_call_cpup_wh(void *args)
5871 + struct au_cpup_wh_args *a = args;
5873 + au_pin_hdir_acquire_nest(a->cpg->pin);
5874 + *a->errp = au_cpup_wh(a->cpg, a->file);
5875 + au_pin_hdir_release(a->cpg->pin);
5878 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5881 + aufs_bindex_t bdst;
5882 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5883 + struct inode *dir, *h_dir, *h_tmpdir;
5884 + struct au_wbr *wbr;
5885 + struct au_pin wh_pin, *pin_orig;
5887 + dentry = cpg->dentry;
5889 + parent = dget_parent(dentry);
5890 + dir = d_inode(parent);
5893 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5896 + if (!h_dir->i_nlink) {
5897 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5898 + h_orph = wbr->wbr_orph;
5900 + h_parent = dget(au_h_dptr(parent, bdst));
5901 + au_set_h_dptr(parent, bdst, dget(h_orph));
5902 + h_tmpdir = d_inode(h_orph);
5903 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5905 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5906 + /* todo: au_h_open_pre()? */
5908 + pin_orig = cpg->pin;
5909 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5910 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5911 + cpg->pin = &wh_pin;
5914 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5915 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5916 + err = au_cpup_wh(cpg, file);
5918 + struct au_cpup_wh_args args = {
5923 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5924 + if (unlikely(wkq_err))
5929 + inode_unlock(h_tmpdir);
5930 + /* todo: au_h_open_post()? */
5931 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5932 + au_set_h_dptr(parent, bdst, h_parent);
5933 + AuDebugOn(!pin_orig);
5934 + cpg->pin = pin_orig;
5942 +/* ---------------------------------------------------------------------- */
5945 + * generic routine for both of copy-up and copy-down.
5947 +/* cf. revalidate function in file.c */
5948 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5949 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5950 + struct au_pin *pin,
5951 + struct dentry *h_parent, void *arg),
5955 + struct au_pin pin;
5956 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5959 + parent = dget_parent(dentry);
5960 + if (IS_ROOT(parent))
5963 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5964 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5966 + /* do not use au_dpage */
5967 + real_parent = parent;
5970 + parent = dget_parent(dentry);
5971 + h_parent = au_h_dptr(parent, bdst);
5973 + goto out; /* success */
5975 + /* find top dir which is necessary to cpup */
5979 + parent = dget_parent(d);
5980 + di_read_lock_parent3(parent, !AuLock_IR);
5981 + h_parent = au_h_dptr(parent, bdst);
5982 + di_read_unlock(parent, !AuLock_IR);
5983 + } while (!h_parent);
5985 + if (d != real_parent)
5986 + di_write_lock_child3(d);
5988 + /* somebody else might create while we were sleeping */
5989 + h_dentry = au_h_dptr(d, bdst);
5990 + if (!h_dentry || d_is_negative(h_dentry)) {
5992 + au_update_dbtop(d);
5994 + au_pin_set_dentry(&pin, d);
5995 + err = au_do_pin(&pin);
5997 + err = cp(d, bdst, &pin, h_parent, arg);
6002 + if (d != real_parent)
6003 + di_write_unlock(d);
6004 + if (unlikely(err))
6013 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6014 + struct au_pin *pin,
6015 + struct dentry *h_parent __maybe_unused,
6016 + void *arg __maybe_unused)
6018 + struct au_cp_generic cpg = {
6024 + .flags = AuCpup_DTIME
6026 + return au_sio_cpup_simple(&cpg);
6029 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6031 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6034 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6037 + struct dentry *parent;
6038 + struct inode *dir;
6040 + parent = dget_parent(dentry);
6041 + dir = d_inode(parent);
6043 + if (au_h_iptr(dir, bdst))
6046 + di_read_unlock(parent, AuLock_IR);
6047 + di_write_lock_parent(parent);
6048 + /* someone else might change our inode while we were sleeping */
6049 + if (!au_h_iptr(dir, bdst))
6050 + err = au_cpup_dirs(dentry, bdst);
6051 + di_downgrade_lock(parent, AuLock_IR);
6057 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6058 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6059 +++ linux/fs/aufs/cpup.h 2017-03-02 14:24:13.856922210 +0100
6062 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6064 + * This program, aufs is free software; you can redistribute it and/or modify
6065 + * it under the terms of the GNU General Public License as published by
6066 + * the Free Software Foundation; either version 2 of the License, or
6067 + * (at your option) any later version.
6069 + * This program is distributed in the hope that it will be useful,
6070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6072 + * GNU General Public License for more details.
6074 + * You should have received a copy of the GNU General Public License
6075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6079 + * copy-up/down functions
6082 +#ifndef __AUFS_CPUP_H__
6083 +#define __AUFS_CPUP_H__
6087 +#include <linux/path.h>
6093 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6094 +void au_cpup_attr_timesizes(struct inode *inode);
6095 +void au_cpup_attr_nlink(struct inode *inode, int force);
6096 +void au_cpup_attr_changeable(struct inode *inode);
6097 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6098 +void au_cpup_attr_all(struct inode *inode, int force);
6100 +/* ---------------------------------------------------------------------- */
6102 +struct au_cp_generic {
6103 + struct dentry *dentry;
6104 + aufs_bindex_t bdst, bsrc;
6106 + struct au_pin *pin;
6107 + unsigned int flags;
6111 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6112 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6114 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6115 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6117 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6119 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6120 + the branch is marked as RO */
6122 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6123 +#define au_fset_cpup(flags, name) \
6124 + do { (flags) |= AuCpup_##name; } while (0)
6125 +#define au_fclr_cpup(flags, name) \
6126 + do { (flags) &= ~AuCpup_##name; } while (0)
6128 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6129 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6130 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6131 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6133 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6134 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6135 + struct au_pin *pin,
6136 + struct dentry *h_parent, void *arg),
6138 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6139 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6141 +/* ---------------------------------------------------------------------- */
6143 +/* keep timestamps when copyup */
6145 + struct dentry *dt_dentry;
6146 + struct path dt_h_path;
6147 + struct timespec dt_atime, dt_mtime;
6149 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6150 + struct path *h_path);
6151 +void au_dtime_revert(struct au_dtime *dt);
6153 +#endif /* __KERNEL__ */
6154 +#endif /* __AUFS_CPUP_H__ */
6155 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6156 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6157 +++ linux/fs/aufs/dbgaufs.c 2017-03-02 14:24:13.856922210 +0100
6160 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6162 + * This program, aufs is free software; you can redistribute it and/or modify
6163 + * it under the terms of the GNU General Public License as published by
6164 + * the Free Software Foundation; either version 2 of the License, or
6165 + * (at your option) any later version.
6167 + * This program is distributed in the hope that it will be useful,
6168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6170 + * GNU General Public License for more details.
6172 + * You should have received a copy of the GNU General Public License
6173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6177 + * debugfs interface
6180 +#include <linux/debugfs.h>
6183 +#ifndef CONFIG_SYSFS
6184 +#error DEBUG_FS depends upon SYSFS
6187 +static struct dentry *dbgaufs;
6188 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6190 +/* 20 is max digits length of ulong 64 */
6191 +struct dbgaufs_arg {
6197 + * common function for all XINO files
6199 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6200 + struct file *file)
6202 + au_delayed_kfree(file->private_data);
6206 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6210 + struct dbgaufs_arg *p;
6213 + p = kmalloc(sizeof(*p), GFP_NOFS);
6219 + file->private_data = p;
6223 + err = vfs_getattr(&xf->f_path, &st);
6227 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6228 + (long)file_count(xf), st.blocks, st.blksize,
6229 + (long long)st.size);
6231 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6232 + st.blocks, st.blksize,
6233 + (long long)st.size);
6234 + AuDebugOn(p->n >= sizeof(p->a));
6236 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6245 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6246 + size_t count, loff_t *ppos)
6248 + struct dbgaufs_arg *p;
6250 + p = file->private_data;
6251 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6254 +/* ---------------------------------------------------------------------- */
6256 +struct dbgaufs_plink_arg {
6261 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6262 + struct file *file)
6264 + au_delayed_free_page((unsigned long)file->private_data);
6268 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6270 + int err, i, limit;
6271 + unsigned long n, sum;
6272 + struct dbgaufs_plink_arg *p;
6273 + struct au_sbinfo *sbinfo;
6274 + struct super_block *sb;
6275 + struct au_sphlhead *sphl;
6278 + p = (void *)get_zeroed_page(GFP_NOFS);
6283 + sbinfo = inode->i_private;
6284 + sb = sbinfo->si_sb;
6285 + si_noflush_read_lock(sb);
6286 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6287 + limit = PAGE_SIZE - sizeof(p->n);
6289 + /* the number of buckets */
6290 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6295 + for (i = 0, sphl = sbinfo->si_plink;
6296 + i < AuPlink_NHASH;
6298 + n = au_sphl_count(sphl);
6301 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6304 + if (unlikely(limit <= 0))
6307 + p->a[p->n - 1] = '\n';
6309 + /* the sum of plinks */
6310 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6313 + if (unlikely(limit <= 0))
6316 +#define str "1\n0\n0\n"
6317 + p->n = sizeof(str) - 1;
6318 + strcpy(p->a, str);
6321 + si_read_unlock(sb);
6324 + file->private_data = p;
6325 + goto out; /* success */
6328 + au_delayed_free_page((unsigned long)p);
6333 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6334 + size_t count, loff_t *ppos)
6336 + struct dbgaufs_plink_arg *p;
6338 + p = file->private_data;
6339 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6342 +static const struct file_operations dbgaufs_plink_fop = {
6343 + .owner = THIS_MODULE,
6344 + .open = dbgaufs_plink_open,
6345 + .release = dbgaufs_plink_release,
6346 + .read = dbgaufs_plink_read
6349 +/* ---------------------------------------------------------------------- */
6351 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6354 + struct au_sbinfo *sbinfo;
6355 + struct super_block *sb;
6357 + sbinfo = inode->i_private;
6358 + sb = sbinfo->si_sb;
6359 + si_noflush_read_lock(sb);
6360 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6361 + si_read_unlock(sb);
6365 +static const struct file_operations dbgaufs_xib_fop = {
6366 + .owner = THIS_MODULE,
6367 + .open = dbgaufs_xib_open,
6368 + .release = dbgaufs_xi_release,
6369 + .read = dbgaufs_xi_read
6372 +/* ---------------------------------------------------------------------- */
6374 +#define DbgaufsXi_PREFIX "xi"
6376 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6380 + struct au_sbinfo *sbinfo;
6381 + struct super_block *sb;
6383 + struct qstr *name;
6387 + name = &file->f_path.dentry->d_name;
6388 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6389 + || memcmp(name->name, DbgaufsXi_PREFIX,
6390 + sizeof(DbgaufsXi_PREFIX) - 1)))
6392 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6393 + if (unlikely(err))
6396 + sbinfo = inode->i_private;
6397 + sb = sbinfo->si_sb;
6398 + si_noflush_read_lock(sb);
6399 + if (l <= au_sbbot(sb)) {
6400 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6401 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6404 + si_read_unlock(sb);
6410 +static const struct file_operations dbgaufs_xino_fop = {
6411 + .owner = THIS_MODULE,
6412 + .open = dbgaufs_xino_open,
6413 + .release = dbgaufs_xi_release,
6414 + .read = dbgaufs_xi_read
6417 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6419 + aufs_bindex_t bbot;
6420 + struct au_branch *br;
6421 + struct au_xino_file *xi;
6423 + if (!au_sbi(sb)->si_dbgaufs)
6426 + bbot = au_sbbot(sb);
6427 + for (; bindex <= bbot; bindex++) {
6428 + br = au_sbr(sb, bindex);
6429 + xi = &br->br_xino;
6430 + /* debugfs acquires the parent i_mutex */
6432 + debugfs_remove(xi->xi_dbgaufs);
6434 + xi->xi_dbgaufs = NULL;
6438 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6440 + struct au_sbinfo *sbinfo;
6441 + struct dentry *parent;
6442 + struct au_branch *br;
6443 + struct au_xino_file *xi;
6444 + aufs_bindex_t bbot;
6445 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6447 + sbinfo = au_sbi(sb);
6448 + parent = sbinfo->si_dbgaufs;
6452 + bbot = au_sbbot(sb);
6453 + for (; bindex <= bbot; bindex++) {
6454 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6455 + br = au_sbr(sb, bindex);
6456 + xi = &br->br_xino;
6457 + AuDebugOn(xi->xi_dbgaufs);
6458 + /* debugfs acquires the parent i_mutex */
6460 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6461 + sbinfo, &dbgaufs_xino_fop);
6463 + /* ignore an error */
6464 + if (unlikely(!xi->xi_dbgaufs))
6465 + AuWarn1("failed %s under debugfs\n", name);
6469 +/* ---------------------------------------------------------------------- */
6471 +#ifdef CONFIG_AUFS_EXPORT
6472 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6475 + struct au_sbinfo *sbinfo;
6476 + struct super_block *sb;
6478 + sbinfo = inode->i_private;
6479 + sb = sbinfo->si_sb;
6480 + si_noflush_read_lock(sb);
6481 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6482 + si_read_unlock(sb);
6486 +static const struct file_operations dbgaufs_xigen_fop = {
6487 + .owner = THIS_MODULE,
6488 + .open = dbgaufs_xigen_open,
6489 + .release = dbgaufs_xi_release,
6490 + .read = dbgaufs_xi_read
6493 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6498 + * This function is a dynamic '__init' function actually,
6499 + * so the tiny check for si_rwsem is unnecessary.
6501 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6504 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6505 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6506 + &dbgaufs_xigen_fop);
6507 + if (sbinfo->si_dbgaufs_xigen)
6513 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6517 +#endif /* CONFIG_AUFS_EXPORT */
6519 +/* ---------------------------------------------------------------------- */
6521 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6524 + * This function is a dynamic '__fin' function actually,
6525 + * so the tiny check for si_rwsem is unnecessary.
6527 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6529 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6530 + sbinfo->si_dbgaufs = NULL;
6531 + kobject_put(&sbinfo->si_kobj);
6534 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6537 + char name[SysaufsSiNameLen];
6540 + * This function is a dynamic '__init' function actually,
6541 + * so the tiny check for si_rwsem is unnecessary.
6543 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6547 + AuErr1("/debug/aufs is uninitialized\n");
6552 + sysaufs_name(sbinfo, name);
6553 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6554 + if (unlikely(!sbinfo->si_dbgaufs))
6556 + kobject_get(&sbinfo->si_kobj);
6558 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6559 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6560 + &dbgaufs_xib_fop);
6561 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6564 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6565 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6566 + &dbgaufs_plink_fop);
6567 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6570 + err = dbgaufs_xigen_init(sbinfo);
6572 + goto out; /* success */
6575 + dbgaufs_si_fin(sbinfo);
6580 +/* ---------------------------------------------------------------------- */
6582 +void dbgaufs_fin(void)
6584 + debugfs_remove(dbgaufs);
6587 +int __init dbgaufs_init(void)
6592 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6597 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6598 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6599 +++ linux/fs/aufs/dbgaufs.h 2017-03-02 14:24:13.856922210 +0100
6602 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6604 + * This program, aufs is free software; you can redistribute it and/or modify
6605 + * it under the terms of the GNU General Public License as published by
6606 + * the Free Software Foundation; either version 2 of the License, or
6607 + * (at your option) any later version.
6609 + * This program is distributed in the hope that it will be useful,
6610 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6611 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6612 + * GNU General Public License for more details.
6614 + * You should have received a copy of the GNU General Public License
6615 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6619 + * debugfs interface
6622 +#ifndef __DBGAUFS_H__
6623 +#define __DBGAUFS_H__
6627 +struct super_block;
6630 +#ifdef CONFIG_DEBUG_FS
6632 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6633 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6634 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6635 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6636 +void dbgaufs_fin(void);
6637 +int __init dbgaufs_init(void);
6639 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6640 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6641 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6642 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6643 +AuStubVoid(dbgaufs_fin, void)
6644 +AuStubInt0(__init dbgaufs_init, void)
6645 +#endif /* CONFIG_DEBUG_FS */
6647 +#endif /* __KERNEL__ */
6648 +#endif /* __DBGAUFS_H__ */
6649 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6650 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6651 +++ linux/fs/aufs/dcsub.c 2017-03-02 14:24:13.856922210 +0100
6654 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6656 + * This program, aufs is free software; you can redistribute it and/or modify
6657 + * it under the terms of the GNU General Public License as published by
6658 + * the Free Software Foundation; either version 2 of the License, or
6659 + * (at your option) any later version.
6661 + * This program is distributed in the hope that it will be useful,
6662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6664 + * GNU General Public License for more details.
6666 + * You should have received a copy of the GNU General Public License
6667 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6671 + * sub-routines for dentry cache
6676 +static void au_dpage_free(struct au_dpage *dpage)
6679 + struct dentry **p;
6681 + p = dpage->dentries;
6682 + for (i = 0; i < dpage->ndentry; i++)
6684 + au_delayed_free_page((unsigned long)dpage->dentries);
6687 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6693 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6694 + if (unlikely(!dpages->dpages))
6697 + p = (void *)__get_free_page(gfp);
6701 + dpages->dpages[0].ndentry = 0;
6702 + dpages->dpages[0].dentries = p;
6703 + dpages->ndpage = 1;
6704 + return 0; /* success */
6707 + au_delayed_kfree(dpages->dpages);
6712 +void au_dpages_free(struct au_dcsub_pages *dpages)
6715 + struct au_dpage *p;
6717 + p = dpages->dpages;
6718 + for (i = 0; i < dpages->ndpage; i++)
6719 + au_dpage_free(p++);
6720 + au_delayed_kfree(dpages->dpages);
6723 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6724 + struct dentry *dentry, gfp_t gfp)
6727 + struct au_dpage *dpage;
6730 + dpage = dpages->dpages + dpages->ndpage - 1;
6731 + sz = PAGE_SIZE / sizeof(dentry);
6732 + if (unlikely(dpage->ndentry >= sz)) {
6733 + AuLabel(new dpage);
6735 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6736 + p = au_kzrealloc(dpages->dpages, sz,
6737 + sz + sizeof(*dpages->dpages), gfp,
6742 + dpages->dpages = p;
6743 + dpage = dpages->dpages + dpages->ndpage;
6744 + p = (void *)__get_free_page(gfp);
6748 + dpage->ndentry = 0;
6749 + dpage->dentries = p;
6753 + AuDebugOn(au_dcount(dentry) <= 0);
6754 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6755 + return 0; /* success */
6761 +/* todo: BAD approach */
6762 +/* copied from linux/fs/dcache.c */
6770 +extern void d_walk(struct dentry *parent, void *data,
6771 + enum d_walk_ret (*enter)(void *, struct dentry *),
6772 + void (*finish)(void *));
6774 +struct ac_dpages_arg {
6776 + struct au_dcsub_pages *dpages;
6777 + struct super_block *sb;
6778 + au_dpages_test test;
6782 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6784 + enum d_walk_ret ret;
6785 + struct ac_dpages_arg *arg = _arg;
6787 + ret = D_WALK_CONTINUE;
6788 + if (dentry->d_sb == arg->sb
6789 + && !IS_ROOT(dentry)
6790 + && au_dcount(dentry) > 0
6792 + && (!arg->test || arg->test(dentry, arg->arg))) {
6793 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6794 + if (unlikely(arg->err))
6795 + ret = D_WALK_QUIT;
6801 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6802 + au_dpages_test test, void *arg)
6804 + struct ac_dpages_arg args = {
6812 + d_walk(root, &args, au_call_dpages_append, NULL);
6817 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6818 + int do_include, au_dpages_test test, void *arg)
6823 + write_seqlock(&rename_lock);
6824 + spin_lock(&dentry->d_lock);
6826 + && au_dcount(dentry) > 0
6827 + && (!test || test(dentry, arg)))
6828 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6829 + spin_unlock(&dentry->d_lock);
6830 + if (unlikely(err))
6834 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6837 + while (!IS_ROOT(dentry)) {
6838 + dentry = dentry->d_parent; /* rename_lock is locked */
6839 + spin_lock(&dentry->d_lock);
6840 + if (au_dcount(dentry) > 0
6841 + && (!test || test(dentry, arg)))
6842 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6843 + spin_unlock(&dentry->d_lock);
6844 + if (unlikely(err))
6849 + write_sequnlock(&rename_lock);
6853 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6855 + return au_di(dentry) && dentry->d_sb == arg;
6858 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6859 + struct dentry *dentry, int do_include)
6861 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6862 + au_dcsub_dpages_aufs, dentry->d_sb);
6865 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6867 + struct path path[2] = {
6876 + return path_is_under(path + 0, path + 1);
6878 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6879 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6880 +++ linux/fs/aufs/dcsub.h 2017-03-02 14:24:13.856922210 +0100
6883 + * Copyright (C) 2005-2017 Junjiro R. Okajima
6885 + * This program, aufs is free software; you can redistribute it and/or modify
6886 + * it under the terms of the GNU General Public License as published by
6887 + * the Free Software Foundation; either version 2 of the License, or
6888 + * (at your option) any later version.
6890 + * This program is distributed in the hope that it will be useful,
6891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6893 + * GNU General Public License for more details.
6895 + * You should have received a copy of the GNU General Public License
6896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6900 + * sub-routines for dentry cache
6903 +#ifndef __AUFS_DCSUB_H__
6904 +#define __AUFS_DCSUB_H__
6908 +#include <linux/dcache.h>
6909 +#include <linux/fs.h>
6913 + struct dentry **dentries;
6916 +struct au_dcsub_pages {
6918 + struct au_dpage *dpages;
6921 +/* ---------------------------------------------------------------------- */
6924 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6925 +void au_dpages_free(struct au_dcsub_pages *dpages);
6926 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6927 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6928 + au_dpages_test test, void *arg);
6929 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6930 + int do_include, au_dpages_test test, void *arg);
6931 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6932 + struct dentry *dentry, int do_include);
6933 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6935 +/* ---------------------------------------------------------------------- */
6938 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6939 + * include/linux/dcache.h. Try them (in the future).
6942 +static inline int au_d_hashed_positive(struct dentry *d)
6945 + struct inode *inode = d_inode(d);
6948 + if (unlikely(d_unhashed(d)
6949 + || d_is_negative(d)
6950 + || !inode->i_nlink))
6955 +static inline int au_d_linkable(struct dentry *d)
6958 + struct inode *inode = d_inode(d);
6960 + err = au_d_hashed_positive(d);
6962 + && d_is_positive(d)
6963 + && (inode->i_state & I_LINKABLE))
6968 +static inline int au_d_alive(struct dentry *d)
6971 + struct inode *inode;
6975 + err = au_d_hashed_positive(d);
6977 + inode = d_inode(d);
6978 + if (unlikely(d_unlinked(d)
6979 + || d_is_negative(d)
6980 + || !inode->i_nlink))
6986 +static inline int au_alive_dir(struct dentry *d)
6990 + err = au_d_alive(d);
6991 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6996 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6998 + return a->len == b->len
6999 + && !memcmp(a->name, b->name, a->len);
7004 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7006 + * the type of d_lockref.count became int, but the inlined function d_count()
7007 + * still returns unsigned int.
7008 + * I don't know why. Maybe it is for every d_count() users?
7009 + * Anyway au_dcount() lives on.
7011 +static inline int au_dcount(struct dentry *d)
7013 + return (int)d_count(d);
7016 +#endif /* __KERNEL__ */
7017 +#endif /* __AUFS_DCSUB_H__ */
7018 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7019 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7020 +++ linux/fs/aufs/debug.c 2017-03-02 14:24:13.856922210 +0100
7023 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7025 + * This program, aufs is free software; you can redistribute it and/or modify
7026 + * it under the terms of the GNU General Public License as published by
7027 + * the Free Software Foundation; either version 2 of the License, or
7028 + * (at your option) any later version.
7030 + * This program is distributed in the hope that it will be useful,
7031 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7032 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7033 + * GNU General Public License for more details.
7035 + * You should have received a copy of the GNU General Public License
7036 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7040 + * debug print functions
7045 +/* Returns 0, or -errno. arg is in kp->arg. */
7046 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7050 + err = kstrtoint(val, 0, &n);
7060 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7061 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7066 + return sprintf(buffer, "%d", atomic_read(a));
7069 +static struct kernel_param_ops param_ops_atomic_t = {
7070 + .set = param_atomic_t_set,
7071 + .get = param_atomic_t_get
7072 + /* void (*free)(void *arg) */
7075 +atomic_t aufs_debug = ATOMIC_INIT(0);
7076 +MODULE_PARM_DESC(debug, "debug print");
7077 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7079 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7080 +char *au_plevel = KERN_DEBUG;
7081 +#define dpri(fmt, ...) do { \
7083 + && strcmp(au_plevel, KERN_DEBUG)) \
7084 + || au_debug_test()) \
7085 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7088 +/* ---------------------------------------------------------------------- */
7090 +void au_dpri_whlist(struct au_nhash *whlist)
7092 + unsigned long ul, n;
7093 + struct hlist_head *head;
7094 + struct au_vdir_wh *pos;
7096 + n = whlist->nh_num;
7097 + head = whlist->nh_head;
7098 + for (ul = 0; ul < n; ul++) {
7099 + hlist_for_each_entry(pos, head, wh_hash)
7100 + dpri("b%d, %.*s, %d\n",
7102 + pos->wh_str.len, pos->wh_str.name,
7108 +void au_dpri_vdir(struct au_vdir *vdir)
7111 + union au_vdir_deblk_p p;
7114 + if (!vdir || IS_ERR(vdir)) {
7115 + dpri("err %ld\n", PTR_ERR(vdir));
7119 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7120 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7121 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7122 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7123 + p.deblk = vdir->vd_deblk[ul];
7125 + dpri("[%lu]: %p\n", ul, o);
7129 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7130 + struct dentry *wh)
7135 + if (!inode || IS_ERR(inode)) {
7136 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7140 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7141 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7142 + && sizeof(inode->i_blocks) != sizeof(u64));
7144 + n = (void *)wh->d_name.name;
7145 + l = wh->d_name.len;
7148 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7149 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7151 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7152 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7153 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7154 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7155 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7156 + inode->i_state, inode->i_flags, inode->i_version,
7157 + inode->i_generation,
7158 + l ? ", wh " : "", l, n);
7162 +void au_dpri_inode(struct inode *inode)
7164 + struct au_iinfo *iinfo;
7165 + struct au_hinode *hi;
7166 + aufs_bindex_t bindex;
7169 + err = do_pri_inode(-1, inode, -1, NULL);
7170 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7173 + iinfo = au_ii(inode);
7174 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7175 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7176 + if (iinfo->ii_btop < 0)
7179 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7180 + hi = au_hinode(iinfo, bindex);
7182 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7186 +void au_dpri_dalias(struct inode *inode)
7190 + spin_lock(&inode->i_lock);
7191 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7192 + au_dpri_dentry(d);
7193 + spin_unlock(&inode->i_lock);
7196 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7198 + struct dentry *wh = NULL;
7200 + struct inode *inode;
7201 + struct au_iinfo *iinfo;
7202 + struct au_hinode *hi;
7204 + if (!dentry || IS_ERR(dentry)) {
7205 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7208 + /* do not call dget_parent() here */
7209 + /* note: access d_xxx without d_lock */
7210 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7211 + bindex, dentry, dentry,
7212 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7213 + au_dcount(dentry), dentry->d_flags,
7214 + d_unhashed(dentry) ? "un" : "");
7217 + if (d_is_positive(dentry))
7218 + inode = d_inode(dentry);
7220 + && au_test_aufs(dentry->d_sb)
7222 + && !au_is_bad_inode(inode)) {
7223 + iinfo = au_ii(inode);
7224 + hi = au_hinode(iinfo, bindex);
7226 + wh = hi->hi_whdentry;
7228 + do_pri_inode(bindex, inode, hn, wh);
7232 +void au_dpri_dentry(struct dentry *dentry)
7234 + struct au_dinfo *dinfo;
7235 + aufs_bindex_t bindex;
7238 + err = do_pri_dentry(-1, dentry);
7239 + if (err || !au_test_aufs(dentry->d_sb))
7242 + dinfo = au_di(dentry);
7245 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7246 + dinfo->di_btop, dinfo->di_bbot,
7247 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7248 + dinfo->di_tmpfile);
7249 + if (dinfo->di_btop < 0)
7251 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7252 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7255 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7259 + if (!file || IS_ERR(file)) {
7260 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7265 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7266 + && au_test_aufs(file->f_path.dentry->d_sb)
7268 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7269 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7270 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7271 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7272 + file->f_version, file->f_pos, a);
7273 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7274 + do_pri_dentry(bindex, file->f_path.dentry);
7278 +void au_dpri_file(struct file *file)
7280 + struct au_finfo *finfo;
7281 + struct au_fidir *fidir;
7282 + struct au_hfile *hfile;
7283 + aufs_bindex_t bindex;
7286 + err = do_pri_file(-1, file);
7288 + || IS_ERR_OR_NULL(file->f_path.dentry)
7289 + || !au_test_aufs(file->f_path.dentry->d_sb))
7292 + finfo = au_fi(file);
7295 + if (finfo->fi_btop < 0)
7297 + fidir = finfo->fi_hdir;
7299 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7301 + for (bindex = finfo->fi_btop;
7302 + bindex >= 0 && bindex <= fidir->fd_bbot;
7304 + hfile = fidir->fd_hfile + bindex;
7305 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7309 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7311 + struct vfsmount *mnt;
7312 + struct super_block *sb;
7314 + if (!br || IS_ERR(br))
7316 + mnt = au_br_mnt(br);
7317 + if (!mnt || IS_ERR(mnt))
7320 + if (!sb || IS_ERR(sb))
7323 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7324 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7326 + bindex, br->br_perm, br->br_id, au_br_count(br),
7327 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7328 + sb->s_flags, sb->s_count,
7329 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7333 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7337 +void au_dpri_sb(struct super_block *sb)
7339 + struct au_sbinfo *sbinfo;
7340 + aufs_bindex_t bindex;
7342 + /* to reuduce stack size */
7344 + struct vfsmount mnt;
7345 + struct au_branch fake;
7348 + /* this function can be called from magic sysrq */
7349 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7350 + if (unlikely(!a)) {
7351 + dpri("no memory\n");
7355 + a->mnt.mnt_sb = sb;
7356 + a->fake.br_path.mnt = &a->mnt;
7357 + au_br_count_init(&a->fake);
7358 + err = do_pri_br(-1, &a->fake);
7359 + au_br_count_fin(&a->fake);
7360 + au_delayed_kfree(a);
7361 + dpri("dev 0x%x\n", sb->s_dev);
7362 + if (err || !au_test_aufs(sb))
7365 + sbinfo = au_sbi(sb);
7368 + dpri("nw %d, gen %u, kobj %d\n",
7369 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7370 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7371 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7372 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7375 +/* ---------------------------------------------------------------------- */
7377 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7379 + struct inode *h_inode, *inode = d_inode(dentry);
7380 + struct dentry *h_dentry;
7381 + aufs_bindex_t bindex, bbot, bi;
7383 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7386 + bbot = au_dbbot(dentry);
7387 + bi = au_ibbot(inode);
7390 + bindex = au_dbtop(dentry);
7391 + bi = au_ibtop(inode);
7395 + for (; bindex <= bbot; bindex++) {
7396 + h_dentry = au_h_dptr(dentry, bindex);
7399 + h_inode = au_h_iptr(inode, bindex);
7400 + if (unlikely(h_inode != d_inode(h_dentry))) {
7402 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7403 + AuDbgDentry(dentry);
7404 + AuDbgInode(inode);
7411 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7414 + struct au_dcsub_pages dpages;
7415 + struct au_dpage *dpage;
7416 + struct dentry **dentries;
7418 + err = au_dpages_init(&dpages, GFP_NOFS);
7420 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7422 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7423 + dpage = dpages.dpages + i;
7424 + dentries = dpage->dentries;
7425 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7426 + AuDebugOn(au_digen_test(dentries[j], sigen));
7428 + au_dpages_free(&dpages);
7431 +void au_dbg_verify_kthread(void)
7433 + if (au_wkq_test()) {
7436 + * It may be recursive, but udba=notify between two aufs mounts,
7437 + * where a single ro branch is shared, is not a problem.
7443 +/* ---------------------------------------------------------------------- */
7445 +int __init au_debug_init(void)
7447 + aufs_bindex_t bindex;
7448 + struct au_vdir_destr destr;
7451 + AuDebugOn(bindex >= 0);
7454 + AuDebugOn(destr.len < NAME_MAX);
7456 +#ifdef CONFIG_4KSTACKS
7457 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7462 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7463 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7464 +++ linux/fs/aufs/debug.h 2017-03-02 14:24:13.856922210 +0100
7467 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7469 + * This program, aufs is free software; you can redistribute it and/or modify
7470 + * it under the terms of the GNU General Public License as published by
7471 + * the Free Software Foundation; either version 2 of the License, or
7472 + * (at your option) any later version.
7474 + * This program is distributed in the hope that it will be useful,
7475 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7476 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7477 + * GNU General Public License for more details.
7479 + * You should have received a copy of the GNU General Public License
7480 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7484 + * debug print functions
7487 +#ifndef __AUFS_DEBUG_H__
7488 +#define __AUFS_DEBUG_H__
7492 +#include <linux/atomic.h>
7493 +#include <linux/module.h>
7494 +#include <linux/kallsyms.h>
7495 +#include <linux/sysrq.h>
7497 +#ifdef CONFIG_AUFS_DEBUG
7498 +#define AuDebugOn(a) BUG_ON(a)
7500 +/* module parameter */
7501 +extern atomic_t aufs_debug;
7502 +static inline void au_debug_on(void)
7504 + atomic_inc(&aufs_debug);
7506 +static inline void au_debug_off(void)
7508 + atomic_dec_if_positive(&aufs_debug);
7511 +static inline int au_debug_test(void)
7513 + return atomic_read(&aufs_debug) > 0;
7516 +#define AuDebugOn(a) do {} while (0)
7517 +AuStubVoid(au_debug_on, void)
7518 +AuStubVoid(au_debug_off, void)
7519 +AuStubInt0(au_debug_test, void)
7520 +#endif /* CONFIG_AUFS_DEBUG */
7522 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7524 +/* ---------------------------------------------------------------------- */
7528 +#define AuDbg(fmt, ...) do { \
7529 + if (au_debug_test()) \
7530 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7532 +#define AuLabel(l) AuDbg(#l "\n")
7533 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7534 +#define AuWarn1(fmt, ...) do { \
7535 + static unsigned char _c; \
7537 + pr_warn(fmt, ##__VA_ARGS__); \
7540 +#define AuErr1(fmt, ...) do { \
7541 + static unsigned char _c; \
7543 + pr_err(fmt, ##__VA_ARGS__); \
7546 +#define AuIOErr1(fmt, ...) do { \
7547 + static unsigned char _c; \
7549 + AuIOErr(fmt, ##__VA_ARGS__); \
7552 +#define AuUnsupportMsg "This operation is not supported." \
7553 + " Please report this application to aufs-users ML."
7554 +#define AuUnsupport(fmt, ...) do { \
7555 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7559 +#define AuTraceErr(e) do { \
7560 + if (unlikely((e) < 0)) \
7561 + AuDbg("err %d\n", (int)(e)); \
7564 +#define AuTraceErrPtr(p) do { \
7566 + AuDbg("err %ld\n", PTR_ERR(p)); \
7569 +/* dirty macros for debug print, use with "%.*s" and caution */
7570 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7572 +/* ---------------------------------------------------------------------- */
7575 +#ifdef CONFIG_AUFS_DEBUG
7576 +extern struct mutex au_dbg_mtx;
7577 +extern char *au_plevel;
7579 +void au_dpri_whlist(struct au_nhash *whlist);
7581 +void au_dpri_vdir(struct au_vdir *vdir);
7583 +void au_dpri_inode(struct inode *inode);
7584 +void au_dpri_dalias(struct inode *inode);
7585 +void au_dpri_dentry(struct dentry *dentry);
7587 +void au_dpri_file(struct file *filp);
7588 +struct super_block;
7589 +void au_dpri_sb(struct super_block *sb);
7591 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7592 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7593 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7594 +void au_dbg_verify_kthread(void);
7596 +int __init au_debug_init(void);
7598 +#define AuDbgWhlist(w) do { \
7599 + mutex_lock(&au_dbg_mtx); \
7601 + au_dpri_whlist(w); \
7602 + mutex_unlock(&au_dbg_mtx); \
7605 +#define AuDbgVdir(v) do { \
7606 + mutex_lock(&au_dbg_mtx); \
7608 + au_dpri_vdir(v); \
7609 + mutex_unlock(&au_dbg_mtx); \
7612 +#define AuDbgInode(i) do { \
7613 + mutex_lock(&au_dbg_mtx); \
7615 + au_dpri_inode(i); \
7616 + mutex_unlock(&au_dbg_mtx); \
7619 +#define AuDbgDAlias(i) do { \
7620 + mutex_lock(&au_dbg_mtx); \
7622 + au_dpri_dalias(i); \
7623 + mutex_unlock(&au_dbg_mtx); \
7626 +#define AuDbgDentry(d) do { \
7627 + mutex_lock(&au_dbg_mtx); \
7629 + au_dpri_dentry(d); \
7630 + mutex_unlock(&au_dbg_mtx); \
7633 +#define AuDbgFile(f) do { \
7634 + mutex_lock(&au_dbg_mtx); \
7636 + au_dpri_file(f); \
7637 + mutex_unlock(&au_dbg_mtx); \
7640 +#define AuDbgSb(sb) do { \
7641 + mutex_lock(&au_dbg_mtx); \
7642 + AuDbg(#sb "\n"); \
7644 + mutex_unlock(&au_dbg_mtx); \
7647 +#define AuDbgSym(addr) do { \
7648 + char sym[KSYM_SYMBOL_LEN]; \
7649 + sprint_symbol(sym, (unsigned long)addr); \
7650 + AuDbg("%s\n", sym); \
7653 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7654 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7655 +AuStubVoid(au_dbg_verify_kthread, void)
7656 +AuStubInt0(__init au_debug_init, void)
7658 +#define AuDbgWhlist(w) do {} while (0)
7659 +#define AuDbgVdir(v) do {} while (0)
7660 +#define AuDbgInode(i) do {} while (0)
7661 +#define AuDbgDAlias(i) do {} while (0)
7662 +#define AuDbgDentry(d) do {} while (0)
7663 +#define AuDbgFile(f) do {} while (0)
7664 +#define AuDbgSb(sb) do {} while (0)
7665 +#define AuDbgSym(addr) do {} while (0)
7666 +#endif /* CONFIG_AUFS_DEBUG */
7668 +/* ---------------------------------------------------------------------- */
7670 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7671 +int __init au_sysrq_init(void);
7672 +void au_sysrq_fin(void);
7674 +#ifdef CONFIG_HW_CONSOLE
7675 +#define au_dbg_blocked() do { \
7677 + handle_sysrq('w'); \
7680 +AuStubVoid(au_dbg_blocked, void)
7684 +AuStubInt0(__init au_sysrq_init, void)
7685 +AuStubVoid(au_sysrq_fin, void)
7686 +AuStubVoid(au_dbg_blocked, void)
7687 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7689 +#endif /* __KERNEL__ */
7690 +#endif /* __AUFS_DEBUG_H__ */
7691 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7692 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7693 +++ linux/fs/aufs/dentry.c 2017-03-02 14:24:13.856922210 +0100
7696 + * Copyright (C) 2005-2017 Junjiro R. Okajima
7698 + * This program, aufs is free software; you can redistribute it and/or modify
7699 + * it under the terms of the GNU General Public License as published by
7700 + * the Free Software Foundation; either version 2 of the License, or
7701 + * (at your option) any later version.
7703 + * This program is distributed in the hope that it will be useful,
7704 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7705 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7706 + * GNU General Public License for more details.
7708 + * You should have received a copy of the GNU General Public License
7709 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7713 + * lookup and dentry operations
7716 +#include <linux/namei.h>
7719 +struct au_do_lookup_args {
7720 + unsigned int flags;
7725 + * returns positive/negative dentry, NULL or an error.
7726 + * NULL means whiteout-ed or not-found.
7728 +static struct dentry*
7729 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7730 + aufs_bindex_t bindex, struct qstr *wh_name,
7731 + struct au_do_lookup_args *args)
7733 + struct dentry *h_dentry;
7734 + struct inode *h_inode;
7735 + struct au_branch *br;
7736 + int wh_found, opq;
7737 + unsigned char wh_able;
7738 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7739 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7743 + br = au_sbr(dentry->d_sb, bindex);
7744 + wh_able = !!au_br_whable(br->br_perm);
7746 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7747 + h_dentry = ERR_PTR(wh_found);
7750 + if (unlikely(wh_found < 0))
7753 + /* We found a whiteout */
7754 + /* au_set_dbbot(dentry, bindex); */
7755 + au_set_dbwh(dentry, bindex);
7757 + return NULL; /* success */
7761 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7763 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7764 + if (IS_ERR(h_dentry)) {
7765 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7771 + h_inode = d_inode(h_dentry);
7772 + if (d_is_negative(h_dentry)) {
7775 + } else if (wh_found
7776 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7779 + if (au_dbbot(dentry) <= bindex)
7780 + au_set_dbbot(dentry, bindex);
7781 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7782 + au_set_dbtop(dentry, bindex);
7783 + au_set_h_dptr(dentry, bindex, h_dentry);
7785 + if (!d_is_dir(h_dentry)
7787 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7788 + goto out; /* success */
7790 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7791 + opq = au_diropq_test(h_dentry);
7792 + inode_unlock(h_inode);
7794 + au_set_dbdiropq(dentry, bindex);
7795 + else if (unlikely(opq < 0)) {
7796 + au_set_h_dptr(dentry, bindex, NULL);
7797 + h_dentry = ERR_PTR(opq);
7808 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7810 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7811 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7817 + * returns the number of lower positive dentries,
7818 + * otherwise an error.
7819 + * can be called at unlinking with @type is zero.
7821 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7822 + unsigned int flags)
7824 + int npositive, err;
7825 + aufs_bindex_t bindex, btail, bdiropq;
7826 + unsigned char isdir, dirperm1;
7827 + struct qstr whname;
7828 + struct au_do_lookup_args args = {
7831 + const struct qstr *name = &dentry->d_name;
7832 + struct dentry *parent;
7833 + struct super_block *sb;
7835 + sb = dentry->d_sb;
7836 + err = au_test_shwh(sb, name);
7837 + if (unlikely(err))
7840 + err = au_wh_name_alloc(&whname, name);
7841 + if (unlikely(err))
7844 + isdir = !!d_is_dir(dentry);
7845 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7848 + parent = dget_parent(dentry);
7849 + btail = au_dbtaildir(parent);
7850 + for (bindex = btop; bindex <= btail; bindex++) {
7851 + struct dentry *h_parent, *h_dentry;
7852 + struct inode *h_inode, *h_dir;
7854 + h_dentry = au_h_dptr(dentry, bindex);
7856 + if (d_is_positive(h_dentry))
7860 + h_parent = au_h_dptr(parent, bindex);
7861 + if (!h_parent || !d_is_dir(h_parent))
7864 + h_dir = d_inode(h_parent);
7865 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7866 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7868 + inode_unlock(h_dir);
7869 + err = PTR_ERR(h_dentry);
7870 + if (IS_ERR(h_dentry))
7873 + au_fclr_lkup(args.flags, ALLOW_NEG);
7875 + au_fset_lkup(args.flags, IGNORE_PERM);
7877 + if (au_dbwh(dentry) == bindex)
7881 + if (d_is_negative(h_dentry))
7883 + h_inode = d_inode(h_dentry);
7886 + args.type = h_inode->i_mode & S_IFMT;
7887 + if (args.type != S_IFDIR)
7890 + /* the type of lower may be different */
7891 + bdiropq = au_dbdiropq(dentry);
7892 + if (bdiropq >= 0 && bdiropq <= bindex)
7898 + AuLabel(positive);
7899 + au_update_dbtop(dentry);
7902 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7903 + && au_dbtop(dentry) < 0)) {
7905 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7911 + au_delayed_kfree(whname.name);
7916 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7918 + struct dentry *dentry;
7921 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7922 + dentry = vfsub_lkup_one(name, parent);
7924 + struct vfsub_lkup_one_args args = {
7930 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7931 + if (unlikely(wkq_err))
7932 + dentry = ERR_PTR(wkq_err);
7939 + * lookup @dentry on @bindex which should be negative.
7941 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7944 + struct dentry *parent, *h_parent, *h_dentry;
7945 + struct au_branch *br;
7947 + parent = dget_parent(dentry);
7948 + h_parent = au_h_dptr(parent, bindex);
7949 + br = au_sbr(dentry->d_sb, bindex);
7951 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7953 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7954 + err = PTR_ERR(h_dentry);
7955 + if (IS_ERR(h_dentry))
7957 + if (unlikely(d_is_positive(h_dentry))) {
7959 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7965 + if (bindex < au_dbtop(dentry))
7966 + au_set_dbtop(dentry, bindex);
7967 + if (au_dbbot(dentry) < bindex)
7968 + au_set_dbbot(dentry, bindex);
7969 + au_set_h_dptr(dentry, bindex, h_dentry);
7976 +/* ---------------------------------------------------------------------- */
7978 +/* subset of struct inode */
7980 + unsigned long i_ino;
7981 + /* unsigned int i_nlink; */
7987 + blkcnt_t i_blocks;
7992 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7994 + ia->i_ino = h_inode->i_ino;
7995 + /* ia->i_nlink = h_inode->i_nlink; */
7996 + ia->i_uid = h_inode->i_uid;
7997 + ia->i_gid = h_inode->i_gid;
7998 + ia->i_version = h_inode->i_version;
8000 + ia->i_size = h_inode->i_size;
8001 + ia->i_blocks = h_inode->i_blocks;
8003 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8006 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8008 + return ia->i_ino != h_inode->i_ino
8009 + /* || ia->i_nlink != h_inode->i_nlink */
8010 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8011 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8012 + || ia->i_version != h_inode->i_version
8014 + || ia->i_size != h_inode->i_size
8015 + || ia->i_blocks != h_inode->i_blocks
8017 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8020 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8021 + struct au_branch *br)
8024 + struct au_iattr ia;
8025 + struct inode *h_inode;
8026 + struct dentry *h_d;
8027 + struct super_block *h_sb;
8030 + memset(&ia, -1, sizeof(ia));
8031 + h_sb = h_dentry->d_sb;
8033 + if (d_is_positive(h_dentry)) {
8034 + h_inode = d_inode(h_dentry);
8035 + au_iattr_save(&ia, h_inode);
8036 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8037 + /* nfs d_revalidate may return 0 for negative dentry */
8038 + /* fuse d_revalidate always return 0 for negative dentry */
8041 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8042 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8043 + err = PTR_ERR(h_d);
8048 + if (unlikely(h_d != h_dentry
8049 + || d_inode(h_d) != h_inode
8050 + || (h_inode && au_iattr_test(&ia, h_inode))))
8051 + err = au_busy_or_stale();
8059 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8060 + struct dentry *h_parent, struct au_branch *br)
8065 + if (udba == AuOpt_UDBA_REVAL
8066 + && !au_test_fs_remote(h_dentry->d_sb)) {
8068 + err = (d_inode(h_dentry->d_parent) != h_dir);
8069 + } else if (udba != AuOpt_UDBA_NONE)
8070 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8075 +/* ---------------------------------------------------------------------- */
8077 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8080 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8081 + struct au_hdentry tmp, *p, *q;
8082 + struct au_dinfo *dinfo;
8083 + struct super_block *sb;
8085 + DiMustWriteLock(dentry);
8087 + sb = dentry->d_sb;
8088 + dinfo = au_di(dentry);
8089 + bbot = dinfo->di_bbot;
8090 + bwh = dinfo->di_bwh;
8091 + bdiropq = dinfo->di_bdiropq;
8092 + bindex = dinfo->di_btop;
8093 + p = au_hdentry(dinfo, bindex);
8094 + for (; bindex <= bbot; bindex++, p++) {
8095 + if (!p->hd_dentry)
8098 + new_bindex = au_br_index(sb, p->hd_id);
8099 + if (new_bindex == bindex)
8102 + if (dinfo->di_bwh == bindex)
8104 + if (dinfo->di_bdiropq == bindex)
8105 + bdiropq = new_bindex;
8106 + if (new_bindex < 0) {
8108 + p->hd_dentry = NULL;
8112 + /* swap two lower dentries, and loop again */
8113 + q = au_hdentry(dinfo, new_bindex);
8117 + if (tmp.hd_dentry) {
8123 + dinfo->di_bwh = -1;
8124 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8125 + dinfo->di_bwh = bwh;
8127 + dinfo->di_bdiropq = -1;
8129 + && bdiropq <= au_sbbot(sb)
8130 + && au_sbr_whable(sb, bdiropq))
8131 + dinfo->di_bdiropq = bdiropq;
8134 + dinfo->di_btop = -1;
8135 + dinfo->di_bbot = -1;
8136 + bbot = au_dbbot(parent);
8138 + p = au_hdentry(dinfo, bindex);
8139 + for (; bindex <= bbot; bindex++, p++)
8140 + if (p->hd_dentry) {
8141 + dinfo->di_btop = bindex;
8145 + if (dinfo->di_btop >= 0) {
8147 + p = au_hdentry(dinfo, bindex);
8148 + for (; bindex >= 0; bindex--, p--)
8149 + if (p->hd_dentry) {
8150 + dinfo->di_bbot = bindex;
8159 +static void au_do_hide(struct dentry *dentry)
8161 + struct inode *inode;
8163 + if (d_really_is_positive(dentry)) {
8164 + inode = d_inode(dentry);
8165 + if (!d_is_dir(dentry)) {
8166 + if (inode->i_nlink && !d_unhashed(dentry))
8167 + drop_nlink(inode);
8169 + clear_nlink(inode);
8170 + /* stop next lookup */
8171 + inode->i_flags |= S_DEAD;
8173 + smp_mb(); /* necessary? */
8178 +static int au_hide_children(struct dentry *parent)
8180 + int err, i, j, ndentry;
8181 + struct au_dcsub_pages dpages;
8182 + struct au_dpage *dpage;
8183 + struct dentry *dentry;
8185 + err = au_dpages_init(&dpages, GFP_NOFS);
8186 + if (unlikely(err))
8188 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8189 + if (unlikely(err))
8192 + /* in reverse order */
8193 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8194 + dpage = dpages.dpages + i;
8195 + ndentry = dpage->ndentry;
8196 + for (j = ndentry - 1; j >= 0; j--) {
8197 + dentry = dpage->dentries[j];
8198 + if (dentry != parent)
8199 + au_do_hide(dentry);
8204 + au_dpages_free(&dpages);
8209 +static void au_hide(struct dentry *dentry)
8213 + AuDbgDentry(dentry);
8214 + if (d_is_dir(dentry)) {
8215 + /* shrink_dcache_parent(dentry); */
8216 + err = au_hide_children(dentry);
8217 + if (unlikely(err))
8218 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8221 + au_do_hide(dentry);
8225 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8227 + * a dirty branch is added
8228 + * - on the top of layers
8229 + * - in the middle of layers
8230 + * - to the bottom of layers
8232 + * on the added branch there exists
8235 + * - a same named entry
8237 + * * negative --> positive
8238 + * * positive --> positive
8239 + * - type is unchanged
8240 + * - type is changed
8242 + * * negative --> negative
8243 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8246 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8247 + struct au_dinfo *tmp)
8250 + aufs_bindex_t bindex, bbot;
8252 + struct dentry *dentry;
8253 + struct inode *inode;
8255 + } orig_h, tmp_h = {
8258 + struct au_hdentry *hd;
8259 + struct inode *inode, *h_inode;
8260 + struct dentry *h_dentry;
8263 + AuDebugOn(dinfo->di_btop < 0);
8265 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8266 + orig_h.inode = NULL;
8267 + if (d_is_positive(orig_h.dentry)) {
8268 + orig_h.inode = d_inode(orig_h.dentry);
8269 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8271 + if (tmp->di_btop >= 0) {
8272 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8273 + if (d_is_positive(tmp_h.dentry)) {
8274 + tmp_h.inode = d_inode(tmp_h.dentry);
8275 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8280 + if (d_really_is_positive(dentry))
8281 + inode = d_inode(dentry);
8282 + if (!orig_h.inode) {
8283 + AuDbg("nagative originally\n");
8289 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8290 + AuDebugOn(dinfo->di_bdiropq != -1);
8292 + if (!tmp_h.inode) {
8293 + AuDbg("negative --> negative\n");
8294 + /* should have only one negative lower */
8295 + if (tmp->di_btop >= 0
8296 + && tmp->di_btop < dinfo->di_btop) {
8297 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8298 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8299 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8300 + au_di_cp(dinfo, tmp);
8301 + hd = au_hdentry(tmp, tmp->di_btop);
8302 + au_set_h_dptr(dentry, tmp->di_btop,
8303 + dget(hd->hd_dentry));
8305 + au_dbg_verify_dinode(dentry);
8307 + AuDbg("negative --> positive\n");
8309 + * similar to the behaviour of creating with bypassing
8311 + * unhash it in order to force an error in the
8312 + * succeeding create operation.
8313 + * we should not set S_DEAD here.
8316 + /* au_di_swap(tmp, dinfo); */
8317 + au_dbg_verify_dinode(dentry);
8320 + AuDbg("positive originally\n");
8321 + /* inode may be NULL */
8322 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8323 + if (!tmp_h.inode) {
8324 + AuDbg("positive --> negative\n");
8325 + /* or bypassing aufs */
8327 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8328 + dinfo->di_bwh = tmp->di_bwh;
8330 + err = au_refresh_hinode_self(inode);
8331 + au_dbg_verify_dinode(dentry);
8332 + } else if (orig_h.mode == tmp_h.mode) {
8333 + AuDbg("positive --> positive, same type\n");
8334 + if (!S_ISDIR(orig_h.mode)
8335 + && dinfo->di_btop > tmp->di_btop) {
8337 + * similar to the behaviour of removing and
8342 + err = au_refresh_hinode_self(inode);
8343 + au_dbg_verify_dinode(dentry);
8345 + /* fill empty slots */
8346 + if (dinfo->di_btop > tmp->di_btop)
8347 + dinfo->di_btop = tmp->di_btop;
8348 + if (dinfo->di_bbot < tmp->di_bbot)
8349 + dinfo->di_bbot = tmp->di_bbot;
8350 + dinfo->di_bwh = tmp->di_bwh;
8351 + dinfo->di_bdiropq = tmp->di_bdiropq;
8352 + bbot = dinfo->di_bbot;
8353 + bindex = tmp->di_btop;
8354 + hd = au_hdentry(tmp, bindex);
8355 + for (; bindex <= bbot; bindex++, hd++) {
8356 + if (au_h_dptr(dentry, bindex))
8358 + h_dentry = hd->hd_dentry;
8361 + AuDebugOn(d_is_negative(h_dentry));
8362 + h_inode = d_inode(h_dentry);
8363 + AuDebugOn(orig_h.mode
8364 + != (h_inode->i_mode
8366 + au_set_h_dptr(dentry, bindex,
8370 + err = au_refresh_hinode(inode, dentry);
8371 + au_dbg_verify_dinode(dentry);
8374 + AuDbg("positive --> positive, different type\n");
8375 + /* similar to the behaviour of removing and creating */
8378 + err = au_refresh_hinode_self(inode);
8379 + au_dbg_verify_dinode(dentry);
8387 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8389 + const struct dentry_operations *dop
8390 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8391 + static const unsigned int mask
8392 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8394 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8396 + if (dentry->d_op == dop)
8399 + AuDbg("%pd\n", dentry);
8400 + spin_lock(&dentry->d_lock);
8401 + if (dop == &aufs_dop)
8402 + dentry->d_flags |= mask;
8404 + dentry->d_flags &= ~mask;
8405 + dentry->d_op = dop;
8406 + spin_unlock(&dentry->d_lock);
8409 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8411 + int err, ebrange, nbr;
8412 + unsigned int sigen;
8413 + struct au_dinfo *dinfo, *tmp;
8414 + struct super_block *sb;
8415 + struct inode *inode;
8417 + DiMustWriteLock(dentry);
8418 + AuDebugOn(IS_ROOT(dentry));
8419 + AuDebugOn(d_really_is_negative(parent));
8421 + sb = dentry->d_sb;
8422 + sigen = au_sigen(sb);
8423 + err = au_digen_test(parent, sigen);
8424 + if (unlikely(err))
8427 + nbr = au_sbbot(sb) + 1;
8428 + dinfo = au_di(dentry);
8429 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8430 + if (unlikely(err))
8432 + ebrange = au_dbrange_test(dentry);
8434 + ebrange = au_do_refresh_hdentry(dentry, parent);
8436 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8437 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8438 + if (d_really_is_positive(dentry)) {
8439 + inode = d_inode(dentry);
8440 + err = au_refresh_hinode_self(inode);
8442 + au_dbg_verify_dinode(dentry);
8444 + goto out_dgen; /* success */
8448 + /* temporary dinfo */
8449 + AuDbgDentry(dentry);
8451 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8452 + if (unlikely(!tmp))
8454 + au_di_swap(tmp, dinfo);
8455 + /* returns the number of positive dentries */
8457 + * if current working dir is removed, it returns an error.
8458 + * but the dentry is legal.
8460 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8461 + AuDbgDentry(dentry);
8462 + au_di_swap(tmp, dinfo);
8463 + if (err == -ENOENT)
8466 + /* compare/refresh by dinfo */
8467 + AuDbgDentry(dentry);
8468 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8469 + au_dbg_verify_dinode(dentry);
8472 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8473 + au_rw_write_unlock(&tmp->di_rwsem);
8475 + if (unlikely(err))
8479 + au_update_digen(dentry);
8481 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8482 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8483 + AuDbgDentry(dentry);
8489 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8490 + struct dentry *dentry, aufs_bindex_t bindex)
8495 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8498 + AuDbg("b%d\n", bindex);
8500 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8501 + * due to whiteout and branch permission.
8503 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8504 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8505 + /* it may return tri-state */
8506 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8508 + if (unlikely(valid < 0))
8518 +/* todo: remove this */
8519 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8520 + unsigned int flags, int do_udba)
8523 + umode_t mode, h_mode;
8524 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8525 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8526 + struct inode *h_inode, *h_cached_inode;
8527 + struct dentry *h_dentry;
8528 + struct qstr *name, *h_name;
8535 + unhashed = !!d_unhashed(dentry);
8536 + is_root = !!IS_ROOT(dentry);
8537 + name = &dentry->d_name;
8538 + tmpfile = au_di(dentry)->di_tmpfile;
8541 + * Theoretically, REVAL test should be unnecessary in case of
8543 + * But {fs,i}notify doesn't fire some necessary events,
8544 + * IN_ATTRIB for atime/nlink/pageio
8545 + * Let's do REVAL test too.
8547 + if (do_udba && inode) {
8548 + mode = (inode->i_mode & S_IFMT);
8549 + plus = (inode->i_nlink > 0);
8550 + ibs = au_ibtop(inode);
8551 + ibe = au_ibbot(inode);
8554 + btop = au_dbtop(dentry);
8556 + if (inode && S_ISDIR(inode->i_mode))
8557 + btail = au_dbtaildir(dentry);
8558 + for (bindex = btop; bindex <= btail; bindex++) {
8559 + h_dentry = au_h_dptr(dentry, bindex);
8563 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8564 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8565 + spin_lock(&h_dentry->d_lock);
8566 + h_name = &h_dentry->d_name;
8567 + if (unlikely(do_udba
8570 + && (unhashed != !!d_unhashed(h_dentry)
8572 + && !au_qstreq(name, h_name))
8575 + && !(flags & LOOKUP_OPEN)
8576 + && (h_dentry->d_flags
8577 + & DCACHE_NFSFS_RENAMED)))
8581 + h_unhashed = d_unhashed(h_dentry);
8582 + spin_unlock(&h_dentry->d_lock);
8583 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8584 + unhashed, h_unhashed, dentry, h_dentry);
8587 + spin_unlock(&h_dentry->d_lock);
8589 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8590 + if (unlikely(err))
8591 + /* do not goto err, to keep the errno */
8594 + /* todo: plink too? */
8599 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8603 + if (d_is_positive(h_dentry))
8604 + h_inode = d_inode(h_dentry);
8607 + h_cached_inode = h_inode;
8609 + h_mode = (h_inode->i_mode & S_IFMT);
8610 + h_plus = (h_inode->i_nlink > 0);
8612 + if (inode && ibs <= bindex && bindex <= ibe)
8613 + h_cached_inode = au_h_iptr(inode, bindex);
8616 + if (unlikely(plus != h_plus && !tmpfile))
8619 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8621 + && !IS_ROOT(h_dentry)
8622 + && unhashed != d_unhashed(h_dentry)))
8625 + if (unlikely(mode != h_mode
8626 + || h_cached_inode != h_inode))
8639 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8640 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8643 + struct dentry *parent;
8645 + if (!au_digen_test(dentry, sigen))
8648 + parent = dget_parent(dentry);
8649 + di_read_lock_parent(parent, AuLock_IR);
8650 + AuDebugOn(au_digen_test(parent, sigen));
8651 + au_dbg_verify_gen(parent, sigen);
8652 + err = au_refresh_dentry(dentry, parent);
8653 + di_read_unlock(parent, AuLock_IR);
8659 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8662 + struct dentry *d, *parent;
8664 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8665 + return simple_reval_dpath(dentry, sigen);
8667 + /* slow loop, keep it simple and stupid */
8668 + /* cf: au_cpup_dirs() */
8671 + while (au_digen_test(dentry, sigen)) {
8675 + parent = dget_parent(d);
8676 + if (!au_digen_test(parent, sigen))
8682 + di_write_lock_child2(d);
8684 + /* someone might update our dentry while we were sleeping */
8685 + if (au_digen_test(d, sigen)) {
8687 + * todo: consolidate with simple_reval_dpath(),
8688 + * do_refresh() and au_reval_for_attr().
8690 + di_read_lock_parent(parent, AuLock_IR);
8691 + err = au_refresh_dentry(d, parent);
8692 + di_read_unlock(parent, AuLock_IR);
8696 + di_write_unlock(d);
8698 + if (unlikely(err))
8706 + * if valid returns 1, otherwise 0.
8708 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8711 + unsigned int sigen;
8712 + unsigned char do_udba;
8713 + struct super_block *sb;
8714 + struct inode *inode;
8716 + /* todo: support rcu-walk? */
8717 + if (flags & LOOKUP_RCU)
8721 + if (unlikely(!au_di(dentry)))
8725 + sb = dentry->d_sb;
8728 + * i_mutex of parent dir may be held,
8729 + * but we should not return 'invalid' due to busy.
8731 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8732 + if (unlikely(err)) {
8738 + if (d_really_is_positive(dentry))
8739 + inode = d_inode(dentry);
8740 + if (unlikely(inode && au_is_bad_inode(inode))) {
8745 + if (unlikely(au_dbrange_test(dentry))) {
8751 + sigen = au_sigen(sb);
8752 + if (au_digen_test(dentry, sigen)) {
8753 + AuDebugOn(IS_ROOT(dentry));
8754 + err = au_reval_dpath(dentry, sigen);
8755 + if (unlikely(err)) {
8760 + di_downgrade_lock(dentry, AuLock_IR);
8763 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8765 + && !(inode->i_state && I_LINKABLE)
8766 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8771 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8772 + if (do_udba && inode) {
8773 + aufs_bindex_t btop = au_ibtop(inode);
8774 + struct inode *h_inode;
8777 + h_inode = au_h_iptr(inode, btop);
8778 + if (h_inode && au_test_higen(inode, h_inode)) {
8785 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8786 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8788 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8794 + di_downgrade_lock(dentry, AuLock_IR);
8796 + aufs_read_unlock(dentry, AuLock_IR);
8801 + AuDbg("%pd invalid, %d\n", dentry, valid);
8807 +static void aufs_d_release(struct dentry *dentry)
8809 + if (au_di(dentry)) {
8810 + au_di_fin(dentry);
8811 + au_hn_di_reinit(dentry);
8815 +const struct dentry_operations aufs_dop = {
8816 + .d_revalidate = aufs_d_revalidate,
8817 + .d_weak_revalidate = aufs_d_revalidate,
8818 + .d_release = aufs_d_release
8821 +/* aufs_dop without d_revalidate */
8822 +const struct dentry_operations aufs_dop_noreval = {
8823 + .d_release = aufs_d_release
8825 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8826 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8827 +++ linux/fs/aufs/dentry.h 2017-03-02 14:24:13.856922210 +0100
8830 + * Copyright (C) 2005-2017 Junjiro R. Okajima
8832 + * This program, aufs is free software; you can redistribute it and/or modify
8833 + * it under the terms of the GNU General Public License as published by
8834 + * the Free Software Foundation; either version 2 of the License, or
8835 + * (at your option) any later version.
8837 + * This program is distributed in the hope that it will be useful,
8838 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8839 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8840 + * GNU General Public License for more details.
8842 + * You should have received a copy of the GNU General Public License
8843 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8847 + * lookup and dentry operations
8850 +#ifndef __AUFS_DENTRY_H__
8851 +#define __AUFS_DENTRY_H__
8855 +#include <linux/dcache.h>
8858 +struct au_hdentry {
8859 + struct dentry *hd_dentry;
8860 + aufs_bindex_t hd_id;
8864 + atomic_t di_generation;
8866 + struct au_rwsem di_rwsem;
8867 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8868 + unsigned char di_tmpfile; /* to allow the different name */
8870 + struct au_hdentry *di_hdentry;
8871 + struct llist_node di_lnode; /* delayed free */
8873 +} ____cacheline_aligned_in_smp;
8875 +/* ---------------------------------------------------------------------- */
8877 +/* flags for au_lkup_dentry() */
8878 +#define AuLkup_ALLOW_NEG 1
8879 +#define AuLkup_IGNORE_PERM (1 << 1)
8880 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8881 +#define au_fset_lkup(flags, name) \
8882 + do { (flags) |= AuLkup_##name; } while (0)
8883 +#define au_fclr_lkup(flags, name) \
8884 + do { (flags) &= ~AuLkup_##name; } while (0)
8886 +/* ---------------------------------------------------------------------- */
8889 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8891 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8892 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8893 + struct dentry *h_parent, struct au_branch *br);
8895 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8896 + unsigned int flags);
8897 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8898 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8899 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8900 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8903 +void au_di_init_once(void *_di);
8904 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8905 +void au_di_free(struct au_dinfo *dinfo);
8906 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8907 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8908 +int au_di_init(struct dentry *dentry);
8909 +void au_di_fin(struct dentry *dentry);
8910 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8912 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8913 +void di_read_unlock(struct dentry *d, int flags);
8914 +void di_downgrade_lock(struct dentry *d, int flags);
8915 +void di_write_lock(struct dentry *d, unsigned int lsc);
8916 +void di_write_unlock(struct dentry *d);
8917 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8918 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8919 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8921 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8922 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8923 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8924 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8926 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8927 + struct dentry *h_dentry);
8928 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8929 +int au_dbrange_test(struct dentry *dentry);
8930 +void au_update_digen(struct dentry *dentry);
8931 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8932 +void au_update_dbtop(struct dentry *dentry);
8933 +void au_update_dbbot(struct dentry *dentry);
8934 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8936 +/* ---------------------------------------------------------------------- */
8938 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8940 + return dentry->d_fsdata;
8943 +/* ---------------------------------------------------------------------- */
8945 +/* lock subclass for dinfo */
8947 + AuLsc_DI_CHILD, /* child first */
8948 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8949 + AuLsc_DI_CHILD3, /* copyup dirs */
8953 + AuLsc_DI_TMP /* temp for replacing dinfo */
8957 + * di_read_lock_child, di_write_lock_child,
8958 + * di_read_lock_child2, di_write_lock_child2,
8959 + * di_read_lock_child3, di_write_lock_child3,
8960 + * di_read_lock_parent, di_write_lock_parent,
8961 + * di_read_lock_parent2, di_write_lock_parent2,
8962 + * di_read_lock_parent3, di_write_lock_parent3,
8964 +#define AuReadLockFunc(name, lsc) \
8965 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8966 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8968 +#define AuWriteLockFunc(name, lsc) \
8969 +static inline void di_write_lock_##name(struct dentry *d) \
8970 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8972 +#define AuRWLockFuncs(name, lsc) \
8973 + AuReadLockFunc(name, lsc) \
8974 + AuWriteLockFunc(name, lsc)
8976 +AuRWLockFuncs(child, CHILD);
8977 +AuRWLockFuncs(child2, CHILD2);
8978 +AuRWLockFuncs(child3, CHILD3);
8979 +AuRWLockFuncs(parent, PARENT);
8980 +AuRWLockFuncs(parent2, PARENT2);
8981 +AuRWLockFuncs(parent3, PARENT3);
8983 +#undef AuReadLockFunc
8984 +#undef AuWriteLockFunc
8985 +#undef AuRWLockFuncs
8987 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8988 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8989 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8991 +/* ---------------------------------------------------------------------- */
8993 +/* todo: memory barrier? */
8994 +static inline unsigned int au_digen(struct dentry *d)
8996 + return atomic_read(&au_di(d)->di_generation);
8999 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9001 + hdentry->hd_dentry = NULL;
9004 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9005 + aufs_bindex_t bindex)
9007 + return di->di_hdentry + bindex;
9010 +static inline void au_hdput(struct au_hdentry *hd)
9013 + dput(hd->hd_dentry);
9016 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9018 + DiMustAnyLock(dentry);
9019 + return au_di(dentry)->di_btop;
9022 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9024 + DiMustAnyLock(dentry);
9025 + return au_di(dentry)->di_bbot;
9028 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9030 + DiMustAnyLock(dentry);
9031 + return au_di(dentry)->di_bwh;
9034 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9036 + DiMustAnyLock(dentry);
9037 + return au_di(dentry)->di_bdiropq;
9040 +/* todo: hard/soft set? */
9041 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9043 + DiMustWriteLock(dentry);
9044 + au_di(dentry)->di_btop = bindex;
9047 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9049 + DiMustWriteLock(dentry);
9050 + au_di(dentry)->di_bbot = bindex;
9053 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9055 + DiMustWriteLock(dentry);
9056 + /* dbwh can be outside of btop - bbot range */
9057 + au_di(dentry)->di_bwh = bindex;
9060 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9062 + DiMustWriteLock(dentry);
9063 + au_di(dentry)->di_bdiropq = bindex;
9066 +/* ---------------------------------------------------------------------- */
9068 +#ifdef CONFIG_AUFS_HNOTIFY
9069 +static inline void au_digen_dec(struct dentry *d)
9071 + atomic_dec(&au_di(d)->di_generation);
9074 +static inline void au_hn_di_reinit(struct dentry *dentry)
9076 + dentry->d_fsdata = NULL;
9079 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9080 +#endif /* CONFIG_AUFS_HNOTIFY */
9082 +#endif /* __KERNEL__ */
9083 +#endif /* __AUFS_DENTRY_H__ */
9084 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9085 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9086 +++ linux/fs/aufs/dinfo.c 2017-03-02 14:24:13.856922210 +0100
9089 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9091 + * This program, aufs is free software; you can redistribute it and/or modify
9092 + * it under the terms of the GNU General Public License as published by
9093 + * the Free Software Foundation; either version 2 of the License, or
9094 + * (at your option) any later version.
9096 + * This program is distributed in the hope that it will be useful,
9097 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9099 + * GNU General Public License for more details.
9101 + * You should have received a copy of the GNU General Public License
9102 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9106 + * dentry private data
9111 +void au_di_init_once(void *_dinfo)
9113 + struct au_dinfo *dinfo = _dinfo;
9115 + au_rw_init(&dinfo->di_rwsem);
9118 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9120 + struct au_dinfo *dinfo;
9123 + dinfo = au_cache_alloc_dinfo();
9124 + if (unlikely(!dinfo))
9127 + nbr = au_sbbot(sb) + 1;
9130 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9131 + if (dinfo->di_hdentry) {
9132 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9133 + dinfo->di_btop = -1;
9134 + dinfo->di_bbot = -1;
9135 + dinfo->di_bwh = -1;
9136 + dinfo->di_bdiropq = -1;
9137 + dinfo->di_tmpfile = 0;
9138 + for (i = 0; i < nbr; i++)
9139 + dinfo->di_hdentry[i].hd_id = -1;
9143 + au_cache_dfree_dinfo(dinfo);
9150 +void au_di_free(struct au_dinfo *dinfo)
9152 + struct au_hdentry *p;
9153 + aufs_bindex_t bbot, bindex;
9155 + /* dentry may not be revalidated */
9156 + bindex = dinfo->di_btop;
9157 + if (bindex >= 0) {
9158 + bbot = dinfo->di_bbot;
9159 + p = au_hdentry(dinfo, bindex);
9160 + while (bindex++ <= bbot)
9163 + au_delayed_kfree(dinfo->di_hdentry);
9164 + au_cache_dfree_dinfo(dinfo);
9167 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9169 + struct au_hdentry *p;
9172 + AuRwMustWriteLock(&a->di_rwsem);
9173 + AuRwMustWriteLock(&b->di_rwsem);
9175 +#define DiSwap(v, name) \
9177 + v = a->di_##name; \
9178 + a->di_##name = b->di_##name; \
9179 + b->di_##name = v; \
9182 + DiSwap(p, hdentry);
9186 + DiSwap(bi, bdiropq);
9192 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9194 + AuRwMustWriteLock(&dst->di_rwsem);
9195 + AuRwMustWriteLock(&src->di_rwsem);
9197 + dst->di_btop = src->di_btop;
9198 + dst->di_bbot = src->di_bbot;
9199 + dst->di_bwh = src->di_bwh;
9200 + dst->di_bdiropq = src->di_bdiropq;
9204 +int au_di_init(struct dentry *dentry)
9207 + struct super_block *sb;
9208 + struct au_dinfo *dinfo;
9211 + sb = dentry->d_sb;
9212 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9214 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9215 + /* smp_mb(); */ /* atomic_set */
9216 + dentry->d_fsdata = dinfo;
9223 +void au_di_fin(struct dentry *dentry)
9225 + struct au_dinfo *dinfo;
9227 + dinfo = au_di(dentry);
9228 + AuRwDestroy(&dinfo->di_rwsem);
9229 + au_di_free(dinfo);
9232 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9235 + struct au_hdentry *hdp;
9237 + AuRwMustWriteLock(&dinfo->di_rwsem);
9240 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9242 + sz = sizeof(*hdp);
9243 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9246 + dinfo->di_hdentry = hdp;
9253 +/* ---------------------------------------------------------------------- */
9255 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9258 + case AuLsc_DI_CHILD:
9259 + ii_write_lock_child(inode);
9261 + case AuLsc_DI_CHILD2:
9262 + ii_write_lock_child2(inode);
9264 + case AuLsc_DI_CHILD3:
9265 + ii_write_lock_child3(inode);
9267 + case AuLsc_DI_PARENT:
9268 + ii_write_lock_parent(inode);
9270 + case AuLsc_DI_PARENT2:
9271 + ii_write_lock_parent2(inode);
9273 + case AuLsc_DI_PARENT3:
9274 + ii_write_lock_parent3(inode);
9281 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9284 + case AuLsc_DI_CHILD:
9285 + ii_read_lock_child(inode);
9287 + case AuLsc_DI_CHILD2:
9288 + ii_read_lock_child2(inode);
9290 + case AuLsc_DI_CHILD3:
9291 + ii_read_lock_child3(inode);
9293 + case AuLsc_DI_PARENT:
9294 + ii_read_lock_parent(inode);
9296 + case AuLsc_DI_PARENT2:
9297 + ii_read_lock_parent2(inode);
9299 + case AuLsc_DI_PARENT3:
9300 + ii_read_lock_parent3(inode);
9307 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9309 + struct inode *inode;
9311 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9312 + if (d_really_is_positive(d)) {
9313 + inode = d_inode(d);
9314 + if (au_ftest_lock(flags, IW))
9315 + do_ii_write_lock(inode, lsc);
9316 + else if (au_ftest_lock(flags, IR))
9317 + do_ii_read_lock(inode, lsc);
9321 +void di_read_unlock(struct dentry *d, int flags)
9323 + struct inode *inode;
9325 + if (d_really_is_positive(d)) {
9326 + inode = d_inode(d);
9327 + if (au_ftest_lock(flags, IW)) {
9328 + au_dbg_verify_dinode(d);
9329 + ii_write_unlock(inode);
9330 + } else if (au_ftest_lock(flags, IR)) {
9331 + au_dbg_verify_dinode(d);
9332 + ii_read_unlock(inode);
9335 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9338 +void di_downgrade_lock(struct dentry *d, int flags)
9340 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9341 + ii_downgrade_lock(d_inode(d));
9342 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9345 +void di_write_lock(struct dentry *d, unsigned int lsc)
9347 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9348 + if (d_really_is_positive(d))
9349 + do_ii_write_lock(d_inode(d), lsc);
9352 +void di_write_unlock(struct dentry *d)
9354 + au_dbg_verify_dinode(d);
9355 + if (d_really_is_positive(d))
9356 + ii_write_unlock(d_inode(d));
9357 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9360 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9362 + AuDebugOn(d1 == d2
9363 + || d_inode(d1) == d_inode(d2)
9364 + || d1->d_sb != d2->d_sb);
9366 + if (isdir && au_test_subdir(d1, d2)) {
9367 + di_write_lock_child(d1);
9368 + di_write_lock_child2(d2);
9370 + /* there should be no races */
9371 + di_write_lock_child(d2);
9372 + di_write_lock_child2(d1);
9376 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9378 + AuDebugOn(d1 == d2
9379 + || d_inode(d1) == d_inode(d2)
9380 + || d1->d_sb != d2->d_sb);
9382 + if (isdir && au_test_subdir(d1, d2)) {
9383 + di_write_lock_parent(d1);
9384 + di_write_lock_parent2(d2);
9386 + /* there should be no races */
9387 + di_write_lock_parent(d2);
9388 + di_write_lock_parent2(d1);
9392 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9394 + di_write_unlock(d1);
9395 + if (d_inode(d1) == d_inode(d2))
9396 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9398 + di_write_unlock(d2);
9401 +/* ---------------------------------------------------------------------- */
9403 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9407 + DiMustAnyLock(dentry);
9409 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9411 + AuDebugOn(bindex < 0);
9412 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9413 + AuDebugOn(d && au_dcount(d) <= 0);
9418 + * extended version of au_h_dptr().
9419 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9422 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9424 + struct dentry *h_dentry;
9425 + struct inode *inode, *h_inode;
9427 + AuDebugOn(d_really_is_negative(dentry));
9430 + if (au_dbtop(dentry) <= bindex
9431 + && bindex <= au_dbbot(dentry))
9432 + h_dentry = au_h_dptr(dentry, bindex);
9433 + if (h_dentry && !au_d_linkable(h_dentry)) {
9435 + goto out; /* success */
9438 + inode = d_inode(dentry);
9439 + AuDebugOn(bindex < au_ibtop(inode));
9440 + AuDebugOn(au_ibbot(inode) < bindex);
9441 + h_inode = au_h_iptr(inode, bindex);
9442 + h_dentry = d_find_alias(h_inode);
9444 + if (!IS_ERR(h_dentry)) {
9445 + if (!au_d_linkable(h_dentry))
9446 + goto out; /* success */
9452 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9453 + h_dentry = au_plink_lkup(inode, bindex);
9454 + AuDebugOn(!h_dentry);
9455 + if (!IS_ERR(h_dentry)) {
9456 + if (!au_d_hashed_positive(h_dentry))
9457 + goto out; /* success */
9464 + AuDbgDentry(h_dentry);
9468 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9470 + aufs_bindex_t bbot, bwh;
9472 + bbot = au_dbbot(dentry);
9474 + bwh = au_dbwh(dentry);
9477 + if (0 < bwh && bwh < bbot)
9483 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9485 + aufs_bindex_t bbot, bopq;
9487 + bbot = au_dbtail(dentry);
9489 + bopq = au_dbdiropq(dentry);
9490 + if (0 <= bopq && bopq < bbot)
9496 +/* ---------------------------------------------------------------------- */
9498 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9499 + struct dentry *h_dentry)
9501 + struct au_dinfo *dinfo;
9502 + struct au_hdentry *hd;
9503 + struct au_branch *br;
9505 + DiMustWriteLock(dentry);
9507 + dinfo = au_di(dentry);
9508 + hd = au_hdentry(dinfo, bindex);
9510 + hd->hd_dentry = h_dentry;
9512 + br = au_sbr(dentry->d_sb, bindex);
9513 + hd->hd_id = br->br_id;
9517 +int au_dbrange_test(struct dentry *dentry)
9520 + aufs_bindex_t btop, bbot;
9523 + btop = au_dbtop(dentry);
9524 + bbot = au_dbbot(dentry);
9526 + AuDebugOn(bbot < 0 && btop > bbot);
9529 + AuDebugOn(bbot >= 0);
9535 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9540 + if (unlikely(au_digen(dentry) != sigen
9541 + || au_iigen_test(d_inode(dentry), sigen)))
9547 +void au_update_digen(struct dentry *dentry)
9549 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9550 + /* smp_mb(); */ /* atomic_set */
9553 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9555 + struct au_dinfo *dinfo;
9556 + struct dentry *h_d;
9557 + struct au_hdentry *hdp;
9558 + aufs_bindex_t bindex, bbot;
9560 + DiMustWriteLock(dentry);
9562 + dinfo = au_di(dentry);
9563 + if (!dinfo || dinfo->di_btop < 0)
9566 + if (do_put_zero) {
9567 + bbot = dinfo->di_bbot;
9568 + bindex = dinfo->di_btop;
9569 + hdp = au_hdentry(dinfo, bindex);
9570 + for (; bindex <= bbot; bindex++, hdp++) {
9571 + h_d = hdp->hd_dentry;
9572 + if (h_d && d_is_negative(h_d))
9573 + au_set_h_dptr(dentry, bindex, NULL);
9577 + dinfo->di_btop = 0;
9578 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9579 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9580 + if (hdp->hd_dentry)
9582 + if (dinfo->di_btop > dinfo->di_bbot) {
9583 + dinfo->di_btop = -1;
9584 + dinfo->di_bbot = -1;
9588 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9589 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9590 + if (hdp->hd_dentry)
9592 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9595 +void au_update_dbtop(struct dentry *dentry)
9597 + aufs_bindex_t bindex, bbot;
9598 + struct dentry *h_dentry;
9600 + bbot = au_dbbot(dentry);
9601 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9602 + h_dentry = au_h_dptr(dentry, bindex);
9605 + if (d_is_positive(h_dentry)) {
9606 + au_set_dbtop(dentry, bindex);
9609 + au_set_h_dptr(dentry, bindex, NULL);
9613 +void au_update_dbbot(struct dentry *dentry)
9615 + aufs_bindex_t bindex, btop;
9616 + struct dentry *h_dentry;
9618 + btop = au_dbtop(dentry);
9619 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9620 + h_dentry = au_h_dptr(dentry, bindex);
9623 + if (d_is_positive(h_dentry)) {
9624 + au_set_dbbot(dentry, bindex);
9627 + au_set_h_dptr(dentry, bindex, NULL);
9631 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9633 + aufs_bindex_t bindex, bbot;
9635 + bbot = au_dbbot(dentry);
9636 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9637 + if (au_h_dptr(dentry, bindex) == h_dentry)
9641 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9642 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9643 +++ linux/fs/aufs/dir.c 2017-03-02 14:24:13.856922210 +0100
9646 + * Copyright (C) 2005-2017 Junjiro R. Okajima
9648 + * This program, aufs is free software; you can redistribute it and/or modify
9649 + * it under the terms of the GNU General Public License as published by
9650 + * the Free Software Foundation; either version 2 of the License, or
9651 + * (at your option) any later version.
9653 + * This program is distributed in the hope that it will be useful,
9654 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9656 + * GNU General Public License for more details.
9658 + * You should have received a copy of the GNU General Public License
9659 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9663 + * directory operations
9666 +#include <linux/fs_stack.h>
9669 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9671 + unsigned int nlink;
9673 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9675 + nlink = dir->i_nlink;
9676 + nlink += h_dir->i_nlink - 2;
9677 + if (h_dir->i_nlink < 2)
9679 + smp_mb(); /* for i_nlink */
9680 + /* 0 can happen in revaliding */
9681 + set_nlink(dir, nlink);
9684 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9686 + unsigned int nlink;
9688 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9690 + nlink = dir->i_nlink;
9691 + nlink -= h_dir->i_nlink - 2;
9692 + if (h_dir->i_nlink < 2)
9694 + smp_mb(); /* for i_nlink */
9695 + /* nlink == 0 means the branch-fs is broken */
9696 + set_nlink(dir, nlink);
9699 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9702 + aufs_bindex_t bindex, bbot;
9703 + struct file *h_file;
9704 + struct dentry *h_dentry;
9708 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9710 + bbot = au_fbbot_dir(file);
9711 + for (bindex = au_fbtop(file);
9712 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9714 + h_file = au_hf_dir(file, bindex);
9715 + if (h_file && file_inode(h_file))
9716 + sz += vfsub_f_size_read(h_file);
9719 + AuDebugOn(!dentry);
9720 + AuDebugOn(!d_is_dir(dentry));
9722 + bbot = au_dbtaildir(dentry);
9723 + for (bindex = au_dbtop(dentry);
9724 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9726 + h_dentry = au_h_dptr(dentry, bindex);
9727 + if (h_dentry && d_is_positive(h_dentry))
9728 + sz += i_size_read(d_inode(h_dentry));
9731 + if (sz < KMALLOC_MAX_SIZE)
9732 + sz = roundup_pow_of_two(sz);
9733 + if (sz > KMALLOC_MAX_SIZE)
9734 + sz = KMALLOC_MAX_SIZE;
9735 + else if (sz < NAME_MAX) {
9736 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9737 + sz = AUFS_RDBLK_DEF;
9742 +struct au_dir_ts_arg {
9743 + struct dentry *dentry;
9744 + aufs_bindex_t brid;
9747 +static void au_do_dir_ts(void *arg)
9749 + struct au_dir_ts_arg *a = arg;
9750 + struct au_dtime dt;
9751 + struct path h_path;
9752 + struct inode *dir, *h_dir;
9753 + struct super_block *sb;
9754 + struct au_branch *br;
9755 + struct au_hinode *hdir;
9757 + aufs_bindex_t btop, bindex;
9759 + sb = a->dentry->d_sb;
9760 + if (d_really_is_negative(a->dentry))
9762 + /* no dir->i_mutex lock */
9763 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9765 + dir = d_inode(a->dentry);
9766 + btop = au_ibtop(dir);
9767 + bindex = au_br_index(sb, a->brid);
9768 + if (bindex < btop)
9771 + br = au_sbr(sb, bindex);
9772 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9773 + if (!h_path.dentry)
9775 + h_path.mnt = au_br_mnt(br);
9776 + au_dtime_store(&dt, a->dentry, &h_path);
9778 + br = au_sbr(sb, btop);
9779 + if (!au_br_writable(br->br_perm))
9781 + h_path.dentry = au_h_dptr(a->dentry, btop);
9782 + h_path.mnt = au_br_mnt(br);
9783 + err = vfsub_mnt_want_write(h_path.mnt);
9786 + hdir = au_hi(dir, btop);
9787 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9788 + h_dir = au_h_iptr(dir, btop);
9789 + if (h_dir->i_nlink
9790 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9791 + dt.dt_h_path = h_path;
9792 + au_dtime_revert(&dt);
9794 + au_hn_inode_unlock(hdir);
9795 + vfsub_mnt_drop_write(h_path.mnt);
9796 + au_cpup_attr_timesizes(dir);
9799 + aufs_read_unlock(a->dentry, AuLock_DW);
9802 + au_nwt_done(&au_sbi(sb)->si_nowait);
9803 + au_delayed_kfree(arg);
9806 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9808 + int perm, wkq_err;
9809 + aufs_bindex_t btop;
9810 + struct au_dir_ts_arg *arg;
9811 + struct dentry *dentry;
9812 + struct super_block *sb;
9816 + dentry = d_find_any_alias(dir);
9817 + AuDebugOn(!dentry);
9818 + sb = dentry->d_sb;
9819 + btop = au_ibtop(dir);
9820 + if (btop == bindex) {
9821 + au_cpup_attr_timesizes(dir);
9825 + perm = au_sbr_perm(sb, btop);
9826 + if (!au_br_writable(perm))
9829 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9833 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9834 + arg->brid = au_sbr_id(sb, bindex);
9835 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9836 + if (unlikely(wkq_err)) {
9837 + pr_err("wkq %d\n", wkq_err);
9839 + au_delayed_kfree(arg);
9846 +/* ---------------------------------------------------------------------- */
9848 +static int reopen_dir(struct file *file)
9851 + unsigned int flags;
9852 + aufs_bindex_t bindex, btail, btop;
9853 + struct dentry *dentry, *h_dentry;
9854 + struct file *h_file;
9856 + /* open all lower dirs */
9857 + dentry = file->f_path.dentry;
9858 + btop = au_dbtop(dentry);
9859 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9860 + au_set_h_fptr(file, bindex, NULL);
9861 + au_set_fbtop(file, btop);
9863 + btail = au_dbtaildir(dentry);
9864 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9865 + au_set_h_fptr(file, bindex, NULL);
9866 + au_set_fbbot_dir(file, btail);
9868 + flags = vfsub_file_flags(file);
9869 + for (bindex = btop; bindex <= btail; bindex++) {
9870 + h_dentry = au_h_dptr(dentry, bindex);
9873 + h_file = au_hf_dir(file, bindex);
9877 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9878 + err = PTR_ERR(h_file);
9879 + if (IS_ERR(h_file))
9880 + goto out; /* close all? */
9881 + au_set_h_fptr(file, bindex, h_file);
9883 + au_update_figen(file);
9884 + /* todo: necessary? */
9885 + /* file->f_ra = h_file->f_ra; */
9892 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9895 + aufs_bindex_t bindex, btail;
9896 + struct dentry *dentry, *h_dentry;
9897 + struct vfsmount *mnt;
9899 + FiMustWriteLock(file);
9900 + AuDebugOn(h_file);
9903 + mnt = file->f_path.mnt;
9904 + dentry = file->f_path.dentry;
9905 + file->f_version = d_inode(dentry)->i_version;
9906 + bindex = au_dbtop(dentry);
9907 + au_set_fbtop(file, bindex);
9908 + btail = au_dbtaildir(dentry);
9909 + au_set_fbbot_dir(file, btail);
9910 + for (; !err && bindex <= btail; bindex++) {
9911 + h_dentry = au_h_dptr(dentry, bindex);
9915 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9916 + if (unlikely(err))
9918 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9919 + if (IS_ERR(h_file)) {
9920 + err = PTR_ERR(h_file);
9923 + au_set_h_fptr(file, bindex, h_file);
9925 + au_update_figen(file);
9926 + /* todo: necessary? */
9927 + /* file->f_ra = h_file->f_ra; */
9929 + return 0; /* success */
9932 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9933 + au_set_h_fptr(file, bindex, NULL);
9934 + au_set_fbtop(file, -1);
9935 + au_set_fbbot_dir(file, -1);
9940 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9941 + struct file *file)
9944 + struct super_block *sb;
9945 + struct au_fidir *fidir;
9948 + sb = file->f_path.dentry->d_sb;
9949 + si_read_lock(sb, AuLock_FLUSH);
9950 + fidir = au_fidir_alloc(sb);
9952 + struct au_do_open_args args = {
9953 + .open = do_open_dir,
9956 + err = au_do_open(file, &args);
9957 + if (unlikely(err))
9958 + au_delayed_kfree(fidir);
9960 + si_read_unlock(sb);
9964 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9965 + struct file *file)
9967 + struct au_vdir *vdir_cache;
9968 + struct au_finfo *finfo;
9969 + struct au_fidir *fidir;
9970 + struct au_hfile *hf;
9971 + aufs_bindex_t bindex, bbot;
9972 + int execed, delayed;
9974 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
9975 + finfo = au_fi(file);
9976 + fidir = finfo->fi_hdir;
9978 + au_sphl_del(&finfo->fi_hlist,
9979 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9980 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9982 + au_vdir_free(vdir_cache, delayed);
9984 + bindex = finfo->fi_btop;
9985 + if (bindex >= 0) {
9986 + execed = vfsub_file_execed(file);
9987 + hf = fidir->fd_hfile + bindex;
9989 + * calls fput() instead of filp_close(),
9990 + * since no dnotify or lock for the lower file.
9992 + bbot = fidir->fd_bbot;
9993 + for (; bindex <= bbot; bindex++, hf++)
9995 + au_hfput(hf, execed);
9997 + au_delayed_kfree(fidir);
9998 + finfo->fi_hdir = NULL;
10000 + au_finfo_fin(file, delayed);
10004 +/* ---------------------------------------------------------------------- */
10006 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10009 + aufs_bindex_t bindex, bbot;
10010 + struct file *h_file;
10013 + bbot = au_fbbot_dir(file);
10014 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10015 + h_file = au_hf_dir(file, bindex);
10017 + err = vfsub_flush(h_file, id);
10022 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10024 + return au_do_flush(file, id, au_do_flush_dir);
10027 +/* ---------------------------------------------------------------------- */
10029 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10032 + aufs_bindex_t bbot, bindex;
10033 + struct inode *inode;
10034 + struct super_block *sb;
10037 + sb = dentry->d_sb;
10038 + inode = d_inode(dentry);
10039 + IMustLock(inode);
10040 + bbot = au_dbbot(dentry);
10041 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10042 + struct path h_path;
10044 + if (au_test_ro(sb, bindex, inode))
10046 + h_path.dentry = au_h_dptr(dentry, bindex);
10047 + if (!h_path.dentry)
10050 + h_path.mnt = au_sbr_mnt(sb, bindex);
10051 + err = vfsub_fsync(NULL, &h_path, datasync);
10057 +static int au_do_fsync_dir(struct file *file, int datasync)
10060 + aufs_bindex_t bbot, bindex;
10061 + struct file *h_file;
10062 + struct super_block *sb;
10063 + struct inode *inode;
10065 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10066 + if (unlikely(err))
10069 + inode = file_inode(file);
10070 + sb = inode->i_sb;
10071 + bbot = au_fbbot_dir(file);
10072 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10073 + h_file = au_hf_dir(file, bindex);
10074 + if (!h_file || au_test_ro(sb, bindex, inode))
10077 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10085 + * @file may be NULL
10087 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10091 + struct dentry *dentry;
10092 + struct inode *inode;
10093 + struct super_block *sb;
10096 + dentry = file->f_path.dentry;
10097 + inode = d_inode(dentry);
10098 + inode_lock(inode);
10099 + sb = dentry->d_sb;
10100 + si_noflush_read_lock(sb);
10102 + err = au_do_fsync_dir(file, datasync);
10104 + di_write_lock_child(dentry);
10105 + err = au_do_fsync_dir_no_file(dentry, datasync);
10107 + au_cpup_attr_timesizes(inode);
10108 + di_write_unlock(dentry);
10110 + fi_write_unlock(file);
10112 + si_read_unlock(sb);
10113 + inode_unlock(inode);
10117 +/* ---------------------------------------------------------------------- */
10119 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10122 + struct dentry *dentry;
10123 + struct inode *inode, *h_inode;
10124 + struct super_block *sb;
10126 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10128 + dentry = file->f_path.dentry;
10129 + inode = d_inode(dentry);
10130 + IMustLock(inode);
10132 + sb = dentry->d_sb;
10133 + si_read_lock(sb, AuLock_FLUSH);
10134 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10135 + if (unlikely(err))
10137 + err = au_alive_dir(dentry);
10139 + err = au_vdir_init(file);
10140 + di_downgrade_lock(dentry, AuLock_IR);
10141 + if (unlikely(err))
10144 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10145 + if (!au_test_nfsd()) {
10146 + err = au_vdir_fill_de(file, ctx);
10147 + fsstack_copy_attr_atime(inode, h_inode);
10150 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10151 + * encode_fh() and others.
10153 + atomic_inc(&h_inode->i_count);
10154 + di_read_unlock(dentry, AuLock_IR);
10155 + si_read_unlock(sb);
10156 + err = au_vdir_fill_de(file, ctx);
10157 + fsstack_copy_attr_atime(inode, h_inode);
10158 + fi_write_unlock(file);
10166 + di_read_unlock(dentry, AuLock_IR);
10167 + fi_write_unlock(file);
10169 + si_read_unlock(sb);
10173 +/* ---------------------------------------------------------------------- */
10175 +#define AuTestEmpty_WHONLY 1
10176 +#define AuTestEmpty_CALLED (1 << 1)
10177 +#define AuTestEmpty_SHWH (1 << 2)
10178 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10179 +#define au_fset_testempty(flags, name) \
10180 + do { (flags) |= AuTestEmpty_##name; } while (0)
10181 +#define au_fclr_testempty(flags, name) \
10182 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10184 +#ifndef CONFIG_AUFS_SHWH
10185 +#undef AuTestEmpty_SHWH
10186 +#define AuTestEmpty_SHWH 0
10189 +struct test_empty_arg {
10190 + struct dir_context ctx;
10191 + struct au_nhash *whlist;
10192 + unsigned int flags;
10194 + aufs_bindex_t bindex;
10197 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10198 + int namelen, loff_t offset __maybe_unused, u64 ino,
10199 + unsigned int d_type)
10201 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10203 + char *name = (void *)__name;
10206 + au_fset_testempty(arg->flags, CALLED);
10208 + if (name[0] == '.'
10209 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10210 + goto out; /* success */
10212 + if (namelen <= AUFS_WH_PFX_LEN
10213 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10214 + if (au_ftest_testempty(arg->flags, WHONLY)
10215 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10216 + arg->err = -ENOTEMPTY;
10220 + name += AUFS_WH_PFX_LEN;
10221 + namelen -= AUFS_WH_PFX_LEN;
10222 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10223 + arg->err = au_nhash_append_wh
10224 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10225 + au_ftest_testempty(arg->flags, SHWH));
10229 + AuTraceErr(arg->err);
10233 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10236 + struct file *h_file;
10238 + h_file = au_h_open(dentry, arg->bindex,
10239 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10240 + /*file*/NULL, /*force_wr*/0);
10241 + err = PTR_ERR(h_file);
10242 + if (IS_ERR(h_file))
10246 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10247 + && !file_inode(h_file)->i_nlink)
10252 + au_fclr_testempty(arg->flags, CALLED);
10254 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10257 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10261 + au_sbr_put(dentry->d_sb, arg->bindex);
10266 +struct do_test_empty_args {
10268 + struct dentry *dentry;
10269 + struct test_empty_arg *arg;
10272 +static void call_do_test_empty(void *args)
10274 + struct do_test_empty_args *a = args;
10275 + *a->errp = do_test_empty(a->dentry, a->arg);
10278 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10280 + int err, wkq_err;
10281 + struct dentry *h_dentry;
10282 + struct inode *h_inode;
10284 + h_dentry = au_h_dptr(dentry, arg->bindex);
10285 + h_inode = d_inode(h_dentry);
10286 + /* todo: i_mode changes anytime? */
10287 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10288 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10289 + inode_unlock(h_inode);
10291 + err = do_test_empty(dentry, arg);
10293 + struct do_test_empty_args args = {
10295 + .dentry = dentry,
10298 + unsigned int flags = arg->flags;
10300 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10301 + if (unlikely(wkq_err))
10303 + arg->flags = flags;
10309 +int au_test_empty_lower(struct dentry *dentry)
10312 + unsigned int rdhash;
10313 + aufs_bindex_t bindex, btop, btail;
10314 + struct au_nhash whlist;
10315 + struct test_empty_arg arg = {
10317 + .actor = test_empty_cb
10320 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10322 + SiMustAnyLock(dentry->d_sb);
10324 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10326 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10327 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10328 + if (unlikely(err))
10332 + arg.whlist = &whlist;
10333 + btop = au_dbtop(dentry);
10334 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10335 + au_fset_testempty(arg.flags, SHWH);
10336 + test_empty = do_test_empty;
10337 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10338 + test_empty = sio_test_empty;
10339 + arg.bindex = btop;
10340 + err = test_empty(dentry, &arg);
10341 + if (unlikely(err))
10344 + au_fset_testempty(arg.flags, WHONLY);
10345 + btail = au_dbtaildir(dentry);
10346 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10347 + struct dentry *h_dentry;
10349 + h_dentry = au_h_dptr(dentry, bindex);
10350 + if (h_dentry && d_is_positive(h_dentry)) {
10351 + arg.bindex = bindex;
10352 + err = test_empty(dentry, &arg);
10357 + au_nhash_wh_free(&whlist);
10362 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10365 + struct test_empty_arg arg = {
10367 + .actor = test_empty_cb
10370 + aufs_bindex_t bindex, btail;
10373 + arg.whlist = whlist;
10374 + arg.flags = AuTestEmpty_WHONLY;
10375 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10376 + au_fset_testempty(arg.flags, SHWH);
10377 + btail = au_dbtaildir(dentry);
10378 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10379 + struct dentry *h_dentry;
10381 + h_dentry = au_h_dptr(dentry, bindex);
10382 + if (h_dentry && d_is_positive(h_dentry)) {
10383 + arg.bindex = bindex;
10384 + err = sio_test_empty(dentry, &arg);
10391 +/* ---------------------------------------------------------------------- */
10393 +const struct file_operations aufs_dir_fop = {
10394 + .owner = THIS_MODULE,
10395 + .llseek = default_llseek,
10396 + .read = generic_read_dir,
10397 + .iterate_shared = aufs_iterate_shared,
10398 + .unlocked_ioctl = aufs_ioctl_dir,
10399 +#ifdef CONFIG_COMPAT
10400 + .compat_ioctl = aufs_compat_ioctl_dir,
10402 + .open = aufs_open_dir,
10403 + .release = aufs_release_dir,
10404 + .flush = aufs_flush_dir,
10405 + .fsync = aufs_fsync_dir
10407 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10408 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10409 +++ linux/fs/aufs/dir.h 2017-03-02 14:24:13.856922210 +0100
10412 + * Copyright (C) 2005-2017 Junjiro R. Okajima
10414 + * This program, aufs is free software; you can redistribute it and/or modify
10415 + * it under the terms of the GNU General Public License as published by
10416 + * the Free Software Foundation; either version 2 of the License, or
10417 + * (at your option) any later version.
10419 + * This program is distributed in the hope that it will be useful,
10420 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10421 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10422 + * GNU General Public License for more details.
10424 + * You should have received a copy of the GNU General Public License
10425 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10429 + * directory operations
10432 +#ifndef __AUFS_DIR_H__
10433 +#define __AUFS_DIR_H__
10437 +#include <linux/fs.h>
10439 +/* ---------------------------------------------------------------------- */
10441 +/* need to be faster and smaller */
10444 + unsigned int nh_num;
10445 + struct hlist_head *nh_head;
10448 +struct au_vdir_destr {
10449 + unsigned char len;
10450 + unsigned char name[0];
10453 +struct au_vdir_dehstr {
10454 + struct hlist_node hash;
10456 + struct au_vdir_destr *str;
10457 + struct llist_node lnode; /* delayed free */
10459 +} ____cacheline_aligned_in_smp;
10461 +struct au_vdir_de {
10463 + unsigned char de_type;
10464 + /* caution: packed */
10465 + struct au_vdir_destr de_str;
10468 +struct au_vdir_wh {
10469 + struct hlist_node wh_hash;
10470 +#ifdef CONFIG_AUFS_SHWH
10472 + aufs_bindex_t wh_bindex;
10473 + unsigned char wh_type;
10475 + aufs_bindex_t wh_bindex;
10477 + /* caution: packed */
10478 + struct au_vdir_destr wh_str;
10481 +union au_vdir_deblk_p {
10482 + unsigned char *deblk;
10483 + struct au_vdir_de *de;
10487 + unsigned char **vd_deblk;
10488 + unsigned long vd_nblk;
10490 + unsigned long ul;
10491 + union au_vdir_deblk_p p;
10494 + unsigned long vd_version;
10495 + unsigned int vd_deblk_sz;
10497 + unsigned long vd_jiffy;
10498 + struct llist_node vd_lnode; /* delayed free */
10500 +} ____cacheline_aligned_in_smp;
10502 +/* ---------------------------------------------------------------------- */
10505 +extern const struct file_operations aufs_dir_fop;
10506 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10507 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10508 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10509 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10510 +int au_test_empty_lower(struct dentry *dentry);
10511 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10514 +unsigned int au_rdhash_est(loff_t sz);
10515 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10516 +void au_nhash_wh_free(struct au_nhash *whlist);
10517 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10519 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10520 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10521 + unsigned int d_type, aufs_bindex_t bindex,
10522 + unsigned char shwh);
10523 +void au_vdir_free(struct au_vdir *vdir, int atonce);
10524 +int au_vdir_init(struct file *file);
10525 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10528 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10530 +#ifdef CONFIG_AUFS_RDU
10532 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10533 +#ifdef CONFIG_COMPAT
10534 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10535 + unsigned long arg);
10538 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10539 + unsigned int cmd, unsigned long arg)
10540 +#ifdef CONFIG_COMPAT
10541 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10542 + unsigned int cmd, unsigned long arg)
10546 +#endif /* __KERNEL__ */
10547 +#endif /* __AUFS_DIR_H__ */
10548 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10549 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10550 +++ linux/fs/aufs/dynop.c 2017-03-02 14:24:13.860255635 +0100
10553 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10555 + * This program, aufs is free software; you can redistribute it and/or modify
10556 + * it under the terms of the GNU General Public License as published by
10557 + * the Free Software Foundation; either version 2 of the License, or
10558 + * (at your option) any later version.
10560 + * This program is distributed in the hope that it will be useful,
10561 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10562 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10563 + * GNU General Public License for more details.
10565 + * You should have received a copy of the GNU General Public License
10566 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10570 + * dynamically customizable operations for regular files
10575 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10578 + * How large will these lists be?
10579 + * Usually just a few elements, 20-30 at most for each, I guess.
10581 +static struct au_sphlhead dynop[AuDyLast];
10583 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10585 + struct au_dykey *key, *tmp;
10586 + struct hlist_head *head;
10589 + head = &sphl->head;
10591 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10592 + if (tmp->dk_op.dy_hop == h_op) {
10594 + kref_get(&key->dk_kref);
10597 + rcu_read_unlock();
10602 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10604 + struct au_dykey **k, *found;
10605 + const void *h_op = key->dk_op.dy_hop;
10609 + k = br->br_dykey;
10610 + for (i = 0; i < AuBrDynOp; i++)
10612 + if (k[i]->dk_op.dy_hop == h_op) {
10619 + spin_lock(&br->br_dykey_lock);
10620 + for (; i < AuBrDynOp; i++)
10622 + if (k[i]->dk_op.dy_hop == h_op) {
10630 + spin_unlock(&br->br_dykey_lock);
10631 + BUG_ON(i == AuBrDynOp); /* expand the array */
10637 +/* kref_get() if @key is already added */
10638 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10640 + struct au_dykey *tmp, *found;
10641 + struct hlist_head *head;
10642 + const void *h_op = key->dk_op.dy_hop;
10645 + head = &sphl->head;
10646 + spin_lock(&sphl->spin);
10647 + hlist_for_each_entry(tmp, head, dk_hnode)
10648 + if (tmp->dk_op.dy_hop == h_op) {
10649 + kref_get(&tmp->dk_kref);
10654 + hlist_add_head_rcu(&key->dk_hnode, head);
10655 + spin_unlock(&sphl->spin);
10662 +static void dy_free_rcu(struct rcu_head *rcu)
10664 + struct au_dykey *key;
10666 + key = container_of(rcu, struct au_dykey, dk_rcu);
10668 + kfree(key); /* not delayed */
10671 +static void dy_free(struct kref *kref)
10673 + struct au_dykey *key;
10674 + struct au_sphlhead *sphl;
10676 + key = container_of(kref, struct au_dykey, dk_kref);
10677 + sphl = dynop + key->dk_op.dy_type;
10678 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10679 + call_rcu(&key->dk_rcu, dy_free_rcu);
10682 +void au_dy_put(struct au_dykey *key)
10684 + kref_put(&key->dk_kref, dy_free);
10687 +/* ---------------------------------------------------------------------- */
10689 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10691 +#ifdef CONFIG_AUFS_DEBUG
10692 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10693 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10695 +#define DyDbgDeclare(cnt) do {} while (0)
10696 +#define DyDbgInc(cnt) do {} while (0)
10699 +#define DySet(func, dst, src, h_op, h_sb) do { \
10701 + if (h_op->func) { \
10703 + dst.func = src.func; \
10705 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10709 +#define DySetForce(func, dst, src) do { \
10710 + AuDebugOn(!src.func); \
10712 + dst.func = src.func; \
10715 +#define DySetAop(func) \
10716 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10717 +#define DySetAopForce(func) \
10718 + DySetForce(func, dyaop->da_op, aufs_aop)
10720 +static void dy_aop(struct au_dykey *key, const void *h_op,
10721 + struct super_block *h_sb __maybe_unused)
10723 + struct au_dyaop *dyaop = (void *)key;
10724 + const struct address_space_operations *h_aop = h_op;
10725 + DyDbgDeclare(cnt);
10727 + AuDbg("%s\n", au_sbtype(h_sb));
10729 + DySetAop(writepage);
10730 + DySetAopForce(readpage); /* force */
10731 + DySetAop(writepages);
10732 + DySetAop(set_page_dirty);
10733 + DySetAop(readpages);
10734 + DySetAop(write_begin);
10735 + DySetAop(write_end);
10737 + DySetAop(invalidatepage);
10738 + DySetAop(releasepage);
10739 + DySetAop(freepage);
10740 + /* this one will be changed according to an aufs mount option */
10741 + DySetAop(direct_IO);
10742 + DySetAop(migratepage);
10743 + DySetAop(isolate_page);
10744 + DySetAop(putback_page);
10745 + DySetAop(launder_page);
10746 + DySetAop(is_partially_uptodate);
10747 + DySetAop(is_dirty_writeback);
10748 + DySetAop(error_remove_page);
10749 + DySetAop(swap_activate);
10750 + DySetAop(swap_deactivate);
10752 + DyDbgSize(cnt, *h_aop);
10755 +/* ---------------------------------------------------------------------- */
10757 +static void dy_bug(struct kref *kref)
10762 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10764 + struct au_dykey *key, *old;
10765 + struct au_sphlhead *sphl;
10768 + void (*set)(struct au_dykey *key, const void *h_op,
10769 + struct super_block *h_sb __maybe_unused);
10771 + static const struct op a[] = {
10773 + .sz = sizeof(struct au_dyaop),
10777 + const struct op *p;
10779 + sphl = dynop + op->dy_type;
10780 + key = dy_gfind_get(sphl, op->dy_hop);
10782 + goto out_add; /* success */
10784 + p = a + op->dy_type;
10785 + key = kzalloc(p->sz, GFP_NOFS);
10786 + if (unlikely(!key)) {
10787 + key = ERR_PTR(-ENOMEM);
10791 + key->dk_op.dy_hop = op->dy_hop;
10792 + kref_init(&key->dk_kref);
10793 + p->set(key, op->dy_hop, au_br_sb(br));
10794 + old = dy_gadd(sphl, key);
10796 + au_delayed_kfree(key);
10801 + old = dy_bradd(br, key);
10803 + /* its ref-count should never be zero here */
10804 + kref_put(&key->dk_kref, dy_bug);
10809 +/* ---------------------------------------------------------------------- */
10811 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10812 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10813 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10814 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10815 + * See the aufs manual in detail.
10817 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10820 + dyaop->da_op.direct_IO = NULL;
10822 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10825 +static struct au_dyaop *dy_aget(struct au_branch *br,
10826 + const struct address_space_operations *h_aop,
10829 + struct au_dyaop *dyaop;
10830 + struct au_dynop op;
10832 + op.dy_type = AuDy_AOP;
10833 + op.dy_haop = h_aop;
10834 + dyaop = (void *)dy_get(&op, br);
10835 + if (IS_ERR(dyaop))
10837 + dy_adx(dyaop, do_dx);
10843 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10844 + struct inode *h_inode)
10847 + struct super_block *sb;
10848 + struct au_branch *br;
10849 + struct au_dyaop *dyaop;
10851 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10852 + IiMustWriteLock(inode);
10854 + sb = inode->i_sb;
10855 + br = au_sbr(sb, bindex);
10856 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10857 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10858 + err = PTR_ERR(dyaop);
10859 + if (IS_ERR(dyaop))
10860 + /* unnecessary to call dy_fput() */
10864 + inode->i_mapping->a_ops = &dyaop->da_op;
10871 + * Is it safe to replace a_ops during the inode/file is in operation?
10872 + * Yes, I hope so.
10874 +int au_dy_irefresh(struct inode *inode)
10877 + aufs_bindex_t btop;
10878 + struct inode *h_inode;
10881 + if (S_ISREG(inode->i_mode)) {
10882 + btop = au_ibtop(inode);
10883 + h_inode = au_h_iptr(inode, btop);
10884 + err = au_dy_iaop(inode, btop, h_inode);
10889 +void au_dy_arefresh(int do_dx)
10891 + struct au_sphlhead *sphl;
10892 + struct hlist_head *head;
10893 + struct au_dykey *key;
10895 + sphl = dynop + AuDy_AOP;
10896 + head = &sphl->head;
10897 + spin_lock(&sphl->spin);
10898 + hlist_for_each_entry(key, head, dk_hnode)
10899 + dy_adx((void *)key, do_dx);
10900 + spin_unlock(&sphl->spin);
10903 +/* ---------------------------------------------------------------------- */
10905 +void __init au_dy_init(void)
10909 + /* make sure that 'struct au_dykey *' can be any type */
10910 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10912 + for (i = 0; i < AuDyLast; i++)
10913 + au_sphl_init(dynop + i);
10916 +void au_dy_fin(void)
10920 + for (i = 0; i < AuDyLast; i++)
10921 + WARN_ON(!hlist_empty(&dynop[i].head));
10923 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10924 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10925 +++ linux/fs/aufs/dynop.h 2017-03-02 14:24:13.860255635 +0100
10928 + * Copyright (C) 2010-2017 Junjiro R. Okajima
10930 + * This program, aufs is free software; you can redistribute it and/or modify
10931 + * it under the terms of the GNU General Public License as published by
10932 + * the Free Software Foundation; either version 2 of the License, or
10933 + * (at your option) any later version.
10935 + * This program is distributed in the hope that it will be useful,
10936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10938 + * GNU General Public License for more details.
10940 + * You should have received a copy of the GNU General Public License
10941 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10945 + * dynamically customizable operations (for regular files only)
10948 +#ifndef __AUFS_DYNOP_H__
10949 +#define __AUFS_DYNOP_H__
10953 +#include <linux/fs.h>
10954 +#include <linux/kref.h>
10956 +enum {AuDy_AOP, AuDyLast};
10961 + const void *dy_hop;
10962 + const struct address_space_operations *dy_haop;
10968 + struct hlist_node dk_hnode;
10969 + struct rcu_head dk_rcu;
10971 + struct au_dynop dk_op;
10974 + * during I am in the branch local array, kref is gotten. when the
10975 + * branch is removed, kref is put.
10977 + struct kref dk_kref;
10980 +/* stop unioning since their sizes are very different from each other */
10982 + struct au_dykey da_key;
10983 + struct address_space_operations da_op; /* not const */
10986 +/* ---------------------------------------------------------------------- */
10990 +void au_dy_put(struct au_dykey *key);
10991 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10992 + struct inode *h_inode);
10993 +int au_dy_irefresh(struct inode *inode);
10994 +void au_dy_arefresh(int do_dio);
10996 +void __init au_dy_init(void);
10997 +void au_dy_fin(void);
10999 +#endif /* __KERNEL__ */
11000 +#endif /* __AUFS_DYNOP_H__ */
11001 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
11002 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
11003 +++ linux/fs/aufs/export.c 2017-03-02 14:24:13.860255635 +0100
11006 + * Copyright (C) 2005-2017 Junjiro R. Okajima
11008 + * This program, aufs is free software; you can redistribute it and/or modify
11009 + * it under the terms of the GNU General Public License as published by
11010 + * the Free Software Foundation; either version 2 of the License, or
11011 + * (at your option) any later version.
11013 + * This program is distributed in the hope that it will be useful,
11014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11016 + * GNU General Public License for more details.
11018 + * You should have received a copy of the GNU General Public License
11019 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11026 +#include <linux/exportfs.h>
11027 +#include <linux/fs_struct.h>
11028 +#include <linux/namei.h>
11029 +#include <linux/nsproxy.h>
11030 +#include <linux/random.h>
11031 +#include <linux/writeback.h>
11035 +#ifdef CONFIG_AUFS_INO_T_64
11043 +static ino_t decode_ino(__u32 *a)
11047 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11049 +#ifdef CONFIG_AUFS_INO_T_64
11055 +static void encode_ino(__u32 *a, ino_t ino)
11061 +#ifdef CONFIG_AUFS_INO_T_64
11066 +/* NFS file handle */
11070 +#ifdef CONFIG_AUFS_INO_T_64
11071 + /* support 64bit inode number */
11084 + Fh_ino = Fh_ino1,
11085 + Fh_dir_ino = Fh_dir_ino1
11088 +static int au_test_anon(struct dentry *dentry)
11090 + /* note: read d_flags without d_lock */
11091 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11094 +int au_test_nfsd(void)
11097 + struct task_struct *tsk = current;
11098 + char comm[sizeof(tsk->comm)];
11101 + if (tsk->flags & PF_KTHREAD) {
11102 + get_task_comm(comm, tsk);
11103 + ret = !strcmp(comm, "nfsd");
11109 +/* ---------------------------------------------------------------------- */
11110 +/* inode generation external table */
11112 +void au_xigen_inc(struct inode *inode)
11117 + struct super_block *sb;
11118 + struct au_sbinfo *sbinfo;
11120 + sb = inode->i_sb;
11121 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11123 + sbinfo = au_sbi(sb);
11124 + pos = inode->i_ino;
11125 + pos *= sizeof(igen);
11126 + igen = inode->i_generation + 1;
11127 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11128 + sizeof(igen), &pos);
11129 + if (sz == sizeof(igen))
11130 + return; /* success */
11132 + if (unlikely(sz >= 0))
11133 + AuIOErr("xigen error (%zd)\n", sz);
11136 +int au_xigen_new(struct inode *inode)
11141 + struct super_block *sb;
11142 + struct au_sbinfo *sbinfo;
11143 + struct file *file;
11146 + /* todo: dirty, at mount time */
11147 + if (inode->i_ino == AUFS_ROOT_INO)
11149 + sb = inode->i_sb;
11150 + SiMustAnyLock(sb);
11151 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11155 + pos = inode->i_ino;
11156 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11157 + AuIOErr1("too large i%lld\n", pos);
11160 + pos *= sizeof(inode->i_generation);
11163 + sbinfo = au_sbi(sb);
11164 + file = sbinfo->si_xigen;
11167 + if (vfsub_f_size_read(file)
11168 + < pos + sizeof(inode->i_generation)) {
11169 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11170 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11171 + sizeof(inode->i_generation), &pos);
11173 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11174 + sizeof(inode->i_generation), &pos);
11175 + if (sz == sizeof(inode->i_generation))
11176 + goto out; /* success */
11179 + if (unlikely(sz >= 0)) {
11181 + AuIOErr("xigen error (%zd)\n", sz);
11188 +int au_xigen_set(struct super_block *sb, struct file *base)
11191 + struct au_sbinfo *sbinfo;
11192 + struct file *file;
11194 + SiMustWriteLock(sb);
11196 + sbinfo = au_sbi(sb);
11197 + file = au_xino_create2(base, sbinfo->si_xigen);
11198 + err = PTR_ERR(file);
11199 + if (IS_ERR(file))
11202 + if (sbinfo->si_xigen)
11203 + fput(sbinfo->si_xigen);
11204 + sbinfo->si_xigen = file;
11210 +void au_xigen_clr(struct super_block *sb)
11212 + struct au_sbinfo *sbinfo;
11214 + SiMustWriteLock(sb);
11216 + sbinfo = au_sbi(sb);
11217 + if (sbinfo->si_xigen) {
11218 + fput(sbinfo->si_xigen);
11219 + sbinfo->si_xigen = NULL;
11223 +/* ---------------------------------------------------------------------- */
11225 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11228 + struct dentry *dentry, *d;
11229 + struct inode *inode;
11230 + unsigned int sigen;
11233 + inode = ilookup(sb, ino);
11237 + dentry = ERR_PTR(-ESTALE);
11238 + sigen = au_sigen(sb);
11239 + if (unlikely(au_is_bad_inode(inode)
11240 + || IS_DEADDIR(inode)
11241 + || sigen != au_iigen(inode, NULL)))
11245 + if (!dir_ino || S_ISDIR(inode->i_mode))
11246 + dentry = d_find_alias(inode);
11248 + spin_lock(&inode->i_lock);
11249 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11250 + spin_lock(&d->d_lock);
11251 + if (!au_test_anon(d)
11252 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11253 + dentry = dget_dlock(d);
11254 + spin_unlock(&d->d_lock);
11257 + spin_unlock(&d->d_lock);
11259 + spin_unlock(&inode->i_lock);
11261 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11262 + /* need to refresh */
11270 + AuTraceErrPtr(dentry);
11274 +/* ---------------------------------------------------------------------- */
11276 +/* todo: dirty? */
11277 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11279 +struct au_compare_mnt_args {
11281 + struct super_block *sb;
11284 + struct vfsmount *mnt;
11287 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11289 + struct au_compare_mnt_args *a = arg;
11291 + if (mnt->mnt_sb != a->sb)
11293 + a->mnt = mntget(mnt);
11297 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11300 + struct path root;
11301 + struct au_compare_mnt_args args = {
11305 + get_fs_root(current->fs, &root);
11307 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11308 + rcu_read_unlock();
11311 + AuDebugOn(!args.mnt);
11315 +struct au_nfsd_si_lock {
11316 + unsigned int sigen;
11317 + aufs_bindex_t bindex, br_id;
11318 + unsigned char force_lock;
11321 +static int si_nfsd_read_lock(struct super_block *sb,
11322 + struct au_nfsd_si_lock *nsi_lock)
11325 + aufs_bindex_t bindex;
11327 + si_read_lock(sb, AuLock_FLUSH);
11329 + /* branch id may be wrapped around */
11331 + bindex = au_br_index(sb, nsi_lock->br_id);
11332 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11333 + goto out; /* success */
11337 + if (!nsi_lock->force_lock)
11338 + si_read_unlock(sb);
11341 + nsi_lock->bindex = bindex;
11345 +struct find_name_by_ino {
11346 + struct dir_context ctx;
11347 + int called, found;
11354 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11355 + loff_t offset, u64 ino, unsigned int d_type)
11357 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11361 + if (a->ino != ino)
11364 + memcpy(a->name, name, namelen);
11365 + a->namelen = namelen;
11370 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11371 + struct au_nfsd_si_lock *nsi_lock)
11373 + struct dentry *dentry, *parent;
11374 + struct file *file;
11375 + struct inode *dir;
11376 + struct find_name_by_ino arg = {
11378 + .actor = find_name_by_ino
11383 + parent = path->dentry;
11385 + si_read_unlock(parent->d_sb);
11386 + file = vfsub_dentry_open(path, au_dir_roflags);
11387 + dentry = (void *)file;
11388 + if (IS_ERR(file))
11391 + dentry = ERR_PTR(-ENOMEM);
11392 + arg.name = (void *)__get_free_page(GFP_NOFS);
11393 + if (unlikely(!arg.name))
11400 + err = vfsub_iterate_dir(file, &arg.ctx);
11401 + } while (!err && !arg.found && arg.called);
11402 + dentry = ERR_PTR(err);
11403 + if (unlikely(err))
11405 + /* instead of ENOENT */
11406 + dentry = ERR_PTR(-ESTALE);
11410 + /* do not call vfsub_lkup_one() */
11411 + dir = d_inode(parent);
11412 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11413 + AuTraceErrPtr(dentry);
11414 + if (IS_ERR(dentry))
11416 + AuDebugOn(au_test_anon(dentry));
11417 + if (unlikely(d_really_is_negative(dentry))) {
11419 + dentry = ERR_PTR(-ENOENT);
11423 + au_delayed_free_page((unsigned long)arg.name);
11427 + if (unlikely(nsi_lock
11428 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11429 + if (!IS_ERR(dentry)) {
11431 + dentry = ERR_PTR(-ESTALE);
11433 + AuTraceErrPtr(dentry);
11437 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11439 + struct au_nfsd_si_lock *nsi_lock)
11441 + struct dentry *dentry;
11442 + struct path path;
11444 + if (dir_ino != AUFS_ROOT_INO) {
11445 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11446 + dentry = path.dentry;
11447 + if (!path.dentry || IS_ERR(path.dentry))
11449 + AuDebugOn(au_test_anon(path.dentry));
11451 + path.dentry = dget(sb->s_root);
11453 + path.mnt = au_mnt_get(sb);
11454 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11458 + AuTraceErrPtr(dentry);
11462 +/* ---------------------------------------------------------------------- */
11464 +static int h_acceptable(void *expv, struct dentry *dentry)
11469 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11470 + char *buf, int len, struct super_block *sb)
11474 + struct path path;
11476 + p = d_path(h_rootpath, buf, len);
11481 + path.mnt = h_rootpath->mnt;
11482 + path.dentry = h_parent;
11483 + p = d_path(&path, buf, len);
11489 + path.mnt = au_mnt_get(sb);
11490 + path.dentry = sb->s_root;
11491 + p = d_path(&path, buf, len - strlen(p));
11492 + mntput(path.mnt);
11496 + p[strlen(p)] = '/';
11499 + AuTraceErrPtr(p);
11504 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11505 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11507 + struct dentry *dentry, *h_parent, *root;
11508 + struct super_block *h_sb;
11509 + char *pathname, *p;
11510 + struct vfsmount *h_mnt;
11511 + struct au_branch *br;
11513 + struct path path;
11515 + br = au_sbr(sb, nsi_lock->bindex);
11516 + h_mnt = au_br_mnt(br);
11517 + h_sb = h_mnt->mnt_sb;
11518 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11520 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11521 + fh_len - Fh_tail, fh[Fh_h_type],
11522 + h_acceptable, /*context*/NULL);
11524 + dentry = h_parent;
11525 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11526 + AuWarn1("%s decode_fh failed, %ld\n",
11527 + au_sbtype(h_sb), PTR_ERR(h_parent));
11531 + if (unlikely(au_test_anon(h_parent))) {
11532 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11533 + au_sbtype(h_sb));
11534 + goto out_h_parent;
11537 + dentry = ERR_PTR(-ENOMEM);
11538 + pathname = (void *)__get_free_page(GFP_NOFS);
11539 + if (unlikely(!pathname))
11540 + goto out_h_parent;
11542 + root = sb->s_root;
11543 + path.mnt = h_mnt;
11544 + di_read_lock_parent(root, !AuLock_IR);
11545 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11546 + di_read_unlock(root, !AuLock_IR);
11547 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11548 + dentry = (void *)p;
11550 + goto out_pathname;
11552 + si_read_unlock(sb);
11553 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11554 + dentry = ERR_PTR(err);
11555 + if (unlikely(err))
11558 + dentry = ERR_PTR(-ENOENT);
11559 + AuDebugOn(au_test_anon(path.dentry));
11560 + if (unlikely(d_really_is_negative(path.dentry)))
11563 + if (ino != d_inode(path.dentry)->i_ino)
11564 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11566 + dentry = dget(path.dentry);
11571 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11572 + if (!IS_ERR(dentry)) {
11574 + dentry = ERR_PTR(-ESTALE);
11577 + au_delayed_free_page((unsigned long)pathname);
11581 + AuTraceErrPtr(dentry);
11585 +/* ---------------------------------------------------------------------- */
11587 +static struct dentry *
11588 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11591 + struct dentry *dentry;
11592 + __u32 *fh = fid->raw;
11593 + struct au_branch *br;
11594 + ino_t ino, dir_ino;
11595 + struct au_nfsd_si_lock nsi_lock = {
11599 + dentry = ERR_PTR(-ESTALE);
11600 + /* it should never happen, but the file handle is unreliable */
11601 + if (unlikely(fh_len < Fh_tail))
11603 + nsi_lock.sigen = fh[Fh_sigen];
11604 + nsi_lock.br_id = fh[Fh_br_id];
11606 + /* branch id may be wrapped around */
11608 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11610 + nsi_lock.force_lock = 1;
11612 + /* is this inode still cached? */
11613 + ino = decode_ino(fh + Fh_ino);
11614 + /* it should never happen */
11615 + if (unlikely(ino == AUFS_ROOT_INO))
11618 + dir_ino = decode_ino(fh + Fh_dir_ino);
11619 + dentry = decode_by_ino(sb, ino, dir_ino);
11620 + if (IS_ERR(dentry))
11625 + /* is the parent dir cached? */
11626 + br = au_sbr(sb, nsi_lock.bindex);
11628 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11629 + if (IS_ERR(dentry))
11634 + /* lookup path */
11635 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11636 + if (IS_ERR(dentry))
11638 + if (unlikely(!dentry))
11639 + /* todo?: make it ESTALE */
11643 + if (!au_digen_test(dentry, au_sigen(sb))
11644 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11645 + goto out_unlock; /* success */
11648 + dentry = ERR_PTR(-ESTALE);
11652 + si_read_unlock(sb);
11654 + AuTraceErrPtr(dentry);
11658 +#if 0 /* reserved for future use */
11659 +/* support subtreecheck option */
11660 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11661 + int fh_len, int fh_type)
11663 + struct dentry *parent;
11664 + __u32 *fh = fid->raw;
11667 + dir_ino = decode_ino(fh + Fh_dir_ino);
11668 + parent = decode_by_ino(sb, dir_ino, 0);
11669 + if (IS_ERR(parent))
11672 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11673 + dir_ino, fh, fh_len);
11676 + AuTraceErrPtr(parent);
11681 +/* ---------------------------------------------------------------------- */
11683 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11684 + struct inode *dir)
11687 + aufs_bindex_t bindex;
11688 + struct super_block *sb, *h_sb;
11689 + struct dentry *dentry, *parent, *h_parent;
11690 + struct inode *h_dir;
11691 + struct au_branch *br;
11694 + if (unlikely(*max_len <= Fh_tail)) {
11695 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11699 + err = FILEID_ROOT;
11700 + if (inode->i_ino == AUFS_ROOT_INO) {
11701 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11706 + sb = inode->i_sb;
11707 + err = si_read_lock(sb, AuLock_FLUSH);
11708 + if (unlikely(err))
11711 +#ifdef CONFIG_AUFS_DEBUG
11712 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11713 + AuWarn1("NFS-exporting requires xino\n");
11717 + ii_read_lock_child(inode);
11718 + bindex = au_ibtop(inode);
11720 + dentry = d_find_any_alias(inode);
11721 + if (unlikely(!dentry))
11723 + AuDebugOn(au_test_anon(dentry));
11724 + parent = dget_parent(dentry);
11726 + if (unlikely(!parent))
11728 + if (d_really_is_positive(parent))
11729 + dir = d_inode(parent);
11732 + ii_read_lock_parent(dir);
11733 + h_dir = au_h_iptr(dir, bindex);
11734 + ii_read_unlock(dir);
11735 + if (unlikely(!h_dir))
11737 + h_parent = d_find_any_alias(h_dir);
11738 + if (unlikely(!h_parent))
11739 + goto out_hparent;
11742 + br = au_sbr(sb, bindex);
11743 + h_sb = au_br_sb(br);
11744 + if (unlikely(!h_sb->s_export_op)) {
11745 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11746 + goto out_hparent;
11749 + fh[Fh_br_id] = br->br_id;
11750 + fh[Fh_sigen] = au_sigen(sb);
11751 + encode_ino(fh + Fh_ino, inode->i_ino);
11752 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11753 + fh[Fh_igen] = inode->i_generation;
11755 + *max_len -= Fh_tail;
11756 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11758 + /*connectable or subtreecheck*/0);
11759 + err = fh[Fh_h_type];
11760 + *max_len += Fh_tail;
11761 + /* todo: macros? */
11762 + if (err != FILEID_INVALID)
11765 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11772 + ii_read_unlock(inode);
11773 + si_read_unlock(sb);
11775 + if (unlikely(err < 0))
11776 + err = FILEID_INVALID;
11780 +/* ---------------------------------------------------------------------- */
11782 +static int aufs_commit_metadata(struct inode *inode)
11785 + aufs_bindex_t bindex;
11786 + struct super_block *sb;
11787 + struct inode *h_inode;
11788 + int (*f)(struct inode *inode);
11790 + sb = inode->i_sb;
11791 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11792 + ii_write_lock_child(inode);
11793 + bindex = au_ibtop(inode);
11794 + AuDebugOn(bindex < 0);
11795 + h_inode = au_h_iptr(inode, bindex);
11797 + f = h_inode->i_sb->s_export_op->commit_metadata;
11799 + err = f(h_inode);
11801 + struct writeback_control wbc = {
11802 + .sync_mode = WB_SYNC_ALL,
11803 + .nr_to_write = 0 /* metadata only */
11806 + err = sync_inode(h_inode, &wbc);
11809 + au_cpup_attr_timesizes(inode);
11810 + ii_write_unlock(inode);
11811 + si_read_unlock(sb);
11815 +/* ---------------------------------------------------------------------- */
11817 +static struct export_operations aufs_export_op = {
11818 + .fh_to_dentry = aufs_fh_to_dentry,
11819 + /* .fh_to_parent = aufs_fh_to_parent, */
11820 + .encode_fh = aufs_encode_fh,
11821 + .commit_metadata = aufs_commit_metadata
11824 +void au_export_init(struct super_block *sb)
11826 + struct au_sbinfo *sbinfo;
11829 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11830 + && IS_MODULE(CONFIG_EXPORTFS),
11831 + AUFS_NAME ": unsupported configuration "
11832 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11834 + sb->s_export_op = &aufs_export_op;
11835 + sbinfo = au_sbi(sb);
11836 + sbinfo->si_xigen = NULL;
11837 + get_random_bytes(&u, sizeof(u));
11838 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11839 + atomic_set(&sbinfo->si_xigen_next, u);
11841 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11842 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11843 +++ linux/fs/aufs/fhsm.c 2017-03-02 14:24:13.860255635 +0100
11846 + * Copyright (C) 2011-2017 Junjiro R. Okajima
11848 + * This program, aufs is free software; you can redistribute it and/or modify
11849 + * it under the terms of the GNU General Public License as published by
11850 + * the Free Software Foundation; either version 2 of the License, or
11851 + * (at your option) any later version.
11853 + * This program is distributed in the hope that it will be useful,
11854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11856 + * GNU General Public License for more details.
11858 + * You should have received a copy of the GNU General Public License
11859 + * along with this program; if not, write to the Free Software
11860 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11864 + * File-based Hierarchy Storage Management
11867 +#include <linux/anon_inodes.h>
11868 +#include <linux/poll.h>
11869 +#include <linux/seq_file.h>
11870 +#include <linux/statfs.h>
11873 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11875 + struct au_sbinfo *sbinfo;
11876 + struct au_fhsm *fhsm;
11878 + SiMustAnyLock(sb);
11880 + sbinfo = au_sbi(sb);
11881 + fhsm = &sbinfo->si_fhsm;
11882 + AuDebugOn(!fhsm);
11883 + return fhsm->fhsm_bottom;
11886 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11888 + struct au_sbinfo *sbinfo;
11889 + struct au_fhsm *fhsm;
11891 + SiMustWriteLock(sb);
11893 + sbinfo = au_sbi(sb);
11894 + fhsm = &sbinfo->si_fhsm;
11895 + AuDebugOn(!fhsm);
11896 + fhsm->fhsm_bottom = bindex;
11899 +/* ---------------------------------------------------------------------- */
11901 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11903 + struct au_br_fhsm *bf;
11905 + bf = br->br_fhsm;
11906 + MtxMustLock(&bf->bf_lock);
11908 + return !bf->bf_readable
11909 + || time_after(jiffies,
11910 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11913 +/* ---------------------------------------------------------------------- */
11915 +static void au_fhsm_notify(struct super_block *sb, int val)
11917 + struct au_sbinfo *sbinfo;
11918 + struct au_fhsm *fhsm;
11920 + SiMustAnyLock(sb);
11922 + sbinfo = au_sbi(sb);
11923 + fhsm = &sbinfo->si_fhsm;
11924 + if (au_fhsm_pid(fhsm)
11925 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11926 + atomic_set(&fhsm->fhsm_readable, val);
11928 + wake_up(&fhsm->fhsm_wqh);
11932 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11933 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11936 + struct au_branch *br;
11937 + struct au_br_fhsm *bf;
11939 + br = au_sbr(sb, bindex);
11940 + AuDebugOn(au_br_rdonly(br));
11941 + bf = br->br_fhsm;
11945 + mutex_lock(&bf->bf_lock);
11947 + MtxMustLock(&bf->bf_lock);
11949 + /* sb->s_root for NFS is unreliable */
11950 + err = au_br_stfs(br, &bf->bf_stfs);
11951 + if (unlikely(err)) {
11952 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11956 + bf->bf_jiffy = jiffies;
11957 + bf->bf_readable = 1;
11959 + au_fhsm_notify(sb, /*val*/1);
11961 + *rstfs = bf->bf_stfs;
11965 + mutex_unlock(&bf->bf_lock);
11966 + au_fhsm_notify(sb, /*val*/1);
11971 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11974 + struct au_sbinfo *sbinfo;
11975 + struct au_fhsm *fhsm;
11976 + struct au_branch *br;
11977 + struct au_br_fhsm *bf;
11979 + AuDbg("b%d, force %d\n", bindex, force);
11980 + SiMustAnyLock(sb);
11982 + sbinfo = au_sbi(sb);
11983 + fhsm = &sbinfo->si_fhsm;
11984 + if (!au_ftest_si(sbinfo, FHSM)
11985 + || fhsm->fhsm_bottom == bindex)
11988 + br = au_sbr(sb, bindex);
11989 + bf = br->br_fhsm;
11991 + mutex_lock(&bf->bf_lock);
11993 + || au_fhsm_pid(fhsm)
11994 + || au_fhsm_test_jiffy(sbinfo, br))
11995 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11997 + mutex_unlock(&bf->bf_lock);
12000 +void au_fhsm_wrote_all(struct super_block *sb, int force)
12002 + aufs_bindex_t bindex, bbot;
12003 + struct au_branch *br;
12005 + /* exclude the bottom */
12006 + bbot = au_fhsm_bottom(sb);
12007 + for (bindex = 0; bindex < bbot; bindex++) {
12008 + br = au_sbr(sb, bindex);
12009 + if (au_br_fhsm(br->br_perm))
12010 + au_fhsm_wrote(sb, bindex, force);
12014 +/* ---------------------------------------------------------------------- */
12016 +static unsigned int au_fhsm_poll(struct file *file,
12017 + struct poll_table_struct *wait)
12019 + unsigned int mask;
12020 + struct au_sbinfo *sbinfo;
12021 + struct au_fhsm *fhsm;
12024 + sbinfo = file->private_data;
12025 + fhsm = &sbinfo->si_fhsm;
12026 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12027 + if (atomic_read(&fhsm->fhsm_readable))
12028 + mask = POLLIN /* | POLLRDNORM */;
12030 + AuTraceErr((int)mask);
12034 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12035 + struct aufs_stfs *stfs, __s16 brid)
12039 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12041 + err = __put_user(brid, &stbr->brid);
12042 + if (unlikely(err))
12048 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12049 + struct aufs_stbr __user *stbr, size_t count)
12053 + aufs_bindex_t bindex, bbot;
12054 + struct au_branch *br;
12055 + struct au_br_fhsm *bf;
12057 + /* except the bottom branch */
12060 + bbot = au_fhsm_bottom(sb);
12061 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12062 + br = au_sbr(sb, bindex);
12063 + if (!au_br_fhsm(br->br_perm))
12066 + bf = br->br_fhsm;
12067 + mutex_lock(&bf->bf_lock);
12068 + if (bf->bf_readable) {
12070 + if (count >= sizeof(*stbr))
12071 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12074 + bf->bf_readable = 0;
12075 + count -= sizeof(*stbr);
12079 + mutex_unlock(&bf->bf_lock);
12082 + err = sizeof(*stbr) * nstbr;
12087 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12092 + aufs_bindex_t nfhsm, bindex, bbot;
12093 + struct au_sbinfo *sbinfo;
12094 + struct au_fhsm *fhsm;
12095 + struct au_branch *br;
12096 + struct super_block *sb;
12099 + sbinfo = file->private_data;
12100 + fhsm = &sbinfo->si_fhsm;
12102 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12103 + if (!atomic_read(&fhsm->fhsm_readable)) {
12104 + if (vfsub_file_flags(file) & O_NONBLOCK)
12107 + err = wait_event_interruptible_locked_irq
12109 + atomic_read(&fhsm->fhsm_readable));
12111 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12112 + if (unlikely(err))
12115 + /* sb may already be dead */
12116 + au_rw_read_lock(&sbinfo->si_rwsem);
12117 + readable = atomic_read(&fhsm->fhsm_readable);
12118 + if (readable > 0) {
12119 + sb = sbinfo->si_sb;
12121 + /* exclude the bottom branch */
12123 + bbot = au_fhsm_bottom(sb);
12124 + for (bindex = 0; bindex < bbot; bindex++) {
12125 + br = au_sbr(sb, bindex);
12126 + if (au_br_fhsm(br->br_perm))
12130 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12131 + atomic_set(&fhsm->fhsm_readable, 0);
12132 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12136 + au_rw_read_unlock(&sbinfo->si_rwsem);
12144 +static int au_fhsm_release(struct inode *inode, struct file *file)
12146 + struct au_sbinfo *sbinfo;
12147 + struct au_fhsm *fhsm;
12149 + /* sb may already be dead */
12150 + sbinfo = file->private_data;
12151 + fhsm = &sbinfo->si_fhsm;
12152 + spin_lock(&fhsm->fhsm_spin);
12153 + fhsm->fhsm_pid = 0;
12154 + spin_unlock(&fhsm->fhsm_spin);
12155 + kobject_put(&sbinfo->si_kobj);
12160 +static const struct file_operations au_fhsm_fops = {
12161 + .owner = THIS_MODULE,
12162 + .llseek = noop_llseek,
12163 + .read = au_fhsm_read,
12164 + .poll = au_fhsm_poll,
12165 + .release = au_fhsm_release
12168 +int au_fhsm_fd(struct super_block *sb, int oflags)
12171 + struct au_sbinfo *sbinfo;
12172 + struct au_fhsm *fhsm;
12175 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12179 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12183 + sbinfo = au_sbi(sb);
12184 + fhsm = &sbinfo->si_fhsm;
12185 + spin_lock(&fhsm->fhsm_spin);
12186 + if (!fhsm->fhsm_pid)
12187 + fhsm->fhsm_pid = current->pid;
12190 + spin_unlock(&fhsm->fhsm_spin);
12191 + if (unlikely(err))
12194 + oflags |= O_RDONLY;
12195 + /* oflags |= FMODE_NONOTIFY; */
12196 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12198 + if (unlikely(fd < 0))
12201 + /* succeed reglardless 'fhsm' status */
12202 + kobject_get(&sbinfo->si_kobj);
12203 + si_noflush_read_lock(sb);
12204 + if (au_ftest_si(sbinfo, FHSM))
12205 + au_fhsm_wrote_all(sb, /*force*/0);
12206 + si_read_unlock(sb);
12207 + goto out; /* success */
12210 + spin_lock(&fhsm->fhsm_spin);
12211 + fhsm->fhsm_pid = 0;
12212 + spin_unlock(&fhsm->fhsm_spin);
12218 +/* ---------------------------------------------------------------------- */
12220 +int au_fhsm_br_alloc(struct au_branch *br)
12225 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12227 + au_br_fhsm_init(br->br_fhsm);
12234 +/* ---------------------------------------------------------------------- */
12236 +void au_fhsm_fin(struct super_block *sb)
12238 + au_fhsm_notify(sb, /*val*/-1);
12241 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12243 + struct au_fhsm *fhsm;
12245 + fhsm = &sbinfo->si_fhsm;
12246 + spin_lock_init(&fhsm->fhsm_spin);
12247 + init_waitqueue_head(&fhsm->fhsm_wqh);
12248 + atomic_set(&fhsm->fhsm_readable, 0);
12249 + fhsm->fhsm_expire
12250 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12251 + fhsm->fhsm_bottom = -1;
12254 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12256 + sbinfo->si_fhsm.fhsm_expire
12257 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12260 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12264 + if (!au_ftest_si(sbinfo, FHSM))
12267 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12268 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12269 + seq_printf(seq, ",fhsm_sec=%u", u);
12271 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12272 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12273 +++ linux/fs/aufs/file.c 2017-03-02 14:24:13.860255635 +0100
12276 + * Copyright (C) 2005-2017 Junjiro R. Okajima
12278 + * This program, aufs is free software; you can redistribute it and/or modify
12279 + * it under the terms of the GNU General Public License as published by
12280 + * the Free Software Foundation; either version 2 of the License, or
12281 + * (at your option) any later version.
12283 + * This program is distributed in the hope that it will be useful,
12284 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12285 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12286 + * GNU General Public License for more details.
12288 + * You should have received a copy of the GNU General Public License
12289 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12293 + * handling file/dir, and address_space operation
12296 +#ifdef CONFIG_AUFS_DEBUG
12297 +#include <linux/migrate.h>
12299 +#include <linux/pagemap.h>
12302 +/* drop flags for writing */
12303 +unsigned int au_file_roflags(unsigned int flags)
12305 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12306 + flags |= O_RDONLY | O_NOATIME;
12310 +/* common functions to regular file and dir */
12311 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12312 + struct file *file, int force_wr)
12314 + struct file *h_file;
12315 + struct dentry *h_dentry;
12316 + struct inode *h_inode;
12317 + struct super_block *sb;
12318 + struct au_branch *br;
12319 + struct path h_path;
12322 + /* a race condition can happen between open and unlink/rmdir */
12323 + h_file = ERR_PTR(-ENOENT);
12324 + h_dentry = au_h_dptr(dentry, bindex);
12325 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12327 + h_inode = d_inode(h_dentry);
12328 + spin_lock(&h_dentry->d_lock);
12329 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12330 + /* || !d_inode(dentry)->i_nlink */
12332 + spin_unlock(&h_dentry->d_lock);
12333 + if (unlikely(err))
12336 + sb = dentry->d_sb;
12337 + br = au_sbr(sb, bindex);
12338 + err = au_br_test_oflag(flags, br);
12339 + h_file = ERR_PTR(err);
12340 + if (unlikely(err))
12343 + /* drop flags for writing */
12344 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12345 + if (force_wr && !(flags & O_WRONLY))
12347 + flags = au_file_roflags(flags);
12349 + h_file = ERR_PTR(-EROFS);
12350 + flags = au_file_roflags(flags);
12351 + if (unlikely(vfsub_native_ro(h_inode)
12352 + || IS_APPEND(h_inode)))
12354 + flags &= ~O_ACCMODE;
12355 + flags |= O_WRONLY;
12358 + flags &= ~O_CREAT;
12360 + h_path.dentry = h_dentry;
12361 + h_path.mnt = au_br_mnt(br);
12362 + h_file = vfsub_dentry_open(&h_path, flags);
12363 + if (IS_ERR(h_file))
12366 + if (flags & __FMODE_EXEC) {
12367 + err = deny_write_access(h_file);
12368 + if (unlikely(err)) {
12370 + h_file = ERR_PTR(err);
12374 + fsnotify_open(h_file);
12375 + goto out; /* success */
12383 +static int au_cmoo(struct dentry *dentry)
12386 + unsigned int udba;
12387 + struct path h_path;
12388 + struct au_pin pin;
12389 + struct au_cp_generic cpg = {
12390 + .dentry = dentry,
12395 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12397 + struct inode *delegated;
12398 + struct super_block *sb;
12399 + struct au_sbinfo *sbinfo;
12400 + struct au_fhsm *fhsm;
12402 + struct au_branch *br;
12403 + struct dentry *parent;
12404 + struct au_hinode *hdir;
12406 + DiMustWriteLock(dentry);
12407 + IiMustWriteLock(d_inode(dentry));
12410 + if (IS_ROOT(dentry))
12412 + cpg.bsrc = au_dbtop(dentry);
12416 + sb = dentry->d_sb;
12417 + sbinfo = au_sbi(sb);
12418 + fhsm = &sbinfo->si_fhsm;
12419 + pid = au_fhsm_pid(fhsm);
12421 + && (current->pid == pid
12422 + || current->real_parent->pid == pid))
12425 + br = au_sbr(sb, cpg.bsrc);
12426 + cmoo = au_br_cmoo(br->br_perm);
12429 + if (!d_is_reg(dentry))
12430 + cmoo &= AuBrAttr_COO_ALL;
12434 + parent = dget_parent(dentry);
12435 + di_write_lock_parent(parent);
12436 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12438 + if (unlikely(err < 0)) {
12439 + err = 0; /* there is no upper writable branch */
12442 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12444 + /* do not respect the coo attrib for the target branch */
12445 + err = au_cpup_dirs(dentry, cpg.bdst);
12446 + if (unlikely(err))
12449 + di_downgrade_lock(parent, AuLock_IR);
12450 + udba = au_opt_udba(sb);
12451 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12452 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12453 + if (unlikely(err))
12456 + err = au_sio_cpup_simple(&cpg);
12458 + if (unlikely(err))
12460 + if (!(cmoo & AuBrWAttr_MOO))
12461 + goto out_parent; /* success */
12463 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12464 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12465 + if (unlikely(err))
12468 + h_path.mnt = au_br_mnt(br);
12469 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12470 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12471 + delegated = NULL;
12472 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12474 + /* todo: keep h_dentry or not? */
12475 + if (unlikely(err == -EWOULDBLOCK)) {
12476 + pr_warn("cannot retry for NFSv4 delegation"
12477 + " for an internal unlink\n");
12480 + if (unlikely(err)) {
12481 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12485 + goto out_parent; /* success */
12488 + di_downgrade_lock(parent, AuLock_IR);
12490 + di_read_unlock(parent, AuLock_IR);
12497 +int au_do_open(struct file *file, struct au_do_open_args *args)
12499 + int err, no_lock = args->no_lock;
12500 + struct dentry *dentry;
12501 + struct au_finfo *finfo;
12504 + err = au_finfo_init(file, args->fidir);
12507 + err = au_finfo_init(file, args->fidir);
12510 + if (unlikely(err))
12513 + dentry = file->f_path.dentry;
12514 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12516 + di_write_lock_child(dentry);
12517 + err = au_cmoo(dentry);
12518 + di_downgrade_lock(dentry, AuLock_IR);
12520 + err = args->open(file, vfsub_file_flags(file), NULL);
12521 + di_read_unlock(dentry, AuLock_IR);
12523 + err = au_cmoo(dentry);
12525 + err = args->open(file, vfsub_file_flags(file),
12527 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12529 + * cmoo happens after h_file was opened.
12530 + * need to refresh file later.
12532 + atomic_dec(&au_fi(file)->fi_generation);
12535 + finfo = au_fi(file);
12537 + finfo->fi_file = file;
12538 + au_sphl_add(&finfo->fi_hlist,
12539 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12542 + fi_write_unlock(file);
12545 + fi_write_unlock(file);
12548 + if (unlikely(err)) {
12549 + finfo->fi_hdir = NULL;
12550 + au_finfo_fin(file, /*atonce*/0);
12557 +int au_reopen_nondir(struct file *file)
12560 + aufs_bindex_t btop;
12561 + struct dentry *dentry;
12562 + struct file *h_file, *h_file_tmp;
12564 + dentry = file->f_path.dentry;
12565 + btop = au_dbtop(dentry);
12566 + h_file_tmp = NULL;
12567 + if (au_fbtop(file) == btop) {
12568 + h_file = au_hf_top(file);
12569 + if (file->f_mode == h_file->f_mode)
12570 + return 0; /* success */
12571 + h_file_tmp = h_file;
12572 + get_file(h_file_tmp);
12573 + au_set_h_fptr(file, btop, NULL);
12575 + AuDebugOn(au_fi(file)->fi_hdir);
12578 + * file exists on both of rw and ro
12579 + * open --> dbtop and fbtop are both 0
12580 + * prepend a branch as rw, "rw" become ro
12582 + * delete the top branch, "rw" becomes rw again
12583 + * --> dbtop is 1, fbtop is still 0
12584 + * write --> fbtop is 0 but dbtop is 1
12586 + /* AuDebugOn(au_fbtop(file) < btop); */
12588 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12589 + file, /*force_wr*/0);
12590 + err = PTR_ERR(h_file);
12591 + if (IS_ERR(h_file)) {
12592 + if (h_file_tmp) {
12593 + au_sbr_get(dentry->d_sb, btop);
12594 + au_set_h_fptr(file, btop, h_file_tmp);
12595 + h_file_tmp = NULL;
12597 + goto out; /* todo: close all? */
12601 + au_set_fbtop(file, btop);
12602 + au_set_h_fptr(file, btop, h_file);
12603 + au_update_figen(file);
12604 + /* todo: necessary? */
12605 + /* file->f_ra = h_file->f_ra; */
12609 + fput(h_file_tmp);
12613 +/* ---------------------------------------------------------------------- */
12615 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12616 + struct dentry *hi_wh)
12619 + aufs_bindex_t btop;
12620 + struct au_dinfo *dinfo;
12621 + struct dentry *h_dentry;
12622 + struct au_hdentry *hdp;
12624 + dinfo = au_di(file->f_path.dentry);
12625 + AuRwMustWriteLock(&dinfo->di_rwsem);
12627 + btop = dinfo->di_btop;
12628 + dinfo->di_btop = btgt;
12629 + hdp = au_hdentry(dinfo, btgt);
12630 + h_dentry = hdp->hd_dentry;
12631 + hdp->hd_dentry = hi_wh;
12632 + err = au_reopen_nondir(file);
12633 + hdp->hd_dentry = h_dentry;
12634 + dinfo->di_btop = btop;
12639 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12640 + aufs_bindex_t bcpup, struct au_pin *pin)
12643 + struct inode *inode, *h_inode;
12644 + struct dentry *h_dentry, *hi_wh;
12645 + struct au_cp_generic cpg = {
12646 + .dentry = file->f_path.dentry,
12653 + au_update_dbtop(cpg.dentry);
12654 + inode = d_inode(cpg.dentry);
12656 + if (au_dbtop(cpg.dentry) <= bcpup
12657 + && au_dbbot(cpg.dentry) >= bcpup) {
12658 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12659 + if (h_dentry && d_is_positive(h_dentry))
12660 + h_inode = d_inode(h_dentry);
12662 + hi_wh = au_hi_wh(inode, bcpup);
12663 + if (!hi_wh && !h_inode)
12664 + err = au_sio_cpup_wh(&cpg, file);
12666 + /* already copied-up after unlink */
12667 + err = au_reopen_wh(file, bcpup, hi_wh);
12670 + && (inode->i_nlink > 1
12671 + || (inode->i_state & I_LINKABLE))
12672 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12673 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12679 + * prepare the @file for writing.
12681 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12684 + aufs_bindex_t dbtop;
12685 + struct dentry *parent;
12686 + struct inode *inode;
12687 + struct super_block *sb;
12688 + struct file *h_file;
12689 + struct au_cp_generic cpg = {
12690 + .dentry = file->f_path.dentry,
12695 + .flags = AuCpup_DTIME
12698 + sb = cpg.dentry->d_sb;
12699 + inode = d_inode(cpg.dentry);
12700 + cpg.bsrc = au_fbtop(file);
12701 + err = au_test_ro(sb, cpg.bsrc, inode);
12702 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12703 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12708 + /* need to cpup or reopen */
12709 + parent = dget_parent(cpg.dentry);
12710 + di_write_lock_parent(parent);
12711 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12713 + if (unlikely(err < 0))
12717 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12718 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12719 + if (unlikely(err))
12723 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12724 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12725 + if (unlikely(err))
12728 + dbtop = au_dbtop(cpg.dentry);
12729 + if (dbtop <= cpg.bdst)
12730 + cpg.bsrc = cpg.bdst;
12732 + if (dbtop <= cpg.bdst /* just reopen */
12733 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12735 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12736 + if (IS_ERR(h_file))
12737 + err = PTR_ERR(h_file);
12739 + di_downgrade_lock(parent, AuLock_IR);
12740 + if (dbtop > cpg.bdst)
12741 + err = au_sio_cpup_simple(&cpg);
12743 + err = au_reopen_nondir(file);
12744 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12746 + } else { /* copyup as wh and reopen */
12748 + * since writable hfsplus branch is not supported,
12749 + * h_open_pre/post() are unnecessary.
12751 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12752 + di_downgrade_lock(parent, AuLock_IR);
12756 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12757 + goto out_dput; /* success */
12763 + di_downgrade_lock(parent, AuLock_IR);
12765 + di_read_unlock(parent, AuLock_IR);
12772 +/* ---------------------------------------------------------------------- */
12774 +int au_do_flush(struct file *file, fl_owner_t id,
12775 + int (*flush)(struct file *file, fl_owner_t id))
12778 + struct super_block *sb;
12779 + struct inode *inode;
12781 + inode = file_inode(file);
12782 + sb = inode->i_sb;
12783 + si_noflush_read_lock(sb);
12784 + fi_read_lock(file);
12785 + ii_read_lock_child(inode);
12787 + err = flush(file, id);
12788 + au_cpup_attr_timesizes(inode);
12790 + ii_read_unlock(inode);
12791 + fi_read_unlock(file);
12792 + si_read_unlock(sb);
12796 +/* ---------------------------------------------------------------------- */
12798 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12801 + struct au_pin pin;
12802 + struct au_finfo *finfo;
12803 + struct dentry *parent, *hi_wh;
12804 + struct inode *inode;
12805 + struct super_block *sb;
12806 + struct au_cp_generic cpg = {
12807 + .dentry = file->f_path.dentry,
12812 + .flags = AuCpup_DTIME
12815 + FiMustWriteLock(file);
12818 + finfo = au_fi(file);
12819 + sb = cpg.dentry->d_sb;
12820 + inode = d_inode(cpg.dentry);
12821 + cpg.bdst = au_ibtop(inode);
12822 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12825 + parent = dget_parent(cpg.dentry);
12826 + if (au_test_ro(sb, cpg.bdst, inode)) {
12827 + di_read_lock_parent(parent, !AuLock_IR);
12828 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12830 + di_read_unlock(parent, !AuLock_IR);
12831 + if (unlikely(err < 0))
12836 + di_read_lock_parent(parent, AuLock_IR);
12837 + hi_wh = au_hi_wh(inode, cpg.bdst);
12838 + if (!S_ISDIR(inode->i_mode)
12839 + && au_opt_test(au_mntflags(sb), PLINK)
12840 + && au_plink_test(inode)
12841 + && !d_unhashed(cpg.dentry)
12842 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12843 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12844 + if (unlikely(err))
12847 + /* always superio. */
12848 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12849 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12851 + err = au_sio_cpup_simple(&cpg);
12854 + } else if (hi_wh) {
12855 + /* already copied-up after unlink */
12856 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12857 + *need_reopen = 0;
12861 + di_read_unlock(parent, AuLock_IR);
12868 +static void au_do_refresh_dir(struct file *file)
12871 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12872 + struct au_hfile *p, tmp, *q;
12873 + struct au_finfo *finfo;
12874 + struct super_block *sb;
12875 + struct au_fidir *fidir;
12877 + FiMustWriteLock(file);
12879 + sb = file->f_path.dentry->d_sb;
12880 + finfo = au_fi(file);
12881 + fidir = finfo->fi_hdir;
12882 + AuDebugOn(!fidir);
12883 + p = fidir->fd_hfile + finfo->fi_btop;
12884 + brid = p->hf_br->br_id;
12885 + bbot = fidir->fd_bbot;
12886 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12890 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12891 + if (new_bindex == bindex)
12893 + if (new_bindex < 0) {
12894 + au_set_h_fptr(file, bindex, NULL);
12898 + /* swap two lower inode, and loop again */
12899 + q = fidir->fd_hfile + new_bindex;
12903 + if (tmp.hf_file) {
12909 + execed = vfsub_file_execed(file);
12910 + p = fidir->fd_hfile;
12911 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12912 + bbot = au_sbbot(sb);
12913 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12914 + finfo->fi_btop++, p++)
12915 + if (p->hf_file) {
12916 + if (file_inode(p->hf_file))
12918 + au_hfput(p, execed);
12921 + bbot = au_br_index(sb, brid);
12922 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12923 + finfo->fi_btop++, p++)
12925 + au_hfput(p, execed);
12926 + bbot = au_sbbot(sb);
12929 + p = fidir->fd_hfile + bbot;
12930 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12931 + fidir->fd_bbot--, p--)
12932 + if (p->hf_file) {
12933 + if (file_inode(p->hf_file))
12935 + au_hfput(p, execed);
12937 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12941 + * after branch manipulating, refresh the file.
12943 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12945 + int err, need_reopen, nbr;
12946 + aufs_bindex_t bbot, bindex;
12947 + struct dentry *dentry;
12948 + struct super_block *sb;
12949 + struct au_finfo *finfo;
12950 + struct au_hfile *hfile;
12952 + dentry = file->f_path.dentry;
12953 + sb = dentry->d_sb;
12954 + nbr = au_sbbot(sb) + 1;
12955 + finfo = au_fi(file);
12956 + if (!finfo->fi_hdir) {
12957 + hfile = &finfo->fi_htop;
12958 + AuDebugOn(!hfile->hf_file);
12959 + bindex = au_br_index(sb, hfile->hf_br->br_id);
12960 + AuDebugOn(bindex < 0);
12961 + if (bindex != finfo->fi_btop)
12962 + au_set_fbtop(file, bindex);
12964 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
12965 + if (unlikely(err))
12967 + au_do_refresh_dir(file);
12972 + if (!au_test_mmapped(file))
12973 + err = au_file_refresh_by_inode(file, &need_reopen);
12974 + if (finfo->fi_hdir)
12975 + /* harmless if err */
12976 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
12977 + if (!err && need_reopen && !d_unlinked(dentry))
12978 + err = reopen(file);
12980 + au_update_figen(file);
12981 + goto out; /* success */
12984 + /* error, close all lower files */
12985 + if (finfo->fi_hdir) {
12986 + bbot = au_fbbot_dir(file);
12987 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
12988 + au_set_h_fptr(file, bindex, NULL);
12995 +/* common function to regular file and dir */
12996 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13000 + unsigned int sigen, figen;
13001 + aufs_bindex_t btop;
13002 + unsigned char pseudo_link;
13003 + struct dentry *dentry;
13004 + struct inode *inode;
13007 + dentry = file->f_path.dentry;
13008 + inode = d_inode(dentry);
13009 + sigen = au_sigen(dentry->d_sb);
13010 + fi_write_lock(file);
13011 + figen = au_figen(file);
13012 + di_write_lock_child(dentry);
13013 + btop = au_dbtop(dentry);
13014 + pseudo_link = (btop != au_ibtop(inode));
13015 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
13017 + di_downgrade_lock(dentry, AuLock_IR);
13018 + fi_downgrade_lock(file);
13020 + goto out; /* success */
13023 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13024 + if (au_digen_test(dentry, sigen)) {
13025 + err = au_reval_dpath(dentry, sigen);
13026 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13030 + err = refresh_file(file, reopen);
13033 + di_downgrade_lock(dentry, AuLock_IR);
13034 + fi_downgrade_lock(file);
13037 + di_write_unlock(dentry);
13038 + fi_write_unlock(file);
13045 +/* ---------------------------------------------------------------------- */
13047 +/* cf. aufs_nopage() */
13048 +/* for madvise(2) */
13049 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13051 + unlock_page(page);
13055 +/* it will never be called, but necessary to support O_DIRECT */
13056 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13057 +{ BUG(); return 0; }
13059 +/* they will never be called. */
13060 +#ifdef CONFIG_AUFS_DEBUG
13061 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13062 + loff_t pos, unsigned len, unsigned flags,
13063 + struct page **pagep, void **fsdata)
13064 +{ AuUnsupport(); return 0; }
13065 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13066 + loff_t pos, unsigned len, unsigned copied,
13067 + struct page *page, void *fsdata)
13068 +{ AuUnsupport(); return 0; }
13069 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13070 +{ AuUnsupport(); return 0; }
13072 +static int aufs_set_page_dirty(struct page *page)
13073 +{ AuUnsupport(); return 0; }
13074 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13075 + unsigned int length)
13076 +{ AuUnsupport(); }
13077 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13078 +{ AuUnsupport(); return 0; }
13079 +#if 0 /* called by memory compaction regardless file */
13080 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13081 + struct page *page, enum migrate_mode mode)
13082 +{ AuUnsupport(); return 0; }
13084 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13085 +{ AuUnsupport(); return true; }
13086 +static void aufs_putback_page(struct page *page)
13087 +{ AuUnsupport(); }
13088 +static int aufs_launder_page(struct page *page)
13089 +{ AuUnsupport(); return 0; }
13090 +static int aufs_is_partially_uptodate(struct page *page,
13091 + unsigned long from,
13092 + unsigned long count)
13093 +{ AuUnsupport(); return 0; }
13094 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13096 +{ AuUnsupport(); }
13097 +static int aufs_error_remove_page(struct address_space *mapping,
13098 + struct page *page)
13099 +{ AuUnsupport(); return 0; }
13100 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13102 +{ AuUnsupport(); return 0; }
13103 +static void aufs_swap_deactivate(struct file *file)
13104 +{ AuUnsupport(); }
13105 +#endif /* CONFIG_AUFS_DEBUG */
13107 +const struct address_space_operations aufs_aop = {
13108 + .readpage = aufs_readpage,
13109 + .direct_IO = aufs_direct_IO,
13110 +#ifdef CONFIG_AUFS_DEBUG
13111 + .writepage = aufs_writepage,
13112 + /* no writepages, because of writepage */
13113 + .set_page_dirty = aufs_set_page_dirty,
13114 + /* no readpages, because of readpage */
13115 + .write_begin = aufs_write_begin,
13116 + .write_end = aufs_write_end,
13117 + /* no bmap, no block device */
13118 + .invalidatepage = aufs_invalidatepage,
13119 + .releasepage = aufs_releasepage,
13120 + /* is fallback_migrate_page ok? */
13121 + /* .migratepage = aufs_migratepage, */
13122 + .isolate_page = aufs_isolate_page,
13123 + .putback_page = aufs_putback_page,
13124 + .launder_page = aufs_launder_page,
13125 + .is_partially_uptodate = aufs_is_partially_uptodate,
13126 + .is_dirty_writeback = aufs_is_dirty_writeback,
13127 + .error_remove_page = aufs_error_remove_page,
13128 + .swap_activate = aufs_swap_activate,
13129 + .swap_deactivate = aufs_swap_deactivate
13130 +#endif /* CONFIG_AUFS_DEBUG */
13132 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13133 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13134 +++ linux/fs/aufs/file.h 2017-03-02 14:24:13.860255635 +0100
13137 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13139 + * This program, aufs is free software; you can redistribute it and/or modify
13140 + * it under the terms of the GNU General Public License as published by
13141 + * the Free Software Foundation; either version 2 of the License, or
13142 + * (at your option) any later version.
13144 + * This program is distributed in the hope that it will be useful,
13145 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13146 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13147 + * GNU General Public License for more details.
13149 + * You should have received a copy of the GNU General Public License
13150 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13154 + * file operations
13157 +#ifndef __AUFS_FILE_H__
13158 +#define __AUFS_FILE_H__
13162 +#include <linux/file.h>
13163 +#include <linux/fs.h>
13164 +#include <linux/poll.h>
13165 +#include "rwsem.h"
13169 + struct file *hf_file;
13170 + struct au_branch *hf_br;
13175 + aufs_bindex_t fd_bbot;
13176 + aufs_bindex_t fd_nent;
13177 + struct au_vdir *fd_vdir_cache;
13178 + struct au_hfile fd_hfile[];
13181 +static inline int au_fidir_sz(int nent)
13183 + AuDebugOn(nent < 0);
13184 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13188 + atomic_t fi_generation;
13190 + struct au_rwsem fi_rwsem;
13191 + aufs_bindex_t fi_btop;
13193 + /* do not union them */
13194 + struct { /* for non-dir */
13195 + struct au_hfile fi_htop;
13196 + atomic_t fi_mmapped;
13198 + struct au_fidir *fi_hdir; /* for dir only */
13200 + struct hlist_node fi_hlist;
13202 + struct file *fi_file; /* very ugly */
13203 + struct llist_node fi_lnode; /* delayed free */
13205 +} ____cacheline_aligned_in_smp;
13207 +/* ---------------------------------------------------------------------- */
13210 +extern const struct address_space_operations aufs_aop;
13211 +unsigned int au_file_roflags(unsigned int flags);
13212 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13213 + struct file *file, int force_wr);
13214 +struct au_do_open_args {
13216 + int (*open)(struct file *file, int flags,
13217 + struct file *h_file);
13218 + struct au_fidir *fidir;
13219 + struct file *h_file;
13221 +int au_do_open(struct file *file, struct au_do_open_args *args);
13222 +int au_reopen_nondir(struct file *file);
13224 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13225 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13227 +int au_do_flush(struct file *file, fl_owner_t id,
13228 + int (*flush)(struct file *file, fl_owner_t id));
13231 +#ifdef CONFIG_AUFS_POLL
13232 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13235 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13237 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13239 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13240 + struct file *h_file);
13242 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13243 + aufs_bindex_t bindex, int force_wr)
13244 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13245 + struct file *h_file);
13249 +extern const struct file_operations aufs_file_fop;
13250 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13251 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13252 +struct file *au_read_pre(struct file *file, int keep_fi);
13255 +void au_hfput(struct au_hfile *hf, int execed);
13256 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13257 + struct file *h_file);
13259 +void au_update_figen(struct file *file);
13260 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13261 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13263 +void au_fi_init_once(void *_fi);
13264 +void au_finfo_fin(struct file *file, int atonce);
13265 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13268 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13269 +#ifdef CONFIG_COMPAT
13270 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13271 + unsigned long arg);
13272 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13273 + unsigned long arg);
13276 +/* ---------------------------------------------------------------------- */
13278 +static inline struct au_finfo *au_fi(struct file *file)
13280 + return file->private_data;
13283 +/* ---------------------------------------------------------------------- */
13286 + * fi_read_lock, fi_write_lock,
13287 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13289 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13291 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13292 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13293 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13295 +/* ---------------------------------------------------------------------- */
13297 +/* todo: hard/soft set? */
13298 +static inline aufs_bindex_t au_fbtop(struct file *file)
13300 + FiMustAnyLock(file);
13301 + return au_fi(file)->fi_btop;
13304 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13306 + FiMustAnyLock(file);
13307 + AuDebugOn(!au_fi(file)->fi_hdir);
13308 + return au_fi(file)->fi_hdir->fd_bbot;
13311 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13313 + FiMustAnyLock(file);
13314 + AuDebugOn(!au_fi(file)->fi_hdir);
13315 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13318 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13320 + FiMustWriteLock(file);
13321 + au_fi(file)->fi_btop = bindex;
13324 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13326 + FiMustWriteLock(file);
13327 + AuDebugOn(!au_fi(file)->fi_hdir);
13328 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13331 +static inline void au_set_fvdir_cache(struct file *file,
13332 + struct au_vdir *vdir_cache)
13334 + FiMustWriteLock(file);
13335 + AuDebugOn(!au_fi(file)->fi_hdir);
13336 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13339 +static inline struct file *au_hf_top(struct file *file)
13341 + FiMustAnyLock(file);
13342 + AuDebugOn(au_fi(file)->fi_hdir);
13343 + return au_fi(file)->fi_htop.hf_file;
13346 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13348 + FiMustAnyLock(file);
13349 + AuDebugOn(!au_fi(file)->fi_hdir);
13350 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13353 +/* todo: memory barrier? */
13354 +static inline unsigned int au_figen(struct file *f)
13356 + return atomic_read(&au_fi(f)->fi_generation);
13359 +static inline void au_set_mmapped(struct file *f)
13361 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13363 + pr_warn("fi_mmapped wrapped around\n");
13364 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13368 +static inline void au_unset_mmapped(struct file *f)
13370 + atomic_dec(&au_fi(f)->fi_mmapped);
13373 +static inline int au_test_mmapped(struct file *f)
13375 + return atomic_read(&au_fi(f)->fi_mmapped);
13378 +/* customize vma->vm_file */
13380 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13381 + struct file *file)
13385 + f = vma->vm_file;
13387 + vma->vm_file = file;
13392 +#define AuDbgVmRegion(file, vma) do {} while (0)
13394 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13395 + struct file *file)
13397 + au_do_vm_file_reset(vma, file);
13400 +#define AuDbgVmRegion(file, vma) \
13401 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13403 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13404 + struct file *file)
13408 + au_do_vm_file_reset(vma, file);
13409 + f = vma->vm_region->vm_file;
13411 + vma->vm_region->vm_file = file;
13414 +#endif /* CONFIG_MMU */
13416 +/* handle vma->vm_prfile */
13417 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13418 + struct file *file)
13421 + vma->vm_prfile = file;
13422 +#ifndef CONFIG_MMU
13424 + vma->vm_region->vm_prfile = file;
13428 +#endif /* __KERNEL__ */
13429 +#endif /* __AUFS_FILE_H__ */
13430 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13431 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13432 +++ linux/fs/aufs/finfo.c 2017-03-02 14:24:13.860255635 +0100
13435 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13437 + * This program, aufs is free software; you can redistribute it and/or modify
13438 + * it under the terms of the GNU General Public License as published by
13439 + * the Free Software Foundation; either version 2 of the License, or
13440 + * (at your option) any later version.
13442 + * This program is distributed in the hope that it will be useful,
13443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13445 + * GNU General Public License for more details.
13447 + * You should have received a copy of the GNU General Public License
13448 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13452 + * file private data
13457 +void au_hfput(struct au_hfile *hf, int execed)
13460 + allow_write_access(hf->hf_file);
13461 + fput(hf->hf_file);
13462 + hf->hf_file = NULL;
13463 + au_br_put(hf->hf_br);
13464 + hf->hf_br = NULL;
13467 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13469 + struct au_finfo *finfo = au_fi(file);
13470 + struct au_hfile *hf;
13471 + struct au_fidir *fidir;
13473 + fidir = finfo->fi_hdir;
13475 + AuDebugOn(finfo->fi_btop != bindex);
13476 + hf = &finfo->fi_htop;
13478 + hf = fidir->fd_hfile + bindex;
13480 + if (hf && hf->hf_file)
13481 + au_hfput(hf, vfsub_file_execed(file));
13483 + FiMustWriteLock(file);
13484 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13485 + hf->hf_file = val;
13486 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13490 +void au_update_figen(struct file *file)
13492 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13493 + /* smp_mb(); */ /* atomic_set */
13496 +/* ---------------------------------------------------------------------- */
13498 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13500 + struct au_fidir *fidir;
13503 + nbr = au_sbbot(sb) + 1;
13505 + nbr = 2; /* initial allocate for 2 branches */
13506 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13508 + fidir->fd_bbot = -1;
13509 + fidir->fd_nent = nbr;
13515 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13518 + struct au_fidir *fidir, *p;
13520 + AuRwMustWriteLock(&finfo->fi_rwsem);
13521 + fidir = finfo->fi_hdir;
13522 + AuDebugOn(!fidir);
13525 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13526 + GFP_NOFS, may_shrink);
13528 + p->fd_nent = nbr;
13529 + finfo->fi_hdir = p;
13536 +/* ---------------------------------------------------------------------- */
13538 +void au_finfo_fin(struct file *file, int atonce)
13540 + struct au_finfo *finfo;
13542 + au_nfiles_dec(file->f_path.dentry->d_sb);
13544 + finfo = au_fi(file);
13545 + AuDebugOn(finfo->fi_hdir);
13546 + AuRwDestroy(&finfo->fi_rwsem);
13548 + au_cache_dfree_finfo(finfo);
13550 + au_cache_free_finfo(finfo);
13553 +void au_fi_init_once(void *_finfo)
13555 + struct au_finfo *finfo = _finfo;
13557 + au_rw_init(&finfo->fi_rwsem);
13560 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13563 + struct au_finfo *finfo;
13564 + struct dentry *dentry;
13567 + dentry = file->f_path.dentry;
13568 + finfo = au_cache_alloc_finfo();
13569 + if (unlikely(!finfo))
13573 + au_nfiles_inc(dentry->d_sb);
13574 + au_rw_write_lock(&finfo->fi_rwsem);
13575 + finfo->fi_btop = -1;
13576 + finfo->fi_hdir = fidir;
13577 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13578 + /* smp_mb(); */ /* atomic_set */
13580 + file->private_data = finfo;
13585 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13586 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13587 +++ linux/fs/aufs/f_op.c 2017-03-02 14:24:13.860255635 +0100
13590 + * Copyright (C) 2005-2017 Junjiro R. Okajima
13592 + * This program, aufs is free software; you can redistribute it and/or modify
13593 + * it under the terms of the GNU General Public License as published by
13594 + * the Free Software Foundation; either version 2 of the License, or
13595 + * (at your option) any later version.
13597 + * This program is distributed in the hope that it will be useful,
13598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13600 + * GNU General Public License for more details.
13602 + * You should have received a copy of the GNU General Public License
13603 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13607 + * file and vm operations
13610 +#include <linux/aio.h>
13611 +#include <linux/fs_stack.h>
13612 +#include <linux/mman.h>
13613 +#include <linux/security.h>
13616 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13619 + aufs_bindex_t bindex;
13620 + struct dentry *dentry, *h_dentry;
13621 + struct au_finfo *finfo;
13622 + struct inode *h_inode;
13624 + FiMustWriteLock(file);
13627 + dentry = file->f_path.dentry;
13628 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13629 + finfo = au_fi(file);
13630 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13631 + atomic_set(&finfo->fi_mmapped, 0);
13632 + bindex = au_dbtop(dentry);
13634 + h_dentry = au_h_dptr(dentry, bindex);
13635 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13636 + if (unlikely(err))
13638 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13640 + h_dentry = h_file->f_path.dentry;
13641 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13642 + if (unlikely(err))
13644 + get_file(h_file);
13646 + if (IS_ERR(h_file))
13647 + err = PTR_ERR(h_file);
13649 + if ((flags & __O_TMPFILE)
13650 + && !(flags & O_EXCL)) {
13651 + h_inode = file_inode(h_file);
13652 + spin_lock(&h_inode->i_lock);
13653 + h_inode->i_state |= I_LINKABLE;
13654 + spin_unlock(&h_inode->i_lock);
13656 + au_set_fbtop(file, bindex);
13657 + au_set_h_fptr(file, bindex, h_file);
13658 + au_update_figen(file);
13659 + /* todo: necessary? */
13660 + /* file->f_ra = h_file->f_ra; */
13667 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13668 + struct file *file)
13671 + struct super_block *sb;
13672 + struct au_do_open_args args = {
13673 + .open = au_do_open_nondir
13676 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13677 + file, vfsub_file_flags(file), file->f_mode);
13679 + sb = file->f_path.dentry->d_sb;
13680 + si_read_lock(sb, AuLock_FLUSH);
13681 + err = au_do_open(file, &args);
13682 + si_read_unlock(sb);
13686 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13688 + struct au_finfo *finfo;
13689 + aufs_bindex_t bindex;
13692 + finfo = au_fi(file);
13693 + au_sphl_del(&finfo->fi_hlist,
13694 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13695 + bindex = finfo->fi_btop;
13697 + au_set_h_fptr(file, bindex, NULL);
13699 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
13700 + au_finfo_fin(file, delayed);
13704 +/* ---------------------------------------------------------------------- */
13706 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13709 + struct file *h_file;
13712 + h_file = au_hf_top(file);
13714 + err = vfsub_flush(h_file, id);
13718 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13720 + return au_do_flush(file, id, au_do_flush_nondir);
13723 +/* ---------------------------------------------------------------------- */
13725 + * read and write functions acquire [fdi]_rwsem once, but release before
13726 + * mmap_sem. This is because to stop a race condition between mmap(2).
13727 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13728 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13729 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13732 +/* Callers should call au_read_post() or fput() in the end */
13733 +struct file *au_read_pre(struct file *file, int keep_fi)
13735 + struct file *h_file;
13738 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13740 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13741 + h_file = au_hf_top(file);
13742 + get_file(h_file);
13744 + fi_read_unlock(file);
13746 + h_file = ERR_PTR(err);
13751 +static void au_read_post(struct inode *inode, struct file *h_file)
13753 + /* update without lock, I don't think it a problem */
13754 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13758 +struct au_write_pre {
13760 + aufs_bindex_t btop;
13764 + * return with iinfo is write-locked
13765 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13768 +static struct file *au_write_pre(struct file *file, int do_ready,
13769 + struct au_write_pre *wpre)
13771 + struct file *h_file;
13772 + struct dentry *dentry;
13774 + struct au_pin pin;
13776 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13777 + h_file = ERR_PTR(err);
13778 + if (unlikely(err))
13781 + dentry = file->f_path.dentry;
13783 + err = au_ready_to_write(file, -1, &pin);
13784 + if (unlikely(err)) {
13785 + h_file = ERR_PTR(err);
13786 + di_write_unlock(dentry);
13791 + di_downgrade_lock(dentry, /*flags*/0);
13793 + wpre->btop = au_fbtop(file);
13794 + h_file = au_hf_top(file);
13795 + get_file(h_file);
13797 + wpre->blks = file_inode(h_file)->i_blocks;
13800 + di_read_unlock(dentry, /*flags*/0);
13803 + fi_write_unlock(file);
13808 +static void au_write_post(struct inode *inode, struct file *h_file,
13809 + struct au_write_pre *wpre, ssize_t written)
13811 + struct inode *h_inode;
13813 + au_cpup_attr_timesizes(inode);
13814 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13815 + h_inode = file_inode(h_file);
13816 + inode->i_mode = h_inode->i_mode;
13817 + ii_write_unlock(inode);
13820 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13822 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13823 + /*force*/h_inode->i_blocks > wpre->blks);
13826 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13830 + struct inode *inode;
13831 + struct file *h_file;
13832 + struct super_block *sb;
13834 + inode = file_inode(file);
13835 + sb = inode->i_sb;
13836 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13838 + h_file = au_read_pre(file, /*keep_fi*/0);
13839 + err = PTR_ERR(h_file);
13840 + if (IS_ERR(h_file))
13843 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13844 + err = vfsub_read_u(h_file, buf, count, ppos);
13845 + /* todo: necessary? */
13846 + /* file->f_ra = h_file->f_ra; */
13847 + au_read_post(inode, h_file);
13850 + si_read_unlock(sb);
13855 + * todo: very ugly
13856 + * it locks both of i_mutex and si_rwsem for read in safe.
13857 + * if the plink maintenance mode continues forever (that is the problem),
13858 + * may loop forever.
13860 +static void au_mtx_and_read_lock(struct inode *inode)
13863 + struct super_block *sb = inode->i_sb;
13866 + inode_lock(inode);
13867 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13870 + inode_unlock(inode);
13871 + si_read_lock(sb, AuLock_NOPLMW);
13872 + si_read_unlock(sb);
13876 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13877 + size_t count, loff_t *ppos)
13880 + struct au_write_pre wpre;
13881 + struct inode *inode;
13882 + struct file *h_file;
13883 + char __user *buf = (char __user *)ubuf;
13885 + inode = file_inode(file);
13886 + au_mtx_and_read_lock(inode);
13888 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13889 + err = PTR_ERR(h_file);
13890 + if (IS_ERR(h_file))
13893 + err = vfsub_write_u(h_file, buf, count, ppos);
13894 + au_write_post(inode, h_file, &wpre, err);
13897 + si_read_unlock(inode->i_sb);
13898 + inode_unlock(inode);
13902 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13903 + struct iov_iter *iov_iter)
13906 + struct file *file;
13907 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13909 + err = security_file_permission(h_file, rw);
13910 + if (unlikely(err))
13915 + if (rw == MAY_READ)
13916 + iter = h_file->f_op->read_iter;
13917 + else if (rw == MAY_WRITE)
13918 + iter = h_file->f_op->write_iter;
13920 + file = kio->ki_filp;
13921 + kio->ki_filp = h_file;
13924 + err = iter(kio, iov_iter);
13927 + /* currently there is no such fs */
13929 + kio->ki_filp = file;
13935 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13938 + struct file *file, *h_file;
13939 + struct inode *inode;
13940 + struct super_block *sb;
13942 + file = kio->ki_filp;
13943 + inode = file_inode(file);
13944 + sb = inode->i_sb;
13945 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13947 + h_file = au_read_pre(file, /*keep_fi*/1);
13948 + err = PTR_ERR(h_file);
13949 + if (IS_ERR(h_file))
13952 + if (au_test_loopback_kthread()) {
13953 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13954 + if (file->f_mapping != h_file->f_mapping) {
13955 + file->f_mapping = h_file->f_mapping;
13956 + smp_mb(); /* unnecessary? */
13959 + fi_read_unlock(file);
13961 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13962 + /* todo: necessary? */
13963 + /* file->f_ra = h_file->f_ra; */
13964 + au_read_post(inode, h_file);
13967 + si_read_unlock(sb);
13971 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13974 + struct au_write_pre wpre;
13975 + struct inode *inode;
13976 + struct file *file, *h_file;
13978 + file = kio->ki_filp;
13979 + inode = file_inode(file);
13980 + au_mtx_and_read_lock(inode);
13982 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13983 + err = PTR_ERR(h_file);
13984 + if (IS_ERR(h_file))
13987 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13988 + au_write_post(inode, h_file, &wpre, err);
13991 + si_read_unlock(inode->i_sb);
13992 + inode_unlock(inode);
13996 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13997 + struct pipe_inode_info *pipe, size_t len,
13998 + unsigned int flags)
14001 + struct file *h_file;
14002 + struct inode *inode;
14003 + struct super_block *sb;
14005 + inode = file_inode(file);
14006 + sb = inode->i_sb;
14007 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14009 + h_file = au_read_pre(file, /*keep_fi*/0);
14010 + err = PTR_ERR(h_file);
14011 + if (IS_ERR(h_file))
14014 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14015 + /* todo: necessasry? */
14016 + /* file->f_ra = h_file->f_ra; */
14017 + au_read_post(inode, h_file);
14020 + si_read_unlock(sb);
14025 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14026 + size_t len, unsigned int flags)
14029 + struct au_write_pre wpre;
14030 + struct inode *inode;
14031 + struct file *h_file;
14033 + inode = file_inode(file);
14034 + au_mtx_and_read_lock(inode);
14036 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14037 + err = PTR_ERR(h_file);
14038 + if (IS_ERR(h_file))
14041 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14042 + au_write_post(inode, h_file, &wpre, err);
14045 + si_read_unlock(inode->i_sb);
14046 + inode_unlock(inode);
14050 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14054 + struct au_write_pre wpre;
14055 + struct inode *inode;
14056 + struct file *h_file;
14058 + inode = file_inode(file);
14059 + au_mtx_and_read_lock(inode);
14061 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14062 + err = PTR_ERR(h_file);
14063 + if (IS_ERR(h_file))
14067 + err = vfs_fallocate(h_file, mode, offset, len);
14069 + au_write_post(inode, h_file, &wpre, /*written*/1);
14072 + si_read_unlock(inode->i_sb);
14073 + inode_unlock(inode);
14077 +/* ---------------------------------------------------------------------- */
14080 + * The locking order around current->mmap_sem.
14081 + * - in most and regular cases
14082 + * file I/O syscall -- aufs_read() or something
14083 + * -- si_rwsem for read -- mmap_sem
14084 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14086 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14087 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14088 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14089 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14090 + * It means that when aufs acquires si_rwsem for write, the process should never
14091 + * acquire mmap_sem.
14093 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14094 + * problem either since any directory is not able to be mmap-ed.
14095 + * The similar scenario is applied to aufs_readlink() too.
14098 +#if 0 /* stop calling security_file_mmap() */
14099 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14100 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14102 +static unsigned long au_arch_prot_conv(unsigned long flags)
14104 + /* currently ppc64 only */
14105 +#ifdef CONFIG_PPC64
14106 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14107 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14108 + return AuConv_VM_PROT(flags, SAO);
14110 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14115 +static unsigned long au_prot_conv(unsigned long flags)
14117 + return AuConv_VM_PROT(flags, READ)
14118 + | AuConv_VM_PROT(flags, WRITE)
14119 + | AuConv_VM_PROT(flags, EXEC)
14120 + | au_arch_prot_conv(flags);
14123 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14124 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14126 +static unsigned long au_flag_conv(unsigned long flags)
14128 + return AuConv_VM_MAP(flags, GROWSDOWN)
14129 + | AuConv_VM_MAP(flags, DENYWRITE)
14130 + | AuConv_VM_MAP(flags, LOCKED);
14134 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14137 + const unsigned char wlock
14138 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14139 + struct super_block *sb;
14140 + struct file *h_file;
14141 + struct inode *inode;
14143 + AuDbgVmRegion(file, vma);
14145 + inode = file_inode(file);
14146 + sb = inode->i_sb;
14148 + si_read_lock(sb, AuLock_NOPLMW);
14150 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14152 + err = PTR_ERR(h_file);
14153 + if (IS_ERR(h_file))
14157 + au_set_mmapped(file);
14158 + au_vm_file_reset(vma, h_file);
14160 + * we cannot call security_mmap_file() here since it may acquire
14161 + * mmap_sem or i_mutex.
14163 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14164 + * au_flag_conv(vma->vm_flags));
14167 + err = h_file->f_op->mmap(h_file, vma);
14169 + au_vm_prfile_set(vma, file);
14170 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14171 + goto out_fput; /* success */
14173 + au_unset_mmapped(file);
14174 + au_vm_file_reset(vma, file);
14178 + ii_write_unlock(inode);
14183 + si_read_unlock(sb);
14189 +/* ---------------------------------------------------------------------- */
14191 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14195 + struct au_write_pre wpre;
14196 + struct inode *inode;
14197 + struct file *h_file;
14199 + err = 0; /* -EBADF; */ /* posix? */
14200 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14203 + inode = file_inode(file);
14204 + au_mtx_and_read_lock(inode);
14206 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14207 + err = PTR_ERR(h_file);
14208 + if (IS_ERR(h_file))
14211 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14212 + au_write_post(inode, h_file, &wpre, /*written*/0);
14215 + si_read_unlock(inode->i_sb);
14216 + inode_unlock(inode);
14221 +static int aufs_fasync(int fd, struct file *file, int flag)
14224 + struct file *h_file;
14225 + struct super_block *sb;
14227 + sb = file->f_path.dentry->d_sb;
14228 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14230 + h_file = au_read_pre(file, /*keep_fi*/0);
14231 + err = PTR_ERR(h_file);
14232 + if (IS_ERR(h_file))
14235 + if (h_file->f_op->fasync)
14236 + err = h_file->f_op->fasync(fd, h_file, flag);
14237 + fput(h_file); /* instead of au_read_post() */
14240 + si_read_unlock(sb);
14244 +static int aufs_setfl(struct file *file, unsigned long arg)
14247 + struct file *h_file;
14248 + struct super_block *sb;
14250 + sb = file->f_path.dentry->d_sb;
14251 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14253 + h_file = au_read_pre(file, /*keep_fi*/0);
14254 + err = PTR_ERR(h_file);
14255 + if (IS_ERR(h_file))
14258 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14259 + err = setfl(/*unused fd*/-1, h_file, arg);
14260 + fput(h_file); /* instead of au_read_post() */
14263 + si_read_unlock(sb);
14267 +/* ---------------------------------------------------------------------- */
14269 +/* no one supports this operation, currently */
14271 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14272 + size_t len, loff_t *pos, int more)
14277 +/* ---------------------------------------------------------------------- */
14279 +const struct file_operations aufs_file_fop = {
14280 + .owner = THIS_MODULE,
14282 + .llseek = default_llseek,
14284 + .read = aufs_read,
14285 + .write = aufs_write,
14286 + .read_iter = aufs_read_iter,
14287 + .write_iter = aufs_write_iter,
14289 +#ifdef CONFIG_AUFS_POLL
14290 + .poll = aufs_poll,
14292 + .unlocked_ioctl = aufs_ioctl_nondir,
14293 +#ifdef CONFIG_COMPAT
14294 + .compat_ioctl = aufs_compat_ioctl_nondir,
14296 + .mmap = aufs_mmap,
14297 + .open = aufs_open_nondir,
14298 + .flush = aufs_flush_nondir,
14299 + .release = aufs_release_nondir,
14300 + .fsync = aufs_fsync_nondir,
14301 + .fasync = aufs_fasync,
14302 + /* .sendpage = aufs_sendpage, */
14303 + .setfl = aufs_setfl,
14304 + .splice_write = aufs_splice_write,
14305 + .splice_read = aufs_splice_read,
14307 + .aio_splice_write = aufs_aio_splice_write,
14308 + .aio_splice_read = aufs_aio_splice_read,
14310 + .fallocate = aufs_fallocate
14312 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14313 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14314 +++ linux/fs/aufs/fstype.h 2017-03-02 14:24:13.860255635 +0100
14317 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14319 + * This program, aufs is free software; you can redistribute it and/or modify
14320 + * it under the terms of the GNU General Public License as published by
14321 + * the Free Software Foundation; either version 2 of the License, or
14322 + * (at your option) any later version.
14324 + * This program is distributed in the hope that it will be useful,
14325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14327 + * GNU General Public License for more details.
14329 + * You should have received a copy of the GNU General Public License
14330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14334 + * judging filesystem type
14337 +#ifndef __AUFS_FSTYPE_H__
14338 +#define __AUFS_FSTYPE_H__
14342 +#include <linux/fs.h>
14343 +#include <linux/magic.h>
14344 +#include <linux/nfs_fs.h>
14345 +#include <linux/romfs_fs.h>
14347 +static inline int au_test_aufs(struct super_block *sb)
14349 + return sb->s_magic == AUFS_SUPER_MAGIC;
14352 +static inline const char *au_sbtype(struct super_block *sb)
14354 + return sb->s_type->name;
14357 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14359 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14360 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14366 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14368 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14369 + return sb->s_magic == ROMFS_MAGIC;
14375 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14377 +#if IS_ENABLED(CONFIG_CRAMFS)
14378 + return sb->s_magic == CRAMFS_MAGIC;
14383 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14385 +#if IS_ENABLED(CONFIG_NFS_FS)
14386 + return sb->s_magic == NFS_SUPER_MAGIC;
14392 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14394 +#if IS_ENABLED(CONFIG_FUSE_FS)
14395 + return sb->s_magic == FUSE_SUPER_MAGIC;
14401 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14403 +#if IS_ENABLED(CONFIG_XFS_FS)
14404 + return sb->s_magic == XFS_SB_MAGIC;
14410 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14412 +#ifdef CONFIG_TMPFS
14413 + return sb->s_magic == TMPFS_MAGIC;
14419 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14421 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14422 + return !strcmp(au_sbtype(sb), "ecryptfs");
14428 +static inline int au_test_ramfs(struct super_block *sb)
14430 + return sb->s_magic == RAMFS_MAGIC;
14433 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14435 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14436 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14442 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14444 +#ifdef CONFIG_PROC_FS
14445 + return sb->s_magic == PROC_SUPER_MAGIC;
14451 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14453 +#ifdef CONFIG_SYSFS
14454 + return sb->s_magic == SYSFS_MAGIC;
14460 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14462 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14463 + return sb->s_magic == CONFIGFS_MAGIC;
14469 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14471 +#if IS_ENABLED(CONFIG_MINIX_FS)
14472 + return sb->s_magic == MINIX3_SUPER_MAGIC
14473 + || sb->s_magic == MINIX2_SUPER_MAGIC
14474 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14475 + || sb->s_magic == MINIX_SUPER_MAGIC
14476 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14482 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14484 +#if IS_ENABLED(CONFIG_FAT_FS)
14485 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14491 +static inline int au_test_msdos(struct super_block *sb)
14493 + return au_test_fat(sb);
14496 +static inline int au_test_vfat(struct super_block *sb)
14498 + return au_test_fat(sb);
14501 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14503 +#ifdef CONFIG_SECURITYFS
14504 + return sb->s_magic == SECURITYFS_MAGIC;
14510 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14512 +#if IS_ENABLED(CONFIG_SQUASHFS)
14513 + return sb->s_magic == SQUASHFS_MAGIC;
14519 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14521 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14522 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14528 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14530 +#if IS_ENABLED(CONFIG_XENFS)
14531 + return sb->s_magic == XENFS_SUPER_MAGIC;
14537 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14539 +#ifdef CONFIG_DEBUG_FS
14540 + return sb->s_magic == DEBUGFS_MAGIC;
14546 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14548 +#if IS_ENABLED(CONFIG_NILFS)
14549 + return sb->s_magic == NILFS_SUPER_MAGIC;
14555 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14557 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14558 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14564 +/* ---------------------------------------------------------------------- */
14566 + * they can't be an aufs branch.
14568 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14571 +#ifndef CONFIG_AUFS_BR_RAMFS
14572 + au_test_ramfs(sb) ||
14574 + au_test_procfs(sb)
14575 + || au_test_sysfs(sb)
14576 + || au_test_configfs(sb)
14577 + || au_test_debugfs(sb)
14578 + || au_test_securityfs(sb)
14579 + || au_test_xenfs(sb)
14580 + || au_test_ecryptfs(sb)
14581 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14582 + || au_test_aufs(sb); /* will be supported in next version */
14585 +static inline int au_test_fs_remote(struct super_block *sb)
14587 + return !au_test_tmpfs(sb)
14588 +#ifdef CONFIG_AUFS_BR_RAMFS
14589 + && !au_test_ramfs(sb)
14591 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14594 +/* ---------------------------------------------------------------------- */
14597 + * Note: these functions (below) are created after reading ->getattr() in all
14598 + * filesystems under linux/fs. it means we have to do so in every update...
14602 + * some filesystems require getattr to refresh the inode attributes before
14604 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14605 + * and leave the work for d_revalidate()
14607 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14609 + return au_test_nfs(sb)
14610 + || au_test_fuse(sb)
14611 + /* || au_test_btrfs(sb) */ /* untested */
14616 + * filesystems which don't maintain i_size or i_blocks.
14618 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14620 + return au_test_xfs(sb)
14621 + || au_test_btrfs(sb)
14622 + || au_test_ubifs(sb)
14623 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14624 + /* || au_test_minix(sb) */ /* untested */
14629 + * filesystems which don't store the correct value in some of their inode
14632 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14634 + return au_test_fs_bad_iattr_size(sb)
14635 + || au_test_fat(sb)
14636 + || au_test_msdos(sb)
14637 + || au_test_vfat(sb);
14640 +/* they don't check i_nlink in link(2) */
14641 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14643 + return au_test_tmpfs(sb)
14644 +#ifdef CONFIG_AUFS_BR_RAMFS
14645 + || au_test_ramfs(sb)
14647 + || au_test_ubifs(sb)
14648 + || au_test_hfsplus(sb);
14652 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14654 +static inline int au_test_fs_notime(struct super_block *sb)
14656 + return au_test_nfs(sb)
14657 + || au_test_fuse(sb)
14658 + || au_test_ubifs(sb)
14662 +/* temporary support for i#1 in cramfs */
14663 +static inline int au_test_fs_unique_ino(struct inode *inode)
14665 + if (au_test_cramfs(inode->i_sb))
14666 + return inode->i_ino != 1;
14670 +/* ---------------------------------------------------------------------- */
14673 + * the filesystem where the xino files placed must support i/o after unlink and
14674 + * maintain i_size and i_blocks.
14676 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14678 + return au_test_fs_remote(sb)
14679 + || au_test_fs_bad_iattr_size(sb)
14680 + /* don't want unnecessary work for xino */
14681 + || au_test_aufs(sb)
14682 + || au_test_ecryptfs(sb)
14683 + || au_test_nilfs(sb);
14686 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14688 + return au_test_tmpfs(sb)
14689 + || au_test_ramfs(sb);
14693 + * test if the @sb is real-readonly.
14695 +static inline int au_test_fs_rr(struct super_block *sb)
14697 + return au_test_squashfs(sb)
14698 + || au_test_iso9660(sb)
14699 + || au_test_cramfs(sb)
14700 + || au_test_romfs(sb);
14704 + * test if the @inode is nfs with 'noacl' option
14705 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14707 +static inline int au_test_nfs_noacl(struct inode *inode)
14709 + return au_test_nfs(inode->i_sb)
14710 + /* && IS_POSIXACL(inode) */
14711 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14714 +#endif /* __KERNEL__ */
14715 +#endif /* __AUFS_FSTYPE_H__ */
14716 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14717 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14718 +++ linux/fs/aufs/hfsnotify.c 2017-03-02 14:24:13.860255635 +0100
14721 + * Copyright (C) 2005-2017 Junjiro R. Okajima
14723 + * This program, aufs is free software; you can redistribute it and/or modify
14724 + * it under the terms of the GNU General Public License as published by
14725 + * the Free Software Foundation; either version 2 of the License, or
14726 + * (at your option) any later version.
14728 + * This program is distributed in the hope that it will be useful,
14729 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14730 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14731 + * GNU General Public License for more details.
14733 + * You should have received a copy of the GNU General Public License
14734 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14738 + * fsnotify for the lower directories
14743 +/* FS_IN_IGNORED is unnecessary */
14744 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14745 + | FS_CREATE | FS_EVENT_ON_CHILD);
14746 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14747 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14749 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14751 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14753 + /* AuDbg("here\n"); */
14754 + au_cache_dfree_hnotify(hn);
14755 + smp_mb__before_atomic();
14756 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14757 + wake_up(&au_hfsn_wq);
14760 +static int au_hfsn_alloc(struct au_hinode *hinode)
14763 + struct au_hnotify *hn;
14764 + struct super_block *sb;
14765 + struct au_branch *br;
14766 + struct fsnotify_mark *mark;
14767 + aufs_bindex_t bindex;
14769 + hn = hinode->hi_notify;
14770 + sb = hn->hn_aufs_inode->i_sb;
14771 + bindex = au_br_index(sb, hinode->hi_id);
14772 + br = au_sbr(sb, bindex);
14773 + AuDebugOn(!br->br_hfsn);
14775 + mark = &hn->hn_mark;
14776 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14777 + mark->mask = AuHfsnMask;
14779 + * by udba rename or rmdir, aufs assign a new inode to the known
14780 + * h_inode, so specify 1 to allow dups.
14783 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14784 + /*mnt*/NULL, /*allow_dups*/1);
14790 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14792 + struct fsnotify_mark *mark;
14793 + unsigned long long ull;
14794 + struct fsnotify_group *group;
14796 + ull = atomic64_inc_return(&au_hfsn_ifree);
14799 + mark = &hn->hn_mark;
14800 + spin_lock(&mark->lock);
14801 + group = mark->group;
14802 + fsnotify_get_group(group);
14803 + spin_unlock(&mark->lock);
14805 + fsnotify_destroy_mark(mark, group);
14806 + fsnotify_put_mark(mark);
14807 + fsnotify_put_group(group);
14810 + /* free hn by myself */
14814 +/* ---------------------------------------------------------------------- */
14816 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14818 + struct fsnotify_mark *mark;
14820 + mark = &hinode->hi_notify->hn_mark;
14821 + spin_lock(&mark->lock);
14823 + AuDebugOn(mark->mask & AuHfsnMask);
14824 + mark->mask |= AuHfsnMask;
14826 + AuDebugOn(!(mark->mask & AuHfsnMask));
14827 + mark->mask &= ~AuHfsnMask;
14829 + spin_unlock(&mark->lock);
14830 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14833 +/* ---------------------------------------------------------------------- */
14835 +/* #define AuDbgHnotify */
14836 +#ifdef AuDbgHnotify
14837 +static char *au_hfsn_name(u32 mask)
14839 +#ifdef CONFIG_AUFS_DEBUG
14840 +#define test_ret(flag) \
14842 + if (mask & flag) \
14845 + test_ret(FS_ACCESS);
14846 + test_ret(FS_MODIFY);
14847 + test_ret(FS_ATTRIB);
14848 + test_ret(FS_CLOSE_WRITE);
14849 + test_ret(FS_CLOSE_NOWRITE);
14850 + test_ret(FS_OPEN);
14851 + test_ret(FS_MOVED_FROM);
14852 + test_ret(FS_MOVED_TO);
14853 + test_ret(FS_CREATE);
14854 + test_ret(FS_DELETE);
14855 + test_ret(FS_DELETE_SELF);
14856 + test_ret(FS_MOVE_SELF);
14857 + test_ret(FS_UNMOUNT);
14858 + test_ret(FS_Q_OVERFLOW);
14859 + test_ret(FS_IN_IGNORED);
14860 + test_ret(FS_ISDIR);
14861 + test_ret(FS_IN_ONESHOT);
14862 + test_ret(FS_EVENT_ON_CHILD);
14871 +/* ---------------------------------------------------------------------- */
14873 +static void au_hfsn_free_group(struct fsnotify_group *group)
14875 + struct au_br_hfsnotify *hfsn = group->private;
14877 + /* AuDbg("here\n"); */
14878 + au_delayed_kfree(hfsn);
14881 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14882 + struct inode *inode,
14883 + struct fsnotify_mark *inode_mark,
14884 + struct fsnotify_mark *vfsmount_mark,
14885 + u32 mask, const void *data, int data_type,
14886 + const unsigned char *file_name, u32 cookie)
14889 + struct au_hnotify *hnotify;
14890 + struct inode *h_dir, *h_inode;
14891 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14893 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14896 + /* if FS_UNMOUNT happens, there must be another bug */
14897 + AuDebugOn(mask & FS_UNMOUNT);
14898 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14903 +#ifdef AuDbgHnotify
14905 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14906 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14907 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14908 + h_dir->i_ino, mask, au_hfsn_name(mask),
14909 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14910 + /* WARN_ON(1); */
14915 + AuDebugOn(!inode_mark);
14916 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14917 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14923 +static struct fsnotify_ops au_hfsn_ops = {
14924 + .handle_event = au_hfsn_handle_event,
14925 + .free_group_priv = au_hfsn_free_group
14928 +/* ---------------------------------------------------------------------- */
14930 +static void au_hfsn_fin_br(struct au_branch *br)
14932 + struct au_br_hfsnotify *hfsn;
14934 + hfsn = br->br_hfsn;
14937 + fsnotify_put_group(hfsn->hfsn_group);
14942 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14945 + struct fsnotify_group *group;
14946 + struct au_br_hfsnotify *hfsn;
14949 + br->br_hfsn = NULL;
14950 + if (!au_br_hnotifyable(perm))
14954 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14955 + if (unlikely(!hfsn))
14959 + group = fsnotify_alloc_group(&au_hfsn_ops);
14960 + if (IS_ERR(group)) {
14961 + err = PTR_ERR(group);
14962 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14966 + group->private = hfsn;
14967 + hfsn->hfsn_group = group;
14968 + br->br_hfsn = hfsn;
14969 + goto out; /* success */
14972 + au_delayed_kfree(hfsn);
14977 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14982 + if (!br->br_hfsn)
14983 + err = au_hfsn_init_br(br, perm);
14988 +/* ---------------------------------------------------------------------- */
14990 +static void au_hfsn_fin(void)
14992 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14993 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14996 +const struct au_hnotify_op au_hnotify_op = {
14997 + .ctl = au_hfsn_ctl,
14998 + .alloc = au_hfsn_alloc,
14999 + .free = au_hfsn_free,
15001 + .fin = au_hfsn_fin,
15003 + .reset_br = au_hfsn_reset_br,
15004 + .fin_br = au_hfsn_fin_br,
15005 + .init_br = au_hfsn_init_br
15007 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15008 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15009 +++ linux/fs/aufs/hfsplus.c 2017-03-02 14:24:13.860255635 +0100
15012 + * Copyright (C) 2010-2017 Junjiro R. Okajima
15014 + * This program, aufs is free software; you can redistribute it and/or modify
15015 + * it under the terms of the GNU General Public License as published by
15016 + * the Free Software Foundation; either version 2 of the License, or
15017 + * (at your option) any later version.
15019 + * This program is distributed in the hope that it will be useful,
15020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15022 + * GNU General Public License for more details.
15024 + * You should have received a copy of the GNU General Public License
15025 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15029 + * special support for filesystems which aqucires an inode mutex
15030 + * at final closing a file, eg, hfsplus.
15032 + * This trick is very simple and stupid, just to open the file before really
15033 + * neceeary open to tell hfsplus that this is not the final closing.
15034 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15035 + * and au_h_open_post() after releasing it.
15040 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15043 + struct file *h_file;
15044 + struct dentry *h_dentry;
15046 + h_dentry = au_h_dptr(dentry, bindex);
15047 + AuDebugOn(!h_dentry);
15048 + AuDebugOn(d_is_negative(h_dentry));
15051 + if (au_test_hfsplus(h_dentry->d_sb)
15052 + && d_is_reg(h_dentry))
15053 + h_file = au_h_open(dentry, bindex,
15054 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15055 + /*file*/NULL, force_wr);
15059 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15060 + struct file *h_file)
15064 + au_sbr_put(dentry->d_sb, bindex);
15067 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15068 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15069 +++ linux/fs/aufs/hnotify.c 2017-03-02 14:24:13.860255635 +0100
15072 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15074 + * This program, aufs is free software; you can redistribute it and/or modify
15075 + * it under the terms of the GNU General Public License as published by
15076 + * the Free Software Foundation; either version 2 of the License, or
15077 + * (at your option) any later version.
15079 + * This program is distributed in the hope that it will be useful,
15080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15082 + * GNU General Public License for more details.
15084 + * You should have received a copy of the GNU General Public License
15085 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15089 + * abstraction to notify the direct changes on lower directories
15094 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15097 + struct au_hnotify *hn;
15100 + hn = au_cache_alloc_hnotify();
15102 + hn->hn_aufs_inode = inode;
15103 + hinode->hi_notify = hn;
15104 + err = au_hnotify_op.alloc(hinode);
15106 + if (unlikely(err)) {
15107 + hinode->hi_notify = NULL;
15108 + au_cache_dfree_hnotify(hn);
15110 + * The upper dir was removed by udba, but the same named
15111 + * dir left. In this case, aufs assignes a new inode
15112 + * number and set the monitor again.
15113 + * For the lower dir, the old monitnor is still left.
15115 + if (err == -EEXIST)
15124 +void au_hn_free(struct au_hinode *hinode)
15126 + struct au_hnotify *hn;
15128 + hn = hinode->hi_notify;
15130 + hinode->hi_notify = NULL;
15131 + if (au_hnotify_op.free(hinode, hn))
15132 + au_cache_dfree_hnotify(hn);
15136 +/* ---------------------------------------------------------------------- */
15138 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15140 + if (hinode->hi_notify)
15141 + au_hnotify_op.ctl(hinode, do_set);
15144 +void au_hn_reset(struct inode *inode, unsigned int flags)
15146 + aufs_bindex_t bindex, bbot;
15147 + struct inode *hi;
15148 + struct dentry *iwhdentry;
15150 + bbot = au_ibbot(inode);
15151 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15152 + hi = au_h_iptr(inode, bindex);
15156 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15157 + iwhdentry = au_hi_wh(inode, bindex);
15161 + au_set_h_iptr(inode, bindex, NULL, 0);
15162 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15163 + flags & ~AuHi_XINO);
15166 + /* inode_unlock(hi); */
15170 +/* ---------------------------------------------------------------------- */
15172 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15175 + aufs_bindex_t bindex, bbot, bfound, btop;
15176 + struct inode *h_i;
15179 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15180 + pr_warn("branch root dir was changed\n");
15185 + bbot = au_ibbot(inode);
15186 + btop = au_ibtop(inode);
15187 +#if 0 /* reserved for future use */
15188 + if (bindex == bbot) {
15189 + /* keep this ino in rename case */
15193 + for (bindex = btop; bindex <= bbot; bindex++)
15194 + if (au_h_iptr(inode, bindex) == h_inode) {
15201 + for (bindex = btop; bindex <= bbot; bindex++) {
15202 + h_i = au_h_iptr(inode, bindex);
15206 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15207 + /* ignore this error */
15208 + /* bad action? */
15211 + /* children inode number will be broken */
15218 +static int hn_gen_tree(struct dentry *dentry)
15220 + int err, i, j, ndentry;
15221 + struct au_dcsub_pages dpages;
15222 + struct au_dpage *dpage;
15223 + struct dentry **dentries;
15225 + err = au_dpages_init(&dpages, GFP_NOFS);
15226 + if (unlikely(err))
15228 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15229 + if (unlikely(err))
15232 + for (i = 0; i < dpages.ndpage; i++) {
15233 + dpage = dpages.dpages + i;
15234 + dentries = dpage->dentries;
15235 + ndentry = dpage->ndentry;
15236 + for (j = 0; j < ndentry; j++) {
15237 + struct dentry *d;
15244 + if (d_really_is_positive(d))
15245 + /* todo: reset children xino?
15246 + cached children only? */
15247 + au_iigen_dec(d_inode(d));
15252 + au_dpages_free(&dpages);
15255 + /* discard children */
15256 + dentry_unhash(dentry);
15264 + * return 0 if processed.
15266 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15267 + const unsigned int isdir)
15270 + struct dentry *d;
15271 + struct qstr *dname;
15274 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15275 + pr_warn("branch root dir was changed\n");
15281 + AuDebugOn(!name);
15282 + au_iigen_dec(inode);
15283 + spin_lock(&inode->i_lock);
15284 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15285 + spin_lock(&d->d_lock);
15286 + dname = &d->d_name;
15287 + if (dname->len != nlen
15288 + && memcmp(dname->name, name, nlen)) {
15289 + spin_unlock(&d->d_lock);
15294 + spin_unlock(&d->d_lock);
15297 + spin_unlock(&inode->i_lock);
15299 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15300 + d = d_find_any_alias(inode);
15302 + au_iigen_dec(inode);
15306 + spin_lock(&d->d_lock);
15307 + dname = &d->d_name;
15308 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15309 + spin_unlock(&d->d_lock);
15310 + err = hn_gen_tree(d);
15311 + spin_lock(&d->d_lock);
15313 + spin_unlock(&d->d_lock);
15322 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15326 + if (IS_ROOT(dentry)) {
15327 + pr_warn("branch root dir was changed\n");
15333 + au_digen_dec(dentry);
15334 + if (d_really_is_positive(dentry))
15335 + au_iigen_dec(d_inode(dentry));
15337 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15338 + if (d_really_is_positive(dentry))
15339 + err = hn_gen_tree(dentry);
15346 +/* ---------------------------------------------------------------------- */
15348 +/* hnotify job flags */
15349 +#define AuHnJob_XINO0 1
15350 +#define AuHnJob_GEN (1 << 1)
15351 +#define AuHnJob_DIRENT (1 << 2)
15352 +#define AuHnJob_ISDIR (1 << 3)
15353 +#define AuHnJob_TRYXINO0 (1 << 4)
15354 +#define AuHnJob_MNTPNT (1 << 5)
15355 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15356 +#define au_fset_hnjob(flags, name) \
15357 + do { (flags) |= AuHnJob_##name; } while (0)
15358 +#define au_fclr_hnjob(flags, name) \
15359 + do { (flags) &= ~AuHnJob_##name; } while (0)
15367 +struct au_hnotify_args {
15368 + struct inode *h_dir, *dir, *h_child_inode;
15370 + unsigned int flags[AuHnLast];
15371 + unsigned int h_child_nlen;
15372 + char h_child_name[];
15375 +struct hn_job_args {
15376 + unsigned int flags;
15377 + struct inode *inode, *h_inode, *dir, *h_dir;
15378 + struct dentry *dentry;
15383 +static int hn_job(struct hn_job_args *a)
15385 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15389 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15390 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15392 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15395 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15396 + if (!a->h_inode->i_nlink
15397 + && !(a->h_inode->i_state & I_LINKABLE))
15398 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15399 + inode_unlock(a->h_inode);
15402 + /* make the generation obsolete */
15403 + if (au_ftest_hnjob(a->flags, GEN)) {
15406 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15408 + if (e && a->dentry)
15409 + hn_gen_by_name(a->dentry, isdir);
15410 + /* ignore this error */
15413 + /* make dir entries obsolete */
15414 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15415 + struct au_vdir *vdir;
15417 + vdir = au_ivdir(a->inode);
15419 + vdir->vd_jiffy = 0;
15420 + /* IMustLock(a->inode); */
15421 + /* a->inode->i_version++; */
15424 + /* can do nothing but warn */
15425 + if (au_ftest_hnjob(a->flags, MNTPNT)
15427 + && d_mountpoint(a->dentry))
15428 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15433 +/* ---------------------------------------------------------------------- */
15435 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15436 + struct inode *dir)
15438 + struct dentry *dentry, *d, *parent;
15439 + struct qstr *dname;
15441 + parent = d_find_any_alias(dir);
15446 + spin_lock(&parent->d_lock);
15447 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15448 + /* AuDbg("%pd\n", d); */
15449 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15450 + dname = &d->d_name;
15451 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15452 + goto cont_unlock;
15456 + goto cont_unlock;
15457 + if (au_dcount(d) > 0) {
15458 + dentry = dget_dlock(d);
15459 + spin_unlock(&d->d_lock);
15464 + spin_unlock(&d->d_lock);
15466 + spin_unlock(&parent->d_lock);
15470 + di_write_lock_child(dentry);
15475 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15476 + aufs_bindex_t bindex, ino_t h_ino)
15478 + struct inode *inode;
15483 + err = au_xino_read(sb, bindex, h_ino, &ino);
15485 + inode = ilookup(sb, ino);
15489 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15490 + pr_warn("wrong root branch\n");
15496 + ii_write_lock_child(inode);
15502 +static void au_hn_bh(void *_args)
15504 + struct au_hnotify_args *a = _args;
15505 + struct super_block *sb;
15506 + aufs_bindex_t bindex, bbot, bfound;
15507 + unsigned char xino, try_iput;
15509 + struct inode *inode;
15511 + struct hn_job_args args;
15512 + struct dentry *dentry;
15513 + struct au_sbinfo *sbinfo;
15515 + AuDebugOn(!_args);
15516 + AuDebugOn(!a->h_dir);
15517 + AuDebugOn(!a->dir);
15518 + AuDebugOn(!a->mask);
15519 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15520 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15521 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15526 + * do not lock a->dir->i_mutex here
15527 + * because of d_revalidate() may cause a deadlock.
15529 + sb = a->dir->i_sb;
15531 + sbinfo = au_sbi(sb);
15532 + AuDebugOn(!sbinfo);
15533 + si_write_lock(sb, AuLock_NOPLMW);
15535 + ii_read_lock_parent(a->dir);
15537 + bbot = au_ibbot(a->dir);
15538 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15539 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15543 + ii_read_unlock(a->dir);
15544 + if (unlikely(bfound < 0))
15547 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15549 + if (a->h_child_inode)
15550 + h_ino = a->h_child_inode->i_ino;
15552 + if (a->h_child_nlen
15553 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15554 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15555 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15558 + if (dentry && d_really_is_positive(dentry))
15559 + inode = d_inode(dentry);
15560 + if (xino && !inode && h_ino
15561 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15562 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15563 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15564 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15568 + args.flags = a->flags[AuHn_CHILD];
15569 + args.dentry = dentry;
15570 + args.inode = inode;
15571 + args.h_inode = a->h_child_inode;
15572 + args.dir = a->dir;
15573 + args.h_dir = a->h_dir;
15574 + args.h_name = a->h_child_name;
15575 + args.h_nlen = a->h_child_nlen;
15576 + err = hn_job(&args);
15578 + if (au_di(dentry))
15579 + di_write_unlock(dentry);
15582 + if (inode && try_iput) {
15583 + ii_write_unlock(inode);
15587 + ii_write_lock_parent(a->dir);
15588 + args.flags = a->flags[AuHn_PARENT];
15589 + args.dentry = NULL;
15590 + args.inode = a->dir;
15591 + args.h_inode = a->h_dir;
15593 + args.h_dir = NULL;
15594 + args.h_name = NULL;
15596 + err = hn_job(&args);
15597 + ii_write_unlock(a->dir);
15600 + iput(a->h_child_inode);
15603 + si_write_unlock(sb);
15604 + au_nwt_done(&sbinfo->si_nowait);
15605 + au_delayed_kfree(a);
15608 +/* ---------------------------------------------------------------------- */
15610 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15611 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15614 + unsigned int flags[AuHnLast], f;
15615 + unsigned char isdir, isroot, wh;
15616 + struct inode *dir;
15617 + struct au_hnotify_args *args;
15618 + char *p, *h_child_name;
15621 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15622 + dir = igrab(hnotify->hn_aufs_inode);
15626 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15628 + h_child_name = (void *)h_child_qstr->name;
15629 + len = h_child_qstr->len;
15630 + if (h_child_name) {
15631 + if (len > AUFS_WH_PFX_LEN
15632 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15633 + h_child_name += AUFS_WH_PFX_LEN;
15634 + len -= AUFS_WH_PFX_LEN;
15640 + if (h_child_inode)
15641 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15642 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15643 + flags[AuHn_CHILD] = 0;
15645 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15646 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15647 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15648 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15649 + case FS_MOVED_FROM:
15650 + case FS_MOVED_TO:
15651 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15652 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15655 + AuDebugOn(!h_child_name);
15660 + * aufs never be able to get this child inode.
15661 + * revalidation should be in d_revalidate()
15662 + * by checking i_nlink, i_generation or d_unhashed().
15664 + AuDebugOn(!h_child_name);
15665 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15666 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15674 + h_child_inode = NULL;
15677 + /* iput() and kfree() will be called in au_hnotify() */
15678 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15679 + if (unlikely(!args)) {
15680 + AuErr1("no memory\n");
15684 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15685 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15686 + args->mask = mask;
15688 + args->h_dir = igrab(h_dir);
15689 + if (h_child_inode)
15690 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15691 + args->h_child_inode = h_child_inode;
15692 + args->h_child_nlen = len;
15694 + p = (void *)args;
15695 + p += sizeof(*args);
15696 + memcpy(p, h_child_name, len);
15700 + /* NFS fires the event for silly-renamed one from kworker */
15702 + if (!dir->i_nlink
15703 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15705 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15706 + if (unlikely(err)) {
15707 + pr_err("wkq %d\n", err);
15708 + iput(args->h_child_inode);
15709 + iput(args->h_dir);
15711 + au_delayed_kfree(args);
15718 +/* ---------------------------------------------------------------------- */
15720 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15724 + AuDebugOn(!(udba & AuOptMask_UDBA));
15727 + if (au_hnotify_op.reset_br)
15728 + err = au_hnotify_op.reset_br(udba, br, perm);
15733 +int au_hnotify_init_br(struct au_branch *br, int perm)
15738 + if (au_hnotify_op.init_br)
15739 + err = au_hnotify_op.init_br(br, perm);
15744 +void au_hnotify_fin_br(struct au_branch *br)
15746 + if (au_hnotify_op.fin_br)
15747 + au_hnotify_op.fin_br(br);
15750 +static void au_hn_destroy_cache(void)
15752 + struct au_cache *cp;
15754 + flush_delayed_work(&au_dfree.dwork);
15755 + cp = au_dfree.cache + AuCache_HNOTIFY;
15756 + AuDebugOn(!llist_empty(&cp->llist));
15757 + kmem_cache_destroy(cp->cache);
15758 + cp->cache = NULL;
15761 +AU_CACHE_DFREE_FUNC(hnotify, HNOTIFY, hn_lnode);
15763 +int __init au_hnotify_init(void)
15766 + struct au_cache *cp;
15769 + cp = au_dfree.cache + AuCache_HNOTIFY;
15770 + cp->cache = AuCache(au_hnotify);
15773 + if (au_hnotify_op.init)
15774 + err = au_hnotify_op.init();
15775 + if (unlikely(err))
15776 + au_hn_destroy_cache();
15782 +void au_hnotify_fin(void)
15784 + struct au_cache *cp;
15786 + if (au_hnotify_op.fin)
15787 + au_hnotify_op.fin();
15789 + /* cf. au_cache_fin() */
15790 + cp = au_dfree.cache + AuCache_HNOTIFY;
15792 + au_hn_destroy_cache();
15794 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15795 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15796 +++ linux/fs/aufs/iinfo.c 2017-03-02 14:24:13.863589061 +0100
15799 + * Copyright (C) 2005-2017 Junjiro R. Okajima
15801 + * This program, aufs is free software; you can redistribute it and/or modify
15802 + * it under the terms of the GNU General Public License as published by
15803 + * the Free Software Foundation; either version 2 of the License, or
15804 + * (at your option) any later version.
15806 + * This program is distributed in the hope that it will be useful,
15807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15809 + * GNU General Public License for more details.
15811 + * You should have received a copy of the GNU General Public License
15812 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15816 + * inode private data
15821 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15823 + struct inode *h_inode;
15824 + struct au_hinode *hinode;
15826 + IiMustAnyLock(inode);
15828 + hinode = au_hinode(au_ii(inode), bindex);
15829 + h_inode = hinode->hi_inode;
15830 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15834 +/* todo: hard/soft set? */
15835 +void au_hiput(struct au_hinode *hinode)
15837 + au_hn_free(hinode);
15838 + dput(hinode->hi_whdentry);
15839 + iput(hinode->hi_inode);
15842 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15844 + unsigned int flags;
15845 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15848 + if (au_opt_test(mnt_flags, XINO))
15849 + au_fset_hi(flags, XINO);
15850 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15851 + au_fset_hi(flags, HNOTIFY);
15855 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15856 + struct inode *h_inode, unsigned int flags)
15858 + struct au_hinode *hinode;
15859 + struct inode *hi;
15860 + struct au_iinfo *iinfo = au_ii(inode);
15862 + IiMustWriteLock(inode);
15864 + hinode = au_hinode(iinfo, bindex);
15865 + hi = hinode->hi_inode;
15866 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15869 + au_hiput(hinode);
15870 + hinode->hi_inode = h_inode;
15873 + struct super_block *sb = inode->i_sb;
15874 + struct au_branch *br;
15876 + AuDebugOn(inode->i_mode
15877 + && (h_inode->i_mode & S_IFMT)
15878 + != (inode->i_mode & S_IFMT));
15879 + if (bindex == iinfo->ii_btop)
15880 + au_cpup_igen(inode, h_inode);
15881 + br = au_sbr(sb, bindex);
15882 + hinode->hi_id = br->br_id;
15883 + if (au_ftest_hi(flags, XINO)) {
15884 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15886 + if (unlikely(err))
15887 + AuIOErr1("failed au_xino_write() %d\n", err);
15890 + if (au_ftest_hi(flags, HNOTIFY)
15891 + && au_br_hnotifyable(br->br_perm)) {
15892 + err = au_hn_alloc(hinode, inode);
15893 + if (unlikely(err))
15894 + AuIOErr1("au_hn_alloc() %d\n", err);
15899 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15900 + struct dentry *h_wh)
15902 + struct au_hinode *hinode;
15904 + IiMustWriteLock(inode);
15906 + hinode = au_hinode(au_ii(inode), bindex);
15907 + AuDebugOn(hinode->hi_whdentry);
15908 + hinode->hi_whdentry = h_wh;
15911 +void au_update_iigen(struct inode *inode, int half)
15913 + struct au_iinfo *iinfo;
15914 + struct au_iigen *iigen;
15915 + unsigned int sigen;
15917 + sigen = au_sigen(inode->i_sb);
15918 + iinfo = au_ii(inode);
15919 + iigen = &iinfo->ii_generation;
15920 + spin_lock(&iigen->ig_spin);
15921 + iigen->ig_generation = sigen;
15923 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15925 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15926 + spin_unlock(&iigen->ig_spin);
15929 +/* it may be called at remount time, too */
15930 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15932 + struct au_iinfo *iinfo;
15933 + aufs_bindex_t bindex, bbot;
15935 + AuDebugOn(au_is_bad_inode(inode));
15936 + IiMustWriteLock(inode);
15938 + iinfo = au_ii(inode);
15939 + if (do_put_zero && iinfo->ii_btop >= 0) {
15940 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
15942 + struct inode *h_i;
15944 + h_i = au_hinode(iinfo, bindex)->hi_inode;
15947 + && !(h_i->i_state & I_LINKABLE))
15948 + au_set_h_iptr(inode, bindex, NULL, 0);
15952 + iinfo->ii_btop = -1;
15953 + iinfo->ii_bbot = -1;
15954 + bbot = au_sbbot(inode->i_sb);
15955 + for (bindex = 0; bindex <= bbot; bindex++)
15956 + if (au_hinode(iinfo, bindex)->hi_inode) {
15957 + iinfo->ii_btop = bindex;
15960 + if (iinfo->ii_btop >= 0)
15961 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
15962 + if (au_hinode(iinfo, bindex)->hi_inode) {
15963 + iinfo->ii_bbot = bindex;
15966 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
15969 +/* ---------------------------------------------------------------------- */
15971 +void au_icntnr_init_once(void *_c)
15973 + struct au_icntnr *c = _c;
15974 + struct au_iinfo *iinfo = &c->iinfo;
15976 + spin_lock_init(&iinfo->ii_generation.ig_spin);
15977 + au_rw_init(&iinfo->ii_rwsem);
15978 + inode_init_once(&c->vfs_inode);
15981 +void au_hinode_init(struct au_hinode *hinode)
15983 + hinode->hi_inode = NULL;
15984 + hinode->hi_id = -1;
15985 + au_hn_init(hinode);
15986 + hinode->hi_whdentry = NULL;
15989 +int au_iinfo_init(struct inode *inode)
15991 + struct au_iinfo *iinfo;
15992 + struct super_block *sb;
15993 + struct au_hinode *hi;
15996 + sb = inode->i_sb;
15997 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15998 + nbr = au_sbbot(sb) + 1;
15999 + if (unlikely(nbr <= 0))
16001 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
16003 + au_ninodes_inc(sb);
16005 + iinfo->ii_hinode = hi;
16006 + for (i = 0; i < nbr; i++, hi++)
16007 + au_hinode_init(hi);
16009 + iinfo->ii_generation.ig_generation = au_sigen(sb);
16010 + iinfo->ii_btop = -1;
16011 + iinfo->ii_bbot = -1;
16012 + iinfo->ii_vdir = NULL;
16018 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16021 + struct au_hinode *hip;
16023 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16026 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16029 + iinfo->ii_hinode = hip;
16030 + i = iinfo->ii_bbot + 1;
16032 + for (; i < nbr; i++, hip++)
16033 + au_hinode_init(hip);
16040 +void au_iinfo_fin(struct inode *inode)
16042 + struct au_iinfo *iinfo;
16043 + struct au_hinode *hi;
16044 + struct super_block *sb;
16045 + aufs_bindex_t bindex, bbot;
16046 + const unsigned char unlinked = !inode->i_nlink;
16048 + AuDebugOn(au_is_bad_inode(inode));
16050 + sb = inode->i_sb;
16051 + au_ninodes_dec(sb);
16052 + if (si_pid_test(sb))
16053 + au_xino_delete_inode(inode, unlinked);
16056 + * it is safe to hide the dependency between sbinfo and
16060 + si_noflush_read_lock(sb);
16061 + au_xino_delete_inode(inode, unlinked);
16062 + si_read_unlock(sb);
16066 + iinfo = au_ii(inode);
16067 + if (iinfo->ii_vdir)
16068 + au_vdir_free(iinfo->ii_vdir, /*atonce*/0);
16070 + bindex = iinfo->ii_btop;
16071 + if (bindex >= 0) {
16072 + hi = au_hinode(iinfo, bindex);
16073 + bbot = iinfo->ii_bbot;
16074 + while (bindex++ <= bbot) {
16075 + if (hi->hi_inode)
16080 + au_delayed_kfree(iinfo->ii_hinode);
16081 + AuRwDestroy(&iinfo->ii_rwsem);
16083 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16084 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16085 +++ linux/fs/aufs/inode.c 2017-03-02 14:24:13.863589061 +0100
16088 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16090 + * This program, aufs is free software; you can redistribute it and/or modify
16091 + * it under the terms of the GNU General Public License as published by
16092 + * the Free Software Foundation; either version 2 of the License, or
16093 + * (at your option) any later version.
16095 + * This program is distributed in the hope that it will be useful,
16096 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16097 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16098 + * GNU General Public License for more details.
16100 + * You should have received a copy of the GNU General Public License
16101 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16105 + * inode functions
16110 +struct inode *au_igrab(struct inode *inode)
16113 + AuDebugOn(!atomic_read(&inode->i_count));
16119 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16121 + au_cpup_attr_all(inode, /*force*/0);
16122 + au_update_iigen(inode, /*half*/1);
16124 + inode->i_version++;
16127 +static int au_ii_refresh(struct inode *inode, int *update)
16131 + aufs_bindex_t bindex, new_bindex;
16132 + struct super_block *sb;
16133 + struct au_iinfo *iinfo;
16134 + struct au_hinode *p, *q, tmp;
16136 + AuDebugOn(au_is_bad_inode(inode));
16137 + IiMustWriteLock(inode);
16140 + sb = inode->i_sb;
16141 + nbr = au_sbbot(sb) + 1;
16142 + type = inode->i_mode & S_IFMT;
16143 + iinfo = au_ii(inode);
16144 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16145 + if (unlikely(err))
16148 + AuDebugOn(iinfo->ii_btop < 0);
16149 + p = au_hinode(iinfo, iinfo->ii_btop);
16150 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16152 + if (!p->hi_inode)
16155 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16156 + new_bindex = au_br_index(sb, p->hi_id);
16157 + if (new_bindex == bindex)
16160 + if (new_bindex < 0) {
16163 + p->hi_inode = NULL;
16167 + if (new_bindex < iinfo->ii_btop)
16168 + iinfo->ii_btop = new_bindex;
16169 + if (iinfo->ii_bbot < new_bindex)
16170 + iinfo->ii_bbot = new_bindex;
16171 + /* swap two lower inode, and loop again */
16172 + q = au_hinode(iinfo, new_bindex);
16176 + if (tmp.hi_inode) {
16181 + au_update_ibrange(inode, /*do_put_zero*/0);
16182 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16183 + e = au_dy_irefresh(inode);
16184 + if (unlikely(e && !err))
16192 +void au_refresh_iop(struct inode *inode, int force_getattr)
16195 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16196 + const struct inode_operations *iop
16197 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16199 + if (inode->i_op == iop)
16202 + switch (inode->i_mode & S_IFMT) {
16204 + type = AuIop_DIR;
16207 + type = AuIop_SYMLINK;
16210 + type = AuIop_OTHER;
16214 + inode->i_op = iop + type;
16215 + /* unnecessary smp_wmb() */
16218 +int au_refresh_hinode_self(struct inode *inode)
16222 + err = au_ii_refresh(inode, &update);
16224 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16230 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16232 + int err, e, update;
16233 + unsigned int flags;
16235 + aufs_bindex_t bindex, bbot;
16236 + unsigned char isdir;
16237 + struct au_hinode *p;
16238 + struct au_iinfo *iinfo;
16240 + err = au_ii_refresh(inode, &update);
16241 + if (unlikely(err))
16245 + iinfo = au_ii(inode);
16246 + p = au_hinode(iinfo, iinfo->ii_btop);
16247 + mode = (inode->i_mode & S_IFMT);
16248 + isdir = S_ISDIR(mode);
16249 + flags = au_hi_flags(inode, isdir);
16250 + bbot = au_dbbot(dentry);
16251 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16252 + struct inode *h_i, *h_inode;
16253 + struct dentry *h_d;
16255 + h_d = au_h_dptr(dentry, bindex);
16256 + if (!h_d || d_is_negative(h_d))
16259 + h_inode = d_inode(h_d);
16260 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16261 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16262 + h_i = au_h_iptr(inode, bindex);
16264 + if (h_i == h_inode)
16270 + if (bindex < iinfo->ii_btop)
16271 + iinfo->ii_btop = bindex;
16272 + if (iinfo->ii_bbot < bindex)
16273 + iinfo->ii_bbot = bindex;
16274 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16277 + au_update_ibrange(inode, /*do_put_zero*/0);
16278 + e = au_dy_irefresh(inode);
16279 + if (unlikely(e && !err))
16282 + au_refresh_hinode_attr(inode, update && isdir);
16289 +static int set_inode(struct inode *inode, struct dentry *dentry)
16292 + unsigned int flags;
16294 + aufs_bindex_t bindex, btop, btail;
16295 + unsigned char isdir;
16296 + struct dentry *h_dentry;
16297 + struct inode *h_inode;
16298 + struct au_iinfo *iinfo;
16299 + struct inode_operations *iop;
16301 + IiMustWriteLock(inode);
16305 + iop = au_sbi(inode->i_sb)->si_iop_array;
16306 + btop = au_dbtop(dentry);
16307 + h_dentry = au_h_dptr(dentry, btop);
16308 + h_inode = d_inode(h_dentry);
16309 + mode = h_inode->i_mode;
16310 + switch (mode & S_IFMT) {
16312 + btail = au_dbtail(dentry);
16313 + inode->i_op = iop + AuIop_OTHER;
16314 + inode->i_fop = &aufs_file_fop;
16315 + err = au_dy_iaop(inode, btop, h_inode);
16316 + if (unlikely(err))
16321 + btail = au_dbtaildir(dentry);
16322 + inode->i_op = iop + AuIop_DIR;
16323 + inode->i_fop = &aufs_dir_fop;
16326 + btail = au_dbtail(dentry);
16327 + inode->i_op = iop + AuIop_SYMLINK;
16333 + btail = au_dbtail(dentry);
16334 + inode->i_op = iop + AuIop_OTHER;
16335 + init_special_inode(inode, mode, h_inode->i_rdev);
16338 + AuIOErr("Unknown file type 0%o\n", mode);
16343 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16344 + flags = au_hi_flags(inode, isdir);
16345 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16346 + && au_ftest_hi(flags, HNOTIFY)
16347 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16348 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16349 + au_fclr_hi(flags, HNOTIFY);
16350 + iinfo = au_ii(inode);
16351 + iinfo->ii_btop = btop;
16352 + iinfo->ii_bbot = btail;
16353 + for (bindex = btop; bindex <= btail; bindex++) {
16354 + h_dentry = au_h_dptr(dentry, bindex);
16356 + au_set_h_iptr(inode, bindex,
16357 + au_igrab(d_inode(h_dentry)), flags);
16359 + au_cpup_attr_all(inode, /*force*/1);
16361 + * to force calling aufs_get_acl() every time,
16362 + * do not call cache_no_acl() for aufs inode.
16370 + * successful returns with iinfo write_locked
16372 + * zero: success, matched
16373 + * plus: no error, but unmatched
16375 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16378 + unsigned int gen, igflags;
16379 + aufs_bindex_t bindex, bbot;
16380 + struct inode *h_inode, *h_dinode;
16381 + struct dentry *h_dentry;
16384 + * before this function, if aufs got any iinfo lock, it must be only
16385 + * one, the parent dir.
16386 + * it can happen by UDBA and the obsoleted inode number.
16389 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16393 + ii_write_lock_new_child(inode);
16394 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16395 + h_dinode = d_inode(h_dentry);
16396 + bbot = au_ibbot(inode);
16397 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16398 + h_inode = au_h_iptr(inode, bindex);
16399 + if (!h_inode || h_inode != h_dinode)
16403 + gen = au_iigen(inode, &igflags);
16404 + if (gen == au_digen(dentry)
16405 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16408 + /* fully refresh inode using dentry */
16409 + err = au_refresh_hinode(inode, dentry);
16411 + au_update_iigen(inode, /*half*/0);
16415 + if (unlikely(err))
16416 + ii_write_unlock(inode);
16421 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16422 + unsigned int d_type, ino_t *ino)
16425 + struct mutex *mtx;
16427 + /* prevent hardlinked inode number from race condition */
16429 + if (d_type != DT_DIR) {
16430 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16433 + err = au_xino_read(sb, bindex, h_ino, ino);
16434 + if (unlikely(err))
16439 + *ino = au_xino_new_ino(sb);
16440 + if (unlikely(!*ino))
16442 + err = au_xino_write(sb, bindex, h_ino, *ino);
16443 + if (unlikely(err))
16449 + mutex_unlock(mtx);
16453 +/* successful returns with iinfo write_locked */
16454 +/* todo: return with unlocked? */
16455 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16457 + struct inode *inode, *h_inode;
16458 + struct dentry *h_dentry;
16459 + struct super_block *sb;
16460 + struct mutex *mtx;
16461 + ino_t h_ino, ino;
16463 + aufs_bindex_t btop;
16465 + sb = dentry->d_sb;
16466 + btop = au_dbtop(dentry);
16467 + h_dentry = au_h_dptr(dentry, btop);
16468 + h_inode = d_inode(h_dentry);
16469 + h_ino = h_inode->i_ino;
16472 + * stop 'race'-ing between hardlinks under different
16476 + if (!d_is_dir(h_dentry))
16477 + mtx = &au_sbr(sb, btop)->br_xino.xi_nondir_mtx;
16482 + err = au_xino_read(sb, btop, h_ino, &ino);
16483 + inode = ERR_PTR(err);
16484 + if (unlikely(err))
16488 + ino = au_xino_new_ino(sb);
16489 + if (unlikely(!ino)) {
16490 + inode = ERR_PTR(-EIO);
16495 + AuDbg("i%lu\n", (unsigned long)ino);
16496 + inode = au_iget_locked(sb, ino);
16497 + err = PTR_ERR(inode);
16498 + if (IS_ERR(inode))
16501 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16502 + if (inode->i_state & I_NEW) {
16503 + ii_write_lock_new_child(inode);
16504 + err = set_inode(inode, dentry);
16506 + unlock_new_inode(inode);
16507 + goto out; /* success */
16511 + * iget_failed() calls iput(), but we need to call
16512 + * ii_write_unlock() after iget_failed(). so dirty hack for
16515 + atomic_inc(&inode->i_count);
16516 + iget_failed(inode);
16517 + ii_write_unlock(inode);
16518 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16519 + /* ignore this error */
16521 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16523 + * horrible race condition between lookup, readdir and copyup
16524 + * (or something).
16527 + mutex_unlock(mtx);
16528 + err = reval_inode(inode, dentry);
16529 + if (unlikely(err < 0)) {
16536 + goto out; /* success */
16541 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16542 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16543 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16544 + btop, au_sbtype(h_dentry->d_sb), dentry,
16545 + (unsigned long)h_ino, (unsigned long)ino);
16547 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16551 + mutex_unlock(mtx);
16557 + inode = ERR_PTR(err);
16560 + mutex_unlock(mtx);
16564 +/* ---------------------------------------------------------------------- */
16566 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16567 + struct inode *inode)
16570 + struct inode *hi;
16572 + err = au_br_rdonly(au_sbr(sb, bindex));
16574 + /* pseudo-link after flushed may happen out of bounds */
16577 + && au_ibtop(inode) <= bindex
16578 + && bindex <= au_ibbot(inode)) {
16580 + * permission check is unnecessary since vfsub routine
16581 + * will be called later
16583 + hi = au_h_iptr(inode, bindex);
16585 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16591 +int au_test_h_perm(struct inode *h_inode, int mask)
16593 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16595 + return inode_permission(h_inode, mask);
16598 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16600 + if (au_test_nfs(h_inode->i_sb)
16601 + && (mask & MAY_WRITE)
16602 + && S_ISDIR(h_inode->i_mode))
16603 + mask |= MAY_READ; /* force permission check */
16604 + return au_test_h_perm(h_inode, mask);
16606 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16607 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16608 +++ linux/fs/aufs/inode.h 2017-03-02 14:24:13.863589061 +0100
16611 + * Copyright (C) 2005-2017 Junjiro R. Okajima
16613 + * This program, aufs is free software; you can redistribute it and/or modify
16614 + * it under the terms of the GNU General Public License as published by
16615 + * the Free Software Foundation; either version 2 of the License, or
16616 + * (at your option) any later version.
16618 + * This program is distributed in the hope that it will be useful,
16619 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16620 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16621 + * GNU General Public License for more details.
16623 + * You should have received a copy of the GNU General Public License
16624 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16628 + * inode operations
16631 +#ifndef __AUFS_INODE_H__
16632 +#define __AUFS_INODE_H__
16636 +#include <linux/fsnotify.h>
16637 +#include "rwsem.h"
16641 +struct au_hnotify {
16642 +#ifdef CONFIG_AUFS_HNOTIFY
16643 +#ifdef CONFIG_AUFS_HFSNOTIFY
16644 + /* never use fsnotify_add_vfsmount_mark() */
16645 + struct fsnotify_mark hn_mark;
16648 + struct inode *hn_aufs_inode; /* no get/put */
16649 + struct llist_node hn_lnode; /* delayed free */
16652 +} ____cacheline_aligned_in_smp;
16654 +struct au_hinode {
16655 + struct inode *hi_inode;
16656 + aufs_bindex_t hi_id;
16657 +#ifdef CONFIG_AUFS_HNOTIFY
16658 + struct au_hnotify *hi_notify;
16661 + /* reference to the copied-up whiteout with get/put */
16662 + struct dentry *hi_whdentry;
16666 +#define AuIG_HALF_REFRESHED 1
16667 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16668 +#define au_ig_fset(flags, name) \
16669 + do { (flags) |= AuIG_##name; } while (0)
16670 +#define au_ig_fclr(flags, name) \
16671 + do { (flags) &= ~AuIG_##name; } while (0)
16674 + spinlock_t ig_spin;
16675 + __u32 ig_generation, ig_flags;
16680 + struct au_iigen ii_generation;
16681 + struct super_block *ii_hsb1; /* no get/put */
16683 + struct au_rwsem ii_rwsem;
16684 + aufs_bindex_t ii_btop, ii_bbot;
16686 + struct au_hinode *ii_hinode;
16687 + struct au_vdir *ii_vdir;
16690 +struct au_icntnr {
16691 + struct au_iinfo iinfo;
16692 + struct inode vfs_inode;
16694 + struct hlist_node plink;
16695 + struct llist_node lnode; /* delayed free */
16697 +} ____cacheline_aligned_in_smp;
16699 +/* au_pin flags */
16700 +#define AuPin_DI_LOCKED 1
16701 +#define AuPin_MNT_WRITE (1 << 1)
16702 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16703 +#define au_fset_pin(flags, name) \
16704 + do { (flags) |= AuPin_##name; } while (0)
16705 +#define au_fclr_pin(flags, name) \
16706 + do { (flags) &= ~AuPin_##name; } while (0)
16710 + struct dentry *dentry;
16711 + unsigned int udba;
16712 + unsigned char lsc_di, lsc_hi, flags;
16713 + aufs_bindex_t bindex;
16716 + struct dentry *parent;
16717 + struct au_hinode *hdir;
16718 + struct vfsmount *h_mnt;
16720 + /* temporary unlock/relock for copyup */
16721 + struct dentry *h_dentry, *h_parent;
16722 + struct au_branch *br;
16723 + struct task_struct *task;
16726 +void au_pin_hdir_unlock(struct au_pin *p);
16727 +int au_pin_hdir_lock(struct au_pin *p);
16728 +int au_pin_hdir_relock(struct au_pin *p);
16729 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16730 +void au_pin_hdir_release(struct au_pin *p);
16732 +/* ---------------------------------------------------------------------- */
16734 +static inline struct au_iinfo *au_ii(struct inode *inode)
16736 + BUG_ON(is_bad_inode(inode));
16737 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16740 +/* ---------------------------------------------------------------------- */
16743 +struct inode *au_igrab(struct inode *inode);
16744 +void au_refresh_iop(struct inode *inode, int force_getattr);
16745 +int au_refresh_hinode_self(struct inode *inode);
16746 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16747 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16748 + unsigned int d_type, ino_t *ino);
16749 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16750 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16751 + struct inode *inode);
16752 +int au_test_h_perm(struct inode *h_inode, int mask);
16753 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16755 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16756 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16758 +#ifdef CONFIG_AUFS_SHWH
16759 + return au_ino(sb, bindex, h_ino, d_type, ino);
16772 +extern struct inode_operations aufs_iop[AuIop_Last],
16773 + aufs_iop_nogetattr[AuIop_Last];
16775 +/* au_wr_dir flags */
16776 +#define AuWrDir_ADD_ENTRY 1
16777 +#define AuWrDir_ISDIR (1 << 1)
16778 +#define AuWrDir_TMPFILE (1 << 2)
16779 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16780 +#define au_fset_wrdir(flags, name) \
16781 + do { (flags) |= AuWrDir_##name; } while (0)
16782 +#define au_fclr_wrdir(flags, name) \
16783 + do { (flags) &= ~AuWrDir_##name; } while (0)
16785 +struct au_wr_dir_args {
16786 + aufs_bindex_t force_btgt;
16787 + unsigned char flags;
16789 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16790 + struct au_wr_dir_args *args);
16792 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16793 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16794 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16795 + unsigned int udba, unsigned char flags);
16796 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16797 + unsigned int udba, unsigned char flags) __must_check;
16798 +int au_do_pin(struct au_pin *pin) __must_check;
16799 +void au_unpin(struct au_pin *pin);
16800 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16802 +#define AuIcpup_DID_CPUP 1
16803 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16804 +#define au_fset_icpup(flags, name) \
16805 + do { (flags) |= AuIcpup_##name; } while (0)
16806 +#define au_fclr_icpup(flags, name) \
16807 + do { (flags) &= ~AuIcpup_##name; } while (0)
16809 +struct au_icpup_args {
16810 + unsigned char flags;
16811 + unsigned char pin_flags;
16812 + aufs_bindex_t btgt;
16813 + unsigned int udba;
16814 + struct au_pin pin;
16815 + struct path h_path;
16816 + struct inode *h_inode;
16819 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16820 + struct au_icpup_args *a);
16822 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
16826 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16827 + struct dentry *h_parent, int isdir);
16828 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16830 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16831 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16833 +struct vfsub_aopen_args;
16834 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16835 + struct vfsub_aopen_args *args);
16836 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16837 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16838 + struct dentry *dentry);
16839 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16842 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16843 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16844 + struct dentry *h_parent, int isdir);
16845 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16846 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16849 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16850 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16851 + struct inode *dir, struct dentry *dentry,
16852 + unsigned int flags);
16855 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16856 +void au_hiput(struct au_hinode *hinode);
16857 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16858 + struct dentry *h_wh);
16859 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16861 +/* hinode flags */
16862 +#define AuHi_XINO 1
16863 +#define AuHi_HNOTIFY (1 << 1)
16864 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16865 +#define au_fset_hi(flags, name) \
16866 + do { (flags) |= AuHi_##name; } while (0)
16867 +#define au_fclr_hi(flags, name) \
16868 + do { (flags) &= ~AuHi_##name; } while (0)
16870 +#ifndef CONFIG_AUFS_HNOTIFY
16871 +#undef AuHi_HNOTIFY
16872 +#define AuHi_HNOTIFY 0
16875 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16876 + struct inode *h_inode, unsigned int flags);
16878 +void au_update_iigen(struct inode *inode, int half);
16879 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16881 +void au_icntnr_init_once(void *_c);
16882 +void au_hinode_init(struct au_hinode *hinode);
16883 +int au_iinfo_init(struct inode *inode);
16884 +void au_iinfo_fin(struct inode *inode);
16885 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
16887 +#ifdef CONFIG_PROC_FS
16889 +int au_plink_maint(struct super_block *sb, int flags);
16891 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16892 +int au_plink_maint_enter(struct super_block *sb);
16893 +#ifdef CONFIG_AUFS_DEBUG
16894 +void au_plink_list(struct super_block *sb);
16896 +AuStubVoid(au_plink_list, struct super_block *sb)
16898 +int au_plink_test(struct inode *inode);
16899 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16900 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16901 + struct dentry *h_dentry);
16902 +void au_plink_put(struct super_block *sb, int verbose);
16903 +void au_plink_clean(struct super_block *sb, int verbose);
16904 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16906 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16907 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16908 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16909 +AuStubVoid(au_plink_list, struct super_block *sb);
16910 +AuStubInt0(au_plink_test, struct inode *inode);
16911 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16912 + struct inode *inode, aufs_bindex_t bindex);
16913 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16914 + struct dentry *h_dentry);
16915 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16916 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16917 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16918 +#endif /* CONFIG_PROC_FS */
16920 +#ifdef CONFIG_AUFS_XATTR
16922 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16923 + unsigned int verbose);
16924 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16925 +void au_xattr_init(struct super_block *sb);
16927 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16928 + int ignore_flags, unsigned int verbose);
16929 +AuStubVoid(au_xattr_init, struct super_block *sb);
16932 +#ifdef CONFIG_FS_POSIX_ACL
16933 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16934 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16937 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16943 +struct au_sxattr {
16947 + const char *name;
16948 + const void *value;
16953 + struct posix_acl *acl;
16958 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
16959 + struct au_sxattr *arg);
16962 +/* ---------------------------------------------------------------------- */
16964 +/* lock subclass for iinfo */
16966 + AuLsc_II_CHILD, /* child first */
16967 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16968 + AuLsc_II_CHILD3, /* copyup dirs */
16969 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16970 + AuLsc_II_PARENT2,
16971 + AuLsc_II_PARENT3, /* copyup dirs */
16972 + AuLsc_II_NEW_CHILD
16976 + * ii_read_lock_child, ii_write_lock_child,
16977 + * ii_read_lock_child2, ii_write_lock_child2,
16978 + * ii_read_lock_child3, ii_write_lock_child3,
16979 + * ii_read_lock_parent, ii_write_lock_parent,
16980 + * ii_read_lock_parent2, ii_write_lock_parent2,
16981 + * ii_read_lock_parent3, ii_write_lock_parent3,
16982 + * ii_read_lock_new_child, ii_write_lock_new_child,
16984 +#define AuReadLockFunc(name, lsc) \
16985 +static inline void ii_read_lock_##name(struct inode *i) \
16987 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16990 +#define AuWriteLockFunc(name, lsc) \
16991 +static inline void ii_write_lock_##name(struct inode *i) \
16993 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16996 +#define AuRWLockFuncs(name, lsc) \
16997 + AuReadLockFunc(name, lsc) \
16998 + AuWriteLockFunc(name, lsc)
17000 +AuRWLockFuncs(child, CHILD);
17001 +AuRWLockFuncs(child2, CHILD2);
17002 +AuRWLockFuncs(child3, CHILD3);
17003 +AuRWLockFuncs(parent, PARENT);
17004 +AuRWLockFuncs(parent2, PARENT2);
17005 +AuRWLockFuncs(parent3, PARENT3);
17006 +AuRWLockFuncs(new_child, NEW_CHILD);
17008 +#undef AuReadLockFunc
17009 +#undef AuWriteLockFunc
17010 +#undef AuRWLockFuncs
17013 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17015 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17017 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17018 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17019 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17021 +/* ---------------------------------------------------------------------- */
17023 +static inline void au_icntnr_init(struct au_icntnr *c)
17025 +#ifdef CONFIG_AUFS_DEBUG
17026 + c->vfs_inode.i_mode = 0;
17030 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17032 + unsigned int gen;
17033 + struct au_iinfo *iinfo;
17034 + struct au_iigen *iigen;
17036 + iinfo = au_ii(inode);
17037 + iigen = &iinfo->ii_generation;
17038 + spin_lock(&iigen->ig_spin);
17040 + *igflags = iigen->ig_flags;
17041 + gen = iigen->ig_generation;
17042 + spin_unlock(&iigen->ig_spin);
17047 +/* tiny test for inode number */
17048 +/* tmpfs generation is too rough */
17049 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17051 + struct au_iinfo *iinfo;
17053 + iinfo = au_ii(inode);
17054 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17055 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17056 + && iinfo->ii_higen == h_inode->i_generation);
17059 +static inline void au_iigen_dec(struct inode *inode)
17061 + struct au_iinfo *iinfo;
17062 + struct au_iigen *iigen;
17064 + iinfo = au_ii(inode);
17065 + iigen = &iinfo->ii_generation;
17066 + spin_lock(&iigen->ig_spin);
17067 + iigen->ig_generation--;
17068 + spin_unlock(&iigen->ig_spin);
17071 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17076 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17082 +/* ---------------------------------------------------------------------- */
17084 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17085 + aufs_bindex_t bindex)
17087 + return iinfo->ii_hinode + bindex;
17090 +static inline int au_is_bad_inode(struct inode *inode)
17092 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17095 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17096 + aufs_bindex_t bindex)
17098 + IiMustAnyLock(inode);
17099 + return au_hinode(au_ii(inode), bindex)->hi_id;
17102 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17104 + IiMustAnyLock(inode);
17105 + return au_ii(inode)->ii_btop;
17108 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17110 + IiMustAnyLock(inode);
17111 + return au_ii(inode)->ii_bbot;
17114 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17116 + IiMustAnyLock(inode);
17117 + return au_ii(inode)->ii_vdir;
17120 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17122 + IiMustAnyLock(inode);
17123 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17126 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17128 + IiMustWriteLock(inode);
17129 + au_ii(inode)->ii_btop = bindex;
17132 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17134 + IiMustWriteLock(inode);
17135 + au_ii(inode)->ii_bbot = bindex;
17138 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17140 + IiMustWriteLock(inode);
17141 + au_ii(inode)->ii_vdir = vdir;
17144 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17146 + IiMustAnyLock(inode);
17147 + return au_hinode(au_ii(inode), bindex);
17150 +/* ---------------------------------------------------------------------- */
17152 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17155 + return pin->parent;
17159 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17161 + if (pin && pin->hdir)
17162 + return pin->hdir->hi_inode;
17166 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17169 + return pin->hdir;
17173 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17176 + pin->dentry = dentry;
17179 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17180 + unsigned char lflag)
17184 + au_fset_pin(pin->flags, DI_LOCKED);
17186 + au_fclr_pin(pin->flags, DI_LOCKED);
17190 +#if 0 /* reserved */
17191 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17194 + dput(pin->parent);
17195 + pin->parent = dget(parent);
17200 +/* ---------------------------------------------------------------------- */
17203 +#ifdef CONFIG_AUFS_HNOTIFY
17204 +struct au_hnotify_op {
17205 + void (*ctl)(struct au_hinode *hinode, int do_set);
17206 + int (*alloc)(struct au_hinode *hinode);
17209 + * if it returns true, the the caller should free hinode->hi_notify,
17210 + * otherwise ->free() frees it.
17212 + int (*free)(struct au_hinode *hinode,
17213 + struct au_hnotify *hn) __must_check;
17215 + void (*fin)(void);
17216 + int (*init)(void);
17218 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17219 + void (*fin_br)(struct au_branch *br);
17220 + int (*init_br)(struct au_branch *br, int perm);
17224 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17225 +void au_hn_free(struct au_hinode *hinode);
17226 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17227 +void au_hn_reset(struct inode *inode, unsigned int flags);
17228 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17229 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17230 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17231 +int au_hnotify_init_br(struct au_branch *br, int perm);
17232 +void au_hnotify_fin_br(struct au_branch *br);
17233 +int __init au_hnotify_init(void);
17234 +void au_hnotify_fin(void);
17237 +extern const struct au_hnotify_op au_hnotify_op;
17240 +void au_hn_init(struct au_hinode *hinode)
17242 + hinode->hi_notify = NULL;
17245 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17247 + return hinode->hi_notify;
17251 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17252 + struct au_hinode *hinode __maybe_unused,
17253 + struct inode *inode __maybe_unused)
17254 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17255 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17256 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17257 + int do_set __maybe_unused)
17258 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17259 + unsigned int flags __maybe_unused)
17260 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17261 + struct au_branch *br __maybe_unused,
17262 + int perm __maybe_unused)
17263 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17264 + int perm __maybe_unused)
17265 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17266 +AuStubInt0(__init au_hnotify_init, void)
17267 +AuStubVoid(au_hnotify_fin, void)
17268 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17269 +#endif /* CONFIG_AUFS_HNOTIFY */
17271 +static inline void au_hn_suspend(struct au_hinode *hdir)
17273 + au_hn_ctl(hdir, /*do_set*/0);
17276 +static inline void au_hn_resume(struct au_hinode *hdir)
17278 + au_hn_ctl(hdir, /*do_set*/1);
17281 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17283 + inode_lock(hdir->hi_inode);
17284 + au_hn_suspend(hdir);
17287 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17288 + unsigned int sc __maybe_unused)
17290 + inode_lock_nested(hdir->hi_inode, sc);
17291 + au_hn_suspend(hdir);
17294 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17296 + au_hn_resume(hdir);
17297 + inode_unlock(hdir->hi_inode);
17300 +#endif /* __KERNEL__ */
17301 +#endif /* __AUFS_INODE_H__ */
17302 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17303 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17304 +++ linux/fs/aufs/ioctl.c 2017-03-02 14:24:13.863589061 +0100
17307 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17309 + * This program, aufs is free software; you can redistribute it and/or modify
17310 + * it under the terms of the GNU General Public License as published by
17311 + * the Free Software Foundation; either version 2 of the License, or
17312 + * (at your option) any later version.
17314 + * This program is distributed in the hope that it will be useful,
17315 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17316 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17317 + * GNU General Public License for more details.
17319 + * You should have received a copy of the GNU General Public License
17320 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17325 + * plink-management and readdir in userspace.
17326 + * assist the pathconf(3) wrapper library.
17328 + * File-based Hierarchical Storage Management.
17331 +#include <linux/compat.h>
17332 +#include <linux/file.h>
17335 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17338 + aufs_bindex_t wbi, bindex, bbot;
17339 + struct file *h_file;
17340 + struct super_block *sb;
17341 + struct dentry *root;
17342 + struct au_branch *br;
17343 + struct aufs_wbr_fd wbrfd = {
17344 + .oflags = au_dir_roflags,
17347 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17348 + | O_NOATIME | O_CLOEXEC;
17350 + AuDebugOn(wbrfd.oflags & ~valid);
17353 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17354 + if (unlikely(err)) {
17360 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17361 + wbrfd.oflags |= au_dir_roflags;
17362 + AuDbg("0%o\n", wbrfd.oflags);
17363 + if (unlikely(wbrfd.oflags & ~valid))
17367 + fd = get_unused_fd_flags(0);
17369 + if (unlikely(fd < 0))
17372 + h_file = ERR_PTR(-EINVAL);
17375 + sb = path->dentry->d_sb;
17376 + root = sb->s_root;
17377 + aufs_read_lock(root, AuLock_IR);
17378 + bbot = au_sbbot(sb);
17379 + if (wbrfd.brid >= 0) {
17380 + wbi = au_br_index(sb, wbrfd.brid);
17381 + if (unlikely(wbi < 0 || wbi > bbot))
17385 + h_file = ERR_PTR(-ENOENT);
17386 + br = au_sbr(sb, wbi);
17387 + if (!au_br_writable(br->br_perm)) {
17391 + bindex = wbi + 1;
17393 + for (; bindex <= bbot; bindex++) {
17394 + br = au_sbr(sb, bindex);
17395 + if (au_br_writable(br->br_perm)) {
17397 + br = au_sbr(sb, wbi);
17402 + AuDbg("wbi %d\n", wbi);
17404 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17408 + aufs_read_unlock(root, AuLock_IR);
17409 + err = PTR_ERR(h_file);
17410 + if (IS_ERR(h_file))
17413 + au_br_put(br); /* cf. au_h_open() */
17414 + fd_install(fd, h_file);
17416 + goto out; /* success */
17419 + put_unused_fd(fd);
17425 +/* ---------------------------------------------------------------------- */
17427 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17430 + struct dentry *dentry;
17433 + case AUFS_CTL_RDU:
17434 + case AUFS_CTL_RDU_INO:
17435 + err = au_rdu_ioctl(file, cmd, arg);
17438 + case AUFS_CTL_WBR_FD:
17439 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17442 + case AUFS_CTL_IBUSY:
17443 + err = au_ibusy_ioctl(file, arg);
17446 + case AUFS_CTL_BRINFO:
17447 + err = au_brinfo_ioctl(file, arg);
17450 + case AUFS_CTL_FHSM_FD:
17451 + dentry = file->f_path.dentry;
17452 + if (IS_ROOT(dentry))
17453 + err = au_fhsm_fd(dentry->d_sb, arg);
17459 + /* do not call the lower */
17460 + AuDbg("0x%x\n", cmd);
17468 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17473 + case AUFS_CTL_MVDOWN:
17474 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17477 + case AUFS_CTL_WBR_FD:
17478 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17482 + /* do not call the lower */
17483 + AuDbg("0x%x\n", cmd);
17491 +#ifdef CONFIG_COMPAT
17492 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17493 + unsigned long arg)
17498 + case AUFS_CTL_RDU:
17499 + case AUFS_CTL_RDU_INO:
17500 + err = au_rdu_compat_ioctl(file, cmd, arg);
17503 + case AUFS_CTL_IBUSY:
17504 + err = au_ibusy_compat_ioctl(file, arg);
17507 + case AUFS_CTL_BRINFO:
17508 + err = au_brinfo_compat_ioctl(file, arg);
17512 + err = aufs_ioctl_dir(file, cmd, arg);
17519 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17520 + unsigned long arg)
17522 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17525 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17526 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17527 +++ linux/fs/aufs/i_op_add.c 2017-03-02 14:24:13.863589061 +0100
17530 + * Copyright (C) 2005-2017 Junjiro R. Okajima
17532 + * This program, aufs is free software; you can redistribute it and/or modify
17533 + * it under the terms of the GNU General Public License as published by
17534 + * the Free Software Foundation; either version 2 of the License, or
17535 + * (at your option) any later version.
17537 + * This program is distributed in the hope that it will be useful,
17538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17540 + * GNU General Public License for more details.
17542 + * You should have received a copy of the GNU General Public License
17543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17547 + * inode operations (add entry)
17553 + * final procedure of adding a new entry, except link(2).
17554 + * remove whiteout, instantiate, copyup the parent dir's times and size
17555 + * and update version.
17556 + * if it failed, re-create the removed whiteout.
17558 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17559 + struct dentry *wh_dentry, struct dentry *dentry)
17562 + aufs_bindex_t bwh;
17563 + struct path h_path;
17564 + struct super_block *sb;
17565 + struct inode *inode, *h_dir;
17566 + struct dentry *wh;
17571 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17572 + IMustLock(h_dir);
17573 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17574 + bwh = au_dbwh(dentry);
17575 + h_path.dentry = wh_dentry;
17576 + h_path.mnt = au_sbr_mnt(sb, bindex);
17577 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17579 + if (unlikely(err))
17583 + inode = au_new_inode(dentry, /*must_new*/1);
17584 + if (!IS_ERR(inode)) {
17585 + d_instantiate(dentry, inode);
17586 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17588 + au_dir_ts(dir, bindex);
17589 + dir->i_version++;
17590 + au_fhsm_wrote(sb, bindex, /*force*/0);
17591 + return 0; /* success */
17594 + err = PTR_ERR(inode);
17599 + /* dir inode is locked */
17600 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17601 + rerr = PTR_ERR(wh);
17602 + if (IS_ERR(wh)) {
17603 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17604 + dentry, err, rerr);
17613 +static int au_d_may_add(struct dentry *dentry)
17618 + if (unlikely(d_unhashed(dentry)))
17620 + if (unlikely(d_really_is_positive(dentry)))
17626 + * simple tests for the adding inode operations.
17627 + * following the checks in vfs, plus the parent-child relationship.
17629 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17630 + struct dentry *h_parent, int isdir)
17634 + struct dentry *h_dentry;
17635 + struct inode *h_inode;
17637 + err = -ENAMETOOLONG;
17638 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17641 + h_dentry = au_h_dptr(dentry, bindex);
17642 + if (d_really_is_negative(dentry)) {
17644 + if (unlikely(d_is_positive(h_dentry)))
17647 + /* rename(2) case */
17649 + if (unlikely(d_is_negative(h_dentry)))
17651 + h_inode = d_inode(h_dentry);
17652 + if (unlikely(!h_inode->i_nlink))
17655 + h_mode = h_inode->i_mode;
17658 + if (unlikely(S_ISDIR(h_mode)))
17660 + } else if (unlikely(!S_ISDIR(h_mode))) {
17667 + /* expected parent dir is locked */
17668 + if (unlikely(h_parent != h_dentry->d_parent))
17677 + * initial procedure of adding a new entry.
17678 + * prepare writable branch and the parent dir, lock it,
17679 + * and lookup whiteout for the new entry.
17681 +static struct dentry*
17682 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17683 + struct dentry *src_dentry, struct au_pin *pin,
17684 + struct au_wr_dir_args *wr_dir_args)
17686 + struct dentry *wh_dentry, *h_parent;
17687 + struct super_block *sb;
17688 + struct au_branch *br;
17690 + unsigned int udba;
17691 + aufs_bindex_t bcpup;
17693 + AuDbg("%pd\n", dentry);
17695 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17697 + wh_dentry = ERR_PTR(err);
17698 + if (unlikely(err < 0))
17701 + sb = dentry->d_sb;
17702 + udba = au_opt_udba(sb);
17703 + err = au_pin(pin, dentry, bcpup, udba,
17704 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17705 + wh_dentry = ERR_PTR(err);
17706 + if (unlikely(err))
17709 + h_parent = au_pinned_h_parent(pin);
17710 + if (udba != AuOpt_UDBA_NONE
17711 + && au_dbtop(dentry) == bcpup)
17712 + err = au_may_add(dentry, bcpup, h_parent,
17713 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17714 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17715 + err = -ENAMETOOLONG;
17716 + wh_dentry = ERR_PTR(err);
17717 + if (unlikely(err))
17720 + br = au_sbr(sb, bcpup);
17722 + struct path tmp = {
17723 + .dentry = h_parent,
17724 + .mnt = au_br_mnt(br)
17726 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17729 + wh_dentry = NULL;
17730 + if (bcpup != au_dbwh(dentry))
17731 + goto out; /* success */
17734 + * ENAMETOOLONG here means that if we allowed create such name, then it
17735 + * would not be able to removed in the future. So we don't allow such
17736 + * name here and we don't handle ENAMETOOLONG differently here.
17738 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17741 + if (IS_ERR(wh_dentry))
17744 + return wh_dentry;
17747 +/* ---------------------------------------------------------------------- */
17749 +enum { Mknod, Symlink, Creat };
17750 +struct simple_arg {
17757 + struct vfsub_aopen_args *aopen;
17760 + const char *symname;
17769 +static int add_simple(struct inode *dir, struct dentry *dentry,
17770 + struct simple_arg *arg)
17773 + aufs_bindex_t btop;
17774 + unsigned char created;
17775 + const unsigned char try_aopen
17776 + = (arg->type == Creat && arg->u.c.try_aopen);
17777 + struct dentry *wh_dentry, *parent;
17778 + struct inode *h_dir;
17779 + struct super_block *sb;
17780 + struct au_branch *br;
17781 + /* to reuduce stack size */
17783 + struct au_dtime dt;
17784 + struct au_pin pin;
17785 + struct path h_path;
17786 + struct au_wr_dir_args wr_dir_args;
17789 + AuDbg("%pd\n", dentry);
17793 + a = kmalloc(sizeof(*a), GFP_NOFS);
17794 + if (unlikely(!a))
17796 + a->wr_dir_args.force_btgt = -1;
17797 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17799 + parent = dentry->d_parent; /* dir inode is locked */
17800 + if (!try_aopen) {
17801 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17802 + if (unlikely(err))
17805 + err = au_d_may_add(dentry);
17806 + if (unlikely(err))
17809 + di_write_lock_parent(parent);
17810 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17811 + &a->pin, &a->wr_dir_args);
17812 + err = PTR_ERR(wh_dentry);
17813 + if (IS_ERR(wh_dentry))
17816 + btop = au_dbtop(dentry);
17817 + sb = dentry->d_sb;
17818 + br = au_sbr(sb, btop);
17819 + a->h_path.dentry = au_h_dptr(dentry, btop);
17820 + a->h_path.mnt = au_br_mnt(br);
17821 + h_dir = au_pinned_h_dir(&a->pin);
17822 + switch (arg->type) {
17825 + if (!try_aopen || !h_dir->i_op->atomic_open)
17826 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17827 + arg->u.c.want_excl);
17829 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17830 + arg->u.c.aopen, br);
17833 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17836 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17844 + err = epilog(dir, btop, wh_dentry, dentry);
17847 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17848 + /* no delegation since it is just created */
17849 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17852 + AuIOErr("%pd revert failure(%d, %d)\n",
17853 + dentry, err, rerr);
17856 + au_dtime_revert(&a->dt);
17859 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17860 + *arg->u.c.aopen->opened |= FILE_CREATED;
17862 + au_unpin(&a->pin);
17867 + di_write_unlock(parent);
17869 + if (unlikely(err)) {
17870 + au_update_dbtop(dentry);
17874 + aufs_read_unlock(dentry, AuLock_DW);
17876 + au_delayed_kfree(a);
17881 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17884 + struct simple_arg arg = {
17891 + return add_simple(dir, dentry, &arg);
17894 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17896 + struct simple_arg arg = {
17898 + .u.s.symname = symname
17900 + return add_simple(dir, dentry, &arg);
17903 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17906 + struct simple_arg arg = {
17910 + .want_excl = want_excl
17913 + return add_simple(dir, dentry, &arg);
17916 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17917 + struct vfsub_aopen_args *aopen_args)
17919 + struct simple_arg arg = {
17922 + .mode = aopen_args->create_mode,
17923 + .want_excl = aopen_args->open_flag & O_EXCL,
17924 + .try_aopen = true,
17925 + .aopen = aopen_args
17928 + return add_simple(dir, dentry, &arg);
17931 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17934 + aufs_bindex_t bindex;
17935 + struct super_block *sb;
17936 + struct dentry *parent, *h_parent, *h_dentry;
17937 + struct inode *h_dir, *inode;
17938 + struct vfsmount *h_mnt;
17939 + struct au_wr_dir_args wr_dir_args = {
17940 + .force_btgt = -1,
17941 + .flags = AuWrDir_TMPFILE
17944 + /* copy-up may happen */
17948 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17949 + if (unlikely(err))
17952 + err = au_di_init(dentry);
17953 + if (unlikely(err))
17957 + parent = d_find_any_alias(dir);
17958 + AuDebugOn(!parent);
17959 + di_write_lock_parent(parent);
17960 + if (unlikely(d_inode(parent) != dir))
17963 + err = au_digen_test(parent, au_sigen(sb));
17964 + if (unlikely(err))
17967 + bindex = au_dbtop(parent);
17968 + au_set_dbtop(dentry, bindex);
17969 + au_set_dbbot(dentry, bindex);
17970 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17972 + if (unlikely(err < 0))
17975 + err = -EOPNOTSUPP;
17976 + h_dir = au_h_iptr(dir, bindex);
17977 + if (unlikely(!h_dir->i_op->tmpfile))
17980 + h_mnt = au_sbr_mnt(sb, bindex);
17981 + err = vfsub_mnt_want_write(h_mnt);
17982 + if (unlikely(err))
17985 + h_parent = au_h_dptr(parent, bindex);
17986 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17987 + if (unlikely(err))
17991 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17992 + if (unlikely(!h_dentry))
17995 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17996 + if (unlikely(err))
17999 + au_set_dbtop(dentry, bindex);
18000 + au_set_dbbot(dentry, bindex);
18001 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18002 + inode = au_new_inode(dentry, /*must_new*/1);
18003 + if (IS_ERR(inode)) {
18004 + err = PTR_ERR(inode);
18005 + au_set_h_dptr(dentry, bindex, NULL);
18006 + au_set_dbtop(dentry, -1);
18007 + au_set_dbbot(dentry, -1);
18009 + if (!inode->i_nlink)
18010 + set_nlink(inode, 1);
18011 + d_tmpfile(dentry, inode);
18012 + au_di(dentry)->di_tmpfile = 1;
18014 + /* update without i_mutex */
18015 + if (au_ibtop(dir) == au_dbtop(dentry))
18016 + au_cpup_attr_timesizes(dir);
18022 + vfsub_mnt_drop_write(h_mnt);
18024 + di_write_unlock(parent);
18026 + di_write_unlock(dentry);
18027 + if (unlikely(err)) {
18028 + au_di_fin(dentry);
18029 + dentry->d_fsdata = NULL;
18032 + si_read_unlock(sb);
18034 + inode_unlock(dir);
18038 +/* ---------------------------------------------------------------------- */
18040 +struct au_link_args {
18041 + aufs_bindex_t bdst, bsrc;
18042 + struct au_pin pin;
18043 + struct path h_path;
18044 + struct dentry *src_parent, *parent;
18047 +static int au_cpup_before_link(struct dentry *src_dentry,
18048 + struct au_link_args *a)
18051 + struct dentry *h_src_dentry;
18052 + struct au_cp_generic cpg = {
18053 + .dentry = src_dentry,
18058 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18061 + di_read_lock_parent(a->src_parent, AuLock_IR);
18062 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18063 + if (unlikely(err))
18066 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18067 + err = au_pin(&a->pin, src_dentry, a->bdst,
18068 + au_opt_udba(src_dentry->d_sb),
18069 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18070 + if (unlikely(err))
18073 + err = au_sio_cpup_simple(&cpg);
18074 + au_unpin(&a->pin);
18077 + di_read_unlock(a->src_parent, AuLock_IR);
18081 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18082 + struct au_link_args *a)
18085 + unsigned char plink;
18086 + aufs_bindex_t bbot;
18087 + struct dentry *h_src_dentry;
18088 + struct inode *h_inode, *inode, *delegated;
18089 + struct super_block *sb;
18090 + struct file *h_file;
18094 + sb = src_dentry->d_sb;
18095 + inode = d_inode(src_dentry);
18096 + if (au_ibtop(inode) <= a->bdst)
18097 + h_inode = au_h_iptr(inode, a->bdst);
18098 + if (!h_inode || !h_inode->i_nlink) {
18099 + /* copyup src_dentry as the name of dentry. */
18100 + bbot = au_dbbot(dentry);
18101 + if (bbot < a->bsrc)
18102 + au_set_dbbot(dentry, a->bsrc);
18103 + au_set_h_dptr(dentry, a->bsrc,
18104 + dget(au_h_dptr(src_dentry, a->bsrc)));
18105 + dget(a->h_path.dentry);
18106 + au_set_h_dptr(dentry, a->bdst, NULL);
18107 + AuDbg("temporary d_inode...\n");
18108 + spin_lock(&dentry->d_lock);
18109 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18110 + spin_unlock(&dentry->d_lock);
18111 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18112 + if (IS_ERR(h_file))
18113 + err = PTR_ERR(h_file);
18115 + struct au_cp_generic cpg = {
18116 + .dentry = dentry,
18121 + .flags = AuCpup_KEEPLINO
18123 + err = au_sio_cpup_simple(&cpg);
18124 + au_h_open_post(dentry, a->bsrc, h_file);
18126 + dput(a->h_path.dentry);
18127 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18129 + au_set_h_dptr(dentry, a->bdst,
18130 + a->h_path.dentry);
18132 + spin_lock(&dentry->d_lock);
18133 + dentry->d_inode = NULL; /* restore */
18134 + spin_unlock(&dentry->d_lock);
18135 + AuDbg("temporary d_inode...done\n");
18136 + au_set_h_dptr(dentry, a->bsrc, NULL);
18137 + au_set_dbbot(dentry, bbot);
18139 + /* the inode of src_dentry already exists on a.bdst branch */
18140 + h_src_dentry = d_find_alias(h_inode);
18141 + if (!h_src_dentry && au_plink_test(inode)) {
18143 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18144 + err = PTR_ERR(h_src_dentry);
18145 + if (IS_ERR(h_src_dentry))
18148 + if (unlikely(d_is_negative(h_src_dentry))) {
18149 + dput(h_src_dentry);
18150 + h_src_dentry = NULL;
18154 + if (h_src_dentry) {
18155 + delegated = NULL;
18156 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18157 + &a->h_path, &delegated);
18158 + if (unlikely(err == -EWOULDBLOCK)) {
18159 + pr_warn("cannot retry for NFSv4 delegation"
18160 + " for an internal link\n");
18163 + dput(h_src_dentry);
18165 + AuIOErr("no dentry found for hi%lu on b%d\n",
18166 + h_inode->i_ino, a->bdst);
18171 + if (!err && !plink)
18172 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18179 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18180 + struct dentry *dentry)
18183 + struct au_dtime dt;
18184 + struct au_link_args *a;
18185 + struct dentry *wh_dentry, *h_src_dentry;
18186 + struct inode *inode, *delegated;
18187 + struct super_block *sb;
18188 + struct au_wr_dir_args wr_dir_args = {
18189 + /* .force_btgt = -1, */
18190 + .flags = AuWrDir_ADD_ENTRY
18194 + inode = d_inode(src_dentry);
18195 + IMustLock(inode);
18198 + a = kzalloc(sizeof(*a), GFP_NOFS);
18199 + if (unlikely(!a))
18202 + a->parent = dentry->d_parent; /* dir inode is locked */
18203 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18204 + AuLock_NOPLM | AuLock_GEN);
18205 + if (unlikely(err))
18207 + err = au_d_linkable(src_dentry);
18208 + if (unlikely(err))
18210 + err = au_d_may_add(dentry);
18211 + if (unlikely(err))
18214 + a->src_parent = dget_parent(src_dentry);
18215 + wr_dir_args.force_btgt = au_ibtop(inode);
18217 + di_write_lock_parent(a->parent);
18218 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18219 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18221 + err = PTR_ERR(wh_dentry);
18222 + if (IS_ERR(wh_dentry))
18226 + sb = dentry->d_sb;
18227 + a->bdst = au_dbtop(dentry);
18228 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18229 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18230 + a->bsrc = au_ibtop(inode);
18231 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18232 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18233 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18234 + if (!h_src_dentry) {
18235 + a->bsrc = au_dbtop(src_dentry);
18236 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18237 + AuDebugOn(!h_src_dentry);
18238 + } else if (IS_ERR(h_src_dentry)) {
18239 + err = PTR_ERR(h_src_dentry);
18244 + * aufs doesn't touch the credential so
18245 + * security_dentry_create_files_as() is unnecrssary.
18247 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18248 + if (a->bdst < a->bsrc
18249 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18250 + err = au_cpup_or_link(src_dentry, dentry, a);
18252 + delegated = NULL;
18253 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18254 + &a->h_path, &delegated);
18255 + if (unlikely(err == -EWOULDBLOCK)) {
18256 + pr_warn("cannot retry for NFSv4 delegation"
18257 + " for an internal link\n");
18261 + dput(h_src_dentry);
18264 + * copyup src_dentry to the branch we process,
18265 + * and then link(2) to it.
18267 + dput(h_src_dentry);
18268 + if (a->bdst < a->bsrc
18269 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18270 + au_unpin(&a->pin);
18271 + di_write_unlock(a->parent);
18272 + err = au_cpup_before_link(src_dentry, a);
18273 + di_write_lock_parent(a->parent);
18275 + err = au_pin(&a->pin, dentry, a->bdst,
18277 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18278 + if (unlikely(err))
18282 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18284 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18285 + delegated = NULL;
18286 + err = vfsub_link(h_src_dentry,
18287 + au_pinned_h_dir(&a->pin),
18288 + &a->h_path, &delegated);
18289 + if (unlikely(err == -EWOULDBLOCK)) {
18290 + pr_warn("cannot retry"
18291 + " for NFSv4 delegation"
18292 + " for an internal link\n");
18298 + if (unlikely(err))
18302 + a->h_path.dentry = wh_dentry;
18303 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18305 + if (unlikely(err))
18309 + au_dir_ts(dir, a->bdst);
18310 + dir->i_version++;
18311 + inc_nlink(inode);
18312 + inode->i_ctime = dir->i_ctime;
18313 + d_instantiate(dentry, au_igrab(inode));
18314 + if (d_unhashed(a->h_path.dentry))
18315 + /* some filesystem calls d_drop() */
18317 + /* some filesystems consume an inode even hardlink */
18318 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18319 + goto out_unpin; /* success */
18322 + /* no delegation since it is just created */
18323 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18324 + /*delegated*/NULL, /*force*/0);
18325 + if (unlikely(rerr)) {
18326 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18329 + au_dtime_revert(&dt);
18331 + au_unpin(&a->pin);
18335 + di_write_unlock(a->parent);
18336 + dput(a->src_parent);
18338 + if (unlikely(err)) {
18339 + au_update_dbtop(dentry);
18342 + aufs_read_and_write_unlock2(dentry, src_dentry);
18344 + au_delayed_kfree(a);
18350 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18353 + aufs_bindex_t bindex;
18354 + unsigned char diropq;
18355 + struct path h_path;
18356 + struct dentry *wh_dentry, *parent, *opq_dentry;
18357 + struct inode *h_inode;
18358 + struct super_block *sb;
18360 + struct au_pin pin;
18361 + struct au_dtime dt;
18362 + } *a; /* reduce the stack usage */
18363 + struct au_wr_dir_args wr_dir_args = {
18364 + .force_btgt = -1,
18365 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18371 + a = kmalloc(sizeof(*a), GFP_NOFS);
18372 + if (unlikely(!a))
18375 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18376 + if (unlikely(err))
18378 + err = au_d_may_add(dentry);
18379 + if (unlikely(err))
18382 + parent = dentry->d_parent; /* dir inode is locked */
18383 + di_write_lock_parent(parent);
18384 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18385 + &a->pin, &wr_dir_args);
18386 + err = PTR_ERR(wh_dentry);
18387 + if (IS_ERR(wh_dentry))
18390 + sb = dentry->d_sb;
18391 + bindex = au_dbtop(dentry);
18392 + h_path.dentry = au_h_dptr(dentry, bindex);
18393 + h_path.mnt = au_sbr_mnt(sb, bindex);
18394 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18395 + if (unlikely(err))
18398 + /* make the dir opaque */
18400 + h_inode = d_inode(h_path.dentry);
18402 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18403 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18404 + opq_dentry = au_diropq_create(dentry, bindex);
18405 + inode_unlock(h_inode);
18406 + err = PTR_ERR(opq_dentry);
18407 + if (IS_ERR(opq_dentry))
18409 + dput(opq_dentry);
18413 + err = epilog(dir, bindex, wh_dentry, dentry);
18416 + goto out_unpin; /* success */
18421 + AuLabel(revert opq);
18422 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18423 + rerr = au_diropq_remove(dentry, bindex);
18424 + inode_unlock(h_inode);
18426 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18427 + dentry, err, rerr);
18433 + AuLabel(revert dir);
18434 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18436 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18437 + dentry, err, rerr);
18440 + au_dtime_revert(&a->dt);
18442 + au_unpin(&a->pin);
18445 + di_write_unlock(parent);
18447 + if (unlikely(err)) {
18448 + au_update_dbtop(dentry);
18451 + aufs_read_unlock(dentry, AuLock_DW);
18453 + au_delayed_kfree(a);
18457 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18458 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18459 +++ linux/fs/aufs/i_op.c 2017-03-02 14:24:13.860255635 +0100
18462 + * Copyright (C) 2005-2017 Junjiro R. Okajima
18464 + * This program, aufs is free software; you can redistribute it and/or modify
18465 + * it under the terms of the GNU General Public License as published by
18466 + * the Free Software Foundation; either version 2 of the License, or
18467 + * (at your option) any later version.
18469 + * This program is distributed in the hope that it will be useful,
18470 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18471 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18472 + * GNU General Public License for more details.
18474 + * You should have received a copy of the GNU General Public License
18475 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18479 + * inode operations (except add/del/rename)
18482 +#include <linux/device_cgroup.h>
18483 +#include <linux/fs_stack.h>
18484 +#include <linux/namei.h>
18485 +#include <linux/security.h>
18488 +static int h_permission(struct inode *h_inode, int mask,
18489 + struct path *h_path, int brperm)
18492 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18495 + if (write_mask && IS_IMMUTABLE(h_inode))
18499 + if (((mask & MAY_EXEC)
18500 + && S_ISREG(h_inode->i_mode)
18501 + && (path_noexec(h_path)
18502 + || !(h_inode->i_mode & S_IXUGO))))
18506 + * - skip the lower fs test in the case of write to ro branch.
18507 + * - nfs dir permission write check is optimized, but a policy for
18508 + * link/rename requires a real check.
18509 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18510 + * in this case, generic_permission() returns -EOPNOTSUPP.
18512 + if ((write_mask && !au_br_writable(brperm))
18513 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18514 + && write_mask && !(mask & MAY_READ))
18515 + || !h_inode->i_op->permission) {
18516 + /* AuLabel(generic_permission); */
18517 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18518 + err = generic_permission(h_inode, mask);
18519 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18520 + err = h_inode->i_op->permission(h_inode, mask);
18523 + /* AuLabel(h_inode->permission); */
18524 + err = h_inode->i_op->permission(h_inode, mask);
18529 + err = devcgroup_inode_permission(h_inode, mask);
18531 + err = security_inode_permission(h_inode, mask);
18535 + /* todo: do we need to call ima_path_check()? */
18536 + struct path h_path = {
18540 + err = ima_path_check(&h_path,
18541 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18542 + IMA_COUNT_LEAVE);
18550 +static int aufs_permission(struct inode *inode, int mask)
18553 + aufs_bindex_t bindex, bbot;
18554 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18555 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18556 + struct inode *h_inode;
18557 + struct super_block *sb;
18558 + struct au_branch *br;
18560 + /* todo: support rcu-walk? */
18561 + if (mask & MAY_NOT_BLOCK)
18564 + sb = inode->i_sb;
18565 + si_read_lock(sb, AuLock_FLUSH);
18566 + ii_read_lock_child(inode);
18568 + err = au_iigen_test(inode, au_sigen(sb));
18569 + if (unlikely(err))
18575 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18576 + err = au_busy_or_stale();
18577 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18578 + if (unlikely(!h_inode
18579 + || (h_inode->i_mode & S_IFMT)
18580 + != (inode->i_mode & S_IFMT)))
18584 + bindex = au_ibtop(inode);
18585 + br = au_sbr(sb, bindex);
18586 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18589 + && !special_file(h_inode->i_mode)) {
18590 + /* test whether the upper writable branch exists */
18592 + for (; bindex >= 0; bindex--)
18593 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18601 + /* non-write to dir */
18603 + bbot = au_ibbot(inode);
18604 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18605 + h_inode = au_h_iptr(inode, bindex);
18607 + err = au_busy_or_stale();
18608 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18611 + br = au_sbr(sb, bindex);
18612 + err = h_permission(h_inode, mask, &br->br_path,
18618 + ii_read_unlock(inode);
18619 + si_read_unlock(sb);
18623 +/* ---------------------------------------------------------------------- */
18625 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18626 + unsigned int flags)
18628 + struct dentry *ret, *parent;
18629 + struct inode *inode;
18630 + struct super_block *sb;
18631 + int err, npositive;
18635 + /* todo: support rcu-walk? */
18636 + ret = ERR_PTR(-ECHILD);
18637 + if (flags & LOOKUP_RCU)
18640 + ret = ERR_PTR(-ENAMETOOLONG);
18641 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18645 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18646 + ret = ERR_PTR(err);
18647 + if (unlikely(err))
18650 + err = au_di_init(dentry);
18651 + ret = ERR_PTR(err);
18652 + if (unlikely(err))
18656 + npositive = 0; /* suppress a warning */
18657 + parent = dentry->d_parent; /* dir inode is locked */
18658 + di_read_lock_parent(parent, AuLock_IR);
18659 + err = au_alive_dir(parent);
18661 + err = au_digen_test(parent, au_sigen(sb));
18663 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18664 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18665 + AuLkup_ALLOW_NEG);
18668 + di_read_unlock(parent, AuLock_IR);
18669 + ret = ERR_PTR(err);
18670 + if (unlikely(err < 0))
18674 + inode = au_new_inode(dentry, /*must_new*/0);
18675 + if (IS_ERR(inode)) {
18676 + ret = (void *)inode;
18683 + atomic_inc(&inode->i_count);
18684 + ret = d_splice_alias(inode, dentry);
18686 + if (unlikely(d_need_lookup(dentry))) {
18687 + spin_lock(&dentry->d_lock);
18688 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18689 + spin_unlock(&dentry->d_lock);
18693 + if (!IS_ERR(ret)) {
18695 + if (ret && ret != dentry)
18696 + ii_write_unlock(inode);
18698 + ii_write_unlock(inode);
18705 + di_write_unlock(dentry);
18707 + si_read_unlock(sb);
18712 +/* ---------------------------------------------------------------------- */
18714 +struct aopen_node {
18715 + struct hlist_node hlist;
18716 + struct file *file, *h_file;
18719 +static int au_do_aopen(struct inode *inode, struct file *file)
18721 + struct au_sphlhead *aopen;
18722 + struct aopen_node *node;
18723 + struct au_do_open_args args = {
18725 + .open = au_do_open_nondir
18728 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18729 + spin_lock(&aopen->spin);
18730 + hlist_for_each_entry(node, &aopen->head, hlist)
18731 + if (node->file == file) {
18732 + args.h_file = node->h_file;
18735 + spin_unlock(&aopen->spin);
18736 + /* AuDebugOn(!args.h_file); */
18738 + return au_do_open(file, &args);
18741 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18742 + struct file *file, unsigned int open_flag,
18743 + umode_t create_mode, int *opened)
18745 + int err, h_opened = *opened;
18746 + unsigned int lkup_flags;
18747 + struct dentry *parent, *d;
18748 + struct au_sphlhead *aopen;
18749 + struct vfsub_aopen_args args = {
18750 + .open_flag = open_flag,
18751 + .create_mode = create_mode,
18752 + .opened = &h_opened
18754 + struct aopen_node aopen_node = {
18759 + AuDbg("open_flag 0%o\n", open_flag);
18760 + AuDbgDentry(dentry);
18763 + if (!au_di(dentry)) {
18764 + lkup_flags = LOOKUP_OPEN;
18765 + if (open_flag & O_CREAT)
18766 + lkup_flags |= LOOKUP_CREATE;
18767 + d = aufs_lookup(dir, dentry, lkup_flags);
18769 + err = PTR_ERR(d);
18774 + * obsoleted dentry found.
18775 + * another error will be returned later.
18781 + AuDbgDentry(dentry);
18784 + if (d_is_positive(dentry)
18785 + || d_unhashed(dentry)
18786 + || d_unlinked(dentry)
18787 + || !(open_flag & O_CREAT))
18788 + goto out_no_open;
18790 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18791 + if (unlikely(err))
18794 + parent = dentry->d_parent; /* dir is locked */
18795 + di_write_lock_parent(parent);
18796 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18797 + if (unlikely(err))
18800 + AuDbgDentry(dentry);
18801 + if (d_is_positive(dentry))
18804 + args.file = get_empty_filp();
18805 + err = PTR_ERR(args.file);
18806 + if (IS_ERR(args.file))
18809 + args.file->f_flags = file->f_flags;
18810 + err = au_aopen_or_create(dir, dentry, &args);
18812 + AuDbgFile(args.file);
18813 + if (unlikely(err < 0)) {
18814 + if (h_opened & FILE_OPENED)
18817 + put_filp(args.file);
18821 + /* some filesystems don't set FILE_CREATED while succeeded? */
18822 + *opened |= FILE_CREATED;
18823 + if (h_opened & FILE_OPENED)
18824 + aopen_node.h_file = args.file;
18826 + put_filp(args.file);
18827 + args.file = NULL;
18829 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18830 + au_sphl_add(&aopen_node.hlist, aopen);
18831 + err = finish_open(file, dentry, au_do_aopen, opened);
18832 + au_sphl_del(&aopen_node.hlist, aopen);
18835 + if (aopen_node.h_file)
18836 + fput(aopen_node.h_file);
18839 + di_write_unlock(parent);
18840 + aufs_read_unlock(dentry, AuLock_DW);
18841 + AuDbgDentry(dentry);
18842 + if (unlikely(err < 0))
18845 + if (err >= 0 && !(*opened & FILE_CREATED)) {
18846 + AuLabel(out_no_open);
18848 + err = finish_no_open(file, dentry);
18851 + AuDbg("%pd%s%s\n", dentry,
18852 + (*opened & FILE_CREATED) ? " created" : "",
18853 + (*opened & FILE_OPENED) ? " opened" : "");
18859 +/* ---------------------------------------------------------------------- */
18861 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18862 + const unsigned char add_entry, aufs_bindex_t bcpup,
18863 + aufs_bindex_t btop)
18866 + struct dentry *h_parent;
18867 + struct inode *h_dir;
18870 + IMustLock(d_inode(parent));
18872 + di_write_lock_parent(parent);
18875 + if (!au_h_dptr(parent, bcpup)) {
18876 + if (btop > bcpup)
18877 + err = au_cpup_dirs(dentry, bcpup);
18878 + else if (btop < bcpup)
18879 + err = au_cpdown_dirs(dentry, bcpup);
18883 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18884 + h_parent = au_h_dptr(parent, bcpup);
18885 + h_dir = d_inode(h_parent);
18886 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
18887 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18888 + /* todo: no unlock here */
18889 + inode_unlock(h_dir);
18891 + AuDbg("bcpup %d\n", bcpup);
18893 + if (d_really_is_negative(dentry))
18894 + au_set_h_dptr(dentry, btop, NULL);
18895 + au_update_dbrange(dentry, /*do_put_zero*/0);
18900 + di_write_unlock(parent);
18902 + err = bcpup; /* success */
18909 + * decide the branch and the parent dir where we will create a new entry.
18910 + * returns new bindex or an error.
18911 + * copyup the parent dir if needed.
18913 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18914 + struct au_wr_dir_args *args)
18917 + unsigned int flags;
18918 + aufs_bindex_t bcpup, btop, src_btop;
18919 + const unsigned char add_entry
18920 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18921 + | au_ftest_wrdir(args->flags, TMPFILE);
18922 + struct super_block *sb;
18923 + struct dentry *parent;
18924 + struct au_sbinfo *sbinfo;
18926 + sb = dentry->d_sb;
18927 + sbinfo = au_sbi(sb);
18928 + parent = dget_parent(dentry);
18929 + btop = au_dbtop(dentry);
18931 + if (args->force_btgt < 0) {
18932 + if (src_dentry) {
18933 + src_btop = au_dbtop(src_dentry);
18934 + if (src_btop < btop)
18935 + bcpup = src_btop;
18936 + } else if (add_entry) {
18938 + if (au_ftest_wrdir(args->flags, ISDIR))
18939 + au_fset_wbr(flags, DIR);
18940 + err = AuWbrCreate(sbinfo, dentry, flags);
18944 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18946 + err = AuWbrCopyup(sbinfo, dentry);
18948 + if (!IS_ROOT(dentry)) {
18949 + di_read_lock_parent(parent, !AuLock_IR);
18950 + err = AuWbrCopyup(sbinfo, dentry);
18951 + di_read_unlock(parent, !AuLock_IR);
18953 + err = AuWbrCopyup(sbinfo, dentry);
18956 + if (unlikely(err < 0))
18960 + bcpup = args->force_btgt;
18961 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18964 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
18966 + if (bcpup == btop)
18967 + goto out; /* success */
18969 + /* copyup the new parent into the branch we process */
18970 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
18972 + if (d_really_is_negative(dentry)) {
18973 + au_set_h_dptr(dentry, btop, NULL);
18974 + au_set_dbtop(dentry, bcpup);
18975 + au_set_dbbot(dentry, bcpup);
18977 + AuDebugOn(add_entry
18978 + && !au_ftest_wrdir(args->flags, TMPFILE)
18979 + && !au_h_dptr(dentry, bcpup));
18987 +/* ---------------------------------------------------------------------- */
18989 +void au_pin_hdir_unlock(struct au_pin *p)
18992 + au_hn_inode_unlock(p->hdir);
18995 +int au_pin_hdir_lock(struct au_pin *p)
19003 + /* even if an error happens later, keep this lock */
19004 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19007 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19012 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19013 + p->h_parent, p->br);
19019 +int au_pin_hdir_relock(struct au_pin *p)
19022 + struct inode *h_i;
19023 + struct dentry *h_d[] = {
19028 + err = au_pin_hdir_lock(p);
19029 + if (unlikely(err))
19032 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19035 + if (d_is_positive(h_d[i])) {
19036 + h_i = d_inode(h_d[i]);
19037 + err = !h_i->i_nlink;
19045 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19047 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19048 + p->hdir->hi_inode->i_rwsem.owner = task;
19052 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19055 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19056 + p->lsc_hi, 0, NULL, _RET_IP_);
19057 + au_pin_hdir_set_owner(p, current);
19061 +void au_pin_hdir_release(struct au_pin *p)
19064 + au_pin_hdir_set_owner(p, p->task);
19065 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19069 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19071 + if (pin && pin->parent)
19072 + return au_h_dptr(pin->parent, pin->bindex);
19076 +void au_unpin(struct au_pin *p)
19079 + au_pin_hdir_unlock(p);
19080 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19081 + vfsub_mnt_drop_write(p->h_mnt);
19085 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19086 + di_read_unlock(p->parent, AuLock_IR);
19087 + iput(p->hdir->hi_inode);
19089 + p->parent = NULL;
19092 + /* do not clear p->task */
19095 +int au_do_pin(struct au_pin *p)
19098 + struct super_block *sb;
19099 + struct inode *h_dir;
19102 + sb = p->dentry->d_sb;
19103 + p->br = au_sbr(sb, p->bindex);
19104 + if (IS_ROOT(p->dentry)) {
19105 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19106 + p->h_mnt = au_br_mnt(p->br);
19107 + err = vfsub_mnt_want_write(p->h_mnt);
19108 + if (unlikely(err)) {
19109 + au_fclr_pin(p->flags, MNT_WRITE);
19116 + p->h_dentry = NULL;
19117 + if (p->bindex <= au_dbbot(p->dentry))
19118 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19120 + p->parent = dget_parent(p->dentry);
19121 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19122 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19125 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19126 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19128 + h_dir = p->hdir->hi_inode;
19132 + * if DI_LOCKED is not set, then p->parent may be different
19133 + * and h_parent can be NULL.
19135 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19137 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19138 + di_read_unlock(p->parent, AuLock_IR);
19140 + p->parent = NULL;
19144 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19145 + p->h_mnt = au_br_mnt(p->br);
19146 + err = vfsub_mnt_want_write(p->h_mnt);
19147 + if (unlikely(err)) {
19148 + au_fclr_pin(p->flags, MNT_WRITE);
19149 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19150 + di_read_unlock(p->parent, AuLock_IR);
19152 + p->parent = NULL;
19158 + err = au_pin_hdir_lock(p);
19160 + goto out; /* success */
19165 + pr_err("err %d\n", err);
19166 + err = au_busy_or_stale();
19171 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19172 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19173 + unsigned int udba, unsigned char flags)
19175 + p->dentry = dentry;
19177 + p->lsc_di = lsc_di;
19178 + p->lsc_hi = lsc_hi;
19179 + p->flags = flags;
19180 + p->bindex = bindex;
19182 + p->parent = NULL;
19186 + p->h_dentry = NULL;
19187 + p->h_parent = NULL;
19189 + p->task = current;
19192 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19193 + unsigned int udba, unsigned char flags)
19195 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19197 + return au_do_pin(pin);
19200 +/* ---------------------------------------------------------------------- */
19203 + * ->setattr() and ->getattr() are called in various cases.
19204 + * chmod, stat: dentry is revalidated.
19205 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19207 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19209 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19210 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19213 + struct dentry *parent;
19216 + if (au_digen_test(dentry, sigen)) {
19217 + parent = dget_parent(dentry);
19218 + di_read_lock_parent(parent, AuLock_IR);
19219 + err = au_refresh_dentry(dentry, parent);
19220 + di_read_unlock(parent, AuLock_IR);
19228 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19229 + struct au_icpup_args *a)
19233 + aufs_bindex_t btop, ibtop;
19234 + struct dentry *hi_wh, *parent;
19235 + struct inode *inode;
19236 + struct au_wr_dir_args wr_dir_args = {
19237 + .force_btgt = -1,
19241 + if (d_is_dir(dentry))
19242 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19243 + /* plink or hi_wh() case */
19244 + btop = au_dbtop(dentry);
19245 + inode = d_inode(dentry);
19246 + ibtop = au_ibtop(inode);
19247 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19248 + wr_dir_args.force_btgt = ibtop;
19249 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19250 + if (unlikely(err < 0))
19254 + au_fset_icpup(a->flags, DID_CPUP);
19257 + a->pin_flags = AuPin_MNT_WRITE;
19259 + if (!IS_ROOT(dentry)) {
19260 + au_fset_pin(a->pin_flags, DI_LOCKED);
19261 + parent = dget_parent(dentry);
19262 + di_write_lock_parent(parent);
19265 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19266 + if (unlikely(err))
19270 + a->h_path.dentry = au_h_dptr(dentry, btop);
19271 + a->h_inode = d_inode(a->h_path.dentry);
19272 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19273 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19274 + if (ia->ia_size < i_size_read(a->h_inode))
19275 + sz = ia->ia_size;
19276 + inode_unlock(a->h_inode);
19280 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19281 + hi_wh = au_hi_wh(inode, a->btgt);
19283 + struct au_cp_generic cpg = {
19284 + .dentry = dentry,
19290 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19291 + if (unlikely(err))
19293 + hi_wh = au_hi_wh(inode, a->btgt);
19294 + /* todo: revalidate hi_wh? */
19299 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19300 + di_downgrade_lock(parent, AuLock_IR);
19304 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19305 + goto out; /* success */
19307 + if (!d_unhashed(dentry)) {
19308 + struct au_cp_generic cpg = {
19309 + .dentry = dentry,
19314 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19316 + err = au_sio_cpup_simple(&cpg);
19318 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19319 + } else if (!hi_wh)
19320 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19322 + a->h_path.dentry = hi_wh; /* do not dget here */
19325 + a->h_inode = d_inode(a->h_path.dentry);
19327 + goto out; /* success */
19328 + au_unpin(&a->pin);
19331 + di_write_unlock(parent);
19336 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19340 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19343 + struct inode *inode, *delegated;
19344 + struct super_block *sb;
19345 + struct file *file;
19346 + struct au_icpup_args *a;
19348 + inode = d_inode(dentry);
19349 + IMustLock(inode);
19351 + err = setattr_prepare(dentry, ia);
19352 + if (unlikely(err))
19356 + a = kzalloc(sizeof(*a), GFP_NOFS);
19357 + if (unlikely(!a))
19360 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19361 + ia->ia_valid &= ~ATTR_MODE;
19364 + sb = dentry->d_sb;
19365 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19366 + if (unlikely(err))
19369 + if (ia->ia_valid & ATTR_FILE) {
19370 + /* currently ftruncate(2) only */
19371 + AuDebugOn(!d_is_reg(dentry));
19372 + file = ia->ia_file;
19373 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19374 + if (unlikely(err))
19376 + ia->ia_file = au_hf_top(file);
19377 + a->udba = AuOpt_UDBA_NONE;
19379 + /* fchmod() doesn't pass ia_file */
19380 + a->udba = au_opt_udba(sb);
19381 + di_write_lock_child(dentry);
19382 + /* no d_unlinked(), to set UDBA_NONE for root */
19383 + if (d_unhashed(dentry))
19384 + a->udba = AuOpt_UDBA_NONE;
19385 + if (a->udba != AuOpt_UDBA_NONE) {
19386 + AuDebugOn(IS_ROOT(dentry));
19387 + err = au_reval_for_attr(dentry, au_sigen(sb));
19388 + if (unlikely(err))
19393 + err = au_pin_and_icpup(dentry, ia, a);
19394 + if (unlikely(err < 0))
19396 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19397 + ia->ia_file = NULL;
19398 + ia->ia_valid &= ~ATTR_FILE;
19401 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19402 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19403 + == (ATTR_MODE | ATTR_CTIME)) {
19404 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19405 + if (unlikely(err))
19407 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19408 + && (ia->ia_valid & ATTR_CTIME)) {
19409 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19410 + if (unlikely(err))
19414 + if (ia->ia_valid & ATTR_SIZE) {
19417 + if (ia->ia_size < i_size_read(inode))
19419 + truncate_setsize(inode, ia->ia_size);
19422 + if (ia->ia_valid & ATTR_FILE)
19424 + inode_unlock(a->h_inode);
19425 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19426 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19428 + delegated = NULL;
19430 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19432 + err = break_deleg_wait(&delegated);
19440 + * regardless aufs 'acl' option setting.
19441 + * why don't all acl-aware fs call this func from their ->setattr()?
19443 + if (!err && (ia->ia_valid & ATTR_MODE))
19444 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19446 + au_cpup_attr_changeable(inode);
19449 + inode_unlock(a->h_inode);
19450 + au_unpin(&a->pin);
19451 + if (unlikely(err))
19452 + au_update_dbtop(dentry);
19454 + di_write_unlock(dentry);
19456 + fi_write_unlock(file);
19457 + ia->ia_file = file;
19458 + ia->ia_valid |= ATTR_FILE;
19461 + si_read_unlock(sb);
19463 + au_delayed_kfree(a);
19469 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19470 +static int au_h_path_to_set_attr(struct dentry *dentry,
19471 + struct au_icpup_args *a, struct path *h_path)
19474 + struct super_block *sb;
19476 + sb = dentry->d_sb;
19477 + a->udba = au_opt_udba(sb);
19478 + /* no d_unlinked(), to set UDBA_NONE for root */
19479 + if (d_unhashed(dentry))
19480 + a->udba = AuOpt_UDBA_NONE;
19481 + if (a->udba != AuOpt_UDBA_NONE) {
19482 + AuDebugOn(IS_ROOT(dentry));
19483 + err = au_reval_for_attr(dentry, au_sigen(sb));
19484 + if (unlikely(err))
19487 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19488 + if (unlikely(err < 0))
19491 + h_path->dentry = a->h_path.dentry;
19492 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19498 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19499 + struct au_sxattr *arg)
19502 + struct path h_path;
19503 + struct super_block *sb;
19504 + struct au_icpup_args *a;
19505 + struct inode *h_inode;
19507 + IMustLock(inode);
19510 + a = kzalloc(sizeof(*a), GFP_NOFS);
19511 + if (unlikely(!a))
19514 + sb = dentry->d_sb;
19515 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19516 + if (unlikely(err))
19519 + h_path.dentry = NULL; /* silence gcc */
19520 + di_write_lock_child(dentry);
19521 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19522 + if (unlikely(err))
19525 + inode_unlock(a->h_inode);
19526 + switch (arg->type) {
19527 + case AU_XATTR_SET:
19528 + AuDebugOn(d_is_negative(h_path.dentry));
19529 + err = vfsub_setxattr(h_path.dentry,
19530 + arg->u.set.name, arg->u.set.value,
19531 + arg->u.set.size, arg->u.set.flags);
19534 + err = -EOPNOTSUPP;
19535 + h_inode = d_inode(h_path.dentry);
19536 + if (h_inode->i_op->set_acl)
19537 + /* this will call posix_acl_update_mode */
19538 + err = h_inode->i_op->set_acl(h_inode,
19539 + arg->u.acl_set.acl,
19540 + arg->u.acl_set.type);
19544 + au_cpup_attr_timesizes(inode);
19546 + au_unpin(&a->pin);
19547 + if (unlikely(err))
19548 + au_update_dbtop(dentry);
19551 + di_write_unlock(dentry);
19552 + si_read_unlock(sb);
19554 + au_delayed_kfree(a);
19561 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19562 + unsigned int nlink)
19566 + inode->i_mode = st->mode;
19567 + /* don't i_[ug]id_write() here */
19568 + inode->i_uid = st->uid;
19569 + inode->i_gid = st->gid;
19570 + inode->i_atime = st->atime;
19571 + inode->i_mtime = st->mtime;
19572 + inode->i_ctime = st->ctime;
19574 + au_cpup_attr_nlink(inode, /*force*/0);
19575 + if (S_ISDIR(inode->i_mode)) {
19576 + n = inode->i_nlink;
19579 + smp_mb(); /* for i_nlink */
19580 + /* 0 can happen */
19581 + set_nlink(inode, n);
19584 + spin_lock(&inode->i_lock);
19585 + inode->i_blocks = st->blocks;
19586 + i_size_write(inode, st->size);
19587 + spin_unlock(&inode->i_lock);
19591 + * common routine for aufs_getattr() and au_getxattr().
19592 + * returns zero or negative (an error).
19593 + * @dentry will be read-locked in success.
19595 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
19599 + unsigned int mnt_flags, sigen;
19600 + unsigned char udba_none;
19601 + aufs_bindex_t bindex;
19602 + struct super_block *sb, *h_sb;
19603 + struct inode *inode;
19605 + h_path->mnt = NULL;
19606 + h_path->dentry = NULL;
19609 + sb = dentry->d_sb;
19610 + mnt_flags = au_mntflags(sb);
19611 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19613 + if (unlikely(locked))
19614 + goto body; /* skip locking dinfo */
19616 + /* support fstat(2) */
19617 + if (!d_unlinked(dentry) && !udba_none) {
19618 + sigen = au_sigen(sb);
19619 + err = au_digen_test(dentry, sigen);
19621 + di_read_lock_child(dentry, AuLock_IR);
19622 + err = au_dbrange_test(dentry);
19623 + if (unlikely(err)) {
19624 + di_read_unlock(dentry, AuLock_IR);
19628 + AuDebugOn(IS_ROOT(dentry));
19629 + di_write_lock_child(dentry);
19630 + err = au_dbrange_test(dentry);
19632 + err = au_reval_for_attr(dentry, sigen);
19634 + di_downgrade_lock(dentry, AuLock_IR);
19636 + di_write_unlock(dentry);
19641 + di_read_lock_child(dentry, AuLock_IR);
19644 + inode = d_inode(dentry);
19645 + bindex = au_ibtop(inode);
19646 + h_path->mnt = au_sbr_mnt(sb, bindex);
19647 + h_sb = h_path->mnt->mnt_sb;
19649 + && !au_test_fs_bad_iattr(h_sb)
19651 + goto out; /* success */
19653 + if (au_dbtop(dentry) == bindex)
19654 + h_path->dentry = au_h_dptr(dentry, bindex);
19655 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19656 + h_path->dentry = au_plink_lkup(inode, bindex);
19657 + if (IS_ERR(h_path->dentry))
19658 + /* pretending success */
19659 + h_path->dentry = NULL;
19661 + dput(h_path->dentry);
19668 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19669 + struct dentry *dentry, struct kstat *st)
19672 + unsigned char positive;
19673 + struct path h_path;
19674 + struct inode *inode;
19675 + struct super_block *sb;
19677 + inode = d_inode(dentry);
19678 + sb = dentry->d_sb;
19679 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19680 + if (unlikely(err))
19682 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
19683 + if (unlikely(err))
19685 + if (unlikely(!h_path.dentry))
19686 + /* illegally overlapped or something */
19687 + goto out_fill; /* pretending success */
19689 + positive = d_is_positive(h_path.dentry);
19691 + err = vfs_getattr(&h_path, st);
19694 + au_refresh_iattr(inode, st,
19695 + d_inode(h_path.dentry)->i_nlink);
19696 + goto out_fill; /* success */
19702 + generic_fillattr(inode, st);
19704 + di_read_unlock(dentry, AuLock_IR);
19706 + si_read_unlock(sb);
19712 +/* ---------------------------------------------------------------------- */
19714 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19715 + struct delayed_call *done)
19718 + struct dentry *h_dentry;
19719 + struct inode *h_inode;
19721 + aufs_bindex_t bindex;
19723 + ret = NULL; /* suppress a warning */
19728 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19729 + if (unlikely(err))
19732 + err = au_d_hashed_positive(dentry);
19733 + if (unlikely(err))
19737 + inode = d_inode(dentry);
19738 + bindex = au_ibtop(inode);
19739 + h_inode = au_h_iptr(inode, bindex);
19740 + if (unlikely(!h_inode->i_op->get_link))
19745 + if (au_dbtop(dentry) <= bindex) {
19746 + h_dentry = au_h_dptr(dentry, bindex);
19751 + h_dentry = d_find_any_alias(h_inode);
19752 + if (IS_ERR(h_dentry)) {
19753 + err = PTR_ERR(h_dentry);
19757 + if (unlikely(!h_dentry))
19761 + AuDbg("%pf\n", h_inode->i_op->get_link);
19762 + AuDbgDentry(h_dentry);
19763 + ret = vfs_get_link(h_dentry, done);
19766 + err = PTR_ERR(ret);
19769 + aufs_read_unlock(dentry, AuLock_IR);
19771 + if (unlikely(err))
19772 + ret = ERR_PTR(err);
19773 + AuTraceErrPtr(ret);
19777 +/* ---------------------------------------------------------------------- */
19779 +static int au_is_special(struct inode *inode)
19781 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19784 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19787 + aufs_bindex_t bindex;
19788 + struct super_block *sb;
19789 + struct inode *h_inode;
19790 + struct vfsmount *h_mnt;
19792 + sb = inode->i_sb;
19793 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19794 + "unexpected s_flags 0x%lx", sb->s_flags);
19796 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19798 + si_read_lock(sb, AuLock_FLUSH);
19799 + ii_write_lock_child(inode);
19803 + bindex = au_ibtop(inode);
19804 + h_inode = au_h_iptr(inode, bindex);
19805 + if (!au_test_ro(sb, bindex, inode)) {
19806 + h_mnt = au_sbr_mnt(sb, bindex);
19807 + err = vfsub_mnt_want_write(h_mnt);
19809 + err = vfsub_update_time(h_inode, ts, flags);
19810 + vfsub_mnt_drop_write(h_mnt);
19812 + } else if (au_is_special(h_inode)) {
19814 + * Never copy-up here.
19815 + * These special files may already be opened and used for
19816 + * communicating. If we copied it up, then the communication
19817 + * would be corrupted.
19819 + AuWarn1("timestamps for i%lu are ignored "
19820 + "since it is on readonly branch (hi%lu).\n",
19821 + inode->i_ino, h_inode->i_ino);
19822 + } else if (flags & ~S_ATIME) {
19824 + AuIOErr1("unexpected flags 0x%x\n", flags);
19830 + au_cpup_attr_timesizes(inode);
19831 + ii_write_unlock(inode);
19832 + si_read_unlock(sb);
19835 + if (!err && (flags & S_VERSION))
19836 + inode_inc_iversion(inode);
19841 +/* ---------------------------------------------------------------------- */
19843 +/* no getattr version will be set by module.c:aufs_init() */
19844 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19846 + [AuIop_SYMLINK] = {
19847 + .permission = aufs_permission,
19848 +#ifdef CONFIG_FS_POSIX_ACL
19849 + .get_acl = aufs_get_acl,
19850 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19853 + .setattr = aufs_setattr,
19854 + .getattr = aufs_getattr,
19856 +#ifdef CONFIG_AUFS_XATTR
19857 + .listxattr = aufs_listxattr,
19860 + .get_link = aufs_get_link,
19862 + /* .update_time = aufs_update_time */
19865 + .create = aufs_create,
19866 + .lookup = aufs_lookup,
19867 + .link = aufs_link,
19868 + .unlink = aufs_unlink,
19869 + .symlink = aufs_symlink,
19870 + .mkdir = aufs_mkdir,
19871 + .rmdir = aufs_rmdir,
19872 + .mknod = aufs_mknod,
19873 + .rename = aufs_rename,
19875 + .permission = aufs_permission,
19876 +#ifdef CONFIG_FS_POSIX_ACL
19877 + .get_acl = aufs_get_acl,
19878 + .set_acl = aufs_set_acl,
19881 + .setattr = aufs_setattr,
19882 + .getattr = aufs_getattr,
19884 +#ifdef CONFIG_AUFS_XATTR
19885 + .listxattr = aufs_listxattr,
19888 + .update_time = aufs_update_time,
19889 + .atomic_open = aufs_atomic_open,
19890 + .tmpfile = aufs_tmpfile
19892 + [AuIop_OTHER] = {
19893 + .permission = aufs_permission,
19894 +#ifdef CONFIG_FS_POSIX_ACL
19895 + .get_acl = aufs_get_acl,
19896 + .set_acl = aufs_set_acl,
19899 + .setattr = aufs_setattr,
19900 + .getattr = aufs_getattr,
19902 +#ifdef CONFIG_AUFS_XATTR
19903 + .listxattr = aufs_listxattr,
19906 + .update_time = aufs_update_time
19909 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19910 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19911 +++ linux/fs/aufs/i_op_del.c 2017-03-02 14:24:13.863589061 +0100
19914 + * Copyright (C) 2005-2017 Junjiro R. Okajima
19916 + * This program, aufs is free software; you can redistribute it and/or modify
19917 + * it under the terms of the GNU General Public License as published by
19918 + * the Free Software Foundation; either version 2 of the License, or
19919 + * (at your option) any later version.
19921 + * This program is distributed in the hope that it will be useful,
19922 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19923 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19924 + * GNU General Public License for more details.
19926 + * You should have received a copy of the GNU General Public License
19927 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19931 + * inode operations (del entry)
19937 + * decide if a new whiteout for @dentry is necessary or not.
19938 + * when it is necessary, prepare the parent dir for the upper branch whose
19939 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19940 + * be done by caller.
19942 + * 0: wh is unnecessary
19943 + * plus: wh is necessary
19946 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19948 + int need_wh, err;
19949 + aufs_bindex_t btop;
19950 + struct super_block *sb;
19952 + sb = dentry->d_sb;
19953 + btop = au_dbtop(dentry);
19954 + if (*bcpup < 0) {
19956 + if (au_test_ro(sb, btop, d_inode(dentry))) {
19957 + err = AuWbrCopyup(au_sbi(sb), dentry);
19959 + if (unlikely(err < 0))
19963 + AuDebugOn(btop < *bcpup
19964 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19965 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
19967 + if (*bcpup != btop) {
19968 + err = au_cpup_dirs(dentry, *bcpup);
19969 + if (unlikely(err))
19973 + struct au_dinfo *dinfo, *tmp;
19975 + need_wh = -ENOMEM;
19976 + dinfo = au_di(dentry);
19977 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19979 + au_di_cp(tmp, dinfo);
19980 + au_di_swap(tmp, dinfo);
19981 + /* returns the number of positive dentries */
19982 + need_wh = au_lkup_dentry(dentry, btop + 1,
19983 + /* AuLkup_IGNORE_PERM */ 0);
19984 + au_di_swap(tmp, dinfo);
19985 + au_rw_write_unlock(&tmp->di_rwsem);
19989 + AuDbg("need_wh %d\n", need_wh);
19997 + * simple tests for the del-entry operations.
19998 + * following the checks in vfs, plus the parent-child relationship.
20000 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20001 + struct dentry *h_parent, int isdir)
20005 + struct dentry *h_dentry, *h_latest;
20006 + struct inode *h_inode;
20008 + h_dentry = au_h_dptr(dentry, bindex);
20009 + if (d_really_is_positive(dentry)) {
20011 + if (unlikely(d_is_negative(h_dentry)))
20013 + h_inode = d_inode(h_dentry);
20014 + if (unlikely(!h_inode->i_nlink))
20017 + h_mode = h_inode->i_mode;
20020 + if (unlikely(S_ISDIR(h_mode)))
20022 + } else if (unlikely(!S_ISDIR(h_mode))) {
20027 + /* rename(2) case */
20029 + if (unlikely(d_is_positive(h_dentry)))
20034 + /* expected parent dir is locked */
20035 + if (unlikely(h_parent != h_dentry->d_parent))
20040 + * rmdir a dir may break the consistency on some filesystem.
20041 + * let's try heavy test.
20044 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20045 + && au_test_h_perm(d_inode(h_parent),
20046 + MAY_EXEC | MAY_WRITE)))
20049 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20051 + if (IS_ERR(h_latest))
20053 + if (h_latest == h_dentry)
20062 + * decide the branch where we operate for @dentry. the branch index will be set
20063 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20064 + * dir for reverting.
20065 + * when a new whiteout is necessary, create it.
20067 +static struct dentry*
20068 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20069 + struct au_dtime *dt, struct au_pin *pin)
20071 + struct dentry *wh_dentry;
20072 + struct super_block *sb;
20073 + struct path h_path;
20074 + int err, need_wh;
20075 + unsigned int udba;
20076 + aufs_bindex_t bcpup;
20078 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20079 + wh_dentry = ERR_PTR(need_wh);
20080 + if (unlikely(need_wh < 0))
20083 + sb = dentry->d_sb;
20084 + udba = au_opt_udba(sb);
20086 + err = au_pin(pin, dentry, bcpup, udba,
20087 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20088 + wh_dentry = ERR_PTR(err);
20089 + if (unlikely(err))
20092 + h_path.dentry = au_pinned_h_parent(pin);
20093 + if (udba != AuOpt_UDBA_NONE
20094 + && au_dbtop(dentry) == bcpup) {
20095 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20096 + wh_dentry = ERR_PTR(err);
20097 + if (unlikely(err))
20101 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20102 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20103 + wh_dentry = NULL;
20105 + goto out; /* success, no need to create whiteout */
20107 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20108 + if (IS_ERR(wh_dentry))
20111 + /* returns with the parent is locked and wh_dentry is dget-ed */
20112 + goto out; /* success */
20117 + return wh_dentry;
20121 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20122 + * in order to be revertible and save time for removing many child whiteouts
20124 + * returns 1 when there are too many child whiteout and caller should remove
20125 + * them asynchronously. returns 0 when the number of children is enough small to
20126 + * remove now or the branch fs is a remote fs.
20127 + * otherwise return an error.
20129 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20130 + struct au_nhash *whlist, struct inode *dir)
20132 + int rmdir_later, err, dirwh;
20133 + struct dentry *h_dentry;
20134 + struct super_block *sb;
20135 + struct inode *inode;
20137 + sb = dentry->d_sb;
20138 + SiMustAnyLock(sb);
20139 + h_dentry = au_h_dptr(dentry, bindex);
20140 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20141 + if (unlikely(err))
20144 + /* stop monitoring */
20145 + inode = d_inode(dentry);
20146 + au_hn_free(au_hi(inode, bindex));
20148 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20149 + dirwh = au_sbi(sb)->si_dirwh;
20150 + rmdir_later = (dirwh <= 1);
20151 + if (!rmdir_later)
20152 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20155 + return rmdir_later;
20158 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20159 + if (unlikely(err)) {
20160 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20161 + h_dentry, bindex, err);
20171 + * final procedure for deleting a entry.
20172 + * maintain dentry and iattr.
20174 +static void epilog(struct inode *dir, struct dentry *dentry,
20175 + aufs_bindex_t bindex)
20177 + struct inode *inode;
20179 + inode = d_inode(dentry);
20181 + inode->i_ctime = dir->i_ctime;
20183 + au_dir_ts(dir, bindex);
20184 + dir->i_version++;
20188 + * when an error happened, remove the created whiteout and revert everything.
20190 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20191 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20192 + struct dentry *dentry, struct au_dtime *dt)
20195 + struct path h_path = {
20196 + .dentry = wh_dentry,
20197 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20200 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20202 + au_set_dbwh(dentry, bwh);
20203 + au_dtime_revert(dt);
20207 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20211 +/* ---------------------------------------------------------------------- */
20213 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20216 + aufs_bindex_t bwh, bindex, btop;
20217 + struct inode *inode, *h_dir, *delegated;
20218 + struct dentry *parent, *wh_dentry;
20219 + /* to reuduce stack size */
20221 + struct au_dtime dt;
20222 + struct au_pin pin;
20223 + struct path h_path;
20229 + a = kmalloc(sizeof(*a), GFP_NOFS);
20230 + if (unlikely(!a))
20233 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20234 + if (unlikely(err))
20236 + err = au_d_hashed_positive(dentry);
20237 + if (unlikely(err))
20239 + inode = d_inode(dentry);
20240 + IMustLock(inode);
20242 + if (unlikely(d_is_dir(dentry)))
20243 + goto out_unlock; /* possible? */
20245 + btop = au_dbtop(dentry);
20246 + bwh = au_dbwh(dentry);
20248 + parent = dentry->d_parent; /* dir inode is locked */
20249 + di_write_lock_parent(parent);
20250 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20252 + err = PTR_ERR(wh_dentry);
20253 + if (IS_ERR(wh_dentry))
20256 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20257 + a->h_path.dentry = au_h_dptr(dentry, btop);
20258 + dget(a->h_path.dentry);
20259 + if (bindex == btop) {
20260 + h_dir = au_pinned_h_dir(&a->pin);
20261 + delegated = NULL;
20262 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20263 + if (unlikely(err == -EWOULDBLOCK)) {
20264 + pr_warn("cannot retry for NFSv4 delegation"
20265 + " for an internal unlink\n");
20269 + /* dir inode is locked */
20270 + h_dir = d_inode(wh_dentry->d_parent);
20271 + IMustLock(h_dir);
20276 + vfsub_drop_nlink(inode);
20277 + epilog(dir, dentry, bindex);
20279 + /* update target timestamps */
20280 + if (bindex == btop) {
20281 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20283 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20285 + /* todo: this timestamp may be reverted later */
20286 + inode->i_ctime = h_dir->i_ctime;
20287 + goto out_unpin; /* success */
20294 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20301 + au_unpin(&a->pin);
20303 + dput(a->h_path.dentry);
20305 + di_write_unlock(parent);
20307 + aufs_read_unlock(dentry, AuLock_DW);
20309 + au_delayed_kfree(a);
20314 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20316 + int err, rmdir_later;
20317 + aufs_bindex_t bwh, bindex, btop;
20318 + struct inode *inode;
20319 + struct dentry *parent, *wh_dentry, *h_dentry;
20320 + struct au_whtmp_rmdir *args;
20321 + /* to reuduce stack size */
20323 + struct au_dtime dt;
20324 + struct au_pin pin;
20330 + a = kmalloc(sizeof(*a), GFP_NOFS);
20331 + if (unlikely(!a))
20334 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20335 + if (unlikely(err))
20337 + err = au_alive_dir(dentry);
20338 + if (unlikely(err))
20340 + inode = d_inode(dentry);
20341 + IMustLock(inode);
20343 + if (unlikely(!d_is_dir(dentry)))
20344 + goto out_unlock; /* possible? */
20347 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20348 + if (unlikely(!args))
20351 + parent = dentry->d_parent; /* dir inode is locked */
20352 + di_write_lock_parent(parent);
20353 + err = au_test_empty(dentry, &args->whlist);
20354 + if (unlikely(err))
20357 + btop = au_dbtop(dentry);
20358 + bwh = au_dbwh(dentry);
20360 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20362 + err = PTR_ERR(wh_dentry);
20363 + if (IS_ERR(wh_dentry))
20366 + h_dentry = au_h_dptr(dentry, btop);
20369 + if (bindex == btop) {
20370 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20372 + rmdir_later = err;
20376 + /* stop monitoring */
20377 + au_hn_free(au_hi(inode, btop));
20379 + /* dir inode is locked */
20380 + IMustLock(d_inode(wh_dentry->d_parent));
20385 + vfsub_dead_dir(inode);
20386 + au_set_dbdiropq(dentry, -1);
20387 + epilog(dir, dentry, bindex);
20389 + if (rmdir_later) {
20390 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20394 + goto out_unpin; /* success */
20402 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20409 + au_unpin(&a->pin);
20413 + di_write_unlock(parent);
20415 + au_whtmp_rmdir_free(args);
20417 + aufs_read_unlock(dentry, AuLock_DW);
20419 + au_delayed_kfree(a);
20424 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20425 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20426 +++ linux/fs/aufs/i_op_ren.c 2017-03-02 14:24:13.863589061 +0100
20429 + * Copyright (C) 2005-2017 Junjiro R. Okajima
20431 + * This program, aufs is free software; you can redistribute it and/or modify
20432 + * it under the terms of the GNU General Public License as published by
20433 + * the Free Software Foundation; either version 2 of the License, or
20434 + * (at your option) any later version.
20436 + * This program is distributed in the hope that it will be useful,
20437 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20438 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20439 + * GNU General Public License for more details.
20441 + * You should have received a copy of the GNU General Public License
20442 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20446 + * inode operation (rename entry)
20447 + * todo: this is crazy monster
20452 +enum { AuSRC, AuDST, AuSrcDst };
20453 +enum { AuPARENT, AuCHILD, AuParentChild };
20455 +#define AuRen_ISDIR_SRC 1
20456 +#define AuRen_ISDIR_DST (1 << 1)
20457 +#define AuRen_ISSAMEDIR (1 << 2)
20458 +#define AuRen_WHSRC (1 << 3)
20459 +#define AuRen_WHDST (1 << 4)
20460 +#define AuRen_MNT_WRITE (1 << 5)
20461 +#define AuRen_DT_DSTDIR (1 << 6)
20462 +#define AuRen_DIROPQ_SRC (1 << 7)
20463 +#define AuRen_DIROPQ_DST (1 << 8)
20464 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20465 +#define au_fset_ren(flags, name) \
20466 + do { (flags) |= AuRen_##name; } while (0)
20467 +#define au_fclr_ren(flags, name) \
20468 + do { (flags) &= ~AuRen_##name; } while (0)
20470 +struct au_ren_args {
20472 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20474 + struct inode *dir, *inode;
20475 + struct au_hinode *hdir, *hinode;
20476 + struct au_dtime dt[AuParentChild];
20477 + aufs_bindex_t btop, bdiropq;
20480 +#define src_dentry sd[AuSRC].dentry
20481 +#define src_dir sd[AuSRC].dir
20482 +#define src_inode sd[AuSRC].inode
20483 +#define src_h_dentry sd[AuSRC].h_dentry
20484 +#define src_parent sd[AuSRC].parent
20485 +#define src_h_parent sd[AuSRC].h_parent
20486 +#define src_wh_dentry sd[AuSRC].wh_dentry
20487 +#define src_hdir sd[AuSRC].hdir
20488 +#define src_hinode sd[AuSRC].hinode
20489 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20490 +#define src_dt sd[AuSRC].dt
20491 +#define src_btop sd[AuSRC].btop
20492 +#define src_bdiropq sd[AuSRC].bdiropq
20494 +#define dst_dentry sd[AuDST].dentry
20495 +#define dst_dir sd[AuDST].dir
20496 +#define dst_inode sd[AuDST].inode
20497 +#define dst_h_dentry sd[AuDST].h_dentry
20498 +#define dst_parent sd[AuDST].parent
20499 +#define dst_h_parent sd[AuDST].h_parent
20500 +#define dst_wh_dentry sd[AuDST].wh_dentry
20501 +#define dst_hdir sd[AuDST].hdir
20502 +#define dst_hinode sd[AuDST].hinode
20503 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20504 +#define dst_dt sd[AuDST].dt
20505 +#define dst_btop sd[AuDST].btop
20506 +#define dst_bdiropq sd[AuDST].bdiropq
20508 + struct dentry *h_trap;
20509 + struct au_branch *br;
20510 + struct path h_path;
20511 + struct au_nhash whlist;
20512 + aufs_bindex_t btgt, src_bwh;
20515 + unsigned short auren_flags;
20516 + unsigned char flags; /* syscall parameter */
20517 + unsigned char exchange;
20520 + struct au_whtmp_rmdir *thargs;
20521 + struct dentry *h_dst;
20524 +/* ---------------------------------------------------------------------- */
20527 + * functions for reverting.
20528 + * when an error happened in a single rename systemcall, we should revert
20529 + * everything as if nothing happened.
20530 + * we don't need to revert the copied-up/down the parent dir since they are
20534 +#define RevertFailure(fmt, ...) do { \
20535 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20536 + ##__VA_ARGS__, err, rerr); \
20540 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20543 + struct dentry *d;
20544 +#define src_or_dst(member) a->sd[idx].member
20546 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20547 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20548 + rerr = au_diropq_remove(d, a->btgt);
20549 + au_hn_inode_unlock(src_or_dst(hinode));
20550 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20552 + RevertFailure("remove diropq %pd", d);
20554 +#undef src_or_dst_
20557 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20559 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20560 + au_ren_do_rev_diropq(err, a, AuSRC);
20561 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20562 + au_ren_do_rev_diropq(err, a, AuDST);
20565 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20568 + struct inode *delegated;
20570 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20571 + a->src_h_parent);
20572 + rerr = PTR_ERR(a->h_path.dentry);
20573 + if (IS_ERR(a->h_path.dentry)) {
20574 + RevertFailure("lkup one %pd", a->src_dentry);
20578 + delegated = NULL;
20579 + rerr = vfsub_rename(a->dst_h_dir,
20580 + au_h_dptr(a->src_dentry, a->btgt),
20581 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20582 + if (unlikely(rerr == -EWOULDBLOCK)) {
20583 + pr_warn("cannot retry for NFSv4 delegation"
20584 + " for an internal rename\n");
20587 + d_drop(a->h_path.dentry);
20588 + dput(a->h_path.dentry);
20589 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20591 + RevertFailure("rename %pd", a->src_dentry);
20594 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20597 + struct inode *delegated;
20599 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20600 + a->dst_h_parent);
20601 + rerr = PTR_ERR(a->h_path.dentry);
20602 + if (IS_ERR(a->h_path.dentry)) {
20603 + RevertFailure("lkup one %pd", a->dst_dentry);
20606 + if (d_is_positive(a->h_path.dentry)) {
20607 + d_drop(a->h_path.dentry);
20608 + dput(a->h_path.dentry);
20612 + delegated = NULL;
20613 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20614 + &delegated, a->flags);
20615 + if (unlikely(rerr == -EWOULDBLOCK)) {
20616 + pr_warn("cannot retry for NFSv4 delegation"
20617 + " for an internal rename\n");
20620 + d_drop(a->h_path.dentry);
20621 + dput(a->h_path.dentry);
20623 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20625 + RevertFailure("rename %pd", a->h_dst);
20628 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20632 + a->h_path.dentry = a->src_wh_dentry;
20633 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20634 + au_set_dbwh(a->src_dentry, a->src_bwh);
20636 + RevertFailure("unlink %pd", a->src_wh_dentry);
20638 +#undef RevertFailure
20640 +/* ---------------------------------------------------------------------- */
20643 + * when we have to copyup the renaming entry, do it with the rename-target name
20644 + * in order to minimize the cost (the later actual rename is unnecessary).
20645 + * otherwise rename it on the target branch.
20647 +static int au_ren_or_cpup(struct au_ren_args *a)
20650 + struct dentry *d;
20651 + struct inode *delegated;
20653 + d = a->src_dentry;
20654 + if (au_dbtop(d) == a->btgt) {
20655 + a->h_path.dentry = a->dst_h_dentry;
20656 + AuDebugOn(au_dbtop(d) != a->btgt);
20657 + delegated = NULL;
20658 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20659 + a->dst_h_dir, &a->h_path, &delegated,
20661 + if (unlikely(err == -EWOULDBLOCK)) {
20662 + pr_warn("cannot retry for NFSv4 delegation"
20663 + " for an internal rename\n");
20669 + if (!err && a->h_dst)
20670 + /* it will be set to dinfo later */
20676 +/* cf. aufs_rmdir() */
20677 +static int au_ren_del_whtmp(struct au_ren_args *a)
20680 + struct inode *dir;
20682 + dir = a->dst_dir;
20683 + SiMustAnyLock(dir->i_sb);
20684 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20685 + au_sbi(dir->i_sb)->si_dirwh)
20686 + || au_test_fs_remote(a->h_dst->d_sb)) {
20687 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20688 + if (unlikely(err))
20689 + pr_warn("failed removing whtmp dir %pd (%d), "
20690 + "ignored.\n", a->h_dst, err);
20692 + au_nhash_wh_free(&a->thargs->whlist);
20693 + a->thargs->whlist = a->whlist;
20694 + a->whlist.nh_num = 0;
20695 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20697 + a->thargs = NULL;
20703 +/* make it 'opaque' dir. */
20704 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20707 + struct dentry *d, *diropq;
20708 +#define src_or_dst(member) a->sd[idx].member
20711 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20712 + src_or_dst(bdiropq) = au_dbdiropq(d);
20713 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20714 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20715 + diropq = au_diropq_create(d, a->btgt);
20716 + au_hn_inode_unlock(src_or_dst(hinode));
20717 + if (IS_ERR(diropq))
20718 + err = PTR_ERR(diropq);
20722 +#undef src_or_dst_
20726 +static int au_ren_diropq(struct au_ren_args *a)
20729 + unsigned char always;
20730 + struct dentry *d;
20733 + d = a->dst_dentry; /* already renamed on the branch */
20734 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20735 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20736 + && a->btgt != au_dbdiropq(a->src_dentry)
20737 + && (a->dst_wh_dentry
20738 + || a->btgt <= au_dbdiropq(d)
20739 + /* hide the lower to keep xino */
20740 + /* the lowers may not be a dir, but we hide them anyway */
20741 + || a->btgt < au_dbbot(d)
20744 + err = au_ren_do_diropq(a, AuSRC);
20745 + if (unlikely(err))
20747 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20749 + if (!a->exchange)
20750 + goto out; /* success */
20752 + d = a->src_dentry; /* already renamed on the branch */
20753 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20754 + && a->btgt != au_dbdiropq(a->dst_dentry)
20755 + && (a->btgt < au_dbdiropq(d)
20756 + || a->btgt < au_dbbot(d)
20758 + AuDbgDentry(a->src_dentry);
20759 + AuDbgDentry(a->dst_dentry);
20760 + err = au_ren_do_diropq(a, AuDST);
20761 + if (unlikely(err))
20762 + goto out_rev_src;
20763 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20765 + goto out; /* success */
20768 + AuDbg("err %d, reverting src\n", err);
20769 + au_ren_rev_diropq(err, a);
20774 +static int do_rename(struct au_ren_args *a)
20777 + struct dentry *d, *h_d;
20779 + if (!a->exchange) {
20780 + /* prepare workqueue args for asynchronous rmdir */
20781 + h_d = a->dst_h_dentry;
20782 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20783 + && d_is_positive(h_d)) {
20785 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20787 + if (unlikely(!a->thargs))
20789 + a->h_dst = dget(h_d);
20792 + /* create whiteout for src_dentry */
20793 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20794 + a->src_bwh = au_dbwh(a->src_dentry);
20795 + AuDebugOn(a->src_bwh >= 0);
20796 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20797 + a->src_h_parent);
20798 + err = PTR_ERR(a->src_wh_dentry);
20799 + if (IS_ERR(a->src_wh_dentry))
20803 + /* lookup whiteout for dentry */
20804 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20805 + h_d = au_wh_lkup(a->dst_h_parent,
20806 + &a->dst_dentry->d_name, a->br);
20807 + err = PTR_ERR(h_d);
20810 + if (d_is_negative(h_d))
20813 + a->dst_wh_dentry = h_d;
20816 + /* rename dentry to tmpwh */
20818 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20819 + if (unlikely(err))
20822 + d = a->dst_dentry;
20823 + au_set_h_dptr(d, a->btgt, NULL);
20824 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20825 + if (unlikely(err))
20827 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20831 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
20833 + /* rename by vfs_rename or cpup */
20834 + err = au_ren_or_cpup(a);
20835 + if (unlikely(err))
20836 + /* leave the copied-up one */
20839 + /* make dir opaque */
20840 + err = au_ren_diropq(a);
20841 + if (unlikely(err))
20844 + /* update target timestamps */
20845 + if (a->exchange) {
20846 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
20847 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
20848 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20849 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20851 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
20852 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20853 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20854 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20856 + if (!a->exchange) {
20857 + /* remove whiteout for dentry */
20858 + if (a->dst_wh_dentry) {
20859 + a->h_path.dentry = a->dst_wh_dentry;
20860 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20862 + if (unlikely(err))
20866 + /* remove whtmp */
20868 + au_ren_del_whtmp(a); /* ignore this error */
20870 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20873 + goto out_success;
20876 + au_ren_rev_diropq(err, a);
20878 + au_ren_rev_rename(err, a);
20882 + au_ren_rev_whtmp(err, a);
20884 + dput(a->dst_wh_dentry);
20885 + a->dst_wh_dentry = NULL;
20887 + if (a->src_wh_dentry)
20888 + au_ren_rev_whsrc(err, a);
20890 + dput(a->src_wh_dentry);
20891 + dput(a->dst_wh_dentry);
20895 + au_whtmp_rmdir_free(a->thargs);
20896 + a->thargs = NULL;
20902 +/* ---------------------------------------------------------------------- */
20905 + * test if @dentry dir can be rename destination or not.
20906 + * success means, it is a logically empty dir.
20908 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20910 + return au_test_empty(dentry, whlist);
20914 + * test if @dentry dir can be rename source or not.
20915 + * if it can, return 0 and @children is filled.
20917 + * - it is a logically empty dir.
20918 + * - or, it exists on writable branch and has no children including whiteouts
20919 + * on the lower branch.
20921 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20924 + unsigned int rdhash;
20925 + aufs_bindex_t btop;
20927 + btop = au_dbtop(dentry);
20928 + if (btop != btgt) {
20929 + struct au_nhash whlist;
20931 + SiMustAnyLock(dentry->d_sb);
20932 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20934 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20936 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20937 + if (unlikely(err))
20939 + err = au_test_empty(dentry, &whlist);
20940 + au_nhash_wh_free(&whlist);
20944 + if (btop == au_dbtaildir(dentry))
20945 + return 0; /* success */
20947 + err = au_test_empty_lower(dentry);
20950 + if (err == -ENOTEMPTY) {
20951 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20952 + " is not supported\n");
20958 +/* side effect: sets whlist and h_dentry */
20959 +static int au_ren_may_dir(struct au_ren_args *a)
20962 + unsigned int rdhash;
20963 + struct dentry *d;
20965 + d = a->dst_dentry;
20966 + SiMustAnyLock(d->d_sb);
20969 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
20970 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20972 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20973 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20974 + if (unlikely(err))
20977 + if (!a->exchange) {
20978 + au_set_dbtop(d, a->dst_btop);
20979 + err = may_rename_dstdir(d, &a->whlist);
20980 + au_set_dbtop(d, a->btgt);
20982 + err = may_rename_srcdir(d, a->btgt);
20984 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
20985 + if (unlikely(err))
20988 + d = a->src_dentry;
20989 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
20990 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
20991 + err = may_rename_srcdir(d, a->btgt);
20992 + if (unlikely(err)) {
20993 + au_nhash_wh_free(&a->whlist);
20994 + a->whlist.nh_num = 0;
21001 +/* ---------------------------------------------------------------------- */
21004 + * simple tests for rename.
21005 + * following the checks in vfs, plus the parent-child relationship.
21007 +static int au_may_ren(struct au_ren_args *a)
21010 + struct inode *h_inode;
21012 + if (a->src_btop == a->btgt) {
21013 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
21014 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
21015 + if (unlikely(err))
21018 + if (unlikely(a->src_h_dentry == a->h_trap))
21023 + if (a->dst_btop != a->btgt)
21026 + err = -ENOTEMPTY;
21027 + if (unlikely(a->dst_h_dentry == a->h_trap))
21031 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21032 + if (d_really_is_negative(a->dst_dentry)) {
21033 + if (d_is_negative(a->dst_h_dentry))
21034 + err = au_may_add(a->dst_dentry, a->btgt,
21035 + a->dst_h_parent, isdir);
21037 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21039 + h_inode = d_inode(a->dst_h_dentry);
21040 + if (h_inode->i_nlink)
21041 + err = au_may_del(a->dst_dentry, a->btgt,
21042 + a->dst_h_parent, isdir);
21046 + if (unlikely(err == -ENOENT || err == -EEXIST))
21052 +/* ---------------------------------------------------------------------- */
21057 + * - src_dir and dir by lock_rename()
21058 + * - inode if exitsts
21061 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21063 + * + di_write_lock2_child()
21064 + * + di_write_lock_child()
21065 + * + ii_write_lock_child()
21066 + * + di_write_lock_child2()
21067 + * + ii_write_lock_child2()
21068 + * + src_parent and parent
21069 + * + di_write_lock_parent()
21070 + * + ii_write_lock_parent()
21071 + * + di_write_lock_parent2()
21072 + * + ii_write_lock_parent2()
21073 + * + lower src_dir and dir by vfsub_lock_rename()
21074 + * + verify the every relationships between child and parent. if any
21075 + * of them failed, unlock all and return -EBUSY.
21077 +static void au_ren_unlock(struct au_ren_args *a)
21079 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21080 + a->dst_h_parent, a->dst_hdir);
21081 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21082 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21085 +static int au_ren_lock(struct au_ren_args *a)
21088 + unsigned int udba;
21091 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21092 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21093 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21094 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21096 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21097 + if (unlikely(err))
21099 + au_fset_ren(a->auren_flags, MNT_WRITE);
21100 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21101 + a->dst_h_parent, a->dst_hdir);
21102 + udba = au_opt_udba(a->src_dentry->d_sb);
21103 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21104 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21105 + err = au_busy_or_stale();
21106 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21107 + err = au_h_verify(a->src_h_dentry, udba,
21108 + d_inode(a->src_h_parent), a->src_h_parent,
21110 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21111 + err = au_h_verify(a->dst_h_dentry, udba,
21112 + d_inode(a->dst_h_parent), a->dst_h_parent,
21115 + goto out; /* success */
21117 + err = au_busy_or_stale();
21118 + au_ren_unlock(a);
21124 +/* ---------------------------------------------------------------------- */
21126 +static void au_ren_refresh_dir(struct au_ren_args *a)
21128 + struct inode *dir;
21130 + dir = a->dst_dir;
21131 + dir->i_version++;
21132 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21133 + /* is this updating defined in POSIX? */
21134 + au_cpup_attr_timesizes(a->src_inode);
21135 + au_cpup_attr_nlink(dir, /*force*/1);
21137 + au_dir_ts(dir, a->btgt);
21139 + if (a->exchange) {
21140 + dir = a->src_dir;
21141 + dir->i_version++;
21142 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21143 + /* is this updating defined in POSIX? */
21144 + au_cpup_attr_timesizes(a->dst_inode);
21145 + au_cpup_attr_nlink(dir, /*force*/1);
21147 + au_dir_ts(dir, a->btgt);
21150 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21153 + dir = a->src_dir;
21154 + dir->i_version++;
21155 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21156 + au_cpup_attr_nlink(dir, /*force*/1);
21157 + au_dir_ts(dir, a->btgt);
21160 +static void au_ren_refresh(struct au_ren_args *a)
21162 + aufs_bindex_t bbot, bindex;
21163 + struct dentry *d, *h_d;
21164 + struct inode *i, *h_i;
21165 + struct super_block *sb;
21167 + d = a->dst_dentry;
21170 + /* already dget-ed by au_ren_or_cpup() */
21171 + au_set_h_dptr(d, a->btgt, a->h_dst);
21173 + i = a->dst_inode;
21175 + if (!a->exchange) {
21176 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21177 + vfsub_drop_nlink(i);
21179 + vfsub_dead_dir(i);
21180 + au_cpup_attr_timesizes(i);
21182 + au_update_dbrange(d, /*do_put_zero*/1);
21184 + au_cpup_attr_nlink(i, /*force*/1);
21187 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21188 + au_set_h_dptr(d, bindex, NULL);
21189 + bbot = au_dbbot(d);
21190 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21191 + au_set_h_dptr(d, bindex, NULL);
21192 + au_update_dbrange(d, /*do_put_zero*/0);
21195 + d = a->src_dentry;
21196 + if (!a->exchange) {
21197 + au_set_dbwh(d, -1);
21198 + bbot = au_dbbot(d);
21199 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21200 + h_d = au_h_dptr(d, bindex);
21202 + au_set_h_dptr(d, bindex, NULL);
21204 + au_set_dbbot(d, a->btgt);
21207 + i = a->src_inode;
21208 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21209 + return; /* success */
21211 + bbot = au_ibbot(i);
21212 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21213 + h_i = au_h_iptr(i, bindex);
21215 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21216 + /* ignore this error */
21217 + au_set_h_iptr(i, bindex, NULL, 0);
21220 + au_set_ibbot(i, a->btgt);
21222 + d_drop(a->src_dentry);
21225 +/* ---------------------------------------------------------------------- */
21227 +/* mainly for link(2) and rename(2) */
21228 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21230 + aufs_bindex_t bdiropq, bwh;
21231 + struct dentry *parent;
21232 + struct au_branch *br;
21234 + parent = dentry->d_parent;
21235 + IMustLock(d_inode(parent)); /* dir is locked */
21237 + bdiropq = au_dbdiropq(parent);
21238 + bwh = au_dbwh(dentry);
21239 + br = au_sbr(dentry->d_sb, btgt);
21240 + if (au_br_rdonly(br)
21241 + || (0 <= bdiropq && bdiropq < btgt)
21242 + || (0 <= bwh && bwh < btgt))
21245 + AuDbg("btgt %d\n", btgt);
21249 +/* sets src_btop, dst_btop and btgt */
21250 +static int au_ren_wbr(struct au_ren_args *a)
21253 + struct au_wr_dir_args wr_dir_args = {
21254 + /* .force_btgt = -1, */
21255 + .flags = AuWrDir_ADD_ENTRY
21258 + a->src_btop = au_dbtop(a->src_dentry);
21259 + a->dst_btop = au_dbtop(a->dst_dentry);
21260 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21261 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21262 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21263 + wr_dir_args.force_btgt = a->src_btop;
21264 + if (a->dst_inode && a->dst_btop < a->src_btop)
21265 + wr_dir_args.force_btgt = a->dst_btop;
21266 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21267 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21270 + au_update_dbtop(a->dst_dentry);
21275 +static void au_ren_dt(struct au_ren_args *a)
21277 + a->h_path.dentry = a->src_h_parent;
21278 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21279 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21280 + a->h_path.dentry = a->dst_h_parent;
21281 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21284 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21285 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21289 + a->h_path.dentry = a->src_h_dentry;
21290 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21291 + if (d_is_positive(a->dst_h_dentry)) {
21292 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21293 + a->h_path.dentry = a->dst_h_dentry;
21294 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21298 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21300 + struct dentry *h_d;
21301 + struct inode *h_inode;
21303 + au_dtime_revert(a->src_dt + AuPARENT);
21304 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21305 + au_dtime_revert(a->dst_dt + AuPARENT);
21307 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21308 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21309 + h_inode = d_inode(h_d);
21310 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21311 + au_dtime_revert(a->src_dt + AuCHILD);
21312 + inode_unlock(h_inode);
21314 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21315 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21316 + h_inode = d_inode(h_d);
21317 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21318 + au_dtime_revert(a->dst_dt + AuCHILD);
21319 + inode_unlock(h_inode);
21324 +/* ---------------------------------------------------------------------- */
21326 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21327 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21328 + unsigned int _flags)
21330 + int err, lock_flags;
21331 + /* reduce stack space */
21332 + struct au_ren_args *a;
21333 + struct au_pin pin;
21335 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21336 + IMustLock(_src_dir);
21337 + IMustLock(_dst_dir);
21340 + if (unlikely(_flags & RENAME_WHITEOUT))
21344 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21345 + a = kzalloc(sizeof(*a), GFP_NOFS);
21346 + if (unlikely(!a))
21349 + a->flags = _flags;
21350 + a->exchange = _flags & RENAME_EXCHANGE;
21351 + a->src_dir = _src_dir;
21352 + a->src_dentry = _src_dentry;
21353 + a->src_inode = NULL;
21354 + if (d_really_is_positive(a->src_dentry))
21355 + a->src_inode = d_inode(a->src_dentry);
21356 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21357 + a->dst_dir = _dst_dir;
21358 + a->dst_dentry = _dst_dentry;
21359 + a->dst_inode = NULL;
21360 + if (d_really_is_positive(a->dst_dentry))
21361 + a->dst_inode = d_inode(a->dst_dentry);
21362 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21363 + if (a->dst_inode) {
21365 + * if EXCHANGE && src is non-dir && dst is dir,
21366 + * dst is not locked.
21368 + /* IMustLock(a->dst_inode); */
21369 + au_igrab(a->dst_inode);
21373 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21374 + if (d_is_dir(a->src_dentry)) {
21375 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21376 + if (unlikely(!a->exchange
21377 + && d_really_is_positive(a->dst_dentry)
21378 + && !d_is_dir(a->dst_dentry)))
21380 + lock_flags |= AuLock_DIRS;
21382 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21383 + au_fset_ren(a->auren_flags, ISDIR_DST);
21384 + if (unlikely(!a->exchange
21385 + && d_really_is_positive(a->src_dentry)
21386 + && !d_is_dir(a->src_dentry)))
21388 + lock_flags |= AuLock_DIRS;
21390 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21391 + if (unlikely(err))
21394 + err = au_d_hashed_positive(a->src_dentry);
21395 + if (unlikely(err))
21398 + if (a->dst_inode) {
21400 + * If it is a dir, VFS unhash it before this
21401 + * function. It means we cannot rely upon d_unhashed().
21403 + if (unlikely(!a->dst_inode->i_nlink))
21405 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21406 + err = au_d_hashed_positive(a->dst_dentry);
21407 + if (unlikely(err && !a->exchange))
21409 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21411 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21415 + * is it possible?
21416 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21417 + * there may exist a problem somewhere else.
21420 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21423 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21424 + di_write_lock_parent(a->dst_parent);
21426 + /* which branch we process */
21427 + err = au_ren_wbr(a);
21428 + if (unlikely(err < 0))
21430 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21431 + a->h_path.mnt = au_br_mnt(a->br);
21433 + /* are they available to be renamed */
21434 + err = au_ren_may_dir(a);
21435 + if (unlikely(err))
21436 + goto out_children;
21438 + /* prepare the writable parent dir on the same branch */
21439 + if (a->dst_btop == a->btgt) {
21440 + au_fset_ren(a->auren_flags, WHDST);
21442 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21443 + if (unlikely(err))
21444 + goto out_children;
21448 + if (!a->exchange) {
21449 + if (a->src_dir != a->dst_dir) {
21451 + * this temporary unlock is safe,
21452 + * because both dir->i_mutex are locked.
21454 + di_write_unlock(a->dst_parent);
21455 + di_write_lock_parent(a->src_parent);
21456 + err = au_wr_dir_need_wh(a->src_dentry,
21457 + au_ftest_ren(a->auren_flags,
21460 + di_write_unlock(a->src_parent);
21461 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21463 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21465 + err = au_wr_dir_need_wh(a->src_dentry,
21466 + au_ftest_ren(a->auren_flags,
21470 + if (unlikely(err < 0))
21471 + goto out_children;
21473 + au_fset_ren(a->auren_flags, WHSRC);
21476 + if (a->src_btop != a->btgt) {
21477 + err = au_pin(&pin, a->src_dentry, a->btgt,
21478 + au_opt_udba(a->src_dentry->d_sb),
21479 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21481 + struct au_cp_generic cpg = {
21482 + .dentry = a->src_dentry,
21484 + .bsrc = a->src_btop,
21487 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21489 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21490 + err = au_sio_cpup_simple(&cpg);
21493 + if (unlikely(err))
21494 + goto out_children;
21495 + a->src_btop = a->btgt;
21496 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21497 + if (!a->exchange)
21498 + au_fset_ren(a->auren_flags, WHSRC);
21502 + if (a->exchange && a->dst_inode
21503 + && a->dst_btop != a->btgt) {
21504 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21505 + au_opt_udba(a->dst_dentry->d_sb),
21506 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21508 + struct au_cp_generic cpg = {
21509 + .dentry = a->dst_dentry,
21511 + .bsrc = a->dst_btop,
21514 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21516 + err = au_sio_cpup_simple(&cpg);
21519 + if (unlikely(err))
21520 + goto out_children;
21521 + a->dst_btop = a->btgt;
21522 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21525 + /* lock them all */
21526 + err = au_ren_lock(a);
21527 + if (unlikely(err))
21528 + /* leave the copied-up one */
21529 + goto out_children;
21531 + if (!a->exchange) {
21532 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21533 + err = au_may_ren(a);
21534 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21535 + err = -ENAMETOOLONG;
21536 + if (unlikely(err))
21540 + /* store timestamps to be revertible */
21544 + err = do_rename(a);
21545 + if (unlikely(err))
21548 + /* update dir attributes */
21549 + au_ren_refresh_dir(a);
21551 + /* dput/iput all lower dentries */
21552 + au_ren_refresh(a);
21554 + goto out_hdir; /* success */
21557 + au_ren_rev_dt(err, a);
21559 + au_ren_unlock(a);
21561 + au_nhash_wh_free(&a->whlist);
21562 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21563 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21564 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21565 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21569 + if (!a->exchange)
21570 + d_move(a->src_dentry, a->dst_dentry);
21572 + d_exchange(a->src_dentry, a->dst_dentry);
21574 + au_update_dbtop(a->dst_dentry);
21575 + if (!a->dst_inode)
21576 + d_drop(a->dst_dentry);
21578 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21579 + di_write_unlock(a->dst_parent);
21581 + di_write_unlock2(a->src_parent, a->dst_parent);
21583 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21585 + iput(a->dst_inode);
21587 + au_whtmp_rmdir_free(a->thargs);
21588 + au_delayed_kfree(a);
21593 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21594 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21595 +++ linux/fs/aufs/Kconfig 2016-10-09 16:55:36.482701377 +0200
21598 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21600 + Aufs is a stackable unification filesystem such as Unionfs,
21601 + which unifies several directories and provides a merged single
21603 + In the early days, aufs was entirely re-designed and
21604 + re-implemented Unionfs Version 1.x series. Introducing many
21605 + original ideas, approaches and improvements, it becomes totally
21606 + different from Unionfs while keeping the basic features.
21610 + prompt "Maximum number of branches"
21611 + default AUFS_BRANCH_MAX_127
21613 + Specifies the maximum number of branches (or member directories)
21614 + in a single aufs. The larger value consumes more system
21615 + resources and has a minor impact to performance.
21616 +config AUFS_BRANCH_MAX_127
21619 + Specifies the maximum number of branches (or member directories)
21620 + in a single aufs. The larger value consumes more system
21621 + resources and has a minor impact to performance.
21622 +config AUFS_BRANCH_MAX_511
21625 + Specifies the maximum number of branches (or member directories)
21626 + in a single aufs. The larger value consumes more system
21627 + resources and has a minor impact to performance.
21628 +config AUFS_BRANCH_MAX_1023
21631 + Specifies the maximum number of branches (or member directories)
21632 + in a single aufs. The larger value consumes more system
21633 + resources and has a minor impact to performance.
21634 +config AUFS_BRANCH_MAX_32767
21637 + Specifies the maximum number of branches (or member directories)
21638 + in a single aufs. The larger value consumes more system
21639 + resources and has a minor impact to performance.
21642 +config AUFS_SBILIST
21644 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21647 + Automatic configuration for internal use.
21648 + When aufs supports Magic SysRq or /proc, enabled automatically.
21650 +config AUFS_HNOTIFY
21651 + bool "Detect direct branch access (bypassing aufs)"
21653 + If you want to modify files on branches directly, eg. bypassing aufs,
21654 + and want aufs to detect the changes of them fully, then enable this
21655 + option and use 'udba=notify' mount option.
21656 + Currently there is only one available configuration, "fsnotify".
21657 + It will have a negative impact to the performance.
21658 + See detail in aufs.5.
21661 + prompt "method" if AUFS_HNOTIFY
21662 + default AUFS_HFSNOTIFY
21663 +config AUFS_HFSNOTIFY
21668 +config AUFS_EXPORT
21669 + bool "NFS-exportable aufs"
21670 + depends on EXPORTFS
21672 + If you want to export your mounted aufs via NFS, then enable this
21673 + option. There are several requirements for this configuration.
21674 + See detail in aufs.5.
21676 +config AUFS_INO_T_64
21678 + depends on AUFS_EXPORT
21679 + depends on 64BIT && !(ALPHA || S390)
21682 + Automatic configuration for internal use.
21683 + /* typedef unsigned long/int __kernel_ino_t */
21684 + /* alpha and s390x are int */
21687 + bool "support for XATTR/EA (including Security Labels)"
21689 + If your branch fs supports XATTR/EA and you want to make them
21690 + available in aufs too, then enable this opsion and specify the
21691 + branch attributes for EA.
21692 + See detail in aufs.5.
21695 + bool "File-based Hierarchical Storage Management"
21697 + Hierarchical Storage Management (or HSM) is a well-known feature
21698 + in the storage world. Aufs provides this feature as file-based.
21699 + with multiple branches.
21700 + These multiple branches are prioritized, ie. the topmost one
21701 + should be the fastest drive and be used heavily.
21704 + bool "Readdir in userspace"
21706 + Aufs has two methods to provide a merged view for a directory,
21707 + by a user-space library and by kernel-space natively. The latter
21708 + is always enabled but sometimes large and slow.
21709 + If you enable this option, install the library in aufs2-util
21710 + package, and set some environment variables for your readdir(3),
21711 + then the work will be handled in user-space which generally
21712 + shows better performance in most cases.
21713 + See detail in aufs.5.
21716 + bool "Show whiteouts"
21718 + If you want to make the whiteouts in aufs visible, then enable
21719 + this option and specify 'shwh' mount option. Although it may
21720 + sounds like philosophy or something, but in technically it
21721 + simply shows the name of whiteout with keeping its behaviour.
21723 +config AUFS_BR_RAMFS
21724 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21726 + If you want to use ramfs as an aufs branch fs, then enable this
21727 + option. Generally tmpfs is recommended.
21728 + Aufs prohibited them to be a branch fs by default, because
21729 + initramfs becomes unusable after switch_root or something
21730 + generally. If you sets initramfs as an aufs branch and boot your
21731 + system by switch_root, you will meet a problem easily since the
21732 + files in initramfs may be inaccessible.
21733 + Unless you are going to use ramfs as an aufs branch fs without
21734 + switch_root or something, leave it N.
21736 +config AUFS_BR_FUSE
21737 + bool "Fuse fs as an aufs branch"
21738 + depends on FUSE_FS
21741 + If you want to use fuse-based userspace filesystem as an aufs
21742 + branch fs, then enable this option.
21743 + It implements the internal poll(2) operation which is
21744 + implemented by fuse only (curretnly).
21749 + Automatic configuration for internal use.
21751 +config AUFS_BR_HFSPLUS
21752 + bool "Hfsplus as an aufs branch"
21753 + depends on HFSPLUS_FS
21756 + If you want to use hfsplus fs as an aufs branch fs, then enable
21757 + this option. This option introduces a small overhead at
21758 + copying-up a file on hfsplus.
21760 +config AUFS_BDEV_LOOP
21762 + depends on BLK_DEV_LOOP
21765 + Automatic configuration for internal use.
21766 + Convert =[ym] into =y.
21769 + bool "Debug aufs"
21771 + Enable this to compile aufs internal debug code.
21772 + It will have a negative impact to the performance.
21774 +config AUFS_MAGIC_SYSRQ
21776 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21779 + Automatic configuration for internal use.
21780 + When aufs supports Magic SysRq, enabled automatically.
21782 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21783 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21784 +++ linux/fs/aufs/loop.c 2017-03-02 14:24:13.863589061 +0100
21787 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21789 + * This program, aufs is free software; you can redistribute it and/or modify
21790 + * it under the terms of the GNU General Public License as published by
21791 + * the Free Software Foundation; either version 2 of the License, or
21792 + * (at your option) any later version.
21794 + * This program is distributed in the hope that it will be useful,
21795 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21796 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21797 + * GNU General Public License for more details.
21799 + * You should have received a copy of the GNU General Public License
21800 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21804 + * support for loopback block device as a branch
21809 +/* added into drivers/block/loop.c */
21810 +static struct file *(*backing_file_func)(struct super_block *sb);
21813 + * test if two lower dentries have overlapping branches.
21815 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21817 + struct super_block *h_sb;
21818 + struct file *backing_file;
21820 + if (unlikely(!backing_file_func)) {
21821 + /* don't load "loop" module here */
21822 + backing_file_func = symbol_get(loop_backing_file);
21823 + if (unlikely(!backing_file_func))
21824 + /* "loop" module is not loaded */
21828 + h_sb = h_adding->d_sb;
21829 + backing_file = backing_file_func(h_sb);
21830 + if (!backing_file)
21833 + h_adding = backing_file->f_path.dentry;
21835 + * h_adding can be local NFS.
21836 + * in this case aufs cannot detect the loop.
21838 + if (unlikely(h_adding->d_sb == sb))
21840 + return !!au_test_subdir(h_adding, sb->s_root);
21843 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21844 +int au_test_loopback_kthread(void)
21847 + struct task_struct *tsk = current;
21848 + char c, comm[sizeof(tsk->comm)];
21851 + if (tsk->flags & PF_KTHREAD) {
21852 + get_task_comm(comm, tsk);
21854 + ret = ('0' <= c && c <= '9'
21855 + && !strncmp(comm, "loop", 4));
21861 +/* ---------------------------------------------------------------------- */
21863 +#define au_warn_loopback_step 16
21864 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21865 +static unsigned long *au_warn_loopback_array;
21867 +void au_warn_loopback(struct super_block *h_sb)
21869 + int i, new_nelem;
21870 + unsigned long *a, magic;
21871 + static DEFINE_SPINLOCK(spin);
21873 + magic = h_sb->s_magic;
21874 + spin_lock(&spin);
21875 + a = au_warn_loopback_array;
21876 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21877 + if (a[i] == magic) {
21878 + spin_unlock(&spin);
21882 + /* h_sb is new to us, print it */
21883 + if (i < au_warn_loopback_nelem) {
21888 + /* expand the array */
21889 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21890 + a = au_kzrealloc(au_warn_loopback_array,
21891 + au_warn_loopback_nelem * sizeof(unsigned long),
21892 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
21893 + /*may_shrink*/0);
21895 + au_warn_loopback_nelem = new_nelem;
21896 + au_warn_loopback_array = a;
21901 + spin_unlock(&spin);
21902 + AuWarn1("realloc failed, ignored\n");
21906 + spin_unlock(&spin);
21907 + pr_warn("you may want to try another patch for loopback file "
21908 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21911 +int au_loopback_init(void)
21914 + struct super_block *sb __maybe_unused;
21916 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21919 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21920 + sizeof(unsigned long), GFP_NOFS);
21921 + if (unlikely(!au_warn_loopback_array))
21927 +void au_loopback_fin(void)
21929 + if (backing_file_func)
21930 + symbol_put(loop_backing_file);
21931 + au_delayed_kfree(au_warn_loopback_array);
21933 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21934 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21935 +++ linux/fs/aufs/loop.h 2017-03-02 14:24:13.863589061 +0100
21938 + * Copyright (C) 2005-2017 Junjiro R. Okajima
21940 + * This program, aufs is free software; you can redistribute it and/or modify
21941 + * it under the terms of the GNU General Public License as published by
21942 + * the Free Software Foundation; either version 2 of the License, or
21943 + * (at your option) any later version.
21945 + * This program is distributed in the hope that it will be useful,
21946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21948 + * GNU General Public License for more details.
21950 + * You should have received a copy of the GNU General Public License
21951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21955 + * support for loopback mount as a branch
21958 +#ifndef __AUFS_LOOP_H__
21959 +#define __AUFS_LOOP_H__
21964 +struct super_block;
21966 +#ifdef CONFIG_AUFS_BDEV_LOOP
21967 +/* drivers/block/loop.c */
21968 +struct file *loop_backing_file(struct super_block *sb);
21971 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21972 +int au_test_loopback_kthread(void);
21973 +void au_warn_loopback(struct super_block *h_sb);
21975 +int au_loopback_init(void);
21976 +void au_loopback_fin(void);
21978 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21979 + struct dentry *h_adding)
21980 +AuStubInt0(au_test_loopback_kthread, void)
21981 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21983 +AuStubInt0(au_loopback_init, void)
21984 +AuStubVoid(au_loopback_fin, void)
21985 +#endif /* BLK_DEV_LOOP */
21987 +#endif /* __KERNEL__ */
21988 +#endif /* __AUFS_LOOP_H__ */
21989 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21990 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21991 +++ linux/fs/aufs/magic.mk 2016-10-09 16:55:36.492701639 +0200
21994 +# defined in ${srctree}/fs/fuse/inode.c
21996 +ifdef CONFIG_FUSE_FS
21997 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
22000 +# defined in ${srctree}/fs/xfs/xfs_sb.h
22002 +ifdef CONFIG_XFS_FS
22003 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
22006 +# defined in ${srctree}/fs/configfs/mount.c
22008 +ifdef CONFIG_CONFIGFS_FS
22009 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
22012 +# defined in ${srctree}/fs/ubifs/ubifs.h
22014 +ifdef CONFIG_UBIFS_FS
22015 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
22018 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22020 +ifdef CONFIG_HFSPLUS_FS
22021 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22023 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22024 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22025 +++ linux/fs/aufs/Makefile 2016-10-09 16:55:36.486034798 +0200
22028 +include ${src}/magic.mk
22029 +ifeq (${CONFIG_AUFS_FS},m)
22030 +include ${src}/conf.mk
22032 +-include ${src}/priv_def.mk
22034 +# cf. include/linux/kernel.h
22036 +ccflags-y += -DDEBUG
22037 +# sparse requires the full pathname
22039 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22041 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22044 +obj-$(CONFIG_AUFS_FS) += aufs.o
22045 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22046 + wkq.o vfsub.o dcsub.o \
22047 + cpup.o whout.o wbr_policy.o \
22048 + dinfo.o dentry.o \
22050 + finfo.o file.o f_op.o \
22052 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22056 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22057 +aufs-$(CONFIG_SYSFS) += sysfs.o
22058 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22059 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22060 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22061 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22062 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22063 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22064 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22065 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22066 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22067 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22068 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22069 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22070 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22071 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22072 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22073 +++ linux/fs/aufs/module.c 2017-03-02 14:24:13.863589061 +0100
22076 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22078 + * This program, aufs is free software; you can redistribute it and/or modify
22079 + * it under the terms of the GNU General Public License as published by
22080 + * the Free Software Foundation; either version 2 of the License, or
22081 + * (at your option) any later version.
22083 + * This program is distributed in the hope that it will be useful,
22084 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22086 + * GNU General Public License for more details.
22088 + * You should have received a copy of the GNU General Public License
22089 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22093 + * module global variables and operations
22096 +#include <linux/module.h>
22097 +#include <linux/seq_file.h>
22100 +/* shrinkable realloc */
22101 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22109 +#if 0 /* unused */
22111 + au_delayed_kfree(p);
22116 + AuDebugOn(!new_sz);
22119 + diff = au_kmidx_sub(sz, new_sz);
22125 + /* expand or SLOB */
22126 + p = krealloc(p, new_sz, gfp);
22127 + else if (new_sz < sz && may_shrink) {
22131 + q = kmalloc(new_sz, gfp);
22134 + memcpy(q, p, new_sz);
22135 + au_delayed_kfree(p);
22146 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22149 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22150 + if (p && new_sz > nused)
22151 + memset(p + nused, 0, new_sz - nused);
22155 +/* ---------------------------------------------------------------------- */
22160 +struct au_dfree au_dfree;
22162 +/* delayed free */
22163 +static void au_do_dfree(struct work_struct *work __maybe_unused)
22165 + struct llist_head *head;
22166 + struct llist_node *node, *next;
22168 +#define AU_CACHE_DFREE_DO_BODY(name, idx, lnode) do { \
22169 + head = &au_dfree.cache[AuCache_##idx].llist; \
22170 + node = llist_del_all(head); \
22171 + for (; node; node = next) { \
22172 + struct au_##name *p \
22173 + = llist_entry(node, struct au_##name, \
22175 + next = llist_next(node); \
22176 + au_cache_free_##name(p); \
22180 + AU_CACHE_DFREE_DO_BODY(dinfo, DINFO, di_lnode);
22181 + AU_CACHE_DFREE_DO_BODY(icntnr, ICNTNR, lnode);
22182 + AU_CACHE_DFREE_DO_BODY(finfo, FINFO, fi_lnode);
22183 + AU_CACHE_DFREE_DO_BODY(vdir, VDIR, vd_lnode);
22184 + AU_CACHE_DFREE_DO_BODY(vdir_dehstr, DEHSTR, lnode);
22185 +#ifdef CONFIG_AUFS_HNOTIFY
22186 + AU_CACHE_DFREE_DO_BODY(hnotify, HNOTIFY, hn_lnode);
22189 +#define AU_DFREE_DO_BODY(llist, func) do { \
22190 + node = llist_del_all(llist); \
22191 + for (; node; node = next) { \
22192 + next = llist_next(node); \
22197 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_KFREE, kfree);
22198 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_FREE_PAGE, au_free_page);
22200 +#undef AU_CACHE_DFREE_DO_BODY
22201 +#undef AU_DFREE_DO_BODY
22204 +AU_CACHE_DFREE_FUNC(dinfo, DINFO, di_lnode);
22205 +AU_CACHE_DFREE_FUNC(icntnr, ICNTNR, lnode);
22206 +AU_CACHE_DFREE_FUNC(finfo, FINFO, fi_lnode);
22207 +AU_CACHE_DFREE_FUNC(vdir, VDIR, vd_lnode);
22208 +AU_CACHE_DFREE_FUNC(vdir_dehstr, DEHSTR, lnode);
22210 +static void au_cache_fin(void)
22213 + struct au_cache *cp;
22216 + * Make sure all delayed rcu free inodes are flushed before we
22221 + /* excluding AuCache_HNOTIFY */
22222 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22223 + flush_delayed_work(&au_dfree.dwork);
22224 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22225 + cp = au_dfree.cache + i;
22226 + AuDebugOn(!llist_empty(&cp->llist));
22227 + kmem_cache_destroy(cp->cache);
22228 + cp->cache = NULL;
22232 +static int __init au_cache_init(void)
22234 + struct au_cache *cp;
22236 + cp = au_dfree.cache;
22237 + cp[AuCache_DINFO].cache = AuCacheCtor(au_dinfo, au_di_init_once);
22238 + if (cp[AuCache_DINFO].cache)
22239 + /* SLAB_DESTROY_BY_RCU */
22240 + cp[AuCache_ICNTNR].cache = AuCacheCtor(au_icntnr,
22241 + au_icntnr_init_once);
22242 + if (cp[AuCache_ICNTNR].cache)
22243 + cp[AuCache_FINFO].cache = AuCacheCtor(au_finfo,
22244 + au_fi_init_once);
22245 + if (cp[AuCache_FINFO].cache)
22246 + cp[AuCache_VDIR].cache = AuCache(au_vdir);
22247 + if (cp[AuCache_VDIR].cache)
22248 + cp[AuCache_DEHSTR].cache = AuCache(au_vdir_dehstr);
22249 + if (cp[AuCache_DEHSTR].cache)
22256 +/* ---------------------------------------------------------------------- */
22258 +int au_dir_roflags;
22260 +#ifdef CONFIG_AUFS_SBILIST
22262 + * iterate_supers_type() doesn't protect us from
22263 + * remounting (branch management)
22265 +struct au_sphlhead au_sbilist;
22269 + * functions for module interface.
22271 +MODULE_LICENSE("GPL");
22272 +/* MODULE_LICENSE("GPL v2"); */
22273 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22274 +MODULE_DESCRIPTION(AUFS_NAME
22275 + " -- Advanced multi layered unification filesystem");
22276 +MODULE_VERSION(AUFS_VERSION);
22277 +MODULE_ALIAS_FS(AUFS_NAME);
22279 +/* this module parameter has no meaning when SYSFS is disabled */
22280 +int sysaufs_brs = 1;
22281 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22282 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22284 +/* this module parameter has no meaning when USER_NS is disabled */
22286 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22287 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22289 +/* ---------------------------------------------------------------------- */
22291 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22293 +int au_seq_path(struct seq_file *seq, struct path *path)
22297 + err = seq_path(seq, path, au_esc_chars);
22300 + else if (err < 0)
22306 +/* ---------------------------------------------------------------------- */
22308 +static int __init aufs_init(void)
22312 + struct au_cache *cp;
22314 + p = au_esc_chars;
22315 + for (i = 1; i <= ' '; i++)
22321 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22323 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22324 + for (i = 0; i < AuIop_Last; i++)
22325 + aufs_iop_nogetattr[i].getattr = NULL;
22327 + /* First, initialize au_dfree */
22328 + for (i = 0; i < AuCache_Last; i++) { /* including hnotify */
22329 + cp = au_dfree.cache + i;
22330 + cp->cache = NULL;
22331 + init_llist_head(&cp->llist);
22333 + for (i = 0; i < AU_DFREE_Last; i++)
22334 + init_llist_head(au_dfree.llist + i);
22335 + INIT_DELAYED_WORK(&au_dfree.dwork, au_do_dfree);
22337 + au_sbilist_init();
22338 + sysaufs_brs_init();
22341 + err = sysaufs_init();
22342 + if (unlikely(err))
22344 + err = au_procfs_init();
22345 + if (unlikely(err))
22346 + goto out_sysaufs;
22347 + err = au_wkq_init();
22348 + if (unlikely(err))
22350 + err = au_loopback_init();
22351 + if (unlikely(err))
22353 + err = au_hnotify_init();
22354 + if (unlikely(err))
22355 + goto out_loopback;
22356 + err = au_sysrq_init();
22357 + if (unlikely(err))
22359 + err = au_cache_init();
22360 + if (unlikely(err))
22363 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22364 + err = register_filesystem(&aufs_fs_type);
22365 + if (unlikely(err))
22368 + /* since we define pr_fmt, call printk directly */
22369 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22370 + goto out; /* success */
22377 + au_hnotify_fin();
22379 + au_loopback_fin();
22387 + flush_delayed_work(&au_dfree.dwork);
22392 +static void __exit aufs_exit(void)
22394 + unregister_filesystem(&aufs_fs_type);
22397 + au_hnotify_fin();
22398 + au_loopback_fin();
22403 + flush_delayed_work(&au_dfree.dwork);
22406 +module_init(aufs_init);
22407 +module_exit(aufs_exit);
22408 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22409 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22410 +++ linux/fs/aufs/module.h 2017-03-02 14:24:13.863589061 +0100
22413 + * Copyright (C) 2005-2017 Junjiro R. Okajima
22415 + * This program, aufs is free software; you can redistribute it and/or modify
22416 + * it under the terms of the GNU General Public License as published by
22417 + * the Free Software Foundation; either version 2 of the License, or
22418 + * (at your option) any later version.
22420 + * This program is distributed in the hope that it will be useful,
22421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22423 + * GNU General Public License for more details.
22425 + * You should have received a copy of the GNU General Public License
22426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22430 + * module initialization and module-global
22433 +#ifndef __AUFS_MODULE_H__
22434 +#define __AUFS_MODULE_H__
22438 +#include <linux/slab.h>
22439 +#include "debug.h"
22444 +/* module parameters */
22445 +extern int sysaufs_brs;
22446 +extern bool au_userns;
22448 +/* ---------------------------------------------------------------------- */
22450 +extern int au_dir_roflags;
22452 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22453 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22456 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22458 +#ifndef CONFIG_SLOB
22459 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22461 + return -1; /* SLOB is untested */
22465 +int au_seq_path(struct seq_file *seq, struct path *path);
22467 +#ifdef CONFIG_PROC_FS
22469 +int __init au_procfs_init(void);
22470 +void au_procfs_fin(void);
22472 +AuStubInt0(au_procfs_init, void);
22473 +AuStubVoid(au_procfs_fin, void);
22476 +/* ---------------------------------------------------------------------- */
22478 +/* kmem cache and delayed free */
22485 + AuCache_HNOTIFY, /* must be last */
22491 + AU_DFREE_FREE_PAGE,
22496 + struct kmem_cache *cache;
22497 + struct llist_head llist; /* delayed free */
22501 + * in order to reduce the cost of the internal timer, consolidate all the
22502 + * delayed free works into a single delayed_work.
22505 + struct au_cache cache[AuCache_Last];
22506 + struct llist_head llist[AU_DFREE_Last];
22507 + struct delayed_work dwork;
22510 +extern struct au_dfree au_dfree;
22512 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22513 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22514 +#define AuCacheCtor(type, ctor) \
22515 + kmem_cache_create(#type, sizeof(struct type), \
22516 + __alignof__(struct type), AuCacheFlags, ctor)
22518 +#define AU_DFREE_DELAY msecs_to_jiffies(10)
22519 +#define AU_DFREE_BODY(lnode, llist) do { \
22520 + if (llist_add(lnode, llist)) \
22521 + schedule_delayed_work(&au_dfree.dwork, \
22522 + AU_DFREE_DELAY); \
22524 +#define AU_CACHE_DFREE_FUNC(name, idx, lnode) \
22525 + void au_cache_dfree_##name(struct au_##name *p) \
22527 + struct au_cache *cp = au_dfree.cache + AuCache_##idx; \
22528 + AU_DFREE_BODY(&p->lnode, &cp->llist); \
22531 +#define AuCacheFuncs(name, index) \
22532 +static inline struct au_##name *au_cache_alloc_##name(void) \
22533 +{ return kmem_cache_alloc(au_dfree.cache[AuCache_##index].cache, GFP_NOFS); } \
22534 +static inline void au_cache_free_##name(struct au_##name *p) \
22535 +{ kmem_cache_free(au_dfree.cache[AuCache_##index].cache, p); } \
22536 +void au_cache_dfree_##name(struct au_##name *p)
22538 +AuCacheFuncs(dinfo, DINFO);
22539 +AuCacheFuncs(icntnr, ICNTNR);
22540 +AuCacheFuncs(finfo, FINFO);
22541 +AuCacheFuncs(vdir, VDIR);
22542 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22543 +#ifdef CONFIG_AUFS_HNOTIFY
22544 +AuCacheFuncs(hnotify, HNOTIFY);
22547 +static inline void au_delayed_kfree(const void *p)
22550 + AuDebugOn(ksize(p) < sizeof(struct llist_node));
22552 + AU_DFREE_BODY((void *)p, au_dfree.llist + AU_DFREE_KFREE);
22556 +static inline void au_free_page(void *p)
22558 + free_page((unsigned long)p);
22561 +static inline void au_delayed_free_page(unsigned long addr)
22563 + AU_DFREE_BODY((void *)addr, au_dfree.llist + AU_DFREE_FREE_PAGE);
22566 +#endif /* __KERNEL__ */
22567 +#endif /* __AUFS_MODULE_H__ */
22568 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22569 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22570 +++ linux/fs/aufs/mvdown.c 2017-03-02 14:24:13.863589061 +0100
22573 + * Copyright (C) 2011-2017 Junjiro R. Okajima
22575 + * This program, aufs is free software; you can redistribute it and/or modify
22576 + * it under the terms of the GNU General Public License as published by
22577 + * the Free Software Foundation; either version 2 of the License, or
22578 + * (at your option) any later version.
22580 + * This program is distributed in the hope that it will be useful,
22581 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22582 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22583 + * GNU General Public License for more details.
22585 + * You should have received a copy of the GNU General Public License
22586 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22590 + * move-down, opposite of copy-up
22595 +struct au_mvd_args {
22597 + struct super_block *h_sb;
22598 + struct dentry *h_parent;
22599 + struct au_hinode *hdir;
22600 + struct inode *h_dir, *h_inode;
22601 + struct au_pin pin;
22602 + } info[AUFS_MVDOWN_NARRAY];
22604 + struct aufs_mvdown mvdown;
22605 + struct dentry *dentry, *parent;
22606 + struct inode *inode, *dir;
22607 + struct super_block *sb;
22608 + aufs_bindex_t bopq, bwh, bfound;
22609 + unsigned char rename_lock;
22612 +#define mvd_errno mvdown.au_errno
22613 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22614 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22615 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22616 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22618 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22619 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22620 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22621 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22622 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22623 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22625 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22626 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22627 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22628 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22629 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22630 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22632 +#define AU_MVD_PR(flag, ...) do { \
22634 + pr_err(__VA_ARGS__); \
22637 +static int find_lower_writable(struct au_mvd_args *a)
22639 + struct super_block *sb;
22640 + aufs_bindex_t bindex, bbot;
22641 + struct au_branch *br;
22644 + bindex = a->mvd_bsrc;
22645 + bbot = au_sbbot(sb);
22646 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22647 + for (bindex++; bindex <= bbot; bindex++) {
22648 + br = au_sbr(sb, bindex);
22649 + if (au_br_fhsm(br->br_perm)
22650 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22653 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22654 + for (bindex++; bindex <= bbot; bindex++) {
22655 + br = au_sbr(sb, bindex);
22656 + if (!au_br_rdonly(br))
22660 + for (bindex++; bindex <= bbot; bindex++) {
22661 + br = au_sbr(sb, bindex);
22662 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22663 + if (au_br_rdonly(br))
22665 + |= AUFS_MVDOWN_ROLOWER_R;
22673 +/* make the parent dir on bdst */
22674 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22679 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22680 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22681 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22682 + a->mvd_h_dst_parent = NULL;
22683 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22684 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22685 + if (!a->mvd_h_dst_parent) {
22686 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22687 + if (unlikely(err)) {
22688 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22691 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22699 +/* lock them all */
22700 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22703 + struct dentry *h_trap;
22705 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22706 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22707 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22708 + au_opt_udba(a->sb),
22709 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22711 + if (unlikely(err)) {
22712 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22716 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22717 + a->rename_lock = 0;
22718 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22719 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22720 + au_opt_udba(a->sb),
22721 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22722 + err = au_do_pin(&a->mvd_pin_src);
22724 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22725 + if (unlikely(err)) {
22726 + AU_MVD_PR(dmsg, "pin_src failed\n");
22729 + goto out; /* success */
22732 + a->rename_lock = 1;
22733 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22734 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22735 + au_opt_udba(a->sb),
22736 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22738 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22739 + if (unlikely(err)) {
22740 + AU_MVD_PR(dmsg, "pin_src failed\n");
22741 + au_pin_hdir_lock(&a->mvd_pin_dst);
22744 + au_pin_hdir_unlock(&a->mvd_pin_src);
22745 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22746 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22748 + err = (h_trap != a->mvd_h_src_parent);
22750 + err = (h_trap != a->mvd_h_dst_parent);
22752 + BUG_ON(err); /* it should never happen */
22753 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22756 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22757 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22758 + au_pin_hdir_lock(&a->mvd_pin_src);
22759 + au_unpin(&a->mvd_pin_src);
22760 + au_pin_hdir_lock(&a->mvd_pin_dst);
22763 + goto out; /* success */
22766 + au_unpin(&a->mvd_pin_dst);
22772 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22774 + if (!a->rename_lock)
22775 + au_unpin(&a->mvd_pin_src);
22777 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22778 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22779 + au_pin_hdir_lock(&a->mvd_pin_src);
22780 + au_unpin(&a->mvd_pin_src);
22781 + au_pin_hdir_lock(&a->mvd_pin_dst);
22783 + au_unpin(&a->mvd_pin_dst);
22786 +/* copy-down the file */
22787 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22790 + struct au_cp_generic cpg = {
22791 + .dentry = a->dentry,
22792 + .bdst = a->mvd_bdst,
22793 + .bsrc = a->mvd_bsrc,
22795 + .pin = &a->mvd_pin_dst,
22796 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22799 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22800 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22801 + au_fset_cpup(cpg.flags, OVERWRITE);
22802 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22803 + au_fset_cpup(cpg.flags, RWDST);
22804 + err = au_sio_cpdown_simple(&cpg);
22805 + if (unlikely(err))
22806 + AU_MVD_PR(dmsg, "cpdown failed\n");
22813 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22816 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22819 + struct path h_path;
22820 + struct au_branch *br;
22821 + struct inode *delegated;
22823 + br = au_sbr(a->sb, a->mvd_bdst);
22824 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22825 + err = PTR_ERR(h_path.dentry);
22826 + if (IS_ERR(h_path.dentry)) {
22827 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22832 + if (d_is_positive(h_path.dentry)) {
22833 + h_path.mnt = au_br_mnt(br);
22834 + delegated = NULL;
22835 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22836 + &delegated, /*force*/0);
22837 + if (unlikely(err == -EWOULDBLOCK)) {
22838 + pr_warn("cannot retry for NFSv4 delegation"
22839 + " for an internal unlink\n");
22842 + if (unlikely(err))
22843 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22845 + dput(h_path.dentry);
22853 + * unlink the topmost h_dentry
22855 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22858 + struct path h_path;
22859 + struct inode *delegated;
22861 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22862 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22863 + delegated = NULL;
22864 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22865 + if (unlikely(err == -EWOULDBLOCK)) {
22866 + pr_warn("cannot retry for NFSv4 delegation"
22867 + " for an internal unlink\n");
22870 + if (unlikely(err))
22871 + AU_MVD_PR(dmsg, "unlink failed\n");
22877 +/* Since mvdown succeeded, we ignore an error of this function */
22878 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22881 + struct au_branch *br;
22883 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22884 + br = au_sbr(a->sb, a->mvd_bsrc);
22885 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22887 + br = au_sbr(a->sb, a->mvd_bdst);
22888 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22889 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22892 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22894 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22898 + * copy-down the file and unlink the bsrc file.
22899 + * - unlink the bdst whout if exist
22900 + * - copy-down the file (with whtmp name and rename)
22901 + * - unlink the bsrc file
22903 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22907 + err = au_do_mkdir(dmsg, a);
22909 + err = au_do_lock(dmsg, a);
22910 + if (unlikely(err))
22914 + * do not revert the activities we made on bdst since they should be
22915 + * harmless in aufs.
22918 + err = au_do_cpdown(dmsg, a);
22920 + err = au_do_unlink_wh(dmsg, a);
22921 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22922 + err = au_do_unlink(dmsg, a);
22923 + if (unlikely(err))
22926 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22927 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22928 + if (find_lower_writable(a) < 0)
22929 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22931 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22932 + au_do_stfs(dmsg, a);
22934 + /* maintain internal array */
22935 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22936 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22937 + au_set_dbtop(a->dentry, a->mvd_bdst);
22938 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22939 + au_set_ibtop(a->inode, a->mvd_bdst);
22941 + /* hide the lower */
22942 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22943 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22944 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22945 + au_set_ibbot(a->inode, a->mvd_bsrc);
22947 + if (au_dbbot(a->dentry) < a->mvd_bdst)
22948 + au_set_dbbot(a->dentry, a->mvd_bdst);
22949 + if (au_ibbot(a->inode) < a->mvd_bdst)
22950 + au_set_ibbot(a->inode, a->mvd_bdst);
22953 + au_do_unlock(dmsg, a);
22959 +/* ---------------------------------------------------------------------- */
22961 +/* make sure the file is idle */
22962 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22964 + int err, plinked;
22967 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22968 + if (au_dbtop(a->dentry) == a->mvd_bsrc
22969 + && au_dcount(a->dentry) == 1
22970 + && atomic_read(&a->inode->i_count) == 1
22971 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22972 + && (!plinked || !au_plink_test(a->inode))
22973 + && a->inode->i_nlink == 1)
22978 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22979 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
22980 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22981 + a->mvd_h_src_inode->i_nlink,
22982 + plinked, plinked ? au_plink_test(a->inode) : 0);
22989 +/* make sure the parent dir is fine */
22990 +static int au_mvd_args_parent(const unsigned char dmsg,
22991 + struct au_mvd_args *a)
22994 + aufs_bindex_t bindex;
22997 + if (unlikely(au_alive_dir(a->parent))) {
22999 + AU_MVD_PR(dmsg, "parent dir is dead\n");
23003 + a->bopq = au_dbdiropq(a->parent);
23004 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
23005 + AuDbg("b%d\n", bindex);
23006 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
23007 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
23009 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
23010 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
23011 + a->bopq, a->mvd_bdst);
23019 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23020 + struct au_mvd_args *a)
23023 + struct au_dinfo *dinfo, *tmp;
23025 + /* lookup the next lower positive entry */
23027 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23028 + if (unlikely(!tmp))
23033 + dinfo = au_di(a->dentry);
23034 + au_di_cp(tmp, dinfo);
23035 + au_di_swap(tmp, dinfo);
23037 + /* returns the number of positive dentries */
23038 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23039 + /* AuLkup_IGNORE_PERM */ 0);
23041 + a->bwh = au_dbwh(a->dentry);
23042 + else if (err > 0)
23043 + a->bfound = au_dbtop(a->dentry);
23045 + au_di_swap(tmp, dinfo);
23046 + au_rw_write_unlock(&tmp->di_rwsem);
23048 + if (unlikely(err < 0))
23049 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23052 + * here, we have these cases.
23054 + * no positive dentry under bsrc. there are more sub-cases.
23056 + * there no whiteout, we can safely move-down.
23059 + * bsrc < bwh && bwh < bdst
23060 + * there is a whiteout on RO branch. cannot proceed.
23062 + * there is a whiteout on the RW target branch. it should
23065 + * there is a whiteout somewhere unrelated branch.
23066 + * -1 < bfound && bfound <= bsrc
23069 + * found, but it is on RO branch between bsrc and bdst. cannot
23072 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23075 + * found, after we create the file on bdst, it will be hidden.
23078 + AuDebugOn(a->bfound == -1
23080 + && a->bwh <= a->mvd_bsrc);
23081 + AuDebugOn(-1 < a->bfound
23082 + && a->bfound <= a->mvd_bsrc);
23085 + if (a->bfound == -1
23086 + && a->mvd_bsrc < a->bwh
23088 + && a->bwh < a->mvd_bdst) {
23089 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23090 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23091 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23093 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23094 + a->mvd_errno = EAU_MVDOWN_UPPER;
23095 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23096 + a->mvd_bdst, a->bfound);
23100 + err = 0; /* success */
23107 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23112 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23113 + && a->bfound == a->mvd_bdst)
23119 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23122 + struct au_branch *br;
23125 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23129 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23130 + a->mvd_bsrc = au_ibtop(a->inode);
23132 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23133 + if (unlikely(a->mvd_bsrc < 0
23134 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23135 + || au_dbbot(a->dentry) < a->mvd_bsrc
23136 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23137 + || (a->mvd_bsrc < au_ibtop(a->inode)
23138 + || au_ibbot(a->inode) < a->mvd_bsrc
23139 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23140 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23141 + AU_MVD_PR(dmsg, "no upper\n");
23145 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23146 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23147 + AU_MVD_PR(dmsg, "on the bottom\n");
23150 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23151 + br = au_sbr(a->sb, a->mvd_bsrc);
23152 + err = au_br_rdonly(br);
23153 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23154 + if (unlikely(err))
23156 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23157 + || IS_APPEND(a->mvd_h_src_inode))) {
23159 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23165 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23166 + a->mvd_bdst = find_lower_writable(a);
23167 + if (unlikely(a->mvd_bdst < 0)) {
23168 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23169 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23173 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23174 + if (unlikely(a->mvd_bdst < 0
23175 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23176 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23177 + AU_MVD_PR(dmsg, "no lower brid\n");
23182 + err = au_mvd_args_busy(dmsg, a);
23184 + err = au_mvd_args_parent(dmsg, a);
23186 + err = au_mvd_args_intermediate(dmsg, a);
23188 + err = au_mvd_args_exist(dmsg, a);
23190 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23197 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23200 + unsigned char dmsg;
23201 + struct au_mvd_args *args;
23202 + struct inode *inode;
23204 + inode = d_inode(dentry);
23206 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23210 + args = kmalloc(sizeof(*args), GFP_NOFS);
23211 + if (unlikely(!args))
23214 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23216 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23217 + if (unlikely(err)) {
23222 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23223 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23224 + args->mvdown.au_errno = 0;
23225 + args->dentry = dentry;
23226 + args->inode = inode;
23227 + args->sb = dentry->d_sb;
23230 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23231 + args->parent = dget_parent(dentry);
23232 + args->dir = d_inode(args->parent);
23233 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23234 + dput(args->parent);
23235 + if (unlikely(args->parent != dentry->d_parent)) {
23236 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23240 + inode_lock_nested(inode, I_MUTEX_CHILD);
23241 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23242 + if (unlikely(err))
23245 + di_write_lock_parent(args->parent);
23246 + err = au_mvd_args(dmsg, args);
23247 + if (unlikely(err))
23250 + err = au_do_mvdown(dmsg, args);
23251 + if (unlikely(err))
23254 + au_cpup_attr_timesizes(args->dir);
23255 + au_cpup_attr_timesizes(inode);
23256 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23257 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23258 + /* au_digen_dec(dentry); */
23261 + di_write_unlock(args->parent);
23262 + aufs_read_unlock(dentry, AuLock_DW);
23264 + inode_unlock(inode);
23266 + inode_unlock(args->dir);
23268 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23271 + au_delayed_kfree(args);
23276 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23277 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23278 +++ linux/fs/aufs/opts.c 2017-03-02 14:24:13.863589061 +0100
23281 + * Copyright (C) 2005-2017 Junjiro R. Okajima
23283 + * This program, aufs is free software; you can redistribute it and/or modify
23284 + * it under the terms of the GNU General Public License as published by
23285 + * the Free Software Foundation; either version 2 of the License, or
23286 + * (at your option) any later version.
23288 + * This program is distributed in the hope that it will be useful,
23289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23291 + * GNU General Public License for more details.
23293 + * You should have received a copy of the GNU General Public License
23294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23298 + * mount options/flags
23301 +#include <linux/namei.h>
23302 +#include <linux/types.h> /* a distribution requires */
23303 +#include <linux/parser.h>
23306 +/* ---------------------------------------------------------------------- */
23310 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23311 + Opt_idel, Opt_imod,
23312 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23313 + Opt_rdblk_def, Opt_rdhash_def,
23314 + Opt_xino, Opt_noxino,
23315 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23316 + Opt_trunc_xino_path, Opt_itrunc_xino,
23317 + Opt_trunc_xib, Opt_notrunc_xib,
23318 + Opt_shwh, Opt_noshwh,
23319 + Opt_plink, Opt_noplink, Opt_list_plink,
23321 + Opt_dio, Opt_nodio,
23322 + Opt_diropq_a, Opt_diropq_w,
23323 + Opt_warn_perm, Opt_nowarn_perm,
23324 + Opt_wbr_copyup, Opt_wbr_create,
23326 + Opt_verbose, Opt_noverbose,
23327 + Opt_sum, Opt_nosum, Opt_wsum,
23328 + Opt_dirperm1, Opt_nodirperm1,
23329 + Opt_acl, Opt_noacl,
23330 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23333 +static match_table_t options = {
23334 + {Opt_br, "br=%s"},
23335 + {Opt_br, "br:%s"},
23337 + {Opt_add, "add=%d:%s"},
23338 + {Opt_add, "add:%d:%s"},
23339 + {Opt_add, "ins=%d:%s"},
23340 + {Opt_add, "ins:%d:%s"},
23341 + {Opt_append, "append=%s"},
23342 + {Opt_append, "append:%s"},
23343 + {Opt_prepend, "prepend=%s"},
23344 + {Opt_prepend, "prepend:%s"},
23346 + {Opt_del, "del=%s"},
23347 + {Opt_del, "del:%s"},
23348 + /* {Opt_idel, "idel:%d"}, */
23349 + {Opt_mod, "mod=%s"},
23350 + {Opt_mod, "mod:%s"},
23351 + /* {Opt_imod, "imod:%d:%s"}, */
23353 + {Opt_dirwh, "dirwh=%d"},
23355 + {Opt_xino, "xino=%s"},
23356 + {Opt_noxino, "noxino"},
23357 + {Opt_trunc_xino, "trunc_xino"},
23358 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23359 + {Opt_notrunc_xino, "notrunc_xino"},
23360 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23361 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23362 + /* {Opt_zxino, "zxino=%s"}, */
23363 + {Opt_trunc_xib, "trunc_xib"},
23364 + {Opt_notrunc_xib, "notrunc_xib"},
23366 +#ifdef CONFIG_PROC_FS
23367 + {Opt_plink, "plink"},
23369 + {Opt_ignore_silent, "plink"},
23372 + {Opt_noplink, "noplink"},
23374 +#ifdef CONFIG_AUFS_DEBUG
23375 + {Opt_list_plink, "list_plink"},
23378 + {Opt_udba, "udba=%s"},
23380 + {Opt_dio, "dio"},
23381 + {Opt_nodio, "nodio"},
23383 +#ifdef CONFIG_AUFS_FHSM
23384 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23386 + {Opt_ignore_silent, "fhsm_sec=%d"},
23389 + {Opt_diropq_a, "diropq=always"},
23390 + {Opt_diropq_a, "diropq=a"},
23391 + {Opt_diropq_w, "diropq=whiteouted"},
23392 + {Opt_diropq_w, "diropq=w"},
23394 + {Opt_warn_perm, "warn_perm"},
23395 + {Opt_nowarn_perm, "nowarn_perm"},
23397 + /* keep them temporary */
23398 + {Opt_ignore_silent, "nodlgt"},
23399 + {Opt_ignore_silent, "clean_plink"},
23401 +#ifdef CONFIG_AUFS_SHWH
23402 + {Opt_shwh, "shwh"},
23404 + {Opt_noshwh, "noshwh"},
23406 + {Opt_dirperm1, "dirperm1"},
23407 + {Opt_nodirperm1, "nodirperm1"},
23409 + {Opt_verbose, "verbose"},
23410 + {Opt_verbose, "v"},
23411 + {Opt_noverbose, "noverbose"},
23412 + {Opt_noverbose, "quiet"},
23413 + {Opt_noverbose, "q"},
23414 + {Opt_noverbose, "silent"},
23416 + {Opt_sum, "sum"},
23417 + {Opt_nosum, "nosum"},
23418 + {Opt_wsum, "wsum"},
23420 + {Opt_rdcache, "rdcache=%d"},
23421 + {Opt_rdblk, "rdblk=%d"},
23422 + {Opt_rdblk_def, "rdblk=def"},
23423 + {Opt_rdhash, "rdhash=%d"},
23424 + {Opt_rdhash_def, "rdhash=def"},
23426 + {Opt_wbr_create, "create=%s"},
23427 + {Opt_wbr_create, "create_policy=%s"},
23428 + {Opt_wbr_copyup, "cpup=%s"},
23429 + {Opt_wbr_copyup, "copyup=%s"},
23430 + {Opt_wbr_copyup, "copyup_policy=%s"},
23432 + /* generic VFS flag */
23433 +#ifdef CONFIG_FS_POSIX_ACL
23434 + {Opt_acl, "acl"},
23435 + {Opt_noacl, "noacl"},
23437 + {Opt_ignore_silent, "acl"},
23438 + {Opt_ignore_silent, "noacl"},
23441 + /* internal use for the scripts */
23442 + {Opt_ignore_silent, "si=%s"},
23444 + {Opt_br, "dirs=%s"},
23445 + {Opt_ignore, "debug=%d"},
23446 + {Opt_ignore, "delete=whiteout"},
23447 + {Opt_ignore, "delete=all"},
23448 + {Opt_ignore, "imap=%s"},
23450 + /* temporary workaround, due to old mount(8)? */
23451 + {Opt_ignore_silent, "relatime"},
23456 +/* ---------------------------------------------------------------------- */
23458 +static const char *au_parser_pattern(int val, match_table_t tbl)
23460 + struct match_token *p;
23463 + while (p->pattern) {
23464 + if (p->token == val)
23465 + return p->pattern;
23472 +static const char *au_optstr(int *val, match_table_t tbl)
23474 + struct match_token *p;
23481 + while (p->pattern) {
23483 + && (v & p->token) == p->token) {
23484 + *val &= ~p->token;
23485 + return p->pattern;
23494 +/* ---------------------------------------------------------------------- */
23496 +static match_table_t brperm = {
23497 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23498 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23499 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23503 +static match_table_t brattr = {
23505 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23506 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23507 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23508 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23509 +#ifdef CONFIG_AUFS_FHSM
23510 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23512 +#ifdef CONFIG_AUFS_XATTR
23513 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23514 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23515 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23516 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23517 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23518 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23521 + /* ro/rr branch */
23522 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23525 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23526 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23531 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23538 + p = strchr(str, '+');
23541 + v = match_token(str, table, args);
23543 + if (v & AuBrAttr_CMOO_Mask)
23544 + attr &= ~AuBrAttr_CMOO_Mask;
23549 + pr_warn("ignored branch attribute %s\n", str);
23559 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23567 + p = au_optstr(&perm, brattr);
23570 + memcpy(q, p, sz + 1);
23576 + p = au_optstr(&perm, brattr);
23580 + memcpy(q, p, sz + 1);
23586 + return q - str->a;
23589 +static int noinline_for_stack br_perm_val(char *perm)
23591 + int val, bad, sz;
23593 + substring_t args[MAX_OPT_ARGS];
23594 + au_br_perm_str_t attr;
23596 + p = strchr(perm, '+');
23599 + val = match_token(perm, brperm, args);
23603 + pr_warn("ignored branch permission %s\n", perm);
23604 + val = AuBrPerm_RO;
23610 + val |= br_attr_val(p + 1, brattr, args);
23613 + switch (val & AuBrPerm_Mask) {
23614 + case AuBrPerm_RO:
23615 + case AuBrPerm_RR:
23616 + bad = val & AuBrWAttr_Mask;
23617 + val &= ~AuBrWAttr_Mask;
23619 + case AuBrPerm_RW:
23620 + bad = val & AuBrRAttr_Mask;
23621 + val &= ~AuBrRAttr_Mask;
23626 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23627 + * does not treat it as an error, just warning.
23628 + * this is a tiny guard for the user operation.
23630 + if (val & AuBrAttr_UNPIN) {
23631 + bad |= AuBrAttr_UNPIN;
23632 + val &= ~AuBrAttr_UNPIN;
23635 + if (unlikely(bad)) {
23636 + sz = au_do_optstr_br_attr(&attr, bad);
23638 + pr_warn("ignored branch attribute %s\n", attr.a);
23645 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23647 + au_br_perm_str_t attr;
23653 + p = au_optstr(&perm, brperm);
23654 + AuDebugOn(!p || !*p);
23656 + memcpy(q, p, sz + 1);
23659 + sz = au_do_optstr_br_attr(&attr, perm);
23662 + memcpy(q, attr.a, sz + 1);
23665 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23668 +/* ---------------------------------------------------------------------- */
23670 +static match_table_t udbalevel = {
23671 + {AuOpt_UDBA_REVAL, "reval"},
23672 + {AuOpt_UDBA_NONE, "none"},
23673 +#ifdef CONFIG_AUFS_HNOTIFY
23674 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23675 +#ifdef CONFIG_AUFS_HFSNOTIFY
23676 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23682 +static int noinline_for_stack udba_val(char *str)
23684 + substring_t args[MAX_OPT_ARGS];
23686 + return match_token(str, udbalevel, args);
23689 +const char *au_optstr_udba(int udba)
23691 + return au_parser_pattern(udba, udbalevel);
23694 +/* ---------------------------------------------------------------------- */
23696 +static match_table_t au_wbr_create_policy = {
23697 + {AuWbrCreate_TDP, "tdp"},
23698 + {AuWbrCreate_TDP, "top-down-parent"},
23699 + {AuWbrCreate_RR, "rr"},
23700 + {AuWbrCreate_RR, "round-robin"},
23701 + {AuWbrCreate_MFS, "mfs"},
23702 + {AuWbrCreate_MFS, "most-free-space"},
23703 + {AuWbrCreate_MFSV, "mfs:%d"},
23704 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23706 + /* top-down regardless the parent, and then mfs */
23707 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23708 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23710 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23711 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23712 + {AuWbrCreate_PMFS, "pmfs"},
23713 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23714 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23715 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23720 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23721 + struct au_opt_wbr_create *create)
23724 + unsigned long long ull;
23727 + if (!match_u64(arg, &ull))
23728 + create->mfsrr_watermark = ull;
23730 + pr_err("bad integer in %s\n", str);
23737 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23738 + struct au_opt_wbr_create *create)
23743 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23744 + create->mfs_second = n;
23746 + pr_err("bad integer in %s\n", str);
23753 +static int noinline_for_stack
23754 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23757 + substring_t args[MAX_OPT_ARGS];
23759 + err = match_token(str, au_wbr_create_policy, args);
23760 + create->wbr_create = err;
23762 + case AuWbrCreate_MFSRRV:
23763 + case AuWbrCreate_TDMFSV:
23764 + case AuWbrCreate_PMFSRRV:
23765 + e = au_wbr_mfs_wmark(&args[0], str, create);
23767 + e = au_wbr_mfs_sec(&args[1], str, create);
23771 + case AuWbrCreate_MFSRR:
23772 + case AuWbrCreate_TDMFS:
23773 + case AuWbrCreate_PMFSRR:
23774 + e = au_wbr_mfs_wmark(&args[0], str, create);
23775 + if (unlikely(e)) {
23780 + case AuWbrCreate_MFS:
23781 + case AuWbrCreate_PMFS:
23782 + create->mfs_second = AUFS_MFS_DEF_SEC;
23784 + case AuWbrCreate_MFSV:
23785 + case AuWbrCreate_PMFSV:
23786 + e = au_wbr_mfs_sec(&args[0], str, create);
23795 +const char *au_optstr_wbr_create(int wbr_create)
23797 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23800 +static match_table_t au_wbr_copyup_policy = {
23801 + {AuWbrCopyup_TDP, "tdp"},
23802 + {AuWbrCopyup_TDP, "top-down-parent"},
23803 + {AuWbrCopyup_BUP, "bup"},
23804 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23805 + {AuWbrCopyup_BU, "bu"},
23806 + {AuWbrCopyup_BU, "bottom-up"},
23810 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23812 + substring_t args[MAX_OPT_ARGS];
23814 + return match_token(str, au_wbr_copyup_policy, args);
23817 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23819 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23822 +/* ---------------------------------------------------------------------- */
23824 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23826 +static void dump_opts(struct au_opts *opts)
23828 +#ifdef CONFIG_AUFS_DEBUG
23829 + /* reduce stack space */
23831 + struct au_opt_add *add;
23832 + struct au_opt_del *del;
23833 + struct au_opt_mod *mod;
23834 + struct au_opt_xino *xino;
23835 + struct au_opt_xino_itrunc *xino_itrunc;
23836 + struct au_opt_wbr_create *create;
23838 + struct au_opt *opt;
23841 + while (opt->type != Opt_tail) {
23842 + switch (opt->type) {
23844 + u.add = &opt->add;
23845 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23846 + u.add->bindex, u.add->pathname, u.add->perm,
23847 + u.add->path.dentry);
23851 + u.del = &opt->del;
23852 + AuDbg("del {%s, %p}\n",
23853 + u.del->pathname, u.del->h_path.dentry);
23857 + u.mod = &opt->mod;
23858 + AuDbg("mod {%s, 0x%x, %p}\n",
23859 + u.mod->path, u.mod->perm, u.mod->h_root);
23862 + u.add = &opt->add;
23863 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23864 + u.add->bindex, u.add->pathname, u.add->perm,
23865 + u.add->path.dentry);
23867 + case Opt_prepend:
23868 + u.add = &opt->add;
23869 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23870 + u.add->bindex, u.add->pathname, u.add->perm,
23871 + u.add->path.dentry);
23874 + AuDbg("dirwh %d\n", opt->dirwh);
23876 + case Opt_rdcache:
23877 + AuDbg("rdcache %d\n", opt->rdcache);
23880 + AuDbg("rdblk %u\n", opt->rdblk);
23882 + case Opt_rdblk_def:
23883 + AuDbg("rdblk_def\n");
23886 + AuDbg("rdhash %u\n", opt->rdhash);
23888 + case Opt_rdhash_def:
23889 + AuDbg("rdhash_def\n");
23892 + u.xino = &opt->xino;
23893 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23895 + case Opt_trunc_xino:
23896 + AuLabel(trunc_xino);
23898 + case Opt_notrunc_xino:
23899 + AuLabel(notrunc_xino);
23901 + case Opt_trunc_xino_path:
23902 + case Opt_itrunc_xino:
23903 + u.xino_itrunc = &opt->xino_itrunc;
23904 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23909 + case Opt_trunc_xib:
23910 + AuLabel(trunc_xib);
23912 + case Opt_notrunc_xib:
23913 + AuLabel(notrunc_xib);
23921 + case Opt_dirperm1:
23922 + AuLabel(dirperm1);
23924 + case Opt_nodirperm1:
23925 + AuLabel(nodirperm1);
23930 + case Opt_noplink:
23931 + AuLabel(noplink);
23933 + case Opt_list_plink:
23934 + AuLabel(list_plink);
23937 + AuDbg("udba %d, %s\n",
23938 + opt->udba, au_optstr_udba(opt->udba));
23946 + case Opt_diropq_a:
23947 + AuLabel(diropq_a);
23949 + case Opt_diropq_w:
23950 + AuLabel(diropq_w);
23952 + case Opt_warn_perm:
23953 + AuLabel(warn_perm);
23955 + case Opt_nowarn_perm:
23956 + AuLabel(nowarn_perm);
23958 + case Opt_verbose:
23959 + AuLabel(verbose);
23961 + case Opt_noverbose:
23962 + AuLabel(noverbose);
23973 + case Opt_wbr_create:
23974 + u.create = &opt->wbr_create;
23975 + AuDbg("create %d, %s\n", u.create->wbr_create,
23976 + au_optstr_wbr_create(u.create->wbr_create));
23977 + switch (u.create->wbr_create) {
23978 + case AuWbrCreate_MFSV:
23979 + case AuWbrCreate_PMFSV:
23980 + AuDbg("%d sec\n", u.create->mfs_second);
23982 + case AuWbrCreate_MFSRR:
23983 + case AuWbrCreate_TDMFS:
23984 + AuDbg("%llu watermark\n",
23985 + u.create->mfsrr_watermark);
23987 + case AuWbrCreate_MFSRRV:
23988 + case AuWbrCreate_TDMFSV:
23989 + case AuWbrCreate_PMFSRRV:
23990 + AuDbg("%llu watermark, %d sec\n",
23991 + u.create->mfsrr_watermark,
23992 + u.create->mfs_second);
23996 + case Opt_wbr_copyup:
23997 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23998 + au_optstr_wbr_copyup(opt->wbr_copyup));
24000 + case Opt_fhsm_sec:
24001 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24017 +void au_opts_free(struct au_opts *opts)
24019 + struct au_opt *opt;
24022 + while (opt->type != Opt_tail) {
24023 + switch (opt->type) {
24026 + case Opt_prepend:
24027 + path_put(&opt->add.path);
24031 + path_put(&opt->del.h_path);
24035 + dput(opt->mod.h_root);
24038 + fput(opt->xino.file);
24045 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24046 + aufs_bindex_t bindex)
24049 + struct au_opt_add *add = &opt->add;
24052 + add->bindex = bindex;
24053 + add->perm = AuBrPerm_RO;
24054 + add->pathname = opt_str;
24055 + p = strchr(opt_str, '=');
24059 + add->perm = br_perm_val(p);
24062 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24065 + add->perm = AuBrPerm_RO;
24066 + if (au_test_fs_rr(add->path.dentry->d_sb))
24067 + add->perm = AuBrPerm_RR;
24068 + else if (!bindex && !(sb_flags & MS_RDONLY))
24069 + add->perm = AuBrPerm_RW;
24071 + opt->type = Opt_add;
24074 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24081 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24085 + del->pathname = args[0].from;
24086 + AuDbg("del path %s\n", del->pathname);
24088 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24089 + if (unlikely(err))
24090 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24095 +#if 0 /* reserved for future use */
24096 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24097 + struct au_opt_del *del, substring_t args[])
24100 + struct dentry *root;
24103 + root = sb->s_root;
24104 + aufs_read_lock(root, AuLock_FLUSH);
24105 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24106 + pr_err("out of bounds, %d\n", bindex);
24111 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24112 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24115 + aufs_read_unlock(root, !AuLock_IR);
24120 +static int noinline_for_stack
24121 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24124 + struct path path;
24128 + mod->path = args[0].from;
24129 + p = strchr(mod->path, '=');
24130 + if (unlikely(!p)) {
24131 + pr_err("no permssion %s\n", args[0].from);
24136 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24137 + if (unlikely(err)) {
24138 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24142 + mod->perm = br_perm_val(p);
24143 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24144 + mod->h_root = dget(path.dentry);
24151 +#if 0 /* reserved for future use */
24152 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24153 + struct au_opt_mod *mod, substring_t args[])
24156 + struct dentry *root;
24159 + root = sb->s_root;
24160 + aufs_read_lock(root, AuLock_FLUSH);
24161 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24162 + pr_err("out of bounds, %d\n", bindex);
24167 + mod->perm = br_perm_val(args[1].from);
24168 + AuDbg("mod path %s, perm 0x%x, %s\n",
24169 + mod->path, mod->perm, args[1].from);
24170 + mod->h_root = dget(au_h_dptr(root, bindex));
24173 + aufs_read_unlock(root, !AuLock_IR);
24178 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24179 + substring_t args[])
24182 + struct file *file;
24184 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24185 + err = PTR_ERR(file);
24186 + if (IS_ERR(file))
24190 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24192 + pr_err("%s must be outside\n", args[0].from);
24197 + xino->file = file;
24198 + xino->path = args[0].from;
24204 +static int noinline_for_stack
24205 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24206 + struct au_opt_xino_itrunc *xino_itrunc,
24207 + substring_t args[])
24210 + aufs_bindex_t bbot, bindex;
24211 + struct path path;
24212 + struct dentry *root;
24214 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24215 + if (unlikely(err)) {
24216 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24220 + xino_itrunc->bindex = -1;
24221 + root = sb->s_root;
24222 + aufs_read_lock(root, AuLock_FLUSH);
24223 + bbot = au_sbbot(sb);
24224 + for (bindex = 0; bindex <= bbot; bindex++) {
24225 + if (au_h_dptr(root, bindex) == path.dentry) {
24226 + xino_itrunc->bindex = bindex;
24230 + aufs_read_unlock(root, !AuLock_IR);
24233 + if (unlikely(xino_itrunc->bindex < 0)) {
24234 + pr_err("no such branch %s\n", args[0].from);
24242 +/* called without aufs lock */
24243 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24245 + int err, n, token;
24246 + aufs_bindex_t bindex;
24247 + unsigned char skipped;
24248 + struct dentry *root;
24249 + struct au_opt *opt, *opt_tail;
24251 + /* reduce the stack space */
24253 + struct au_opt_xino_itrunc *xino_itrunc;
24254 + struct au_opt_wbr_create *create;
24257 + substring_t args[MAX_OPT_ARGS];
24261 + a = kmalloc(sizeof(*a), GFP_NOFS);
24262 + if (unlikely(!a))
24265 + root = sb->s_root;
24269 + opt_tail = opt + opts->max_opt - 1;
24270 + opt->type = Opt_tail;
24271 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24274 + token = match_token(opt_str, options, a->args);
24278 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24280 + err = opt_add(opt, opt_str, opts->sb_flags,
24282 + if (unlikely(!err && ++opt > opt_tail)) {
24286 + opt->type = Opt_tail;
24291 + if (unlikely(match_int(&a->args[0], &n))) {
24292 + pr_err("bad integer in %s\n", opt_str);
24296 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24299 + opt->type = token;
24302 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24303 + /*dummy bindex*/1);
24305 + opt->type = token;
24307 + case Opt_prepend:
24308 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24311 + opt->type = token;
24314 + err = au_opts_parse_del(&opt->del, a->args);
24316 + opt->type = token;
24318 +#if 0 /* reserved for future use */
24320 + del->pathname = "(indexed)";
24321 + if (unlikely(match_int(&args[0], &n))) {
24322 + pr_err("bad integer in %s\n", opt_str);
24325 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24327 + opt->type = token;
24331 + err = au_opts_parse_mod(&opt->mod, a->args);
24333 + opt->type = token;
24335 +#ifdef IMOD /* reserved for future use */
24337 + u.mod->path = "(indexed)";
24338 + if (unlikely(match_int(&a->args[0], &n))) {
24339 + pr_err("bad integer in %s\n", opt_str);
24342 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24344 + opt->type = token;
24348 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24350 + opt->type = token;
24353 + case Opt_trunc_xino_path:
24354 + err = au_opts_parse_xino_itrunc_path
24355 + (sb, &opt->xino_itrunc, a->args);
24357 + opt->type = token;
24360 + case Opt_itrunc_xino:
24361 + u.xino_itrunc = &opt->xino_itrunc;
24362 + if (unlikely(match_int(&a->args[0], &n))) {
24363 + pr_err("bad integer in %s\n", opt_str);
24366 + u.xino_itrunc->bindex = n;
24367 + aufs_read_lock(root, AuLock_FLUSH);
24368 + if (n < 0 || au_sbbot(sb) < n) {
24369 + pr_err("out of bounds, %d\n", n);
24370 + aufs_read_unlock(root, !AuLock_IR);
24373 + aufs_read_unlock(root, !AuLock_IR);
24375 + opt->type = token;
24379 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24382 + opt->type = token;
24385 + case Opt_rdcache:
24386 + if (unlikely(match_int(&a->args[0], &n))) {
24387 + pr_err("bad integer in %s\n", opt_str);
24390 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24391 + pr_err("rdcache must be smaller than %d\n",
24392 + AUFS_RDCACHE_MAX);
24395 + opt->rdcache = n;
24397 + opt->type = token;
24400 + if (unlikely(match_int(&a->args[0], &n)
24402 + || n > KMALLOC_MAX_SIZE)) {
24403 + pr_err("bad integer in %s\n", opt_str);
24406 + if (unlikely(n && n < NAME_MAX)) {
24407 + pr_err("rdblk must be larger than %d\n",
24413 + opt->type = token;
24416 + if (unlikely(match_int(&a->args[0], &n)
24418 + || n * sizeof(struct hlist_head)
24419 + > KMALLOC_MAX_SIZE)) {
24420 + pr_err("bad integer in %s\n", opt_str);
24425 + opt->type = token;
24428 + case Opt_trunc_xino:
24429 + case Opt_notrunc_xino:
24431 + case Opt_trunc_xib:
24432 + case Opt_notrunc_xib:
24435 + case Opt_dirperm1:
24436 + case Opt_nodirperm1:
24438 + case Opt_noplink:
24439 + case Opt_list_plink:
24442 + case Opt_diropq_a:
24443 + case Opt_diropq_w:
24444 + case Opt_warn_perm:
24445 + case Opt_nowarn_perm:
24446 + case Opt_verbose:
24447 + case Opt_noverbose:
24451 + case Opt_rdblk_def:
24452 + case Opt_rdhash_def:
24456 + opt->type = token;
24460 + opt->udba = udba_val(a->args[0].from);
24461 + if (opt->udba >= 0) {
24463 + opt->type = token;
24465 + pr_err("wrong value, %s\n", opt_str);
24468 + case Opt_wbr_create:
24469 + u.create = &opt->wbr_create;
24470 + u.create->wbr_create
24471 + = au_wbr_create_val(a->args[0].from, u.create);
24472 + if (u.create->wbr_create >= 0) {
24474 + opt->type = token;
24476 + pr_err("wrong value, %s\n", opt_str);
24478 + case Opt_wbr_copyup:
24479 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24480 + if (opt->wbr_copyup >= 0) {
24482 + opt->type = token;
24484 + pr_err("wrong value, %s\n", opt_str);
24487 + case Opt_fhsm_sec:
24488 + if (unlikely(match_int(&a->args[0], &n)
24490 + pr_err("bad integer in %s\n", opt_str);
24493 + if (sysaufs_brs) {
24494 + opt->fhsm_second = n;
24495 + opt->type = token;
24497 + pr_warn("ignored %s\n", opt_str);
24502 + pr_warn("ignored %s\n", opt_str);
24504 + case Opt_ignore_silent:
24509 + pr_err("unknown option %s\n", opt_str);
24513 + if (!err && !skipped) {
24514 + if (unlikely(++opt > opt_tail)) {
24517 + opt->type = Opt_tail;
24520 + opt->type = Opt_tail;
24524 + au_delayed_kfree(a);
24526 + if (unlikely(err))
24527 + au_opts_free(opts);
24533 +static int au_opt_wbr_create(struct super_block *sb,
24534 + struct au_opt_wbr_create *create)
24537 + struct au_sbinfo *sbinfo;
24539 + SiMustWriteLock(sb);
24541 + err = 1; /* handled */
24542 + sbinfo = au_sbi(sb);
24543 + if (sbinfo->si_wbr_create_ops->fin) {
24544 + err = sbinfo->si_wbr_create_ops->fin(sb);
24549 + sbinfo->si_wbr_create = create->wbr_create;
24550 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24551 + switch (create->wbr_create) {
24552 + case AuWbrCreate_MFSRRV:
24553 + case AuWbrCreate_MFSRR:
24554 + case AuWbrCreate_TDMFS:
24555 + case AuWbrCreate_TDMFSV:
24556 + case AuWbrCreate_PMFSRR:
24557 + case AuWbrCreate_PMFSRRV:
24558 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24560 + case AuWbrCreate_MFS:
24561 + case AuWbrCreate_MFSV:
24562 + case AuWbrCreate_PMFS:
24563 + case AuWbrCreate_PMFSV:
24564 + sbinfo->si_wbr_mfs.mfs_expire
24565 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24569 + if (sbinfo->si_wbr_create_ops->init)
24570 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24577 + * plus: processed without an error
24578 + * zero: unprocessed
24580 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24581 + struct au_opts *opts)
24584 + struct au_sbinfo *sbinfo;
24586 + SiMustWriteLock(sb);
24588 + err = 1; /* handled */
24589 + sbinfo = au_sbi(sb);
24590 + switch (opt->type) {
24592 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24593 + sbinfo->si_mntflags |= opt->udba;
24594 + opts->given_udba |= opt->udba;
24598 + au_opt_set(sbinfo->si_mntflags, PLINK);
24600 + case Opt_noplink:
24601 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24602 + au_plink_put(sb, /*verbose*/1);
24603 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24605 + case Opt_list_plink:
24606 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24607 + au_plink_list(sb);
24611 + au_opt_set(sbinfo->si_mntflags, DIO);
24612 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24615 + au_opt_clr(sbinfo->si_mntflags, DIO);
24616 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24619 + case Opt_fhsm_sec:
24620 + au_fhsm_set(sbinfo, opt->fhsm_second);
24623 + case Opt_diropq_a:
24624 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24626 + case Opt_diropq_w:
24627 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24630 + case Opt_warn_perm:
24631 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24633 + case Opt_nowarn_perm:
24634 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24637 + case Opt_verbose:
24638 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24640 + case Opt_noverbose:
24641 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24645 + au_opt_set(sbinfo->si_mntflags, SUM);
24648 + au_opt_clr(sbinfo->si_mntflags, SUM);
24649 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24651 + au_opt_clr(sbinfo->si_mntflags, SUM);
24652 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24655 + case Opt_wbr_create:
24656 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24658 + case Opt_wbr_copyup:
24659 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24660 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24664 + sbinfo->si_dirwh = opt->dirwh;
24667 + case Opt_rdcache:
24668 + sbinfo->si_rdcache
24669 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24672 + sbinfo->si_rdblk = opt->rdblk;
24674 + case Opt_rdblk_def:
24675 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24678 + sbinfo->si_rdhash = opt->rdhash;
24680 + case Opt_rdhash_def:
24681 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24685 + au_opt_set(sbinfo->si_mntflags, SHWH);
24688 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24691 + case Opt_dirperm1:
24692 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24694 + case Opt_nodirperm1:
24695 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24698 + case Opt_trunc_xino:
24699 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24701 + case Opt_notrunc_xino:
24702 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24705 + case Opt_trunc_xino_path:
24706 + case Opt_itrunc_xino:
24707 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24712 + case Opt_trunc_xib:
24713 + au_fset_opts(opts->flags, TRUNC_XIB);
24715 + case Opt_notrunc_xib:
24716 + au_fclr_opts(opts->flags, TRUNC_XIB);
24720 + sb->s_flags |= MS_POSIXACL;
24723 + sb->s_flags &= ~MS_POSIXACL;
24735 + * returns tri-state.
24736 + * plus: processed without an error
24737 + * zero: unprocessed
24740 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24741 + struct au_opts *opts)
24743 + int err, do_refresh;
24746 + switch (opt->type) {
24748 + opt->add.bindex = au_sbbot(sb) + 1;
24749 + if (opt->add.bindex < 0)
24750 + opt->add.bindex = 0;
24752 + case Opt_prepend:
24753 + opt->add.bindex = 0;
24754 + add: /* indented label */
24756 + err = au_br_add(sb, &opt->add,
24757 + au_ftest_opts(opts->flags, REMOUNT));
24760 + au_fset_opts(opts->flags, REFRESH);
24766 + err = au_br_del(sb, &opt->del,
24767 + au_ftest_opts(opts->flags, REMOUNT));
24770 + au_fset_opts(opts->flags, TRUNC_XIB);
24771 + au_fset_opts(opts->flags, REFRESH);
24777 + err = au_br_mod(sb, &opt->mod,
24778 + au_ftest_opts(opts->flags, REMOUNT),
24783 + au_fset_opts(opts->flags, REFRESH);
24791 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24792 + struct au_opt_xino **opt_xino,
24793 + struct au_opts *opts)
24796 + aufs_bindex_t bbot, bindex;
24797 + struct dentry *root, *parent, *h_root;
24800 + switch (opt->type) {
24802 + err = au_xino_set(sb, &opt->xino,
24803 + !!au_ftest_opts(opts->flags, REMOUNT));
24804 + if (unlikely(err))
24807 + *opt_xino = &opt->xino;
24808 + au_xino_brid_set(sb, -1);
24810 + /* safe d_parent access */
24811 + parent = opt->xino.file->f_path.dentry->d_parent;
24812 + root = sb->s_root;
24813 + bbot = au_sbbot(sb);
24814 + for (bindex = 0; bindex <= bbot; bindex++) {
24815 + h_root = au_h_dptr(root, bindex);
24816 + if (h_root == parent) {
24817 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24825 + au_xino_brid_set(sb, -1);
24826 + *opt_xino = (void *)-1;
24833 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24834 + unsigned int pending)
24837 + aufs_bindex_t bindex, bbot;
24838 + unsigned char do_plink, skip, do_free, can_no_dreval;
24839 + struct au_branch *br;
24840 + struct au_wbr *wbr;
24841 + struct dentry *root, *dentry;
24842 + struct inode *dir, *h_dir;
24843 + struct au_sbinfo *sbinfo;
24844 + struct au_hinode *hdir;
24846 + SiMustAnyLock(sb);
24848 + sbinfo = au_sbi(sb);
24849 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24851 + if (!(sb_flags & MS_RDONLY)) {
24852 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24853 + pr_warn("first branch should be rw\n");
24854 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24855 + pr_warn_once("shwh should be used with ro\n");
24858 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24859 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24860 + pr_warn_once("udba=*notify requires xino\n");
24862 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24863 + pr_warn_once("dirperm1 breaks the protection"
24864 + " by the permission bits on the lower branch\n");
24868 + root = sb->s_root;
24869 + dir = d_inode(root);
24870 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24871 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24873 + bbot = au_sbbot(sb);
24874 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24876 + h_dir = au_h_iptr(dir, bindex);
24877 + br = au_sbr(sb, bindex);
24879 + if ((br->br_perm & AuBrAttr_ICEX)
24880 + && !h_dir->i_op->listxattr)
24881 + br->br_perm &= ~AuBrAttr_ICEX;
24883 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24884 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24885 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24889 + wbr = br->br_wbr;
24891 + wbr_wh_read_lock(wbr);
24893 + if (!au_br_writable(br->br_perm)) {
24896 + || (!wbr->wbr_whbase
24897 + && !wbr->wbr_plink
24898 + && !wbr->wbr_orph));
24899 + } else if (!au_br_wh_linkable(br->br_perm)) {
24900 + /* skip = (!br->br_whbase && !br->br_orph); */
24901 + skip = (!wbr || !wbr->wbr_whbase);
24902 + if (skip && wbr) {
24904 + skip = !!wbr->wbr_plink;
24906 + skip = !wbr->wbr_plink;
24909 + /* skip = (br->br_whbase && br->br_ohph); */
24910 + skip = (wbr && wbr->wbr_whbase);
24913 + skip = !!wbr->wbr_plink;
24915 + skip = !wbr->wbr_plink;
24919 + wbr_wh_read_unlock(wbr);
24921 + if (can_no_dreval) {
24922 + dentry = br->br_path.dentry;
24923 + spin_lock(&dentry->d_lock);
24924 + if (dentry->d_flags &
24925 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24926 + can_no_dreval = 0;
24927 + spin_unlock(&dentry->d_lock);
24930 + if (au_br_fhsm(br->br_perm)) {
24932 + AuDebugOn(!br->br_fhsm);
24938 + hdir = au_hi(dir, bindex);
24939 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24941 + wbr_wh_write_lock(wbr);
24942 + err = au_wh_init(br, sb);
24944 + wbr_wh_write_unlock(wbr);
24945 + au_hn_inode_unlock(hdir);
24947 + if (!err && do_free) {
24949 + au_delayed_kfree(wbr);
24950 + br->br_wbr = NULL;
24954 + if (can_no_dreval)
24955 + au_fset_si(sbinfo, NO_DREVAL);
24957 + au_fclr_si(sbinfo, NO_DREVAL);
24960 + au_fset_si(sbinfo, FHSM);
24961 + for (bindex = bbot; bindex >= 0; bindex--) {
24962 + br = au_sbr(sb, bindex);
24963 + if (au_br_fhsm(br->br_perm)) {
24964 + au_fhsm_set_bottom(sb, bindex);
24969 + au_fclr_si(sbinfo, FHSM);
24970 + au_fhsm_set_bottom(sb, -1);
24976 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24979 + unsigned int tmp;
24980 + aufs_bindex_t bindex, bbot;
24981 + struct au_opt *opt;
24982 + struct au_opt_xino *opt_xino, xino;
24983 + struct au_sbinfo *sbinfo;
24984 + struct au_branch *br;
24985 + struct inode *dir;
24987 + SiMustWriteLock(sb);
24992 + while (err >= 0 && opt->type != Opt_tail)
24993 + err = au_opt_simple(sb, opt++, opts);
24996 + else if (unlikely(err < 0))
24999 + /* disable xino and udba temporary */
25000 + sbinfo = au_sbi(sb);
25001 + tmp = sbinfo->si_mntflags;
25002 + au_opt_clr(sbinfo->si_mntflags, XINO);
25003 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25006 + while (err >= 0 && opt->type != Opt_tail)
25007 + err = au_opt_br(sb, opt++, opts);
25010 + else if (unlikely(err < 0))
25013 + bbot = au_sbbot(sb);
25014 + if (unlikely(bbot < 0)) {
25016 + pr_err("no branches\n");
25020 + if (au_opt_test(tmp, XINO))
25021 + au_opt_set(sbinfo->si_mntflags, XINO);
25023 + while (!err && opt->type != Opt_tail)
25024 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25025 + if (unlikely(err))
25028 + err = au_opts_verify(sb, sb->s_flags, tmp);
25029 + if (unlikely(err))
25032 + /* restore xino */
25033 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25034 + xino.file = au_xino_def(sb);
25035 + err = PTR_ERR(xino.file);
25036 + if (IS_ERR(xino.file))
25039 + err = au_xino_set(sb, &xino, /*remount*/0);
25041 + if (unlikely(err))
25045 + /* restore udba */
25046 + tmp &= AuOptMask_UDBA;
25047 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25048 + sbinfo->si_mntflags |= tmp;
25049 + bbot = au_sbbot(sb);
25050 + for (bindex = 0; bindex <= bbot; bindex++) {
25051 + br = au_sbr(sb, bindex);
25052 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25053 + if (unlikely(err))
25054 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25056 + /* go on even if err */
25058 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25059 + dir = d_inode(sb->s_root);
25060 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25067 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25070 + unsigned char no_dreval;
25071 + struct inode *dir;
25072 + struct au_opt_xino *opt_xino;
25073 + struct au_opt *opt;
25074 + struct au_sbinfo *sbinfo;
25076 + SiMustWriteLock(sb);
25079 + dir = d_inode(sb->s_root);
25080 + sbinfo = au_sbi(sb);
25083 + while (err >= 0 && opt->type != Opt_tail) {
25084 + err = au_opt_simple(sb, opt, opts);
25086 + err = au_opt_br(sb, opt, opts);
25088 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25094 + /* go on even err */
25096 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25097 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25098 + if (unlikely(rerr && !err))
25101 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25102 + au_fset_opts(opts->flags, REFRESH_IDOP);
25104 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25105 + rerr = au_xib_trunc(sb);
25106 + if (unlikely(rerr && !err))
25110 + /* will be handled by the caller */
25111 + if (!au_ftest_opts(opts->flags, REFRESH)
25112 + && (opts->given_udba
25113 + || au_opt_test(sbinfo->si_mntflags, XINO)
25114 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25116 + au_fset_opts(opts->flags, REFRESH);
25118 + AuDbg("status 0x%x\n", opts->flags);
25122 +/* ---------------------------------------------------------------------- */
25124 +unsigned int au_opt_udba(struct super_block *sb)
25126 + return au_mntflags(sb) & AuOptMask_UDBA;
25128 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25129 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25130 +++ linux/fs/aufs/opts.h 2017-03-02 14:24:13.863589061 +0100
25133 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25135 + * This program, aufs is free software; you can redistribute it and/or modify
25136 + * it under the terms of the GNU General Public License as published by
25137 + * the Free Software Foundation; either version 2 of the License, or
25138 + * (at your option) any later version.
25140 + * This program is distributed in the hope that it will be useful,
25141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25143 + * GNU General Public License for more details.
25145 + * You should have received a copy of the GNU General Public License
25146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25150 + * mount options/flags
25153 +#ifndef __AUFS_OPTS_H__
25154 +#define __AUFS_OPTS_H__
25158 +#include <linux/path.h>
25161 +struct super_block;
25163 +/* ---------------------------------------------------------------------- */
25166 +#define AuOpt_XINO 1 /* external inode number bitmap
25167 + and translation table */
25168 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25169 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25170 +#define AuOpt_UDBA_REVAL (1 << 3)
25171 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25172 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25173 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25174 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25176 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25177 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25178 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25179 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25180 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25181 +#define AuOpt_DIO (1 << 14) /* direct io */
25183 +#ifndef CONFIG_AUFS_HNOTIFY
25184 +#undef AuOpt_UDBA_HNOTIFY
25185 +#define AuOpt_UDBA_HNOTIFY 0
25187 +#ifndef CONFIG_AUFS_SHWH
25189 +#define AuOpt_SHWH 0
25192 +#define AuOpt_Def (AuOpt_XINO \
25193 + | AuOpt_UDBA_REVAL \
25195 + /* | AuOpt_DIRPERM1 */ \
25196 + | AuOpt_WARN_PERM)
25197 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25198 + | AuOpt_UDBA_REVAL \
25199 + | AuOpt_UDBA_HNOTIFY)
25201 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25202 +#define au_opt_set(flags, name) do { \
25203 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25204 + ((flags) |= AuOpt_##name); \
25206 +#define au_opt_set_udba(flags, name) do { \
25207 + (flags) &= ~AuOptMask_UDBA; \
25208 + ((flags) |= AuOpt_##name); \
25210 +#define au_opt_clr(flags, name) do { \
25211 + ((flags) &= ~AuOpt_##name); \
25214 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25216 +#ifdef CONFIG_PROC_FS
25219 + return mntflags & ~AuOpt_PLINK;
25223 +/* ---------------------------------------------------------------------- */
25225 +/* policies to select one among multiple writable branches */
25227 + AuWbrCreate_TDP, /* top down parent */
25228 + AuWbrCreate_RR, /* round robin */
25229 + AuWbrCreate_MFS, /* most free space */
25230 + AuWbrCreate_MFSV, /* mfs with seconds */
25231 + AuWbrCreate_MFSRR, /* mfs then rr */
25232 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25233 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25234 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25235 + AuWbrCreate_PMFS, /* parent and mfs */
25236 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25237 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25238 + AuWbrCreate_PMFSRRV, /* plus seconds */
25240 + AuWbrCreate_Def = AuWbrCreate_TDP
25244 + AuWbrCopyup_TDP, /* top down parent */
25245 + AuWbrCopyup_BUP, /* bottom up parent */
25246 + AuWbrCopyup_BU, /* bottom up */
25248 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25251 +/* ---------------------------------------------------------------------- */
25253 +struct au_opt_add {
25254 + aufs_bindex_t bindex;
25257 + struct path path;
25260 +struct au_opt_del {
25262 + struct path h_path;
25265 +struct au_opt_mod {
25268 + struct dentry *h_root;
25271 +struct au_opt_xino {
25273 + struct file *file;
25276 +struct au_opt_xino_itrunc {
25277 + aufs_bindex_t bindex;
25280 +struct au_opt_wbr_create {
25283 + unsigned long long mfsrr_watermark;
25289 + struct au_opt_xino xino;
25290 + struct au_opt_xino_itrunc xino_itrunc;
25291 + struct au_opt_add add;
25292 + struct au_opt_del del;
25293 + struct au_opt_mod mod;
25296 + unsigned int rdblk;
25297 + unsigned int rdhash;
25299 + struct au_opt_wbr_create wbr_create;
25301 + unsigned int fhsm_second;
25306 +#define AuOpts_REMOUNT 1
25307 +#define AuOpts_REFRESH (1 << 1)
25308 +#define AuOpts_TRUNC_XIB (1 << 2)
25309 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25310 +#define AuOpts_REFRESH_IDOP (1 << 4)
25311 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25312 +#define au_fset_opts(flags, name) \
25313 + do { (flags) |= AuOpts_##name; } while (0)
25314 +#define au_fclr_opts(flags, name) \
25315 + do { (flags) &= ~AuOpts_##name; } while (0)
25318 + struct au_opt *opt;
25321 + unsigned int given_udba;
25322 + unsigned int flags;
25323 + unsigned long sb_flags;
25326 +/* ---------------------------------------------------------------------- */
25329 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25330 +const char *au_optstr_udba(int udba);
25331 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25332 +const char *au_optstr_wbr_create(int wbr_create);
25334 +void au_opts_free(struct au_opts *opts);
25335 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25336 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25337 + unsigned int pending);
25338 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25339 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25341 +unsigned int au_opt_udba(struct super_block *sb);
25343 +#endif /* __KERNEL__ */
25344 +#endif /* __AUFS_OPTS_H__ */
25345 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25346 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25347 +++ linux/fs/aufs/plink.c 2017-03-02 14:24:13.866922487 +0100
25350 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25352 + * This program, aufs is free software; you can redistribute it and/or modify
25353 + * it under the terms of the GNU General Public License as published by
25354 + * the Free Software Foundation; either version 2 of the License, or
25355 + * (at your option) any later version.
25357 + * This program is distributed in the hope that it will be useful,
25358 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25359 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25360 + * GNU General Public License for more details.
25362 + * You should have received a copy of the GNU General Public License
25363 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25373 + * the pseudo-link maintenance mode.
25374 + * during a user process maintains the pseudo-links,
25375 + * prohibit adding a new plink and branch manipulation.
25379 + * For entry functions which will handle plink, and i_mutex is already held
25381 + * They cannot wait and should return an error at once.
25382 + * Callers has to check the error.
25384 + * For entry functions which will handle plink, but i_mutex is not held
25386 + * They can wait the plink maintenance mode to finish.
25388 + * They behave like F_SETLK and F_SETLKW.
25389 + * If the caller never handle plink, then both flags are unnecessary.
25392 +int au_plink_maint(struct super_block *sb, int flags)
25396 + struct task_struct *parent, *prev;
25397 + struct au_sbinfo *sbi;
25399 + SiMustAnyLock(sb);
25402 + if (!au_opt_test(au_mntflags(sb), PLINK))
25405 + sbi = au_sbi(sb);
25406 + pid = sbi->si_plink_maint_pid;
25407 + if (!pid || pid == current->pid)
25410 + /* todo: it highly depends upon /sbin/mount.aufs */
25412 + parent = current;
25416 + parent = rcu_dereference(parent->real_parent);
25417 + if (parent == prev)
25419 + ppid = task_pid_vnr(parent);
25420 + if (pid == ppid) {
25421 + rcu_read_unlock();
25426 + rcu_read_unlock();
25428 + if (au_ftest_lock(flags, NOPLMW)) {
25429 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25430 + /* AuDebugOn(!lockdep_depth(current)); */
25431 + while (sbi->si_plink_maint_pid) {
25432 + si_read_unlock(sb);
25433 + /* gave up wake_up_bit() */
25434 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25436 + if (au_ftest_lock(flags, FLUSH))
25437 + au_nwt_flush(&sbi->si_nowait);
25438 + si_noflush_read_lock(sb);
25440 + } else if (au_ftest_lock(flags, NOPLM)) {
25441 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25449 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25451 + spin_lock(&sbinfo->si_plink_maint_lock);
25452 + sbinfo->si_plink_maint_pid = 0;
25453 + spin_unlock(&sbinfo->si_plink_maint_lock);
25454 + wake_up_all(&sbinfo->si_plink_wq);
25457 +int au_plink_maint_enter(struct super_block *sb)
25460 + struct au_sbinfo *sbinfo;
25463 + sbinfo = au_sbi(sb);
25464 + /* make sure i am the only one in this fs */
25465 + si_write_lock(sb, AuLock_FLUSH);
25466 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25467 + spin_lock(&sbinfo->si_plink_maint_lock);
25468 + if (!sbinfo->si_plink_maint_pid)
25469 + sbinfo->si_plink_maint_pid = current->pid;
25472 + spin_unlock(&sbinfo->si_plink_maint_lock);
25474 + si_write_unlock(sb);
25479 +/* ---------------------------------------------------------------------- */
25481 +#ifdef CONFIG_AUFS_DEBUG
25482 +void au_plink_list(struct super_block *sb)
25485 + struct au_sbinfo *sbinfo;
25486 + struct hlist_head *plink_hlist;
25487 + struct au_icntnr *icntnr;
25489 + SiMustAnyLock(sb);
25491 + sbinfo = au_sbi(sb);
25492 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25493 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25495 + for (i = 0; i < AuPlink_NHASH; i++) {
25496 + plink_hlist = &sbinfo->si_plink[i].head;
25498 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25499 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25500 + rcu_read_unlock();
25505 +/* is the inode pseudo-linked? */
25506 +int au_plink_test(struct inode *inode)
25509 + struct au_sbinfo *sbinfo;
25510 + struct hlist_head *plink_hlist;
25511 + struct au_icntnr *icntnr;
25513 + sbinfo = au_sbi(inode->i_sb);
25514 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25515 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25516 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25519 + i = au_plink_hash(inode->i_ino);
25520 + plink_hlist = &sbinfo->si_plink[i].head;
25522 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25523 + if (&icntnr->vfs_inode == inode) {
25527 + rcu_read_unlock();
25531 +/* ---------------------------------------------------------------------- */
25534 + * generate a name for plink.
25535 + * the file will be stored under AUFS_WH_PLINKDIR.
25537 +/* 20 is max digits length of ulong 64 */
25538 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25540 +static int plink_name(char *name, int len, struct inode *inode,
25541 + aufs_bindex_t bindex)
25544 + struct inode *h_inode;
25546 + h_inode = au_h_iptr(inode, bindex);
25547 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25551 +struct au_do_plink_lkup_args {
25552 + struct dentry **errp;
25553 + struct qstr *tgtname;
25554 + struct dentry *h_parent;
25555 + struct au_branch *br;
25558 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25559 + struct dentry *h_parent,
25560 + struct au_branch *br)
25562 + struct dentry *h_dentry;
25563 + struct inode *h_inode;
25565 + h_inode = d_inode(h_parent);
25566 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25567 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25568 + inode_unlock(h_inode);
25572 +static void au_call_do_plink_lkup(void *args)
25574 + struct au_do_plink_lkup_args *a = args;
25575 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25578 +/* lookup the plink-ed @inode under the branch at @bindex */
25579 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25581 + struct dentry *h_dentry, *h_parent;
25582 + struct au_branch *br;
25584 + char a[PLINK_NAME_LEN];
25585 + struct qstr tgtname = QSTR_INIT(a, 0);
25587 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25589 + br = au_sbr(inode->i_sb, bindex);
25590 + h_parent = br->br_wbr->wbr_plink;
25591 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25593 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25594 + struct au_do_plink_lkup_args args = {
25595 + .errp = &h_dentry,
25596 + .tgtname = &tgtname,
25597 + .h_parent = h_parent,
25601 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25602 + if (unlikely(wkq_err))
25603 + h_dentry = ERR_PTR(wkq_err);
25605 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25610 +/* create a pseudo-link */
25611 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25612 + struct dentry *h_dentry, struct au_branch *br)
25615 + struct path h_path = {
25616 + .mnt = au_br_mnt(br)
25618 + struct inode *h_dir, *delegated;
25620 + h_dir = d_inode(h_parent);
25621 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25623 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25624 + err = PTR_ERR(h_path.dentry);
25625 + if (IS_ERR(h_path.dentry))
25629 + /* wh.plink dir is not monitored */
25630 + /* todo: is it really safe? */
25631 + if (d_is_positive(h_path.dentry)
25632 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25633 + delegated = NULL;
25634 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25635 + if (unlikely(err == -EWOULDBLOCK)) {
25636 + pr_warn("cannot retry for NFSv4 delegation"
25637 + " for an internal unlink\n");
25640 + dput(h_path.dentry);
25641 + h_path.dentry = NULL;
25645 + if (!err && d_is_negative(h_path.dentry)) {
25646 + delegated = NULL;
25647 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25648 + if (unlikely(err == -EWOULDBLOCK)) {
25649 + pr_warn("cannot retry for NFSv4 delegation"
25650 + " for an internal link\n");
25654 + dput(h_path.dentry);
25657 + inode_unlock(h_dir);
25661 +struct do_whplink_args {
25663 + struct qstr *tgt;
25664 + struct dentry *h_parent;
25665 + struct dentry *h_dentry;
25666 + struct au_branch *br;
25669 +static void call_do_whplink(void *args)
25671 + struct do_whplink_args *a = args;
25672 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25675 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25676 + aufs_bindex_t bindex, struct au_branch *br)
25678 + int err, wkq_err;
25679 + struct au_wbr *wbr;
25680 + struct dentry *h_parent;
25681 + char a[PLINK_NAME_LEN];
25682 + struct qstr tgtname = QSTR_INIT(a, 0);
25684 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25685 + h_parent = wbr->wbr_plink;
25686 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25688 + /* always superio. */
25689 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25690 + struct do_whplink_args args = {
25693 + .h_parent = h_parent,
25694 + .h_dentry = h_dentry,
25697 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25698 + if (unlikely(wkq_err))
25701 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25707 + * create a new pseudo-link for @h_dentry on @bindex.
25708 + * the linked inode is held in aufs @inode.
25710 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25711 + struct dentry *h_dentry)
25713 + struct super_block *sb;
25714 + struct au_sbinfo *sbinfo;
25715 + struct hlist_head *plink_hlist;
25716 + struct au_icntnr *icntnr;
25717 + struct au_sphlhead *sphl;
25718 + int found, err, cnt, i;
25720 + sb = inode->i_sb;
25721 + sbinfo = au_sbi(sb);
25722 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25723 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25725 + found = au_plink_test(inode);
25729 + i = au_plink_hash(inode->i_ino);
25730 + sphl = sbinfo->si_plink + i;
25731 + plink_hlist = &sphl->head;
25734 + spin_lock(&sphl->spin);
25735 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25736 + if (&icntnr->vfs_inode == inode) {
25742 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25743 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25745 + spin_unlock(&sphl->spin);
25747 + cnt = au_sphl_count(sphl);
25748 +#define msg "unexpectedly unblanced or too many pseudo-links"
25749 + if (cnt > AUFS_PLINK_WARN)
25750 + AuWarn1(msg ", %d\n", cnt);
25752 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25753 + if (unlikely(err)) {
25754 + pr_warn("err %d, damaged pseudo link.\n", err);
25755 + au_sphl_del_rcu(&icntnr->plink, sphl);
25756 + iput(&icntnr->vfs_inode);
25759 + iput(&icntnr->vfs_inode);
25762 +/* free all plinks */
25763 +void au_plink_put(struct super_block *sb, int verbose)
25766 + struct au_sbinfo *sbinfo;
25767 + struct hlist_head *plink_hlist;
25768 + struct hlist_node *tmp;
25769 + struct au_icntnr *icntnr;
25771 + SiMustWriteLock(sb);
25773 + sbinfo = au_sbi(sb);
25774 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25775 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25777 + /* no spin_lock since sbinfo is write-locked */
25779 + for (i = 0; i < AuPlink_NHASH; i++) {
25780 + plink_hlist = &sbinfo->si_plink[i].head;
25781 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25782 + pr_warn("pseudo-link is not flushed");
25785 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25786 + iput(&icntnr->vfs_inode);
25787 + INIT_HLIST_HEAD(plink_hlist);
25791 +void au_plink_clean(struct super_block *sb, int verbose)
25793 + struct dentry *root;
25795 + root = sb->s_root;
25796 + aufs_write_lock(root);
25797 + if (au_opt_test(au_mntflags(sb), PLINK))
25798 + au_plink_put(sb, verbose);
25799 + aufs_write_unlock(root);
25802 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25805 + aufs_bindex_t btop, bbot, bindex;
25808 + btop = au_ibtop(inode);
25809 + bbot = au_ibbot(inode);
25811 + for (bindex = btop; bindex <= bbot; bindex++) {
25812 + if (!au_h_iptr(inode, bindex)
25813 + || au_ii_br_id(inode, bindex) != br_id)
25815 + au_set_h_iptr(inode, bindex, NULL, 0);
25820 + for (bindex = btop; bindex <= bbot; bindex++)
25821 + if (au_h_iptr(inode, bindex)) {
25831 +/* free the plinks on a branch specified by @br_id */
25832 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25834 + struct au_sbinfo *sbinfo;
25835 + struct hlist_head *plink_hlist;
25836 + struct hlist_node *tmp;
25837 + struct au_icntnr *icntnr;
25838 + struct inode *inode;
25841 + SiMustWriteLock(sb);
25843 + sbinfo = au_sbi(sb);
25844 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25845 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25847 + /* no spin_lock since sbinfo is write-locked */
25848 + for (i = 0; i < AuPlink_NHASH; i++) {
25849 + plink_hlist = &sbinfo->si_plink[i].head;
25850 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25851 + inode = au_igrab(&icntnr->vfs_inode);
25852 + ii_write_lock_child(inode);
25853 + do_put = au_plink_do_half_refresh(inode, br_id);
25855 + hlist_del(&icntnr->plink);
25858 + ii_write_unlock(inode);
25863 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25864 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25865 +++ linux/fs/aufs/poll.c 2017-03-02 14:24:13.866922487 +0100
25868 + * Copyright (C) 2005-2017 Junjiro R. Okajima
25870 + * This program, aufs is free software; you can redistribute it and/or modify
25871 + * it under the terms of the GNU General Public License as published by
25872 + * the Free Software Foundation; either version 2 of the License, or
25873 + * (at your option) any later version.
25875 + * This program is distributed in the hope that it will be useful,
25876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25878 + * GNU General Public License for more details.
25880 + * You should have received a copy of the GNU General Public License
25881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25886 + * There is only one filesystem which implements ->poll operation, currently.
25891 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25893 + unsigned int mask;
25895 + struct file *h_file;
25896 + struct super_block *sb;
25898 + /* We should pretend an error happened. */
25899 + mask = POLLERR /* | POLLIN | POLLOUT */;
25900 + sb = file->f_path.dentry->d_sb;
25901 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25903 + h_file = au_read_pre(file, /*keep_fi*/0);
25904 + err = PTR_ERR(h_file);
25905 + if (IS_ERR(h_file))
25908 + /* it is not an error if h_file has no operation */
25909 + mask = DEFAULT_POLLMASK;
25910 + if (h_file->f_op->poll)
25911 + mask = h_file->f_op->poll(h_file, wait);
25912 + fput(h_file); /* instead of au_read_post() */
25915 + si_read_unlock(sb);
25916 + AuTraceErr((int)mask);
25919 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25920 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25921 +++ linux/fs/aufs/posix_acl.c 2017-03-02 14:24:13.866922487 +0100
25924 + * Copyright (C) 2014-2017 Junjiro R. Okajima
25926 + * This program, aufs is free software; you can redistribute it and/or modify
25927 + * it under the terms of the GNU General Public License as published by
25928 + * the Free Software Foundation; either version 2 of the License, or
25929 + * (at your option) any later version.
25931 + * This program is distributed in the hope that it will be useful,
25932 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25933 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25934 + * GNU General Public License for more details.
25936 + * You should have received a copy of the GNU General Public License
25937 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25941 + * posix acl operations
25944 +#include <linux/fs.h>
25947 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25949 + struct posix_acl *acl;
25951 + aufs_bindex_t bindex;
25952 + struct inode *h_inode;
25953 + struct super_block *sb;
25956 + sb = inode->i_sb;
25957 + si_read_lock(sb, AuLock_FLUSH);
25958 + ii_read_lock_child(inode);
25959 + if (!(sb->s_flags & MS_POSIXACL))
25962 + bindex = au_ibtop(inode);
25963 + h_inode = au_h_iptr(inode, bindex);
25964 + if (unlikely(!h_inode
25965 + || ((h_inode->i_mode & S_IFMT)
25966 + != (inode->i_mode & S_IFMT)))) {
25967 + err = au_busy_or_stale();
25968 + acl = ERR_PTR(err);
25972 + /* always topmost only */
25973 + acl = get_acl(h_inode, type);
25974 + if (!IS_ERR_OR_NULL(acl))
25975 + set_cached_acl(inode, type, acl);
25978 + ii_read_unlock(inode);
25979 + si_read_unlock(sb);
25981 + AuTraceErrPtr(acl);
25985 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25989 + struct dentry *dentry;
25990 + struct au_sxattr arg = {
25991 + .type = AU_ACL_SET,
25998 + IMustLock(inode);
26000 + if (inode->i_ino == AUFS_ROOT_INO)
26001 + dentry = dget(inode->i_sb->s_root);
26003 + dentry = d_find_alias(inode);
26005 + dentry = d_find_any_alias(inode);
26007 + pr_warn("cannot handle this inode, "
26008 + "please report to aufs-users ML\n");
26014 + ssz = au_sxattr(dentry, inode, &arg);
26019 + set_cached_acl(inode, type, acl);
26025 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
26026 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
26027 +++ linux/fs/aufs/procfs.c 2017-03-02 14:24:13.866922487 +0100
26030 + * Copyright (C) 2010-2017 Junjiro R. Okajima
26032 + * This program, aufs is free software; you can redistribute it and/or modify
26033 + * it under the terms of the GNU General Public License as published by
26034 + * the Free Software Foundation; either version 2 of the License, or
26035 + * (at your option) any later version.
26037 + * This program is distributed in the hope that it will be useful,
26038 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26039 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26040 + * GNU General Public License for more details.
26042 + * You should have received a copy of the GNU General Public License
26043 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26047 + * procfs interfaces
26050 +#include <linux/proc_fs.h>
26053 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
26055 + struct au_sbinfo *sbinfo;
26057 + sbinfo = file->private_data;
26059 + au_plink_maint_leave(sbinfo);
26060 + kobject_put(&sbinfo->si_kobj);
26066 +static void au_procfs_plm_write_clean(struct file *file)
26068 + struct au_sbinfo *sbinfo;
26070 + sbinfo = file->private_data;
26072 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
26075 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
26078 + struct super_block *sb;
26079 + struct au_sbinfo *sbinfo;
26082 + if (unlikely(file->private_data))
26086 + /* don't use au_sbilist_lock() here */
26087 + spin_lock(&au_sbilist.spin);
26088 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26089 + if (id == sysaufs_si_id(sbinfo)) {
26090 + kobject_get(&sbinfo->si_kobj);
26091 + sb = sbinfo->si_sb;
26094 + spin_unlock(&au_sbilist.spin);
26097 + if (unlikely(!sb))
26100 + err = au_plink_maint_enter(sb);
26102 + /* keep kobject_get() */
26103 + file->private_data = sbinfo;
26105 + kobject_put(&sbinfo->si_kobj);
26111 + * Accept a valid "si=xxxx" only.
26112 + * Once it is accepted successfully, accept "clean" too.
26114 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26115 + size_t count, loff_t *ppos)
26118 + unsigned long id;
26119 + /* last newline is allowed */
26120 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26123 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26127 + if (unlikely(count > sizeof(buf)))
26130 + err = copy_from_user(buf, ubuf, count);
26131 + if (unlikely(err)) {
26138 + if (!strcmp("clean", buf)) {
26139 + au_procfs_plm_write_clean(file);
26140 + goto out_success;
26141 + } else if (unlikely(strncmp("si=", buf, 3)))
26144 + err = kstrtoul(buf + 3, 16, &id);
26145 + if (unlikely(err))
26148 + err = au_procfs_plm_write_si(file, id);
26149 + if (unlikely(err))
26153 + err = count; /* success */
26158 +static const struct file_operations au_procfs_plm_fop = {
26159 + .write = au_procfs_plm_write,
26160 + .release = au_procfs_plm_release,
26161 + .owner = THIS_MODULE
26164 +/* ---------------------------------------------------------------------- */
26166 +static struct proc_dir_entry *au_procfs_dir;
26168 +void au_procfs_fin(void)
26170 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26171 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26174 +int __init au_procfs_init(void)
26177 + struct proc_dir_entry *entry;
26180 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26181 + if (unlikely(!au_procfs_dir))
26184 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26185 + au_procfs_dir, &au_procfs_plm_fop);
26186 + if (unlikely(!entry))
26190 + goto out; /* success */
26194 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26198 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26199 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26200 +++ linux/fs/aufs/rdu.c 2017-03-02 14:24:13.866922487 +0100
26203 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26205 + * This program, aufs is free software; you can redistribute it and/or modify
26206 + * it under the terms of the GNU General Public License as published by
26207 + * the Free Software Foundation; either version 2 of the License, or
26208 + * (at your option) any later version.
26210 + * This program is distributed in the hope that it will be useful,
26211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26213 + * GNU General Public License for more details.
26215 + * You should have received a copy of the GNU General Public License
26216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26220 + * readdir in userspace.
26223 +#include <linux/compat.h>
26224 +#include <linux/fs_stack.h>
26225 +#include <linux/security.h>
26228 +/* bits for struct aufs_rdu.flags */
26229 +#define AuRdu_CALLED 1
26230 +#define AuRdu_CONT (1 << 1)
26231 +#define AuRdu_FULL (1 << 2)
26232 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26233 +#define au_fset_rdu(flags, name) \
26234 + do { (flags) |= AuRdu_##name; } while (0)
26235 +#define au_fclr_rdu(flags, name) \
26236 + do { (flags) &= ~AuRdu_##name; } while (0)
26238 +struct au_rdu_arg {
26239 + struct dir_context ctx;
26240 + struct aufs_rdu *rdu;
26241 + union au_rdu_ent_ul ent;
26242 + unsigned long end;
26244 + struct super_block *sb;
26248 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26249 + loff_t offset, u64 h_ino, unsigned int d_type)
26252 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26253 + struct aufs_rdu *rdu = arg->rdu;
26254 + struct au_rdu_ent ent;
26258 + au_fset_rdu(rdu->cookie.flags, CALLED);
26259 + len = au_rdu_len(nlen);
26260 + if (arg->ent.ul + len < arg->end) {
26262 + ent.bindex = rdu->cookie.bindex;
26263 + ent.type = d_type;
26265 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26266 + ent.type = DT_UNKNOWN;
26268 + /* unnecessary to support mmap_sem since this is a dir */
26270 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26272 + if (copy_to_user(arg->ent.e->name, name, nlen))
26274 + /* the terminating NULL */
26275 + if (__put_user(0, arg->ent.e->name + nlen))
26278 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26279 + arg->ent.ul += len;
26283 + au_fset_rdu(rdu->cookie.flags, FULL);
26285 + rdu->tail = arg->ent;
26289 + /* AuTraceErr(err); */
26293 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26297 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26299 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26300 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26302 + if (unlikely(offset != cookie->h_pos))
26308 + au_fclr_rdu(cookie->flags, CALLED);
26310 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26314 + && au_ftest_rdu(cookie->flags, CALLED)
26315 + && !au_ftest_rdu(cookie->flags, FULL));
26316 + cookie->h_pos = h_file->f_pos;
26323 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26326 + aufs_bindex_t bbot;
26327 + struct au_rdu_arg arg = {
26329 + .actor = au_rdu_fill
26332 + struct dentry *dentry;
26333 + struct inode *inode;
26334 + struct file *h_file;
26335 + struct au_rdu_cookie *cookie = &rdu->cookie;
26337 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26338 + if (unlikely(err)) {
26344 + rdu->tail = rdu->ent;
26347 + arg.ent = rdu->ent;
26348 + arg.end = arg.ent.ul;
26349 + arg.end += rdu->sz;
26352 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26355 + err = security_file_permission(file, MAY_READ);
26357 + if (unlikely(err))
26360 + dentry = file->f_path.dentry;
26361 + inode = d_inode(dentry);
26362 + inode_lock_shared(inode);
26364 + arg.sb = inode->i_sb;
26365 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26366 + if (unlikely(err))
26368 + err = au_alive_dir(dentry);
26369 + if (unlikely(err))
26371 + /* todo: reval? */
26372 + fi_read_lock(file);
26375 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26376 + && cookie->generation != au_figen(file)))
26381 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26383 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26385 + bbot = au_fbtop(file);
26386 + if (cookie->bindex < bbot)
26387 + cookie->bindex = bbot;
26388 + bbot = au_fbbot_dir(file);
26389 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26390 + for (; !err && cookie->bindex <= bbot;
26391 + cookie->bindex++, cookie->h_pos = 0) {
26392 + h_file = au_hf_dir(file, cookie->bindex);
26396 + au_fclr_rdu(cookie->flags, FULL);
26397 + err = au_rdu_do(h_file, &arg);
26399 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26402 + AuDbg("rent %llu\n", rdu->rent);
26404 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26405 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26406 + au_fset_rdu(cookie->flags, CONT);
26407 + cookie->generation = au_figen(file);
26410 + ii_read_lock_child(inode);
26411 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26412 + ii_read_unlock(inode);
26415 + fi_read_unlock(file);
26417 + si_read_unlock(arg.sb);
26419 + inode_unlock_shared(inode);
26425 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26429 + unsigned long long nent;
26430 + union au_rdu_ent_ul *u;
26431 + struct au_rdu_ent ent;
26432 + struct super_block *sb;
26435 + nent = rdu->nent;
26437 + sb = file->f_path.dentry->d_sb;
26438 + si_read_lock(sb, AuLock_FLUSH);
26439 + while (nent-- > 0) {
26440 + /* unnecessary to support mmap_sem since this is a dir */
26441 + err = copy_from_user(&ent, u->e, sizeof(ent));
26443 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26444 + if (unlikely(err)) {
26450 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26452 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26454 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26456 + if (unlikely(err)) {
26461 + err = __put_user(ino, &u->e->ino);
26462 + if (unlikely(err)) {
26467 + u->ul += au_rdu_len(ent.nlen);
26469 + si_read_unlock(sb);
26474 +/* ---------------------------------------------------------------------- */
26476 +static int au_rdu_verify(struct aufs_rdu *rdu)
26478 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26479 + "%llu, b%d, 0x%x, g%u}\n",
26480 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26482 + rdu->rent, rdu->shwh, rdu->full,
26483 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26484 + rdu->cookie.generation);
26486 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26490 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26494 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26497 + struct aufs_rdu rdu;
26498 + void __user *p = (void __user *)arg;
26500 + err = copy_from_user(&rdu, p, sizeof(rdu));
26501 + if (unlikely(err)) {
26506 + err = au_rdu_verify(&rdu);
26507 + if (unlikely(err))
26511 + case AUFS_CTL_RDU:
26512 + err = au_rdu(file, &rdu);
26513 + if (unlikely(err))
26516 + e = copy_to_user(p, &rdu, sizeof(rdu));
26517 + if (unlikely(e)) {
26522 + case AUFS_CTL_RDU_INO:
26523 + err = au_rdu_ino(file, &rdu);
26527 + /* err = -ENOTTY; */
26536 +#ifdef CONFIG_COMPAT
26537 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26540 + struct aufs_rdu rdu;
26541 + void __user *p = compat_ptr(arg);
26543 + /* todo: get_user()? */
26544 + err = copy_from_user(&rdu, p, sizeof(rdu));
26545 + if (unlikely(err)) {
26550 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26551 + err = au_rdu_verify(&rdu);
26552 + if (unlikely(err))
26556 + case AUFS_CTL_RDU:
26557 + err = au_rdu(file, &rdu);
26558 + if (unlikely(err))
26561 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26562 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26563 + e = copy_to_user(p, &rdu, sizeof(rdu));
26564 + if (unlikely(e)) {
26569 + case AUFS_CTL_RDU_INO:
26570 + err = au_rdu_ino(file, &rdu);
26574 + /* err = -ENOTTY; */
26583 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26584 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26585 +++ linux/fs/aufs/rwsem.h 2017-03-02 14:24:13.866922487 +0100
26588 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26590 + * This program, aufs is free software; you can redistribute it and/or modify
26591 + * it under the terms of the GNU General Public License as published by
26592 + * the Free Software Foundation; either version 2 of the License, or
26593 + * (at your option) any later version.
26595 + * This program is distributed in the hope that it will be useful,
26596 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26597 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26598 + * GNU General Public License for more details.
26600 + * You should have received a copy of the GNU General Public License
26601 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26605 + * simple read-write semaphore wrappers
26608 +#ifndef __AUFS_RWSEM_H__
26609 +#define __AUFS_RWSEM_H__
26613 +#include "debug.h"
26616 + struct rw_semaphore rwsem;
26617 +#ifdef CONFIG_AUFS_DEBUG
26618 + /* just for debugging, not almighty counter */
26619 + atomic_t rcnt, wcnt;
26623 +#ifdef CONFIG_LOCKDEP
26624 +#define au_lockdep_set_name(rw) \
26625 + lockdep_set_class_and_name(&(rw)->rwsem, \
26626 + /*original key*/(rw)->rwsem.dep_map.key, \
26629 +#define au_lockdep_set_name(rw) do {} while (0)
26632 +#ifdef CONFIG_AUFS_DEBUG
26633 +#define AuDbgCntInit(rw) do { \
26634 + atomic_set(&(rw)->rcnt, 0); \
26635 + atomic_set(&(rw)->wcnt, 0); \
26636 + smp_mb(); /* atomic set */ \
26639 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26640 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26641 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26642 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26643 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26644 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26645 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26647 +#define AuDbgCnt(rw, cnt) 0
26648 +#define AuDbgCntInit(rw) do {} while (0)
26649 +#define AuDbgRcntInc(rw) do {} while (0)
26650 +#define AuDbgRcntDec(rw) do {} while (0)
26651 +#define AuDbgWcntInc(rw) do {} while (0)
26652 +#define AuDbgWcntDec(rw) do {} while (0)
26653 +#endif /* CONFIG_AUFS_DEBUG */
26655 +/* to debug easier, do not make them inlined functions */
26656 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26657 +/* rwsem_is_locked() is unusable */
26658 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26659 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26660 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26661 + && AuDbgCnt(rw, wcnt) <= 0)
26662 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26663 + || AuDbgCnt(rw, wcnt))
26665 +#define au_rw_init(rw) do { \
26666 + AuDbgCntInit(rw); \
26667 + init_rwsem(&(rw)->rwsem); \
26668 + au_lockdep_set_name(rw); \
26671 +#define au_rw_init_wlock(rw) do { \
26672 + au_rw_init(rw); \
26673 + down_write(&(rw)->rwsem); \
26674 + AuDbgWcntInc(rw); \
26677 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26678 + au_rw_init(rw); \
26679 + down_write_nested(&(rw)->rwsem, lsc); \
26680 + AuDbgWcntInc(rw); \
26683 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26685 + down_read(&rw->rwsem);
26686 + AuDbgRcntInc(rw);
26689 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26691 + down_read_nested(&rw->rwsem, lsc);
26692 + AuDbgRcntInc(rw);
26695 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26697 + AuRwMustReadLock(rw);
26698 + AuDbgRcntDec(rw);
26699 + up_read(&rw->rwsem);
26702 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26704 + AuRwMustWriteLock(rw);
26705 + AuDbgRcntInc(rw);
26706 + AuDbgWcntDec(rw);
26707 + downgrade_write(&rw->rwsem);
26710 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26712 + down_write(&rw->rwsem);
26713 + AuDbgWcntInc(rw);
26716 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26717 + unsigned int lsc)
26719 + down_write_nested(&rw->rwsem, lsc);
26720 + AuDbgWcntInc(rw);
26723 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26725 + AuRwMustWriteLock(rw);
26726 + AuDbgWcntDec(rw);
26727 + up_write(&rw->rwsem);
26730 +/* why is not _nested version defined */
26731 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26735 + ret = down_read_trylock(&rw->rwsem);
26737 + AuDbgRcntInc(rw);
26741 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26745 + ret = down_write_trylock(&rw->rwsem);
26747 + AuDbgWcntInc(rw);
26751 +#undef AuDbgCntDec
26752 +#undef AuDbgRcntInc
26753 +#undef AuDbgRcntDec
26754 +#undef AuDbgWcntDec
26756 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26757 +static inline void prefix##_read_lock(param) \
26758 +{ au_rw_read_lock(rwsem); } \
26759 +static inline void prefix##_write_lock(param) \
26760 +{ au_rw_write_lock(rwsem); } \
26761 +static inline int prefix##_read_trylock(param) \
26762 +{ return au_rw_read_trylock(rwsem); } \
26763 +static inline int prefix##_write_trylock(param) \
26764 +{ return au_rw_write_trylock(rwsem); }
26765 +/* why is not _nested version defined */
26766 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26767 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26768 +static inline void prefix##_write_trylock_nestd(param, lsc)
26769 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26771 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26772 +static inline void prefix##_read_unlock(param) \
26773 +{ au_rw_read_unlock(rwsem); } \
26774 +static inline void prefix##_write_unlock(param) \
26775 +{ au_rw_write_unlock(rwsem); } \
26776 +static inline void prefix##_downgrade_lock(param) \
26777 +{ au_rw_dgrade_lock(rwsem); }
26779 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26780 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26781 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26783 +#endif /* __KERNEL__ */
26784 +#endif /* __AUFS_RWSEM_H__ */
26785 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26786 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26787 +++ linux/fs/aufs/sbinfo.c 2017-03-02 14:24:13.866922487 +0100
26790 + * Copyright (C) 2005-2017 Junjiro R. Okajima
26792 + * This program, aufs is free software; you can redistribute it and/or modify
26793 + * it under the terms of the GNU General Public License as published by
26794 + * the Free Software Foundation; either version 2 of the License, or
26795 + * (at your option) any later version.
26797 + * This program is distributed in the hope that it will be useful,
26798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26800 + * GNU General Public License for more details.
26802 + * You should have received a copy of the GNU General Public License
26803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26807 + * superblock private data
26813 + * they are necessary regardless sysfs is disabled.
26815 +void au_si_free(struct kobject *kobj)
26818 + struct au_sbinfo *sbinfo;
26819 + char *locked __maybe_unused; /* debug only */
26821 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26822 + for (i = 0; i < AuPlink_NHASH; i++)
26823 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26824 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26826 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26827 + percpu_counter_destroy(&sbinfo->si_ninodes);
26828 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26829 + percpu_counter_destroy(&sbinfo->si_nfiles);
26831 + au_rw_write_lock(&sbinfo->si_rwsem);
26832 + au_br_free(sbinfo);
26833 + au_rw_write_unlock(&sbinfo->si_rwsem);
26835 + au_delayed_kfree(sbinfo->si_branch);
26836 + mutex_destroy(&sbinfo->si_xib_mtx);
26837 + AuRwDestroy(&sbinfo->si_rwsem);
26839 + au_delayed_kfree(sbinfo);
26842 +int au_si_alloc(struct super_block *sb)
26845 + struct au_sbinfo *sbinfo;
26848 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26849 + if (unlikely(!sbinfo))
26852 + /* will be reallocated separately */
26853 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26854 + if (unlikely(!sbinfo->si_branch))
26857 + err = sysaufs_si_init(sbinfo);
26858 + if (unlikely(err))
26861 + au_nwt_init(&sbinfo->si_nowait);
26862 + au_rw_init_wlock(&sbinfo->si_rwsem);
26864 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26865 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26867 + sbinfo->si_bbot = -1;
26868 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26870 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26871 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26872 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26873 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26875 + au_fhsm_init(sbinfo);
26877 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26879 + sbinfo->si_xino_jiffy = jiffies;
26880 + sbinfo->si_xino_expire
26881 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26882 + mutex_init(&sbinfo->si_xib_mtx);
26883 + sbinfo->si_xino_brid = -1;
26884 + /* leave si_xib_last_pindex and si_xib_next_bit */
26886 + au_sphl_init(&sbinfo->si_aopen);
26888 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26889 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26890 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26891 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26893 + for (i = 0; i < AuPlink_NHASH; i++)
26894 + au_sphl_init(sbinfo->si_plink + i);
26895 + init_waitqueue_head(&sbinfo->si_plink_wq);
26896 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26898 + au_sphl_init(&sbinfo->si_files);
26900 + /* with getattr by default */
26901 + sbinfo->si_iop_array = aufs_iop;
26903 + /* leave other members for sysaufs and si_mnt. */
26904 + sbinfo->si_sb = sb;
26905 + sb->s_fs_info = sbinfo;
26907 + return 0; /* success */
26910 + au_delayed_kfree(sbinfo->si_branch);
26912 + au_delayed_kfree(sbinfo);
26917 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
26920 + struct au_branch **brp;
26922 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26925 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26926 + if (unlikely(!sz))
26927 + sz = sizeof(*brp);
26928 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
26931 + sbinfo->si_branch = brp;
26938 +/* ---------------------------------------------------------------------- */
26940 +unsigned int au_sigen_inc(struct super_block *sb)
26942 + unsigned int gen;
26943 + struct inode *inode;
26945 + SiMustWriteLock(sb);
26947 + gen = ++au_sbi(sb)->si_generation;
26948 + au_update_digen(sb->s_root);
26949 + inode = d_inode(sb->s_root);
26950 + au_update_iigen(inode, /*half*/0);
26951 + inode->i_version++;
26955 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26957 + aufs_bindex_t br_id;
26959 + struct au_sbinfo *sbinfo;
26961 + SiMustWriteLock(sb);
26963 + sbinfo = au_sbi(sb);
26964 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26965 + br_id = ++sbinfo->si_last_br_id;
26966 + AuDebugOn(br_id < 0);
26967 + if (br_id && au_br_index(sb, br_id) < 0)
26974 +/* ---------------------------------------------------------------------- */
26976 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26977 +int si_read_lock(struct super_block *sb, int flags)
26982 + if (au_ftest_lock(flags, FLUSH))
26983 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26985 + si_noflush_read_lock(sb);
26986 + err = au_plink_maint(sb, flags);
26987 + if (unlikely(err))
26988 + si_read_unlock(sb);
26993 +int si_write_lock(struct super_block *sb, int flags)
26997 + if (au_ftest_lock(flags, FLUSH))
26998 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27000 + si_noflush_write_lock(sb);
27001 + err = au_plink_maint(sb, flags);
27002 + if (unlikely(err))
27003 + si_write_unlock(sb);
27008 +/* dentry and super_block lock. call at entry point */
27009 +int aufs_read_lock(struct dentry *dentry, int flags)
27012 + struct super_block *sb;
27014 + sb = dentry->d_sb;
27015 + err = si_read_lock(sb, flags);
27016 + if (unlikely(err))
27019 + if (au_ftest_lock(flags, DW))
27020 + di_write_lock_child(dentry);
27022 + di_read_lock_child(dentry, flags);
27024 + if (au_ftest_lock(flags, GEN)) {
27025 + err = au_digen_test(dentry, au_sigen(sb));
27026 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
27027 + AuDebugOn(!err && au_dbrange_test(dentry));
27029 + err = au_dbrange_test(dentry);
27030 + if (unlikely(err))
27031 + aufs_read_unlock(dentry, flags);
27038 +void aufs_read_unlock(struct dentry *dentry, int flags)
27040 + if (au_ftest_lock(flags, DW))
27041 + di_write_unlock(dentry);
27043 + di_read_unlock(dentry, flags);
27044 + si_read_unlock(dentry->d_sb);
27047 +void aufs_write_lock(struct dentry *dentry)
27049 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
27050 + di_write_lock_child(dentry);
27053 +void aufs_write_unlock(struct dentry *dentry)
27055 + di_write_unlock(dentry);
27056 + si_write_unlock(dentry->d_sb);
27059 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
27062 + unsigned int sigen;
27063 + struct super_block *sb;
27066 + err = si_read_lock(sb, flags);
27067 + if (unlikely(err))
27070 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
27072 + if (au_ftest_lock(flags, GEN)) {
27073 + sigen = au_sigen(sb);
27074 + err = au_digen_test(d1, sigen);
27075 + AuDebugOn(!err && au_dbrange_test(d1));
27077 + err = au_digen_test(d2, sigen);
27078 + AuDebugOn(!err && au_dbrange_test(d2));
27080 + if (unlikely(err))
27081 + aufs_read_and_write_unlock2(d1, d2);
27088 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
27090 + di_write_unlock2(d1, d2);
27091 + si_read_unlock(d1->d_sb);
27093 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27094 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27095 +++ linux/fs/aufs/spl.h 2017-03-02 14:24:13.866922487 +0100
27098 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27100 + * This program, aufs is free software; you can redistribute it and/or modify
27101 + * it under the terms of the GNU General Public License as published by
27102 + * the Free Software Foundation; either version 2 of the License, or
27103 + * (at your option) any later version.
27105 + * This program is distributed in the hope that it will be useful,
27106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27108 + * GNU General Public License for more details.
27110 + * You should have received a copy of the GNU General Public License
27111 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27115 + * simple list protected by a spinlock
27118 +#ifndef __AUFS_SPL_H__
27119 +#define __AUFS_SPL_H__
27124 +struct au_splhead {
27126 + struct list_head head;
27129 +static inline void au_spl_init(struct au_splhead *spl)
27131 + spin_lock_init(&spl->spin);
27132 + INIT_LIST_HEAD(&spl->head);
27135 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27137 + spin_lock(&spl->spin);
27138 + list_add(list, &spl->head);
27139 + spin_unlock(&spl->spin);
27142 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27144 + spin_lock(&spl->spin);
27146 + spin_unlock(&spl->spin);
27149 +static inline void au_spl_del_rcu(struct list_head *list,
27150 + struct au_splhead *spl)
27152 + spin_lock(&spl->spin);
27153 + list_del_rcu(list);
27154 + spin_unlock(&spl->spin);
27158 +/* ---------------------------------------------------------------------- */
27160 +struct au_sphlhead {
27162 + struct hlist_head head;
27165 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27167 + spin_lock_init(&sphl->spin);
27168 + INIT_HLIST_HEAD(&sphl->head);
27171 +static inline void au_sphl_add(struct hlist_node *hlist,
27172 + struct au_sphlhead *sphl)
27174 + spin_lock(&sphl->spin);
27175 + hlist_add_head(hlist, &sphl->head);
27176 + spin_unlock(&sphl->spin);
27179 +static inline void au_sphl_del(struct hlist_node *hlist,
27180 + struct au_sphlhead *sphl)
27182 + spin_lock(&sphl->spin);
27183 + hlist_del(hlist);
27184 + spin_unlock(&sphl->spin);
27187 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27188 + struct au_sphlhead *sphl)
27190 + spin_lock(&sphl->spin);
27191 + hlist_del_rcu(hlist);
27192 + spin_unlock(&sphl->spin);
27195 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27197 + unsigned long cnt;
27198 + struct hlist_node *pos;
27201 + spin_lock(&sphl->spin);
27202 + hlist_for_each(pos, &sphl->head)
27204 + spin_unlock(&sphl->spin);
27208 +#endif /* __KERNEL__ */
27209 +#endif /* __AUFS_SPL_H__ */
27210 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27211 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27212 +++ linux/fs/aufs/super.c 2017-03-02 14:24:13.866922487 +0100
27215 + * Copyright (C) 2005-2017 Junjiro R. Okajima
27217 + * This program, aufs is free software; you can redistribute it and/or modify
27218 + * it under the terms of the GNU General Public License as published by
27219 + * the Free Software Foundation; either version 2 of the License, or
27220 + * (at your option) any later version.
27222 + * This program is distributed in the hope that it will be useful,
27223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27225 + * GNU General Public License for more details.
27227 + * You should have received a copy of the GNU General Public License
27228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27232 + * mount and super_block operations
27235 +#include <linux/mm.h>
27236 +#include <linux/seq_file.h>
27237 +#include <linux/statfs.h>
27238 +#include <linux/vmalloc.h>
27242 + * super_operations
27244 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27246 + struct au_icntnr *c;
27248 + c = au_cache_alloc_icntnr();
27250 + au_icntnr_init(c);
27251 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27252 + c->iinfo.ii_hinode = NULL;
27253 + return &c->vfs_inode;
27258 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27260 + struct inode *inode = container_of(head, struct inode, i_rcu);
27262 + au_cache_dfree_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27265 +static void aufs_destroy_inode(struct inode *inode)
27267 + if (!au_is_bad_inode(inode))
27268 + au_iinfo_fin(inode);
27269 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27272 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27274 + struct inode *inode;
27277 + inode = iget_locked(sb, ino);
27278 + if (unlikely(!inode)) {
27279 + inode = ERR_PTR(-ENOMEM);
27282 + if (!(inode->i_state & I_NEW))
27285 + err = au_xigen_new(inode);
27287 + err = au_iinfo_init(inode);
27289 + inode->i_version++;
27291 + iget_failed(inode);
27292 + inode = ERR_PTR(err);
27296 + /* never return NULL */
27297 + AuDebugOn(!inode);
27298 + AuTraceErrPtr(inode);
27302 +/* lock free root dinfo */
27303 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27306 + aufs_bindex_t bindex, bbot;
27307 + struct path path;
27308 + struct au_hdentry *hdp;
27309 + struct au_branch *br;
27310 + au_br_perm_str_t perm;
27313 + bbot = au_sbbot(sb);
27315 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27316 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27317 + br = au_sbr(sb, bindex);
27318 + path.mnt = au_br_mnt(br);
27319 + path.dentry = hdp->hd_dentry;
27320 + err = au_seq_path(seq, &path);
27322 + au_optstr_br_perm(&perm, br->br_perm);
27323 + seq_printf(seq, "=%s", perm.a);
27324 + if (bindex != bbot)
27325 + seq_putc(seq, ':');
27328 + if (unlikely(err || seq_has_overflowed(seq)))
27334 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
27335 + const char *append)
27340 + while (*pat != ':')
27343 + strcpy(p, append);
27344 + AuDebugOn(strlen(fmt) >= len);
27347 +static void au_show_wbr_create(struct seq_file *m, int v,
27348 + struct au_sbinfo *sbinfo)
27352 + struct au_wbr_mfs *mfs;
27354 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27356 + seq_puts(m, ",create=");
27357 + pat = au_optstr_wbr_create(v);
27358 + mfs = &sbinfo->si_wbr_mfs;
27360 + case AuWbrCreate_TDP:
27361 + case AuWbrCreate_RR:
27362 + case AuWbrCreate_MFS:
27363 + case AuWbrCreate_PMFS:
27364 + seq_puts(m, pat);
27366 + case AuWbrCreate_MFSRR:
27367 + case AuWbrCreate_TDMFS:
27368 + case AuWbrCreate_PMFSRR:
27369 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
27370 + seq_printf(m, fmt, mfs->mfsrr_watermark);
27372 + case AuWbrCreate_MFSV:
27373 + case AuWbrCreate_PMFSV:
27374 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
27375 + seq_printf(m, fmt,
27376 + jiffies_to_msecs(mfs->mfs_expire)
27379 + case AuWbrCreate_MFSRRV:
27380 + case AuWbrCreate_TDMFSV:
27381 + case AuWbrCreate_PMFSRRV:
27382 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
27383 + seq_printf(m, fmt, mfs->mfsrr_watermark,
27384 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
27391 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27393 +#ifdef CONFIG_SYSFS
27397 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27398 + aufs_bindex_t bindex, brid;
27399 + struct qstr *name;
27401 + struct dentry *d, *h_root;
27403 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27406 + f = au_sbi(sb)->si_xib;
27410 + /* stop printing the default xino path on the first writable branch */
27412 + brid = au_xino_brid(sb);
27414 + bindex = au_br_index(sb, brid);
27415 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27417 + d = f->f_path.dentry;
27418 + name = &d->d_name;
27419 + /* safe ->d_parent because the file is unlinked */
27420 + if (d->d_parent == h_root
27421 + && name->len == len
27422 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27425 + seq_puts(seq, ",xino=");
27426 + err = au_xino_path(seq, f);
27433 +/* seq_file will re-call me in case of too long string */
27434 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27437 + unsigned int mnt_flags, v;
27438 + struct super_block *sb;
27439 + struct au_sbinfo *sbinfo;
27441 +#define AuBool(name, str) do { \
27442 + v = au_opt_test(mnt_flags, name); \
27443 + if (v != au_opt_test(AuOpt_Def, name)) \
27444 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27447 +#define AuStr(name, str) do { \
27448 + v = mnt_flags & AuOptMask_##name; \
27449 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27450 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27453 +#define AuUInt(name, str, val) do { \
27454 + if (val != AUFS_##name##_DEF) \
27455 + seq_printf(m, "," #str "=%u", val); \
27458 + sb = dentry->d_sb;
27459 + if (sb->s_flags & MS_POSIXACL)
27460 + seq_puts(m, ",acl");
27462 + /* lock free root dinfo */
27463 + si_noflush_read_lock(sb);
27464 + sbinfo = au_sbi(sb);
27465 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27467 + mnt_flags = au_mntflags(sb);
27468 + if (au_opt_test(mnt_flags, XINO)) {
27469 + err = au_show_xino(m, sb);
27470 + if (unlikely(err))
27473 + seq_puts(m, ",noxino");
27475 + AuBool(TRUNC_XINO, trunc_xino);
27476 + AuStr(UDBA, udba);
27477 + AuBool(SHWH, shwh);
27478 + AuBool(PLINK, plink);
27479 + AuBool(DIO, dio);
27480 + AuBool(DIRPERM1, dirperm1);
27482 + v = sbinfo->si_wbr_create;
27483 + if (v != AuWbrCreate_Def)
27484 + au_show_wbr_create(m, v, sbinfo);
27486 + v = sbinfo->si_wbr_copyup;
27487 + if (v != AuWbrCopyup_Def)
27488 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27490 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27491 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27492 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27494 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27496 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27497 + AuUInt(RDCACHE, rdcache, v);
27499 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27500 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27502 + au_fhsm_show(m, sbinfo);
27504 + AuBool(SUM, sum);
27505 + /* AuBool(SUM_W, wsum); */
27506 + AuBool(WARN_PERM, warn_perm);
27507 + AuBool(VERBOSE, verbose);
27510 + /* be sure to print "br:" last */
27511 + if (!sysaufs_brs) {
27512 + seq_puts(m, ",br:");
27513 + au_show_brs(m, sb);
27515 + si_read_unlock(sb);
27523 +/* ---------------------------------------------------------------------- */
27525 +/* sum mode which returns the summation for statfs(2) */
27527 +static u64 au_add_till_max(u64 a, u64 b)
27535 + return ULLONG_MAX;
27538 +static u64 au_mul_till_max(u64 a, long mul)
27546 + return ULLONG_MAX;
27549 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27552 + long bsize, factor;
27553 + u64 blocks, bfree, bavail, files, ffree;
27554 + aufs_bindex_t bbot, bindex, i;
27555 + unsigned char shared;
27556 + struct path h_path;
27557 + struct super_block *h_sb;
27560 + bsize = LONG_MAX;
27566 + bbot = au_sbbot(sb);
27567 + for (bindex = 0; bindex <= bbot; bindex++) {
27568 + h_path.mnt = au_sbr_mnt(sb, bindex);
27569 + h_sb = h_path.mnt->mnt_sb;
27571 + for (i = 0; !shared && i < bindex; i++)
27572 + shared = (au_sbr_sb(sb, i) == h_sb);
27576 + /* sb->s_root for NFS is unreliable */
27577 + h_path.dentry = h_path.mnt->mnt_root;
27578 + err = vfs_statfs(&h_path, buf);
27579 + if (unlikely(err))
27582 + if (bsize > buf->f_bsize) {
27584 + * we will reduce bsize, so we have to expand blocks
27585 + * etc. to match them again
27587 + factor = (bsize / buf->f_bsize);
27588 + blocks = au_mul_till_max(blocks, factor);
27589 + bfree = au_mul_till_max(bfree, factor);
27590 + bavail = au_mul_till_max(bavail, factor);
27591 + bsize = buf->f_bsize;
27594 + factor = (buf->f_bsize / bsize);
27595 + blocks = au_add_till_max(blocks,
27596 + au_mul_till_max(buf->f_blocks, factor));
27597 + bfree = au_add_till_max(bfree,
27598 + au_mul_till_max(buf->f_bfree, factor));
27599 + bavail = au_add_till_max(bavail,
27600 + au_mul_till_max(buf->f_bavail, factor));
27601 + files = au_add_till_max(files, buf->f_files);
27602 + ffree = au_add_till_max(ffree, buf->f_ffree);
27605 + buf->f_bsize = bsize;
27606 + buf->f_blocks = blocks;
27607 + buf->f_bfree = bfree;
27608 + buf->f_bavail = bavail;
27609 + buf->f_files = files;
27610 + buf->f_ffree = ffree;
27611 + buf->f_frsize = 0;
27617 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27620 + struct path h_path;
27621 + struct super_block *sb;
27623 + /* lock free root dinfo */
27624 + sb = dentry->d_sb;
27625 + si_noflush_read_lock(sb);
27626 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27627 + /* sb->s_root for NFS is unreliable */
27628 + h_path.mnt = au_sbr_mnt(sb, 0);
27629 + h_path.dentry = h_path.mnt->mnt_root;
27630 + err = vfs_statfs(&h_path, buf);
27632 + err = au_statfs_sum(sb, buf);
27633 + si_read_unlock(sb);
27636 + buf->f_type = AUFS_SUPER_MAGIC;
27637 + buf->f_namelen = AUFS_MAX_NAMELEN;
27638 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27640 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27645 +/* ---------------------------------------------------------------------- */
27647 +static int aufs_sync_fs(struct super_block *sb, int wait)
27650 + aufs_bindex_t bbot, bindex;
27651 + struct au_branch *br;
27652 + struct super_block *h_sb;
27655 + si_noflush_read_lock(sb);
27656 + bbot = au_sbbot(sb);
27657 + for (bindex = 0; bindex <= bbot; bindex++) {
27658 + br = au_sbr(sb, bindex);
27659 + if (!au_br_writable(br->br_perm))
27662 + h_sb = au_sbr_sb(sb, bindex);
27663 + e = vfsub_sync_filesystem(h_sb, wait);
27664 + if (unlikely(e && !err))
27666 + /* go on even if an error happens */
27668 + si_read_unlock(sb);
27673 +/* ---------------------------------------------------------------------- */
27675 +/* final actions when unmounting a file system */
27676 +static void aufs_put_super(struct super_block *sb)
27678 + struct au_sbinfo *sbinfo;
27680 + sbinfo = au_sbi(sb);
27684 + dbgaufs_si_fin(sbinfo);
27685 + kobject_put(&sbinfo->si_kobj);
27688 +/* ---------------------------------------------------------------------- */
27690 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27691 + struct super_block *sb, void *arg)
27694 + unsigned long long n, sz;
27701 + if (*hint > ULLONG_MAX / sizeof(array)) {
27702 + array = ERR_PTR(-EMFILE);
27703 + pr_err("hint %llu\n", *hint);
27707 + sz = sizeof(array) * *hint;
27708 + array = kzalloc(sz, GFP_NOFS);
27709 + if (unlikely(!array))
27710 + array = vzalloc(sz);
27711 + if (unlikely(!array)) {
27712 + array = ERR_PTR(-ENOMEM);
27716 + n = cb(sb, array, *hint, arg);
27717 + AuDebugOn(n > *hint);
27724 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27725 + unsigned long long max __maybe_unused,
27728 + unsigned long long n;
27729 + struct inode **p, *inode;
27730 + struct list_head *head;
27735 + spin_lock(&sb->s_inode_list_lock);
27736 + list_for_each_entry(inode, head, i_sb_list) {
27737 + if (!au_is_bad_inode(inode)
27738 + && au_ii(inode)->ii_btop >= 0) {
27739 + spin_lock(&inode->i_lock);
27740 + if (atomic_read(&inode->i_count)) {
27744 + AuDebugOn(n > max);
27746 + spin_unlock(&inode->i_lock);
27749 + spin_unlock(&sb->s_inode_list_lock);
27754 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27756 + *max = au_ninodes(sb);
27757 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27760 +void au_iarray_free(struct inode **a, unsigned long long max)
27762 + unsigned long long ull;
27764 + for (ull = 0; ull < max; ull++)
27769 +/* ---------------------------------------------------------------------- */
27772 + * refresh dentry and inode at remount time.
27774 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27775 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27776 + struct dentry *parent)
27780 + di_write_lock_child(dentry);
27781 + di_read_lock_parent(parent, AuLock_IR);
27782 + err = au_refresh_dentry(dentry, parent);
27783 + if (!err && dir_flags)
27784 + au_hn_reset(d_inode(dentry), dir_flags);
27785 + di_read_unlock(parent, AuLock_IR);
27786 + di_write_unlock(dentry);
27791 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27792 + struct au_sbinfo *sbinfo,
27793 + const unsigned int dir_flags, unsigned int do_idop)
27796 + struct dentry *parent;
27799 + parent = dget_parent(dentry);
27800 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27801 + if (d_really_is_positive(dentry)) {
27802 + if (!d_is_dir(dentry))
27803 + err = au_do_refresh(dentry, /*dir_flags*/0,
27806 + err = au_do_refresh(dentry, dir_flags, parent);
27807 + if (unlikely(err))
27808 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27811 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27812 + AuDbgDentry(dentry);
27818 + au_refresh_dop(dentry, /*force_reval*/0);
27820 + au_refresh_dop(dentry, /*force_reval*/1);
27826 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27828 + int err, i, j, ndentry, e;
27829 + unsigned int sigen;
27830 + struct au_dcsub_pages dpages;
27831 + struct au_dpage *dpage;
27832 + struct dentry **dentries, *d;
27833 + struct au_sbinfo *sbinfo;
27834 + struct dentry *root = sb->s_root;
27835 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27838 + au_refresh_dop(root, /*force_reval*/0);
27840 + err = au_dpages_init(&dpages, GFP_NOFS);
27841 + if (unlikely(err))
27843 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27844 + if (unlikely(err))
27847 + sigen = au_sigen(sb);
27848 + sbinfo = au_sbi(sb);
27849 + for (i = 0; i < dpages.ndpage; i++) {
27850 + dpage = dpages.dpages + i;
27851 + dentries = dpage->dentries;
27852 + ndentry = dpage->ndentry;
27853 + for (j = 0; j < ndentry; j++) {
27855 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27857 + if (unlikely(e && !err))
27859 + /* go on even err */
27864 + au_dpages_free(&dpages);
27869 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27872 + unsigned int sigen;
27873 + unsigned long long max, ull;
27874 + struct inode *inode, **array;
27876 + array = au_iarray_alloc(sb, &max);
27877 + err = PTR_ERR(array);
27878 + if (IS_ERR(array))
27882 + sigen = au_sigen(sb);
27883 + for (ull = 0; ull < max; ull++) {
27884 + inode = array[ull];
27885 + if (unlikely(!inode))
27889 + ii_write_lock_child(inode);
27890 + if (au_iigen(inode, NULL) != sigen) {
27891 + e = au_refresh_hinode_self(inode);
27892 + if (unlikely(e)) {
27893 + au_refresh_iop(inode, /*force_getattr*/1);
27894 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27897 + /* go on even if err */
27900 + if (!e && do_idop)
27901 + au_refresh_iop(inode, /*force_getattr*/0);
27902 + ii_write_unlock(inode);
27905 + au_iarray_free(array, max);
27911 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27914 + unsigned int udba;
27915 + aufs_bindex_t bindex, bbot;
27916 + struct dentry *root;
27917 + struct inode *inode;
27918 + struct au_branch *br;
27919 + struct au_sbinfo *sbi;
27921 + au_sigen_inc(sb);
27922 + sbi = au_sbi(sb);
27923 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27925 + root = sb->s_root;
27926 + DiMustNoWaiters(root);
27927 + inode = d_inode(root);
27928 + IiMustNoWaiters(inode);
27930 + udba = au_opt_udba(sb);
27931 + bbot = au_sbbot(sb);
27932 + for (bindex = 0; bindex <= bbot; bindex++) {
27933 + br = au_sbr(sb, bindex);
27934 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27935 + if (unlikely(err))
27936 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27938 + /* go on even if err */
27940 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27943 + if (au_ftest_si(sbi, NO_DREVAL)) {
27944 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27945 + sb->s_d_op = &aufs_dop_noreval;
27946 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27947 + sbi->si_iop_array = aufs_iop_nogetattr;
27949 + AuDebugOn(sb->s_d_op == &aufs_dop);
27950 + sb->s_d_op = &aufs_dop;
27951 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27952 + sbi->si_iop_array = aufs_iop;
27954 + pr_info("reset to %pf and %pf\n",
27955 + sb->s_d_op, sbi->si_iop_array);
27958 + di_write_unlock(root);
27959 + err = au_refresh_d(sb, do_idop);
27960 + e = au_refresh_i(sb, do_idop);
27961 + if (unlikely(e && !err))
27963 + /* aufs_write_lock() calls ..._child() */
27964 + di_write_lock_child(root);
27966 + au_cpup_attr_all(inode, /*force*/1);
27968 + if (unlikely(err))
27969 + AuIOErr("refresh failed, ignored, %d\n", err);
27972 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27973 +static int cvt_err(int err)
27987 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27990 + unsigned int mntflags;
27991 + struct au_opts opts = {
27994 + struct dentry *root;
27995 + struct inode *inode;
27996 + struct au_sbinfo *sbinfo;
27999 + root = sb->s_root;
28000 + if (!data || !*data) {
28001 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28003 + di_write_lock_child(root);
28004 + err = au_opts_verify(sb, *flags, /*pending*/0);
28005 + aufs_write_unlock(root);
28011 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28012 + if (unlikely(!opts.opt))
28014 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28015 + opts.flags = AuOpts_REMOUNT;
28016 + opts.sb_flags = *flags;
28018 + /* parse it before aufs lock */
28019 + err = au_opts_parse(sb, data, &opts);
28020 + if (unlikely(err))
28023 + sbinfo = au_sbi(sb);
28024 + inode = d_inode(root);
28025 + inode_lock(inode);
28026 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28027 + if (unlikely(err))
28029 + di_write_lock_child(root);
28031 + /* au_opts_remount() may return an error */
28032 + err = au_opts_remount(sb, &opts);
28033 + au_opts_free(&opts);
28035 + if (au_ftest_opts(opts.flags, REFRESH))
28036 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
28038 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
28039 + mntflags = au_mntflags(sb);
28040 + do_dx = !!au_opt_test(mntflags, DIO);
28041 + au_dy_arefresh(do_dx);
28044 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
28045 + aufs_write_unlock(root);
28048 + inode_unlock(inode);
28050 + au_delayed_free_page((unsigned long)opts.opt);
28052 + err = cvt_err(err);
28057 +static const struct super_operations aufs_sop = {
28058 + .alloc_inode = aufs_alloc_inode,
28059 + .destroy_inode = aufs_destroy_inode,
28060 + /* always deleting, no clearing */
28061 + .drop_inode = generic_delete_inode,
28062 + .show_options = aufs_show_options,
28063 + .statfs = aufs_statfs,
28064 + .put_super = aufs_put_super,
28065 + .sync_fs = aufs_sync_fs,
28066 + .remount_fs = aufs_remount_fs
28069 +/* ---------------------------------------------------------------------- */
28071 +static int alloc_root(struct super_block *sb)
28074 + struct inode *inode;
28075 + struct dentry *root;
28078 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28079 + err = PTR_ERR(inode);
28080 + if (IS_ERR(inode))
28083 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28084 + inode->i_fop = &aufs_dir_fop;
28085 + inode->i_mode = S_IFDIR;
28086 + set_nlink(inode, 2);
28087 + unlock_new_inode(inode);
28089 + root = d_make_root(inode);
28090 + if (unlikely(!root))
28092 + err = PTR_ERR(root);
28093 + if (IS_ERR(root))
28096 + err = au_di_init(root);
28098 + sb->s_root = root;
28099 + return 0; /* success */
28107 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28108 + int silent __maybe_unused)
28111 + struct au_opts opts = {
28114 + struct au_sbinfo *sbinfo;
28115 + struct dentry *root;
28116 + struct inode *inode;
28117 + char *arg = raw_data;
28119 + if (unlikely(!arg || !*arg)) {
28121 + pr_err("no arg\n");
28126 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28127 + if (unlikely(!opts.opt))
28129 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28130 + opts.sb_flags = sb->s_flags;
28132 + err = au_si_alloc(sb);
28133 + if (unlikely(err))
28135 + sbinfo = au_sbi(sb);
28137 + /* all timestamps always follow the ones on the branch */
28138 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28139 + sb->s_op = &aufs_sop;
28140 + sb->s_d_op = &aufs_dop;
28141 + sb->s_magic = AUFS_SUPER_MAGIC;
28142 + sb->s_maxbytes = 0;
28143 + sb->s_stack_depth = 1;
28144 + au_export_init(sb);
28145 + au_xattr_init(sb);
28147 + err = alloc_root(sb);
28148 + if (unlikely(err)) {
28149 + si_write_unlock(sb);
28152 + root = sb->s_root;
28153 + inode = d_inode(root);
28156 + * actually we can parse options regardless aufs lock here.
28157 + * but at remount time, parsing must be done before aufs lock.
28158 + * so we follow the same rule.
28160 + ii_write_lock_parent(inode);
28161 + aufs_write_unlock(root);
28162 + err = au_opts_parse(sb, arg, &opts);
28163 + if (unlikely(err))
28166 + /* lock vfs_inode first, then aufs. */
28167 + inode_lock(inode);
28168 + aufs_write_lock(root);
28169 + err = au_opts_mount(sb, &opts);
28170 + au_opts_free(&opts);
28171 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28172 + sb->s_d_op = &aufs_dop_noreval;
28173 + pr_info("%pf\n", sb->s_d_op);
28174 + au_refresh_dop(root, /*force_reval*/0);
28175 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28176 + au_refresh_iop(inode, /*force_getattr*/0);
28178 + aufs_write_unlock(root);
28179 + inode_unlock(inode);
28181 + goto out_opts; /* success */
28185 + sb->s_root = NULL;
28187 + dbgaufs_si_fin(sbinfo);
28188 + kobject_put(&sbinfo->si_kobj);
28189 + sb->s_fs_info = NULL;
28191 + au_delayed_free_page((unsigned long)opts.opt);
28194 + err = cvt_err(err);
28199 +/* ---------------------------------------------------------------------- */
28201 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28202 + const char *dev_name __maybe_unused,
28205 + struct dentry *root;
28206 + struct super_block *sb;
28208 + /* all timestamps always follow the ones on the branch */
28209 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28210 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28211 + if (IS_ERR(root))
28215 + si_write_lock(sb, !AuLock_FLUSH);
28216 + sysaufs_brs_add(sb, 0);
28217 + si_write_unlock(sb);
28218 + au_sbilist_add(sb);
28224 +static void aufs_kill_sb(struct super_block *sb)
28226 + struct au_sbinfo *sbinfo;
28228 + sbinfo = au_sbi(sb);
28230 + au_sbilist_del(sb);
28231 + aufs_write_lock(sb->s_root);
28233 + if (sbinfo->si_wbr_create_ops->fin)
28234 + sbinfo->si_wbr_create_ops->fin(sb);
28235 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28236 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28237 + au_remount_refresh(sb, /*do_idop*/0);
28239 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28240 + au_plink_put(sb, /*verbose*/1);
28242 + sbinfo->si_sb = NULL;
28243 + aufs_write_unlock(sb->s_root);
28244 + au_nwt_flush(&sbinfo->si_nowait);
28246 + kill_anon_super(sb);
28249 +struct file_system_type aufs_fs_type = {
28250 + .name = AUFS_FSTYPE,
28251 + /* a race between rename and others */
28252 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28253 + .mount = aufs_mount,
28254 + .kill_sb = aufs_kill_sb,
28255 + /* no need to __module_get() and module_put(). */
28256 + .owner = THIS_MODULE,
28258 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28259 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28260 +++ linux/fs/aufs/super.h 2017-03-02 14:24:13.866922487 +0100
28263 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28265 + * This program, aufs is free software; you can redistribute it and/or modify
28266 + * it under the terms of the GNU General Public License as published by
28267 + * the Free Software Foundation; either version 2 of the License, or
28268 + * (at your option) any later version.
28270 + * This program is distributed in the hope that it will be useful,
28271 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28272 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28273 + * GNU General Public License for more details.
28275 + * You should have received a copy of the GNU General Public License
28276 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28280 + * super_block operations
28283 +#ifndef __AUFS_SUPER_H__
28284 +#define __AUFS_SUPER_H__
28288 +#include <linux/fs.h>
28289 +#include <linux/kobject.h>
28290 +#include "rwsem.h"
28294 +/* policies to select one among multiple writable branches */
28295 +struct au_wbr_copyup_operations {
28296 + int (*copyup)(struct dentry *dentry);
28299 +#define AuWbr_DIR 1 /* target is a dir */
28300 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28302 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28303 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28304 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28306 +struct au_wbr_create_operations {
28307 + int (*create)(struct dentry *dentry, unsigned int flags);
28308 + int (*init)(struct super_block *sb);
28309 + int (*fin)(struct super_block *sb);
28312 +struct au_wbr_mfs {
28313 + struct mutex mfs_lock; /* protect this structure */
28314 + unsigned long mfs_jiffy;
28315 + unsigned long mfs_expire;
28316 + aufs_bindex_t mfs_bindex;
28318 + unsigned long long mfsrr_bytes;
28319 + unsigned long long mfsrr_watermark;
28322 +#define AuPlink_NHASH 100
28323 +static inline int au_plink_hash(ino_t ino)
28325 + return ino % AuPlink_NHASH;
28328 +/* File-based Hierarchical Storage Management */
28330 +#ifdef CONFIG_AUFS_FHSM
28331 + /* allow only one process who can receive the notification */
28332 + spinlock_t fhsm_spin;
28334 + wait_queue_head_t fhsm_wqh;
28335 + atomic_t fhsm_readable;
28337 + /* these are protected by si_rwsem */
28338 + unsigned long fhsm_expire;
28339 + aufs_bindex_t fhsm_bottom;
28344 +struct au_sbinfo {
28345 + /* nowait tasks in the system-wide workqueue */
28346 + struct au_nowait_tasks si_nowait;
28349 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28350 + * rwsem for au_sbinfo is necessary.
28352 + struct au_rwsem si_rwsem;
28355 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28358 + struct percpu_counter si_ninodes, si_nfiles;
28360 + /* branch management */
28361 + unsigned int si_generation;
28363 + /* see AuSi_ flags */
28364 + unsigned char au_si_status;
28366 + aufs_bindex_t si_bbot;
28368 + /* dirty trick to keep br_id plus */
28369 + unsigned int si_last_br_id :
28370 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28371 + struct au_branch **si_branch;
28373 + /* policy to select a writable branch */
28374 + unsigned char si_wbr_copyup;
28375 + unsigned char si_wbr_create;
28376 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28377 + struct au_wbr_create_operations *si_wbr_create_ops;
28379 + /* round robin */
28380 + atomic_t si_wbr_rr_next;
28382 + /* most free space */
28383 + struct au_wbr_mfs si_wbr_mfs;
28385 + /* File-based Hierarchical Storage Management */
28386 + struct au_fhsm si_fhsm;
28388 + /* mount flags */
28389 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28390 + unsigned int si_mntflags;
28392 + /* external inode number (bitmap and translation table) */
28393 + vfs_readf_t si_xread;
28394 + vfs_writef_t si_xwrite;
28395 + struct file *si_xib;
28396 + struct mutex si_xib_mtx; /* protect xib members */
28397 + unsigned long *si_xib_buf;
28398 + unsigned long si_xib_last_pindex;
28399 + int si_xib_next_bit;
28400 + aufs_bindex_t si_xino_brid;
28401 + unsigned long si_xino_jiffy;
28402 + unsigned long si_xino_expire;
28403 + /* reserved for future use */
28404 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28406 +#ifdef CONFIG_AUFS_EXPORT
28407 + /* i_generation */
28408 + struct file *si_xigen;
28409 + atomic_t si_xigen_next;
28412 + /* dirty trick to suppoer atomic_open */
28413 + struct au_sphlhead si_aopen;
28415 + /* vdir parameters */
28416 + unsigned long si_rdcache; /* max cache time in jiffies */
28417 + unsigned int si_rdblk; /* deblk size */
28418 + unsigned int si_rdhash; /* hash size */
28421 + * If the number of whiteouts are larger than si_dirwh, leave all of
28422 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28423 + * future fsck.aufs or kernel thread will remove them later.
28424 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28426 + unsigned int si_dirwh;
28428 + /* pseudo_link list */
28429 + struct au_sphlhead si_plink[AuPlink_NHASH];
28430 + wait_queue_head_t si_plink_wq;
28431 + spinlock_t si_plink_maint_lock;
28432 + pid_t si_plink_maint_pid;
28435 + struct au_sphlhead si_files;
28437 + /* with/without getattr, brother of sb->s_d_op */
28438 + struct inode_operations *si_iop_array;
28441 + * sysfs and lifetime management.
28442 + * this is not a small structure and it may be a waste of memory in case
28443 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28444 + * but using sysfs is majority.
28446 + struct kobject si_kobj;
28447 +#ifdef CONFIG_DEBUG_FS
28448 + struct dentry *si_dbgaufs;
28449 + struct dentry *si_dbgaufs_plink;
28450 + struct dentry *si_dbgaufs_xib;
28451 +#ifdef CONFIG_AUFS_EXPORT
28452 + struct dentry *si_dbgaufs_xigen;
28456 +#ifdef CONFIG_AUFS_SBILIST
28457 + struct hlist_node si_list;
28460 + /* dirty, necessary for unmounting, sysfs and sysrq */
28461 + struct super_block *si_sb;
28464 +/* sbinfo status flags */
28466 + * set true when refresh_dirs() failed at remount time.
28467 + * then try refreshing dirs at access time again.
28468 + * if it is false, refreshing dirs at access time is unnecesary
28470 +#define AuSi_FAILED_REFRESH_DIR 1
28471 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28472 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28474 +#ifndef CONFIG_AUFS_FHSM
28476 +#define AuSi_FHSM 0
28479 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28480 + unsigned int flag)
28482 + AuRwMustAnyLock(&sbi->si_rwsem);
28483 + return sbi->au_si_status & flag;
28485 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28486 +#define au_fset_si(sbinfo, name) do { \
28487 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28488 + (sbinfo)->au_si_status |= AuSi_##name; \
28490 +#define au_fclr_si(sbinfo, name) do { \
28491 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28492 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28495 +/* ---------------------------------------------------------------------- */
28497 +/* policy to select one among writable branches */
28498 +#define AuWbrCopyup(sbinfo, ...) \
28499 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28500 +#define AuWbrCreate(sbinfo, ...) \
28501 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28503 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28504 +#define AuLock_DW 1 /* write-lock dentry */
28505 +#define AuLock_IR (1 << 1) /* read-lock inode */
28506 +#define AuLock_IW (1 << 2) /* write-lock inode */
28507 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28508 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28509 + /* except RENAME_EXCHANGE */
28510 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28511 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28512 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28513 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28514 +#define au_fset_lock(flags, name) \
28515 + do { (flags) |= AuLock_##name; } while (0)
28516 +#define au_fclr_lock(flags, name) \
28517 + do { (flags) &= ~AuLock_##name; } while (0)
28519 +/* ---------------------------------------------------------------------- */
28522 +extern struct file_system_type aufs_fs_type;
28523 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28524 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28525 + unsigned long long max, void *arg);
28526 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28527 + struct super_block *sb, void *arg);
28528 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28529 +void au_iarray_free(struct inode **a, unsigned long long max);
28532 +void au_si_free(struct kobject *kobj);
28533 +int au_si_alloc(struct super_block *sb);
28534 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28536 +unsigned int au_sigen_inc(struct super_block *sb);
28537 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28539 +int si_read_lock(struct super_block *sb, int flags);
28540 +int si_write_lock(struct super_block *sb, int flags);
28541 +int aufs_read_lock(struct dentry *dentry, int flags);
28542 +void aufs_read_unlock(struct dentry *dentry, int flags);
28543 +void aufs_write_lock(struct dentry *dentry);
28544 +void aufs_write_unlock(struct dentry *dentry);
28545 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28546 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28548 +/* wbr_policy.c */
28549 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28550 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28551 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28552 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28553 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28556 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28558 +#ifdef CONFIG_AUFS_FHSM
28561 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28565 + spin_lock(&fhsm->fhsm_spin);
28566 + pid = fhsm->fhsm_pid;
28567 + spin_unlock(&fhsm->fhsm_spin);
28572 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28573 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28574 +int au_fhsm_fd(struct super_block *sb, int oflags);
28575 +int au_fhsm_br_alloc(struct au_branch *br);
28576 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28577 +void au_fhsm_fin(struct super_block *sb);
28578 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28579 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28580 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28582 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28584 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28585 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28586 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28587 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28588 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28589 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28590 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28591 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28592 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28595 +/* ---------------------------------------------------------------------- */
28597 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28599 + return sb->s_fs_info;
28602 +/* ---------------------------------------------------------------------- */
28604 +#ifdef CONFIG_AUFS_EXPORT
28605 +int au_test_nfsd(void);
28606 +void au_export_init(struct super_block *sb);
28607 +void au_xigen_inc(struct inode *inode);
28608 +int au_xigen_new(struct inode *inode);
28609 +int au_xigen_set(struct super_block *sb, struct file *base);
28610 +void au_xigen_clr(struct super_block *sb);
28612 +static inline int au_busy_or_stale(void)
28614 + if (!au_test_nfsd())
28619 +AuStubInt0(au_test_nfsd, void)
28620 +AuStubVoid(au_export_init, struct super_block *sb)
28621 +AuStubVoid(au_xigen_inc, struct inode *inode)
28622 +AuStubInt0(au_xigen_new, struct inode *inode)
28623 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28624 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28625 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28626 +#endif /* CONFIG_AUFS_EXPORT */
28628 +/* ---------------------------------------------------------------------- */
28630 +#ifdef CONFIG_AUFS_SBILIST
28632 +extern struct au_sphlhead au_sbilist;
28634 +static inline void au_sbilist_init(void)
28636 + au_sphl_init(&au_sbilist);
28639 +static inline void au_sbilist_add(struct super_block *sb)
28641 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28644 +static inline void au_sbilist_del(struct super_block *sb)
28646 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28649 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28650 +static inline void au_sbilist_lock(void)
28652 + spin_lock(&au_sbilist.spin);
28655 +static inline void au_sbilist_unlock(void)
28657 + spin_unlock(&au_sbilist.spin);
28659 +#define AuGFP_SBILIST GFP_ATOMIC
28661 +AuStubVoid(au_sbilist_lock, void)
28662 +AuStubVoid(au_sbilist_unlock, void)
28663 +#define AuGFP_SBILIST GFP_NOFS
28664 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28666 +AuStubVoid(au_sbilist_init, void)
28667 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28668 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28669 +AuStubVoid(au_sbilist_lock, void)
28670 +AuStubVoid(au_sbilist_unlock, void)
28671 +#define AuGFP_SBILIST GFP_NOFS
28674 +/* ---------------------------------------------------------------------- */
28676 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28679 + * This function is a dynamic '__init' function actually,
28680 + * so the tiny check for si_rwsem is unnecessary.
28682 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28683 +#ifdef CONFIG_DEBUG_FS
28684 + sbinfo->si_dbgaufs = NULL;
28685 + sbinfo->si_dbgaufs_plink = NULL;
28686 + sbinfo->si_dbgaufs_xib = NULL;
28687 +#ifdef CONFIG_AUFS_EXPORT
28688 + sbinfo->si_dbgaufs_xigen = NULL;
28693 +/* ---------------------------------------------------------------------- */
28695 +/* current->atomic_flags */
28696 +/* this value should never corrupt the ones defined in linux/sched.h */
28697 +#define PFA_AUFS 7
28699 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
28700 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
28701 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
28703 +static inline int si_pid_test(struct super_block *sb)
28705 + return !!task_test_aufs(current);
28708 +static inline void si_pid_clr(struct super_block *sb)
28710 + AuDebugOn(!task_test_aufs(current));
28711 + task_clear_aufs(current);
28714 +static inline void si_pid_set(struct super_block *sb)
28716 + AuDebugOn(task_test_aufs(current));
28717 + task_set_aufs(current);
28720 +/* ---------------------------------------------------------------------- */
28722 +/* lock superblock. mainly for entry point functions */
28724 + * __si_read_lock, __si_write_lock,
28725 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28727 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28729 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28730 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28731 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28733 +static inline void si_noflush_read_lock(struct super_block *sb)
28735 + __si_read_lock(sb);
28739 +static inline int si_noflush_read_trylock(struct super_block *sb)
28743 + locked = __si_read_trylock(sb);
28749 +static inline void si_noflush_write_lock(struct super_block *sb)
28751 + __si_write_lock(sb);
28755 +static inline int si_noflush_write_trylock(struct super_block *sb)
28759 + locked = __si_write_trylock(sb);
28765 +#if 0 /* reserved */
28766 +static inline int si_read_trylock(struct super_block *sb, int flags)
28768 + if (au_ftest_lock(flags, FLUSH))
28769 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28770 + return si_noflush_read_trylock(sb);
28774 +static inline void si_read_unlock(struct super_block *sb)
28777 + __si_read_unlock(sb);
28780 +#if 0 /* reserved */
28781 +static inline int si_write_trylock(struct super_block *sb, int flags)
28783 + if (au_ftest_lock(flags, FLUSH))
28784 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28785 + return si_noflush_write_trylock(sb);
28789 +static inline void si_write_unlock(struct super_block *sb)
28792 + __si_write_unlock(sb);
28795 +#if 0 /* reserved */
28796 +static inline void si_downgrade_lock(struct super_block *sb)
28798 + __si_downgrade_lock(sb);
28802 +/* ---------------------------------------------------------------------- */
28804 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28806 + SiMustAnyLock(sb);
28807 + return au_sbi(sb)->si_bbot;
28810 +static inline unsigned int au_mntflags(struct super_block *sb)
28812 + SiMustAnyLock(sb);
28813 + return au_sbi(sb)->si_mntflags;
28816 +static inline unsigned int au_sigen(struct super_block *sb)
28818 + SiMustAnyLock(sb);
28819 + return au_sbi(sb)->si_generation;
28822 +static inline unsigned long long au_ninodes(struct super_block *sb)
28824 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28830 +static inline void au_ninodes_inc(struct super_block *sb)
28832 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28835 +static inline void au_ninodes_dec(struct super_block *sb)
28837 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28840 +static inline unsigned long long au_nfiles(struct super_block *sb)
28842 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28848 +static inline void au_nfiles_inc(struct super_block *sb)
28850 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28853 +static inline void au_nfiles_dec(struct super_block *sb)
28855 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28858 +static inline struct au_branch *au_sbr(struct super_block *sb,
28859 + aufs_bindex_t bindex)
28861 + SiMustAnyLock(sb);
28862 + return au_sbi(sb)->si_branch[0 + bindex];
28865 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28867 + SiMustWriteLock(sb);
28868 + au_sbi(sb)->si_xino_brid = brid;
28871 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28873 + SiMustAnyLock(sb);
28874 + return au_sbi(sb)->si_xino_brid;
28877 +#endif /* __KERNEL__ */
28878 +#endif /* __AUFS_SUPER_H__ */
28879 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28880 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28881 +++ linux/fs/aufs/sysaufs.c 2017-03-02 14:24:13.866922487 +0100
28884 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28886 + * This program, aufs is free software; you can redistribute it and/or modify
28887 + * it under the terms of the GNU General Public License as published by
28888 + * the Free Software Foundation; either version 2 of the License, or
28889 + * (at your option) any later version.
28891 + * This program is distributed in the hope that it will be useful,
28892 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28893 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28894 + * GNU General Public License for more details.
28896 + * You should have received a copy of the GNU General Public License
28897 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28901 + * sysfs interface and lifetime management
28902 + * they are necessary regardless sysfs is disabled.
28905 +#include <linux/random.h>
28908 +unsigned long sysaufs_si_mask;
28909 +struct kset *sysaufs_kset;
28911 +#define AuSiAttr(_name) { \
28912 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28913 + .show = sysaufs_si_##_name, \
28916 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28917 +struct attribute *sysaufs_si_attrs[] = {
28918 + &sysaufs_si_attr_xi_path.attr,
28922 +static const struct sysfs_ops au_sbi_ops = {
28923 + .show = sysaufs_si_show
28926 +static struct kobj_type au_sbi_ktype = {
28927 + .release = au_si_free,
28928 + .sysfs_ops = &au_sbi_ops,
28929 + .default_attrs = sysaufs_si_attrs
28932 +/* ---------------------------------------------------------------------- */
28934 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28938 + sbinfo->si_kobj.kset = sysaufs_kset;
28939 + /* cf. sysaufs_name() */
28940 + err = kobject_init_and_add
28941 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28942 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28944 + dbgaufs_si_null(sbinfo);
28946 + err = dbgaufs_si_init(sbinfo);
28947 + if (unlikely(err))
28948 + kobject_put(&sbinfo->si_kobj);
28953 +void sysaufs_fin(void)
28956 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28957 + kset_unregister(sysaufs_kset);
28960 +int __init sysaufs_init(void)
28965 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28966 + } while (!sysaufs_si_mask);
28969 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28970 + if (unlikely(!sysaufs_kset))
28972 + err = PTR_ERR(sysaufs_kset);
28973 + if (IS_ERR(sysaufs_kset))
28975 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28976 + if (unlikely(err)) {
28977 + kset_unregister(sysaufs_kset);
28981 + err = dbgaufs_init();
28982 + if (unlikely(err))
28987 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28988 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28989 +++ linux/fs/aufs/sysaufs.h 2017-03-02 14:24:13.866922487 +0100
28992 + * Copyright (C) 2005-2017 Junjiro R. Okajima
28994 + * This program, aufs is free software; you can redistribute it and/or modify
28995 + * it under the terms of the GNU General Public License as published by
28996 + * the Free Software Foundation; either version 2 of the License, or
28997 + * (at your option) any later version.
28999 + * This program is distributed in the hope that it will be useful,
29000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29002 + * GNU General Public License for more details.
29004 + * You should have received a copy of the GNU General Public License
29005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29009 + * sysfs interface and mount lifetime management
29012 +#ifndef __SYSAUFS_H__
29013 +#define __SYSAUFS_H__
29017 +#include <linux/sysfs.h>
29018 +#include "module.h"
29020 +struct super_block;
29023 +struct sysaufs_si_attr {
29024 + struct attribute attr;
29025 + int (*show)(struct seq_file *seq, struct super_block *sb);
29028 +/* ---------------------------------------------------------------------- */
29031 +extern unsigned long sysaufs_si_mask;
29032 +extern struct kset *sysaufs_kset;
29033 +extern struct attribute *sysaufs_si_attrs[];
29034 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
29035 +int __init sysaufs_init(void);
29036 +void sysaufs_fin(void);
29038 +/* ---------------------------------------------------------------------- */
29040 +/* some people doesn't like to show a pointer in kernel */
29041 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
29043 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
29046 +#define SysaufsSiNamePrefix "si_"
29047 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29048 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29050 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29051 + sysaufs_si_id(sbinfo));
29055 +#ifdef CONFIG_SYSFS
29057 +extern struct attribute_group *sysaufs_attr_group;
29059 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29060 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29062 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29063 +#ifdef CONFIG_COMPAT
29064 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29067 +void sysaufs_br_init(struct au_branch *br);
29068 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29069 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29071 +#define sysaufs_brs_init() do {} while (0)
29074 +#define sysaufs_attr_group NULL
29076 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29077 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29078 + struct attribute *attr, char *buf)
29079 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29080 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29081 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29083 +static inline void sysaufs_brs_init(void)
29088 +#endif /* CONFIG_SYSFS */
29090 +#endif /* __KERNEL__ */
29091 +#endif /* __SYSAUFS_H__ */
29092 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29093 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29094 +++ linux/fs/aufs/sysfs.c 2017-03-02 14:24:13.866922487 +0100
29097 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29099 + * This program, aufs is free software; you can redistribute it and/or modify
29100 + * it under the terms of the GNU General Public License as published by
29101 + * the Free Software Foundation; either version 2 of the License, or
29102 + * (at your option) any later version.
29104 + * This program is distributed in the hope that it will be useful,
29105 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29106 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29107 + * GNU General Public License for more details.
29109 + * You should have received a copy of the GNU General Public License
29110 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29114 + * sysfs interface
29117 +#include <linux/compat.h>
29118 +#include <linux/seq_file.h>
29121 +#ifdef CONFIG_AUFS_FS_MODULE
29122 +/* this entry violates the "one line per file" policy of sysfs */
29123 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29127 + static char *conf =
29128 +/* this file is generated at compiling */
29129 +#include "conf.str"
29132 + err = snprintf(buf, PAGE_SIZE, conf);
29133 + if (unlikely(err >= PAGE_SIZE))
29138 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29141 +static struct attribute *au_attr[] = {
29142 +#ifdef CONFIG_AUFS_FS_MODULE
29143 + &au_config_attr.attr,
29145 + NULL, /* need to NULL terminate the list of attributes */
29148 +static struct attribute_group sysaufs_attr_group_body = {
29152 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29154 +/* ---------------------------------------------------------------------- */
29156 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29160 + SiMustAnyLock(sb);
29163 + if (au_opt_test(au_mntflags(sb), XINO)) {
29164 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29165 + seq_putc(seq, '\n');
29171 + * the lifetime of branch is independent from the entry under sysfs.
29172 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29175 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29176 + aufs_bindex_t bindex, int idx)
29179 + struct path path;
29180 + struct dentry *root;
29181 + struct au_branch *br;
29182 + au_br_perm_str_t perm;
29184 + AuDbg("b%d\n", bindex);
29187 + root = sb->s_root;
29188 + di_read_lock_parent(root, !AuLock_IR);
29189 + br = au_sbr(sb, bindex);
29192 + case AuBrSysfs_BR:
29193 + path.mnt = au_br_mnt(br);
29194 + path.dentry = au_h_dptr(root, bindex);
29195 + err = au_seq_path(seq, &path);
29197 + au_optstr_br_perm(&perm, br->br_perm);
29198 + seq_printf(seq, "=%s\n", perm.a);
29201 + case AuBrSysfs_BRID:
29202 + seq_printf(seq, "%d\n", br->br_id);
29205 + di_read_unlock(root, !AuLock_IR);
29206 + if (unlikely(err || seq_has_overflowed(seq)))
29212 +/* ---------------------------------------------------------------------- */
29214 +static struct seq_file *au_seq(char *p, ssize_t len)
29216 + struct seq_file *seq;
29218 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29220 + /* mutex_init(&seq.lock); */
29223 + return seq; /* success */
29226 + seq = ERR_PTR(-ENOMEM);
29230 +#define SysaufsBr_PREFIX "br"
29231 +#define SysaufsBrid_PREFIX "brid"
29233 +/* todo: file size may exceed PAGE_SIZE */
29234 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29240 + aufs_bindex_t bbot;
29241 + struct au_sbinfo *sbinfo;
29242 + struct super_block *sb;
29243 + struct seq_file *seq;
29245 + struct attribute **cattr;
29247 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29248 + sb = sbinfo->si_sb;
29251 + * prevent a race condition between sysfs and aufs.
29252 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29253 + * prohibits maintaining the sysfs entries.
29254 + * hew we acquire read lock after sysfs_get_active_two().
29255 + * on the other hand, the remount process may maintain the sysfs/aufs
29256 + * entries after acquiring write lock.
29257 + * it can cause a deadlock.
29258 + * simply we gave up processing read here.
29261 + if (unlikely(!si_noflush_read_trylock(sb)))
29264 + seq = au_seq(buf, PAGE_SIZE);
29265 + err = PTR_ERR(seq);
29269 + name = (void *)attr->name;
29270 + cattr = sysaufs_si_attrs;
29272 + if (!strcmp(name, (*cattr)->name)) {
29273 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29280 + if (!strncmp(name, SysaufsBrid_PREFIX,
29281 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29282 + idx = AuBrSysfs_BRID;
29283 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29284 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29285 + sizeof(SysaufsBr_PREFIX) - 1)) {
29286 + idx = AuBrSysfs_BR;
29287 + name += sizeof(SysaufsBr_PREFIX) - 1;
29291 + err = kstrtol(name, 10, &l);
29293 + bbot = au_sbbot(sb);
29295 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29302 + err = seq->count;
29303 + /* sysfs limit */
29304 + if (unlikely(err == PAGE_SIZE))
29307 + au_delayed_kfree(seq);
29309 + si_read_unlock(sb);
29314 +/* ---------------------------------------------------------------------- */
29316 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29320 + aufs_bindex_t bindex, bbot;
29323 + struct seq_file *seq;
29324 + struct au_branch *br;
29326 + si_read_lock(sb, AuLock_FLUSH);
29327 + bbot = au_sbbot(sb);
29333 + buf = (void *)__get_free_page(GFP_NOFS);
29334 + if (unlikely(!buf))
29337 + seq = au_seq(buf, PAGE_SIZE);
29338 + err = PTR_ERR(seq);
29342 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29343 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29344 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29345 + if (unlikely(err))
29348 + br = au_sbr(sb, bindex);
29349 + brid = br->br_id;
29350 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29351 + err = __put_user(brid, &arg->id);
29352 + if (unlikely(err))
29355 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29356 + err = __put_user(br->br_perm, &arg->perm);
29357 + if (unlikely(err))
29360 + err = au_seq_path(seq, &br->br_path);
29361 + if (unlikely(err))
29363 + seq_putc(seq, '\0');
29364 + if (!seq_has_overflowed(seq)) {
29365 + err = copy_to_user(arg->path, seq->buf, seq->count);
29367 + if (unlikely(err))
29374 + if (unlikely(err))
29378 + au_delayed_kfree(seq);
29380 + au_delayed_free_page((unsigned long)buf);
29382 + si_read_unlock(sb);
29386 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29388 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29391 +#ifdef CONFIG_COMPAT
29392 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29394 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29398 +/* ---------------------------------------------------------------------- */
29400 +void sysaufs_br_init(struct au_branch *br)
29403 + struct au_brsysfs *br_sysfs;
29404 + struct attribute *attr;
29406 + br_sysfs = br->br_sysfs;
29407 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29408 + attr = &br_sysfs->attr;
29409 + sysfs_attr_init(attr);
29410 + attr->name = br_sysfs->name;
29411 + attr->mode = S_IRUGO;
29416 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29418 + struct au_branch *br;
29419 + struct kobject *kobj;
29420 + struct au_brsysfs *br_sysfs;
29422 + aufs_bindex_t bbot;
29424 + dbgaufs_brs_del(sb, bindex);
29426 + if (!sysaufs_brs)
29429 + kobj = &au_sbi(sb)->si_kobj;
29430 + bbot = au_sbbot(sb);
29431 + for (; bindex <= bbot; bindex++) {
29432 + br = au_sbr(sb, bindex);
29433 + br_sysfs = br->br_sysfs;
29434 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29435 + sysfs_remove_file(kobj, &br_sysfs->attr);
29441 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29444 + aufs_bindex_t bbot;
29445 + struct kobject *kobj;
29446 + struct au_branch *br;
29447 + struct au_brsysfs *br_sysfs;
29449 + dbgaufs_brs_add(sb, bindex);
29451 + if (!sysaufs_brs)
29454 + kobj = &au_sbi(sb)->si_kobj;
29455 + bbot = au_sbbot(sb);
29456 + for (; bindex <= bbot; bindex++) {
29457 + br = au_sbr(sb, bindex);
29458 + br_sysfs = br->br_sysfs;
29459 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29460 + SysaufsBr_PREFIX "%d", bindex);
29461 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29462 + SysaufsBrid_PREFIX "%d", bindex);
29463 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29464 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29465 + if (unlikely(err))
29466 + pr_warn("failed %s under sysfs(%d)\n",
29467 + br_sysfs->name, err);
29472 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29473 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29474 +++ linux/fs/aufs/sysrq.c 2017-03-02 14:24:13.866922487 +0100
29477 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29479 + * This program, aufs is free software; you can redistribute it and/or modify
29480 + * it under the terms of the GNU General Public License as published by
29481 + * the Free Software Foundation; either version 2 of the License, or
29482 + * (at your option) any later version.
29484 + * This program is distributed in the hope that it will be useful,
29485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29487 + * GNU General Public License for more details.
29489 + * You should have received a copy of the GNU General Public License
29490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29494 + * magic sysrq hanlder
29497 +/* #include <linux/sysrq.h> */
29498 +#include <linux/writeback.h>
29501 +/* ---------------------------------------------------------------------- */
29503 +static void sysrq_sb(struct super_block *sb)
29506 + struct au_sbinfo *sbinfo;
29507 + struct file *file;
29508 + struct au_sphlhead *files;
29509 + struct au_finfo *finfo;
29511 + plevel = au_plevel;
29512 + au_plevel = KERN_WARNING;
29514 + /* since we define pr_fmt, call printk directly */
29515 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29517 + sbinfo = au_sbi(sb);
29518 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29519 + pr("superblock\n");
29523 + pr("root dentry\n");
29524 + au_dpri_dentry(sb->s_root);
29525 + pr("root inode\n");
29526 + au_dpri_inode(d_inode(sb->s_root));
29531 + int err, i, j, ndentry;
29532 + struct au_dcsub_pages dpages;
29533 + struct au_dpage *dpage;
29535 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29536 + if (unlikely(err))
29538 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29540 + for (i = 0; i < dpages.ndpage; i++) {
29541 + dpage = dpages.dpages + i;
29542 + ndentry = dpage->ndentry;
29543 + for (j = 0; j < ndentry; j++)
29544 + au_dpri_dentry(dpage->dentries[j]);
29546 + au_dpages_free(&dpages);
29554 + pr("isolated inode\n");
29555 + spin_lock(&sb->s_inode_list_lock);
29556 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29557 + spin_lock(&i->i_lock);
29558 + if (1 || hlist_empty(&i->i_dentry))
29559 + au_dpri_inode(i);
29560 + spin_unlock(&i->i_lock);
29562 + spin_unlock(&sb->s_inode_list_lock);
29566 + files = &au_sbi(sb)->si_files;
29567 + spin_lock(&files->spin);
29568 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29571 + file = finfo->fi_file;
29572 + mode = file_inode(file)->i_mode;
29573 + if (!special_file(mode))
29574 + au_dpri_file(file);
29576 + spin_unlock(&files->spin);
29580 + au_plevel = plevel;
29583 +/* ---------------------------------------------------------------------- */
29585 +/* module parameter */
29586 +static char *aufs_sysrq_key = "a";
29587 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29588 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29590 +static void au_sysrq(int key __maybe_unused)
29592 + struct au_sbinfo *sbinfo;
29595 + au_sbilist_lock();
29596 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29597 + sysrq_sb(sbinfo->si_sb);
29598 + au_sbilist_unlock();
29602 +static struct sysrq_key_op au_sysrq_op = {
29603 + .handler = au_sysrq,
29604 + .help_msg = "Aufs",
29605 + .action_msg = "Aufs",
29606 + .enable_mask = SYSRQ_ENABLE_DUMP
29609 +/* ---------------------------------------------------------------------- */
29611 +int __init au_sysrq_init(void)
29617 + key = *aufs_sysrq_key;
29618 + if ('a' <= key && key <= 'z')
29619 + err = register_sysrq_key(key, &au_sysrq_op);
29620 + if (unlikely(err))
29621 + pr_err("err %d, sysrq=%c\n", err, key);
29625 +void au_sysrq_fin(void)
29629 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29630 + if (unlikely(err))
29631 + pr_err("err %d (ignored)\n", err);
29633 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29634 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29635 +++ linux/fs/aufs/vdir.c 2017-03-02 14:24:13.866922487 +0100
29638 + * Copyright (C) 2005-2017 Junjiro R. Okajima
29640 + * This program, aufs is free software; you can redistribute it and/or modify
29641 + * it under the terms of the GNU General Public License as published by
29642 + * the Free Software Foundation; either version 2 of the License, or
29643 + * (at your option) any later version.
29645 + * This program is distributed in the hope that it will be useful,
29646 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29647 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29648 + * GNU General Public License for more details.
29650 + * You should have received a copy of the GNU General Public License
29651 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29655 + * virtual or vertical directory
29660 +static unsigned int calc_size(int nlen)
29662 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29665 +static int set_deblk_end(union au_vdir_deblk_p *p,
29666 + union au_vdir_deblk_p *deblk_end)
29668 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29669 + p->de->de_str.len = 0;
29673 + return -1; /* error */
29676 +/* returns true or false */
29677 +static int is_deblk_end(union au_vdir_deblk_p *p,
29678 + union au_vdir_deblk_p *deblk_end)
29680 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29681 + return !p->de->de_str.len;
29685 +static unsigned char *last_deblk(struct au_vdir *vdir)
29687 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29690 +/* ---------------------------------------------------------------------- */
29692 +/* estimate the appropriate size for name hash table */
29693 +unsigned int au_rdhash_est(loff_t sz)
29701 + if (sz < AUFS_RDHASH_DEF)
29702 + n = AUFS_RDHASH_DEF;
29703 + /* pr_info("n %u\n", n); */
29708 + * the allocated memory has to be freed by
29709 + * au_nhash_wh_free() or au_nhash_de_free().
29711 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29713 + struct hlist_head *head;
29717 + sz = sizeof(*nhash->nh_head) * num_hash;
29718 + head = kmalloc(sz, gfp);
29720 + nhash->nh_num = num_hash;
29721 + nhash->nh_head = head;
29722 + for (u = 0; u < num_hash; u++)
29723 + INIT_HLIST_HEAD(head++);
29724 + return 0; /* success */
29730 +static void nhash_count(struct hlist_head *head)
29734 + struct hlist_node *pos;
29737 + hlist_for_each(pos, head)
29739 + pr_info("%lu\n", n);
29743 +static void au_nhash_wh_do_free(struct hlist_head *head)
29745 + struct au_vdir_wh *pos;
29746 + struct hlist_node *node;
29748 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29749 + au_delayed_kfree(pos);
29752 +static void au_nhash_de_do_free(struct hlist_head *head)
29754 + struct au_vdir_dehstr *pos;
29755 + struct hlist_node *node;
29757 + hlist_for_each_entry_safe(pos, node, head, hash)
29758 + au_cache_dfree_vdir_dehstr(pos);
29761 +static void au_nhash_do_free(struct au_nhash *nhash,
29762 + void (*free)(struct hlist_head *head))
29765 + struct hlist_head *head;
29767 + n = nhash->nh_num;
29771 + head = nhash->nh_head;
29772 + while (n-- > 0) {
29773 + nhash_count(head);
29776 + au_delayed_kfree(nhash->nh_head);
29779 +void au_nhash_wh_free(struct au_nhash *whlist)
29781 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29784 +static void au_nhash_de_free(struct au_nhash *delist)
29786 + au_nhash_do_free(delist, au_nhash_de_do_free);
29789 +/* ---------------------------------------------------------------------- */
29791 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29795 + unsigned int u, n;
29796 + struct hlist_head *head;
29797 + struct au_vdir_wh *pos;
29800 + n = whlist->nh_num;
29801 + head = whlist->nh_head;
29802 + for (u = 0; u < n; u++, head++)
29803 + hlist_for_each_entry(pos, head, wh_hash)
29804 + if (pos->wh_bindex == btgt && ++num > limit)
29809 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29810 + unsigned char *name,
29811 + unsigned int len)
29814 + /* const unsigned int magic_bit = 12; */
29816 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29823 + /* v = hash_long(v, magic_bit); */
29824 + v %= nhash->nh_num;
29825 + return nhash->nh_head + v;
29828 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29831 + return str->len == nlen && !memcmp(str->name, name, nlen);
29834 +/* returns found or not */
29835 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29837 + struct hlist_head *head;
29838 + struct au_vdir_wh *pos;
29839 + struct au_vdir_destr *str;
29841 + head = au_name_hash(whlist, name, nlen);
29842 + hlist_for_each_entry(pos, head, wh_hash) {
29843 + str = &pos->wh_str;
29844 + AuDbg("%.*s\n", str->len, str->name);
29845 + if (au_nhash_test_name(str, name, nlen))
29851 +/* returns found(true) or not */
29852 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29854 + struct hlist_head *head;
29855 + struct au_vdir_dehstr *pos;
29856 + struct au_vdir_destr *str;
29858 + head = au_name_hash(delist, name, nlen);
29859 + hlist_for_each_entry(pos, head, hash) {
29861 + AuDbg("%.*s\n", str->len, str->name);
29862 + if (au_nhash_test_name(str, name, nlen))
29868 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29869 + unsigned char d_type)
29871 +#ifdef CONFIG_AUFS_SHWH
29872 + wh->wh_ino = ino;
29873 + wh->wh_type = d_type;
29877 +/* ---------------------------------------------------------------------- */
29879 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29880 + unsigned int d_type, aufs_bindex_t bindex,
29881 + unsigned char shwh)
29884 + struct au_vdir_destr *str;
29885 + struct au_vdir_wh *wh;
29887 + AuDbg("%.*s\n", nlen, name);
29888 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29891 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29892 + if (unlikely(!wh))
29896 + wh->wh_bindex = bindex;
29898 + au_shwh_init_wh(wh, ino, d_type);
29899 + str = &wh->wh_str;
29901 + memcpy(str->name, name, nlen);
29902 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29909 +static int append_deblk(struct au_vdir *vdir)
29912 + unsigned long ul;
29913 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29914 + union au_vdir_deblk_p p, deblk_end;
29915 + unsigned char **o;
29918 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29919 + GFP_NOFS, /*may_shrink*/0);
29920 + if (unlikely(!o))
29923 + vdir->vd_deblk = o;
29924 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29926 + ul = vdir->vd_nblk++;
29927 + vdir->vd_deblk[ul] = p.deblk;
29928 + vdir->vd_last.ul = ul;
29929 + vdir->vd_last.p.deblk = p.deblk;
29930 + deblk_end.deblk = p.deblk + deblk_sz;
29931 + err = set_deblk_end(&p, &deblk_end);
29938 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29939 + unsigned int d_type, struct au_nhash *delist)
29943 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29944 + union au_vdir_deblk_p p, *room, deblk_end;
29945 + struct au_vdir_dehstr *dehstr;
29947 + p.deblk = last_deblk(vdir);
29948 + deblk_end.deblk = p.deblk + deblk_sz;
29949 + room = &vdir->vd_last.p;
29950 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29951 + || !is_deblk_end(room, &deblk_end));
29953 + sz = calc_size(nlen);
29954 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29955 + err = append_deblk(vdir);
29956 + if (unlikely(err))
29959 + p.deblk = last_deblk(vdir);
29960 + deblk_end.deblk = p.deblk + deblk_sz;
29962 + AuDebugOn(room->deblk != p.deblk);
29966 + dehstr = au_cache_alloc_vdir_dehstr();
29967 + if (unlikely(!dehstr))
29970 + dehstr->str = &room->de->de_str;
29971 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29972 + room->de->de_ino = ino;
29973 + room->de->de_type = d_type;
29974 + room->de->de_str.len = nlen;
29975 + memcpy(room->de->de_str.name, name, nlen);
29978 + room->deblk += sz;
29979 + if (unlikely(set_deblk_end(room, &deblk_end)))
29980 + err = append_deblk(vdir);
29987 +/* ---------------------------------------------------------------------- */
29989 +void au_vdir_free(struct au_vdir *vdir, int atonce)
29991 + unsigned char **deblk;
29993 + deblk = vdir->vd_deblk;
29995 + while (vdir->vd_nblk--)
29996 + au_delayed_kfree(*deblk++);
29997 + au_delayed_kfree(vdir->vd_deblk);
29998 + au_cache_dfree_vdir(vdir);
30000 + /* not delayed */
30001 + while (vdir->vd_nblk--)
30003 + kfree(vdir->vd_deblk);
30004 + au_cache_free_vdir(vdir);
30008 +static struct au_vdir *alloc_vdir(struct file *file)
30010 + struct au_vdir *vdir;
30011 + struct super_block *sb;
30014 + sb = file->f_path.dentry->d_sb;
30015 + SiMustAnyLock(sb);
30018 + vdir = au_cache_alloc_vdir();
30019 + if (unlikely(!vdir))
30022 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
30023 + if (unlikely(!vdir->vd_deblk))
30026 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
30027 + if (!vdir->vd_deblk_sz) {
30028 + /* estimate the appropriate size for deblk */
30029 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
30030 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
30032 + vdir->vd_nblk = 0;
30033 + vdir->vd_version = 0;
30034 + vdir->vd_jiffy = 0;
30035 + err = append_deblk(vdir);
30037 + return vdir; /* success */
30039 + au_delayed_kfree(vdir->vd_deblk);
30042 + au_cache_dfree_vdir(vdir);
30044 + vdir = ERR_PTR(err);
30048 +static int reinit_vdir(struct au_vdir *vdir)
30051 + union au_vdir_deblk_p p, deblk_end;
30053 + while (vdir->vd_nblk > 1) {
30054 + au_delayed_kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30055 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30058 + p.deblk = vdir->vd_deblk[0];
30059 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30060 + err = set_deblk_end(&p, &deblk_end);
30061 + /* keep vd_dblk_sz */
30062 + vdir->vd_last.ul = 0;
30063 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30064 + vdir->vd_version = 0;
30065 + vdir->vd_jiffy = 0;
30070 +/* ---------------------------------------------------------------------- */
30072 +#define AuFillVdir_CALLED 1
30073 +#define AuFillVdir_WHABLE (1 << 1)
30074 +#define AuFillVdir_SHWH (1 << 2)
30075 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30076 +#define au_fset_fillvdir(flags, name) \
30077 + do { (flags) |= AuFillVdir_##name; } while (0)
30078 +#define au_fclr_fillvdir(flags, name) \
30079 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30081 +#ifndef CONFIG_AUFS_SHWH
30082 +#undef AuFillVdir_SHWH
30083 +#define AuFillVdir_SHWH 0
30086 +struct fillvdir_arg {
30087 + struct dir_context ctx;
30088 + struct file *file;
30089 + struct au_vdir *vdir;
30090 + struct au_nhash delist;
30091 + struct au_nhash whlist;
30092 + aufs_bindex_t bindex;
30093 + unsigned int flags;
30097 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30098 + loff_t offset __maybe_unused, u64 h_ino,
30099 + unsigned int d_type)
30101 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30102 + char *name = (void *)__name;
30103 + struct super_block *sb;
30105 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30108 + sb = arg->file->f_path.dentry->d_sb;
30109 + au_fset_fillvdir(arg->flags, CALLED);
30111 + if (nlen <= AUFS_WH_PFX_LEN
30112 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30113 + if (test_known(&arg->delist, name, nlen)
30114 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30115 + goto out; /* already exists or whiteouted */
30117 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30119 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30120 + d_type = DT_UNKNOWN;
30121 + arg->err = append_de(arg->vdir, name, nlen, ino,
30122 + d_type, &arg->delist);
30124 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30125 + name += AUFS_WH_PFX_LEN;
30126 + nlen -= AUFS_WH_PFX_LEN;
30127 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30128 + goto out; /* already whiteouted */
30131 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30134 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30135 + d_type = DT_UNKNOWN;
30136 + arg->err = au_nhash_append_wh
30137 + (&arg->whlist, name, nlen, ino, d_type,
30138 + arg->bindex, shwh);
30144 + arg->vdir->vd_jiffy = jiffies;
30146 + AuTraceErr(arg->err);
30150 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30151 + struct au_nhash *whlist, struct au_nhash *delist)
30153 +#ifdef CONFIG_AUFS_SHWH
30155 + unsigned int nh, u;
30156 + struct hlist_head *head;
30157 + struct au_vdir_wh *pos;
30158 + struct hlist_node *n;
30160 + struct au_vdir_destr *destr;
30162 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30165 + o = p = (void *)__get_free_page(GFP_NOFS);
30166 + if (unlikely(!p))
30170 + nh = whlist->nh_num;
30171 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30172 + p += AUFS_WH_PFX_LEN;
30173 + for (u = 0; u < nh; u++) {
30174 + head = whlist->nh_head + u;
30175 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30176 + destr = &pos->wh_str;
30177 + memcpy(p, destr->name, destr->len);
30178 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30179 + pos->wh_ino, pos->wh_type, delist);
30180 + if (unlikely(err))
30185 + au_delayed_free_page((unsigned long)o);
30195 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30198 + unsigned int rdhash;
30200 + aufs_bindex_t bbot, bindex, btop;
30201 + unsigned char shwh;
30202 + struct file *hf, *file;
30203 + struct super_block *sb;
30205 + file = arg->file;
30206 + sb = file->f_path.dentry->d_sb;
30207 + SiMustAnyLock(sb);
30209 + rdhash = au_sbi(sb)->si_rdhash;
30211 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30212 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30213 + if (unlikely(err))
30215 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30216 + if (unlikely(err))
30222 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30224 + au_fset_fillvdir(arg->flags, SHWH);
30226 + btop = au_fbtop(file);
30227 + bbot = au_fbbot_dir(file);
30228 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30229 + hf = au_hf_dir(file, bindex);
30233 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30235 + if (unlikely(offset))
30238 + arg->bindex = bindex;
30239 + au_fclr_fillvdir(arg->flags, WHABLE);
30241 + || (bindex != bbot
30242 + && au_br_whable(au_sbr_perm(sb, bindex))))
30243 + au_fset_fillvdir(arg->flags, WHABLE);
30246 + au_fclr_fillvdir(arg->flags, CALLED);
30248 + err = vfsub_iterate_dir(hf, &arg->ctx);
30251 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30254 + * dir_relax() may be good for concurrency, but aufs should not
30255 + * use it since it will cause a lockdep problem.
30259 + if (!err && shwh)
30260 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30262 + au_nhash_wh_free(&arg->whlist);
30265 + au_nhash_de_free(&arg->delist);
30270 +static int read_vdir(struct file *file, int may_read)
30273 + unsigned long expire;
30274 + unsigned char do_read;
30275 + struct fillvdir_arg arg = {
30277 + .actor = fillvdir
30280 + struct inode *inode;
30281 + struct au_vdir *vdir, *allocated;
30284 + inode = file_inode(file);
30285 + IMustLock(inode);
30286 + IiMustWriteLock(inode);
30287 + SiMustAnyLock(inode->i_sb);
30289 + allocated = NULL;
30291 + expire = au_sbi(inode->i_sb)->si_rdcache;
30292 + vdir = au_ivdir(inode);
30295 + vdir = alloc_vdir(file);
30296 + err = PTR_ERR(vdir);
30297 + if (IS_ERR(vdir))
30300 + allocated = vdir;
30301 + } else if (may_read
30302 + && (inode->i_version != vdir->vd_version
30303 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30305 + err = reinit_vdir(vdir);
30306 + if (unlikely(err))
30311 + return 0; /* success */
30315 + err = au_do_read_vdir(&arg);
30317 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30318 + vdir->vd_version = inode->i_version;
30319 + vdir->vd_last.ul = 0;
30320 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30322 + au_set_ivdir(inode, allocated);
30323 + } else if (allocated)
30324 + au_vdir_free(allocated, /*atonce*/0);
30330 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30333 + unsigned long ul, n;
30334 + const unsigned int deblk_sz = src->vd_deblk_sz;
30336 + AuDebugOn(tgt->vd_nblk != 1);
30339 + if (tgt->vd_nblk < src->vd_nblk) {
30340 + unsigned char **p;
30342 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30343 + GFP_NOFS, /*may_shrink*/0);
30344 + if (unlikely(!p))
30346 + tgt->vd_deblk = p;
30349 + if (tgt->vd_deblk_sz != deblk_sz) {
30350 + unsigned char *p;
30352 + tgt->vd_deblk_sz = deblk_sz;
30353 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30354 + /*may_shrink*/1);
30355 + if (unlikely(!p))
30357 + tgt->vd_deblk[0] = p;
30359 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30360 + tgt->vd_version = src->vd_version;
30361 + tgt->vd_jiffy = src->vd_jiffy;
30363 + n = src->vd_nblk;
30364 + for (ul = 1; ul < n; ul++) {
30365 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30367 + if (unlikely(!tgt->vd_deblk[ul]))
30371 + tgt->vd_nblk = n;
30372 + tgt->vd_last.ul = tgt->vd_last.ul;
30373 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30374 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30375 + - src->vd_deblk[src->vd_last.ul];
30377 + return 0; /* success */
30380 + rerr = reinit_vdir(tgt);
30385 +int au_vdir_init(struct file *file)
30388 + struct inode *inode;
30389 + struct au_vdir *vdir_cache, *allocated;
30391 + /* test file->f_pos here instead of ctx->pos */
30392 + err = read_vdir(file, !file->f_pos);
30393 + if (unlikely(err))
30396 + allocated = NULL;
30397 + vdir_cache = au_fvdir_cache(file);
30398 + if (!vdir_cache) {
30399 + vdir_cache = alloc_vdir(file);
30400 + err = PTR_ERR(vdir_cache);
30401 + if (IS_ERR(vdir_cache))
30403 + allocated = vdir_cache;
30404 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30405 + /* test file->f_pos here instead of ctx->pos */
30406 + err = reinit_vdir(vdir_cache);
30407 + if (unlikely(err))
30410 + return 0; /* success */
30412 + inode = file_inode(file);
30413 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30415 + file->f_version = inode->i_version;
30417 + au_set_fvdir_cache(file, allocated);
30418 + } else if (allocated)
30419 + au_vdir_free(allocated, /*atonce*/0);
30425 +static loff_t calc_offset(struct au_vdir *vdir)
30428 + union au_vdir_deblk_p p;
30430 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30431 + offset = vdir->vd_last.p.deblk - p.deblk;
30432 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30436 +/* returns true or false */
30437 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30440 + unsigned int deblk_sz;
30441 + unsigned long ul, n;
30443 + union au_vdir_deblk_p p, deblk_end;
30444 + struct au_vdir *vdir_cache;
30447 + vdir_cache = au_fvdir_cache(file);
30448 + offset = calc_offset(vdir_cache);
30449 + AuDbg("offset %lld\n", offset);
30450 + if (ctx->pos == offset)
30453 + vdir_cache->vd_last.ul = 0;
30454 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30459 + deblk_sz = vdir_cache->vd_deblk_sz;
30460 + ul = div64_u64(ctx->pos, deblk_sz);
30461 + AuDbg("ul %lu\n", ul);
30462 + if (ul >= vdir_cache->vd_nblk)
30465 + n = vdir_cache->vd_nblk;
30466 + for (; ul < n; ul++) {
30467 + p.deblk = vdir_cache->vd_deblk[ul];
30468 + deblk_end.deblk = p.deblk + deblk_sz;
30470 + offset *= deblk_sz;
30471 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30474 + l = calc_size(p.de->de_str.len);
30478 + if (!is_deblk_end(&p, &deblk_end)) {
30480 + vdir_cache->vd_last.ul = ul;
30481 + vdir_cache->vd_last.p = p;
30488 + AuTraceErr(!valid);
30492 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30494 + unsigned int l, deblk_sz;
30495 + union au_vdir_deblk_p deblk_end;
30496 + struct au_vdir *vdir_cache;
30497 + struct au_vdir_de *de;
30499 + vdir_cache = au_fvdir_cache(file);
30500 + if (!seek_vdir(file, ctx))
30503 + deblk_sz = vdir_cache->vd_deblk_sz;
30505 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30506 + deblk_end.deblk += deblk_sz;
30507 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30508 + de = vdir_cache->vd_last.p.de;
30509 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30510 + de->de_str.len, de->de_str.name, ctx->pos,
30511 + (unsigned long)de->de_ino, de->de_type);
30512 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30513 + de->de_str.len, de->de_ino,
30515 + /* todo: ignore the error caused by udba? */
30516 + /* return err; */
30520 + l = calc_size(de->de_str.len);
30521 + vdir_cache->vd_last.p.deblk += l;
30524 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30525 + vdir_cache->vd_last.ul++;
30526 + vdir_cache->vd_last.p.deblk
30527 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30528 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30537 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30538 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30539 +++ linux/fs/aufs/vfsub.c 2017-03-02 14:24:13.870255912 +0100
30542 + * Copyright (C) 2005-2017 Junjiro R. Okajima
30544 + * This program, aufs is free software; you can redistribute it and/or modify
30545 + * it under the terms of the GNU General Public License as published by
30546 + * the Free Software Foundation; either version 2 of the License, or
30547 + * (at your option) any later version.
30549 + * This program is distributed in the hope that it will be useful,
30550 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30551 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30552 + * GNU General Public License for more details.
30554 + * You should have received a copy of the GNU General Public License
30555 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30559 + * sub-routines for VFS
30562 +#include <linux/namei.h>
30563 +#include <linux/nsproxy.h>
30564 +#include <linux/security.h>
30565 +#include <linux/splice.h>
30566 +#ifdef CONFIG_AUFS_BR_FUSE
30567 +#include "../fs/mount.h"
30571 +#ifdef CONFIG_AUFS_BR_FUSE
30572 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30574 + struct nsproxy *ns;
30576 + if (!au_test_fuse(h_sb) || !au_userns)
30579 + ns = current->nsproxy;
30580 + /* no {get,put}_nsproxy(ns) */
30581 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30585 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
30590 + down_read(&h_sb->s_umount);
30591 + err = __sync_filesystem(h_sb, wait);
30592 + up_read(&h_sb->s_umount);
30598 +/* ---------------------------------------------------------------------- */
30600 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30604 + struct super_block *h_sb;
30606 + /* for remote fs, leave work for its getattr or d_revalidate */
30607 + /* for bad i_attr fs, handle them in aufs_getattr() */
30608 + /* still some fs may acquire i_mutex. we need to skip them */
30612 + h_sb = h_path->dentry->d_sb;
30613 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30615 + err = vfs_getattr(h_path, &st);
30620 +/* ---------------------------------------------------------------------- */
30622 +struct file *vfsub_dentry_open(struct path *path, int flags)
30624 + struct file *file;
30626 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30628 + if (!IS_ERR_OR_NULL(file)
30629 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30630 + i_readcount_inc(d_inode(path->dentry));
30635 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30637 + struct file *file;
30640 + file = filp_open(path,
30641 + oflags /* | __FMODE_NONOTIFY */,
30644 + if (IS_ERR(file))
30646 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30653 + * Ideally this function should call VFS:do_last() in order to keep all its
30654 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30655 + * structure such as nameidata. This is a second (or third) best approach.
30656 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30658 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30659 + struct vfsub_aopen_args *args, struct au_branch *br)
30662 + struct file *file = args->file;
30663 + /* copied from linux/fs/namei.c:atomic_open() */
30664 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30667 + AuDebugOn(!dir->i_op->atomic_open);
30669 + err = au_br_test_oflag(args->open_flag, br);
30670 + if (unlikely(err))
30673 + args->file->f_path.dentry = DENTRY_NOT_SET;
30674 + args->file->f_path.mnt = au_br_mnt(br);
30675 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30676 + args->create_mode, args->opened);
30678 + /* some filesystems don't set FILE_CREATED while succeeded? */
30679 + if (*args->opened & FILE_CREATED)
30680 + fsnotify_create(dir, dentry);
30686 + /* todo: call VFS:may_open() here */
30687 + err = open_check_o_direct(file);
30688 + /* todo: ima_file_check() too? */
30689 + if (!err && (args->open_flag & __FMODE_EXEC))
30690 + err = deny_write_access(file);
30691 + if (unlikely(err))
30692 + /* note that the file is created and still opened */
30697 + fsnotify_open(file);
30703 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30707 + err = kern_path(name, flags, path);
30708 + if (!err && d_is_positive(path->dentry))
30709 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30713 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30714 + struct dentry *parent, int len)
30716 + struct path path = {
30720 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30721 + if (IS_ERR(path.dentry))
30723 + if (d_is_positive(path.dentry))
30724 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30727 + AuTraceErrPtr(path.dentry);
30728 + return path.dentry;
30731 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30734 + struct path path = {
30738 + /* VFS checks it too, but by WARN_ON_ONCE() */
30739 + IMustLock(d_inode(parent));
30741 + path.dentry = lookup_one_len(name, parent, len);
30742 + if (IS_ERR(path.dentry))
30744 + if (d_is_positive(path.dentry))
30745 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30748 + AuTraceErrPtr(path.dentry);
30749 + return path.dentry;
30752 +void vfsub_call_lkup_one(void *args)
30754 + struct vfsub_lkup_one_args *a = args;
30755 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30758 +/* ---------------------------------------------------------------------- */
30760 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30761 + struct dentry *d2, struct au_hinode *hdir2)
30763 + struct dentry *d;
30766 + d = lock_rename(d1, d2);
30768 + au_hn_suspend(hdir1);
30769 + if (hdir1 != hdir2)
30770 + au_hn_suspend(hdir2);
30775 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30776 + struct dentry *d2, struct au_hinode *hdir2)
30778 + au_hn_resume(hdir1);
30779 + if (hdir1 != hdir2)
30780 + au_hn_resume(hdir2);
30782 + unlock_rename(d1, d2);
30786 +/* ---------------------------------------------------------------------- */
30788 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30791 + struct dentry *d;
30795 + d = path->dentry;
30796 + path->dentry = d->d_parent;
30797 + err = security_path_mknod(path, d, mode, 0);
30798 + path->dentry = d;
30799 + if (unlikely(err))
30803 + err = vfs_create(dir, path->dentry, mode, want_excl);
30806 + struct path tmp = *path;
30809 + vfsub_update_h_iattr(&tmp, &did);
30811 + tmp.dentry = path->dentry->d_parent;
30812 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30821 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30824 + struct dentry *d;
30828 + d = path->dentry;
30829 + path->dentry = d->d_parent;
30830 + err = security_path_symlink(path, d, symname);
30831 + path->dentry = d;
30832 + if (unlikely(err))
30836 + err = vfs_symlink(dir, path->dentry, symname);
30839 + struct path tmp = *path;
30842 + vfsub_update_h_iattr(&tmp, &did);
30844 + tmp.dentry = path->dentry->d_parent;
30845 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30854 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30857 + struct dentry *d;
30861 + d = path->dentry;
30862 + path->dentry = d->d_parent;
30863 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30864 + path->dentry = d;
30865 + if (unlikely(err))
30869 + err = vfs_mknod(dir, path->dentry, mode, dev);
30872 + struct path tmp = *path;
30875 + vfsub_update_h_iattr(&tmp, &did);
30877 + tmp.dentry = path->dentry->d_parent;
30878 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30887 +static int au_test_nlink(struct inode *inode)
30889 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30891 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30892 + || inode->i_nlink < link_max)
30897 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30898 + struct inode **delegated_inode)
30901 + struct dentry *d;
30905 + err = au_test_nlink(d_inode(src_dentry));
30906 + if (unlikely(err))
30909 + /* we don't call may_linkat() */
30910 + d = path->dentry;
30911 + path->dentry = d->d_parent;
30912 + err = security_path_link(src_dentry, path, d);
30913 + path->dentry = d;
30914 + if (unlikely(err))
30918 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30921 + struct path tmp = *path;
30924 + /* fuse has different memory inode for the same inumber */
30925 + vfsub_update_h_iattr(&tmp, &did);
30927 + tmp.dentry = path->dentry->d_parent;
30928 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30929 + tmp.dentry = src_dentry;
30930 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30939 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30940 + struct inode *dir, struct path *path,
30941 + struct inode **delegated_inode, unsigned int flags)
30944 + struct path tmp = {
30947 + struct dentry *d;
30950 + IMustLock(src_dir);
30952 + d = path->dentry;
30953 + path->dentry = d->d_parent;
30954 + tmp.dentry = src_dentry->d_parent;
30955 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30956 + path->dentry = d;
30957 + if (unlikely(err))
30961 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30962 + delegated_inode, flags);
30967 + tmp.dentry = d->d_parent;
30968 + vfsub_update_h_iattr(&tmp, &did);
30970 + tmp.dentry = src_dentry;
30971 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30972 + tmp.dentry = src_dentry->d_parent;
30973 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30982 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30985 + struct dentry *d;
30989 + d = path->dentry;
30990 + path->dentry = d->d_parent;
30991 + err = security_path_mkdir(path, d, mode);
30992 + path->dentry = d;
30993 + if (unlikely(err))
30997 + err = vfs_mkdir(dir, path->dentry, mode);
31000 + struct path tmp = *path;
31003 + vfsub_update_h_iattr(&tmp, &did);
31005 + tmp.dentry = path->dentry->d_parent;
31006 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31015 +int vfsub_rmdir(struct inode *dir, struct path *path)
31018 + struct dentry *d;
31022 + d = path->dentry;
31023 + path->dentry = d->d_parent;
31024 + err = security_path_rmdir(path, d);
31025 + path->dentry = d;
31026 + if (unlikely(err))
31030 + err = vfs_rmdir(dir, path->dentry);
31033 + struct path tmp = {
31034 + .dentry = path->dentry->d_parent,
31038 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31045 +/* ---------------------------------------------------------------------- */
31047 +/* todo: support mmap_sem? */
31048 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31054 + err = vfs_read(file, ubuf, count, ppos);
31057 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31061 +/* todo: kernel_read()? */
31062 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31066 + mm_segment_t oldfs;
31073 + oldfs = get_fs();
31074 + set_fs(KERNEL_DS);
31075 + err = vfsub_read_u(file, buf.u, count, ppos);
31080 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31086 + err = vfs_write(file, ubuf, count, ppos);
31089 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31093 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31096 + mm_segment_t oldfs;
31099 + const char __user *u;
31103 + oldfs = get_fs();
31104 + set_fs(KERNEL_DS);
31105 + err = vfsub_write_u(file, buf.u, count, ppos);
31110 +int vfsub_flush(struct file *file, fl_owner_t id)
31115 + if (file->f_op->flush) {
31116 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31117 + err = file->f_op->flush(file, id);
31120 + err = file->f_op->flush(file, id);
31124 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31130 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31134 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31137 + err = iterate_dir(file, ctx);
31140 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31144 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31145 + struct pipe_inode_info *pipe, size_t len,
31146 + unsigned int flags)
31151 + err = do_splice_to(in, ppos, pipe, len, flags);
31153 + file_accessed(in);
31155 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31159 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31160 + loff_t *ppos, size_t len, unsigned int flags)
31165 + err = do_splice_from(pipe, out, ppos, len, flags);
31168 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31172 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31176 + /* file can be NULL */
31178 + err = vfs_fsync(file, datasync);
31182 + AuDebugOn(!file);
31183 + path = &file->f_path;
31185 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31190 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31191 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31192 + struct file *h_file)
31195 + struct inode *h_inode;
31196 + struct super_block *h_sb;
31199 + err = vfsub_truncate(h_path, length);
31203 + h_inode = d_inode(h_path->dentry);
31204 + h_sb = h_inode->i_sb;
31206 + sb_start_write(h_sb);
31208 + err = locks_verify_truncate(h_inode, h_file, length);
31210 + err = security_path_truncate(h_path);
31213 + err = do_truncate(h_path->dentry, length, attr, h_file);
31217 + sb_end_write(h_sb);
31224 +/* ---------------------------------------------------------------------- */
31226 +struct au_vfsub_mkdir_args {
31228 + struct inode *dir;
31229 + struct path *path;
31233 +static void au_call_vfsub_mkdir(void *args)
31235 + struct au_vfsub_mkdir_args *a = args;
31236 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31239 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31241 + int err, do_sio, wkq_err;
31243 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31246 + err = vfsub_mkdir(dir, path, mode);
31249 + struct au_vfsub_mkdir_args args = {
31255 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31256 + if (unlikely(wkq_err))
31263 +struct au_vfsub_rmdir_args {
31265 + struct inode *dir;
31266 + struct path *path;
31269 +static void au_call_vfsub_rmdir(void *args)
31271 + struct au_vfsub_rmdir_args *a = args;
31272 + *a->errp = vfsub_rmdir(a->dir, a->path);
31275 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31277 + int err, do_sio, wkq_err;
31279 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31282 + err = vfsub_rmdir(dir, path);
31285 + struct au_vfsub_rmdir_args args = {
31290 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31291 + if (unlikely(wkq_err))
31298 +/* ---------------------------------------------------------------------- */
31300 +struct notify_change_args {
31302 + struct path *path;
31303 + struct iattr *ia;
31304 + struct inode **delegated_inode;
31307 +static void call_notify_change(void *args)
31309 + struct notify_change_args *a = args;
31310 + struct inode *h_inode;
31312 + h_inode = d_inode(a->path->dentry);
31313 + IMustLock(h_inode);
31315 + *a->errp = -EPERM;
31316 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31318 + *a->errp = notify_change(a->path->dentry, a->ia,
31319 + a->delegated_inode);
31322 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31324 + AuTraceErr(*a->errp);
31327 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31328 + struct inode **delegated_inode)
31331 + struct notify_change_args args = {
31335 + .delegated_inode = delegated_inode
31338 + call_notify_change(&args);
31343 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31344 + struct inode **delegated_inode)
31346 + int err, wkq_err;
31347 + struct notify_change_args args = {
31351 + .delegated_inode = delegated_inode
31354 + wkq_err = au_wkq_wait(call_notify_change, &args);
31355 + if (unlikely(wkq_err))
31361 +/* ---------------------------------------------------------------------- */
31363 +struct unlink_args {
31365 + struct inode *dir;
31366 + struct path *path;
31367 + struct inode **delegated_inode;
31370 +static void call_unlink(void *args)
31372 + struct unlink_args *a = args;
31373 + struct dentry *d = a->path->dentry;
31374 + struct inode *h_inode;
31375 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31376 + && au_dcount(d) == 1);
31378 + IMustLock(a->dir);
31380 + a->path->dentry = d->d_parent;
31381 + *a->errp = security_path_unlink(a->path, d);
31382 + a->path->dentry = d;
31383 + if (unlikely(*a->errp))
31386 + if (!stop_sillyrename)
31389 + if (d_is_positive(d)) {
31390 + h_inode = d_inode(d);
31395 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31398 + struct path tmp = {
31399 + .dentry = d->d_parent,
31400 + .mnt = a->path->mnt
31402 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31405 + if (!stop_sillyrename)
31410 + AuTraceErr(*a->errp);
31414 + * @dir: must be locked.
31415 + * @dentry: target dentry.
31417 +int vfsub_unlink(struct inode *dir, struct path *path,
31418 + struct inode **delegated_inode, int force)
31421 + struct unlink_args args = {
31425 + .delegated_inode = delegated_inode
31429 + call_unlink(&args);
31433 + wkq_err = au_wkq_wait(call_unlink, &args);
31434 + if (unlikely(wkq_err))
31440 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31441 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31442 +++ linux/fs/aufs/vfsub.h 2017-03-02 14:24:13.870255912 +0100
31445 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31447 + * This program, aufs is free software; you can redistribute it and/or modify
31448 + * it under the terms of the GNU General Public License as published by
31449 + * the Free Software Foundation; either version 2 of the License, or
31450 + * (at your option) any later version.
31452 + * This program is distributed in the hope that it will be useful,
31453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31455 + * GNU General Public License for more details.
31457 + * You should have received a copy of the GNU General Public License
31458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31462 + * sub-routines for VFS
31465 +#ifndef __AUFS_VFSUB_H__
31466 +#define __AUFS_VFSUB_H__
31470 +#include <linux/fs.h>
31471 +#include <linux/mount.h>
31472 +#include <linux/posix_acl.h>
31473 +#include <linux/xattr.h>
31474 +#include "debug.h"
31476 +/* copied from linux/fs/internal.h */
31477 +/* todo: BAD approach!! */
31478 +extern void __mnt_drop_write(struct vfsmount *);
31479 +extern int open_check_o_direct(struct file *f);
31481 +/* ---------------------------------------------------------------------- */
31483 +/* lock subclass for lower inode */
31484 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31485 +/* reduce? gave up. */
31487 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31488 + AuLsc_I_PARENT, /* lower inode, parent first */
31489 + AuLsc_I_PARENT2, /* copyup dirs */
31490 + AuLsc_I_PARENT3, /* copyup wh */
31496 +/* to debug easier, do not make them inlined functions */
31497 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31498 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31500 +/* ---------------------------------------------------------------------- */
31502 +static inline void vfsub_drop_nlink(struct inode *inode)
31504 + AuDebugOn(!inode->i_nlink);
31505 + drop_nlink(inode);
31508 +static inline void vfsub_dead_dir(struct inode *inode)
31510 + AuDebugOn(!S_ISDIR(inode->i_mode));
31511 + inode->i_flags |= S_DEAD;
31512 + clear_nlink(inode);
31515 +static inline int vfsub_native_ro(struct inode *inode)
31517 + return (inode->i_sb->s_flags & MS_RDONLY)
31518 + || IS_RDONLY(inode)
31519 + /* || IS_APPEND(inode) */
31520 + || IS_IMMUTABLE(inode);
31523 +#ifdef CONFIG_AUFS_BR_FUSE
31524 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31526 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31529 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
31531 +/* ---------------------------------------------------------------------- */
31533 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31534 +struct file *vfsub_dentry_open(struct path *path, int flags);
31535 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31536 +struct vfsub_aopen_args {
31537 + struct file *file;
31538 + unsigned int open_flag;
31539 + umode_t create_mode;
31543 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31544 + struct vfsub_aopen_args *args, struct au_branch *br);
31545 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31547 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31548 + struct dentry *parent, int len);
31549 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31552 +struct vfsub_lkup_one_args {
31553 + struct dentry **errp;
31554 + struct qstr *name;
31555 + struct dentry *parent;
31558 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31559 + struct dentry *parent)
31561 + return vfsub_lookup_one_len(name->name, parent, name->len);
31564 +void vfsub_call_lkup_one(void *args);
31566 +/* ---------------------------------------------------------------------- */
31568 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31573 + err = mnt_want_write(mnt);
31578 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31581 + mnt_drop_write(mnt);
31585 +#if 0 /* reserved */
31586 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31589 + mnt_drop_write_file(file);
31594 +/* ---------------------------------------------------------------------- */
31597 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31598 + struct dentry *d2, struct au_hinode *hdir2);
31599 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31600 + struct dentry *d2, struct au_hinode *hdir2);
31602 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31604 +int vfsub_symlink(struct inode *dir, struct path *path,
31605 + const char *symname);
31606 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31607 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31608 + struct path *path, struct inode **delegated_inode);
31609 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31610 + struct inode *hdir, struct path *path,
31611 + struct inode **delegated_inode, unsigned int flags);
31612 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31613 +int vfsub_rmdir(struct inode *dir, struct path *path);
31615 +/* ---------------------------------------------------------------------- */
31617 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31619 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31621 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31623 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31625 +int vfsub_flush(struct file *file, fl_owner_t id);
31626 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31628 +static inline loff_t vfsub_f_size_read(struct file *file)
31630 + return i_size_read(file_inode(file));
31633 +static inline unsigned int vfsub_file_flags(struct file *file)
31635 + unsigned int flags;
31637 + spin_lock(&file->f_lock);
31638 + flags = file->f_flags;
31639 + spin_unlock(&file->f_lock);
31644 +static inline int vfsub_file_execed(struct file *file)
31646 + /* todo: direct access f_flags */
31647 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31650 +#if 0 /* reserved */
31651 +static inline void vfsub_file_accessed(struct file *h_file)
31653 + file_accessed(h_file);
31654 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31658 +#if 0 /* reserved */
31659 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31660 + struct dentry *h_dentry)
31662 + struct path h_path = {
31663 + .dentry = h_dentry,
31666 + touch_atime(&h_path);
31667 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31671 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31674 + return update_time(h_inode, ts, flags);
31675 + /* no vfsub_update_h_iattr() since we don't have struct path */
31678 +#ifdef CONFIG_FS_POSIX_ACL
31679 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31683 + err = posix_acl_chmod(h_inode, h_mode);
31684 + if (err == -EOPNOTSUPP)
31689 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31692 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31693 + struct pipe_inode_info *pipe, size_t len,
31694 + unsigned int flags);
31695 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31696 + loff_t *ppos, size_t len, unsigned int flags);
31698 +static inline long vfsub_truncate(struct path *path, loff_t length)
31703 + err = vfs_truncate(path, length);
31708 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31709 + struct file *h_file);
31710 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31712 +/* ---------------------------------------------------------------------- */
31714 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31719 + err = vfs_llseek(file, offset, origin);
31724 +/* ---------------------------------------------------------------------- */
31726 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31727 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31728 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31729 + struct inode **delegated_inode);
31730 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31731 + struct inode **delegated_inode);
31732 +int vfsub_unlink(struct inode *dir, struct path *path,
31733 + struct inode **delegated_inode, int force);
31735 +/* ---------------------------------------------------------------------- */
31737 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31738 + const void *value, size_t size, int flags)
31743 + err = vfs_setxattr(dentry, name, value, size, flags);
31749 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31754 + err = vfs_removexattr(dentry, name);
31760 +#endif /* __KERNEL__ */
31761 +#endif /* __AUFS_VFSUB_H__ */
31762 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31763 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31764 +++ linux/fs/aufs/wbr_policy.c 2017-03-02 14:24:13.870255912 +0100
31767 + * Copyright (C) 2005-2017 Junjiro R. Okajima
31769 + * This program, aufs is free software; you can redistribute it and/or modify
31770 + * it under the terms of the GNU General Public License as published by
31771 + * the Free Software Foundation; either version 2 of the License, or
31772 + * (at your option) any later version.
31774 + * This program is distributed in the hope that it will be useful,
31775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31777 + * GNU General Public License for more details.
31779 + * You should have received a copy of the GNU General Public License
31780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31784 + * policies for selecting one among multiple writable branches
31787 +#include <linux/statfs.h>
31790 +/* subset of cpup_attr() */
31791 +static noinline_for_stack
31792 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31796 + struct inode *h_isrc;
31798 + h_isrc = d_inode(h_src);
31799 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31800 + ia.ia_mode = h_isrc->i_mode;
31801 + ia.ia_uid = h_isrc->i_uid;
31802 + ia.ia_gid = h_isrc->i_gid;
31803 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31804 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31805 + /* no delegation since it is just created */
31806 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31808 + /* is this nfs only? */
31809 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31810 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31811 + ia.ia_mode = h_isrc->i_mode;
31812 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31818 +#define AuCpdown_PARENT_OPQ 1
31819 +#define AuCpdown_WHED (1 << 1)
31820 +#define AuCpdown_MADE_DIR (1 << 2)
31821 +#define AuCpdown_DIROPQ (1 << 3)
31822 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31823 +#define au_fset_cpdown(flags, name) \
31824 + do { (flags) |= AuCpdown_##name; } while (0)
31825 +#define au_fclr_cpdown(flags, name) \
31826 + do { (flags) &= ~AuCpdown_##name; } while (0)
31828 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31829 + unsigned int *flags)
31832 + struct dentry *opq_dentry;
31834 + opq_dentry = au_diropq_create(dentry, bdst);
31835 + err = PTR_ERR(opq_dentry);
31836 + if (IS_ERR(opq_dentry))
31838 + dput(opq_dentry);
31839 + au_fset_cpdown(*flags, DIROPQ);
31845 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31846 + struct inode *dir, aufs_bindex_t bdst)
31849 + struct path h_path;
31850 + struct au_branch *br;
31852 + br = au_sbr(dentry->d_sb, bdst);
31853 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31854 + err = PTR_ERR(h_path.dentry);
31855 + if (IS_ERR(h_path.dentry))
31859 + if (d_is_positive(h_path.dentry)) {
31860 + h_path.mnt = au_br_mnt(br);
31861 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31864 + dput(h_path.dentry);
31870 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31871 + struct au_pin *pin,
31872 + struct dentry *h_parent, void *arg)
31875 + aufs_bindex_t bopq, btop;
31876 + struct path h_path;
31877 + struct dentry *parent;
31878 + struct inode *h_dir, *h_inode, *inode, *dir;
31879 + unsigned int *flags = arg;
31881 + btop = au_dbtop(dentry);
31882 + /* dentry is di-locked */
31883 + parent = dget_parent(dentry);
31884 + dir = d_inode(parent);
31885 + h_dir = d_inode(h_parent);
31886 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31887 + IMustLock(h_dir);
31889 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31890 + if (unlikely(err < 0))
31892 + h_path.dentry = au_h_dptr(dentry, bdst);
31893 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31894 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31895 + S_IRWXU | S_IRUGO | S_IXUGO);
31896 + if (unlikely(err))
31898 + au_fset_cpdown(*flags, MADE_DIR);
31900 + bopq = au_dbdiropq(dentry);
31901 + au_fclr_cpdown(*flags, WHED);
31902 + au_fclr_cpdown(*flags, DIROPQ);
31903 + if (au_dbwh(dentry) == bdst)
31904 + au_fset_cpdown(*flags, WHED);
31905 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31906 + au_fset_cpdown(*flags, PARENT_OPQ);
31907 + h_inode = d_inode(h_path.dentry);
31908 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31909 + if (au_ftest_cpdown(*flags, WHED)) {
31910 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31911 + if (unlikely(err)) {
31912 + inode_unlock(h_inode);
31917 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31918 + inode_unlock(h_inode);
31919 + if (unlikely(err))
31922 + if (au_ftest_cpdown(*flags, WHED)) {
31923 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31924 + if (unlikely(err))
31928 + inode = d_inode(dentry);
31929 + if (au_ibbot(inode) < bdst)
31930 + au_set_ibbot(inode, bdst);
31931 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31932 + au_hi_flags(inode, /*isdir*/1));
31933 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31934 + goto out; /* success */
31938 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31939 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31940 + rerr = au_diropq_remove(dentry, bdst);
31941 + inode_unlock(h_inode);
31942 + if (unlikely(rerr)) {
31943 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31944 + dentry, bdst, rerr);
31950 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31951 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31952 + if (unlikely(rerr)) {
31953 + AuIOErr("failed removing %pd b%d (%d)\n",
31954 + dentry, bdst, rerr);
31959 + au_set_h_dptr(dentry, bdst, NULL);
31960 + if (au_dbbot(dentry) == bdst)
31961 + au_update_dbbot(dentry);
31967 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31970 + unsigned int flags;
31973 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31978 +/* ---------------------------------------------------------------------- */
31980 +/* policies for create */
31982 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31984 + int err, i, j, ndentry;
31985 + aufs_bindex_t bopq;
31986 + struct au_dcsub_pages dpages;
31987 + struct au_dpage *dpage;
31988 + struct dentry **dentries, *parent, *d;
31990 + err = au_dpages_init(&dpages, GFP_NOFS);
31991 + if (unlikely(err))
31993 + parent = dget_parent(dentry);
31994 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31995 + if (unlikely(err))
31999 + for (i = 0; i < dpages.ndpage; i++) {
32000 + dpage = dpages.dpages + i;
32001 + dentries = dpage->dentries;
32002 + ndentry = dpage->ndentry;
32003 + for (j = 0; j < ndentry; j++) {
32005 + di_read_lock_parent2(d, !AuLock_IR);
32006 + bopq = au_dbdiropq(d);
32007 + di_read_unlock(d, !AuLock_IR);
32008 + if (bopq >= 0 && bopq < err)
32015 + au_dpages_free(&dpages);
32020 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32022 + for (; bindex >= 0; bindex--)
32023 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32028 +/* top down parent */
32029 +static int au_wbr_create_tdp(struct dentry *dentry,
32030 + unsigned int flags __maybe_unused)
32033 + aufs_bindex_t btop, bindex;
32034 + struct super_block *sb;
32035 + struct dentry *parent, *h_parent;
32037 + sb = dentry->d_sb;
32038 + btop = au_dbtop(dentry);
32040 + if (!au_br_rdonly(au_sbr(sb, btop)))
32044 + parent = dget_parent(dentry);
32045 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32046 + h_parent = au_h_dptr(parent, bindex);
32047 + if (!h_parent || d_is_negative(h_parent))
32050 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32057 + /* bottom up here */
32058 + if (unlikely(err < 0)) {
32059 + err = au_wbr_bu(sb, btop - 1);
32061 + err = au_wbr_nonopq(dentry, err);
32065 + AuDbg("b%d\n", err);
32069 +/* ---------------------------------------------------------------------- */
32071 +/* an exception for the policy other than tdp */
32072 +static int au_wbr_create_exp(struct dentry *dentry)
32075 + aufs_bindex_t bwh, bdiropq;
32076 + struct dentry *parent;
32079 + bwh = au_dbwh(dentry);
32080 + parent = dget_parent(dentry);
32081 + bdiropq = au_dbdiropq(parent);
32083 + if (bdiropq >= 0)
32084 + err = min(bdiropq, bwh);
32087 + AuDbg("%d\n", err);
32088 + } else if (bdiropq >= 0) {
32090 + AuDbg("%d\n", err);
32095 + err = au_wbr_nonopq(dentry, err);
32097 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32100 + AuDbg("%d\n", err);
32104 +/* ---------------------------------------------------------------------- */
32107 +static int au_wbr_create_init_rr(struct super_block *sb)
32111 + err = au_wbr_bu(sb, au_sbbot(sb));
32112 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32115 + AuDbg("b%d\n", err);
32119 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32123 + aufs_bindex_t bindex, bbot;
32124 + struct super_block *sb;
32127 + err = au_wbr_create_exp(dentry);
32131 + sb = dentry->d_sb;
32132 + next = &au_sbi(sb)->si_wbr_rr_next;
32133 + bbot = au_sbbot(sb);
32135 + for (bindex = 0; bindex <= bbot; bindex++) {
32136 + if (!au_ftest_wbr(flags, DIR)) {
32137 + err = atomic_dec_return(next) + 1;
32138 + /* modulo for 0 is meaningless */
32139 + if (unlikely(!err))
32140 + err = atomic_dec_return(next) + 1;
32142 + err = atomic_read(next);
32143 + AuDbg("%d\n", err);
32146 + AuDbg("%d\n", err);
32147 + if (!au_br_rdonly(au_sbr(sb, err)))
32153 + err = au_wbr_nonopq(dentry, err);
32156 + AuDbg("%d\n", err);
32160 +/* ---------------------------------------------------------------------- */
32162 +/* most free space */
32163 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32165 + struct super_block *sb;
32166 + struct au_branch *br;
32167 + struct au_wbr_mfs *mfs;
32168 + struct dentry *h_parent;
32169 + aufs_bindex_t bindex, bbot;
32171 + unsigned long long b, bavail;
32172 + struct path h_path;
32173 + /* reduce the stack usage */
32174 + struct kstatfs *st;
32176 + st = kmalloc(sizeof(*st), GFP_NOFS);
32177 + if (unlikely(!st)) {
32178 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32183 + sb = dentry->d_sb;
32184 + mfs = &au_sbi(sb)->si_wbr_mfs;
32185 + MtxMustLock(&mfs->mfs_lock);
32186 + mfs->mfs_bindex = -EROFS;
32187 + mfs->mfsrr_bytes = 0;
32190 + bbot = au_sbbot(sb);
32192 + bindex = au_dbtop(parent);
32193 + bbot = au_dbtaildir(parent);
32196 + for (; bindex <= bbot; bindex++) {
32198 + h_parent = au_h_dptr(parent, bindex);
32199 + if (!h_parent || d_is_negative(h_parent))
32202 + br = au_sbr(sb, bindex);
32203 + if (au_br_rdonly(br))
32206 + /* sb->s_root for NFS is unreliable */
32207 + h_path.mnt = au_br_mnt(br);
32208 + h_path.dentry = h_path.mnt->mnt_root;
32209 + err = vfs_statfs(&h_path, st);
32210 + if (unlikely(err)) {
32211 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32215 + /* when the available size is equal, select the lower one */
32216 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32217 + || sizeof(b) < sizeof(st->f_bsize));
32218 + b = st->f_bavail * st->f_bsize;
32219 + br->br_wbr->wbr_bytes = b;
32220 + if (b >= bavail) {
32222 + mfs->mfs_bindex = bindex;
32223 + mfs->mfs_jiffy = jiffies;
32227 + mfs->mfsrr_bytes = bavail;
32228 + AuDbg("b%d\n", mfs->mfs_bindex);
32229 + au_delayed_kfree(st);
32232 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32235 + struct dentry *parent;
32236 + struct super_block *sb;
32237 + struct au_wbr_mfs *mfs;
32239 + err = au_wbr_create_exp(dentry);
32243 + sb = dentry->d_sb;
32245 + if (au_ftest_wbr(flags, PARENT))
32246 + parent = dget_parent(dentry);
32247 + mfs = &au_sbi(sb)->si_wbr_mfs;
32248 + mutex_lock(&mfs->mfs_lock);
32249 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32250 + || mfs->mfs_bindex < 0
32251 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32252 + au_mfs(dentry, parent);
32253 + mutex_unlock(&mfs->mfs_lock);
32254 + err = mfs->mfs_bindex;
32258 + err = au_wbr_nonopq(dentry, err);
32261 + AuDbg("b%d\n", err);
32265 +static int au_wbr_create_init_mfs(struct super_block *sb)
32267 + struct au_wbr_mfs *mfs;
32269 + mfs = &au_sbi(sb)->si_wbr_mfs;
32270 + mutex_init(&mfs->mfs_lock);
32271 + mfs->mfs_jiffy = 0;
32272 + mfs->mfs_bindex = -EROFS;
32277 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32279 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32283 +/* ---------------------------------------------------------------------- */
32285 +/* top down regardless parent, and then mfs */
32286 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32287 + unsigned int flags __maybe_unused)
32290 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32291 + unsigned long long watermark;
32292 + struct super_block *sb;
32293 + struct au_wbr_mfs *mfs;
32294 + struct au_branch *br;
32295 + struct dentry *parent;
32297 + sb = dentry->d_sb;
32298 + mfs = &au_sbi(sb)->si_wbr_mfs;
32299 + mutex_lock(&mfs->mfs_lock);
32300 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32301 + || mfs->mfs_bindex < 0)
32302 + au_mfs(dentry, /*parent*/NULL);
32303 + watermark = mfs->mfsrr_watermark;
32304 + bmfs = mfs->mfs_bindex;
32305 + mutex_unlock(&mfs->mfs_lock);
32307 + /* another style of au_wbr_create_exp() */
32308 + bwh = au_dbwh(dentry);
32309 + parent = dget_parent(dentry);
32310 + btail = au_dbtaildir(parent);
32311 + if (bwh >= 0 && bwh < btail)
32314 + err = au_wbr_nonopq(dentry, btail);
32315 + if (unlikely(err < 0))
32319 + for (bindex = 0; bindex <= btail; bindex++) {
32320 + br = au_sbr(sb, bindex);
32321 + if (au_br_rdonly(br))
32323 + if (br->br_wbr->wbr_bytes > watermark) {
32334 + AuDbg("b%d\n", err);
32338 +/* ---------------------------------------------------------------------- */
32340 +/* most free space and then round robin */
32341 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32344 + struct au_wbr_mfs *mfs;
32346 + err = au_wbr_create_mfs(dentry, flags);
32348 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32349 + mutex_lock(&mfs->mfs_lock);
32350 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32351 + err = au_wbr_create_rr(dentry, flags);
32352 + mutex_unlock(&mfs->mfs_lock);
32355 + AuDbg("b%d\n", err);
32359 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32363 + au_wbr_create_init_mfs(sb); /* ignore */
32364 + err = au_wbr_create_init_rr(sb);
32369 +/* ---------------------------------------------------------------------- */
32371 +/* top down parent and most free space */
32372 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32375 + unsigned long long b;
32376 + aufs_bindex_t bindex, btop, bbot;
32377 + struct super_block *sb;
32378 + struct dentry *parent, *h_parent;
32379 + struct au_branch *br;
32381 + err = au_wbr_create_tdp(dentry, flags);
32382 + if (unlikely(err < 0))
32384 + parent = dget_parent(dentry);
32385 + btop = au_dbtop(parent);
32386 + bbot = au_dbtaildir(parent);
32387 + if (btop == bbot)
32388 + goto out_parent; /* success */
32390 + e2 = au_wbr_create_mfs(dentry, flags);
32392 + goto out_parent; /* success */
32394 + /* when the available size is equal, select upper one */
32395 + sb = dentry->d_sb;
32396 + br = au_sbr(sb, err);
32397 + b = br->br_wbr->wbr_bytes;
32398 + AuDbg("b%d, %llu\n", err, b);
32400 + for (bindex = btop; bindex <= bbot; bindex++) {
32401 + h_parent = au_h_dptr(parent, bindex);
32402 + if (!h_parent || d_is_negative(h_parent))
32405 + br = au_sbr(sb, bindex);
32406 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32407 + b = br->br_wbr->wbr_bytes;
32409 + AuDbg("b%d, %llu\n", err, b);
32414 + err = au_wbr_nonopq(dentry, err);
32419 + AuDbg("b%d\n", err);
32423 +/* ---------------------------------------------------------------------- */
32426 + * - top down parent
32427 + * - most free space with parent
32428 + * - most free space round-robin regardless parent
32430 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32433 + unsigned long long watermark;
32434 + struct super_block *sb;
32435 + struct au_branch *br;
32436 + struct au_wbr_mfs *mfs;
32438 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32439 + if (unlikely(err < 0))
32442 + sb = dentry->d_sb;
32443 + br = au_sbr(sb, err);
32444 + mfs = &au_sbi(sb)->si_wbr_mfs;
32445 + mutex_lock(&mfs->mfs_lock);
32446 + watermark = mfs->mfsrr_watermark;
32447 + mutex_unlock(&mfs->mfs_lock);
32448 + if (br->br_wbr->wbr_bytes < watermark)
32449 + /* regardless the parent dir */
32450 + err = au_wbr_create_mfsrr(dentry, flags);
32453 + AuDbg("b%d\n", err);
32457 +/* ---------------------------------------------------------------------- */
32459 +/* policies for copyup */
32461 +/* top down parent */
32462 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32464 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32467 +/* bottom up parent */
32468 +static int au_wbr_copyup_bup(struct dentry *dentry)
32471 + aufs_bindex_t bindex, btop;
32472 + struct dentry *parent, *h_parent;
32473 + struct super_block *sb;
32476 + sb = dentry->d_sb;
32477 + parent = dget_parent(dentry);
32478 + btop = au_dbtop(parent);
32479 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32480 + h_parent = au_h_dptr(parent, bindex);
32481 + if (!h_parent || d_is_negative(h_parent))
32484 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32491 + /* bottom up here */
32492 + if (unlikely(err < 0))
32493 + err = au_wbr_bu(sb, btop - 1);
32495 + AuDbg("b%d\n", err);
32500 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32504 + err = au_wbr_bu(dentry->d_sb, btop);
32505 + AuDbg("b%d\n", err);
32507 + err = au_wbr_nonopq(dentry, err);
32509 + AuDbg("b%d\n", err);
32513 +static int au_wbr_copyup_bu(struct dentry *dentry)
32516 + aufs_bindex_t btop;
32518 + btop = au_dbtop(dentry);
32519 + err = au_wbr_do_copyup_bu(dentry, btop);
32523 +/* ---------------------------------------------------------------------- */
32525 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32526 + [AuWbrCopyup_TDP] = {
32527 + .copyup = au_wbr_copyup_tdp
32529 + [AuWbrCopyup_BUP] = {
32530 + .copyup = au_wbr_copyup_bup
32532 + [AuWbrCopyup_BU] = {
32533 + .copyup = au_wbr_copyup_bu
32537 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32538 + [AuWbrCreate_TDP] = {
32539 + .create = au_wbr_create_tdp
32541 + [AuWbrCreate_RR] = {
32542 + .create = au_wbr_create_rr,
32543 + .init = au_wbr_create_init_rr
32545 + [AuWbrCreate_MFS] = {
32546 + .create = au_wbr_create_mfs,
32547 + .init = au_wbr_create_init_mfs,
32548 + .fin = au_wbr_create_fin_mfs
32550 + [AuWbrCreate_MFSV] = {
32551 + .create = au_wbr_create_mfs,
32552 + .init = au_wbr_create_init_mfs,
32553 + .fin = au_wbr_create_fin_mfs
32555 + [AuWbrCreate_MFSRR] = {
32556 + .create = au_wbr_create_mfsrr,
32557 + .init = au_wbr_create_init_mfsrr,
32558 + .fin = au_wbr_create_fin_mfs
32560 + [AuWbrCreate_MFSRRV] = {
32561 + .create = au_wbr_create_mfsrr,
32562 + .init = au_wbr_create_init_mfsrr,
32563 + .fin = au_wbr_create_fin_mfs
32565 + [AuWbrCreate_TDMFS] = {
32566 + .create = au_wbr_create_tdmfs,
32567 + .init = au_wbr_create_init_mfs,
32568 + .fin = au_wbr_create_fin_mfs
32570 + [AuWbrCreate_TDMFSV] = {
32571 + .create = au_wbr_create_tdmfs,
32572 + .init = au_wbr_create_init_mfs,
32573 + .fin = au_wbr_create_fin_mfs
32575 + [AuWbrCreate_PMFS] = {
32576 + .create = au_wbr_create_pmfs,
32577 + .init = au_wbr_create_init_mfs,
32578 + .fin = au_wbr_create_fin_mfs
32580 + [AuWbrCreate_PMFSV] = {
32581 + .create = au_wbr_create_pmfs,
32582 + .init = au_wbr_create_init_mfs,
32583 + .fin = au_wbr_create_fin_mfs
32585 + [AuWbrCreate_PMFSRR] = {
32586 + .create = au_wbr_create_pmfsrr,
32587 + .init = au_wbr_create_init_mfsrr,
32588 + .fin = au_wbr_create_fin_mfs
32590 + [AuWbrCreate_PMFSRRV] = {
32591 + .create = au_wbr_create_pmfsrr,
32592 + .init = au_wbr_create_init_mfsrr,
32593 + .fin = au_wbr_create_fin_mfs
32596 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32597 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32598 +++ linux/fs/aufs/whout.c 2017-03-02 14:24:13.870255912 +0100
32601 + * Copyright (C) 2005-2017 Junjiro R. Okajima
32603 + * This program, aufs is free software; you can redistribute it and/or modify
32604 + * it under the terms of the GNU General Public License as published by
32605 + * the Free Software Foundation; either version 2 of the License, or
32606 + * (at your option) any later version.
32608 + * This program is distributed in the hope that it will be useful,
32609 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32610 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32611 + * GNU General Public License for more details.
32613 + * You should have received a copy of the GNU General Public License
32614 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32618 + * whiteout for logical deletion and opaque directory
32623 +#define WH_MASK S_IRUGO
32626 + * If a directory contains this file, then it is opaque. We start with the
32627 + * .wh. flag so that it is blocked by lookup.
32629 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32630 + sizeof(AUFS_WH_DIROPQ) - 1);
32633 + * generate whiteout name, which is NOT terminated by NULL.
32634 + * @name: original d_name.name
32635 + * @len: original d_name.len
32636 + * @wh: whiteout qstr
32637 + * returns zero when succeeds, otherwise error.
32638 + * succeeded value as wh->name should be freed by kfree().
32640 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32644 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32645 + return -ENAMETOOLONG;
32647 + wh->len = name->len + AUFS_WH_PFX_LEN;
32648 + p = kmalloc(wh->len, GFP_NOFS);
32651 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32652 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32659 +/* ---------------------------------------------------------------------- */
32662 + * test if the @wh_name exists under @h_parent.
32663 + * @try_sio specifies the necessary of super-io.
32665 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32668 + struct dentry *wh_dentry;
32671 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32673 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32674 + err = PTR_ERR(wh_dentry);
32675 + if (IS_ERR(wh_dentry)) {
32676 + if (err == -ENAMETOOLONG)
32682 + if (d_is_negative(wh_dentry))
32683 + goto out_wh; /* success */
32686 + if (d_is_reg(wh_dentry))
32687 + goto out_wh; /* success */
32690 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32691 + wh_dentry, d_inode(wh_dentry)->i_mode);
32700 + * test if the @h_dentry sets opaque or not.
32702 +int au_diropq_test(struct dentry *h_dentry)
32705 + struct inode *h_dir;
32707 + h_dir = d_inode(h_dentry);
32708 + err = au_wh_test(h_dentry, &diropq_name,
32709 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32714 + * returns a negative dentry whose name is unique and temporary.
32716 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32717 + struct qstr *prefix)
32719 + struct dentry *dentry;
32721 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32723 + /* strict atomic_t is unnecessary here */
32724 + static unsigned short cnt;
32727 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32730 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32731 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32732 + dentry = ERR_PTR(-ENAMETOOLONG);
32733 + if (unlikely(qs.len > NAME_MAX))
32735 + dentry = ERR_PTR(-ENOMEM);
32736 + name = kmalloc(qs.len + 1, GFP_NOFS);
32737 + if (unlikely(!name))
32741 + /* doubly whiteout-ed */
32742 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32743 + p = name + AUFS_WH_PFX_LEN * 2;
32744 + memcpy(p, prefix->name, prefix->len);
32745 + p += prefix->len;
32747 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32750 + for (i = 0; i < 3; i++) {
32751 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32752 + dentry = au_sio_lkup_one(&qs, h_parent);
32753 + if (IS_ERR(dentry) || d_is_negative(dentry))
32757 + /* pr_warn("could not get random name\n"); */
32758 + dentry = ERR_PTR(-EEXIST);
32759 + AuDbg("%.*s\n", AuLNPair(&qs));
32763 + if (name != defname)
32764 + au_delayed_kfree(name);
32766 + AuTraceErrPtr(dentry);
32771 + * rename the @h_dentry on @br to the whiteouted temporary name.
32773 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32776 + struct path h_path = {
32777 + .mnt = au_br_mnt(br)
32779 + struct inode *h_dir, *delegated;
32780 + struct dentry *h_parent;
32782 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32783 + h_dir = d_inode(h_parent);
32784 + IMustLock(h_dir);
32786 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32787 + err = PTR_ERR(h_path.dentry);
32788 + if (IS_ERR(h_path.dentry))
32791 + /* under the same dir, no need to lock_rename() */
32792 + delegated = NULL;
32793 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
32796 + if (unlikely(err == -EWOULDBLOCK)) {
32797 + pr_warn("cannot retry for NFSv4 delegation"
32798 + " for an internal rename\n");
32801 + dput(h_path.dentry);
32808 +/* ---------------------------------------------------------------------- */
32810 + * functions for removing a whiteout
32813 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32816 + struct inode *delegated;
32819 + * forces superio when the dir has a sticky bit.
32820 + * this may be a violation of unix fs semantics.
32822 + force = (h_dir->i_mode & S_ISVTX)
32823 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32824 + delegated = NULL;
32825 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32826 + if (unlikely(err == -EWOULDBLOCK)) {
32827 + pr_warn("cannot retry for NFSv4 delegation"
32828 + " for an internal unlink\n");
32834 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32835 + struct dentry *dentry)
32839 + err = do_unlink_wh(h_dir, h_path);
32840 + if (!err && dentry)
32841 + au_set_dbwh(dentry, -1);
32846 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32847 + struct au_branch *br)
32850 + struct path h_path = {
32851 + .mnt = au_br_mnt(br)
32855 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32856 + if (IS_ERR(h_path.dentry))
32857 + err = PTR_ERR(h_path.dentry);
32859 + if (d_is_reg(h_path.dentry))
32860 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32861 + dput(h_path.dentry);
32867 +/* ---------------------------------------------------------------------- */
32869 + * initialize/clean whiteout for a branch
32872 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32876 + struct inode *delegated;
32878 + if (d_is_negative(whpath->dentry))
32882 + err = vfsub_rmdir(h_dir, whpath);
32884 + delegated = NULL;
32885 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32886 + if (unlikely(err == -EWOULDBLOCK)) {
32887 + pr_warn("cannot retry for NFSv4 delegation"
32888 + " for an internal unlink\n");
32892 + if (unlikely(err))
32893 + pr_warn("failed removing %pd (%d), ignored.\n",
32894 + whpath->dentry, err);
32897 +static int test_linkable(struct dentry *h_root)
32899 + struct inode *h_dir = d_inode(h_root);
32901 + if (h_dir->i_op->link)
32904 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32905 + h_root, au_sbtype(h_root->d_sb));
32909 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32910 +static int au_whdir(struct inode *h_dir, struct path *path)
32915 + if (d_is_negative(path->dentry)) {
32916 + int mode = S_IRWXU;
32918 + if (au_test_nfs(path->dentry->d_sb))
32920 + err = vfsub_mkdir(h_dir, path, mode);
32921 + } else if (d_is_dir(path->dentry))
32924 + pr_err("unknown %pd exists\n", path->dentry);
32929 +struct au_wh_base {
32930 + const struct qstr *name;
32931 + struct dentry *dentry;
32934 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32935 + struct path *h_path)
32937 + h_path->dentry = base[AuBrWh_BASE].dentry;
32938 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32939 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32940 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32941 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32942 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32946 + * returns tri-state,
32947 + * minus: error, caller should print the message
32949 + * plus: error, caller should NOT print the message
32951 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32952 + int do_plink, struct au_wh_base base[],
32953 + struct path *h_path)
32956 + struct inode *h_dir;
32958 + h_dir = d_inode(h_root);
32959 + h_path->dentry = base[AuBrWh_BASE].dentry;
32960 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32961 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32963 + err = test_linkable(h_root);
32964 + if (unlikely(err)) {
32969 + err = au_whdir(h_dir, h_path);
32970 + if (unlikely(err))
32972 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32974 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32975 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32976 + err = au_whdir(h_dir, h_path);
32977 + if (unlikely(err))
32979 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32986 + * for the moment, aufs supports the branch filesystem which does not support
32987 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32988 + * copyup failed. finally, such filesystem will not be used as the writable
32991 + * returns tri-state, see above.
32993 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32994 + int do_plink, struct au_wh_base base[],
32995 + struct path *h_path)
32998 + struct inode *h_dir;
33000 + WbrWhMustWriteLock(wbr);
33002 + err = test_linkable(h_root);
33003 + if (unlikely(err)) {
33009 + * todo: should this create be done in /sbin/mount.aufs helper?
33012 + h_dir = d_inode(h_root);
33013 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33014 + h_path->dentry = base[AuBrWh_BASE].dentry;
33015 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33016 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33019 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33020 + if (unlikely(err))
33023 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33025 + err = au_whdir(h_dir, h_path);
33026 + if (unlikely(err))
33028 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33030 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33031 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33033 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33034 + err = au_whdir(h_dir, h_path);
33035 + if (unlikely(err))
33037 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33044 + * initialize the whiteout base file/dir for @br.
33046 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33049 + const unsigned char do_plink
33050 + = !!au_opt_test(au_mntflags(sb), PLINK);
33051 + struct inode *h_dir;
33052 + struct path path = br->br_path;
33053 + struct dentry *h_root = path.dentry;
33054 + struct au_wbr *wbr = br->br_wbr;
33055 + static const struct qstr base_name[] = {
33056 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33057 + sizeof(AUFS_BASE_NAME) - 1),
33058 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33059 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33060 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33061 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33063 + struct au_wh_base base[] = {
33064 + [AuBrWh_BASE] = {
33065 + .name = base_name + AuBrWh_BASE,
33068 + [AuBrWh_PLINK] = {
33069 + .name = base_name + AuBrWh_PLINK,
33072 + [AuBrWh_ORPH] = {
33073 + .name = base_name + AuBrWh_ORPH,
33079 + WbrWhMustWriteLock(wbr);
33081 + for (i = 0; i < AuBrWh_Last; i++) {
33082 + /* doubly whiteouted */
33083 + struct dentry *d;
33085 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33086 + err = PTR_ERR(d);
33090 + base[i].dentry = d;
33092 + && wbr->wbr_wh[i]
33093 + && wbr->wbr_wh[i] != base[i].dentry);
33097 + for (i = 0; i < AuBrWh_Last; i++) {
33098 + dput(wbr->wbr_wh[i]);
33099 + wbr->wbr_wh[i] = NULL;
33103 + if (!au_br_writable(br->br_perm)) {
33104 + h_dir = d_inode(h_root);
33105 + au_wh_init_ro(h_dir, base, &path);
33106 + } else if (!au_br_wh_linkable(br->br_perm)) {
33107 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33113 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33119 + goto out; /* success */
33122 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33123 + err, h_root, au_sbtype(h_root->d_sb));
33125 + for (i = 0; i < AuBrWh_Last; i++)
33126 + dput(base[i].dentry);
33130 +/* ---------------------------------------------------------------------- */
33132 + * whiteouts are all hard-linked usually.
33133 + * when its link count reaches a ceiling, we create a new whiteout base
33134 + * asynchronously.
33137 +struct reinit_br_wh {
33138 + struct super_block *sb;
33139 + struct au_branch *br;
33142 +static void reinit_br_wh(void *arg)
33145 + aufs_bindex_t bindex;
33146 + struct path h_path;
33147 + struct reinit_br_wh *a = arg;
33148 + struct au_wbr *wbr;
33149 + struct inode *dir, *delegated;
33150 + struct dentry *h_root;
33151 + struct au_hinode *hdir;
33154 + wbr = a->br->br_wbr;
33155 + /* big aufs lock */
33156 + si_noflush_write_lock(a->sb);
33157 + if (!au_br_writable(a->br->br_perm))
33159 + bindex = au_br_index(a->sb, a->br->br_id);
33160 + if (unlikely(bindex < 0))
33163 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33164 + dir = d_inode(a->sb->s_root);
33165 + hdir = au_hi(dir, bindex);
33166 + h_root = au_h_dptr(a->sb->s_root, bindex);
33167 + AuDebugOn(h_root != au_br_dentry(a->br));
33169 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33170 + wbr_wh_write_lock(wbr);
33171 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33174 + h_path.dentry = wbr->wbr_whbase;
33175 + h_path.mnt = au_br_mnt(a->br);
33176 + delegated = NULL;
33177 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33179 + if (unlikely(err == -EWOULDBLOCK)) {
33180 + pr_warn("cannot retry for NFSv4 delegation"
33181 + " for an internal unlink\n");
33185 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33188 + dput(wbr->wbr_whbase);
33189 + wbr->wbr_whbase = NULL;
33191 + err = au_wh_init(a->br, a->sb);
33192 + wbr_wh_write_unlock(wbr);
33193 + au_hn_inode_unlock(hdir);
33194 + di_read_unlock(a->sb->s_root, AuLock_IR);
33196 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33200 + atomic_dec(&wbr->wbr_wh_running);
33201 + au_br_put(a->br);
33202 + si_write_unlock(a->sb);
33203 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33204 + au_delayed_kfree(arg);
33205 + if (unlikely(err))
33206 + AuIOErr("err %d\n", err);
33209 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33211 + int do_dec, wkq_err;
33212 + struct reinit_br_wh *arg;
33215 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33218 + /* ignore ENOMEM */
33219 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33222 + * dec(wh_running), kfree(arg) and dec(br_count)
33223 + * in reinit function
33228 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33229 + if (unlikely(wkq_err)) {
33230 + atomic_dec(&br->br_wbr->wbr_wh_running);
33232 + au_delayed_kfree(arg);
33239 + atomic_dec(&br->br_wbr->wbr_wh_running);
33242 +/* ---------------------------------------------------------------------- */
33245 + * create the whiteout @wh.
33247 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33248 + struct dentry *wh)
33251 + struct path h_path = {
33254 + struct au_branch *br;
33255 + struct au_wbr *wbr;
33256 + struct dentry *h_parent;
33257 + struct inode *h_dir, *delegated;
33259 + h_parent = wh->d_parent; /* dir inode is locked */
33260 + h_dir = d_inode(h_parent);
33261 + IMustLock(h_dir);
33263 + br = au_sbr(sb, bindex);
33264 + h_path.mnt = au_br_mnt(br);
33265 + wbr = br->br_wbr;
33266 + wbr_wh_read_lock(wbr);
33267 + if (wbr->wbr_whbase) {
33268 + delegated = NULL;
33269 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33270 + if (unlikely(err == -EWOULDBLOCK)) {
33271 + pr_warn("cannot retry for NFSv4 delegation"
33272 + " for an internal link\n");
33275 + if (!err || err != -EMLINK)
33278 + /* link count full. re-initialize br_whbase. */
33279 + kick_reinit_br_wh(sb, br);
33282 + /* return this error in this context */
33283 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33285 + au_fhsm_wrote(sb, bindex, /*force*/0);
33288 + wbr_wh_read_unlock(wbr);
33292 +/* ---------------------------------------------------------------------- */
33295 + * create or remove the diropq.
33297 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33298 + unsigned int flags)
33300 + struct dentry *opq_dentry, *h_dentry;
33301 + struct super_block *sb;
33302 + struct au_branch *br;
33305 + sb = dentry->d_sb;
33306 + br = au_sbr(sb, bindex);
33307 + h_dentry = au_h_dptr(dentry, bindex);
33308 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33309 + if (IS_ERR(opq_dentry))
33312 + if (au_ftest_diropq(flags, CREATE)) {
33313 + err = link_or_create_wh(sb, bindex, opq_dentry);
33315 + au_set_dbdiropq(dentry, bindex);
33316 + goto out; /* success */
33319 + struct path tmp = {
33320 + .dentry = opq_dentry,
33321 + .mnt = au_br_mnt(br)
33323 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33325 + au_set_dbdiropq(dentry, -1);
33327 + dput(opq_dentry);
33328 + opq_dentry = ERR_PTR(err);
33331 + return opq_dentry;
33334 +struct do_diropq_args {
33335 + struct dentry **errp;
33336 + struct dentry *dentry;
33337 + aufs_bindex_t bindex;
33338 + unsigned int flags;
33341 +static void call_do_diropq(void *args)
33343 + struct do_diropq_args *a = args;
33344 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33347 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33348 + unsigned int flags)
33350 + struct dentry *diropq, *h_dentry;
33352 + h_dentry = au_h_dptr(dentry, bindex);
33353 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33354 + diropq = do_diropq(dentry, bindex, flags);
33357 + struct do_diropq_args args = {
33359 + .dentry = dentry,
33360 + .bindex = bindex,
33364 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33365 + if (unlikely(wkq_err))
33366 + diropq = ERR_PTR(wkq_err);
33372 +/* ---------------------------------------------------------------------- */
33375 + * lookup whiteout dentry.
33376 + * @h_parent: lower parent dentry which must exist and be locked
33377 + * @base_name: name of dentry which will be whiteouted
33378 + * returns dentry for whiteout.
33380 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33381 + struct au_branch *br)
33384 + struct qstr wh_name;
33385 + struct dentry *wh_dentry;
33387 + err = au_wh_name_alloc(&wh_name, base_name);
33388 + wh_dentry = ERR_PTR(err);
33390 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33391 + au_delayed_kfree(wh_name.name);
33393 + return wh_dentry;
33397 + * link/create a whiteout for @dentry on @bindex.
33399 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33400 + struct dentry *h_parent)
33402 + struct dentry *wh_dentry;
33403 + struct super_block *sb;
33406 + sb = dentry->d_sb;
33407 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33408 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33409 + err = link_or_create_wh(sb, bindex, wh_dentry);
33411 + au_set_dbwh(dentry, bindex);
33412 + au_fhsm_wrote(sb, bindex, /*force*/0);
33415 + wh_dentry = ERR_PTR(err);
33419 + return wh_dentry;
33422 +/* ---------------------------------------------------------------------- */
33424 +/* Delete all whiteouts in this directory on branch bindex. */
33425 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33426 + aufs_bindex_t bindex, struct au_branch *br)
33429 + unsigned long ul, n;
33430 + struct qstr wh_name;
33432 + struct hlist_head *head;
33433 + struct au_vdir_wh *pos;
33434 + struct au_vdir_destr *str;
33437 + p = (void *)__get_free_page(GFP_NOFS);
33438 + wh_name.name = p;
33439 + if (unlikely(!wh_name.name))
33443 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33444 + p += AUFS_WH_PFX_LEN;
33445 + n = whlist->nh_num;
33446 + head = whlist->nh_head;
33447 + for (ul = 0; !err && ul < n; ul++, head++) {
33448 + hlist_for_each_entry(pos, head, wh_hash) {
33449 + if (pos->wh_bindex != bindex)
33452 + str = &pos->wh_str;
33453 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33454 + memcpy(p, str->name, str->len);
33455 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33456 + err = unlink_wh_name(h_dentry, &wh_name, br);
33461 + AuIOErr("whiteout name too long %.*s\n",
33462 + str->len, str->name);
33467 + au_delayed_free_page((unsigned long)wh_name.name);
33473 +struct del_wh_children_args {
33475 + struct dentry *h_dentry;
33476 + struct au_nhash *whlist;
33477 + aufs_bindex_t bindex;
33478 + struct au_branch *br;
33481 +static void call_del_wh_children(void *args)
33483 + struct del_wh_children_args *a = args;
33484 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33487 +/* ---------------------------------------------------------------------- */
33489 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33491 + struct au_whtmp_rmdir *whtmp;
33493 + unsigned int rdhash;
33495 + SiMustAnyLock(sb);
33497 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33498 + if (unlikely(!whtmp)) {
33499 + whtmp = ERR_PTR(-ENOMEM);
33503 + /* no estimation for dir size */
33504 + rdhash = au_sbi(sb)->si_rdhash;
33506 + rdhash = AUFS_RDHASH_DEF;
33507 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33508 + if (unlikely(err)) {
33509 + au_delayed_kfree(whtmp);
33510 + whtmp = ERR_PTR(err);
33517 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33520 + au_br_put(whtmp->br);
33521 + dput(whtmp->wh_dentry);
33522 + iput(whtmp->dir);
33523 + au_nhash_wh_free(&whtmp->whlist);
33524 + au_delayed_kfree(whtmp);
33528 + * rmdir the whiteouted temporary named dir @h_dentry.
33529 + * @whlist: whiteouted children.
33531 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33532 + struct dentry *wh_dentry, struct au_nhash *whlist)
33535 + unsigned int h_nlink;
33536 + struct path h_tmp;
33537 + struct inode *wh_inode, *h_dir;
33538 + struct au_branch *br;
33540 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33541 + IMustLock(h_dir);
33543 + br = au_sbr(dir->i_sb, bindex);
33544 + wh_inode = d_inode(wh_dentry);
33545 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33548 + * someone else might change some whiteouts while we were sleeping.
33549 + * it means this whlist may have an obsoleted entry.
33551 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33552 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33555 + struct del_wh_children_args args = {
33557 + .h_dentry = wh_dentry,
33558 + .whlist = whlist,
33559 + .bindex = bindex,
33563 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33564 + if (unlikely(wkq_err))
33567 + inode_unlock(wh_inode);
33570 + h_tmp.dentry = wh_dentry;
33571 + h_tmp.mnt = au_br_mnt(br);
33572 + h_nlink = h_dir->i_nlink;
33573 + err = vfsub_rmdir(h_dir, &h_tmp);
33574 + /* some fs doesn't change the parent nlink in some cases */
33575 + h_nlink -= h_dir->i_nlink;
33579 + if (au_ibtop(dir) == bindex) {
33580 + /* todo: dir->i_mutex is necessary */
33581 + au_cpup_attr_timesizes(dir);
33583 + vfsub_drop_nlink(dir);
33585 + return 0; /* success */
33588 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33592 +static void call_rmdir_whtmp(void *args)
33595 + aufs_bindex_t bindex;
33596 + struct au_whtmp_rmdir *a = args;
33597 + struct super_block *sb;
33598 + struct dentry *h_parent;
33599 + struct inode *h_dir;
33600 + struct au_hinode *hdir;
33602 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33603 + /* inode_lock(a->dir); */
33605 + sb = a->dir->i_sb;
33606 + si_read_lock(sb, !AuLock_FLUSH);
33607 + if (!au_br_writable(a->br->br_perm))
33609 + bindex = au_br_index(sb, a->br->br_id);
33610 + if (unlikely(bindex < 0))
33614 + ii_write_lock_parent(a->dir);
33615 + h_parent = dget_parent(a->wh_dentry);
33616 + h_dir = d_inode(h_parent);
33617 + hdir = au_hi(a->dir, bindex);
33618 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33619 + if (unlikely(err))
33621 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33622 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33625 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33626 + au_hn_inode_unlock(hdir);
33627 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33631 + ii_write_unlock(a->dir);
33633 + /* inode_unlock(a->dir); */
33634 + au_whtmp_rmdir_free(a);
33635 + si_read_unlock(sb);
33636 + au_nwt_done(&au_sbi(sb)->si_nowait);
33637 + if (unlikely(err))
33638 + AuIOErr("err %d\n", err);
33641 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33642 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33645 + struct super_block *sb;
33649 + /* all post-process will be done in do_rmdir_whtmp(). */
33651 + args->dir = au_igrab(dir);
33652 + args->br = au_sbr(sb, bindex);
33653 + au_br_get(args->br);
33654 + args->wh_dentry = dget(wh_dentry);
33655 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33656 + if (unlikely(wkq_err)) {
33657 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33658 + au_whtmp_rmdir_free(args);
33661 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33662 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33663 +++ linux/fs/aufs/whout.h 2017-03-02 14:24:13.870255912 +0100
33666 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33668 + * This program, aufs is free software; you can redistribute it and/or modify
33669 + * it under the terms of the GNU General Public License as published by
33670 + * the Free Software Foundation; either version 2 of the License, or
33671 + * (at your option) any later version.
33673 + * This program is distributed in the hope that it will be useful,
33674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33676 + * GNU General Public License for more details.
33678 + * You should have received a copy of the GNU General Public License
33679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33683 + * whiteout for logical deletion and opaque directory
33686 +#ifndef __AUFS_WHOUT_H__
33687 +#define __AUFS_WHOUT_H__
33694 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33695 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33696 +int au_diropq_test(struct dentry *h_dentry);
33698 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33699 + struct qstr *prefix);
33700 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33701 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33702 + struct dentry *dentry);
33703 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33705 +/* diropq flags */
33706 +#define AuDiropq_CREATE 1
33707 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33708 +#define au_fset_diropq(flags, name) \
33709 + do { (flags) |= AuDiropq_##name; } while (0)
33710 +#define au_fclr_diropq(flags, name) \
33711 + do { (flags) &= ~AuDiropq_##name; } while (0)
33713 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33714 + unsigned int flags);
33715 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33716 + struct au_branch *br);
33717 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33718 + struct dentry *h_parent);
33720 +/* real rmdir for the whiteout-ed dir */
33721 +struct au_whtmp_rmdir {
33722 + struct inode *dir;
33723 + struct au_branch *br;
33724 + struct dentry *wh_dentry;
33725 + struct au_nhash whlist;
33728 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33729 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33730 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33731 + struct dentry *wh_dentry, struct au_nhash *whlist);
33732 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33733 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33735 +/* ---------------------------------------------------------------------- */
33737 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33738 + aufs_bindex_t bindex)
33740 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33743 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33745 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33748 +#endif /* __KERNEL__ */
33749 +#endif /* __AUFS_WHOUT_H__ */
33750 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33751 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33752 +++ linux/fs/aufs/wkq.c 2017-03-02 14:24:13.870255912 +0100
33755 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33757 + * This program, aufs is free software; you can redistribute it and/or modify
33758 + * it under the terms of the GNU General Public License as published by
33759 + * the Free Software Foundation; either version 2 of the License, or
33760 + * (at your option) any later version.
33762 + * This program is distributed in the hope that it will be useful,
33763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33765 + * GNU General Public License for more details.
33767 + * You should have received a copy of the GNU General Public License
33768 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33772 + * workqueue for asynchronous/super-io operations
33773 + * todo: try new dredential scheme
33776 +#include <linux/module.h>
33779 +/* internal workqueue named AUFS_WKQ_NAME */
33781 +static struct workqueue_struct *au_wkq;
33783 +struct au_wkinfo {
33784 + struct work_struct wk;
33785 + struct kobject *kobj;
33787 + unsigned int flags; /* see wkq.h */
33789 + au_wkq_func_t func;
33792 + struct completion *comp;
33795 +/* ---------------------------------------------------------------------- */
33797 +static void wkq_func(struct work_struct *wk)
33799 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33801 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33802 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33804 + wkinfo->func(wkinfo->args);
33805 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33806 + complete(wkinfo->comp);
33808 + kobject_put(wkinfo->kobj);
33809 + module_put(THIS_MODULE); /* todo: ?? */
33810 + au_delayed_kfree(wkinfo);
33815 + * Since struct completion is large, try allocating it dynamically.
33817 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33818 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33820 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33822 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33824 + init_completion(*comp);
33825 + wkinfo->comp = *comp;
33831 +static void au_wkq_comp_free(struct completion *comp)
33833 + au_delayed_kfree(comp);
33839 +#define AuWkqCompDeclare(name) \
33840 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33841 + struct completion *comp = &_ ## name
33843 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33845 + wkinfo->comp = *comp;
33849 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33853 +#endif /* 4KSTACKS */
33855 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33857 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33858 + if (au_wkq_test()) {
33859 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33860 + " due to a dead dir by UDBA?\n");
33861 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33864 + au_dbg_verify_kthread();
33866 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33867 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33868 + queue_work(au_wkq, &wkinfo->wk);
33870 + INIT_WORK(&wkinfo->wk, wkq_func);
33871 + schedule_work(&wkinfo->wk);
33876 + * Be careful. It is easy to make deadlock happen.
33877 + * processA: lock, wkq and wait
33878 + * processB: wkq and wait, lock in wkq
33881 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33884 + AuWkqCompDeclare(comp);
33885 + struct au_wkinfo wkinfo = {
33891 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33893 + au_wkq_run(&wkinfo);
33894 + /* no timeout, no interrupt */
33895 + wait_for_completion(wkinfo.comp);
33896 + au_wkq_comp_free(comp);
33897 + destroy_work_on_stack(&wkinfo.wk);
33905 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33906 + * problem in a concurrent umounting.
33908 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33909 + unsigned int flags)
33912 + struct au_wkinfo *wkinfo;
33914 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33917 + * wkq_func() must free this wkinfo.
33918 + * it highly depends upon the implementation of workqueue.
33921 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33923 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33924 + wkinfo->flags = flags & ~AuWkq_WAIT;
33925 + wkinfo->func = func;
33926 + wkinfo->args = args;
33927 + wkinfo->comp = NULL;
33928 + kobject_get(wkinfo->kobj);
33929 + __module_get(THIS_MODULE); /* todo: ?? */
33931 + au_wkq_run(wkinfo);
33934 + au_nwt_done(&au_sbi(sb)->si_nowait);
33940 +/* ---------------------------------------------------------------------- */
33942 +void au_nwt_init(struct au_nowait_tasks *nwt)
33944 + atomic_set(&nwt->nw_len, 0);
33945 + /* smp_mb(); */ /* atomic_set */
33946 + init_waitqueue_head(&nwt->nw_wq);
33949 +void au_wkq_fin(void)
33951 + destroy_workqueue(au_wkq);
33954 +int __init au_wkq_init(void)
33959 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33960 + if (IS_ERR(au_wkq))
33961 + err = PTR_ERR(au_wkq);
33962 + else if (!au_wkq)
33967 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33968 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33969 +++ linux/fs/aufs/wkq.h 2017-03-02 14:24:13.870255912 +0100
33972 + * Copyright (C) 2005-2017 Junjiro R. Okajima
33974 + * This program, aufs is free software; you can redistribute it and/or modify
33975 + * it under the terms of the GNU General Public License as published by
33976 + * the Free Software Foundation; either version 2 of the License, or
33977 + * (at your option) any later version.
33979 + * This program is distributed in the hope that it will be useful,
33980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33982 + * GNU General Public License for more details.
33984 + * You should have received a copy of the GNU General Public License
33985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33989 + * workqueue for asynchronous/super-io operations
33990 + * todo: try new credentials management scheme
33993 +#ifndef __AUFS_WKQ_H__
33994 +#define __AUFS_WKQ_H__
33998 +#include <linux/percpu_counter.h>
34000 +struct super_block;
34002 +/* ---------------------------------------------------------------------- */
34005 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34007 +struct au_nowait_tasks {
34009 + wait_queue_head_t nw_wq;
34012 +/* ---------------------------------------------------------------------- */
34014 +typedef void (*au_wkq_func_t)(void *args);
34017 +#define AuWkq_WAIT 1
34018 +#define AuWkq_NEST (1 << 1)
34019 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34020 +#define au_fset_wkq(flags, name) \
34021 + do { (flags) |= AuWkq_##name; } while (0)
34022 +#define au_fclr_wkq(flags, name) \
34023 + do { (flags) &= ~AuWkq_##name; } while (0)
34025 +#ifndef CONFIG_AUFS_HNOTIFY
34027 +#define AuWkq_NEST 0
34031 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34032 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34033 + unsigned int flags);
34034 +void au_nwt_init(struct au_nowait_tasks *nwt);
34035 +int __init au_wkq_init(void);
34036 +void au_wkq_fin(void);
34038 +/* ---------------------------------------------------------------------- */
34040 +static inline int au_wkq_test(void)
34042 + return current->flags & PF_WQ_WORKER;
34045 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34047 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34050 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34052 + if (atomic_dec_and_test(&nwt->nw_len))
34053 + wake_up_all(&nwt->nw_wq);
34056 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34058 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34062 +#endif /* __KERNEL__ */
34063 +#endif /* __AUFS_WKQ_H__ */
34064 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34065 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34066 +++ linux/fs/aufs/xattr.c 2017-03-02 14:24:13.870255912 +0100
34069 + * Copyright (C) 2014-2017 Junjiro R. Okajima
34071 + * This program, aufs is free software; you can redistribute it and/or modify
34072 + * it under the terms of the GNU General Public License as published by
34073 + * the Free Software Foundation; either version 2 of the License, or
34074 + * (at your option) any later version.
34076 + * This program is distributed in the hope that it will be useful,
34077 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34078 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34079 + * GNU General Public License for more details.
34081 + * You should have received a copy of the GNU General Public License
34082 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34086 + * handling xattr functions
34089 +#include <linux/fs.h>
34090 +#include <linux/posix_acl_xattr.h>
34091 +#include <linux/xattr.h>
34094 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34096 + if (!ignore_flags)
34104 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34109 +#define cmp(brattr, prefix) do { \
34110 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34111 + XATTR_##prefix##_PREFIX_LEN)) { \
34112 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34118 + cmp(SEC, SECURITY);
34119 + cmp(SYS, SYSTEM);
34120 + cmp(TR, TRUSTED);
34124 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34131 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34133 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34134 + char *name, char **buf, unsigned int ignore_flags,
34135 + unsigned int verbose)
34139 + struct inode *h_idst;
34141 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34143 + if (unlikely(err <= 0)) {
34144 + if (err == -ENODATA
34145 + || (err == -EOPNOTSUPP
34146 + && ((ignore_flags & au_xattr_out_of_list)
34147 + || (au_test_nfs_noacl(d_inode(h_src))
34148 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34150 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34153 + if (err && (verbose || au_debug_test()))
34154 + pr_err("%s, err %d\n", name, err);
34158 + /* unlock it temporary */
34159 + h_idst = d_inode(h_dst);
34160 + inode_unlock(h_idst);
34161 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34162 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34163 + if (unlikely(err)) {
34164 + if (verbose || au_debug_test())
34165 + pr_err("%s, err %d\n", name, err);
34166 + err = au_xattr_ignore(err, name, ignore_flags);
34173 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34174 + unsigned int verbose)
34176 + int err, unlocked, acl_access, acl_default;
34178 + struct inode *h_isrc, *h_idst;
34179 + char *value, *p, *o, *e;
34181 + /* try stopping to update the source inode while we are referencing */
34182 + /* there should not be the parent-child relationship between them */
34183 + h_isrc = d_inode(h_src);
34184 + h_idst = d_inode(h_dst);
34185 + inode_unlock(h_idst);
34186 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34187 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34190 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34191 + ssz = vfs_listxattr(h_src, NULL, 0);
34193 + if (unlikely(err < 0)) {
34195 + if (err == -ENODATA
34196 + || err == -EOPNOTSUPP)
34197 + err = 0; /* ignore */
34206 + p = kmalloc(ssz, GFP_NOFS);
34208 + if (unlikely(!p))
34210 + err = vfs_listxattr(h_src, p, ssz);
34212 + inode_unlock(h_isrc);
34214 + AuDbg("err %d, ssz %zd\n", err, ssz);
34215 + if (unlikely(err < 0))
34223 + while (!err && p < e) {
34224 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34225 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34226 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34227 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34229 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34231 + p += strlen(p) + 1;
34234 + ignore_flags |= au_xattr_out_of_list;
34235 + if (!err && !acl_access) {
34236 + err = au_do_cpup_xattr(h_dst, h_src,
34237 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34238 + ignore_flags, verbose);
34241 + if (!err && !acl_default) {
34242 + err = au_do_cpup_xattr(h_dst, h_src,
34243 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34244 + ignore_flags, verbose);
34249 + au_delayed_kfree(value);
34253 + au_delayed_kfree(o);
34256 + inode_unlock(h_isrc);
34261 +/* ---------------------------------------------------------------------- */
34263 +static int au_smack_reentering(struct super_block *sb)
34265 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
34267 + * as a part of lookup, smack_d_instantiate() is called, and it calls
34268 + * i_op->getxattr(). ouch.
34270 + return si_pid_test(sb);
34281 +struct au_lgxattr {
34289 + const char *name;
34296 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34300 + struct path h_path;
34301 + struct super_block *sb;
34303 + sb = dentry->d_sb;
34304 + reenter = au_smack_reentering(sb);
34306 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34307 + if (unlikely(err))
34310 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
34311 + if (unlikely(err))
34313 + if (unlikely(!h_path.dentry))
34314 + /* illegally overlapped or something */
34315 + goto out_di; /* pretending success */
34317 + /* always topmost entry only */
34318 + switch (arg->type) {
34319 + case AU_XATTR_LIST:
34320 + err = vfs_listxattr(h_path.dentry,
34321 + arg->u.list.list, arg->u.list.size);
34323 + case AU_XATTR_GET:
34324 + AuDebugOn(d_is_negative(h_path.dentry));
34325 + err = vfs_getxattr(h_path.dentry,
34326 + arg->u.get.name, arg->u.get.value,
34327 + arg->u.get.size);
34333 + di_read_unlock(dentry, AuLock_IR);
34336 + si_read_unlock(sb);
34342 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34344 + struct au_lgxattr arg = {
34345 + .type = AU_XATTR_LIST,
34352 + return au_lgxattr(dentry, &arg);
34355 +static ssize_t au_getxattr(struct dentry *dentry,
34356 + struct inode *inode __maybe_unused,
34357 + const char *name, void *value, size_t size)
34359 + struct au_lgxattr arg = {
34360 + .type = AU_XATTR_GET,
34368 + return au_lgxattr(dentry, &arg);
34371 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34372 + const char *name, const void *value, size_t size,
34375 + struct au_sxattr arg = {
34376 + .type = AU_XATTR_SET,
34385 + return au_sxattr(dentry, inode, &arg);
34388 +/* ---------------------------------------------------------------------- */
34390 +static int au_xattr_get(const struct xattr_handler *handler,
34391 + struct dentry *dentry, struct inode *inode,
34392 + const char *name, void *buffer, size_t size)
34394 + return au_getxattr(dentry, inode, name, buffer, size);
34397 +static int au_xattr_set(const struct xattr_handler *handler,
34398 + struct dentry *dentry, struct inode *inode,
34399 + const char *name, const void *value, size_t size,
34402 + return au_setxattr(dentry, inode, name, value, size, flags);
34405 +static const struct xattr_handler au_xattr_handler = {
34408 + .get = au_xattr_get,
34409 + .set = au_xattr_set
34412 +static const struct xattr_handler *au_xattr_handlers[] = {
34413 +#ifdef CONFIG_FS_POSIX_ACL
34414 + &posix_acl_access_xattr_handler,
34415 + &posix_acl_default_xattr_handler,
34417 + &au_xattr_handler, /* must be last */
34421 +void au_xattr_init(struct super_block *sb)
34423 + sb->s_xattr = au_xattr_handlers;
34425 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34426 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34427 +++ linux/fs/aufs/xino.c 2017-03-02 14:24:13.870255912 +0100
34430 + * Copyright (C) 2005-2017 Junjiro R. Okajima
34432 + * This program, aufs is free software; you can redistribute it and/or modify
34433 + * it under the terms of the GNU General Public License as published by
34434 + * the Free Software Foundation; either version 2 of the License, or
34435 + * (at your option) any later version.
34437 + * This program is distributed in the hope that it will be useful,
34438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34440 + * GNU General Public License for more details.
34442 + * You should have received a copy of the GNU General Public License
34443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34447 + * external inode number translation table and bitmap
34450 +#include <linux/seq_file.h>
34451 +#include <linux/statfs.h>
34454 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34455 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34459 + mm_segment_t oldfs;
34466 + oldfs = get_fs();
34467 + set_fs(KERNEL_DS);
34469 + /* todo: signal_pending? */
34470 + err = func(file, buf.u, size, pos);
34471 + } while (err == -EAGAIN || err == -EINTR);
34474 +#if 0 /* reserved for future use */
34476 + fsnotify_access(file->f_path.dentry);
34482 +/* ---------------------------------------------------------------------- */
34484 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34485 + size_t size, loff_t *pos);
34487 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34488 + size_t size, loff_t *pos)
34491 + mm_segment_t oldfs;
34494 + const char __user *u;
34497 + const int prevent_endless = 10;
34501 + oldfs = get_fs();
34502 + set_fs(KERNEL_DS);
34504 + err = func(file, buf.u, size, pos);
34505 + if (err == -EINTR
34506 + && !au_wkq_test()
34507 + && fatal_signal_pending(current)) {
34509 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34510 + BUG_ON(err == -EINTR);
34511 + oldfs = get_fs();
34512 + set_fs(KERNEL_DS);
34514 + } while (i++ < prevent_endless
34515 + && (err == -EAGAIN || err == -EINTR));
34518 +#if 0 /* reserved for future use */
34520 + fsnotify_modify(file->f_path.dentry);
34526 +struct do_xino_fwrite_args {
34528 + vfs_writef_t func;
34529 + struct file *file;
34535 +static void call_do_xino_fwrite(void *args)
34537 + struct do_xino_fwrite_args *a = args;
34538 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34541 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34542 + size_t size, loff_t *pos)
34546 + struct do_xino_fwrite_args args = {
34556 + * it breaks RLIMIT_FSIZE and normal user's limit,
34557 + * users should care about quota and real 'filesystem full.'
34559 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34560 + if (unlikely(wkq_err))
34566 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34567 + size_t size, loff_t *pos)
34571 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34573 + err = do_xino_fwrite(func, file, buf, size, pos);
34576 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34581 +/* ---------------------------------------------------------------------- */
34584 + * create a new xinofile at the same place/path as @base_file.
34586 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34588 + struct file *file;
34589 + struct dentry *base, *parent;
34590 + struct inode *dir, *delegated;
34591 + struct qstr *name;
34592 + struct path path;
34595 + base = base_file->f_path.dentry;
34596 + parent = base->d_parent; /* dir inode is locked */
34597 + dir = d_inode(parent);
34600 + file = ERR_PTR(-EINVAL);
34601 + name = &base->d_name;
34602 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34603 + if (IS_ERR(path.dentry)) {
34604 + file = (void *)path.dentry;
34605 + pr_err("%pd lookup err %ld\n",
34606 + base, PTR_ERR(path.dentry));
34610 + /* no need to mnt_want_write() since we call dentry_open() later */
34611 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34612 + if (unlikely(err)) {
34613 + file = ERR_PTR(err);
34614 + pr_err("%pd create err %d\n", base, err);
34618 + path.mnt = base_file->f_path.mnt;
34619 + file = vfsub_dentry_open(&path,
34620 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34621 + /* | __FMODE_NONOTIFY */);
34622 + if (IS_ERR(file)) {
34623 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34627 + delegated = NULL;
34628 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34629 + if (unlikely(err == -EWOULDBLOCK)) {
34630 + pr_warn("cannot retry for NFSv4 delegation"
34631 + " for an internal unlink\n");
34634 + if (unlikely(err)) {
34635 + pr_err("%pd unlink err %d\n", base, err);
34640 + /* no one can touch copy_src xino */
34641 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34642 + if (unlikely(err)) {
34643 + pr_err("%pd copy err %d\n", base, err);
34647 + goto out_dput; /* success */
34651 + file = ERR_PTR(err);
34653 + dput(path.dentry);
34658 +struct au_xino_lock_dir {
34659 + struct au_hinode *hdir;
34660 + struct dentry *parent;
34661 + struct inode *dir;
34664 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34665 + struct au_xino_lock_dir *ldir)
34667 + aufs_bindex_t brid, bindex;
34669 + ldir->hdir = NULL;
34671 + brid = au_xino_brid(sb);
34673 + bindex = au_br_index(sb, brid);
34674 + if (bindex >= 0) {
34675 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34676 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34678 + ldir->parent = dget_parent(xino->f_path.dentry);
34679 + ldir->dir = d_inode(ldir->parent);
34680 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34684 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34687 + au_hn_inode_unlock(ldir->hdir);
34689 + inode_unlock(ldir->dir);
34690 + dput(ldir->parent);
34694 +/* ---------------------------------------------------------------------- */
34696 +/* trucate xino files asynchronously */
34698 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34701 + unsigned long jiffy;
34703 + aufs_bindex_t bi, bbot;
34704 + struct kstatfs *st;
34705 + struct au_branch *br;
34706 + struct file *new_xino, *file;
34707 + struct super_block *h_sb;
34708 + struct au_xino_lock_dir ldir;
34711 + st = kmalloc(sizeof(*st), GFP_NOFS);
34712 + if (unlikely(!st))
34716 + bbot = au_sbbot(sb);
34717 + if (unlikely(bindex < 0 || bbot < bindex))
34719 + br = au_sbr(sb, bindex);
34720 + file = br->br_xino.xi_file;
34724 + err = vfs_statfs(&file->f_path, st);
34725 + if (unlikely(err))
34726 + AuErr1("statfs err %d, ignored\n", err);
34728 + blocks = file_inode(file)->i_blocks;
34729 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34730 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34732 + au_xino_lock_dir(sb, file, &ldir);
34733 + /* mnt_want_write() is unnecessary here */
34734 + new_xino = au_xino_create2(file, file);
34735 + au_xino_unlock_dir(&ldir);
34736 + err = PTR_ERR(new_xino);
34737 + if (IS_ERR(new_xino)) {
34738 + pr_err("err %d, ignored\n", err);
34743 + br->br_xino.xi_file = new_xino;
34745 + h_sb = au_br_sb(br);
34746 + for (bi = 0; bi <= bbot; bi++) {
34747 + if (unlikely(bi == bindex))
34749 + br = au_sbr(sb, bi);
34750 + if (au_br_sb(br) != h_sb)
34753 + fput(br->br_xino.xi_file);
34754 + br->br_xino.xi_file = new_xino;
34755 + get_file(new_xino);
34758 + err = vfs_statfs(&new_xino->f_path, st);
34760 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34761 + bindex, (u64)file_inode(new_xino)->i_blocks,
34762 + st->f_bfree, st->f_blocks);
34763 + if (file_inode(new_xino)->i_blocks < blocks)
34764 + au_sbi(sb)->si_xino_jiffy = jiffy;
34766 + AuErr1("statfs err %d, ignored\n", err);
34769 + au_delayed_kfree(st);
34774 +struct xino_do_trunc_args {
34775 + struct super_block *sb;
34776 + struct au_branch *br;
34779 +static void xino_do_trunc(void *_args)
34781 + struct xino_do_trunc_args *args = _args;
34782 + struct super_block *sb;
34783 + struct au_branch *br;
34784 + struct inode *dir;
34786 + aufs_bindex_t bindex;
34790 + dir = d_inode(sb->s_root);
34793 + si_noflush_write_lock(sb);
34794 + ii_read_lock_parent(dir);
34795 + bindex = au_br_index(sb, br->br_id);
34796 + err = au_xino_trunc(sb, bindex);
34797 + ii_read_unlock(dir);
34798 + if (unlikely(err))
34799 + pr_warn("err b%d, (%d)\n", bindex, err);
34800 + atomic_dec(&br->br_xino_running);
34802 + si_write_unlock(sb);
34803 + au_nwt_done(&au_sbi(sb)->si_nowait);
34804 + au_delayed_kfree(args);
34807 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34810 + struct kstatfs st;
34811 + struct au_sbinfo *sbinfo;
34813 + /* todo: si_xino_expire and the ratio should be customizable */
34814 + sbinfo = au_sbi(sb);
34815 + if (time_before(jiffies,
34816 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34819 + /* truncation border */
34820 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34821 + if (unlikely(err)) {
34822 + AuErr1("statfs err %d, ignored\n", err);
34825 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34831 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34833 + struct xino_do_trunc_args *args;
34836 + if (!xino_trunc_test(sb, br))
34839 + if (atomic_inc_return(&br->br_xino_running) > 1)
34842 + /* lock and kfree() will be called in trunc_xino() */
34843 + args = kmalloc(sizeof(*args), GFP_NOFS);
34844 + if (unlikely(!args)) {
34845 + AuErr1("no memory\n");
34852 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34854 + return; /* success */
34856 + pr_err("wkq %d\n", wkq_err);
34858 + au_delayed_kfree(args);
34861 + atomic_dec(&br->br_xino_running);
34864 +/* ---------------------------------------------------------------------- */
34866 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34867 + ino_t h_ino, ino_t ino)
34873 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34874 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34877 + pos *= sizeof(ino);
34878 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34879 + if (sz == sizeof(ino))
34880 + return 0; /* success */
34882 + AuIOErr("write failed (%zd)\n", sz);
34887 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34888 + * at the position of @h_ino.
34889 + * even if @ino is zero, it is written to the xinofile and means no entry.
34890 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34891 + * try truncating it.
34893 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34897 + unsigned int mnt_flags;
34898 + struct au_branch *br;
34900 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34901 + || ((loff_t)-1) > 0);
34902 + SiMustAnyLock(sb);
34904 + mnt_flags = au_mntflags(sb);
34905 + if (!au_opt_test(mnt_flags, XINO))
34908 + br = au_sbr(sb, bindex);
34909 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34912 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34913 + && au_test_fs_trunc_xino(au_br_sb(br)))
34914 + xino_try_trunc(sb, br);
34915 + return 0; /* success */
34918 + AuIOErr("write failed (%d)\n", err);
34922 +/* ---------------------------------------------------------------------- */
34924 +/* aufs inode number bitmap */
34926 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34927 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34931 + AuDebugOn(bit < 0 || page_bits <= bit);
34932 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34936 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34938 + AuDebugOn(ino < AUFS_FIRST_INO);
34939 + ino -= AUFS_FIRST_INO;
34940 + *pindex = ino / page_bits;
34941 + *bit = ino % page_bits;
34944 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34949 + struct au_sbinfo *sbinfo;
34950 + struct file *xib;
34951 + unsigned long *p;
34953 + sbinfo = au_sbi(sb);
34954 + MtxMustLock(&sbinfo->si_xib_mtx);
34955 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34956 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34958 + if (pindex == sbinfo->si_xib_last_pindex)
34961 + xib = sbinfo->si_xib;
34962 + p = sbinfo->si_xib_buf;
34963 + pos = sbinfo->si_xib_last_pindex;
34964 + pos *= PAGE_SIZE;
34965 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34966 + if (unlikely(sz != PAGE_SIZE))
34970 + pos *= PAGE_SIZE;
34971 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34972 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34974 + memset(p, 0, PAGE_SIZE);
34975 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34977 + if (sz == PAGE_SIZE) {
34978 + sbinfo->si_xib_last_pindex = pindex;
34979 + return 0; /* success */
34983 + AuIOErr1("write failed (%zd)\n", sz);
34990 +/* ---------------------------------------------------------------------- */
34992 +static void au_xib_clear_bit(struct inode *inode)
34995 + unsigned long pindex;
34996 + struct super_block *sb;
34997 + struct au_sbinfo *sbinfo;
34999 + AuDebugOn(inode->i_nlink);
35001 + sb = inode->i_sb;
35002 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35003 + AuDebugOn(page_bits <= bit);
35004 + sbinfo = au_sbi(sb);
35005 + mutex_lock(&sbinfo->si_xib_mtx);
35006 + err = xib_pindex(sb, pindex);
35008 + clear_bit(bit, sbinfo->si_xib_buf);
35009 + sbinfo->si_xib_next_bit = bit;
35011 + mutex_unlock(&sbinfo->si_xib_mtx);
35014 +/* for s_op->delete_inode() */
35015 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35018 + unsigned int mnt_flags;
35019 + aufs_bindex_t bindex, bbot, bi;
35020 + unsigned char try_trunc;
35021 + struct au_iinfo *iinfo;
35022 + struct super_block *sb;
35023 + struct au_hinode *hi;
35024 + struct inode *h_inode;
35025 + struct au_branch *br;
35026 + vfs_writef_t xwrite;
35028 + AuDebugOn(au_is_bad_inode(inode));
35030 + sb = inode->i_sb;
35031 + mnt_flags = au_mntflags(sb);
35032 + if (!au_opt_test(mnt_flags, XINO)
35033 + || inode->i_ino == AUFS_ROOT_INO)
35037 + au_xigen_inc(inode);
35038 + au_xib_clear_bit(inode);
35041 + iinfo = au_ii(inode);
35042 + bindex = iinfo->ii_btop;
35046 + xwrite = au_sbi(sb)->si_xwrite;
35047 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35048 + hi = au_hinode(iinfo, bindex);
35049 + bbot = iinfo->ii_bbot;
35050 + for (; bindex <= bbot; bindex++, hi++) {
35051 + h_inode = hi->hi_inode;
35053 + || (!unlinked && h_inode->i_nlink))
35056 + /* inode may not be revalidated */
35057 + bi = au_br_index(sb, hi->hi_id);
35061 + br = au_sbr(sb, bi);
35062 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35063 + h_inode->i_ino, /*ino*/0);
35064 + if (!err && try_trunc
35065 + && au_test_fs_trunc_xino(au_br_sb(br)))
35066 + xino_try_trunc(sb, br);
35070 +/* get an unused inode number from bitmap */
35071 +ino_t au_xino_new_ino(struct super_block *sb)
35074 + unsigned long *p, pindex, ul, pend;
35075 + struct au_sbinfo *sbinfo;
35076 + struct file *file;
35077 + int free_bit, err;
35079 + if (!au_opt_test(au_mntflags(sb), XINO))
35080 + return iunique(sb, AUFS_FIRST_INO);
35082 + sbinfo = au_sbi(sb);
35083 + mutex_lock(&sbinfo->si_xib_mtx);
35084 + p = sbinfo->si_xib_buf;
35085 + free_bit = sbinfo->si_xib_next_bit;
35086 + if (free_bit < page_bits && !test_bit(free_bit, p))
35087 + goto out; /* success */
35088 + free_bit = find_first_zero_bit(p, page_bits);
35089 + if (free_bit < page_bits)
35090 + goto out; /* success */
35092 + pindex = sbinfo->si_xib_last_pindex;
35093 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35094 + err = xib_pindex(sb, ul);
35095 + if (unlikely(err))
35097 + free_bit = find_first_zero_bit(p, page_bits);
35098 + if (free_bit < page_bits)
35099 + goto out; /* success */
35102 + file = sbinfo->si_xib;
35103 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35104 + for (ul = pindex + 1; ul <= pend; ul++) {
35105 + err = xib_pindex(sb, ul);
35106 + if (unlikely(err))
35108 + free_bit = find_first_zero_bit(p, page_bits);
35109 + if (free_bit < page_bits)
35110 + goto out; /* success */
35115 + set_bit(free_bit, p);
35116 + sbinfo->si_xib_next_bit = free_bit + 1;
35117 + pindex = sbinfo->si_xib_last_pindex;
35118 + mutex_unlock(&sbinfo->si_xib_mtx);
35119 + ino = xib_calc_ino(pindex, free_bit);
35120 + AuDbg("i%lu\n", (unsigned long)ino);
35123 + mutex_unlock(&sbinfo->si_xib_mtx);
35129 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35130 + * at the position of @h_ino.
35131 + * if @ino does not exist and @do_new is true, get new one.
35133 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35139 + struct file *file;
35140 + struct au_sbinfo *sbinfo;
35143 + if (!au_opt_test(au_mntflags(sb), XINO))
35144 + return 0; /* no xino */
35147 + sbinfo = au_sbi(sb);
35149 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35150 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35153 + pos *= sizeof(*ino);
35155 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35156 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35157 + return 0; /* no ino */
35159 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35160 + if (sz == sizeof(*ino))
35161 + return 0; /* success */
35164 + if (unlikely(sz >= 0)) {
35166 + AuIOErr("xino read error (%zd)\n", sz);
35172 +/* ---------------------------------------------------------------------- */
35174 +/* create and set a new xino file */
35176 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35178 + struct file *file;
35179 + struct dentry *h_parent, *d;
35180 + struct inode *h_dir, *inode;
35184 + * at mount-time, and the xino file is the default path,
35185 + * hnotify is disabled so we have no notify events to ignore.
35186 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35188 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35189 + /* | __FMODE_NONOTIFY */,
35190 + S_IRUGO | S_IWUGO);
35191 + if (IS_ERR(file)) {
35193 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35197 + /* keep file count */
35199 + inode = file_inode(file);
35200 + h_parent = dget_parent(file->f_path.dentry);
35201 + h_dir = d_inode(h_parent);
35202 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35203 + /* mnt_want_write() is unnecessary here */
35204 + /* no delegation since it is just created */
35205 + if (inode->i_nlink)
35206 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35208 + inode_unlock(h_dir);
35210 + if (unlikely(err)) {
35212 + pr_err("unlink %s(%d)\n", fname, err);
35217 + d = file->f_path.dentry;
35218 + if (unlikely(sb == d->d_sb)) {
35220 + pr_err("%s must be outside\n", fname);
35223 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35225 + pr_err("xino doesn't support %s(%s)\n",
35226 + fname, au_sbtype(d->d_sb));
35229 + return file; /* success */
35233 + file = ERR_PTR(err);
35238 + * find another branch who is on the same filesystem of the specified
35239 + * branch{@btgt}. search until @bbot.
35241 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35242 + aufs_bindex_t bbot)
35244 + aufs_bindex_t bindex;
35245 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35247 + for (bindex = 0; bindex < btgt; bindex++)
35248 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35250 + for (bindex++; bindex <= bbot; bindex++)
35251 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35256 +/* ---------------------------------------------------------------------- */
35259 + * initialize the xinofile for the specified branch @br
35260 + * at the place/path where @base_file indicates.
35261 + * test whether another branch is on the same filesystem or not,
35262 + * if @do_test is true.
35264 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35265 + struct file *base_file, int do_test)
35269 + aufs_bindex_t bbot, bindex;
35270 + struct au_branch *shared_br, *b;
35271 + struct file *file;
35272 + struct super_block *tgt_sb;
35274 + shared_br = NULL;
35275 + bbot = au_sbbot(sb);
35277 + tgt_sb = au_br_sb(br);
35278 + for (bindex = 0; bindex <= bbot; bindex++) {
35279 + b = au_sbr(sb, bindex);
35280 + if (tgt_sb == au_br_sb(b)) {
35287 + if (!shared_br || !shared_br->br_xino.xi_file) {
35288 + struct au_xino_lock_dir ldir;
35290 + au_xino_lock_dir(sb, base_file, &ldir);
35291 + /* mnt_want_write() is unnecessary here */
35292 + file = au_xino_create2(base_file, NULL);
35293 + au_xino_unlock_dir(&ldir);
35294 + err = PTR_ERR(file);
35295 + if (IS_ERR(file))
35297 + br->br_xino.xi_file = file;
35299 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35300 + get_file(br->br_xino.xi_file);
35303 + ino = AUFS_ROOT_INO;
35304 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35306 + if (unlikely(err)) {
35307 + fput(br->br_xino.xi_file);
35308 + br->br_xino.xi_file = NULL;
35315 +/* ---------------------------------------------------------------------- */
35317 +/* trucate a xino bitmap file */
35320 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35324 + unsigned long pindex;
35325 + loff_t pos, pend;
35326 + struct au_sbinfo *sbinfo;
35327 + vfs_readf_t func;
35329 + unsigned long *p;
35332 + sbinfo = au_sbi(sb);
35333 + MtxMustLock(&sbinfo->si_xib_mtx);
35334 + p = sbinfo->si_xib_buf;
35335 + func = sbinfo->si_xread;
35336 + pend = vfsub_f_size_read(file);
35338 + while (pos < pend) {
35339 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35341 + if (unlikely(sz <= 0))
35345 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35346 + if (unlikely(*ino < AUFS_FIRST_INO))
35349 + xib_calc_bit(*ino, &pindex, &bit);
35350 + AuDebugOn(page_bits <= bit);
35351 + err = xib_pindex(sb, pindex);
35363 +static int xib_restore(struct super_block *sb)
35366 + aufs_bindex_t bindex, bbot;
35370 + page = (void *)__get_free_page(GFP_NOFS);
35371 + if (unlikely(!page))
35375 + bbot = au_sbbot(sb);
35376 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35377 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35378 + err = do_xib_restore
35379 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35381 + AuDbg("b%d\n", bindex);
35382 + au_delayed_free_page((unsigned long)page);
35388 +int au_xib_trunc(struct super_block *sb)
35393 + struct au_xino_lock_dir ldir;
35394 + struct au_sbinfo *sbinfo;
35395 + unsigned long *p;
35396 + struct file *file;
35398 + SiMustWriteLock(sb);
35401 + sbinfo = au_sbi(sb);
35402 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35405 + file = sbinfo->si_xib;
35406 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35409 + au_xino_lock_dir(sb, file, &ldir);
35410 + /* mnt_want_write() is unnecessary here */
35411 + file = au_xino_create2(sbinfo->si_xib, NULL);
35412 + au_xino_unlock_dir(&ldir);
35413 + err = PTR_ERR(file);
35414 + if (IS_ERR(file))
35416 + fput(sbinfo->si_xib);
35417 + sbinfo->si_xib = file;
35419 + p = sbinfo->si_xib_buf;
35420 + memset(p, 0, PAGE_SIZE);
35422 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35423 + if (unlikely(sz != PAGE_SIZE)) {
35425 + AuIOErr("err %d\n", err);
35431 + mutex_lock(&sbinfo->si_xib_mtx);
35432 + /* mnt_want_write() is unnecessary here */
35433 + err = xib_restore(sb);
35434 + mutex_unlock(&sbinfo->si_xib_mtx);
35440 +/* ---------------------------------------------------------------------- */
35443 + * xino mount option handlers
35447 +static void xino_clear_xib(struct super_block *sb)
35449 + struct au_sbinfo *sbinfo;
35451 + SiMustWriteLock(sb);
35453 + sbinfo = au_sbi(sb);
35454 + sbinfo->si_xread = NULL;
35455 + sbinfo->si_xwrite = NULL;
35456 + if (sbinfo->si_xib)
35457 + fput(sbinfo->si_xib);
35458 + sbinfo->si_xib = NULL;
35459 + if (sbinfo->si_xib_buf)
35460 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35461 + sbinfo->si_xib_buf = NULL;
35464 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35468 + struct au_sbinfo *sbinfo;
35469 + struct file *file;
35471 + SiMustWriteLock(sb);
35473 + sbinfo = au_sbi(sb);
35474 + file = au_xino_create2(base, sbinfo->si_xib);
35475 + err = PTR_ERR(file);
35476 + if (IS_ERR(file))
35478 + if (sbinfo->si_xib)
35479 + fput(sbinfo->si_xib);
35480 + sbinfo->si_xib = file;
35481 + sbinfo->si_xread = vfs_readf(file);
35482 + sbinfo->si_xwrite = vfs_writef(file);
35485 + if (!sbinfo->si_xib_buf)
35486 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35487 + if (unlikely(!sbinfo->si_xib_buf))
35490 + sbinfo->si_xib_last_pindex = 0;
35491 + sbinfo->si_xib_next_bit = 0;
35492 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35494 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35495 + PAGE_SIZE, &pos);
35496 + if (unlikely(err != PAGE_SIZE))
35500 + goto out; /* success */
35503 + if (sbinfo->si_xib_buf)
35504 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35505 + sbinfo->si_xib_buf = NULL;
35509 + fput(sbinfo->si_xib);
35510 + sbinfo->si_xib = NULL;
35511 + sbinfo->si_xread = NULL;
35512 + sbinfo->si_xwrite = NULL;
35517 +/* xino for each branch */
35518 +static void xino_clear_br(struct super_block *sb)
35520 + aufs_bindex_t bindex, bbot;
35521 + struct au_branch *br;
35523 + bbot = au_sbbot(sb);
35524 + for (bindex = 0; bindex <= bbot; bindex++) {
35525 + br = au_sbr(sb, bindex);
35526 + if (!br || !br->br_xino.xi_file)
35529 + fput(br->br_xino.xi_file);
35530 + br->br_xino.xi_file = NULL;
35534 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35538 + aufs_bindex_t bindex, bbot, bshared;
35540 + struct file *old, *new;
35542 + struct au_branch *br;
35543 + struct inode *inode;
35544 + vfs_writef_t writef;
35546 + SiMustWriteLock(sb);
35549 + bbot = au_sbbot(sb);
35550 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35551 + if (unlikely(!fpair))
35554 + inode = d_inode(sb->s_root);
35555 + ino = AUFS_ROOT_INO;
35556 + writef = au_sbi(sb)->si_xwrite;
35557 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35558 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35559 + if (bshared >= 0) {
35560 + /* shared xino */
35561 + *p = fpair[bshared];
35562 + get_file(p->new);
35567 + br = au_sbr(sb, bindex);
35568 + p->old = br->br_xino.xi_file;
35569 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35570 + err = PTR_ERR(p->new);
35571 + if (IS_ERR(p->new)) {
35577 + err = au_xino_do_write(writef, p->new,
35578 + au_h_iptr(inode, bindex)->i_ino, ino);
35579 + if (unlikely(err))
35583 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35584 + br = au_sbr(sb, bindex);
35585 + if (br->br_xino.xi_file)
35586 + fput(br->br_xino.xi_file);
35587 + get_file(p->new);
35588 + br->br_xino.xi_file = p->new;
35592 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35597 + au_delayed_kfree(fpair);
35602 +void au_xino_clr(struct super_block *sb)
35604 + struct au_sbinfo *sbinfo;
35606 + au_xigen_clr(sb);
35607 + xino_clear_xib(sb);
35608 + xino_clear_br(sb);
35609 + sbinfo = au_sbi(sb);
35610 + /* lvalue, do not call au_mntflags() */
35611 + au_opt_clr(sbinfo->si_mntflags, XINO);
35614 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35617 + struct dentry *parent, *cur_parent;
35618 + struct qstr *dname, *cur_name;
35619 + struct file *cur_xino;
35620 + struct inode *dir;
35621 + struct au_sbinfo *sbinfo;
35623 + SiMustWriteLock(sb);
35626 + sbinfo = au_sbi(sb);
35627 + parent = dget_parent(xino->file->f_path.dentry);
35630 + dname = &xino->file->f_path.dentry->d_name;
35631 + cur_xino = sbinfo->si_xib;
35633 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35634 + cur_name = &cur_xino->f_path.dentry->d_name;
35635 + skip = (cur_parent == parent
35636 + && au_qstreq(dname, cur_name));
35637 + dput(cur_parent);
35643 + au_opt_set(sbinfo->si_mntflags, XINO);
35644 + dir = d_inode(parent);
35645 + inode_lock_nested(dir, AuLsc_I_PARENT);
35646 + /* mnt_want_write() is unnecessary here */
35647 + err = au_xino_set_xib(sb, xino->file);
35649 + err = au_xigen_set(sb, xino->file);
35651 + err = au_xino_set_br(sb, xino->file);
35652 + inode_unlock(dir);
35654 + goto out; /* success */
35657 + AuIOErr("failed creating xino(%d).\n", err);
35658 + au_xigen_clr(sb);
35659 + xino_clear_xib(sb);
35666 +/* ---------------------------------------------------------------------- */
35669 + * create a xinofile at the default place/path.
35671 +struct file *au_xino_def(struct super_block *sb)
35673 + struct file *file;
35675 + struct au_branch *br;
35676 + struct super_block *h_sb;
35677 + struct path path;
35678 + aufs_bindex_t bbot, bindex, bwr;
35681 + bbot = au_sbbot(sb);
35683 + for (bindex = 0; bindex <= bbot; bindex++) {
35684 + br = au_sbr(sb, bindex);
35685 + if (au_br_writable(br->br_perm)
35686 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35693 + file = ERR_PTR(-ENOMEM);
35694 + page = (void *)__get_free_page(GFP_NOFS);
35695 + if (unlikely(!page))
35697 + path.mnt = au_br_mnt(br);
35698 + path.dentry = au_h_dptr(sb->s_root, bwr);
35699 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35700 + file = (void *)p;
35701 + if (!IS_ERR(p)) {
35702 + strcat(p, "/" AUFS_XINO_FNAME);
35703 + AuDbg("%s\n", p);
35704 + file = au_xino_create(sb, p, /*silent*/0);
35705 + if (!IS_ERR(file))
35706 + au_xino_brid_set(sb, br->br_id);
35708 + au_delayed_free_page((unsigned long)page);
35710 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35711 + if (IS_ERR(file))
35713 + h_sb = file->f_path.dentry->d_sb;
35714 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35715 + pr_err("xino doesn't support %s(%s)\n",
35716 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35718 + file = ERR_PTR(-EINVAL);
35720 + if (!IS_ERR(file))
35721 + au_xino_brid_set(sb, -1);
35728 +/* ---------------------------------------------------------------------- */
35730 +int au_xino_path(struct seq_file *seq, struct file *file)
35734 + err = au_seq_path(seq, &file->f_path);
35735 + if (unlikely(err))
35738 +#define Deleted "\\040(deleted)"
35739 + seq->count -= sizeof(Deleted) - 1;
35740 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35741 + sizeof(Deleted) - 1));
35747 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35748 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35749 +++ linux/include/uapi/linux/aufs_type.h 2017-03-02 14:24:13.870255912 +0100
35752 + * Copyright (C) 2005-2017 Junjiro R. Okajima
35754 + * This program, aufs is free software; you can redistribute it and/or modify
35755 + * it under the terms of the GNU General Public License as published by
35756 + * the Free Software Foundation; either version 2 of the License, or
35757 + * (at your option) any later version.
35759 + * This program is distributed in the hope that it will be useful,
35760 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35761 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35762 + * GNU General Public License for more details.
35764 + * You should have received a copy of the GNU General Public License
35765 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35768 +#ifndef __AUFS_TYPE_H__
35769 +#define __AUFS_TYPE_H__
35771 +#define AUFS_NAME "aufs"
35775 + * define it before including all other headers.
35776 + * sched.h may use pr_* macros before defining "current", so define the
35777 + * no-current version first, and re-define later.
35779 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35780 +#include <linux/sched.h>
35782 +#define pr_fmt(fmt) \
35783 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35784 + (int)sizeof(current->comm), current->comm, current->pid
35786 +#include <stdint.h>
35787 +#include <sys/types.h>
35788 +#endif /* __KERNEL__ */
35790 +#include <linux/limits.h>
35792 +#define AUFS_VERSION "4.x-rcN-20170220"
35794 +/* todo? move this to linux-2.6.19/include/magic.h */
35795 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35797 +/* ---------------------------------------------------------------------- */
35799 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35800 +typedef int8_t aufs_bindex_t;
35801 +#define AUFS_BRANCH_MAX 127
35803 +typedef int16_t aufs_bindex_t;
35804 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35805 +#define AUFS_BRANCH_MAX 511
35806 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35807 +#define AUFS_BRANCH_MAX 1023
35808 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35809 +#define AUFS_BRANCH_MAX 32767
35814 +#ifndef AUFS_BRANCH_MAX
35815 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35817 +#endif /* __KERNEL__ */
35819 +/* ---------------------------------------------------------------------- */
35821 +#define AUFS_FSTYPE AUFS_NAME
35823 +#define AUFS_ROOT_INO 2
35824 +#define AUFS_FIRST_INO 11
35826 +#define AUFS_WH_PFX ".wh."
35827 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35828 +#define AUFS_WH_TMP_LEN 4
35829 +/* a limit for rmdir/rename a dir and copyup */
35830 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35831 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35833 + - AUFS_WH_TMP_LEN) /* hex */
35834 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35835 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35836 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35837 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35838 +#define AUFS_DIRWH_DEF 3
35839 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35840 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35841 +#define AUFS_RDBLK_DEF 512 /* bytes */
35842 +#define AUFS_RDHASH_DEF 32
35843 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35844 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35845 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35846 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35847 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35849 +/* pseudo-link maintenace under /proc */
35850 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35851 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35852 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35854 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35855 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35857 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35858 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35859 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35861 +/* doubly whiteouted */
35862 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35863 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35864 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35866 +/* branch permissions and attributes */
35867 +#define AUFS_BRPERM_RW "rw"
35868 +#define AUFS_BRPERM_RO "ro"
35869 +#define AUFS_BRPERM_RR "rr"
35870 +#define AUFS_BRATTR_COO_REG "coo_reg"
35871 +#define AUFS_BRATTR_COO_ALL "coo_all"
35872 +#define AUFS_BRATTR_FHSM "fhsm"
35873 +#define AUFS_BRATTR_UNPIN "unpin"
35874 +#define AUFS_BRATTR_ICEX "icex"
35875 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35876 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35877 +#define AUFS_BRATTR_ICEX_TR "icextr"
35878 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35879 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35880 +#define AUFS_BRRATTR_WH "wh"
35881 +#define AUFS_BRWATTR_NLWH "nolwh"
35882 +#define AUFS_BRWATTR_MOO "moo"
35884 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35885 +#define AuBrPerm_RO (1 << 1) /* readonly */
35886 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35887 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35889 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35890 +#define AuBrAttr_COO_ALL (1 << 4)
35891 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35893 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35894 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35895 + branch. meaningless since
35896 + linux-3.18-rc1 */
35898 +/* ignore error in copying XATTR */
35899 +#define AuBrAttr_ICEX_SEC (1 << 7)
35900 +#define AuBrAttr_ICEX_SYS (1 << 8)
35901 +#define AuBrAttr_ICEX_TR (1 << 9)
35902 +#define AuBrAttr_ICEX_USR (1 << 10)
35903 +#define AuBrAttr_ICEX_OTH (1 << 11)
35904 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35905 + | AuBrAttr_ICEX_SYS \
35906 + | AuBrAttr_ICEX_TR \
35907 + | AuBrAttr_ICEX_USR \
35908 + | AuBrAttr_ICEX_OTH)
35910 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35911 +#define AuBrRAttr_Mask AuBrRAttr_WH
35913 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35914 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35915 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35917 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35919 +/* #warning test userspace */
35921 +#ifndef CONFIG_AUFS_FHSM
35922 +#undef AuBrAttr_FHSM
35923 +#define AuBrAttr_FHSM 0
35925 +#ifndef CONFIG_AUFS_XATTR
35926 +#undef AuBrAttr_ICEX
35927 +#define AuBrAttr_ICEX 0
35928 +#undef AuBrAttr_ICEX_SEC
35929 +#define AuBrAttr_ICEX_SEC 0
35930 +#undef AuBrAttr_ICEX_SYS
35931 +#define AuBrAttr_ICEX_SYS 0
35932 +#undef AuBrAttr_ICEX_TR
35933 +#define AuBrAttr_ICEX_TR 0
35934 +#undef AuBrAttr_ICEX_USR
35935 +#define AuBrAttr_ICEX_USR 0
35936 +#undef AuBrAttr_ICEX_OTH
35937 +#define AuBrAttr_ICEX_OTH 0
35941 +/* the longest combination */
35942 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35943 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35944 + "+" AUFS_BRATTR_COO_REG \
35945 + "+" AUFS_BRATTR_FHSM \
35946 + "+" AUFS_BRATTR_UNPIN \
35947 + "+" AUFS_BRATTR_ICEX_SEC \
35948 + "+" AUFS_BRATTR_ICEX_SYS \
35949 + "+" AUFS_BRATTR_ICEX_USR \
35950 + "+" AUFS_BRATTR_ICEX_OTH \
35951 + "+" AUFS_BRWATTR_NLWH)
35954 + char a[AuBrPermStrSz];
35955 +} au_br_perm_str_t;
35957 +static inline int au_br_writable(int brperm)
35959 + return brperm & AuBrPerm_RW;
35962 +static inline int au_br_whable(int brperm)
35964 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35967 +static inline int au_br_wh_linkable(int brperm)
35969 + return !(brperm & AuBrWAttr_NoLinkWH);
35972 +static inline int au_br_cmoo(int brperm)
35974 + return brperm & AuBrAttr_CMOO_Mask;
35977 +static inline int au_br_fhsm(int brperm)
35979 + return brperm & AuBrAttr_FHSM;
35982 +/* ---------------------------------------------------------------------- */
35986 + /* readdir in userspace */
35990 + AuCtl_WBR_FD, /* pathconf wrapper */
35991 + AuCtl_IBUSY, /* busy inode */
35992 + AuCtl_MVDOWN, /* move-down */
35993 + AuCtl_BR, /* info about branches */
35994 + AuCtl_FHSM_FD /* connection for fhsm */
35997 +/* borrowed from linux/include/linux/kernel.h */
35999 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36000 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36003 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36005 +#define __aligned(x) __attribute__((aligned(x)))
36010 +#define __packed __attribute__((packed))
36014 +struct au_rdu_cookie {
36019 + uint32_t generation;
36022 +struct au_rdu_ent {
36031 +static inline int au_rdu_len(int nlen)
36033 + /* include the terminating NULL */
36034 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36035 + sizeof(uint64_t));
36038 +union au_rdu_ent_ul {
36039 + struct au_rdu_ent __user *e;
36051 + uint64_t sz; /* AuCtl_RDU */
36052 + uint64_t nent; /* AuCtl_RDU_INO */
36054 + union au_rdu_ent_ul ent;
36055 + uint16_t verify[AufsCtlRduV_End];
36057 + /* input/output */
36061 + union au_rdu_ent_ul tail;
36062 + /* number of entries which were added in a single call */
36067 + struct au_rdu_cookie cookie;
36070 +/* ---------------------------------------------------------------------- */
36072 +struct aufs_wbr_fd {
36077 +/* ---------------------------------------------------------------------- */
36079 +struct aufs_ibusy {
36080 + uint64_t ino, h_ino;
36084 +/* ---------------------------------------------------------------------- */
36086 +/* error code for move-down */
36087 +/* the actual message strings are implemented in aufs-util.git */
36089 + EAU_MVDOWN_OPAQUE = 1,
36090 + EAU_MVDOWN_WHITEOUT,
36091 + EAU_MVDOWN_UPPER,
36092 + EAU_MVDOWN_BOTTOM,
36093 + EAU_MVDOWN_NOUPPER,
36094 + EAU_MVDOWN_NOLOWERBR,
36098 +/* flags for move-down */
36099 +#define AUFS_MVDOWN_DMSG 1
36100 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36101 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36102 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36103 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36104 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36105 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36106 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36107 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36108 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36109 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36110 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36111 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36113 +/* index for move-down */
36115 + AUFS_MVDOWN_UPPER,
36116 + AUFS_MVDOWN_LOWER,
36117 + AUFS_MVDOWN_NARRAY
36121 + * additional info of move-down
36122 + * number of free blocks and inodes.
36123 + * subset of struct kstatfs, but smaller and always 64bit.
36125 +struct aufs_stfs {
36126 + uint64_t f_blocks;
36127 + uint64_t f_bavail;
36128 + uint64_t f_files;
36129 + uint64_t f_ffree;
36132 +struct aufs_stbr {
36133 + int16_t brid; /* optional input */
36134 + int16_t bindex; /* output */
36135 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36138 +struct aufs_mvdown {
36139 + uint32_t flags; /* input/output */
36140 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36141 + int8_t au_errno; /* output */
36144 +/* ---------------------------------------------------------------------- */
36146 +union aufs_brinfo {
36147 + /* PATH_MAX may differ between kernel-space and user-space */
36148 + char _spacer[4096];
36156 +/* ---------------------------------------------------------------------- */
36158 +#define AuCtlType 'A'
36159 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36160 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36161 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36162 + struct aufs_wbr_fd)
36163 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36164 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36165 + struct aufs_mvdown)
36166 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36167 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36169 +#endif /* __AUFS_TYPE_H__ */
36170 aufs4.x-rcN loopback patch
36172 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36173 index b63f68b..c0f4b8c 100644
36174 --- a/drivers/block/loop.c
36175 +++ b/drivers/block/loop.c
36176 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36179 struct switch_request {
36180 - struct file *file;
36181 + struct file *file, *virt_file;
36182 struct completion wait;
36185 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36186 mapping = file->f_mapping;
36187 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36188 lo->lo_backing_file = file;
36189 + lo->lo_backing_virt_file = p->virt_file;
36190 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36191 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36192 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36193 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36194 * First it needs to flush existing IO, it does this by sending a magic
36195 * BIO down the pipe. The completion of this BIO does the actual switch.
36197 -static int loop_switch(struct loop_device *lo, struct file *file)
36198 +static int loop_switch(struct loop_device *lo, struct file *file,
36199 + struct file *virt_file)
36201 struct switch_request w;
36204 + w.virt_file = virt_file;
36206 /* freeze queue and wait for completion of scheduled requests */
36207 blk_mq_freeze_queue(lo->lo_queue);
36208 @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
36210 static int loop_flush(struct loop_device *lo)
36212 - return loop_switch(lo, NULL);
36213 + return loop_switch(lo, NULL, NULL);
36216 +static struct file *loop_real_file(struct file *file)
36218 + struct file *f = NULL;
36220 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36221 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36225 static void loop_reread_partitions(struct loop_device *lo,
36226 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36229 struct file *file, *old_file;
36230 + struct file *f, *virt_file = NULL, *old_virt_file;
36231 struct inode *inode;
36234 @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36238 + f = loop_real_file(file);
36240 + virt_file = file;
36245 inode = file->f_mapping->host;
36246 old_file = lo->lo_backing_file;
36247 + old_virt_file = lo->lo_backing_virt_file;
36251 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36254 /* and ... switch */
36255 - error = loop_switch(lo, file);
36256 + error = loop_switch(lo, file, virt_file);
36261 + if (old_virt_file)
36262 + fput(old_virt_file);
36263 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36264 loop_reread_partitions(lo, bdev);
36274 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36275 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36276 struct block_device *bdev, unsigned int arg)
36278 - struct file *file, *f;
36279 + struct file *file, *f, *virt_file = NULL;
36280 struct inode *inode;
36281 struct address_space *mapping;
36282 unsigned lo_blocksize;
36283 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36287 + f = loop_real_file(file);
36289 + virt_file = file;
36295 if (lo->lo_state != Lo_unbound)
36296 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36297 lo->lo_device = bdev;
36298 lo->lo_flags = lo_flags;
36299 lo->lo_backing_file = file;
36300 + lo->lo_backing_virt_file = virt_file;
36301 lo->transfer = NULL;
36303 lo->lo_sizelimit = 0;
36304 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36311 /* This is safe: open() is still holding a reference. */
36312 module_put(THIS_MODULE);
36313 @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36314 static int loop_clr_fd(struct loop_device *lo)
36316 struct file *filp = lo->lo_backing_file;
36317 + struct file *virt_filp = lo->lo_backing_virt_file;
36318 gfp_t gfp = lo->old_gfp_mask;
36319 struct block_device *bdev = lo->lo_device;
36321 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
36322 spin_lock_irq(&lo->lo_lock);
36323 lo->lo_state = Lo_rundown;
36324 lo->lo_backing_file = NULL;
36325 + lo->lo_backing_virt_file = NULL;
36326 spin_unlock_irq(&lo->lo_lock);
36328 loop_release_xfer(lo);
36329 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
36330 * bd_mutex which is usually taken before lo_ctl_mutex.
36338 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36339 index fb2237c..c3888c5 100644
36340 --- a/drivers/block/loop.h
36341 +++ b/drivers/block/loop.h
36342 @@ -46,7 +46,7 @@ struct loop_device {
36343 int (*ioctl)(struct loop_device *, int cmd,
36344 unsigned long arg);
36346 - struct file * lo_backing_file;
36347 + struct file * lo_backing_file, *lo_backing_virt_file;
36348 struct block_device *lo_device;
36349 unsigned lo_blocksize;
36351 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36352 index 6da0f10..d211f9e 100644
36353 --- a/fs/aufs/f_op.c
36354 +++ b/fs/aufs/f_op.c
36355 @@ -351,7 +351,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36356 if (IS_ERR(h_file))
36359 - if (au_test_loopback_kthread()) {
36360 + if (0 && au_test_loopback_kthread()) {
36361 au_warn_loopback(h_file->f_path.dentry->d_sb);
36362 if (file->f_mapping != h_file->f_mapping) {
36363 file->f_mapping = h_file->f_mapping;
36364 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36365 index 61e9197..9910bea 100644
36366 --- a/fs/aufs/loop.c
36367 +++ b/fs/aufs/loop.c
36368 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36369 symbol_put(loop_backing_file);
36370 au_delayed_kfree(au_warn_loopback_array);
36373 +/* ---------------------------------------------------------------------- */
36375 +/* support the loopback block device insude aufs */
36377 +struct file *aufs_real_loop(struct file *file)
36381 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36382 + fi_read_lock(file);
36383 + f = au_hf_top(file);
36384 + fi_read_unlock(file);
36388 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36389 index e2df495..36e5052 100644
36390 --- a/fs/aufs/loop.h
36391 +++ b/fs/aufs/loop.h
36392 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36394 int au_loopback_init(void);
36395 void au_loopback_fin(void);
36397 +struct file *aufs_real_loop(struct file *file);
36399 +AuStub(struct file *, loop_backing_file, return NULL)
36401 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36402 struct dentry *h_adding)
36403 AuStubInt0(au_test_loopback_kthread, void)
36404 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36406 AuStubInt0(au_loopback_init, void)
36407 AuStubVoid(au_loopback_fin, void)
36409 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36410 #endif /* BLK_DEV_LOOP */
36412 #endif /* __KERNEL__ */
36413 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36414 index 0e9bbc3..b90d52f 100644
36415 --- a/fs/aufs/super.c
36416 +++ b/fs/aufs/super.c
36417 @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = {
36418 .statfs = aufs_statfs,
36419 .put_super = aufs_put_super,
36420 .sync_fs = aufs_sync_fs,
36421 - .remount_fs = aufs_remount_fs
36422 + .remount_fs = aufs_remount_fs,
36423 +#ifdef CONFIG_AUFS_BDEV_LOOP
36424 + .real_loop = aufs_real_loop
36428 /* ---------------------------------------------------------------------- */
36429 diff --git a/include/linux/fs.h b/include/linux/fs.h
36430 index a808c7c..214b51f 100644
36431 --- a/include/linux/fs.h
36432 +++ b/include/linux/fs.h
36433 @@ -1791,6 +1791,10 @@ struct super_operations {
36434 struct shrink_control *);
36435 long (*free_cached_objects)(struct super_block *,
36436 struct shrink_control *);
36437 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36439 + struct file *(*real_loop)(struct file *);