3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 4bd03a2..620e01b 100644
7 @@ -249,6 +249,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index ed2b632..aa6d14b 100644
19 @@ -129,3 +129,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 cd2be1c..78f3c68 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
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 63cefa6..d78b954 100644
42 @@ -2293,6 +2293,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 fa1b7a9..6ee9235 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 5c7cc95..df0268c 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 350a2c8..6f42279 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/namespace.c b/fs/namespace.c
140 index e6c234b..db0b1ac 100644
143 @@ -787,6 +787,12 @@ static inline int check_mnt(struct mount *mnt)
144 return mnt->mnt_ns == current->nsproxy->mnt_ns;
147 +/* for aufs, CONFIG_AUFS_BR_FUSE */
148 +int is_current_mnt_ns(struct vfsmount *mnt)
150 + return check_mnt(real_mount(mnt));
154 * vfsmount lock must be held for write
156 diff --git a/fs/read_write.c b/fs/read_write.c
157 index 190e0d36..4052813 100644
158 --- a/fs/read_write.c
159 +++ b/fs/read_write.c
160 @@ -515,6 +515,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
162 EXPORT_SYMBOL(__vfs_write);
164 +vfs_readf_t vfs_readf(struct file *file)
166 + const struct file_operations *fop = file->f_op;
170 + if (fop->read_iter)
171 + return new_sync_read;
172 + return ERR_PTR(-ENOSYS);
175 +vfs_writef_t vfs_writef(struct file *file)
177 + const struct file_operations *fop = file->f_op;
181 + if (fop->write_iter)
182 + return new_sync_write;
183 + return ERR_PTR(-ENOSYS);
186 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
189 diff --git a/fs/splice.c b/fs/splice.c
190 index 5a7750b..28160a7 100644
193 @@ -855,8 +855,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
195 * Attempt to initiate a splice from pipe to file.
197 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
198 - loff_t *ppos, size_t len, unsigned int flags)
199 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
200 + loff_t *ppos, size_t len, unsigned int flags)
202 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
203 loff_t *, size_t, unsigned int);
204 @@ -872,9 +872,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
206 * Attempt to initiate a splice from a file to a pipe.
208 -static long do_splice_to(struct file *in, loff_t *ppos,
209 - struct pipe_inode_info *pipe, size_t len,
210 - unsigned int flags)
211 +long do_splice_to(struct file *in, loff_t *ppos,
212 + struct pipe_inode_info *pipe, size_t len,
213 + unsigned int flags)
215 ssize_t (*splice_read)(struct file *, loff_t *,
216 struct pipe_inode_info *, size_t, unsigned int);
217 diff --git a/fs/sync.c b/fs/sync.c
218 index 2a54c1f..7a5fa3f 100644
222 * wait == 1 case since in that case write_inode() functions do
223 * sync_dirty_buffer() and thus effectively write one block at a time.
225 -static int __sync_filesystem(struct super_block *sb, int wait)
226 +int __sync_filesystem(struct super_block *sb, int wait)
230 diff --git a/include/linux/file.h b/include/linux/file.h
231 index 7444f5f..bdac0be 100644
232 --- a/include/linux/file.h
233 +++ b/include/linux/file.h
234 @@ -19,6 +19,7 @@ struct dentry;
236 extern struct file *alloc_file(struct path *, fmode_t mode,
237 const struct file_operations *fop);
238 +extern struct file *get_empty_filp(void);
240 static inline void fput_light(struct file *file, int fput_needed)
242 diff --git a/include/linux/fs.h b/include/linux/fs.h
243 index dc0478c..a02be40d 100644
244 --- a/include/linux/fs.h
245 +++ b/include/linux/fs.h
246 @@ -1291,6 +1291,7 @@ extern void fasync_free(struct fasync_struct *);
247 /* can be called from interrupts */
248 extern void kill_fasync(struct fasync_struct **, int, int);
250 +extern int setfl(int fd, struct file * filp, unsigned long arg);
251 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
252 extern void f_setown(struct file *filp, unsigned long arg, int force);
253 extern void f_delown(struct file *filp);
254 @@ -1715,6 +1716,7 @@ struct file_operations {
255 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
256 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
257 int (*check_flags)(int);
258 + int (*setfl)(struct file *, unsigned long);
259 int (*flock) (struct file *, int, struct file_lock *);
260 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
261 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
262 @@ -1768,6 +1770,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
263 struct iovec *fast_pointer,
264 struct iovec **ret_pointer);
266 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
267 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
269 +vfs_readf_t vfs_readf(struct file *file);
270 +vfs_writef_t vfs_writef(struct file *file);
272 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
273 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
274 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
275 @@ -2140,6 +2148,7 @@ extern int current_umask(void);
276 extern void ihold(struct inode * inode);
277 extern void iput(struct inode *);
278 extern int generic_update_time(struct inode *, struct timespec *, int);
279 +extern int update_time(struct inode *, struct timespec *, int);
282 extern struct kobject *fs_kobj;
283 @@ -2419,6 +2428,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
287 +extern int __sync_filesystem(struct super_block *, int);
288 extern int sync_filesystem(struct super_block *);
289 extern const struct file_operations def_blk_fops;
290 extern const struct file_operations def_chr_fops;
291 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
292 index 12b2ab5..8b810d1 100644
293 --- a/include/linux/mnt_namespace.h
294 +++ b/include/linux/mnt_namespace.h
296 struct mnt_namespace;
298 struct user_namespace;
301 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
302 struct user_namespace *, struct fs_struct *);
303 extern void put_mnt_ns(struct mnt_namespace *ns);
305 +extern int is_current_mnt_ns(struct vfsmount *mnt);
307 extern const struct file_operations proc_mounts_operations;
308 extern const struct file_operations proc_mountinfo_operations;
309 extern const struct file_operations proc_mountstats_operations;
310 diff --git a/include/linux/splice.h b/include/linux/splice.h
311 index 00a2116..1f0a4a2 100644
312 --- a/include/linux/splice.h
313 +++ b/include/linux/splice.h
314 @@ -86,4 +86,10 @@ extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
316 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
317 extern const struct pipe_buf_operations default_pipe_buf_ops;
319 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
320 + loff_t *ppos, size_t len, unsigned int flags);
321 +extern long do_splice_to(struct file *in, loff_t *ppos,
322 + struct pipe_inode_info *pipe, size_t len,
323 + unsigned int flags);
327 diff --git a/fs/proc/base.c b/fs/proc/base.c
328 index ca651ac..0e8551a 100644
331 @@ -1953,7 +1953,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
332 down_read(&mm->mmap_sem);
333 vma = find_exact_vma(mm, vm_start, vm_end);
334 if (vma && vma->vm_file) {
335 - *path = vma->vm_file->f_path;
336 + *path = vma_pr_or_file(vma)->f_path;
340 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
341 index f8595e8..cb8eda0 100644
342 --- a/fs/proc/nommu.c
343 +++ b/fs/proc/nommu.c
344 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
345 file = region->vm_file;
348 - struct inode *inode = file_inode(region->vm_file);
349 + struct inode *inode;
351 + file = vmr_pr_or_file(region);
352 + inode = file_inode(file);
353 dev = inode->i_sb->s_dev;
356 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
357 index 35b92d8..5b981db 100644
358 --- a/fs/proc/task_mmu.c
359 +++ b/fs/proc/task_mmu.c
360 @@ -291,7 +291,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
361 const char *name = NULL;
364 - struct inode *inode = file_inode(vma->vm_file);
365 + struct inode *inode;
367 + file = vma_pr_or_file(vma);
368 + inode = file_inode(file);
369 dev = inode->i_sb->s_dev;
371 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
372 @@ -1627,7 +1630,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
373 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
374 struct vm_area_struct *vma = v;
375 struct numa_maps *md = &numa_priv->md;
376 - struct file *file = vma->vm_file;
377 + struct file *file = vma_pr_or_file(vma);
378 struct mm_struct *mm = vma->vm_mm;
379 struct mm_walk walk = {
380 .hugetlb_entry = gather_hugetlb_stats,
381 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
382 index 3717562..6a328f1 100644
383 --- a/fs/proc/task_nommu.c
384 +++ b/fs/proc/task_nommu.c
385 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
389 - struct inode *inode = file_inode(vma->vm_file);
390 + struct inode *inode;
392 + file = vma_pr_or_file(vma);
393 + inode = file_inode(file);
394 dev = inode->i_sb->s_dev;
396 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
397 diff --git a/include/linux/mm.h b/include/linux/mm.h
398 index a92c8d7..1d83a2a 100644
399 --- a/include/linux/mm.h
400 +++ b/include/linux/mm.h
401 @@ -1266,6 +1266,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
405 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
406 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
408 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
409 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
411 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
413 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
415 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
416 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
419 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
420 +extern void vmr_do_fput(struct vm_region *, const char[], int);
422 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
424 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
425 +#endif /* !CONFIG_MMU */
427 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
428 unsigned int gup_flags);
429 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
430 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
431 index 4a8aced..badd16b 100644
432 --- a/include/linux/mm_types.h
433 +++ b/include/linux/mm_types.h
434 @@ -275,6 +275,7 @@ struct vm_region {
435 unsigned long vm_top; /* region allocated to here */
436 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
437 struct file *vm_file; /* the backing file or NULL */
438 + struct file *vm_prfile; /* the virtual backing file or NULL */
440 int vm_usage; /* region usage count (access under nommu_region_sem) */
441 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
442 @@ -349,6 +350,7 @@ struct vm_area_struct {
443 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
445 struct file * vm_file; /* File we map to (can be NULL). */
446 + struct file *vm_prfile; /* shadow of vm_file */
447 void * vm_private_data; /* was vm_pte (shared mem) */
450 diff --git a/kernel/fork.c b/kernel/fork.c
451 index 997ac1d..4d0131b 100644
454 @@ -624,7 +624,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
455 struct inode *inode = file_inode(file);
456 struct address_space *mapping = file->f_mapping;
460 if (tmp->vm_flags & VM_DENYWRITE)
461 atomic_dec(&inode->i_writecount);
462 i_mmap_lock_write(mapping);
463 diff --git a/mm/Makefile b/mm/Makefile
464 index 295bd7a..14fa1c8 100644
467 @@ -37,7 +37,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
468 mm_init.o mmu_context.o percpu.o slab_common.o \
469 compaction.o vmacache.o \
470 interval_tree.o list_lru.o workingset.o \
472 + prfile.o debug.o $(mmu-y)
476 diff --git a/mm/filemap.c b/mm/filemap.c
477 index 50b52fe..9e607f9 100644
480 @@ -2304,7 +2304,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
481 int ret = VM_FAULT_LOCKED;
483 sb_start_pagefault(inode->i_sb);
484 - file_update_time(vma->vm_file);
485 + vma_file_update_time(vma);
487 if (page->mapping != inode->i_mapping) {
489 diff --git a/mm/memory.c b/mm/memory.c
490 index e18c57b..7be4a39 100644
493 @@ -2117,7 +2117,7 @@ static inline int wp_page_reuse(struct fault_env *fe, pte_t orig_pte,
497 - file_update_time(vma->vm_file);
498 + vma_file_update_time(vma);
501 return VM_FAULT_WRITE;
502 diff --git a/mm/mmap.c b/mm/mmap.c
503 index 1af87c1..95b0ff4 100644
506 @@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
507 if (vma->vm_ops && vma->vm_ops->close)
508 vma->vm_ops->close(vma);
510 - fput(vma->vm_file);
512 mpol_put(vma_policy(vma));
513 kmem_cache_free(vm_area_cachep, vma);
515 @@ -879,7 +879,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
518 uprobe_munmap(next, next->vm_start, next->vm_end);
523 anon_vma_merge(vma, next);
524 @@ -1727,8 +1727,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
532 /* Undo any partial mapping done by a device driver. */
533 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
534 @@ -2533,7 +2533,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
538 - get_file(new->vm_file);
541 if (new->vm_ops && new->vm_ops->open)
542 new->vm_ops->open(new);
543 @@ -2552,7 +2552,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
544 if (new->vm_ops && new->vm_ops->close)
545 new->vm_ops->close(new);
547 - fput(new->vm_file);
549 unlink_anon_vmas(new);
551 mpol_put(vma_policy(new));
552 @@ -2703,7 +2703,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
553 struct vm_area_struct *vma;
554 unsigned long populate = 0;
555 unsigned long ret = -EINVAL;
557 + struct file *file, *prfile;
559 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
560 current->comm, current->pid);
561 @@ -2778,10 +2778,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
565 - file = get_file(vma->vm_file);
567 + file = vma->vm_file;
568 + prfile = vma->vm_prfile;
569 ret = do_mmap_pgoff(vma->vm_file, start, size,
570 prot, flags, pgoff, &populate);
571 + if (!IS_ERR_VALUE(ret) && file && prfile) {
572 + struct vm_area_struct *new_vma;
574 + new_vma = find_vma(mm, ret);
575 + if (!new_vma->vm_prfile)
576 + new_vma->vm_prfile = prfile;
577 + if (new_vma != vma)
581 + * two fput()s instead of vma_fput(vma),
582 + * coz vma may not be available anymore.
588 up_write(&mm->mmap_sem);
590 @@ -3056,7 +3073,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
591 if (anon_vma_clone(new_vma, vma))
592 goto out_free_mempol;
593 if (new_vma->vm_file)
594 - get_file(new_vma->vm_file);
595 + vma_get_file(new_vma);
596 if (new_vma->vm_ops && new_vma->vm_ops->open)
597 new_vma->vm_ops->open(new_vma);
598 vma_link(mm, new_vma, prev, rb_link, rb_parent);
599 diff --git a/mm/nommu.c b/mm/nommu.c
600 index 8b8faaf..5d26ed94 100644
603 @@ -636,7 +636,7 @@ static void __put_nommu_region(struct vm_region *region)
604 up_write(&nommu_region_sem);
607 - fput(region->vm_file);
610 /* IO memory and memory shared directly out of the pagecache
611 * from ramfs/tmpfs mustn't be released here */
612 @@ -794,7 +794,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
613 if (vma->vm_ops && vma->vm_ops->close)
614 vma->vm_ops->close(vma);
616 - fput(vma->vm_file);
618 put_nommu_region(vma->vm_region);
619 kmem_cache_free(vm_area_cachep, vma);
621 @@ -1320,7 +1320,7 @@ unsigned long do_mmap(struct file *file,
622 goto error_just_free;
625 - fput(region->vm_file);
627 kmem_cache_free(vm_region_jar, region);
630 @@ -1395,10 +1395,10 @@ unsigned long do_mmap(struct file *file,
631 up_write(&nommu_region_sem);
634 - fput(region->vm_file);
636 kmem_cache_free(vm_region_jar, region);
638 - fput(vma->vm_file);
640 kmem_cache_free(vm_area_cachep, vma);
643 diff --git a/mm/prfile.c b/mm/prfile.c
645 index 0000000..86e01bd
650 + * Mainly for aufs which mmap(2) different file and wants to print different
651 + * path in /proc/PID/maps.
652 + * Call these functions via macros defined in linux/mm.h.
654 + * See Documentation/filesystems/aufs/design/06mmap.txt
656 + * Copyright (c) 2014-2018 Junjro R. Okajima
657 + * Copyright (c) 2014 Ian Campbell
660 +#include <linux/mm.h>
661 +#include <linux/file.h>
662 +#include <linux/fs.h>
664 +/* #define PRFILE_TRACE */
665 +static inline void prfile_trace(struct file *f, struct file *pr,
666 + const char func[], int line, const char func2[])
670 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
674 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
677 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
679 + prfile_trace(f, pr, func, line, __func__);
680 + file_update_time(f);
682 + file_update_time(pr);
685 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
688 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
690 + prfile_trace(f, pr, func, line, __func__);
691 + return (f && pr) ? pr : f;
694 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
696 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
698 + prfile_trace(f, pr, func, line, __func__);
704 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
706 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
708 + prfile_trace(f, pr, func, line, __func__);
715 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
718 + struct file *f = region->vm_file, *pr = region->vm_prfile;
720 + prfile_trace(f, pr, func, line, __func__);
721 + return (f && pr) ? pr : f;
724 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
726 + struct file *f = region->vm_file, *pr = region->vm_prfile;
728 + prfile_trace(f, pr, func, line, __func__);
733 +#endif /* !CONFIG_MMU */
734 aufs4.9 standalone patch
736 diff --git a/fs/dcache.c b/fs/dcache.c
737 index df0268c..755fea1 100644
740 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
744 +EXPORT_SYMBOL_GPL(d_walk);
747 * Search for at least 1 mount point in the dentry's subdirs.
748 @@ -2855,6 +2856,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
750 write_sequnlock(&rename_lock);
752 +EXPORT_SYMBOL_GPL(d_exchange);
755 * d_ancestor - search for an ancestor
756 diff --git a/fs/exec.c b/fs/exec.c
757 index 4e497b9..e27d323 100644
760 @@ -104,6 +104,7 @@ bool path_noexec(const struct path *path)
761 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
762 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
764 +EXPORT_SYMBOL_GPL(path_noexec);
768 diff --git a/fs/fcntl.c b/fs/fcntl.c
769 index 6f42279..04fd33c 100644
772 @@ -82,6 +82,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
776 +EXPORT_SYMBOL_GPL(setfl);
778 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
780 diff --git a/fs/file_table.c b/fs/file_table.c
781 index ad17e05..ae9f267 100644
782 --- a/fs/file_table.c
783 +++ b/fs/file_table.c
784 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
786 return ERR_PTR(-ENFILE);
788 +EXPORT_SYMBOL_GPL(get_empty_filp);
791 * alloc_file - allocate and initialize a 'struct file'
792 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
796 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
798 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
800 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
804 +EXPORT_SYMBOL_GPL(__fput_sync);
806 void put_filp(struct file *file)
808 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
812 +EXPORT_SYMBOL_GPL(put_filp);
814 void __init files_init(void)
816 diff --git a/fs/inode.c b/fs/inode.c
817 index 9a9ba3a..a3a18d83 100644
820 @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
822 return update_time(inode, time, flags);
824 +EXPORT_SYMBOL_GPL(update_time);
827 * touch_atime - update the access time
828 diff --git a/fs/namespace.c b/fs/namespace.c
829 index db0b1ac..2d1e8ff 100644
832 @@ -466,6 +466,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
833 mnt_dec_writers(real_mount(mnt));
836 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
839 * mnt_drop_write - give up write access to a mount
840 @@ -792,6 +793,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
842 return check_mnt(real_mount(mnt));
844 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
847 * vfsmount lock must be held for write
848 @@ -1829,6 +1831,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
852 +EXPORT_SYMBOL_GPL(iterate_mounts);
854 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
856 diff --git a/fs/notify/group.c b/fs/notify/group.c
857 index fbe3cbe..bdfc61e 100644
858 --- a/fs/notify/group.c
859 +++ b/fs/notify/group.c
861 #include <linux/srcu.h>
862 #include <linux/rculist.h>
863 #include <linux/wait.h>
864 +#include <linux/module.h>
866 #include <linux/fsnotify_backend.h>
867 #include "fsnotify.h"
868 @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
870 atomic_inc(&group->refcnt);
872 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
875 * Drop a reference to a group. Free it if it's through.
876 @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
877 if (atomic_dec_and_test(&group->refcnt))
878 fsnotify_final_destroy_group(group);
880 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
883 * Create a new fsnotify_group and hold a reference for the group returned.
884 @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
888 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
890 int fsnotify_fasync(int fd, struct file *file, int on)
892 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
893 index d3fea0b..5fc06ad 100644
894 --- a/fs/notify/mark.c
895 +++ b/fs/notify/mark.c
896 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
897 mark->free_mark(mark);
900 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
902 /* Calculate mask of events for a list of marks */
903 u32 fsnotify_recalc_mask(struct hlist_head *head)
904 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
905 mutex_unlock(&group->mark_mutex);
906 fsnotify_free_mark(mark);
908 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
910 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
912 @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
916 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
918 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
919 struct inode *inode, struct vfsmount *mnt, int allow_dups)
920 @@ -533,6 +536,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
921 atomic_set(&mark->refcnt, 1);
922 mark->free_mark = free_mark;
924 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
927 * Destroy all marks in destroy_list, waits for SRCU period to finish before
928 diff --git a/fs/open.c b/fs/open.c
929 index d3ed817..20d2494 100644
932 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
933 inode_unlock(dentry->d_inode);
936 +EXPORT_SYMBOL_GPL(do_truncate);
938 long vfs_truncate(const struct path *path, loff_t length)
940 @@ -695,6 +696,7 @@ int open_check_o_direct(struct file *f)
944 +EXPORT_SYMBOL_GPL(open_check_o_direct);
946 static int do_dentry_open(struct file *f,
948 diff --git a/fs/read_write.c b/fs/read_write.c
949 index 4052813..7dfd732 100644
950 --- a/fs/read_write.c
951 +++ b/fs/read_write.c
952 @@ -525,6 +525,7 @@ vfs_readf_t vfs_readf(struct file *file)
953 return new_sync_read;
954 return ERR_PTR(-ENOSYS);
956 +EXPORT_SYMBOL_GPL(vfs_readf);
958 vfs_writef_t vfs_writef(struct file *file)
960 @@ -536,6 +537,7 @@ vfs_writef_t vfs_writef(struct file *file)
961 return new_sync_write;
962 return ERR_PTR(-ENOSYS);
964 +EXPORT_SYMBOL_GPL(vfs_writef);
966 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
968 diff --git a/fs/splice.c b/fs/splice.c
969 index 28160a7..98c1902 100644
972 @@ -868,6 +868,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
974 return splice_write(pipe, out, ppos, len, flags);
976 +EXPORT_SYMBOL_GPL(do_splice_from);
979 * Attempt to initiate a splice from a file to a pipe.
980 @@ -897,6 +898,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
982 return splice_read(in, ppos, pipe, len, flags);
984 +EXPORT_SYMBOL_GPL(do_splice_to);
987 * splice_direct_to_actor - splices data directly between two non-pipes
988 diff --git a/fs/sync.c b/fs/sync.c
989 index 7a5fa3f..c9b9d46 100644
992 @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
993 sb->s_op->sync_fs(sb, wait);
994 return __sync_blockdev(sb->s_bdev, wait);
996 +EXPORT_SYMBOL_GPL(__sync_filesystem);
999 * Write out and wait upon all dirty data associated with this
1000 diff --git a/fs/xattr.c b/fs/xattr.c
1001 index 2d13b4e..41c2bcd 100644
1004 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1005 *xattr_value = value;
1008 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1011 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1012 diff --git a/kernel/task_work.c b/kernel/task_work.c
1013 index d513051..e056d54 100644
1014 --- a/kernel/task_work.c
1015 +++ b/kernel/task_work.c
1016 @@ -119,3 +119,4 @@ void task_work_run(void)
1020 +EXPORT_SYMBOL_GPL(task_work_run);
1021 diff --git a/security/commoncap.c b/security/commoncap.c
1022 index 8df676f..6b5cc07 100644
1023 --- a/security/commoncap.c
1024 +++ b/security/commoncap.c
1025 @@ -1061,12 +1061,14 @@ int cap_mmap_addr(unsigned long addr)
1029 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1031 int cap_mmap_file(struct file *file, unsigned long reqprot,
1032 unsigned long prot, unsigned long flags)
1036 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1038 #ifdef CONFIG_SECURITY
1040 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1041 index 03c1652..f88c84b 100644
1042 --- a/security/device_cgroup.c
1043 +++ b/security/device_cgroup.c
1045 #include <linux/device_cgroup.h>
1046 #include <linux/cgroup.h>
1047 #include <linux/ctype.h>
1048 +#include <linux/export.h>
1049 #include <linux/list.h>
1050 #include <linux/uaccess.h>
1051 #include <linux/seq_file.h>
1052 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
1053 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
1056 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
1058 int devcgroup_inode_mknod(int mode, dev_t dev)
1060 diff --git a/security/security.c b/security/security.c
1061 index f825304..8dd441d 100644
1062 --- a/security/security.c
1063 +++ b/security/security.c
1064 @@ -443,6 +443,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1066 return call_int_hook(path_rmdir, 0, dir, dentry);
1068 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1070 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1072 @@ -459,6 +460,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1074 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1076 +EXPORT_SYMBOL_GPL(security_path_symlink);
1078 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1079 struct dentry *new_dentry)
1080 @@ -467,6 +469,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1082 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1084 +EXPORT_SYMBOL_GPL(security_path_link);
1086 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1087 const struct path *new_dir, struct dentry *new_dentry,
1088 @@ -494,6 +497,7 @@ int security_path_truncate(const struct path *path)
1090 return call_int_hook(path_truncate, 0, path);
1092 +EXPORT_SYMBOL_GPL(security_path_truncate);
1094 int security_path_chmod(const struct path *path, umode_t mode)
1096 @@ -501,6 +505,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1098 return call_int_hook(path_chmod, 0, path, mode);
1100 +EXPORT_SYMBOL_GPL(security_path_chmod);
1102 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1104 @@ -508,6 +513,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1106 return call_int_hook(path_chown, 0, path, uid, gid);
1108 +EXPORT_SYMBOL_GPL(security_path_chown);
1110 int security_path_chroot(const struct path *path)
1112 @@ -593,6 +599,7 @@ int security_inode_readlink(struct dentry *dentry)
1114 return call_int_hook(inode_readlink, 0, dentry);
1116 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1118 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1120 @@ -608,6 +615,7 @@ int security_inode_permission(struct inode *inode, int mask)
1122 return call_int_hook(inode_permission, 0, inode, mask);
1124 +EXPORT_SYMBOL_GPL(security_inode_permission);
1126 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1128 @@ -779,6 +787,7 @@ int security_file_permission(struct file *file, int mask)
1130 return fsnotify_perm(file, mask);
1132 +EXPORT_SYMBOL_GPL(security_file_permission);
1134 int security_file_alloc(struct file *file)
1136 @@ -838,6 +847,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1138 return ima_file_mmap(file, prot);
1140 +EXPORT_SYMBOL_GPL(security_mmap_file);
1142 int security_mmap_addr(unsigned long addr)
1144 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1145 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1146 +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-07-29 12:14:25.893041746 +0200
1148 +What: /debug/aufs/si_<id>/
1150 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1152 + Under /debug/aufs, a directory named si_<id> is created
1153 + per aufs mount, where <id> is a unique id generated
1156 +What: /debug/aufs/si_<id>/plink
1158 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1160 + It has three lines and shows the information about the
1161 + pseudo-link. The first line is a single number
1162 + representing a number of buckets. The second line is a
1163 + number of pseudo-links per buckets (separated by a
1164 + blank). The last line is a single number representing a
1165 + total number of psedo-links.
1166 + When the aufs mount option 'noplink' is specified, it
1167 + will show "1\n0\n0\n".
1169 +What: /debug/aufs/si_<id>/xib
1171 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1173 + It shows the consumed blocks by xib (External Inode Number
1174 + Bitmap), its block size and file size.
1175 + When the aufs mount option 'noxino' is specified, it
1176 + will be empty. About XINO files, see the aufs manual.
1178 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1180 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1182 + It shows the consumed blocks by xino (External Inode Number
1183 + Translation Table), its link count, block size and file
1185 + When the aufs mount option 'noxino' is specified, it
1186 + will be empty. About XINO files, see the aufs manual.
1188 +What: /debug/aufs/si_<id>/xigen
1190 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1192 + It shows the consumed blocks by xigen (External Inode
1193 + Generation Table), its block size and file size.
1194 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1196 + When the aufs mount option 'noxino' is specified, it
1197 + will be empty. About XINO files, see the aufs manual.
1198 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1199 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1200 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1202 +What: /sys/fs/aufs/si_<id>/
1204 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1206 + Under /sys/fs/aufs, a directory named si_<id> is created
1207 + per aufs mount, where <id> is a unique id generated
1210 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1212 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1214 + It shows the abolute path of a member directory (which
1215 + is called branch) in aufs, and its permission.
1217 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1219 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1221 + It shows the id of a member directory (which is called
1224 +What: /sys/fs/aufs/si_<id>/xi_path
1226 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1228 + It shows the abolute path of XINO (External Inode Number
1229 + Bitmap, Translation Table and Generation Table) file
1230 + even if it is the default path.
1231 + When the aufs mount option 'noxino' is specified, it
1232 + will be empty. About XINO files, see the aufs manual.
1233 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1234 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1235 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-04-15 08:49:13.394483860 +0200
1238 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1240 +# This program is free software; you can redistribute it and/or modify
1241 +# it under the terms of the GNU General Public License as published by
1242 +# the Free Software Foundation; either version 2 of the License, or
1243 +# (at your option) any later version.
1245 +# This program is distributed in the hope that it will be useful,
1246 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1247 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1248 +# GNU General Public License for more details.
1250 +# You should have received a copy of the GNU General Public License
1251 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1254 +----------------------------------------
1256 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1257 +1. abbrev. for "advanced multi-layered unification filesystem".
1258 +2. abbrev. for "another unionfs".
1259 +3. abbrev. for "auf das" in German which means "on the" in English.
1260 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1261 + But "Filesystem aufs Filesystem" is hard to understand.
1262 +4. abbrev. for "African Urban Fashion Show".
1264 +AUFS is a filesystem with features:
1265 +- multi layered stackable unification filesystem, the member directory
1266 + is called as a branch.
1267 +- branch permission and attribute, 'readonly', 'real-readonly',
1268 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1270 +- internal "file copy-on-write".
1271 +- logical deletion, whiteout.
1272 +- dynamic branch manipulation, adding, deleting and changing permission.
1273 +- allow bypassing aufs, user's direct branch access.
1274 +- external inode number translation table and bitmap which maintains the
1275 + persistent aufs inode number.
1276 +- seekable directory, including NFS readdir.
1277 +- file mapping, mmap and sharing pages.
1278 +- pseudo-link, hardlink over branches.
1279 +- loopback mounted filesystem as a branch.
1280 +- several policies to select one among multiple writable branches.
1281 +- revert a single systemcall when an error occurs in aufs.
1285 +Multi Layered Stackable Unification Filesystem
1286 +----------------------------------------------------------------------
1287 +Most people already knows what it is.
1288 +It is a filesystem which unifies several directories and provides a
1289 +merged single directory. When users access a file, the access will be
1290 +passed/re-directed/converted (sorry, I am not sure which English word is
1291 +correct) to the real file on the member filesystem. The member
1292 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1293 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1294 +readonly branch is handled by creating 'whiteout' on the upper writable
1297 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1298 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1299 +different approaches to implement the merged-view.
1300 +The former tries putting it into VFS, and the latter implements as a
1301 +separate filesystem.
1302 +(If I misunderstand about these implementations, please let me know and
1303 +I shall correct it. Because it is a long time ago when I read their
1304 +source files last time).
1306 +UnionMount's approach will be able to small, but may be hard to share
1307 +branches between several UnionMount since the whiteout in it is
1308 +implemented in the inode on branch filesystem and always
1309 +shared. According to Bharata's post, readdir does not seems to be
1311 +There are several missing features known in this implementations such as
1312 +- for users, the inode number may change silently. eg. copy-up.
1313 +- link(2) may break by copy-up.
1314 +- read(2) may get an obsoleted filedata (fstat(2) too).
1315 +- fcntl(F_SETLK) may be broken by copy-up.
1316 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1319 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1320 +merged into mainline. This is another implementation of UnionMount as a
1321 +separated filesystem. All the limitations and known problems which
1322 +UnionMount are equally inherited to "overlay" filesystem.
1324 +Unionfs has a longer history. When I started implementing a stackable
1325 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1326 +inode, dentry and file objects and they have an array pointing lower
1327 +same kind objects. After contributing many patches for Unionfs, I
1328 +re-started my project AUFS (Jun 2006).
1330 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1331 +implemented my own ideas, approaches and enhancements and it became
1332 +totally different one.
1334 +Comparing DM snapshot and fs based implementation
1335 +- the number of bytes to be copied between devices is much smaller.
1336 +- the type of filesystem must be one and only.
1337 +- the fs must be writable, no readonly fs, even for the lower original
1338 + device. so the compression fs will not be usable. but if we use
1339 + loopback mount, we may address this issue.
1341 + mount /cdrom/squashfs.img /sq
1342 + losetup /sq/ext2.img
1343 + losetup /somewhere/cow
1344 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1345 +- it will be difficult (or needs more operations) to extract the
1346 + difference between the original device and COW.
1347 +- DM snapshot-merge may help a lot when users try merging. in the
1348 + fs-layer union, users will use rsync(1).
1350 +You may want to read my old paper "Filesystems in LiveCD"
1351 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1354 +Several characters/aspects/persona of aufs
1355 +----------------------------------------------------------------------
1357 +Aufs has several characters, aspects or persona.
1358 +1. a filesystem, callee of VFS helper
1359 +2. sub-VFS, caller of VFS helper for branches
1360 +3. a virtual filesystem which maintains persistent inode number
1361 +4. reader/writer of files on branches such like an application
1363 +1. Callee of VFS Helper
1364 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1365 +unlink(2) from an application reaches sys_unlink() kernel function and
1366 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1367 +calls filesystem specific unlink operation. Actually aufs implements the
1368 +unlink operation but it behaves like a redirector.
1370 +2. Caller of VFS Helper for Branches
1371 +aufs_unlink() passes the unlink request to the branch filesystem as if
1372 +it were called from VFS. So the called unlink operation of the branch
1373 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1374 +every necessary pre/post operation for the branch filesystem.
1375 +- acquire the lock for the parent dir on a branch
1376 +- lookup in a branch
1377 +- revalidate dentry on a branch
1378 +- mnt_want_write() for a branch
1379 +- vfs_unlink() for a branch
1380 +- mnt_drop_write() for a branch
1381 +- release the lock on a branch
1383 +3. Persistent Inode Number
1384 +One of the most important issue for a filesystem is to maintain inode
1385 +numbers. This is particularly important to support exporting a
1386 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1387 +backend block device for its own. But some storage is necessary to
1388 +keep and maintain the inode numbers. It may be a large space and may not
1389 +suit to keep in memory. Aufs rents some space from its first writable
1390 +branch filesystem (by default) and creates file(s) on it. These files
1391 +are created by aufs internally and removed soon (currently) keeping
1393 +Note: Because these files are removed, they are totally gone after
1394 + unmounting aufs. It means the inode numbers are not persistent
1395 + across unmount or reboot. I have a plan to make them really
1396 + persistent which will be important for aufs on NFS server.
1398 +4. Read/Write Files Internally (copy-on-write)
1399 +Because a branch can be readonly, when you write a file on it, aufs will
1400 +"copy-up" it to the upper writable branch internally. And then write the
1401 +originally requested thing to the file. Generally kernel doesn't
1402 +open/read/write file actively. In aufs, even a single write may cause a
1403 +internal "file copy". This behaviour is very similar to cp(1) command.
1405 +Some people may think it is better to pass such work to user space
1406 +helper, instead of doing in kernel space. Actually I am still thinking
1407 +about it. But currently I have implemented it in kernel space.
1408 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1409 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1410 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-04-15 08:49:13.394483860 +0200
1413 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1415 +# This program is free software; you can redistribute it and/or modify
1416 +# it under the terms of the GNU General Public License as published by
1417 +# the Free Software Foundation; either version 2 of the License, or
1418 +# (at your option) any later version.
1420 +# This program is distributed in the hope that it will be useful,
1421 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1422 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1423 +# GNU General Public License for more details.
1425 +# You should have received a copy of the GNU General Public License
1426 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1428 +Basic Aufs Internal Structure
1430 +Superblock/Inode/Dentry/File Objects
1431 +----------------------------------------------------------------------
1432 +As like an ordinary filesystem, aufs has its own
1433 +superblock/inode/dentry/file objects. All these objects have a
1434 +dynamically allocated array and store the same kind of pointers to the
1435 +lower filesystem, branch.
1436 +For example, when you build a union with one readwrite branch and one
1437 +readonly, mounted /au, /rw and /ro respectively.
1439 +- /ro/fileA exists but /rw/fileA
1441 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1442 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1443 +- [0] = NULL (because /rw/fileA doesn't exist)
1446 +This style of an array is essentially same to the aufs
1447 +superblock/inode/dentry/file objects.
1449 +Because aufs supports manipulating branches, ie. add/delete/change
1450 +branches dynamically, these objects has its own generation. When
1451 +branches are changed, the generation in aufs superblock is
1452 +incremented. And a generation in other object are compared when it is
1453 +accessed. When a generation in other objects are obsoleted, aufs
1454 +refreshes the internal array.
1458 +----------------------------------------------------------------------
1459 +Additionally aufs superblock has some data for policies to select one
1460 +among multiple writable branches, XIB files, pseudo-links and kobject.
1461 +See below in detail.
1462 +About the policies which supports copy-down a directory, see
1463 +wbr_policy.txt too.
1466 +Branch and XINO(External Inode Number Translation Table)
1467 +----------------------------------------------------------------------
1468 +Every branch has its own xino (external inode number translation table)
1469 +file. The xino file is created and unlinked by aufs internally. When two
1470 +members of a union exist on the same filesystem, they share the single
1472 +The struct of a xino file is simple, just a sequence of aufs inode
1473 +numbers which is indexed by the lower inode number.
1474 +In the above sample, assume the inode number of /ro/fileA is i111 and
1475 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1476 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1478 +When the inode numbers are not contiguous, the xino file will be sparse
1479 +which has a hole in it and doesn't consume as much disk space as it
1480 +might appear. If your branch filesystem consumes disk space for such
1481 +holes, then you should specify 'xino=' option at mounting aufs.
1483 +Aufs has a mount option to free the disk blocks for such holes in XINO
1484 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1485 +meet a problem of disk shortage due to XINO files, then you should try
1486 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1487 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1488 +the holes in XINO files.
1490 +Also a writable branch has three kinds of "whiteout bases". All these
1491 +are existed when the branch is joined to aufs, and their names are
1492 +whiteout-ed doubly, so that users will never see their names in aufs
1494 +1. a regular file which will be hardlinked to all whiteouts.
1495 +2. a directory to store a pseudo-link.
1496 +3. a directory to store an "orphan"-ed file temporary.
1499 + When you remove a file on a readonly branch, aufs handles it as a
1500 + logical deletion and creates a whiteout on the upper writable branch
1501 + as a hardlink of this file in order not to consume inode on the
1504 + See below, Pseudo-link.
1506 + When "fileC" exists on the lower readonly branch only and it is
1507 + opened and removed with its parent dir, and then user writes
1508 + something into it, then aufs copies-up fileC to this
1509 + directory. Because there is no other dir to store fileC. After
1510 + creating a file under this dir, the file is unlinked.
1512 +Because aufs supports manipulating branches, ie. add/delete/change
1513 +dynamically, a branch has its own id. When the branch order changes,
1514 +aufs finds the new index by searching the branch id.
1518 +----------------------------------------------------------------------
1519 +Assume "fileA" exists on the lower readonly branch only and it is
1520 +hardlinked to "fileB" on the branch. When you write something to fileA,
1521 +aufs copies-up it to the upper writable branch. Additionally aufs
1522 +creates a hardlink under the Pseudo-link Directory of the writable
1523 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1524 +simple list. If fileB is read after unlinking fileA, aufs returns
1525 +filedata from the pseudo-link instead of the lower readonly
1526 +branch. Because the pseudo-link is based upon the inode, to keep the
1527 +inode number by xino (see above) is essentially necessary.
1529 +All the hardlinks under the Pseudo-link Directory of the writable branch
1530 +should be restored in a proper location later. Aufs provides a utility
1531 +to do this. The userspace helpers executed at remounting and unmounting
1533 +During this utility is running, it puts aufs into the pseudo-link
1534 +maintenance mode. In this mode, only the process which began the
1535 +maintenance mode (and its child processes) is allowed to operate in
1536 +aufs. Some other processes which are not related to the pseudo-link will
1537 +be allowed to run too, but the rest have to return an error or wait
1538 +until the maintenance mode ends. If a process already acquires an inode
1539 +mutex (in VFS), it has to return an error.
1542 +XIB(external inode number bitmap)
1543 +----------------------------------------------------------------------
1544 +Addition to the xino file per a branch, aufs has an external inode number
1545 +bitmap in a superblock object. It is also an internal file such like a
1547 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1549 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1551 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1552 +reduce the number of consumed disk blocks for these files.
1555 +Virtual or Vertical Dir, and Readdir in Userspace
1556 +----------------------------------------------------------------------
1557 +In order to support multiple layers (branches), aufs readdir operation
1558 +constructs a virtual dir block on memory. For readdir, aufs calls
1559 +vfs_readdir() internally for each dir on branches, merges their entries
1560 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1561 +object. So the file object has its entry list until it is closed. The
1562 +entry list will be updated when the file position is zero and becomes
1563 +obsoleted. This decision is made in aufs automatically.
1565 +The dynamically allocated memory block for the name of entries has a
1566 +unit of 512 bytes (by default) and stores the names contiguously (no
1567 +padding). Another block for each entry is handled by kmem_cache too.
1568 +During building dir blocks, aufs creates hash list and judging whether
1569 +the entry is whiteouted by its upper branch or already listed.
1570 +The merged result is cached in the corresponding inode object and
1571 +maintained by a customizable life-time option.
1573 +Some people may call it can be a security hole or invite DoS attack
1574 +since the opened and once readdir-ed dir (file object) holds its entry
1575 +list and becomes a pressure for system memory. But I'd say it is similar
1576 +to files under /proc or /sys. The virtual files in them also holds a
1577 +memory page (generally) while they are opened. When an idea to reduce
1578 +memory for them is introduced, it will be applied to aufs too.
1579 +For those who really hate this situation, I've developed readdir(3)
1580 +library which operates this merging in userspace. You just need to set
1581 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1582 +kernel space for readdir(3).
1586 +----------------------------------------------------------------------
1587 +Aufs sometimes requires privilege access to a branch. For instance,
1588 +in copy-up/down operation. When a user process is going to make changes
1589 +to a file which exists in the lower readonly branch only, and the mode
1590 +of one of ancestor directories may not be writable by a user
1591 +process. Here aufs copy-up the file with its ancestors and they may
1592 +require privilege to set its owner/group/mode/etc.
1593 +This is a typical case of a application character of aufs (see
1596 +Aufs uses workqueue synchronously for this case. It creates its own
1597 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1598 +passes the request to call mkdir or write (for example), and wait for
1599 +its completion. This approach solves a problem of a signal handler
1601 +If aufs didn't adopt the workqueue and changed the privilege of the
1602 +process, then the process may receive the unexpected SIGXFSZ or other
1605 +Also aufs uses the system global workqueue ("events" kernel thread) too
1606 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1607 +whiteout base and etc. This is unrelated to a privilege.
1608 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1609 +superblock at the beginning, at the same time waits for the completion
1610 +of all queued asynchronous tasks.
1614 +----------------------------------------------------------------------
1615 +The whiteout in aufs is very similar to Unionfs's. That is represented
1616 +by its filename. UnionMount takes an approach of a file mode, but I am
1617 +afraid several utilities (find(1) or something) will have to support it.
1619 +Basically the whiteout represents "logical deletion" which stops aufs to
1620 +lookup further, but also it represents "dir is opaque" which also stop
1623 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1624 +In order to make several functions in a single systemcall to be
1625 +revertible, aufs adopts an approach to rename a directory to a temporary
1626 +unique whiteouted name.
1627 +For example, in rename(2) dir where the target dir already existed, aufs
1628 +renames the target dir to a temporary unique whiteouted name before the
1629 +actual rename on a branch, and then handles other actions (make it opaque,
1630 +update the attributes, etc). If an error happens in these actions, aufs
1631 +simply renames the whiteouted name back and returns an error. If all are
1632 +succeeded, aufs registers a function to remove the whiteouted unique
1633 +temporary name completely and asynchronously to the system global
1638 +----------------------------------------------------------------------
1639 +It is a well-known feature or concept.
1640 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1641 +internally and makes change to the new file on the upper writable branch.
1642 +When the trigger systemcall does not update the timestamps of the parent
1643 +dir, aufs reverts it after copy-up.
1646 +Move-down (aufs3.9 and later)
1647 +----------------------------------------------------------------------
1648 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1649 +the lower readonly branch to the upper writable branch when a user
1650 +changes something about the file.
1651 +"Move-down" is an opposite action of copy-up. Basically this action is
1652 +ran manually instead of automatically and internally.
1653 +For desgin and implementation, aufs has to consider these issues.
1654 +- whiteout for the file may exist on the lower branch.
1655 +- ancestor directories may not exist on the lower branch.
1656 +- diropq for the ancestor directories may exist on the upper branch.
1657 +- free space on the lower branch will reduce.
1658 +- another access to the file may happen during moving-down, including
1659 + UDBA (see "Revalidate Dentry and UDBA").
1660 +- the file should not be hard-linked nor pseudo-linked. they should be
1661 + handled by auplink utility later.
1663 +Sometimes users want to move-down a file from the upper writable branch
1664 +to the lower readonly or writable branch. For instance,
1665 +- the free space of the upper writable branch is going to run out.
1666 +- create a new intermediate branch between the upper and lower branch.
1669 +For this purpose, use "aumvdown" command in aufs-util.git.
1670 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1671 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1672 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-04-15 08:49:13.394483860 +0200
1675 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1677 +# This program is free software; you can redistribute it and/or modify
1678 +# it under the terms of the GNU General Public License as published by
1679 +# the Free Software Foundation; either version 2 of the License, or
1680 +# (at your option) any later version.
1682 +# This program is distributed in the hope that it will be useful,
1683 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1684 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1685 +# GNU General Public License for more details.
1687 +# You should have received a copy of the GNU General Public License
1688 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1690 +Support for a branch who has its ->atomic_open()
1691 +----------------------------------------------------------------------
1692 +The filesystems who implement its ->atomic_open() are not majority. For
1693 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1694 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1695 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1696 +sure whether all filesystems who have ->atomic_open() behave like this,
1697 +but NFSv4 surely returns the error.
1699 +In order to support ->atomic_open() for aufs, there are a few
1702 +A. Introduce aufs_atomic_open()
1703 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1705 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1706 + an aufs user Pip Cet's approach
1707 + - calls aufs_create(), VFS finish_open() and notify_change().
1708 + - pass fake-mode to finish_open(), and then correct the mode by
1710 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1711 + - no aufs_atomic_open().
1712 + - aufs_lookup() registers the TID to an aufs internal object.
1713 + - aufs_create() does nothing when the matching TID is registered, but
1714 + registers the mode.
1715 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1716 + TID is registered.
1717 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1719 + - no aufs_atomic_open().
1720 + - aufs_create() registers the TID to an internal object. this info
1721 + represents "this process created this file just now."
1722 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1723 + registered TID and re-try open() with superuser's credential.
1725 +Pros and cons for each approach.
1728 + - straightforward but highly depends upon VFS internal.
1729 + - the atomic behavaiour is kept.
1730 + - some of parameters such as nameidata are hard to reproduce for
1734 + - easy to implement.
1735 + - the atomic behavaiour is lost.
1737 + - the atomic behavaiour is kept.
1738 + - dirty and tricky.
1739 + - VFS checks whether the file is created correctly after calling
1740 + ->create(), which means this approach doesn't work.
1742 + - easy to implement.
1743 + - the atomic behavaiour is lost.
1744 + - to open a file with superuser's credential and give it to a user
1745 + process is a bad idea, since the file object keeps the credential
1746 + in it. It may affect LSM or something. This approach doesn't work
1749 +The approach A is ideal, but it hard to implement. So here is a
1750 +variation of A, which is to be implemented.
1752 +A-1. Introduce aufs_atomic_open()
1753 + - calls branch fs ->atomic_open() if exists. otherwise calls
1754 + vfs_create() and finish_open().
1755 + - the demerit is that the several checks after branch fs
1756 + ->atomic_open() are lost. in the ordinary case, the checks are
1757 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1758 + be implemented in aufs, but not all I am afraid.
1759 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1760 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1761 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-04-15 08:49:13.394483860 +0200
1764 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1766 +# This program is free software; you can redistribute it and/or modify
1767 +# it under the terms of the GNU General Public License as published by
1768 +# the Free Software Foundation; either version 2 of the License, or
1769 +# (at your option) any later version.
1771 +# This program is distributed in the hope that it will be useful,
1772 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1773 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1774 +# GNU General Public License for more details.
1776 +# You should have received a copy of the GNU General Public License
1777 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1780 +----------------------------------------------------------------------
1781 +Since aufs has a character of sub-VFS (see Introduction), it operates
1782 +lookup for branches as VFS does. It may be a heavy work. But almost all
1783 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1784 +directly connected to its parent. Digging down the directory hierarchy
1785 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1788 +When a branch is a remote filesystem, aufs basically relies upon its
1789 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1791 +For d_revalidate, aufs implements three levels of revalidate tests. See
1792 +"Revalidate Dentry and UDBA" in detail.
1795 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1796 +----------------------------------------------------------------------
1797 +Let's try case study.
1798 +- aufs has two branches, upper readwrite and lower readonly.
1800 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1801 +- user invoked "chmod a+rx /au/dirA"
1802 +- the internal copy-up is activated and "/rw/dirA" is created and its
1803 + permission bits are set to world readable.
1804 +- then "/au/dirA" becomes world readable?
1806 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1807 +or it may be a natively readonly filesystem. If aufs respects the lower
1808 +branch, it should not respond readdir request from other users. But user
1809 +allowed it by chmod. Should really aufs rejects showing the entries
1812 +To be honest, I don't have a good solution for this case. So aufs
1813 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1815 +When dirperm1 is specified, aufs checks only the highest one for the
1816 +directory permission, and shows the entries. Otherwise, as usual, checks
1817 +every dir existing on all branches and rejects the request.
1819 +As a side effect, dirperm1 option improves the performance of aufs
1820 +because the number of permission check is reduced when the number of
1824 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1825 +----------------------------------------------------------------------
1826 +Generally VFS helpers re-validate a dentry as a part of lookup.
1827 +0. digging down the directory hierarchy.
1828 +1. lock the parent dir by its i_mutex.
1829 +2. lookup the final (child) entry.
1831 +4. call the actual operation (create, unlink, etc.)
1832 +5. unlock the parent dir
1834 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1835 +called. Actually aufs implements it and checks the dentry on a branch is
1837 +But it is not enough. Because aufs has to release the lock for the
1838 +parent dir on a branch at the end of ->lookup() (step 2) and
1839 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1841 +If the file on a branch is changed directly, eg. bypassing aufs, after
1842 +aufs released the lock, then the subsequent operation may cause
1843 +something unpleasant result.
1845 +This situation is a result of VFS architecture, ->lookup() and
1846 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1847 +design from VFS's point of view. It is just not suitable for sub-VFS
1850 +Aufs supports such case by three level of revalidation which is
1851 +selectable by user.
1852 +1. Simple Revalidate
1853 + Addition to the native flow in VFS's, confirm the child-parent
1854 + relationship on the branch just after locking the parent dir on the
1855 + branch in the "actual operation" (step 4). When this validation
1856 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1857 + checks the validation of the dentry on branches.
1858 +2. Monitor Changes Internally by Inotify/Fsnotify
1859 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1860 + the dentry on the branch, and returns EBUSY if it finds different
1862 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1863 + during it is in cache. When the event is notified, aufs registers a
1864 + function to kernel 'events' thread by schedule_work(). And the
1865 + function sets some special status to the cached aufs dentry and inode
1866 + private data. If they are not cached, then aufs has nothing to
1867 + do. When the same file is accessed through aufs (step 0-3) later,
1868 + aufs will detect the status and refresh all necessary data.
1869 + In this mode, aufs has to ignore the event which is fired by aufs
1871 +3. No Extra Validation
1872 + This is the simplest test and doesn't add any additional revalidation
1873 + test, and skip the revalidation in step 4. It is useful and improves
1874 + aufs performance when system surely hide the aufs branches from user,
1875 + by over-mounting something (or another method).
1876 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1877 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1878 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-04-15 08:49:13.394483860 +0200
1881 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1883 +# This program is free software; you can redistribute it and/or modify
1884 +# it under the terms of the GNU General Public License as published by
1885 +# the Free Software Foundation; either version 2 of the License, or
1886 +# (at your option) any later version.
1888 +# This program is distributed in the hope that it will be useful,
1889 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1890 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1891 +# GNU General Public License for more details.
1893 +# You should have received a copy of the GNU General Public License
1894 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1896 +Branch Manipulation
1898 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1899 +and changing its permission/attribute, there are a lot of works to do.
1903 +----------------------------------------------------------------------
1904 +o Confirm the adding dir exists outside of aufs, including loopback
1905 + mount, and its various attributes.
1906 +o Initialize the xino file and whiteout bases if necessary.
1909 +o Check the owner/group/mode of the directory
1910 + When the owner/group/mode of the adding directory differs from the
1911 + existing branch, aufs issues a warning because it may impose a
1913 + For example, when a upper writable branch has a world writable empty
1914 + top directory, a malicious user can create any files on the writable
1915 + branch directly, like copy-up and modify manually. If something like
1916 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1917 + writable branch, and the writable branch is world-writable, then a
1918 + malicious guy may create /etc/passwd on the writable branch directly
1919 + and the infected file will be valid in aufs.
1920 + I am afraid it can be a security issue, but aufs can do nothing except
1921 + producing a warning.
1925 +----------------------------------------------------------------------
1926 +o Confirm the deleting branch is not busy
1927 + To be general, there is one merit to adopt "remount" interface to
1928 + manipulate branches. It is to discard caches. At deleting a branch,
1929 + aufs checks the still cached (and connected) dentries and inodes. If
1930 + there are any, then they are all in-use. An inode without its
1931 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1933 + For the cached one, aufs checks whether the same named entry exists on
1935 + If the cached one is a directory, because aufs provides a merged view
1936 + to users, as long as one dir is left on any branch aufs can show the
1937 + dir to users. In this case, the branch can be removed from aufs.
1938 + Otherwise aufs rejects deleting the branch.
1940 + If any file on the deleting branch is opened by aufs, then aufs
1944 +Modify the Permission of a Branch
1945 +----------------------------------------------------------------------
1946 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1949 +o rw --> ro: Confirm the modifying branch is not busy
1950 + Aufs rejects the request if any of these conditions are true.
1951 + - a file on the branch is mmap-ed.
1952 + - a regular file on the branch is opened for write and there is no
1953 + same named entry on the upper branch.
1954 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1955 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1956 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-04-15 08:49:13.394483860 +0200
1959 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1961 +# This program is free software; you can redistribute it and/or modify
1962 +# it under the terms of the GNU General Public License as published by
1963 +# the Free Software Foundation; either version 2 of the License, or
1964 +# (at your option) any later version.
1966 +# This program is distributed in the hope that it will be useful,
1967 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1968 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1969 +# GNU General Public License for more details.
1971 +# You should have received a copy of the GNU General Public License
1972 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1974 +Policies to Select One among Multiple Writable Branches
1975 +----------------------------------------------------------------------
1976 +When the number of writable branch is more than one, aufs has to decide
1977 +the target branch for file creation or copy-up. By default, the highest
1978 +writable branch which has the parent (or ancestor) dir of the target
1979 +file is chosen (top-down-parent policy).
1980 +By user's request, aufs implements some other policies to select the
1981 +writable branch, for file creation several policies, round-robin,
1982 +most-free-space, and other policies. For copy-up, top-down-parent,
1983 +bottom-up-parent, bottom-up and others.
1985 +As expected, the round-robin policy selects the branch in circular. When
1986 +you have two writable branches and creates 10 new files, 5 files will be
1987 +created for each branch. mkdir(2) systemcall is an exception. When you
1988 +create 10 new directories, all will be created on the same branch.
1989 +And the most-free-space policy selects the one which has most free
1990 +space among the writable branches. The amount of free space will be
1991 +checked by aufs internally, and users can specify its time interval.
1993 +The policies for copy-up is more simple,
1994 +top-down-parent is equivalent to the same named on in create policy,
1995 +bottom-up-parent selects the writable branch where the parent dir
1996 +exists and the nearest upper one from the copyup-source,
1997 +bottom-up selects the nearest upper writable branch from the
1998 +copyup-source, regardless the existence of the parent dir.
2000 +There are some rules or exceptions to apply these policies.
2001 +- If there is a readonly branch above the policy-selected branch and
2002 + the parent dir is marked as opaque (a variation of whiteout), or the
2003 + target (creating) file is whiteout-ed on the upper readonly branch,
2004 + then the result of the policy is ignored and the target file will be
2005 + created on the nearest upper writable branch than the readonly branch.
2006 +- If there is a writable branch above the policy-selected branch and
2007 + the parent dir is marked as opaque or the target file is whiteouted
2008 + on the branch, then the result of the policy is ignored and the target
2009 + file will be created on the highest one among the upper writable
2010 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2012 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2013 + They try selecting the branch where the source exists as possible
2014 + since copyup a large file will take long time. If it can't be,
2015 + ie. the branch where the source exists is readonly, then they will
2016 + follow the copyup policy.
2017 +- There is an exception for rename(2) when the target exists.
2018 + If the rename target exists, aufs compares the index of the branches
2019 + where the source and the target exists and selects the higher
2020 + one. If the selected branch is readonly, then aufs follows the
2022 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2023 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2024 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2027 +// to view this graph, run dot(1) command in GRAPHVIZ.
2031 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2035 +aufs_rename -> whinfo [label="store/remove"];
2038 +inode_list [label="h_inum list in branch\ncache"];
2041 +whinode [label="h_inum list file"];
2044 +brmgmt [label="br_add/del/mod/umount"];
2046 +brmgmt -> inode_list [label="create/remove"];
2047 +brmgmt -> whinode [label="load/store"];
2049 +inode_list -> whinode [style=dashed,dir=both];
2051 +aufs_rename -> inode_list [label="add/del"];
2053 +aufs_lookup -> inode_list [label="search"];
2055 +aufs_lookup -> whinfo [label="load/remove"];
2057 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2058 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2059 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-04-15 08:49:13.394483860 +0200
2062 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2064 +# This program is free software; you can redistribute it and/or modify
2065 +# it under the terms of the GNU General Public License as published by
2066 +# the Free Software Foundation; either version 2 of the License, or
2067 +# (at your option) any later version.
2069 +# This program is distributed in the hope that it will be useful,
2070 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2071 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2072 +# GNU General Public License for more details.
2074 +# You should have received a copy of the GNU General Public License
2075 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2077 +Special handling for renaming a directory (DIRREN)
2078 +----------------------------------------------------------------------
2079 +First, let's assume we have a simple usecase.
2083 +- /ro/dirA and /ro/dirA/file exist too
2084 +- there is no dirB on both branches
2085 +- a user issues rename("dirA", "dirB")
2087 +Now, what should aufs behave against this rename(2)?
2088 +There are a few possible cases.
2091 + since dirA exists on a readonly branch which cannot be renamed.
2093 + it is possible to copy-up dirA (only the dir itself), but the child
2094 + entries ("file" in this case) should not be. it must be a bad
2095 + approach to copy-up recursively.
2096 +C. returns a success.
2097 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2098 + is a violation of aufs' policy.
2099 +D. construct an extra information which indicates that /ro/dirA should
2100 + be handled as the name of dirB.
2101 + overlayfs has a similar feature called REDIRECT.
2103 +Until now, aufs implements the case B only which returns EXDEV, and
2104 +expects the userspace application behaves like mv(1) which tries
2105 +issueing rename(2) recursively.
2107 +A new aufs feature called DIRREN is introduced which implements the case
2108 +D. There are several "extra information" added.
2110 +1. detailed info per renamed directory
2111 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2112 +2. the inode-number list of directories on a branch
2113 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2115 +The filename of "detailed info per directory" represents the lower
2116 +branch, and its format is
2117 +- a type of the branch id
2119 + + uuid (not implemented yet)
2122 +- the inode-number of the branch root dir
2124 +And it contains these info in a single regular file.
2126 +- branch's inode-number of the logically renamed dir
2127 +- the name of the before-renamed dir
2129 +The "detailed info per directory" file is created in aufs rename(2), and
2130 +loaded in any lookup.
2131 +The info is considered in lookup for the matching case only. Here
2132 +"matching" means that the root of branch (in the info filename) is same
2133 +to the current looking-up branch. After looking-up the before-renamed
2134 +name, the inode-number is compared. And the matched dentry is used.
2136 +The "inode-number list of directories" is a regular file which contains
2137 +simply the inode-numbers on the branch. The file is created or updated
2138 +in removing the branch, and loaded in adding the branch. Its lifetime is
2139 +equal to the branch.
2140 +The list is refered in lookup, and when the current target inode is
2141 +found in the list, the aufs tries loading the "detailed info per
2142 +directory" and get the changed and valid name of the dir.
2144 +Theoretically these "extra informaiton" may be able to be put into XATTR
2145 +in the dir inode. But aufs doesn't choose this way because
2146 +1. XATTR may not be supported by the branch (or its configuration)
2147 +2. XATTR may have its size limit.
2148 +3. XATTR may be less easy to convert than a regular file, when the
2149 + format of the info is changed in the future.
2150 +At the same time, I agree that the regular file approach is much slower
2151 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2154 +This DIRREN feature is enabled by aufs configuration, and is activated
2155 +by a new mount option.
2157 +For the more complicated case, there is a work with UDBA option, which
2158 +is to dected the direct access to the branches (by-passing aufs) and to
2159 +maintain the cashes in aufs. Since a single cached aufs dentry may
2160 +contains two names, before- and after-rename, the name comparision in
2161 +UDBA handler may not work correctly. In this case, the behaviour will be
2162 +equivalen to udba=reval case.
2163 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2164 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2165 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-04-15 08:49:13.394483860 +0200
2168 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2170 +# This program is free software; you can redistribute it and/or modify
2171 +# it under the terms of the GNU General Public License as published by
2172 +# the Free Software Foundation; either version 2 of the License, or
2173 +# (at your option) any later version.
2175 +# This program is distributed in the hope that it will be useful,
2176 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2177 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2178 +# GNU General Public License for more details.
2180 +# You should have received a copy of the GNU General Public License
2181 +# along with this program; if not, write to the Free Software
2182 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2185 +File-based Hierarchical Storage Management (FHSM)
2186 +----------------------------------------------------------------------
2187 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2188 +storage world. Aufs provides this feature as file-based with multiple
2189 +writable branches, based upon the principle of "Colder, the Lower".
2190 +Here the word "colder" means that the less used files, and "lower" means
2191 +that the position in the order of the stacked branches vertically.
2192 +These multiple writable branches are prioritized, ie. the topmost one
2193 +should be the fastest drive and be used heavily.
2195 +o Characters in aufs FHSM story
2196 +- aufs itself and a new branch attribute.
2197 +- a new ioctl interface to move-down and to establish a connection with
2198 + the daemon ("move-down" is a converse of "copy-up").
2199 +- userspace tool and daemon.
2201 +The userspace daemon establishes a connection with aufs and waits for
2202 +the notification. The notified information is very similar to struct
2203 +statfs containing the number of consumed blocks and inodes.
2204 +When the consumed blocks/inodes of a branch exceeds the user-specified
2205 +upper watermark, the daemon activates its move-down process until the
2206 +consumed blocks/inodes reaches the user-specified lower watermark.
2208 +The actual move-down is done by aufs based upon the request from
2209 +user-space since we need to maintain the inode number and the internal
2210 +pointer arrays in aufs.
2212 +Currently aufs FHSM handles the regular files only. Additionally they
2213 +must not be hard-linked nor pseudo-linked.
2216 +o Cowork of aufs and the user-space daemon
2217 + During the userspace daemon established the connection, aufs sends a
2218 + small notification to it whenever aufs writes something into the
2219 + writable branch. But it may cost high since aufs issues statfs(2)
2220 + internally. So user can specify a new option to cache the
2221 + info. Actually the notification is controlled by these factors.
2222 + + the specified cache time.
2223 + + classified as "force" by aufs internally.
2224 + Until the specified time expires, aufs doesn't send the info
2225 + except the forced cases. When aufs decide forcing, the info is always
2226 + notified to userspace.
2227 + For example, the number of free inodes is generally large enough and
2228 + the shortage of it happens rarely. So aufs doesn't force the
2229 + notification when creating a new file, directory and others. This is
2230 + the typical case which aufs doesn't force.
2231 + When aufs writes the actual filedata and the files consumes any of new
2232 + blocks, the aufs forces notifying.
2235 +o Interfaces in aufs
2236 +- New branch attribute.
2238 + Specifies that the branch is managed by FHSM feature. In other word,
2239 + participant in the FHSM.
2240 + When nofhsm is set to the branch, it will not be the source/target
2241 + branch of the move-down operation. This attribute is set
2242 + independently from coo and moo attributes, and if you want full
2243 + FHSM, you should specify them as well.
2244 +- New mount option.
2246 + Specifies a second to suppress many less important info to be
2249 + + AUFS_CTL_FHSM_FD
2250 + create a new file descriptor which userspace can read the notification
2251 + (a subset of struct statfs) from aufs.
2252 +- Module parameter 'brs'
2253 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2255 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2256 + When there are two or more branches with fhsm attributes,
2257 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2258 + terminates it. As a result of remounting and branch-manipulation, the
2259 + number of branches with fhsm attribute can be one. In this case,
2260 + /sbin/mount.aufs will terminate the user-space daemon.
2263 +Finally the operation is done as these steps in kernel-space.
2265 + + no one else is using the file.
2266 + + the file is not hard-linked.
2267 + + the file is not pseudo-linked.
2268 + + the file is a regular file.
2269 + + the parent dir is not opaqued.
2270 +- find the target writable branch.
2271 +- make sure the file is not whiteout-ed by the upper (than the target)
2273 +- make the parent dir on the target branch.
2274 +- mutex lock the inode on the branch.
2275 +- unlink the whiteout on the target branch (if exists).
2276 +- lookup and create the whiteout-ed temporary name on the target branch.
2277 +- copy the file as the whiteout-ed temporary name on the target branch.
2278 +- rename the whiteout-ed temporary name to the original name.
2279 +- unlink the file on the source branch.
2280 +- maintain the internal pointer array and the external inode number
2282 +- maintain the timestamps and other attributes of the parent dir and the
2285 +And of course, in every step, an error may happen. So the operation
2286 +should restore the original file state after an error happens.
2287 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2288 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2289 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-04-15 08:49:13.394483860 +0200
2292 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2294 +# This program is free software; you can redistribute it and/or modify
2295 +# it under the terms of the GNU General Public License as published by
2296 +# the Free Software Foundation; either version 2 of the License, or
2297 +# (at your option) any later version.
2299 +# This program is distributed in the hope that it will be useful,
2300 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2301 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2302 +# GNU General Public License for more details.
2304 +# You should have received a copy of the GNU General Public License
2305 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2307 +mmap(2) -- File Memory Mapping
2308 +----------------------------------------------------------------------
2309 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2310 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2312 +This approach is simple and good, but there is one problem.
2313 +Under /proc, several entries show the mmapped files by its path (with
2314 +device and inode number), and the printed path will be the path on the
2315 +branch fs's instead of virtual aufs's.
2316 +This is not a problem in most cases, but some utilities lsof(1) (and its
2317 +user) may expect the path on aufs.
2319 +To address this issue, aufs adds a new member called vm_prfile in struct
2320 +vm_area_struct (and struct vm_region). The original vm_file points to
2321 +the file on the branch fs in order to handle everything correctly as
2322 +usual. The new vm_prfile points to a virtual file in aufs, and the
2323 +show-functions in procfs refers to vm_prfile if it is set.
2324 +Also we need to maintain several other places where touching vm_file
2326 +- fork()/clone() copies vma and the reference count of vm_file is
2328 +- merging vma maintains the ref count too.
2330 +This is not a good approach. It just fakes the printed path. But it
2331 +leaves all behaviour around f_mapping unchanged. This is surely an
2333 +Actually aufs had adopted another complicated approach which calls
2334 +generic_file_mmap() and handles struct vm_operations_struct. In this
2335 +approach, aufs met a hard problem and I could not solve it without
2336 +switching the approach.
2338 +There may be one more another approach which is
2339 +- bind-mount the branch-root onto the aufs-root internally
2340 +- grab the new vfsmount (ie. struct mount)
2341 +- lazy-umount the branch-root internally
2342 +- in open(2) the aufs-file, open the branch-file with the hidden
2343 + vfsmount (instead of the original branch's vfsmount)
2344 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2345 + but it may be possible from userspace by the mount helper.
2347 +Adding the internal hidden vfsmount and using it in opening a file, the
2348 +file path under /proc will be printed correctly. This approach looks
2349 +smarter, but is not possible I am afraid.
2350 +- aufs-root may be bind-mount later. when it happens, another hidden
2351 + vfsmount will be required.
2352 +- it is hard to get the chance to bind-mount and lazy-umount
2353 + + in kernel-space, FS can have vfsmount in open(2) via
2354 + file->f_path, and aufs can know its vfsmount. But several locks are
2355 + already acquired, and if aufs tries to bind-mount and lazy-umount
2356 + here, then it may cause a deadlock.
2357 + + in user-space, bind-mount doesn't invoke the mount helper.
2358 +- since /proc shows dev and ino, aufs has to give vma these info. it
2359 + means a new member vm_prinode will be necessary. this is essentially
2360 + equivalent to vm_prfile described above.
2362 +I have to give up this "looks-smater" approach.
2363 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2364 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2365 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-04-15 08:49:13.394483860 +0200
2368 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2370 +# This program is free software; you can redistribute it and/or modify
2371 +# it under the terms of the GNU General Public License as published by
2372 +# the Free Software Foundation; either version 2 of the License, or
2373 +# (at your option) any later version.
2375 +# This program is distributed in the hope that it will be useful,
2376 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2377 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2378 +# GNU General Public License for more details.
2380 +# You should have received a copy of the GNU General Public License
2381 +# along with this program; if not, write to the Free Software
2382 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2385 +Listing XATTR/EA and getting the value
2386 +----------------------------------------------------------------------
2387 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2388 +shows the values from the topmost existing file. This behaviour is good
2389 +for the non-dir entries since the bahaviour exactly matches the shown
2390 +information. But for the directories, aufs considers all the same named
2391 +entries on the lower branches. Which means, if one of the lower entry
2392 +rejects readdir call, then aufs returns an error even if the topmost
2393 +entry allows it. This behaviour is necessary to respect the branch fs's
2394 +security, but can make users confused since the user-visible standard
2395 +attributes don't match the behaviour.
2396 +To address this issue, aufs has a mount option called dirperm1 which
2397 +checks the permission for the topmost entry only, and ignores the lower
2398 +entry's permission.
2400 +A similar issue can happen around XATTR.
2401 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2402 +always set. Otherwise these very unpleasant situation would happen.
2403 +- listxattr(2) may return the duplicated entries.
2404 +- users may not be able to remove or reset the XATTR forever,
2407 +XATTR/EA support in the internal (copy,move)-(up,down)
2408 +----------------------------------------------------------------------
2409 +Generally the extended attributes of inode are categorized as these.
2410 +- "security" for LSM and capability.
2411 +- "system" for posix ACL, 'acl' mount option is required for the branch
2413 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2414 +- "user" for userspace, 'user_xattr' mount option is required for the
2415 + branch fs generally.
2417 +Moreover there are some other categories. Aufs handles these rather
2418 +unpopular categories as the ordinary ones, ie. there is no special
2419 +condition nor exception.
2421 +In copy-up, the support for XATTR on the dst branch may differ from the
2422 +src branch. In this case, the copy-up operation will get an error and
2423 +the original user operation which triggered the copy-up will fail. It
2424 +can happen that even all copy-up will fail.
2425 +When both of src and dst branches support XATTR and if an error occurs
2426 +during copying XATTR, then the copy-up should fail obviously. That is a
2427 +good reason and aufs should return an error to userspace. But when only
2428 +the src branch support that XATTR, aufs should not return an error.
2429 +For example, the src branch supports ACL but the dst branch doesn't
2430 +because the dst branch may natively un-support it or temporary
2431 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2432 +may NOT return an error even if the XATTR is not supported. It is
2433 +totally up to the branch fs.
2435 +Anyway when the aufs internal copy-up gets an error from the dst branch
2436 +fs, then aufs tries removing the just copied entry and returns the error
2437 +to the userspace. The worst case of this situation will be all copy-up
2440 +For the copy-up operation, there two basic approaches.
2441 +- copy the specified XATTR only (by category above), and return the
2442 + error unconditionally if it happens.
2443 +- copy all XATTR, and ignore the error on the specified category only.
2445 +In order to support XATTR and to implement the correct behaviour, aufs
2446 +chooses the latter approach and introduces some new branch attributes,
2447 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2448 +They correspond to the XATTR namespaces (see above). Additionally, to be
2449 +convenient, "icex" is also provided which means all "icex*" attributes
2450 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2452 +The meaning of these attributes is to ignore the error from setting
2453 +XATTR on that branch.
2454 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2455 +error from the dst branch according to the specified attributes.
2457 +Some XATTR may have its default value. The default value may come from
2458 +the parent dir or the environment. If the default value is set at the
2459 +file creating-time, it will be overwritten by copy-up.
2460 +Some contradiction may happen I am afraid.
2461 +Do we need another attribute to stop copying XATTR? I am unsure. For
2462 +now, aufs implements the branch attributes to ignore the error.
2463 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2464 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2465 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-04-15 08:49:13.394483860 +0200
2468 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2470 +# This program is free software; you can redistribute it and/or modify
2471 +# it under the terms of the GNU General Public License as published by
2472 +# the Free Software Foundation; either version 2 of the License, or
2473 +# (at your option) any later version.
2475 +# This program is distributed in the hope that it will be useful,
2476 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2477 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2478 +# GNU General Public License for more details.
2480 +# You should have received a copy of the GNU General Public License
2481 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2483 +Export Aufs via NFS
2484 +----------------------------------------------------------------------
2485 +Here is an approach.
2486 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2488 +- iget_locked(): initialize aufs inode generation for a new inode, and
2489 + store it in xigen file.
2490 +- destroy_inode(): increment aufs inode generation and store it in xigen
2491 + file. it is necessary even if it is not unlinked, because any data of
2492 + inode may be changed by UDBA.
2493 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2494 + build file handle by
2495 + + branch id (4 bytes)
2496 + + superblock generation (4 bytes)
2497 + + inode number (4 or 8 bytes)
2498 + + parent dir inode number (4 or 8 bytes)
2499 + + inode generation (4 bytes))
2500 + + return value of exportfs_encode_fh() for the parent on a branch (4
2502 + + file handle for a branch (by exportfs_encode_fh())
2504 + + find the index of a branch from its id in handle, and check it is
2505 + still exist in aufs.
2506 + + 1st level: get the inode number from handle and search it in cache.
2507 + + 2nd level: if not found in cache, get the parent inode number from
2508 + the handle and search it in cache. and then open the found parent
2509 + dir, find the matching inode number by vfs_readdir() and get its
2510 + name, and call lookup_one_len() for the target dentry.
2511 + + 3rd level: if the parent dir is not cached, call
2512 + exportfs_decode_fh() for a branch and get the parent on a branch,
2513 + build a pathname of it, convert it a pathname in aufs, call
2514 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2516 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2517 + for every branch, but not itself. to get this, (currently) aufs
2518 + searches in current->nsproxy->mnt_ns list. it may not be a good
2519 + idea, but I didn't get other approach.
2520 + + test the generation of the gotten inode.
2521 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2522 + convert it into ESTALE for NFSD.
2523 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2524 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2525 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2526 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2527 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-04-15 08:49:13.394483860 +0200
2530 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2532 +# This program is free software; you can redistribute it and/or modify
2533 +# it under the terms of the GNU General Public License as published by
2534 +# the Free Software Foundation; either version 2 of the License, or
2535 +# (at your option) any later version.
2537 +# This program is distributed in the hope that it will be useful,
2538 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2539 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2540 +# GNU General Public License for more details.
2542 +# You should have received a copy of the GNU General Public License
2543 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2545 +Show Whiteout Mode (shwh)
2546 +----------------------------------------------------------------------
2547 +Generally aufs hides the name of whiteouts. But in some cases, to show
2548 +them is very useful for users. For instance, creating a new middle layer
2549 +(branch) by merging existing layers.
2551 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2552 +When you have three branches,
2553 +- Bottom: 'system', squashfs (underlying base system), read-only
2554 +- Middle: 'mods', squashfs, read-only
2555 +- Top: 'overlay', ram (tmpfs), read-write
2557 +The top layer is loaded at boot time and saved at shutdown, to preserve
2558 +the changes made to the system during the session.
2559 +When larger changes have been made, or smaller changes have accumulated,
2560 +the size of the saved top layer data grows. At this point, it would be
2561 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2562 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2563 +restoring save and load speed.
2565 +This merging is simplified by the use of another aufs mount, of just the
2566 +two overlay branches using the 'shwh' option.
2567 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2568 + aufs /livesys/merge_union
2570 +A merged view of these two branches is then available at
2571 +/livesys/merge_union, and the new feature is that the whiteouts are
2573 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2574 +writing to all branches. Also the default mode for all branches is 'ro'.
2575 +It is now possible to save the combined contents of the two overlay
2576 +branches to a new squashfs, e.g.:
2577 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2579 +This new squashfs archive can be stored on the boot device and the
2580 +initramfs will use it to replace the old one at the next boot.
2581 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2582 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2583 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-04-15 08:49:13.394483860 +0200
2586 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2588 +# This program is free software; you can redistribute it and/or modify
2589 +# it under the terms of the GNU General Public License as published by
2590 +# the Free Software Foundation; either version 2 of the License, or
2591 +# (at your option) any later version.
2593 +# This program is distributed in the hope that it will be useful,
2594 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2595 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2596 +# GNU General Public License for more details.
2598 +# You should have received a copy of the GNU General Public License
2599 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2601 +Dynamically customizable FS operations
2602 +----------------------------------------------------------------------
2603 +Generally FS operations (struct inode_operations, struct
2604 +address_space_operations, struct file_operations, etc.) are defined as
2605 +"static const", but it never means that FS have only one set of
2606 +operation. Some FS have multiple sets of them. For instance, ext2 has
2607 +three sets, one for XIP, for NOBH, and for normal.
2608 +Since aufs overrides and redirects these operations, sometimes aufs has
2609 +to change its behaviour according to the branch FS type. More importantly
2610 +VFS acts differently if a function (member in the struct) is set or
2611 +not. It means aufs should have several sets of operations and select one
2612 +among them according to the branch FS definition.
2614 +In order to solve this problem and not to affect the behaviour of VFS,
2615 +aufs defines these operations dynamically. For instance, aufs defines
2616 +dummy direct_IO function for struct address_space_operations, but it may
2617 +not be set to the address_space_operations actually. When the branch FS
2618 +doesn't have it, aufs doesn't set it to its address_space_operations
2619 +while the function definition itself is still alive. So the behaviour
2620 +itself will not change, and it will return an error when direct_IO is
2623 +The lifetime of these dynamically generated operation object is
2624 +maintained by aufs branch object. When the branch is removed from aufs,
2625 +the reference counter of the object is decremented. When it reaches
2626 +zero, the dynamically generated operation object will be freed.
2628 +This approach is designed to support AIO (io_submit), Direct I/O and
2630 +Currently this approach is applied to address_space_operations for
2631 +regular files only.
2632 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2633 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2634 +++ linux/Documentation/filesystems/aufs/README 2017-07-29 12:14:25.893041746 +0200
2637 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2643 +----------------------------------------
2644 +In the early days, aufs was entirely re-designed and re-implemented
2645 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2646 +improvements and implementations, it becomes totally different from
2647 +Unionfs while keeping the basic features.
2648 +Recently, Unionfs Version 2.x series begin taking some of the same
2649 +approaches to aufs1's.
2650 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2651 +University and his team.
2653 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2654 +If you want older kernel version support, try aufs2-2.6.git or
2655 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2657 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2658 + According to Christoph Hellwig, linux rejects all union-type
2659 + filesystems but UnionMount.
2660 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2662 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2663 + UnionMount, and he pointed out an issue around a directory mutex
2664 + lock and aufs addressed it. But it is still unsure whether aufs will
2665 + be merged (or any other union solution).
2666 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2670 +----------------------------------------
2671 +- unite several directories into a single virtual filesystem. The member
2672 + directory is called as a branch.
2673 +- you can specify the permission flags to the branch, which are 'readonly',
2674 + 'readwrite' and 'whiteout-able.'
2675 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2676 + readonly branch are modifiable logically.
2677 +- dynamic branch manipulation, add, del.
2680 +Also there are many enhancements in aufs, such as:
2681 +- test only the highest one for the directory permission (dirperm1)
2682 +- copyup on open (coo=)
2683 +- 'move' policy for copy-up between two writable branches, after
2684 + checking free space.
2686 +- readdir(3) in userspace.
2687 +- keep inode number by external inode number table
2688 +- keep the timestamps of file/dir in internal copyup operation
2689 +- seekable directory, supporting NFS readdir.
2690 +- whiteout is hardlinked in order to reduce the consumption of inodes
2692 +- do not copyup, nor create a whiteout when it is unnecessary
2693 +- revert a single systemcall when an error occurs in aufs
2694 +- remount interface instead of ioctl
2695 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2696 +- loopback mounted filesystem as a branch
2697 +- kernel thread for removing the dir who has a plenty of whiteouts
2698 +- support copyup sparse file (a file which has a 'hole' in it)
2699 +- default permission flags for branches
2700 +- selectable permission flags for ro branch, whether whiteout can
2703 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2704 +- support multiple writable branches, some policies to select one
2705 + among multiple writable branches.
2706 +- a new semantics for link(2) and rename(2) to support multiple
2707 + writable branches.
2708 +- no glibc changes are required.
2709 +- pseudo hardlink (hardlink over branches)
2710 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2711 + including NFS or remote filesystem branch.
2712 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2715 +Currently these features are dropped temporary from aufs4.
2716 +See design/08plan.txt in detail.
2717 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2719 +- statistics of aufs thread (/sys/fs/aufs/stat)
2721 +Features or just an idea in the future (see also design/*.txt),
2722 +- reorder the branch index without del/re-add.
2723 +- permanent xino files for NFSD
2724 +- an option for refreshing the opened files after add/del branches
2725 +- light version, without branch manipulation. (unnecessary?)
2726 +- copyup in userspace
2727 +- inotify in userspace
2732 +----------------------------------------
2733 +There are three GIT trees for aufs4, aufs4-linux.git,
2734 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2736 +While the aufs-util is always necessary, you need either of aufs4-linux
2737 +or aufs4-standalone.
2739 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2740 +git://git.kernel.org/.../torvalds/linux.git.
2741 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2742 +build aufs4 as an external kernel module.
2743 +Several extra patches are not included in this tree. Only
2744 +aufs4-standalone tree contains them. They are described in the later
2745 +section "Configuration and Compilation."
2747 +On the other hand, the aufs4-standalone tree has only aufs source files
2748 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2749 +But you need to apply all aufs patches manually.
2751 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2752 +represents the linux kernel version, "linux-4.x". For instance,
2753 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2754 +"aufs4.x-rcN" branch.
2757 +$ git clone --reference /your/linux/git/tree \
2758 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2759 +- if you don't have linux GIT tree, then remove "--reference ..."
2760 +$ cd aufs4-linux.git
2761 +$ git checkout origin/aufs4.0
2763 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2764 +leave the patch-work to GIT.
2765 +$ cd /your/linux/git/tree
2766 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2768 +$ git checkout -b my4.0 v4.0
2769 +$ (add your local change...)
2770 +$ git pull aufs4 aufs4.0
2771 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2772 +- you may need to solve some conflicts between your_changes and
2773 + aufs4.0. in this case, git-rerere is recommended so that you can
2774 + solve the similar conflicts automatically when you upgrade to 4.1 or
2775 + later in the future.
2777 +o aufs4-standalone tree
2778 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2779 +$ cd aufs4-standalone.git
2780 +$ git checkout origin/aufs4.0
2783 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2784 +- note that the public aufs-util.git is on SourceForge instead of
2787 +$ git checkout origin/aufs4.0
2789 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2790 +The minor version number, 'x' in '4.x', of aufs may not always
2791 +follow the minor version number of the kernel.
2792 +Because changes in the kernel that cause the use of a new
2793 +minor version number do not always require changes to aufs-util.
2795 +Since aufs-util has its own minor version number, you may not be
2796 +able to find a GIT branch in aufs-util for your kernel's
2797 +exact minor version number.
2798 +In this case, you should git-checkout the branch for the
2799 +nearest lower number.
2801 +For (an unreleased) example:
2802 +If you are using "linux-4.10" and the "aufs4.10" branch
2803 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2804 +or something numerically smaller is the branch for your kernel.
2806 +Also you can view all branches by
2810 +3. Configuration and Compilation
2811 +----------------------------------------
2812 +Make sure you have git-checkout'ed the correct branch.
2814 +For aufs4-linux tree,
2815 +- enable CONFIG_AUFS_FS.
2816 +- set other aufs configurations if necessary.
2818 +For aufs4-standalone tree,
2819 +There are several ways to build.
2822 +- apply ./aufs4-kbuild.patch to your kernel source files.
2823 +- apply ./aufs4-base.patch too.
2824 +- apply ./aufs4-mmap.patch too.
2825 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2826 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2827 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2828 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2829 +- enable CONFIG_AUFS_FS, you can select either
2831 +- and build your kernel as usual.
2832 +- install the built kernel.
2833 + Note: Since linux-3.9, every filesystem module requires an alias
2834 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2835 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2836 +- install the header files too by "make headers_install" to the
2837 + directory where you specify. By default, it is $PWD/usr.
2838 + "make help" shows a brief note for headers_install.
2839 +- and reboot your system.
2842 +- module only (CONFIG_AUFS_FS=m).
2843 +- apply ./aufs4-base.patch to your kernel source files.
2844 +- apply ./aufs4-mmap.patch too.
2845 +- apply ./aufs4-standalone.patch too.
2846 +- build your kernel, don't forget "make headers_install", and reboot.
2847 +- edit ./config.mk and set other aufs configurations if necessary.
2848 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2849 + every aufs configurations.
2850 +- build the module by simple "make".
2851 + Note: Since linux-3.9, every filesystem module requires an alias
2852 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2853 + modules.aliases file.
2854 +- you can specify ${KDIR} make variable which points to your kernel
2856 +- install the files
2857 + + run "make install" to install the aufs module, or copy the built
2858 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2859 + + run "make install_headers" (instead of headers_install) to install
2860 + the modified aufs header file (you can specify DESTDIR which is
2861 + available in aufs standalone version's Makefile only), or copy
2862 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2863 + you like manually. By default, the target directory is $PWD/usr.
2864 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2865 + kernel source tree.
2867 +Note: The header file aufs_type.h is necessary to build aufs-util
2868 + as well as "make headers_install" in the kernel source tree.
2869 + headers_install is subject to be forgotten, but it is essentially
2870 + necessary, not only for building aufs-util.
2871 + You may not meet problems without headers_install in some older
2875 +- read README in aufs-util, build and install it
2876 +- note that your distribution may contain an obsoleted version of
2877 + aufs_type.h in /usr/include/linux or something. When you build aufs
2878 + utilities, make sure that your compiler refers the correct aufs header
2879 + file which is built by "make headers_install."
2880 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2881 + then run "make install_ulib" too. And refer to the aufs manual in
2884 +There several other patches in aufs4-standalone.git. They are all
2885 +optional. When you meet some problems, they will help you.
2886 +- aufs4-loopback.patch
2887 + Supports a nested loopback mount in a branch-fs. This patch is
2888 + unnecessary until aufs produces a message like "you may want to try
2889 + another patch for loopback file".
2891 + Modifies a system global kernel internal function get_next_ino() in
2892 + order to stop assigning 0 for an inode-number. Not directly related to
2893 + aufs, but recommended generally.
2895 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2896 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2897 + duplication of inode number, which is important for backup tools and
2898 + other utilities. When you find aufs XINO files for tmpfs branch
2899 + growing too much, try this patch.
2900 +- lockdep-debug.patch
2901 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2902 + also a caller of VFS functions for branch filesystems, subclassing of
2903 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2904 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2905 + need to apply this debug patch to expand several constant values.
2906 + If don't know what LOCKDEP, then you don't have apply this patch.
2910 +----------------------------------------
2911 +At first, make sure aufs-util are installed, and please read the aufs
2912 +manual, aufs.5 in aufs-util.git tree.
2916 +$ mkdir /tmp/rw /tmp/aufs
2917 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2919 +Here is another example. The result is equivalent.
2920 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2922 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2923 +# mount -o remount,append:${HOME} /tmp/aufs
2925 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2926 +you modify a file under /tmp/aufs, the one on your home directory is
2927 +not affected, instead the same named file will be newly created under
2928 +/tmp/rw. And all of your modification to a file will be applied to
2929 +the one under /tmp/rw. This is called the file based Copy on Write
2931 +Aufs mount options are described in aufs.5.
2932 +If you run chroot or something and make your aufs as a root directory,
2933 +then you need to customize the shutdown script. See the aufs manual in
2936 +Additionally, there are some sample usages of aufs which are a
2937 +diskless system with network booting, and LiveCD over NFS.
2938 +See sample dir in CVS tree on SourceForge.
2942 +----------------------------------------
2943 +When you have any problems or strange behaviour in aufs, please let me
2945 +- /proc/mounts (instead of the output of mount(8))
2946 +- /sys/module/aufs/*
2947 +- /sys/fs/aufs/* (if you have them)
2948 +- /debug/aufs/* (if you have them)
2949 +- linux kernel version
2950 + if your kernel is not plain, for example modified by distributor,
2951 + the url where i can download its source is necessary too.
2952 +- aufs version which was printed at loading the module or booting the
2953 + system, instead of the date you downloaded.
2954 +- configuration (define/undefine CONFIG_AUFS_xxx)
2955 +- kernel configuration or /proc/config.gz (if you have it)
2956 +- behaviour which you think to be incorrect
2957 +- actual operation, reproducible one is better
2958 +- mailto: aufs-users at lists.sourceforge.net
2960 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2961 +and Feature Requests) on SourceForge. Please join and write to
2965 +6. Acknowledgements
2966 +----------------------------------------
2967 +Thanks to everyone who have tried and are using aufs, whoever
2968 +have reported a bug or any feedback.
2970 +Especially donators:
2971 +Tomas Matejicek(slax.org) made a donation (much more than once).
2972 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2973 + scripts) is making "doubling" donations.
2974 + Unfortunately I cannot list all of the donators, but I really
2976 + It ends Aug 2010, but the ordinary donation URL is still available.
2977 + <http://sourceforge.net/donate/index.php?group_id=167503>
2978 +Dai Itasaka made a donation (2007/8).
2979 +Chuck Smith made a donation (2008/4, 10 and 12).
2980 +Henk Schoneveld made a donation (2008/9).
2981 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2982 +Francois Dupoux made a donation (2008/11).
2983 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2984 + aufs2 GIT tree (2009/2).
2985 +William Grant made a donation (2009/3).
2986 +Patrick Lane made a donation (2009/4).
2987 +The Mail Archive (mail-archive.com) made donations (2009/5).
2988 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2989 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2990 +Pavel Pronskiy made a donation (2011/2).
2991 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2992 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2993 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2995 +Sam Liddicott made a donation (2011/9).
2996 +Era Scarecrow made a donation (2013/4).
2997 +Bor Ratajc made a donation (2013/4).
2998 +Alessandro Gorreta made a donation (2013/4).
2999 +POIRETTE Marc made a donation (2013/4).
3000 +Alessandro Gorreta made a donation (2013/4).
3001 +lauri kasvandik made a donation (2013/5).
3002 +"pemasu from Finland" made a donation (2013/7).
3003 +The Parted Magic Project made a donation (2013/9 and 11).
3004 +Pavel Barta made a donation (2013/10).
3005 +Nikolay Pertsev made a donation (2014/5).
3006 +James B made a donation (2014/7 and 2015/7).
3007 +Stefano Di Biase made a donation (2014/8).
3008 +Daniel Epellei made a donation (2015/1).
3009 +OmegaPhil made a donation (2016/1).
3010 +Tomasz Szewczyk made a donation (2016/4).
3011 +James Burry made a donation (2016/12).
3013 +Thank you very much.
3014 +Donations are always, including future donations, very important and
3015 +helpful for me to keep on developing aufs.
3019 +----------------------------------------
3020 +If you are an experienced user, no explanation is needed. Aufs is
3021 +just a linux filesystem.
3026 +# Local variables: ;
3029 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3030 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3031 +++ linux/fs/aufs/aufs.h 2018-04-15 08:49:13.394483860 +0200
3034 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3036 + * This program, aufs is free software; you can redistribute it and/or modify
3037 + * it under the terms of the GNU General Public License as published by
3038 + * the Free Software Foundation; either version 2 of the License, or
3039 + * (at your option) any later version.
3041 + * This program is distributed in the hope that it will be useful,
3042 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3044 + * GNU General Public License for more details.
3046 + * You should have received a copy of the GNU General Public License
3047 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3051 + * all header files
3059 +#define AuStub(type, name, body, ...) \
3060 + static inline type name(__VA_ARGS__) { body; }
3062 +#define AuStubVoid(name, ...) \
3063 + AuStub(void, name, , __VA_ARGS__)
3064 +#define AuStubInt0(name, ...) \
3065 + AuStub(int, name, return 0, __VA_ARGS__)
3069 +#include "branch.h"
3072 +#include "dbgaufs.h"
3073 +#include "dentry.h"
3075 +#include "dirren.h"
3078 +#include "fstype.h"
3082 +#include "module.h"
3086 +#include "sysaufs.h"
3091 +#endif /* __KERNEL__ */
3092 +#endif /* __AUFS_H__ */
3093 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3094 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3095 +++ linux/fs/aufs/branch.c 2018-04-15 08:49:13.394483860 +0200
3098 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3100 + * This program, aufs is free software; you can redistribute it and/or modify
3101 + * it under the terms of the GNU General Public License as published by
3102 + * the Free Software Foundation; either version 2 of the License, or
3103 + * (at your option) any later version.
3105 + * This program is distributed in the hope that it will be useful,
3106 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3107 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3108 + * GNU General Public License for more details.
3110 + * You should have received a copy of the GNU General Public License
3111 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3115 + * branch management
3118 +#include <linux/compat.h>
3119 +#include <linux/statfs.h>
3123 + * free a single branch
3125 +static void au_br_do_free(struct au_branch *br)
3128 + struct au_wbr *wbr;
3129 + struct au_dykey **key;
3131 + au_hnotify_fin_br(br);
3132 + /* always, regardless the mount option */
3133 + au_dr_hino_free(&br->br_dirren);
3135 + if (br->br_xino.xi_file)
3136 + fput(br->br_xino.xi_file);
3137 + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--)
3138 + AuDebugOn(br->br_xino.xi_nondir.array[i]);
3139 + kfree(br->br_xino.xi_nondir.array);
3141 + AuDebugOn(au_br_count(br));
3142 + au_br_count_fin(br);
3146 + for (i = 0; i < AuBrWh_Last; i++)
3147 + dput(wbr->wbr_wh[i]);
3148 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3149 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3152 + if (br->br_fhsm) {
3153 + au_br_fhsm_fin(br->br_fhsm);
3154 + kfree(br->br_fhsm);
3157 + key = br->br_dykey;
3158 + for (i = 0; i < AuBrDynOp; i++, key++)
3164 + /* recursive lock, s_umount of branch's */
3166 + path_put(&br->br_path);
3173 + * frees all branches
3175 +void au_br_free(struct au_sbinfo *sbinfo)
3177 + aufs_bindex_t bmax;
3178 + struct au_branch **br;
3180 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3182 + bmax = sbinfo->si_bbot + 1;
3183 + br = sbinfo->si_branch;
3185 + au_br_do_free(*br++);
3189 + * find the index of a branch which is specified by @br_id.
3191 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3193 + aufs_bindex_t bindex, bbot;
3195 + bbot = au_sbbot(sb);
3196 + for (bindex = 0; bindex <= bbot; bindex++)
3197 + if (au_sbr_id(sb, bindex) == br_id)
3202 +/* ---------------------------------------------------------------------- */
3208 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3209 + struct dentry *h_root)
3211 + if (unlikely(h_adding == h_root
3212 + || au_test_loopback_overlap(sb, h_adding)))
3214 + if (h_adding->d_sb != h_root->d_sb)
3216 + return au_test_subdir(h_adding, h_root)
3217 + || au_test_subdir(h_root, h_adding);
3221 + * returns a newly allocated branch. @new_nbranch is a number of branches
3222 + * after adding a branch.
3224 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3227 + struct au_branch *add_branch;
3228 + struct dentry *root;
3229 + struct inode *inode;
3233 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3234 + if (unlikely(!add_branch))
3236 + add_branch->br_xino.xi_nondir.total = 8; /* initial size */
3237 + add_branch->br_xino.xi_nondir.array
3238 + = kcalloc(add_branch->br_xino.xi_nondir.total, sizeof(ino_t),
3240 + if (unlikely(!add_branch->br_xino.xi_nondir.array))
3243 + err = au_hnotify_init_br(add_branch, perm);
3244 + if (unlikely(err))
3245 + goto out_xinondir;
3247 + if (au_br_writable(perm)) {
3248 + /* may be freed separately at changing the branch permission */
3249 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3251 + if (unlikely(!add_branch->br_wbr))
3255 + if (au_br_fhsm(perm)) {
3256 + err = au_fhsm_br_alloc(add_branch);
3257 + if (unlikely(err))
3261 + root = sb->s_root;
3262 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3264 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3266 + inode = d_inode(root);
3267 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3271 + return add_branch; /* success */
3274 + kfree(add_branch->br_wbr);
3276 + au_hnotify_fin_br(add_branch);
3278 + kfree(add_branch->br_xino.xi_nondir.array);
3280 + kfree(add_branch);
3282 + return ERR_PTR(err);
3286 + * test if the branch permission is legal or not.
3288 +static int test_br(struct inode *inode, int brperm, char *path)
3292 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3297 + pr_err("write permission for readonly mount or inode, %s\n", path);
3305 + * 0: success, the caller will add it
3306 + * plus: success, it is already unified, the caller should ignore it
3309 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3312 + aufs_bindex_t bbot, bindex;
3313 + struct dentry *root, *h_dentry;
3314 + struct inode *inode, *h_inode;
3316 + root = sb->s_root;
3317 + bbot = au_sbbot(sb);
3318 + if (unlikely(bbot >= 0
3319 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3323 + pr_err("%s duplicated\n", add->pathname);
3328 + err = -ENOSPC; /* -E2BIG; */
3329 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3330 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3331 + pr_err("number of branches exceeded %s\n", add->pathname);
3336 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3337 + pr_err("bad index %d\n", add->bindex);
3341 + inode = d_inode(add->path.dentry);
3343 + if (unlikely(!inode->i_nlink)) {
3344 + pr_err("no existence %s\n", add->pathname);
3349 + if (unlikely(inode->i_sb == sb)) {
3350 + pr_err("%s must be outside\n", add->pathname);
3354 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3355 + pr_err("unsupported filesystem, %s (%s)\n",
3356 + add->pathname, au_sbtype(inode->i_sb));
3360 + if (unlikely(inode->i_sb->s_stack_depth)) {
3361 + pr_err("already stacked, %s (%s)\n",
3362 + add->pathname, au_sbtype(inode->i_sb));
3366 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3367 + if (unlikely(err))
3371 + return 0; /* success */
3374 + for (bindex = 0; bindex <= bbot; bindex++)
3375 + if (unlikely(test_overlap(sb, add->path.dentry,
3376 + au_h_dptr(root, bindex)))) {
3377 + pr_err("%s is overlapped\n", add->pathname);
3382 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3383 + h_dentry = au_h_dptr(root, 0);
3384 + h_inode = d_inode(h_dentry);
3385 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3386 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3387 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3388 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3390 + i_uid_read(inode), i_gid_read(inode),
3391 + (inode->i_mode & S_IALLUGO),
3392 + i_uid_read(h_inode), i_gid_read(h_inode),
3393 + (h_inode->i_mode & S_IALLUGO));
3401 + * initialize or clean the whiteouts for an adding branch
3403 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3406 + int err, old_perm;
3407 + aufs_bindex_t bindex;
3408 + struct inode *h_inode;
3409 + struct au_wbr *wbr;
3410 + struct au_hinode *hdir;
3411 + struct dentry *h_dentry;
3413 + err = vfsub_mnt_want_write(au_br_mnt(br));
3414 + if (unlikely(err))
3418 + old_perm = br->br_perm;
3419 + br->br_perm = new_perm;
3422 + bindex = au_br_index(sb, br->br_id);
3423 + if (0 <= bindex) {
3424 + hdir = au_hi(d_inode(sb->s_root), bindex);
3425 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3427 + h_dentry = au_br_dentry(br);
3428 + h_inode = d_inode(h_dentry);
3429 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3432 + err = au_wh_init(br, sb);
3434 + wbr_wh_write_lock(wbr);
3435 + err = au_wh_init(br, sb);
3436 + wbr_wh_write_unlock(wbr);
3439 + au_hn_inode_unlock(hdir);
3441 + inode_unlock(h_inode);
3442 + vfsub_mnt_drop_write(au_br_mnt(br));
3443 + br->br_perm = old_perm;
3445 + if (!err && wbr && !au_br_writable(new_perm)) {
3447 + br->br_wbr = NULL;
3454 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3458 + struct kstatfs kst;
3459 + struct au_wbr *wbr;
3462 + au_rw_init(&wbr->wbr_wh_rwsem);
3463 + atomic_set(&wbr->wbr_wh_running, 0);
3466 + * a limit for rmdir/rename a dir
3467 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3469 + err = vfs_statfs(&br->br_path, &kst);
3470 + if (unlikely(err))
3473 + if (kst.f_namelen >= NAME_MAX)
3474 + err = au_br_init_wh(sb, br, perm);
3476 + pr_err("%pd(%s), unsupported namelen %ld\n",
3478 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3484 +/* initialize a new branch */
3485 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3486 + struct au_opt_add *add)
3489 + struct inode *h_inode;
3492 + spin_lock_init(&br->br_xino.xi_nondir.spin);
3493 + init_waitqueue_head(&br->br_xino.xi_nondir.wqh);
3494 + br->br_perm = add->perm;
3495 + br->br_path = add->path; /* set first, path_get() later */
3496 + spin_lock_init(&br->br_dykey_lock);
3497 + au_br_count_init(br);
3498 + atomic_set(&br->br_xino_running, 0);
3499 + br->br_id = au_new_br_id(sb);
3500 + AuDebugOn(br->br_id < 0);
3502 + /* always, regardless the given option */
3503 + err = au_dr_br_init(sb, br, &add->path);
3504 + if (unlikely(err))
3507 + if (au_br_writable(add->perm)) {
3508 + err = au_wbr_init(br, sb, add->perm);
3509 + if (unlikely(err))
3513 + if (au_opt_test(au_mntflags(sb), XINO)) {
3514 + h_inode = d_inode(add->path.dentry);
3515 + err = au_xino_br(sb, br, h_inode->i_ino,
3516 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3517 + if (unlikely(err)) {
3518 + AuDebugOn(br->br_xino.xi_file);
3523 + sysaufs_br_init(br);
3524 + path_get(&br->br_path);
3525 + goto out; /* success */
3528 + memset(&br->br_path, 0, sizeof(br->br_path));
3533 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3534 + struct au_branch *br, aufs_bindex_t bbot,
3535 + aufs_bindex_t amount)
3537 + struct au_branch **brp;
3539 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3541 + brp = sbinfo->si_branch + bindex;
3542 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3544 + sbinfo->si_bbot++;
3545 + if (unlikely(bbot < 0))
3546 + sbinfo->si_bbot = 0;
3549 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3550 + aufs_bindex_t bbot, aufs_bindex_t amount)
3552 + struct au_hdentry *hdp;
3554 + AuRwMustWriteLock(&dinfo->di_rwsem);
3556 + hdp = au_hdentry(dinfo, bindex);
3557 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3558 + au_h_dentry_init(hdp);
3560 + if (unlikely(bbot < 0))
3561 + dinfo->di_btop = 0;
3564 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3565 + aufs_bindex_t bbot, aufs_bindex_t amount)
3567 + struct au_hinode *hip;
3569 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3571 + hip = au_hinode(iinfo, bindex);
3572 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3573 + au_hinode_init(hip);
3575 + if (unlikely(bbot < 0))
3576 + iinfo->ii_btop = 0;
3579 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3580 + aufs_bindex_t bindex)
3582 + struct dentry *root, *h_dentry;
3583 + struct inode *root_inode, *h_inode;
3584 + aufs_bindex_t bbot, amount;
3586 + root = sb->s_root;
3587 + root_inode = d_inode(root);
3588 + bbot = au_sbbot(sb);
3589 + amount = bbot + 1 - bindex;
3590 + h_dentry = au_br_dentry(br);
3591 + au_sbilist_lock();
3592 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3593 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3594 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3595 + au_set_h_dptr(root, bindex, dget(h_dentry));
3596 + h_inode = d_inode(h_dentry);
3597 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3598 + au_sbilist_unlock();
3601 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3604 + aufs_bindex_t bbot, add_bindex;
3605 + struct dentry *root, *h_dentry;
3606 + struct inode *root_inode;
3607 + struct au_branch *add_branch;
3609 + root = sb->s_root;
3610 + root_inode = d_inode(root);
3611 + IMustLock(root_inode);
3612 + IiMustWriteLock(root_inode);
3613 + err = test_add(sb, add, remount);
3614 + if (unlikely(err < 0))
3618 + goto out; /* success */
3621 + bbot = au_sbbot(sb);
3622 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3623 + err = PTR_ERR(add_branch);
3624 + if (IS_ERR(add_branch))
3627 + err = au_br_init(add_branch, sb, add);
3628 + if (unlikely(err)) {
3629 + au_br_do_free(add_branch);
3633 + add_bindex = add->bindex;
3635 + au_br_do_add(sb, add_branch, add_bindex);
3637 + sysaufs_brs_del(sb, add_bindex);
3638 + au_br_do_add(sb, add_branch, add_bindex);
3639 + sysaufs_brs_add(sb, add_bindex);
3642 + h_dentry = add->path.dentry;
3643 + if (!add_bindex) {
3644 + au_cpup_attr_all(root_inode, /*force*/1);
3645 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3647 + au_add_nlink(root_inode, d_inode(h_dentry));
3650 + * this test/set prevents aufs from handling unnecesary notify events
3651 + * of xino files, in case of re-adding a writable branch which was
3652 + * once detached from aufs.
3654 + if (au_xino_brid(sb) < 0
3655 + && au_br_writable(add_branch->br_perm)
3656 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3657 + && add_branch->br_xino.xi_file
3658 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3659 + au_xino_brid_set(sb, add_branch->br_id);
3665 +/* ---------------------------------------------------------------------- */
3667 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3668 + unsigned long long max __maybe_unused,
3671 + unsigned long long n;
3672 + struct file **p, *f;
3673 + struct hlist_bl_head *files;
3674 + struct hlist_bl_node *pos;
3675 + struct au_finfo *finfo;
3679 + files = &au_sbi(sb)->si_files;
3680 + hlist_bl_lock(files);
3681 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3682 + f = finfo->fi_file;
3684 + && !special_file(file_inode(f)->i_mode)) {
3688 + AuDebugOn(n > max);
3691 + hlist_bl_unlock(files);
3696 +static struct file **au_farray_alloc(struct super_block *sb,
3697 + unsigned long long *max)
3699 + *max = au_nfiles(sb);
3700 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3703 +static void au_farray_free(struct file **a, unsigned long long max)
3705 + unsigned long long ull;
3707 + for (ull = 0; ull < max; ull++)
3713 +/* ---------------------------------------------------------------------- */
3719 +/* to show the line number, do not make it inlined function */
3720 +#define AuVerbose(do_info, fmt, ...) do { \
3722 + pr_info(fmt, ##__VA_ARGS__); \
3725 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3726 + aufs_bindex_t bbot)
3728 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3731 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3732 + aufs_bindex_t bbot)
3734 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3738 + * test if the branch is deletable or not.
3740 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3741 + unsigned int sigen, const unsigned int verbose)
3743 + int err, i, j, ndentry;
3744 + aufs_bindex_t btop, bbot;
3745 + struct au_dcsub_pages dpages;
3746 + struct au_dpage *dpage;
3749 + err = au_dpages_init(&dpages, GFP_NOFS);
3750 + if (unlikely(err))
3752 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3753 + if (unlikely(err))
3756 + for (i = 0; !err && i < dpages.ndpage; i++) {
3757 + dpage = dpages.dpages + i;
3758 + ndentry = dpage->ndentry;
3759 + for (j = 0; !err && j < ndentry; j++) {
3760 + d = dpage->dentries[j];
3761 + AuDebugOn(au_dcount(d) <= 0);
3762 + if (!au_digen_test(d, sigen)) {
3763 + di_read_lock_child(d, AuLock_IR);
3764 + if (unlikely(au_dbrange_test(d))) {
3765 + di_read_unlock(d, AuLock_IR);
3769 + di_write_lock_child(d);
3770 + if (unlikely(au_dbrange_test(d))) {
3771 + di_write_unlock(d);
3774 + err = au_reval_dpath(d, sigen);
3776 + di_downgrade_lock(d, AuLock_IR);
3778 + di_write_unlock(d);
3783 + /* AuDbgDentry(d); */
3784 + btop = au_dbtop(d);
3785 + bbot = au_dbbot(d);
3786 + if (btop <= bindex
3788 + && au_h_dptr(d, bindex)
3789 + && au_test_dbusy(d, btop, bbot)) {
3791 + AuVerbose(verbose, "busy %pd\n", d);
3794 + di_read_unlock(d, AuLock_IR);
3799 + au_dpages_free(&dpages);
3804 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3805 + unsigned int sigen, const unsigned int verbose)
3808 + unsigned long long max, ull;
3809 + struct inode *i, **array;
3810 + aufs_bindex_t btop, bbot;
3812 + array = au_iarray_alloc(sb, &max);
3813 + err = PTR_ERR(array);
3814 + if (IS_ERR(array))
3818 + AuDbg("b%d\n", bindex);
3819 + for (ull = 0; !err && ull < max; ull++) {
3823 + if (i->i_ino == AUFS_ROOT_INO)
3826 + /* AuDbgInode(i); */
3827 + if (au_iigen(i, NULL) == sigen)
3828 + ii_read_lock_child(i);
3830 + ii_write_lock_child(i);
3831 + err = au_refresh_hinode_self(i);
3834 + ii_downgrade_lock(i);
3836 + ii_write_unlock(i);
3841 + btop = au_ibtop(i);
3842 + bbot = au_ibbot(i);
3843 + if (btop <= bindex
3845 + && au_h_iptr(i, bindex)
3846 + && au_test_ibusy(i, btop, bbot)) {
3848 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3851 + ii_read_unlock(i);
3853 + au_iarray_free(array, max);
3859 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3860 + const unsigned int verbose)
3863 + unsigned int sigen;
3865 + sigen = au_sigen(root->d_sb);
3866 + DiMustNoWaiters(root);
3867 + IiMustNoWaiters(d_inode(root));
3868 + di_write_unlock(root);
3869 + err = test_dentry_busy(root, bindex, sigen, verbose);
3871 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3872 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3877 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3878 + struct file **to_free, int *idx)
3881 + unsigned char matched, root;
3882 + aufs_bindex_t bindex, bbot;
3883 + struct au_fidir *fidir;
3884 + struct au_hfile *hfile;
3887 + root = IS_ROOT(file->f_path.dentry);
3890 + to_free[*idx] = file;
3896 + fidir = au_fi(file)->fi_hdir;
3897 + AuDebugOn(!fidir);
3898 + bbot = au_fbbot_dir(file);
3899 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3900 + hfile = fidir->fd_hfile + bindex;
3901 + if (!hfile->hf_file)
3904 + if (hfile->hf_br->br_id == br_id) {
3916 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3917 + struct file **to_free, int opened)
3920 + unsigned long long ull, max;
3921 + aufs_bindex_t btop;
3922 + struct file *file, **array;
3923 + struct dentry *root;
3924 + struct au_hfile *hfile;
3926 + array = au_farray_alloc(sb, &max);
3927 + err = PTR_ERR(array);
3928 + if (IS_ERR(array))
3933 + root = sb->s_root;
3934 + di_write_unlock(root);
3935 + for (ull = 0; ull < max; ull++) {
3936 + file = array[ull];
3937 + if (unlikely(!file))
3940 + /* AuDbg("%pD\n", file); */
3941 + fi_read_lock(file);
3942 + btop = au_fbtop(file);
3943 + if (!d_is_dir(file->f_path.dentry)) {
3944 + hfile = &au_fi(file)->fi_htop;
3945 + if (hfile->hf_br->br_id == br_id)
3948 + err = test_dir_busy(file, br_id, to_free, &idx);
3949 + fi_read_unlock(file);
3950 + if (unlikely(err))
3953 + di_write_lock_child(root);
3954 + au_farray_free(array, max);
3955 + AuDebugOn(idx > opened);
3961 +static void br_del_file(struct file **to_free, unsigned long long opened,
3962 + aufs_bindex_t br_id)
3964 + unsigned long long ull;
3965 + aufs_bindex_t bindex, btop, bbot, bfound;
3966 + struct file *file;
3967 + struct au_fidir *fidir;
3968 + struct au_hfile *hfile;
3970 + for (ull = 0; ull < opened; ull++) {
3971 + file = to_free[ull];
3972 + if (unlikely(!file))
3975 + /* AuDbg("%pD\n", file); */
3976 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3978 + fidir = au_fi(file)->fi_hdir;
3979 + AuDebugOn(!fidir);
3980 + fi_write_lock(file);
3981 + btop = au_fbtop(file);
3982 + bbot = au_fbbot_dir(file);
3983 + for (bindex = btop; bindex <= bbot; bindex++) {
3984 + hfile = fidir->fd_hfile + bindex;
3985 + if (!hfile->hf_file)
3988 + if (hfile->hf_br->br_id == br_id) {
3993 + AuDebugOn(bfound < 0);
3994 + au_set_h_fptr(file, bfound, NULL);
3995 + if (bfound == btop) {
3996 + for (btop++; btop <= bbot; btop++)
3997 + if (au_hf_dir(file, btop)) {
3998 + au_set_fbtop(file, btop);
4002 + fi_write_unlock(file);
4006 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4007 + const aufs_bindex_t bindex,
4008 + const aufs_bindex_t bbot)
4010 + struct au_branch **brp, **p;
4012 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4014 + brp = sbinfo->si_branch + bindex;
4015 + if (bindex < bbot)
4016 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4017 + sbinfo->si_branch[0 + bbot] = NULL;
4018 + sbinfo->si_bbot--;
4020 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4023 + sbinfo->si_branch = p;
4024 + /* harmless error */
4027 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4028 + const aufs_bindex_t bbot)
4030 + struct au_hdentry *hdp, *p;
4032 + AuRwMustWriteLock(&dinfo->di_rwsem);
4034 + hdp = au_hdentry(dinfo, bindex);
4035 + if (bindex < bbot)
4036 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4037 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4040 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4043 + dinfo->di_hdentry = p;
4044 + /* harmless error */
4047 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4048 + const aufs_bindex_t bbot)
4050 + struct au_hinode *hip, *p;
4052 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4054 + hip = au_hinode(iinfo, bindex);
4055 + if (bindex < bbot)
4056 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4057 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4060 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4063 + iinfo->ii_hinode = p;
4064 + /* harmless error */
4067 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4068 + struct au_branch *br)
4070 + aufs_bindex_t bbot;
4071 + struct au_sbinfo *sbinfo;
4072 + struct dentry *root, *h_root;
4073 + struct inode *inode, *h_inode;
4074 + struct au_hinode *hinode;
4076 + SiMustWriteLock(sb);
4078 + root = sb->s_root;
4079 + inode = d_inode(root);
4080 + sbinfo = au_sbi(sb);
4081 + bbot = sbinfo->si_bbot;
4083 + h_root = au_h_dptr(root, bindex);
4084 + hinode = au_hi(inode, bindex);
4085 + h_inode = au_igrab(hinode->hi_inode);
4088 + au_sbilist_lock();
4089 + au_br_do_del_brp(sbinfo, bindex, bbot);
4090 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4091 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4092 + au_sbilist_unlock();
4094 + /* ignore an error */
4095 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4099 + au_br_do_free(br);
4102 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4103 + unsigned long long max, void *arg)
4108 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4111 + unsigned long long opened;
4112 + unsigned int mnt_flags;
4113 + aufs_bindex_t bindex, bbot, br_id;
4114 + unsigned char do_wh, verbose;
4115 + struct au_branch *br;
4116 + struct au_wbr *wbr;
4117 + struct dentry *root;
4118 + struct file **to_free;
4123 + root = sb->s_root;
4124 + bindex = au_find_dbindex(root, del->h_path.dentry);
4127 + goto out; /* success */
4129 + pr_err("%s no such branch\n", del->pathname);
4132 + AuDbg("bindex b%d\n", bindex);
4135 + mnt_flags = au_mntflags(sb);
4136 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4137 + bbot = au_sbbot(sb);
4138 + if (unlikely(!bbot)) {
4139 + AuVerbose(verbose, "no more branches left\n");
4142 + br = au_sbr(sb, bindex);
4143 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4145 + br_id = br->br_id;
4146 + opened = au_br_count(br);
4147 + if (unlikely(opened)) {
4148 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4149 + err = PTR_ERR(to_free);
4150 + if (IS_ERR(to_free))
4153 + err = test_file_busy(sb, br_id, to_free, opened);
4154 + if (unlikely(err)) {
4155 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4161 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4163 + /* instead of WbrWhMustWriteLock(wbr) */
4164 + SiMustWriteLock(sb);
4165 + for (i = 0; i < AuBrWh_Last; i++) {
4166 + dput(wbr->wbr_wh[i]);
4167 + wbr->wbr_wh[i] = NULL;
4171 + err = test_children_busy(root, bindex, verbose);
4172 + if (unlikely(err)) {
4181 + * now we confirmed the branch is deletable.
4182 + * let's free the remaining opened dirs on the branch.
4184 + di_write_unlock(root);
4185 + br_del_file(to_free, opened, br_id);
4186 + di_write_lock_child(root);
4190 + au_br_do_del(sb, bindex, br);
4192 + sysaufs_brs_del(sb, bindex);
4193 + au_br_do_del(sb, bindex, br);
4194 + sysaufs_brs_add(sb, bindex);
4198 + au_cpup_attr_all(d_inode(root), /*force*/1);
4199 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4201 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4202 + if (au_opt_test(mnt_flags, PLINK))
4203 + au_plink_half_refresh(sb, br_id);
4205 + if (au_xino_brid(sb) == br_id)
4206 + au_xino_brid_set(sb, -1);
4207 + goto out; /* success */
4211 + rerr = au_br_init_wh(sb, br, br->br_perm);
4213 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4214 + del->pathname, rerr);
4217 + au_farray_free(to_free, opened);
4221 +/* ---------------------------------------------------------------------- */
4223 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4226 + aufs_bindex_t btop, bbot;
4227 + struct aufs_ibusy ibusy;
4228 + struct inode *inode, *h_inode;
4231 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4234 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4236 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4237 + if (unlikely(err)) {
4244 + si_read_lock(sb, AuLock_FLUSH);
4245 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4249 + ibusy.h_ino = 0; /* invalid */
4250 + inode = ilookup(sb, ibusy.ino);
4252 + || inode->i_ino == AUFS_ROOT_INO
4253 + || au_is_bad_inode(inode))
4256 + ii_read_lock_child(inode);
4257 + btop = au_ibtop(inode);
4258 + bbot = au_ibbot(inode);
4259 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4260 + h_inode = au_h_iptr(inode, ibusy.bindex);
4261 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4262 + ibusy.h_ino = h_inode->i_ino;
4264 + ii_read_unlock(inode);
4268 + si_read_unlock(sb);
4270 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4271 + if (unlikely(err)) {
4280 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4282 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4285 +#ifdef CONFIG_COMPAT
4286 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4288 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4292 +/* ---------------------------------------------------------------------- */
4295 + * change a branch permission
4298 +static void au_warn_ima(void)
4301 + /* since it doesn't support mark_files_ro() */
4302 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4306 +static int do_need_sigen_inc(int a, int b)
4308 + return au_br_whable(a) && !au_br_whable(b);
4311 +static int need_sigen_inc(int old, int new)
4313 + return do_need_sigen_inc(old, new)
4314 + || do_need_sigen_inc(new, old);
4317 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4320 + unsigned int mnt_flags;
4321 + unsigned long long ull, max;
4322 + aufs_bindex_t br_id;
4323 + unsigned char verbose, writer;
4324 + struct file *file, *hf, **array;
4325 + struct au_hfile *hfile;
4327 + mnt_flags = au_mntflags(sb);
4328 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4330 + array = au_farray_alloc(sb, &max);
4331 + err = PTR_ERR(array);
4332 + if (IS_ERR(array))
4336 + br_id = au_sbr_id(sb, bindex);
4337 + for (ull = 0; ull < max; ull++) {
4338 + file = array[ull];
4339 + if (unlikely(!file))
4342 + /* AuDbg("%pD\n", file); */
4343 + fi_read_lock(file);
4344 + if (unlikely(au_test_mmapped(file))) {
4346 + AuVerbose(verbose, "mmapped %pD\n", file);
4348 + FiMustNoWaiters(file);
4349 + fi_read_unlock(file);
4353 + hfile = &au_fi(file)->fi_htop;
4354 + hf = hfile->hf_file;
4355 + if (!d_is_reg(file->f_path.dentry)
4356 + || !(file->f_mode & FMODE_WRITE)
4357 + || hfile->hf_br->br_id != br_id
4358 + || !(hf->f_mode & FMODE_WRITE))
4359 + array[ull] = NULL;
4365 + FiMustNoWaiters(file);
4366 + fi_read_unlock(file);
4374 + for (ull = 0; ull < max; ull++) {
4375 + file = array[ull];
4379 + /* todo: already flushed? */
4381 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4382 + * approach which resets f_mode and calls mnt_drop_write() and
4383 + * file_release_write() for each file, because the branch
4384 + * attribute in aufs world is totally different from the native
4387 + /* fi_read_lock(file); */
4388 + hfile = &au_fi(file)->fi_htop;
4389 + hf = hfile->hf_file;
4390 + /* fi_read_unlock(file); */
4391 + spin_lock(&hf->f_lock);
4392 + writer = !!(hf->f_mode & FMODE_WRITER);
4393 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4394 + spin_unlock(&hf->f_lock);
4396 + put_write_access(file_inode(hf));
4397 + __mnt_drop_write(hf->f_path.mnt);
4402 + au_farray_free(array, max);
4408 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4412 + aufs_bindex_t bindex;
4413 + struct dentry *root;
4414 + struct au_branch *br;
4415 + struct au_br_fhsm *bf;
4417 + root = sb->s_root;
4418 + bindex = au_find_dbindex(root, mod->h_root);
4421 + return 0; /* success */
4423 + pr_err("%s no such branch\n", mod->path);
4426 + AuDbg("bindex b%d\n", bindex);
4428 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4429 + if (unlikely(err))
4432 + br = au_sbr(sb, bindex);
4433 + AuDebugOn(mod->h_root != au_br_dentry(br));
4434 + if (br->br_perm == mod->perm)
4435 + return 0; /* success */
4437 + /* pre-allocate for non-fhsm --> fhsm */
4439 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4440 + err = au_fhsm_br_alloc(br);
4441 + if (unlikely(err))
4444 + br->br_fhsm = NULL;
4447 + if (au_br_writable(br->br_perm)) {
4448 + /* remove whiteout base */
4449 + err = au_br_init_wh(sb, br, mod->perm);
4450 + if (unlikely(err))
4453 + if (!au_br_writable(mod->perm)) {
4454 + /* rw --> ro, file might be mmapped */
4455 + DiMustNoWaiters(root);
4456 + IiMustNoWaiters(d_inode(root));
4457 + di_write_unlock(root);
4458 + err = au_br_mod_files_ro(sb, bindex);
4459 + /* aufs_write_lock() calls ..._child() */
4460 + di_write_lock_child(root);
4462 + if (unlikely(err)) {
4464 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4467 + rerr = au_wbr_init(br, sb, br->br_perm);
4468 + if (unlikely(rerr)) {
4469 + AuIOErr("nested error %d (%d)\n",
4471 + br->br_perm = mod->perm;
4475 + } else if (au_br_writable(mod->perm)) {
4478 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4480 + err = au_wbr_init(br, sb, mod->perm);
4481 + if (unlikely(err)) {
4482 + kfree(br->br_wbr);
4483 + br->br_wbr = NULL;
4487 + if (unlikely(err))
4490 + if (au_br_fhsm(br->br_perm)) {
4491 + if (!au_br_fhsm(mod->perm)) {
4492 + /* fhsm --> non-fhsm */
4493 + au_br_fhsm_fin(br->br_fhsm);
4494 + kfree(br->br_fhsm);
4495 + br->br_fhsm = NULL;
4497 + } else if (au_br_fhsm(mod->perm))
4498 + /* non-fhsm --> fhsm */
4501 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4502 + br->br_perm = mod->perm;
4503 + goto out; /* success */
4512 +/* ---------------------------------------------------------------------- */
4514 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4517 + struct kstatfs kstfs;
4519 + err = vfs_statfs(&br->br_path, &kstfs);
4521 + stfs->f_blocks = kstfs.f_blocks;
4522 + stfs->f_bavail = kstfs.f_bavail;
4523 + stfs->f_files = kstfs.f_files;
4524 + stfs->f_ffree = kstfs.f_ffree;
4529 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4530 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4531 +++ linux/fs/aufs/branch.h 2018-04-15 08:49:13.394483860 +0200
4534 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4536 + * This program, aufs is free software; you can redistribute it and/or modify
4537 + * it under the terms of the GNU General Public License as published by
4538 + * the Free Software Foundation; either version 2 of the License, or
4539 + * (at your option) any later version.
4541 + * This program is distributed in the hope that it will be useful,
4542 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4543 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4544 + * GNU General Public License for more details.
4546 + * You should have received a copy of the GNU General Public License
4547 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4551 + * branch filesystems and xino for them
4554 +#ifndef __AUFS_BRANCH_H__
4555 +#define __AUFS_BRANCH_H__
4559 +#include <linux/mount.h>
4560 +#include "dirren.h"
4565 +/* ---------------------------------------------------------------------- */
4568 +struct au_xino_file {
4569 + struct file *xi_file;
4574 + /* reserved for future use */
4575 + /* unsigned long *bitmap; */
4576 + wait_queue_head_t wqh;
4579 + /* todo: make xino files an array to support huge inode number */
4581 +#ifdef CONFIG_DEBUG_FS
4582 + struct dentry *xi_dbgaufs;
4586 +/* File-based Hierarchical Storage Management */
4587 +struct au_br_fhsm {
4588 +#ifdef CONFIG_AUFS_FHSM
4589 + struct mutex bf_lock;
4590 + unsigned long bf_jiffy;
4591 + struct aufs_stfs bf_stfs;
4596 +/* members for writable branch only */
4597 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4599 + struct au_rwsem wbr_wh_rwsem;
4600 + struct dentry *wbr_wh[AuBrWh_Last];
4601 + atomic_t wbr_wh_running;
4602 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4603 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4604 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4607 + unsigned long long wbr_bytes;
4610 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4611 +#define AuBrDynOp (AuDyLast * 4)
4613 +#ifdef CONFIG_AUFS_HFSNOTIFY
4614 +/* support for asynchronous destruction */
4615 +struct au_br_hfsnotify {
4616 + struct fsnotify_group *hfsn_group;
4620 +/* sysfs entries */
4621 +struct au_brsysfs {
4623 + struct attribute attr;
4632 +/* protected by superblock rwsem */
4634 + struct au_xino_file br_xino;
4636 + aufs_bindex_t br_id;
4639 + struct path br_path;
4640 + spinlock_t br_dykey_lock;
4641 + struct au_dykey *br_dykey[AuBrDynOp];
4642 + struct percpu_counter br_count;
4644 + struct au_wbr *br_wbr;
4645 + struct au_br_fhsm *br_fhsm;
4647 + /* xino truncation */
4648 + atomic_t br_xino_running;
4650 +#ifdef CONFIG_AUFS_HFSNOTIFY
4651 + struct au_br_hfsnotify *br_hfsn;
4654 +#ifdef CONFIG_SYSFS
4655 + /* entries under sysfs per mount-point */
4656 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4659 + struct au_dr_br br_dirren;
4662 +/* ---------------------------------------------------------------------- */
4664 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4666 + return br->br_path.mnt;
4669 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4671 + return br->br_path.dentry;
4674 +static inline struct super_block *au_br_sb(struct au_branch *br)
4676 + return au_br_mnt(br)->mnt_sb;
4679 +static inline void au_br_get(struct au_branch *br)
4681 + percpu_counter_inc(&br->br_count);
4684 +static inline void au_br_put(struct au_branch *br)
4686 + percpu_counter_dec(&br->br_count);
4689 +static inline s64 au_br_count(struct au_branch *br)
4691 + return percpu_counter_sum(&br->br_count);
4694 +static inline void au_br_count_init(struct au_branch *br)
4696 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4699 +static inline void au_br_count_fin(struct au_branch *br)
4701 + percpu_counter_destroy(&br->br_count);
4704 +static inline int au_br_rdonly(struct au_branch *br)
4706 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4707 + || !au_br_writable(br->br_perm))
4711 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4713 +#ifdef CONFIG_AUFS_HNOTIFY
4714 + return !(brperm & AuBrPerm_RR);
4720 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4722 + int err, exec_flag;
4725 + exec_flag = oflag & __FMODE_EXEC;
4726 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4732 +/* ---------------------------------------------------------------------- */
4736 +void au_br_free(struct au_sbinfo *sinfo);
4737 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4739 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4741 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4742 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4743 +#ifdef CONFIG_COMPAT
4744 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4747 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4750 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4753 +static const loff_t au_loff_max = LLONG_MAX;
4755 +int au_xib_trunc(struct super_block *sb);
4756 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4758 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4759 + size_t size, loff_t *pos);
4760 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4761 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4762 +ino_t au_xino_new_ino(struct super_block *sb);
4763 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4764 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4766 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4768 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4769 + struct file *base_file, int do_test);
4770 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4772 +struct au_opt_xino;
4773 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4774 +void au_xino_clr(struct super_block *sb);
4775 +struct file *au_xino_def(struct super_block *sb);
4776 +int au_xino_path(struct seq_file *seq, struct file *file);
4778 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4779 + ino_t h_ino, int idx);
4780 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4783 +/* ---------------------------------------------------------------------- */
4785 +/* Superblock to branch */
4787 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4789 + return au_sbr(sb, bindex)->br_id;
4793 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4795 + return au_br_mnt(au_sbr(sb, bindex));
4799 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4801 + return au_br_sb(au_sbr(sb, bindex));
4804 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4806 + au_br_get(au_sbr(sb, bindex));
4809 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4811 + au_br_put(au_sbr(sb, bindex));
4814 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4816 + return au_sbr(sb, bindex)->br_perm;
4819 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4821 + return au_br_whable(au_sbr_perm(sb, bindex));
4824 +/* ---------------------------------------------------------------------- */
4827 + * wbr_wh_read_lock, wbr_wh_write_lock
4828 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4830 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4832 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4833 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4834 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4836 +/* ---------------------------------------------------------------------- */
4838 +#ifdef CONFIG_AUFS_FHSM
4839 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4841 + mutex_init(&brfhsm->bf_lock);
4842 + brfhsm->bf_jiffy = 0;
4843 + brfhsm->bf_readable = 0;
4846 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4848 + mutex_destroy(&brfhsm->bf_lock);
4851 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4852 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4855 +#endif /* __KERNEL__ */
4856 +#endif /* __AUFS_BRANCH_H__ */
4857 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4858 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4859 +++ linux/fs/aufs/conf.mk 2018-04-15 08:49:13.394483860 +0200
4862 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4866 +AuConfStr += ${1}=${${1}}
4870 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4872 + HNOTIFY HFSNOTIFY \
4884 +$(foreach i, ${AuConfAll}, \
4885 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4887 +AuConfName = ${obj}/conf.str
4888 +${AuConfName}.tmp: FORCE
4889 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4890 +${AuConfName}: ${AuConfName}.tmp
4891 + @diff -q $< $@ > /dev/null 2>&1 || { \
4892 + echo ' GEN ' $@; \
4896 +clean-files += ${AuConfName} ${AuConfName}.tmp
4897 +${obj}/sysfs.o: ${AuConfName}
4899 +-include ${srctree}/${src}/conf_priv.mk
4900 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4901 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4902 +++ linux/fs/aufs/cpup.c 2018-04-15 08:49:13.397817296 +0200
4905 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4907 + * This program, aufs is free software; you can redistribute it and/or modify
4908 + * it under the terms of the GNU General Public License as published by
4909 + * the Free Software Foundation; either version 2 of the License, or
4910 + * (at your option) any later version.
4912 + * This program is distributed in the hope that it will be useful,
4913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4915 + * GNU General Public License for more details.
4917 + * You should have received a copy of the GNU General Public License
4918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4922 + * copy-up functions, see wbr_policy.c for copy-down
4925 +#include <linux/fs_stack.h>
4926 +#include <linux/mm.h>
4927 +#include <linux/task_work.h>
4930 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4932 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4933 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4935 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4937 + dst->i_flags |= iflags & ~mask;
4938 + if (au_test_fs_notime(dst->i_sb))
4939 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4942 +void au_cpup_attr_timesizes(struct inode *inode)
4944 + struct inode *h_inode;
4946 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4947 + fsstack_copy_attr_times(inode, h_inode);
4948 + fsstack_copy_inode_size(inode, h_inode);
4951 +void au_cpup_attr_nlink(struct inode *inode, int force)
4953 + struct inode *h_inode;
4954 + struct super_block *sb;
4955 + aufs_bindex_t bindex, bbot;
4958 + bindex = au_ibtop(inode);
4959 + h_inode = au_h_iptr(inode, bindex);
4961 + && !S_ISDIR(h_inode->i_mode)
4962 + && au_opt_test(au_mntflags(sb), PLINK)
4963 + && au_plink_test(inode))
4967 + * 0 can happen in revalidating.
4968 + * h_inode->i_mutex may not be held here, but it is harmless since once
4969 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4971 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4972 + * the incorrect link count.
4974 + set_nlink(inode, h_inode->i_nlink);
4977 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4978 + * it may includes whplink directory.
4980 + if (S_ISDIR(h_inode->i_mode)) {
4981 + bbot = au_ibbot(inode);
4982 + for (bindex++; bindex <= bbot; bindex++) {
4983 + h_inode = au_h_iptr(inode, bindex);
4985 + au_add_nlink(inode, h_inode);
4990 +void au_cpup_attr_changeable(struct inode *inode)
4992 + struct inode *h_inode;
4994 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4995 + inode->i_mode = h_inode->i_mode;
4996 + inode->i_uid = h_inode->i_uid;
4997 + inode->i_gid = h_inode->i_gid;
4998 + au_cpup_attr_timesizes(inode);
4999 + au_cpup_attr_flags(inode, h_inode->i_flags);
5002 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5004 + struct au_iinfo *iinfo = au_ii(inode);
5006 + IiMustWriteLock(inode);
5008 + iinfo->ii_higen = h_inode->i_generation;
5009 + iinfo->ii_hsb1 = h_inode->i_sb;
5012 +void au_cpup_attr_all(struct inode *inode, int force)
5014 + struct inode *h_inode;
5016 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5017 + au_cpup_attr_changeable(inode);
5018 + if (inode->i_nlink > 0)
5019 + au_cpup_attr_nlink(inode, force);
5020 + inode->i_rdev = h_inode->i_rdev;
5021 + inode->i_blkbits = h_inode->i_blkbits;
5022 + au_cpup_igen(inode, h_inode);
5025 +/* ---------------------------------------------------------------------- */
5027 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5029 +/* keep the timestamps of the parent dir when cpup */
5030 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5031 + struct path *h_path)
5033 + struct inode *h_inode;
5035 + dt->dt_dentry = dentry;
5036 + dt->dt_h_path = *h_path;
5037 + h_inode = d_inode(h_path->dentry);
5038 + dt->dt_atime = h_inode->i_atime;
5039 + dt->dt_mtime = h_inode->i_mtime;
5043 +void au_dtime_revert(struct au_dtime *dt)
5045 + struct iattr attr;
5048 + attr.ia_atime = dt->dt_atime;
5049 + attr.ia_mtime = dt->dt_mtime;
5050 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5051 + | ATTR_ATIME | ATTR_ATIME_SET;
5053 + /* no delegation since this is a directory */
5054 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5055 + if (unlikely(err))
5056 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5059 +/* ---------------------------------------------------------------------- */
5061 +/* internal use only */
5062 +struct au_cpup_reg_attr {
5065 + unsigned int iflags; /* inode->i_flags */
5068 +static noinline_for_stack
5069 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5070 + struct au_cpup_reg_attr *h_src_attr)
5072 + int err, sbits, icex;
5073 + unsigned int mnt_flags;
5074 + unsigned char verbose;
5076 + struct path h_path;
5077 + struct inode *h_isrc, *h_idst;
5078 + struct kstat *h_st;
5079 + struct au_branch *br;
5081 + h_path.dentry = au_h_dptr(dst, bindex);
5082 + h_idst = d_inode(h_path.dentry);
5083 + br = au_sbr(dst->d_sb, bindex);
5084 + h_path.mnt = au_br_mnt(br);
5085 + h_isrc = d_inode(h_src);
5086 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5087 + | ATTR_ATIME | ATTR_MTIME
5088 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5089 + if (h_src_attr && h_src_attr->valid) {
5090 + h_st = &h_src_attr->st;
5091 + ia.ia_uid = h_st->uid;
5092 + ia.ia_gid = h_st->gid;
5093 + ia.ia_atime = h_st->atime;
5094 + ia.ia_mtime = h_st->mtime;
5095 + if (h_idst->i_mode != h_st->mode
5096 + && !S_ISLNK(h_idst->i_mode)) {
5097 + ia.ia_valid |= ATTR_MODE;
5098 + ia.ia_mode = h_st->mode;
5100 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5101 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5103 + ia.ia_uid = h_isrc->i_uid;
5104 + ia.ia_gid = h_isrc->i_gid;
5105 + ia.ia_atime = h_isrc->i_atime;
5106 + ia.ia_mtime = h_isrc->i_mtime;
5107 + if (h_idst->i_mode != h_isrc->i_mode
5108 + && !S_ISLNK(h_idst->i_mode)) {
5109 + ia.ia_valid |= ATTR_MODE;
5110 + ia.ia_mode = h_isrc->i_mode;
5112 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5113 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5115 + /* no delegation since it is just created */
5116 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5118 + /* is this nfs only? */
5119 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5120 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5121 + ia.ia_mode = h_isrc->i_mode;
5122 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5125 + icex = br->br_perm & AuBrAttr_ICEX;
5127 + mnt_flags = au_mntflags(dst->d_sb);
5128 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5129 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5135 +/* ---------------------------------------------------------------------- */
5137 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5138 + char *buf, unsigned long blksize)
5141 + size_t sz, rbytes, wbytes;
5142 + unsigned char all_zero;
5144 + struct inode *h_inode;
5145 + /* reduce stack usage */
5148 + zp = page_address(ZERO_PAGE(0));
5149 + if (unlikely(!zp))
5150 + return -ENOMEM; /* possible? */
5155 + AuDbg("len %lld\n", len);
5157 + if (len < blksize)
5161 + /* todo: signal_pending? */
5162 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5163 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5166 + if (unlikely(err < 0))
5170 + if (len >= rbytes && rbytes == blksize)
5171 + all_zero = !memcmp(buf, zp, rbytes);
5178 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5180 + /* todo: signal_pending? */
5181 + if (unlikely(err == -EAGAIN || err == -EINTR))
5183 + if (unlikely(err < 0))
5188 + if (unlikely(err < 0))
5194 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5196 + if (unlikely(res < 0))
5203 + /* the last block may be a hole */
5204 + if (!err && all_zero) {
5205 + AuLabel(last hole);
5208 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5209 + /* nfs requires this step to make last hole */
5210 + /* is this only nfs? */
5212 + /* todo: signal_pending? */
5213 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5214 + } while (err == -EAGAIN || err == -EINTR);
5221 + ia->ia_size = dst->f_pos;
5222 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5223 + ia->ia_file = dst;
5224 + h_inode = file_inode(dst);
5225 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5226 + /* no delegation since it is just created */
5227 + err = vfsub_notify_change(&dst->f_path, ia,
5228 + /*delegated*/NULL);
5229 + inode_unlock(h_inode);
5236 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5239 + unsigned long blksize;
5240 + unsigned char do_kfree;
5244 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5245 + if (!blksize || PAGE_SIZE < blksize)
5246 + blksize = PAGE_SIZE;
5247 + AuDbg("blksize %lu\n", blksize);
5248 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5250 + buf = kmalloc(blksize, GFP_NOFS);
5252 + buf = (void *)__get_free_page(GFP_NOFS);
5253 + if (unlikely(!buf))
5256 + if (len > (1 << 22))
5257 + AuDbg("copying a large file %lld\n", (long long)len);
5261 + err = au_do_copy_file(dst, src, len, buf, blksize);
5265 + free_page((unsigned long)buf);
5272 + * to support a sparse file which is opened with O_APPEND,
5273 + * we need to close the file.
5275 +static int au_cp_regular(struct au_cp_generic *cpg)
5278 + enum { SRC, DST };
5280 + aufs_bindex_t bindex;
5281 + unsigned int flags;
5282 + struct dentry *dentry;
5284 + struct file *file;
5288 + .bindex = cpg->bsrc,
5289 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5293 + .bindex = cpg->bdst,
5294 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5295 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5296 + .label = &&out_src
5299 + struct super_block *sb, *h_src_sb;
5300 + struct inode *h_src_inode;
5301 + struct task_struct *tsk = current;
5303 + /* bsrc branch can be ro/rw. */
5304 + sb = cpg->dentry->d_sb;
5306 + for (i = 0; i < 2; i++, f++) {
5307 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5308 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5309 + /*file*/NULL, f->force_wr);
5310 + err = PTR_ERR(f->file);
5311 + if (IS_ERR(f->file))
5315 + /* try stopping to update while we copyup */
5316 + h_src_inode = d_inode(file[SRC].dentry);
5317 + h_src_sb = h_src_inode->i_sb;
5318 + if (!au_test_nfs(h_src_sb))
5319 + IMustLock(h_src_inode);
5321 + if (h_src_sb != file_inode(file[DST].file)->i_sb
5322 + || !file[DST].file->f_op->clone_file_range)
5323 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5325 + if (!au_test_nfs(h_src_sb)) {
5326 + inode_unlock_shared(h_src_inode);
5327 + err = vfsub_clone_file_range(file[SRC].file,
5328 + file[DST].file, cpg->len);
5329 + vfsub_inode_lock_shared_nested(h_src_inode,
5332 + err = vfsub_clone_file_range(file[SRC].file,
5333 + file[DST].file, cpg->len);
5334 + if (unlikely(err == -EOPNOTSUPP && au_test_nfs(h_src_sb)))
5335 + /* the backend fs on NFS may not support cloning */
5336 + err = au_copy_file(file[DST].file, file[SRC].file,
5341 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5342 + if (tsk->flags & PF_KTHREAD)
5343 + __fput_sync(file[DST].file);
5345 + /* it happend actually */
5346 + fput(file[DST].file);
5349 + * we have to call both since we don't know which place the file
5353 + flush_delayed_fput();
5355 + au_sbr_put(sb, file[DST].bindex);
5358 + fput(file[SRC].file);
5359 + au_sbr_put(sb, file[SRC].bindex);
5364 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5365 + struct au_cpup_reg_attr *h_src_attr)
5369 + struct path h_path;
5370 + struct inode *h_src_inode, *h_dst_inode;
5373 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5374 + l = i_size_read(h_src_inode);
5375 + if (cpg->len == -1 || l < cpg->len)
5378 + /* try stopping to update while we are referencing */
5379 + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5380 + au_pin_hdir_unlock(cpg->pin);
5382 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5383 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5384 + h_src_attr->iflags = h_src_inode->i_flags;
5385 + if (!au_test_nfs(h_src_inode->i_sb))
5386 + err = vfs_getattr(&h_path, &h_src_attr->st);
5388 + inode_unlock_shared(h_src_inode);
5389 + err = vfs_getattr(&h_path, &h_src_attr->st);
5390 + vfsub_inode_lock_shared_nested(h_src_inode,
5393 + if (unlikely(err)) {
5394 + inode_unlock_shared(h_src_inode);
5397 + h_src_attr->valid = 1;
5398 + if (!au_test_nfs(h_src_inode->i_sb)) {
5399 + err = au_cp_regular(cpg);
5400 + inode_unlock_shared(h_src_inode);
5402 + inode_unlock_shared(h_src_inode);
5403 + err = au_cp_regular(cpg);
5405 + rerr = au_pin_hdir_relock(cpg->pin);
5409 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5410 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5411 + h_dst_inode = d_inode(h_path.dentry);
5412 + spin_lock(&h_dst_inode->i_lock);
5413 + h_dst_inode->i_state |= I_LINKABLE;
5414 + spin_unlock(&h_dst_inode->i_lock);
5421 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5422 + struct inode *h_dir)
5425 + mm_segment_t old_fs;
5430 + struct inode *h_inode = d_inode(h_src);
5431 + const struct inode_operations *h_iop = h_inode->i_op;
5434 + if (unlikely(!h_iop->readlink))
5438 + sym.k = (void *)__get_free_page(GFP_NOFS);
5439 + if (unlikely(!sym.k))
5442 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5443 + old_fs = get_fs();
5444 + set_fs(KERNEL_DS);
5445 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5450 + sym.k[symlen] = 0;
5451 + err = vfsub_symlink(h_dir, h_path, sym.k);
5453 + free_page((unsigned long)sym.k);
5460 + * regardless 'acl' option, reset all ACL.
5461 + * All ACL will be copied up later from the original entry on the lower branch.
5463 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5466 + struct dentry *h_dentry;
5467 + struct inode *h_inode;
5469 + h_dentry = h_path->dentry;
5470 + h_inode = d_inode(h_dentry);
5471 + /* forget_all_cached_acls(h_inode)); */
5472 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5474 + if (err == -EOPNOTSUPP)
5477 + err = vfsub_acl_chmod(h_inode, mode);
5483 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5484 + struct inode *h_dir, struct path *h_path)
5487 + struct inode *dir, *inode;
5489 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5491 + if (err == -EOPNOTSUPP)
5493 + if (unlikely(err))
5497 + * strange behaviour from the users view,
5498 + * particularry setattr case
5500 + dir = d_inode(dst_parent);
5501 + if (au_ibtop(dir) == cpg->bdst)
5502 + au_cpup_attr_nlink(dir, /*force*/1);
5503 + inode = d_inode(cpg->dentry);
5504 + au_cpup_attr_nlink(inode, /*force*/1);
5510 +static noinline_for_stack
5511 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5512 + struct au_cpup_reg_attr *h_src_attr)
5516 + unsigned int mnt_flags;
5517 + unsigned char isdir, isreg, force;
5518 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5519 + struct au_dtime dt;
5520 + struct path h_path;
5521 + struct dentry *h_src, *h_dst, *h_parent;
5522 + struct inode *h_inode, *h_dir;
5523 + struct super_block *sb;
5525 + /* bsrc branch can be ro/rw. */
5526 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5527 + h_inode = d_inode(h_src);
5528 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5530 + /* try stopping to be referenced while we are creating */
5531 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5532 + if (au_ftest_cpup(cpg->flags, RENAME))
5533 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5534 + AUFS_WH_PFX_LEN));
5535 + h_parent = h_dst->d_parent; /* dir inode is locked */
5536 + h_dir = d_inode(h_parent);
5538 + AuDebugOn(h_parent != h_dst->d_parent);
5540 + sb = cpg->dentry->d_sb;
5541 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5543 + h_path.dentry = h_parent;
5544 + au_dtime_store(&dt, dst_parent, &h_path);
5546 + h_path.dentry = h_dst;
5550 + mode = h_inode->i_mode;
5551 + switch (mode & S_IFMT) {
5554 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5555 + /*want_excl*/true);
5557 + err = au_do_cpup_regular(cpg, h_src_attr);
5561 + err = vfsub_mkdir(h_dir, &h_path, mode);
5563 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5566 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5570 + AuDebugOn(!capable(CAP_MKNOD));
5574 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5577 + AuIOErr("Unknown inode type 0%o\n", mode);
5581 + err = au_reset_acl(h_dir, &h_path, mode);
5583 + mnt_flags = au_mntflags(sb);
5584 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5586 + && au_opt_test(mnt_flags, XINO)
5587 + && (h_inode->i_nlink == 1
5588 + || (h_inode->i_state & I_LINKABLE))
5589 + /* todo: unnecessary? */
5590 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5591 + && cpg->bdst < cpg->bsrc
5592 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5593 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5594 + /* ignore this error */
5599 + force = !!cpg->len;
5600 + if (cpg->len == -1)
5601 + force = !!i_size_read(h_inode);
5603 + au_fhsm_wrote(sb, cpg->bdst, force);
5607 + au_dtime_revert(&dt);
5611 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5614 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5615 + struct inode *h_dir;
5616 + aufs_bindex_t bdst;
5618 + dentry = cpg->dentry;
5620 + h_dentry = au_h_dptr(dentry, bdst);
5621 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5623 + au_set_h_dptr(dentry, bdst, NULL);
5624 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5626 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5627 + au_set_h_dptr(dentry, bdst, h_dentry);
5630 + parent = dget_parent(dentry);
5631 + h_parent = au_h_dptr(parent, bdst);
5633 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5634 + if (IS_ERR(h_path->dentry))
5635 + err = PTR_ERR(h_path->dentry);
5637 + if (unlikely(err))
5640 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5641 + h_dir = d_inode(h_parent);
5643 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5644 + /* no delegation since it is just created */
5645 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5647 + dput(h_path->dentry);
5654 + * copyup the @dentry from @bsrc to @bdst.
5655 + * the caller must set the both of lower dentries.
5656 + * @len is for truncating when it is -1 copyup the entire file.
5657 + * in link/rename cases, @dst_parent may be different from the real one.
5658 + * basic->bsrc can be larger than basic->bdst.
5659 + * aufs doesn't touch the credential so
5660 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5662 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5665 + aufs_bindex_t old_ibtop;
5666 + unsigned char isdir, plink;
5667 + struct dentry *h_src, *h_dst, *h_parent;
5668 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5669 + struct super_block *sb;
5670 + struct au_branch *br;
5671 + /* to reuduce stack size */
5673 + struct au_dtime dt;
5674 + struct path h_path;
5675 + struct au_cpup_reg_attr h_src_attr;
5679 + a = kmalloc(sizeof(*a), GFP_NOFS);
5682 + a->h_src_attr.valid = 0;
5684 + sb = cpg->dentry->d_sb;
5685 + br = au_sbr(sb, cpg->bdst);
5686 + a->h_path.mnt = au_br_mnt(br);
5687 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5688 + h_parent = h_dst->d_parent; /* dir inode is locked */
5689 + h_dir = d_inode(h_parent);
5692 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5693 + inode = d_inode(cpg->dentry);
5696 + dst_parent = dget_parent(cpg->dentry);
5700 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5701 + dst_inode = au_h_iptr(inode, cpg->bdst);
5703 + if (unlikely(!plink)) {
5705 + AuIOErr("hi%lu(i%lu) exists on b%d "
5706 + "but plink is disabled\n",
5707 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5711 + if (dst_inode->i_nlink) {
5712 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5714 + h_src = au_plink_lkup(inode, cpg->bdst);
5715 + err = PTR_ERR(h_src);
5716 + if (IS_ERR(h_src))
5718 + if (unlikely(d_is_negative(h_src))) {
5720 + AuIOErr("i%lu exists on b%d "
5721 + "but not pseudo-linked\n",
5722 + inode->i_ino, cpg->bdst);
5728 + a->h_path.dentry = h_parent;
5729 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5732 + a->h_path.dentry = h_dst;
5734 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5735 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5736 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5738 + au_dtime_revert(&a->dt);
5739 + if (unlikely(err == -EWOULDBLOCK)) {
5740 + pr_warn("cannot retry for NFSv4 delegation"
5741 + " for an internal link\n");
5747 + /* todo: cpup_wh_file? */
5749 + au_update_ibrange(inode, /*do_put_zero*/1);
5752 + isdir = S_ISDIR(inode->i_mode);
5753 + old_ibtop = au_ibtop(inode);
5754 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5755 + if (unlikely(err))
5757 + dst_inode = d_inode(h_dst);
5758 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5759 + /* todo: necessary? */
5760 + /* au_pin_hdir_unlock(cpg->pin); */
5762 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5763 + if (unlikely(err)) {
5764 + /* todo: necessary? */
5765 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5766 + inode_unlock(dst_inode);
5770 + if (cpg->bdst < old_ibtop) {
5771 + if (S_ISREG(inode->i_mode)) {
5772 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5773 + if (unlikely(err)) {
5774 + /* ignore an error */
5775 + /* au_pin_hdir_relock(cpg->pin); */
5776 + inode_unlock(dst_inode);
5780 + au_set_ibtop(inode, cpg->bdst);
5782 + au_set_ibbot(inode, cpg->bdst);
5783 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5784 + au_hi_flags(inode, isdir));
5786 + /* todo: necessary? */
5787 + /* err = au_pin_hdir_relock(cpg->pin); */
5788 + inode_unlock(dst_inode);
5789 + if (unlikely(err))
5792 + src_inode = d_inode(h_src);
5794 + && (src_inode->i_nlink > 1
5795 + || src_inode->i_state & I_LINKABLE)
5797 + au_plink_append(inode, cpg->bdst, h_dst);
5799 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5800 + a->h_path.dentry = h_dst;
5801 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5804 + goto out_parent; /* success */
5808 + a->h_path.dentry = h_parent;
5809 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5810 + a->h_path.dentry = h_dst;
5812 + if (d_is_positive(h_dst)) {
5814 + /* no delegation since it is just created */
5815 + rerr = vfsub_unlink(h_dir, &a->h_path,
5816 + /*delegated*/NULL, /*force*/0);
5818 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5820 + au_dtime_revert(&a->dt);
5822 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5832 +#if 0 /* reserved */
5833 +struct au_cpup_single_args {
5835 + struct au_cp_generic *cpg;
5836 + struct dentry *dst_parent;
5839 +static void au_call_cpup_single(void *args)
5841 + struct au_cpup_single_args *a = args;
5843 + au_pin_hdir_acquire_nest(a->cpg->pin);
5844 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5845 + au_pin_hdir_release(a->cpg->pin);
5850 + * prevent SIGXFSZ in copy-up.
5851 + * testing CAP_MKNOD is for generic fs,
5852 + * but CAP_FSETID is for xfs only, currently.
5854 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5857 + struct super_block *sb;
5858 + struct inode *h_dir;
5861 + sb = au_pinned_parent(pin)->d_sb;
5862 + if (!au_wkq_test()
5863 + && (!au_sbi(sb)->si_plink_maint_pid
5864 + || au_plink_maint(sb, AuLock_NOPLM))) {
5865 + switch (mode & S_IFMT) {
5867 + /* no condition about RLIMIT_FSIZE and the file size */
5872 + do_sio = !capable(CAP_MKNOD);
5876 + do_sio = ((mode & (S_ISUID | S_ISGID))
5877 + && !capable(CAP_FSETID));
5878 + /* this workaround may be removed in the future */
5880 + h_dir = au_pinned_h_dir(pin);
5881 + do_sio = h_dir->i_mode & S_ISVTX;
5888 +#if 0 /* reserved */
5889 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5892 + struct dentry *h_dentry;
5894 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5895 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5896 + err = au_cpup_single(cpg, dst_parent);
5898 + struct au_cpup_single_args args = {
5901 + .dst_parent = dst_parent
5903 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5904 + if (unlikely(wkq_err))
5913 + * copyup the @dentry from the first active lower branch to @bdst,
5914 + * using au_cpup_single().
5916 +static int au_cpup_simple(struct au_cp_generic *cpg)
5919 + unsigned int flags_orig;
5920 + struct dentry *dentry;
5922 + AuDebugOn(cpg->bsrc < 0);
5924 + dentry = cpg->dentry;
5925 + DiMustWriteLock(dentry);
5927 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5929 + flags_orig = cpg->flags;
5930 + au_fset_cpup(cpg->flags, RENAME);
5931 + err = au_cpup_single(cpg, NULL);
5932 + cpg->flags = flags_orig;
5934 + return 0; /* success */
5937 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5938 + au_set_dbtop(dentry, cpg->bsrc);
5944 +struct au_cpup_simple_args {
5946 + struct au_cp_generic *cpg;
5949 +static void au_call_cpup_simple(void *args)
5951 + struct au_cpup_simple_args *a = args;
5953 + au_pin_hdir_acquire_nest(a->cpg->pin);
5954 + *a->errp = au_cpup_simple(a->cpg);
5955 + au_pin_hdir_release(a->cpg->pin);
5958 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5961 + struct dentry *dentry, *parent;
5962 + struct file *h_file;
5963 + struct inode *h_dir;
5965 + dentry = cpg->dentry;
5967 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5968 + AuDebugOn(cpg->bsrc < 0);
5969 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5970 + err = PTR_ERR(h_file);
5971 + if (IS_ERR(h_file))
5975 + parent = dget_parent(dentry);
5976 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5977 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5978 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5979 + err = au_cpup_simple(cpg);
5981 + struct au_cpup_simple_args args = {
5985 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5986 + if (unlikely(wkq_err))
5992 + au_h_open_post(dentry, cpg->bsrc, h_file);
5998 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6000 + aufs_bindex_t bsrc, bbot;
6001 + struct dentry *dentry, *h_dentry;
6003 + if (cpg->bsrc < 0) {
6004 + dentry = cpg->dentry;
6005 + bbot = au_dbbot(dentry);
6006 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6007 + h_dentry = au_h_dptr(dentry, bsrc);
6009 + AuDebugOn(d_is_negative(h_dentry));
6013 + AuDebugOn(bsrc > bbot);
6016 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6017 + return au_do_sio_cpup_simple(cpg);
6020 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6022 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6023 + return au_do_sio_cpup_simple(cpg);
6026 +/* ---------------------------------------------------------------------- */
6029 + * copyup the deleted file for writing.
6031 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6032 + struct file *file)
6035 + unsigned int flags_orig;
6036 + aufs_bindex_t bsrc_orig;
6037 + struct au_dinfo *dinfo;
6039 + struct au_hdentry *hd;
6040 + struct dentry *h_dentry;
6043 + dinfo = au_di(cpg->dentry);
6044 + AuRwMustWriteLock(&dinfo->di_rwsem);
6046 + bsrc_orig = cpg->bsrc;
6047 + cpg->bsrc = dinfo->di_btop;
6048 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6049 + hdst.h_dentry = hdst.hd->hd_dentry;
6050 + hdst.hd->hd_dentry = wh_dentry;
6051 + dinfo->di_btop = cpg->bdst;
6053 + hsrc.h_dentry = NULL;
6055 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6056 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6057 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6059 + flags_orig = cpg->flags;
6060 + cpg->flags = !AuCpup_DTIME;
6061 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6062 + cpg->flags = flags_orig;
6065 + err = au_reopen_nondir(file);
6066 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6068 + hdst.hd->hd_dentry = hdst.h_dentry;
6069 + dinfo->di_btop = cpg->bsrc;
6070 + cpg->bsrc = bsrc_orig;
6075 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6078 + aufs_bindex_t bdst;
6079 + struct au_dtime dt;
6080 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6081 + struct au_branch *br;
6082 + struct path h_path;
6084 + dentry = cpg->dentry;
6086 + br = au_sbr(dentry->d_sb, bdst);
6087 + parent = dget_parent(dentry);
6088 + h_parent = au_h_dptr(parent, bdst);
6089 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6090 + err = PTR_ERR(wh_dentry);
6091 + if (IS_ERR(wh_dentry))
6094 + h_path.dentry = h_parent;
6095 + h_path.mnt = au_br_mnt(br);
6096 + au_dtime_store(&dt, parent, &h_path);
6097 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6098 + if (unlikely(err))
6102 + h_path.dentry = wh_dentry;
6103 + if (!d_is_dir(wh_dentry)) {
6104 + /* no delegation since it is just created */
6105 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6106 + /*delegated*/NULL, /*force*/0);
6108 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6109 + if (unlikely(err)) {
6110 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6114 + au_dtime_revert(&dt);
6115 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6124 +struct au_cpup_wh_args {
6126 + struct au_cp_generic *cpg;
6127 + struct file *file;
6130 +static void au_call_cpup_wh(void *args)
6132 + struct au_cpup_wh_args *a = args;
6134 + au_pin_hdir_acquire_nest(a->cpg->pin);
6135 + *a->errp = au_cpup_wh(a->cpg, a->file);
6136 + au_pin_hdir_release(a->cpg->pin);
6139 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6142 + aufs_bindex_t bdst;
6143 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6144 + struct inode *dir, *h_dir, *h_tmpdir;
6145 + struct au_wbr *wbr;
6146 + struct au_pin wh_pin, *pin_orig;
6148 + dentry = cpg->dentry;
6150 + parent = dget_parent(dentry);
6151 + dir = d_inode(parent);
6154 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6157 + if (!h_dir->i_nlink) {
6158 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6159 + h_orph = wbr->wbr_orph;
6161 + h_parent = dget(au_h_dptr(parent, bdst));
6162 + au_set_h_dptr(parent, bdst, dget(h_orph));
6163 + h_tmpdir = d_inode(h_orph);
6164 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6166 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6167 + /* todo: au_h_open_pre()? */
6169 + pin_orig = cpg->pin;
6170 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6171 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6172 + cpg->pin = &wh_pin;
6175 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6176 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6177 + err = au_cpup_wh(cpg, file);
6179 + struct au_cpup_wh_args args = {
6184 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6185 + if (unlikely(wkq_err))
6190 + inode_unlock(h_tmpdir);
6191 + /* todo: au_h_open_post()? */
6192 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6193 + au_set_h_dptr(parent, bdst, h_parent);
6194 + AuDebugOn(!pin_orig);
6195 + cpg->pin = pin_orig;
6203 +/* ---------------------------------------------------------------------- */
6206 + * generic routine for both of copy-up and copy-down.
6208 +/* cf. revalidate function in file.c */
6209 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6210 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6211 + struct au_pin *pin,
6212 + struct dentry *h_parent, void *arg),
6216 + struct au_pin pin;
6217 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6220 + parent = dget_parent(dentry);
6221 + if (IS_ROOT(parent))
6224 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6225 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6227 + /* do not use au_dpage */
6228 + real_parent = parent;
6231 + parent = dget_parent(dentry);
6232 + h_parent = au_h_dptr(parent, bdst);
6234 + goto out; /* success */
6236 + /* find top dir which is necessary to cpup */
6240 + parent = dget_parent(d);
6241 + di_read_lock_parent3(parent, !AuLock_IR);
6242 + h_parent = au_h_dptr(parent, bdst);
6243 + di_read_unlock(parent, !AuLock_IR);
6244 + } while (!h_parent);
6246 + if (d != real_parent)
6247 + di_write_lock_child3(d);
6249 + /* somebody else might create while we were sleeping */
6250 + h_dentry = au_h_dptr(d, bdst);
6251 + if (!h_dentry || d_is_negative(h_dentry)) {
6253 + au_update_dbtop(d);
6255 + au_pin_set_dentry(&pin, d);
6256 + err = au_do_pin(&pin);
6258 + err = cp(d, bdst, &pin, h_parent, arg);
6263 + if (d != real_parent)
6264 + di_write_unlock(d);
6265 + if (unlikely(err))
6274 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6275 + struct au_pin *pin,
6276 + struct dentry *h_parent __maybe_unused,
6277 + void *arg __maybe_unused)
6279 + struct au_cp_generic cpg = {
6285 + .flags = AuCpup_DTIME
6287 + return au_sio_cpup_simple(&cpg);
6290 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6292 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6295 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6298 + struct dentry *parent;
6299 + struct inode *dir;
6301 + parent = dget_parent(dentry);
6302 + dir = d_inode(parent);
6304 + if (au_h_iptr(dir, bdst))
6307 + di_read_unlock(parent, AuLock_IR);
6308 + di_write_lock_parent(parent);
6309 + /* someone else might change our inode while we were sleeping */
6310 + if (!au_h_iptr(dir, bdst))
6311 + err = au_cpup_dirs(dentry, bdst);
6312 + di_downgrade_lock(parent, AuLock_IR);
6318 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6319 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6320 +++ linux/fs/aufs/cpup.h 2018-04-15 08:49:13.397817296 +0200
6323 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6325 + * This program, aufs is free software; you can redistribute it and/or modify
6326 + * it under the terms of the GNU General Public License as published by
6327 + * the Free Software Foundation; either version 2 of the License, or
6328 + * (at your option) any later version.
6330 + * This program is distributed in the hope that it will be useful,
6331 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6332 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6333 + * GNU General Public License for more details.
6335 + * You should have received a copy of the GNU General Public License
6336 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6340 + * copy-up/down functions
6343 +#ifndef __AUFS_CPUP_H__
6344 +#define __AUFS_CPUP_H__
6348 +#include <linux/path.h>
6354 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6355 +void au_cpup_attr_timesizes(struct inode *inode);
6356 +void au_cpup_attr_nlink(struct inode *inode, int force);
6357 +void au_cpup_attr_changeable(struct inode *inode);
6358 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6359 +void au_cpup_attr_all(struct inode *inode, int force);
6361 +/* ---------------------------------------------------------------------- */
6363 +struct au_cp_generic {
6364 + struct dentry *dentry;
6365 + aufs_bindex_t bdst, bsrc;
6367 + struct au_pin *pin;
6368 + unsigned int flags;
6372 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6373 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6375 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6376 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6378 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6380 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6381 + the branch is marked as RO */
6383 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6384 +#undef AuCpup_HOPEN
6385 +#define AuCpup_HOPEN 0
6388 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6389 +#define au_fset_cpup(flags, name) \
6390 + do { (flags) |= AuCpup_##name; } while (0)
6391 +#define au_fclr_cpup(flags, name) \
6392 + do { (flags) &= ~AuCpup_##name; } while (0)
6394 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6395 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6396 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6397 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6399 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6400 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6401 + struct au_pin *pin,
6402 + struct dentry *h_parent, void *arg),
6404 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6405 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6407 +/* ---------------------------------------------------------------------- */
6409 +/* keep timestamps when copyup */
6411 + struct dentry *dt_dentry;
6412 + struct path dt_h_path;
6413 + struct timespec dt_atime, dt_mtime;
6415 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6416 + struct path *h_path);
6417 +void au_dtime_revert(struct au_dtime *dt);
6419 +#endif /* __KERNEL__ */
6420 +#endif /* __AUFS_CPUP_H__ */
6421 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6422 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6423 +++ linux/fs/aufs/dbgaufs.c 2018-04-15 08:49:13.397817296 +0200
6426 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6428 + * This program, aufs is free software; you can redistribute it and/or modify
6429 + * it under the terms of the GNU General Public License as published by
6430 + * the Free Software Foundation; either version 2 of the License, or
6431 + * (at your option) any later version.
6433 + * This program is distributed in the hope that it will be useful,
6434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6436 + * GNU General Public License for more details.
6438 + * You should have received a copy of the GNU General Public License
6439 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6443 + * debugfs interface
6446 +#include <linux/debugfs.h>
6449 +#ifndef CONFIG_SYSFS
6450 +#error DEBUG_FS depends upon SYSFS
6453 +static struct dentry *dbgaufs;
6454 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6456 +/* 20 is max digits length of ulong 64 */
6457 +struct dbgaufs_arg {
6463 + * common function for all XINO files
6465 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6466 + struct file *file)
6468 + kfree(file->private_data);
6472 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6476 + struct dbgaufs_arg *p;
6479 + p = kmalloc(sizeof(*p), GFP_NOFS);
6485 + file->private_data = p;
6489 + err = vfs_getattr(&xf->f_path, &st);
6493 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6494 + (long)file_count(xf), st.blocks, st.blksize,
6495 + (long long)st.size);
6497 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6498 + st.blocks, st.blksize,
6499 + (long long)st.size);
6500 + AuDebugOn(p->n >= sizeof(p->a));
6502 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6511 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6512 + size_t count, loff_t *ppos)
6514 + struct dbgaufs_arg *p;
6516 + p = file->private_data;
6517 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6520 +/* ---------------------------------------------------------------------- */
6522 +struct dbgaufs_plink_arg {
6527 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6528 + struct file *file)
6530 + free_page((unsigned long)file->private_data);
6534 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6536 + int err, i, limit;
6537 + unsigned long n, sum;
6538 + struct dbgaufs_plink_arg *p;
6539 + struct au_sbinfo *sbinfo;
6540 + struct super_block *sb;
6541 + struct hlist_bl_head *hbl;
6544 + p = (void *)get_zeroed_page(GFP_NOFS);
6549 + sbinfo = inode->i_private;
6550 + sb = sbinfo->si_sb;
6551 + si_noflush_read_lock(sb);
6552 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6553 + limit = PAGE_SIZE - sizeof(p->n);
6555 + /* the number of buckets */
6556 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6561 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6563 + n = au_hbl_count(hbl);
6566 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6569 + if (unlikely(limit <= 0))
6572 + p->a[p->n - 1] = '\n';
6574 + /* the sum of plinks */
6575 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6578 + if (unlikely(limit <= 0))
6581 +#define str "1\n0\n0\n"
6582 + p->n = sizeof(str) - 1;
6583 + strcpy(p->a, str);
6586 + si_read_unlock(sb);
6589 + file->private_data = p;
6590 + goto out; /* success */
6593 + free_page((unsigned long)p);
6598 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6599 + size_t count, loff_t *ppos)
6601 + struct dbgaufs_plink_arg *p;
6603 + p = file->private_data;
6604 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6607 +static const struct file_operations dbgaufs_plink_fop = {
6608 + .owner = THIS_MODULE,
6609 + .open = dbgaufs_plink_open,
6610 + .release = dbgaufs_plink_release,
6611 + .read = dbgaufs_plink_read
6614 +/* ---------------------------------------------------------------------- */
6616 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6619 + struct au_sbinfo *sbinfo;
6620 + struct super_block *sb;
6622 + sbinfo = inode->i_private;
6623 + sb = sbinfo->si_sb;
6624 + si_noflush_read_lock(sb);
6625 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6626 + si_read_unlock(sb);
6630 +static const struct file_operations dbgaufs_xib_fop = {
6631 + .owner = THIS_MODULE,
6632 + .open = dbgaufs_xib_open,
6633 + .release = dbgaufs_xi_release,
6634 + .read = dbgaufs_xi_read
6637 +/* ---------------------------------------------------------------------- */
6639 +#define DbgaufsXi_PREFIX "xi"
6641 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6645 + struct au_sbinfo *sbinfo;
6646 + struct super_block *sb;
6648 + struct qstr *name;
6652 + name = &file->f_path.dentry->d_name;
6653 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6654 + || memcmp(name->name, DbgaufsXi_PREFIX,
6655 + sizeof(DbgaufsXi_PREFIX) - 1)))
6657 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6658 + if (unlikely(err))
6661 + sbinfo = inode->i_private;
6662 + sb = sbinfo->si_sb;
6663 + si_noflush_read_lock(sb);
6664 + if (l <= au_sbbot(sb)) {
6665 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6666 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6669 + si_read_unlock(sb);
6675 +static const struct file_operations dbgaufs_xino_fop = {
6676 + .owner = THIS_MODULE,
6677 + .open = dbgaufs_xino_open,
6678 + .release = dbgaufs_xi_release,
6679 + .read = dbgaufs_xi_read
6682 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6684 + aufs_bindex_t bbot;
6685 + struct au_branch *br;
6686 + struct au_xino_file *xi;
6688 + if (!au_sbi(sb)->si_dbgaufs)
6691 + bbot = au_sbbot(sb);
6692 + for (; bindex <= bbot; bindex++) {
6693 + br = au_sbr(sb, bindex);
6694 + xi = &br->br_xino;
6695 + /* debugfs acquires the parent i_mutex */
6697 + debugfs_remove(xi->xi_dbgaufs);
6699 + xi->xi_dbgaufs = NULL;
6703 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6705 + struct au_sbinfo *sbinfo;
6706 + struct dentry *parent;
6707 + struct au_branch *br;
6708 + struct au_xino_file *xi;
6709 + aufs_bindex_t bbot;
6710 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6712 + sbinfo = au_sbi(sb);
6713 + parent = sbinfo->si_dbgaufs;
6717 + bbot = au_sbbot(sb);
6718 + for (; bindex <= bbot; bindex++) {
6719 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6720 + br = au_sbr(sb, bindex);
6721 + xi = &br->br_xino;
6722 + AuDebugOn(xi->xi_dbgaufs);
6723 + /* debugfs acquires the parent i_mutex */
6725 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6726 + sbinfo, &dbgaufs_xino_fop);
6728 + /* ignore an error */
6729 + if (unlikely(!xi->xi_dbgaufs))
6730 + AuWarn1("failed %s under debugfs\n", name);
6734 +/* ---------------------------------------------------------------------- */
6736 +#ifdef CONFIG_AUFS_EXPORT
6737 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6740 + struct au_sbinfo *sbinfo;
6741 + struct super_block *sb;
6743 + sbinfo = inode->i_private;
6744 + sb = sbinfo->si_sb;
6745 + si_noflush_read_lock(sb);
6746 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6747 + si_read_unlock(sb);
6751 +static const struct file_operations dbgaufs_xigen_fop = {
6752 + .owner = THIS_MODULE,
6753 + .open = dbgaufs_xigen_open,
6754 + .release = dbgaufs_xi_release,
6755 + .read = dbgaufs_xi_read
6758 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6763 + * This function is a dynamic '__init' function actually,
6764 + * so the tiny check for si_rwsem is unnecessary.
6766 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6769 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6770 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6771 + &dbgaufs_xigen_fop);
6772 + if (sbinfo->si_dbgaufs_xigen)
6778 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6782 +#endif /* CONFIG_AUFS_EXPORT */
6784 +/* ---------------------------------------------------------------------- */
6786 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6789 + * This function is a dynamic '__fin' function actually,
6790 + * so the tiny check for si_rwsem is unnecessary.
6792 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6794 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6795 + sbinfo->si_dbgaufs = NULL;
6796 + kobject_put(&sbinfo->si_kobj);
6799 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6802 + char name[SysaufsSiNameLen];
6805 + * This function is a dynamic '__init' function actually,
6806 + * so the tiny check for si_rwsem is unnecessary.
6808 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6812 + AuErr1("/debug/aufs is uninitialized\n");
6817 + sysaufs_name(sbinfo, name);
6818 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6819 + if (unlikely(!sbinfo->si_dbgaufs))
6821 + kobject_get(&sbinfo->si_kobj);
6823 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6824 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6825 + &dbgaufs_xib_fop);
6826 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6829 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6830 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6831 + &dbgaufs_plink_fop);
6832 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6835 + err = dbgaufs_xigen_init(sbinfo);
6837 + goto out; /* success */
6840 + dbgaufs_si_fin(sbinfo);
6845 +/* ---------------------------------------------------------------------- */
6847 +void dbgaufs_fin(void)
6849 + debugfs_remove(dbgaufs);
6852 +int __init dbgaufs_init(void)
6857 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6862 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6863 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6864 +++ linux/fs/aufs/dbgaufs.h 2018-04-15 08:49:13.397817296 +0200
6867 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6869 + * This program, aufs is free software; you can redistribute it and/or modify
6870 + * it under the terms of the GNU General Public License as published by
6871 + * the Free Software Foundation; either version 2 of the License, or
6872 + * (at your option) any later version.
6874 + * This program is distributed in the hope that it will be useful,
6875 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6876 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6877 + * GNU General Public License for more details.
6879 + * You should have received a copy of the GNU General Public License
6880 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6884 + * debugfs interface
6887 +#ifndef __DBGAUFS_H__
6888 +#define __DBGAUFS_H__
6892 +struct super_block;
6895 +#ifdef CONFIG_DEBUG_FS
6897 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6898 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6899 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6900 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6901 +void dbgaufs_fin(void);
6902 +int __init dbgaufs_init(void);
6904 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6905 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6906 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6907 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6908 +AuStubVoid(dbgaufs_fin, void)
6909 +AuStubInt0(__init dbgaufs_init, void)
6910 +#endif /* CONFIG_DEBUG_FS */
6912 +#endif /* __KERNEL__ */
6913 +#endif /* __DBGAUFS_H__ */
6914 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6915 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6916 +++ linux/fs/aufs/dcsub.c 2018-04-15 08:49:13.397817296 +0200
6919 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6921 + * This program, aufs is free software; you can redistribute it and/or modify
6922 + * it under the terms of the GNU General Public License as published by
6923 + * the Free Software Foundation; either version 2 of the License, or
6924 + * (at your option) any later version.
6926 + * This program is distributed in the hope that it will be useful,
6927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6929 + * GNU General Public License for more details.
6931 + * You should have received a copy of the GNU General Public License
6932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6936 + * sub-routines for dentry cache
6941 +static void au_dpage_free(struct au_dpage *dpage)
6944 + struct dentry **p;
6946 + p = dpage->dentries;
6947 + for (i = 0; i < dpage->ndentry; i++)
6949 + free_page((unsigned long)dpage->dentries);
6952 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6958 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6959 + if (unlikely(!dpages->dpages))
6962 + p = (void *)__get_free_page(gfp);
6966 + dpages->dpages[0].ndentry = 0;
6967 + dpages->dpages[0].dentries = p;
6968 + dpages->ndpage = 1;
6969 + return 0; /* success */
6972 + kfree(dpages->dpages);
6977 +void au_dpages_free(struct au_dcsub_pages *dpages)
6980 + struct au_dpage *p;
6982 + p = dpages->dpages;
6983 + for (i = 0; i < dpages->ndpage; i++)
6984 + au_dpage_free(p++);
6985 + kfree(dpages->dpages);
6988 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6989 + struct dentry *dentry, gfp_t gfp)
6992 + struct au_dpage *dpage;
6995 + dpage = dpages->dpages + dpages->ndpage - 1;
6996 + sz = PAGE_SIZE / sizeof(dentry);
6997 + if (unlikely(dpage->ndentry >= sz)) {
6998 + AuLabel(new dpage);
7000 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7001 + p = au_kzrealloc(dpages->dpages, sz,
7002 + sz + sizeof(*dpages->dpages), gfp,
7007 + dpages->dpages = p;
7008 + dpage = dpages->dpages + dpages->ndpage;
7009 + p = (void *)__get_free_page(gfp);
7013 + dpage->ndentry = 0;
7014 + dpage->dentries = p;
7018 + AuDebugOn(au_dcount(dentry) <= 0);
7019 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7020 + return 0; /* success */
7026 +/* todo: BAD approach */
7027 +/* copied from linux/fs/dcache.c */
7035 +extern void d_walk(struct dentry *parent, void *data,
7036 + enum d_walk_ret (*enter)(void *, struct dentry *),
7037 + void (*finish)(void *));
7039 +struct ac_dpages_arg {
7041 + struct au_dcsub_pages *dpages;
7042 + struct super_block *sb;
7043 + au_dpages_test test;
7047 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7049 + enum d_walk_ret ret;
7050 + struct ac_dpages_arg *arg = _arg;
7052 + ret = D_WALK_CONTINUE;
7053 + if (dentry->d_sb == arg->sb
7054 + && !IS_ROOT(dentry)
7055 + && au_dcount(dentry) > 0
7057 + && (!arg->test || arg->test(dentry, arg->arg))) {
7058 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7059 + if (unlikely(arg->err))
7060 + ret = D_WALK_QUIT;
7066 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7067 + au_dpages_test test, void *arg)
7069 + struct ac_dpages_arg args = {
7077 + d_walk(root, &args, au_call_dpages_append, NULL);
7082 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7083 + int do_include, au_dpages_test test, void *arg)
7088 + write_seqlock(&rename_lock);
7089 + spin_lock(&dentry->d_lock);
7091 + && au_dcount(dentry) > 0
7092 + && (!test || test(dentry, arg)))
7093 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7094 + spin_unlock(&dentry->d_lock);
7095 + if (unlikely(err))
7099 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7102 + while (!IS_ROOT(dentry)) {
7103 + dentry = dentry->d_parent; /* rename_lock is locked */
7104 + spin_lock(&dentry->d_lock);
7105 + if (au_dcount(dentry) > 0
7106 + && (!test || test(dentry, arg)))
7107 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7108 + spin_unlock(&dentry->d_lock);
7109 + if (unlikely(err))
7114 + write_sequnlock(&rename_lock);
7118 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7120 + return au_di(dentry) && dentry->d_sb == arg;
7123 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7124 + struct dentry *dentry, int do_include)
7126 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7127 + au_dcsub_dpages_aufs, dentry->d_sb);
7130 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7132 + struct path path[2] = {
7141 + return path_is_under(path + 0, path + 1);
7143 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7144 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7145 +++ linux/fs/aufs/dcsub.h 2018-04-15 08:49:13.397817296 +0200
7148 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7150 + * This program, aufs is free software; you can redistribute it and/or modify
7151 + * it under the terms of the GNU General Public License as published by
7152 + * the Free Software Foundation; either version 2 of the License, or
7153 + * (at your option) any later version.
7155 + * This program is distributed in the hope that it will be useful,
7156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7158 + * GNU General Public License for more details.
7160 + * You should have received a copy of the GNU General Public License
7161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7165 + * sub-routines for dentry cache
7168 +#ifndef __AUFS_DCSUB_H__
7169 +#define __AUFS_DCSUB_H__
7173 +#include <linux/dcache.h>
7174 +#include <linux/fs.h>
7178 + struct dentry **dentries;
7181 +struct au_dcsub_pages {
7183 + struct au_dpage *dpages;
7186 +/* ---------------------------------------------------------------------- */
7189 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7190 +void au_dpages_free(struct au_dcsub_pages *dpages);
7191 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7192 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7193 + au_dpages_test test, void *arg);
7194 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7195 + int do_include, au_dpages_test test, void *arg);
7196 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7197 + struct dentry *dentry, int do_include);
7198 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7200 +/* ---------------------------------------------------------------------- */
7203 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7204 + * include/linux/dcache.h. Try them (in the future).
7207 +static inline int au_d_hashed_positive(struct dentry *d)
7210 + struct inode *inode = d_inode(d);
7213 + if (unlikely(d_unhashed(d)
7214 + || d_is_negative(d)
7215 + || !inode->i_nlink))
7220 +static inline int au_d_linkable(struct dentry *d)
7223 + struct inode *inode = d_inode(d);
7225 + err = au_d_hashed_positive(d);
7227 + && d_is_positive(d)
7228 + && (inode->i_state & I_LINKABLE))
7233 +static inline int au_d_alive(struct dentry *d)
7236 + struct inode *inode;
7240 + err = au_d_hashed_positive(d);
7242 + inode = d_inode(d);
7243 + if (unlikely(d_unlinked(d)
7244 + || d_is_negative(d)
7245 + || !inode->i_nlink))
7251 +static inline int au_alive_dir(struct dentry *d)
7255 + err = au_d_alive(d);
7256 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7261 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7263 + return a->len == b->len
7264 + && !memcmp(a->name, b->name, a->len);
7269 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7271 + * the type of d_lockref.count became int, but the inlined function d_count()
7272 + * still returns unsigned int.
7273 + * I don't know why. Maybe it is for every d_count() users?
7274 + * Anyway au_dcount() lives on.
7276 +static inline int au_dcount(struct dentry *d)
7278 + return (int)d_count(d);
7281 +#endif /* __KERNEL__ */
7282 +#endif /* __AUFS_DCSUB_H__ */
7283 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7284 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7285 +++ linux/fs/aufs/debug.c 2018-04-15 08:49:13.397817296 +0200
7288 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7290 + * This program, aufs is free software; you can redistribute it and/or modify
7291 + * it under the terms of the GNU General Public License as published by
7292 + * the Free Software Foundation; either version 2 of the License, or
7293 + * (at your option) any later version.
7295 + * This program is distributed in the hope that it will be useful,
7296 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7297 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7298 + * GNU General Public License for more details.
7300 + * You should have received a copy of the GNU General Public License
7301 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7305 + * debug print functions
7310 +/* Returns 0, or -errno. arg is in kp->arg. */
7311 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7315 + err = kstrtoint(val, 0, &n);
7325 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7326 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7331 + return sprintf(buffer, "%d", atomic_read(a));
7334 +static struct kernel_param_ops param_ops_atomic_t = {
7335 + .set = param_atomic_t_set,
7336 + .get = param_atomic_t_get
7337 + /* void (*free)(void *arg) */
7340 +atomic_t aufs_debug = ATOMIC_INIT(0);
7341 +MODULE_PARM_DESC(debug, "debug print");
7342 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7344 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7345 +char *au_plevel = KERN_DEBUG;
7346 +#define dpri(fmt, ...) do { \
7348 + && strcmp(au_plevel, KERN_DEBUG)) \
7349 + || au_debug_test()) \
7350 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7353 +/* ---------------------------------------------------------------------- */
7355 +void au_dpri_whlist(struct au_nhash *whlist)
7357 + unsigned long ul, n;
7358 + struct hlist_head *head;
7359 + struct au_vdir_wh *pos;
7361 + n = whlist->nh_num;
7362 + head = whlist->nh_head;
7363 + for (ul = 0; ul < n; ul++) {
7364 + hlist_for_each_entry(pos, head, wh_hash)
7365 + dpri("b%d, %.*s, %d\n",
7367 + pos->wh_str.len, pos->wh_str.name,
7373 +void au_dpri_vdir(struct au_vdir *vdir)
7376 + union au_vdir_deblk_p p;
7379 + if (!vdir || IS_ERR(vdir)) {
7380 + dpri("err %ld\n", PTR_ERR(vdir));
7384 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7385 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7386 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7387 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7388 + p.deblk = vdir->vd_deblk[ul];
7390 + dpri("[%lu]: %p\n", ul, o);
7394 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7395 + struct dentry *wh)
7400 + if (!inode || IS_ERR(inode)) {
7401 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7405 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7406 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7407 + && sizeof(inode->i_blocks) != sizeof(u64));
7409 + n = (void *)wh->d_name.name;
7410 + l = wh->d_name.len;
7413 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7414 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7416 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7417 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7418 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7419 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7420 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7421 + inode->i_state, inode->i_flags, inode->i_version,
7422 + inode->i_generation,
7423 + l ? ", wh " : "", l, n);
7427 +void au_dpri_inode(struct inode *inode)
7429 + struct au_iinfo *iinfo;
7430 + struct au_hinode *hi;
7431 + aufs_bindex_t bindex;
7434 + err = do_pri_inode(-1, inode, -1, NULL);
7435 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7438 + iinfo = au_ii(inode);
7439 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7440 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7441 + if (iinfo->ii_btop < 0)
7444 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7445 + hi = au_hinode(iinfo, bindex);
7447 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7451 +void au_dpri_dalias(struct inode *inode)
7455 + spin_lock(&inode->i_lock);
7456 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7457 + au_dpri_dentry(d);
7458 + spin_unlock(&inode->i_lock);
7461 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7463 + struct dentry *wh = NULL;
7465 + struct inode *inode;
7466 + struct au_iinfo *iinfo;
7467 + struct au_hinode *hi;
7469 + if (!dentry || IS_ERR(dentry)) {
7470 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7473 + /* do not call dget_parent() here */
7474 + /* note: access d_xxx without d_lock */
7475 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7476 + bindex, dentry, dentry,
7477 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7478 + au_dcount(dentry), dentry->d_flags,
7479 + d_unhashed(dentry) ? "un" : "");
7482 + if (d_is_positive(dentry))
7483 + inode = d_inode(dentry);
7485 + && au_test_aufs(dentry->d_sb)
7487 + && !au_is_bad_inode(inode)) {
7488 + iinfo = au_ii(inode);
7489 + hi = au_hinode(iinfo, bindex);
7491 + wh = hi->hi_whdentry;
7493 + do_pri_inode(bindex, inode, hn, wh);
7497 +void au_dpri_dentry(struct dentry *dentry)
7499 + struct au_dinfo *dinfo;
7500 + aufs_bindex_t bindex;
7503 + err = do_pri_dentry(-1, dentry);
7504 + if (err || !au_test_aufs(dentry->d_sb))
7507 + dinfo = au_di(dentry);
7510 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7511 + dinfo->di_btop, dinfo->di_bbot,
7512 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7513 + dinfo->di_tmpfile);
7514 + if (dinfo->di_btop < 0)
7516 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7517 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7520 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7524 + if (!file || IS_ERR(file)) {
7525 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7530 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7531 + && au_test_aufs(file->f_path.dentry->d_sb)
7533 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7534 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7535 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7536 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7537 + file->f_version, file->f_pos, a);
7538 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7539 + do_pri_dentry(bindex, file->f_path.dentry);
7543 +void au_dpri_file(struct file *file)
7545 + struct au_finfo *finfo;
7546 + struct au_fidir *fidir;
7547 + struct au_hfile *hfile;
7548 + aufs_bindex_t bindex;
7551 + err = do_pri_file(-1, file);
7553 + || IS_ERR_OR_NULL(file->f_path.dentry)
7554 + || !au_test_aufs(file->f_path.dentry->d_sb))
7557 + finfo = au_fi(file);
7560 + if (finfo->fi_btop < 0)
7562 + fidir = finfo->fi_hdir;
7564 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7566 + for (bindex = finfo->fi_btop;
7567 + bindex >= 0 && bindex <= fidir->fd_bbot;
7569 + hfile = fidir->fd_hfile + bindex;
7570 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7574 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7576 + struct vfsmount *mnt;
7577 + struct super_block *sb;
7579 + if (!br || IS_ERR(br))
7581 + mnt = au_br_mnt(br);
7582 + if (!mnt || IS_ERR(mnt))
7585 + if (!sb || IS_ERR(sb))
7588 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7589 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7591 + bindex, br->br_perm, br->br_id, au_br_count(br),
7592 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7593 + sb->s_flags, sb->s_count,
7594 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7598 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7602 +void au_dpri_sb(struct super_block *sb)
7604 + struct au_sbinfo *sbinfo;
7605 + aufs_bindex_t bindex;
7607 + /* to reuduce stack size */
7609 + struct vfsmount mnt;
7610 + struct au_branch fake;
7613 + /* this function can be called from magic sysrq */
7614 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7615 + if (unlikely(!a)) {
7616 + dpri("no memory\n");
7620 + a->mnt.mnt_sb = sb;
7621 + a->fake.br_path.mnt = &a->mnt;
7622 + au_br_count_init(&a->fake);
7623 + err = do_pri_br(-1, &a->fake);
7624 + au_br_count_fin(&a->fake);
7626 + dpri("dev 0x%x\n", sb->s_dev);
7627 + if (err || !au_test_aufs(sb))
7630 + sbinfo = au_sbi(sb);
7633 + dpri("nw %d, gen %u, kobj %d\n",
7634 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7635 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7636 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7637 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7640 +/* ---------------------------------------------------------------------- */
7642 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7644 + struct inode *h_inode, *inode = d_inode(dentry);
7645 + struct dentry *h_dentry;
7646 + aufs_bindex_t bindex, bbot, bi;
7648 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7651 + bbot = au_dbbot(dentry);
7652 + bi = au_ibbot(inode);
7655 + bindex = au_dbtop(dentry);
7656 + bi = au_ibtop(inode);
7660 + for (; bindex <= bbot; bindex++) {
7661 + h_dentry = au_h_dptr(dentry, bindex);
7664 + h_inode = au_h_iptr(inode, bindex);
7665 + if (unlikely(h_inode != d_inode(h_dentry))) {
7667 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7668 + AuDbgDentry(dentry);
7669 + AuDbgInode(inode);
7676 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7679 + struct au_dcsub_pages dpages;
7680 + struct au_dpage *dpage;
7681 + struct dentry **dentries;
7683 + err = au_dpages_init(&dpages, GFP_NOFS);
7685 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7687 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7688 + dpage = dpages.dpages + i;
7689 + dentries = dpage->dentries;
7690 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7691 + AuDebugOn(au_digen_test(dentries[j], sigen));
7693 + au_dpages_free(&dpages);
7696 +void au_dbg_verify_kthread(void)
7698 + if (au_wkq_test()) {
7701 + * It may be recursive, but udba=notify between two aufs mounts,
7702 + * where a single ro branch is shared, is not a problem.
7708 +/* ---------------------------------------------------------------------- */
7710 +int __init au_debug_init(void)
7712 + aufs_bindex_t bindex;
7713 + struct au_vdir_destr destr;
7716 + AuDebugOn(bindex >= 0);
7719 + AuDebugOn(destr.len < NAME_MAX);
7721 +#ifdef CONFIG_4KSTACKS
7722 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7727 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7728 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7729 +++ linux/fs/aufs/debug.h 2018-04-15 08:49:13.397817296 +0200
7732 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7734 + * This program, aufs is free software; you can redistribute it and/or modify
7735 + * it under the terms of the GNU General Public License as published by
7736 + * the Free Software Foundation; either version 2 of the License, or
7737 + * (at your option) any later version.
7739 + * This program is distributed in the hope that it will be useful,
7740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7742 + * GNU General Public License for more details.
7744 + * You should have received a copy of the GNU General Public License
7745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7749 + * debug print functions
7752 +#ifndef __AUFS_DEBUG_H__
7753 +#define __AUFS_DEBUG_H__
7757 +#include <linux/atomic.h>
7758 +#include <linux/module.h>
7759 +#include <linux/kallsyms.h>
7760 +#include <linux/sysrq.h>
7762 +#ifdef CONFIG_AUFS_DEBUG
7763 +#define AuDebugOn(a) BUG_ON(a)
7765 +/* module parameter */
7766 +extern atomic_t aufs_debug;
7767 +static inline void au_debug_on(void)
7769 + atomic_inc(&aufs_debug);
7771 +static inline void au_debug_off(void)
7773 + atomic_dec_if_positive(&aufs_debug);
7776 +static inline int au_debug_test(void)
7778 + return atomic_read(&aufs_debug) > 0;
7781 +#define AuDebugOn(a) do {} while (0)
7782 +AuStubVoid(au_debug_on, void)
7783 +AuStubVoid(au_debug_off, void)
7784 +AuStubInt0(au_debug_test, void)
7785 +#endif /* CONFIG_AUFS_DEBUG */
7787 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7789 +/* ---------------------------------------------------------------------- */
7793 +#define AuDbg(fmt, ...) do { \
7794 + if (au_debug_test()) \
7795 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7797 +#define AuLabel(l) AuDbg(#l "\n")
7798 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7799 +#define AuWarn1(fmt, ...) do { \
7800 + static unsigned char _c; \
7802 + pr_warn(fmt, ##__VA_ARGS__); \
7805 +#define AuErr1(fmt, ...) do { \
7806 + static unsigned char _c; \
7808 + pr_err(fmt, ##__VA_ARGS__); \
7811 +#define AuIOErr1(fmt, ...) do { \
7812 + static unsigned char _c; \
7814 + AuIOErr(fmt, ##__VA_ARGS__); \
7817 +#define AuUnsupportMsg "This operation is not supported." \
7818 + " Please report this application to aufs-users ML."
7819 +#define AuUnsupport(fmt, ...) do { \
7820 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7824 +#define AuTraceErr(e) do { \
7825 + if (unlikely((e) < 0)) \
7826 + AuDbg("err %d\n", (int)(e)); \
7829 +#define AuTraceErrPtr(p) do { \
7831 + AuDbg("err %ld\n", PTR_ERR(p)); \
7834 +/* dirty macros for debug print, use with "%.*s" and caution */
7835 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7837 +/* ---------------------------------------------------------------------- */
7840 +#ifdef CONFIG_AUFS_DEBUG
7841 +extern struct mutex au_dbg_mtx;
7842 +extern char *au_plevel;
7844 +void au_dpri_whlist(struct au_nhash *whlist);
7846 +void au_dpri_vdir(struct au_vdir *vdir);
7848 +void au_dpri_inode(struct inode *inode);
7849 +void au_dpri_dalias(struct inode *inode);
7850 +void au_dpri_dentry(struct dentry *dentry);
7852 +void au_dpri_file(struct file *filp);
7853 +struct super_block;
7854 +void au_dpri_sb(struct super_block *sb);
7856 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7857 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7858 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7859 +void au_dbg_verify_kthread(void);
7861 +int __init au_debug_init(void);
7863 +#define AuDbgWhlist(w) do { \
7864 + mutex_lock(&au_dbg_mtx); \
7866 + au_dpri_whlist(w); \
7867 + mutex_unlock(&au_dbg_mtx); \
7870 +#define AuDbgVdir(v) do { \
7871 + mutex_lock(&au_dbg_mtx); \
7873 + au_dpri_vdir(v); \
7874 + mutex_unlock(&au_dbg_mtx); \
7877 +#define AuDbgInode(i) do { \
7878 + mutex_lock(&au_dbg_mtx); \
7880 + au_dpri_inode(i); \
7881 + mutex_unlock(&au_dbg_mtx); \
7884 +#define AuDbgDAlias(i) do { \
7885 + mutex_lock(&au_dbg_mtx); \
7887 + au_dpri_dalias(i); \
7888 + mutex_unlock(&au_dbg_mtx); \
7891 +#define AuDbgDentry(d) do { \
7892 + mutex_lock(&au_dbg_mtx); \
7894 + au_dpri_dentry(d); \
7895 + mutex_unlock(&au_dbg_mtx); \
7898 +#define AuDbgFile(f) do { \
7899 + mutex_lock(&au_dbg_mtx); \
7901 + au_dpri_file(f); \
7902 + mutex_unlock(&au_dbg_mtx); \
7905 +#define AuDbgSb(sb) do { \
7906 + mutex_lock(&au_dbg_mtx); \
7907 + AuDbg(#sb "\n"); \
7909 + mutex_unlock(&au_dbg_mtx); \
7912 +#define AuDbgSym(addr) do { \
7913 + char sym[KSYM_SYMBOL_LEN]; \
7914 + sprint_symbol(sym, (unsigned long)addr); \
7915 + AuDbg("%s\n", sym); \
7918 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7919 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7920 +AuStubVoid(au_dbg_verify_kthread, void)
7921 +AuStubInt0(__init au_debug_init, void)
7923 +#define AuDbgWhlist(w) do {} while (0)
7924 +#define AuDbgVdir(v) do {} while (0)
7925 +#define AuDbgInode(i) do {} while (0)
7926 +#define AuDbgDAlias(i) do {} while (0)
7927 +#define AuDbgDentry(d) do {} while (0)
7928 +#define AuDbgFile(f) do {} while (0)
7929 +#define AuDbgSb(sb) do {} while (0)
7930 +#define AuDbgSym(addr) do {} while (0)
7931 +#endif /* CONFIG_AUFS_DEBUG */
7933 +/* ---------------------------------------------------------------------- */
7935 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7936 +int __init au_sysrq_init(void);
7937 +void au_sysrq_fin(void);
7939 +#ifdef CONFIG_HW_CONSOLE
7940 +#define au_dbg_blocked() do { \
7942 + handle_sysrq('w'); \
7945 +AuStubVoid(au_dbg_blocked, void)
7949 +AuStubInt0(__init au_sysrq_init, void)
7950 +AuStubVoid(au_sysrq_fin, void)
7951 +AuStubVoid(au_dbg_blocked, void)
7952 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7954 +#endif /* __KERNEL__ */
7955 +#endif /* __AUFS_DEBUG_H__ */
7956 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7957 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7958 +++ linux/fs/aufs/dentry.c 2018-04-15 08:49:13.397817296 +0200
7961 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7963 + * This program, aufs is free software; you can redistribute it and/or modify
7964 + * it under the terms of the GNU General Public License as published by
7965 + * the Free Software Foundation; either version 2 of the License, or
7966 + * (at your option) any later version.
7968 + * This program is distributed in the hope that it will be useful,
7969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7971 + * GNU General Public License for more details.
7973 + * You should have received a copy of the GNU General Public License
7974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7978 + * lookup and dentry operations
7981 +#include <linux/namei.h>
7985 + * returns positive/negative dentry, NULL or an error.
7986 + * NULL means whiteout-ed or not-found.
7988 +static struct dentry*
7989 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7990 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7992 + struct dentry *h_dentry;
7993 + struct inode *h_inode;
7994 + struct au_branch *br;
7995 + int wh_found, opq;
7996 + unsigned char wh_able;
7997 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7998 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8002 + br = au_sbr(dentry->d_sb, bindex);
8003 + wh_able = !!au_br_whable(br->br_perm);
8005 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8006 + h_dentry = ERR_PTR(wh_found);
8009 + if (unlikely(wh_found < 0))
8012 + /* We found a whiteout */
8013 + /* au_set_dbbot(dentry, bindex); */
8014 + au_set_dbwh(dentry, bindex);
8016 + return NULL; /* success */
8020 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8022 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8023 + if (IS_ERR(h_dentry)) {
8024 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8030 + h_inode = d_inode(h_dentry);
8031 + if (d_is_negative(h_dentry)) {
8034 + } else if (wh_found
8035 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8037 + else if (au_ftest_lkup(args->flags, DIRREN)
8039 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8040 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8041 + (unsigned long long)h_inode->i_ino);
8045 + if (au_dbbot(dentry) <= bindex)
8046 + au_set_dbbot(dentry, bindex);
8047 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8048 + au_set_dbtop(dentry, bindex);
8049 + au_set_h_dptr(dentry, bindex, h_dentry);
8051 + if (!d_is_dir(h_dentry)
8053 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8054 + goto out; /* success */
8056 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8057 + opq = au_diropq_test(h_dentry);
8058 + inode_unlock_shared(h_inode);
8060 + au_set_dbdiropq(dentry, bindex);
8061 + else if (unlikely(opq < 0)) {
8062 + au_set_h_dptr(dentry, bindex, NULL);
8063 + h_dentry = ERR_PTR(opq);
8074 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8076 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8077 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8083 + * returns the number of lower positive dentries,
8084 + * otherwise an error.
8085 + * can be called at unlinking with @type is zero.
8087 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8088 + unsigned int flags)
8090 + int npositive, err;
8091 + aufs_bindex_t bindex, btail, bdiropq;
8092 + unsigned char isdir, dirperm1, dirren;
8093 + struct au_do_lookup_args args = {
8095 + .name = &dentry->d_name
8097 + struct dentry *parent;
8098 + struct super_block *sb;
8100 + sb = dentry->d_sb;
8101 + err = au_test_shwh(sb, args.name);
8102 + if (unlikely(err))
8105 + err = au_wh_name_alloc(&args.whname, args.name);
8106 + if (unlikely(err))
8109 + isdir = !!d_is_dir(dentry);
8110 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8111 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8113 + au_fset_lkup(args.flags, DIRREN);
8116 + parent = dget_parent(dentry);
8117 + btail = au_dbtaildir(parent);
8118 + for (bindex = btop; bindex <= btail; bindex++) {
8119 + struct dentry *h_parent, *h_dentry;
8120 + struct inode *h_inode, *h_dir;
8121 + struct au_branch *br;
8123 + h_dentry = au_h_dptr(dentry, bindex);
8125 + if (d_is_positive(h_dentry))
8129 + h_parent = au_h_dptr(parent, bindex);
8130 + if (!h_parent || !d_is_dir(h_parent))
8134 + /* if the inum matches, then use the prepared name */
8135 + err = au_dr_lkup_name(&args, bindex);
8136 + if (unlikely(err))
8140 + h_dir = d_inode(h_parent);
8141 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8142 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8143 + inode_unlock_shared(h_dir);
8144 + err = PTR_ERR(h_dentry);
8145 + if (IS_ERR(h_dentry))
8148 + au_fclr_lkup(args.flags, ALLOW_NEG);
8150 + au_fset_lkup(args.flags, IGNORE_PERM);
8152 + if (au_dbwh(dentry) == bindex)
8156 + if (d_is_negative(h_dentry))
8158 + h_inode = d_inode(h_dentry);
8161 + args.type = h_inode->i_mode & S_IFMT;
8162 + if (args.type != S_IFDIR)
8165 + /* the type of lower may be different */
8166 + bdiropq = au_dbdiropq(dentry);
8167 + if (bdiropq >= 0 && bdiropq <= bindex)
8170 + br = au_sbr(sb, bindex);
8172 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8173 + /*add_ent*/NULL)) {
8174 + /* prepare next name to lookup */
8175 + err = au_dr_lkup(&args, dentry, bindex);
8176 + if (unlikely(err))
8182 + AuLabel(positive);
8183 + au_update_dbtop(dentry);
8186 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8187 + && au_dbtop(dentry) < 0)) {
8189 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8195 + kfree(args.whname.name);
8197 + au_dr_lkup_fin(&args);
8202 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8204 + struct dentry *dentry;
8207 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8208 + dentry = vfsub_lkup_one(name, parent);
8210 + struct vfsub_lkup_one_args args = {
8216 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8217 + if (unlikely(wkq_err))
8218 + dentry = ERR_PTR(wkq_err);
8225 + * lookup @dentry on @bindex which should be negative.
8227 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8230 + struct dentry *parent, *h_parent, *h_dentry;
8231 + struct au_branch *br;
8233 + parent = dget_parent(dentry);
8234 + h_parent = au_h_dptr(parent, bindex);
8235 + br = au_sbr(dentry->d_sb, bindex);
8237 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8239 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8240 + err = PTR_ERR(h_dentry);
8241 + if (IS_ERR(h_dentry))
8243 + if (unlikely(d_is_positive(h_dentry))) {
8245 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8251 + if (bindex < au_dbtop(dentry))
8252 + au_set_dbtop(dentry, bindex);
8253 + if (au_dbbot(dentry) < bindex)
8254 + au_set_dbbot(dentry, bindex);
8255 + au_set_h_dptr(dentry, bindex, h_dentry);
8262 +/* ---------------------------------------------------------------------- */
8264 +/* subset of struct inode */
8266 + unsigned long i_ino;
8267 + /* unsigned int i_nlink; */
8273 + blkcnt_t i_blocks;
8278 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8280 + ia->i_ino = h_inode->i_ino;
8281 + /* ia->i_nlink = h_inode->i_nlink; */
8282 + ia->i_uid = h_inode->i_uid;
8283 + ia->i_gid = h_inode->i_gid;
8284 + ia->i_version = h_inode->i_version;
8286 + ia->i_size = h_inode->i_size;
8287 + ia->i_blocks = h_inode->i_blocks;
8289 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8292 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8294 + return ia->i_ino != h_inode->i_ino
8295 + /* || ia->i_nlink != h_inode->i_nlink */
8296 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8297 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8298 + || ia->i_version != h_inode->i_version
8300 + || ia->i_size != h_inode->i_size
8301 + || ia->i_blocks != h_inode->i_blocks
8303 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8306 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8307 + struct au_branch *br)
8310 + struct au_iattr ia;
8311 + struct inode *h_inode;
8312 + struct dentry *h_d;
8313 + struct super_block *h_sb;
8316 + memset(&ia, -1, sizeof(ia));
8317 + h_sb = h_dentry->d_sb;
8319 + if (d_is_positive(h_dentry)) {
8320 + h_inode = d_inode(h_dentry);
8321 + au_iattr_save(&ia, h_inode);
8322 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8323 + /* nfs d_revalidate may return 0 for negative dentry */
8324 + /* fuse d_revalidate always return 0 for negative dentry */
8327 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8328 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8329 + err = PTR_ERR(h_d);
8334 + if (unlikely(h_d != h_dentry
8335 + || d_inode(h_d) != h_inode
8336 + || (h_inode && au_iattr_test(&ia, h_inode))))
8337 + err = au_busy_or_stale();
8345 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8346 + struct dentry *h_parent, struct au_branch *br)
8351 + if (udba == AuOpt_UDBA_REVAL
8352 + && !au_test_fs_remote(h_dentry->d_sb)) {
8354 + err = (d_inode(h_dentry->d_parent) != h_dir);
8355 + } else if (udba != AuOpt_UDBA_NONE)
8356 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8361 +/* ---------------------------------------------------------------------- */
8363 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8366 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8367 + struct au_hdentry tmp, *p, *q;
8368 + struct au_dinfo *dinfo;
8369 + struct super_block *sb;
8371 + DiMustWriteLock(dentry);
8373 + sb = dentry->d_sb;
8374 + dinfo = au_di(dentry);
8375 + bbot = dinfo->di_bbot;
8376 + bwh = dinfo->di_bwh;
8377 + bdiropq = dinfo->di_bdiropq;
8378 + bindex = dinfo->di_btop;
8379 + p = au_hdentry(dinfo, bindex);
8380 + for (; bindex <= bbot; bindex++, p++) {
8381 + if (!p->hd_dentry)
8384 + new_bindex = au_br_index(sb, p->hd_id);
8385 + if (new_bindex == bindex)
8388 + if (dinfo->di_bwh == bindex)
8390 + if (dinfo->di_bdiropq == bindex)
8391 + bdiropq = new_bindex;
8392 + if (new_bindex < 0) {
8394 + p->hd_dentry = NULL;
8398 + /* swap two lower dentries, and loop again */
8399 + q = au_hdentry(dinfo, new_bindex);
8403 + if (tmp.hd_dentry) {
8409 + dinfo->di_bwh = -1;
8410 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8411 + dinfo->di_bwh = bwh;
8413 + dinfo->di_bdiropq = -1;
8415 + && bdiropq <= au_sbbot(sb)
8416 + && au_sbr_whable(sb, bdiropq))
8417 + dinfo->di_bdiropq = bdiropq;
8420 + dinfo->di_btop = -1;
8421 + dinfo->di_bbot = -1;
8422 + bbot = au_dbbot(parent);
8424 + p = au_hdentry(dinfo, bindex);
8425 + for (; bindex <= bbot; bindex++, p++)
8426 + if (p->hd_dentry) {
8427 + dinfo->di_btop = bindex;
8431 + if (dinfo->di_btop >= 0) {
8433 + p = au_hdentry(dinfo, bindex);
8434 + for (; bindex >= 0; bindex--, p--)
8435 + if (p->hd_dentry) {
8436 + dinfo->di_bbot = bindex;
8445 +static void au_do_hide(struct dentry *dentry)
8447 + struct inode *inode;
8449 + if (d_really_is_positive(dentry)) {
8450 + inode = d_inode(dentry);
8451 + if (!d_is_dir(dentry)) {
8452 + if (inode->i_nlink && !d_unhashed(dentry))
8453 + drop_nlink(inode);
8455 + clear_nlink(inode);
8456 + /* stop next lookup */
8457 + inode->i_flags |= S_DEAD;
8459 + smp_mb(); /* necessary? */
8464 +static int au_hide_children(struct dentry *parent)
8466 + int err, i, j, ndentry;
8467 + struct au_dcsub_pages dpages;
8468 + struct au_dpage *dpage;
8469 + struct dentry *dentry;
8471 + err = au_dpages_init(&dpages, GFP_NOFS);
8472 + if (unlikely(err))
8474 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8475 + if (unlikely(err))
8478 + /* in reverse order */
8479 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8480 + dpage = dpages.dpages + i;
8481 + ndentry = dpage->ndentry;
8482 + for (j = ndentry - 1; j >= 0; j--) {
8483 + dentry = dpage->dentries[j];
8484 + if (dentry != parent)
8485 + au_do_hide(dentry);
8490 + au_dpages_free(&dpages);
8495 +static void au_hide(struct dentry *dentry)
8499 + AuDbgDentry(dentry);
8500 + if (d_is_dir(dentry)) {
8501 + /* shrink_dcache_parent(dentry); */
8502 + err = au_hide_children(dentry);
8503 + if (unlikely(err))
8504 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8507 + au_do_hide(dentry);
8511 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8513 + * a dirty branch is added
8514 + * - on the top of layers
8515 + * - in the middle of layers
8516 + * - to the bottom of layers
8518 + * on the added branch there exists
8521 + * - a same named entry
8523 + * * negative --> positive
8524 + * * positive --> positive
8525 + * - type is unchanged
8526 + * - type is changed
8528 + * * negative --> negative
8529 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8532 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8533 + struct au_dinfo *tmp)
8536 + aufs_bindex_t bindex, bbot;
8538 + struct dentry *dentry;
8539 + struct inode *inode;
8541 + } orig_h, tmp_h = {
8544 + struct au_hdentry *hd;
8545 + struct inode *inode, *h_inode;
8546 + struct dentry *h_dentry;
8549 + AuDebugOn(dinfo->di_btop < 0);
8551 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8552 + orig_h.inode = NULL;
8553 + if (d_is_positive(orig_h.dentry)) {
8554 + orig_h.inode = d_inode(orig_h.dentry);
8555 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8557 + if (tmp->di_btop >= 0) {
8558 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8559 + if (d_is_positive(tmp_h.dentry)) {
8560 + tmp_h.inode = d_inode(tmp_h.dentry);
8561 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8566 + if (d_really_is_positive(dentry))
8567 + inode = d_inode(dentry);
8568 + if (!orig_h.inode) {
8569 + AuDbg("nagative originally\n");
8575 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8576 + AuDebugOn(dinfo->di_bdiropq != -1);
8578 + if (!tmp_h.inode) {
8579 + AuDbg("negative --> negative\n");
8580 + /* should have only one negative lower */
8581 + if (tmp->di_btop >= 0
8582 + && tmp->di_btop < dinfo->di_btop) {
8583 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8584 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8585 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8586 + au_di_cp(dinfo, tmp);
8587 + hd = au_hdentry(tmp, tmp->di_btop);
8588 + au_set_h_dptr(dentry, tmp->di_btop,
8589 + dget(hd->hd_dentry));
8591 + au_dbg_verify_dinode(dentry);
8593 + AuDbg("negative --> positive\n");
8595 + * similar to the behaviour of creating with bypassing
8597 + * unhash it in order to force an error in the
8598 + * succeeding create operation.
8599 + * we should not set S_DEAD here.
8602 + /* au_di_swap(tmp, dinfo); */
8603 + au_dbg_verify_dinode(dentry);
8606 + AuDbg("positive originally\n");
8607 + /* inode may be NULL */
8608 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8609 + if (!tmp_h.inode) {
8610 + AuDbg("positive --> negative\n");
8611 + /* or bypassing aufs */
8613 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8614 + dinfo->di_bwh = tmp->di_bwh;
8616 + err = au_refresh_hinode_self(inode);
8617 + au_dbg_verify_dinode(dentry);
8618 + } else if (orig_h.mode == tmp_h.mode) {
8619 + AuDbg("positive --> positive, same type\n");
8620 + if (!S_ISDIR(orig_h.mode)
8621 + && dinfo->di_btop > tmp->di_btop) {
8623 + * similar to the behaviour of removing and
8628 + err = au_refresh_hinode_self(inode);
8629 + au_dbg_verify_dinode(dentry);
8631 + /* fill empty slots */
8632 + if (dinfo->di_btop > tmp->di_btop)
8633 + dinfo->di_btop = tmp->di_btop;
8634 + if (dinfo->di_bbot < tmp->di_bbot)
8635 + dinfo->di_bbot = tmp->di_bbot;
8636 + dinfo->di_bwh = tmp->di_bwh;
8637 + dinfo->di_bdiropq = tmp->di_bdiropq;
8638 + bbot = dinfo->di_bbot;
8639 + bindex = tmp->di_btop;
8640 + hd = au_hdentry(tmp, bindex);
8641 + for (; bindex <= bbot; bindex++, hd++) {
8642 + if (au_h_dptr(dentry, bindex))
8644 + h_dentry = hd->hd_dentry;
8647 + AuDebugOn(d_is_negative(h_dentry));
8648 + h_inode = d_inode(h_dentry);
8649 + AuDebugOn(orig_h.mode
8650 + != (h_inode->i_mode
8652 + au_set_h_dptr(dentry, bindex,
8656 + err = au_refresh_hinode(inode, dentry);
8657 + au_dbg_verify_dinode(dentry);
8660 + AuDbg("positive --> positive, different type\n");
8661 + /* similar to the behaviour of removing and creating */
8664 + err = au_refresh_hinode_self(inode);
8665 + au_dbg_verify_dinode(dentry);
8673 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8675 + const struct dentry_operations *dop
8676 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8677 + static const unsigned int mask
8678 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8680 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8682 + if (dentry->d_op == dop)
8685 + AuDbg("%pd\n", dentry);
8686 + spin_lock(&dentry->d_lock);
8687 + if (dop == &aufs_dop)
8688 + dentry->d_flags |= mask;
8690 + dentry->d_flags &= ~mask;
8691 + dentry->d_op = dop;
8692 + spin_unlock(&dentry->d_lock);
8695 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8697 + int err, ebrange, nbr;
8698 + unsigned int sigen;
8699 + struct au_dinfo *dinfo, *tmp;
8700 + struct super_block *sb;
8701 + struct inode *inode;
8703 + DiMustWriteLock(dentry);
8704 + AuDebugOn(IS_ROOT(dentry));
8705 + AuDebugOn(d_really_is_negative(parent));
8707 + sb = dentry->d_sb;
8708 + sigen = au_sigen(sb);
8709 + err = au_digen_test(parent, sigen);
8710 + if (unlikely(err))
8713 + nbr = au_sbbot(sb) + 1;
8714 + dinfo = au_di(dentry);
8715 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8716 + if (unlikely(err))
8718 + ebrange = au_dbrange_test(dentry);
8720 + ebrange = au_do_refresh_hdentry(dentry, parent);
8722 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8723 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8724 + if (d_really_is_positive(dentry)) {
8725 + inode = d_inode(dentry);
8726 + err = au_refresh_hinode_self(inode);
8728 + au_dbg_verify_dinode(dentry);
8730 + goto out_dgen; /* success */
8734 + /* temporary dinfo */
8735 + AuDbgDentry(dentry);
8737 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8738 + if (unlikely(!tmp))
8740 + au_di_swap(tmp, dinfo);
8741 + /* returns the number of positive dentries */
8743 + * if current working dir is removed, it returns an error.
8744 + * but the dentry is legal.
8746 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8747 + AuDbgDentry(dentry);
8748 + au_di_swap(tmp, dinfo);
8749 + if (err == -ENOENT)
8752 + /* compare/refresh by dinfo */
8753 + AuDbgDentry(dentry);
8754 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8755 + au_dbg_verify_dinode(dentry);
8758 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8759 + au_rw_write_unlock(&tmp->di_rwsem);
8761 + if (unlikely(err))
8765 + au_update_digen(dentry);
8767 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8768 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8769 + AuDbgDentry(dentry);
8775 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8776 + struct dentry *dentry, aufs_bindex_t bindex)
8781 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8784 + AuDbg("b%d\n", bindex);
8786 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8787 + * due to whiteout and branch permission.
8789 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8790 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8791 + /* it may return tri-state */
8792 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8794 + if (unlikely(valid < 0))
8804 +/* todo: remove this */
8805 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8806 + unsigned int flags, int do_udba, int dirren)
8809 + umode_t mode, h_mode;
8810 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8811 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8812 + struct inode *h_inode, *h_cached_inode;
8813 + struct dentry *h_dentry;
8814 + struct qstr *name, *h_name;
8821 + unhashed = !!d_unhashed(dentry);
8822 + is_root = !!IS_ROOT(dentry);
8823 + name = &dentry->d_name;
8824 + tmpfile = au_di(dentry)->di_tmpfile;
8827 + * Theoretically, REVAL test should be unnecessary in case of
8829 + * But {fs,i}notify doesn't fire some necessary events,
8830 + * IN_ATTRIB for atime/nlink/pageio
8831 + * Let's do REVAL test too.
8833 + if (do_udba && inode) {
8834 + mode = (inode->i_mode & S_IFMT);
8835 + plus = (inode->i_nlink > 0);
8836 + ibs = au_ibtop(inode);
8837 + ibe = au_ibbot(inode);
8840 + btop = au_dbtop(dentry);
8842 + if (inode && S_ISDIR(inode->i_mode))
8843 + btail = au_dbtaildir(dentry);
8844 + for (bindex = btop; bindex <= btail; bindex++) {
8845 + h_dentry = au_h_dptr(dentry, bindex);
8849 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8850 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8851 + spin_lock(&h_dentry->d_lock);
8852 + h_name = &h_dentry->d_name;
8853 + if (unlikely(do_udba
8856 + && (unhashed != !!d_unhashed(h_dentry)
8857 + || (!tmpfile && !dirren
8858 + && !au_qstreq(name, h_name))
8861 + && !(flags & LOOKUP_OPEN)
8862 + && (h_dentry->d_flags
8863 + & DCACHE_NFSFS_RENAMED)))
8867 + h_unhashed = d_unhashed(h_dentry);
8868 + spin_unlock(&h_dentry->d_lock);
8869 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8870 + unhashed, h_unhashed, dentry, h_dentry);
8873 + spin_unlock(&h_dentry->d_lock);
8875 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8876 + if (unlikely(err))
8877 + /* do not goto err, to keep the errno */
8880 + /* todo: plink too? */
8885 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8889 + if (d_is_positive(h_dentry))
8890 + h_inode = d_inode(h_dentry);
8893 + h_cached_inode = h_inode;
8895 + h_mode = (h_inode->i_mode & S_IFMT);
8896 + h_plus = (h_inode->i_nlink > 0);
8898 + if (inode && ibs <= bindex && bindex <= ibe)
8899 + h_cached_inode = au_h_iptr(inode, bindex);
8902 + if (unlikely(plus != h_plus && !tmpfile))
8905 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8907 + && !IS_ROOT(h_dentry)
8908 + && unhashed != d_unhashed(h_dentry)))
8911 + if (unlikely(mode != h_mode
8912 + || h_cached_inode != h_inode))
8925 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8926 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8929 + struct dentry *parent;
8931 + if (!au_digen_test(dentry, sigen))
8934 + parent = dget_parent(dentry);
8935 + di_read_lock_parent(parent, AuLock_IR);
8936 + AuDebugOn(au_digen_test(parent, sigen));
8937 + au_dbg_verify_gen(parent, sigen);
8938 + err = au_refresh_dentry(dentry, parent);
8939 + di_read_unlock(parent, AuLock_IR);
8945 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8948 + struct dentry *d, *parent;
8950 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8951 + return simple_reval_dpath(dentry, sigen);
8953 + /* slow loop, keep it simple and stupid */
8954 + /* cf: au_cpup_dirs() */
8957 + while (au_digen_test(dentry, sigen)) {
8961 + parent = dget_parent(d);
8962 + if (!au_digen_test(parent, sigen))
8968 + di_write_lock_child2(d);
8970 + /* someone might update our dentry while we were sleeping */
8971 + if (au_digen_test(d, sigen)) {
8973 + * todo: consolidate with simple_reval_dpath(),
8974 + * do_refresh() and au_reval_for_attr().
8976 + di_read_lock_parent(parent, AuLock_IR);
8977 + err = au_refresh_dentry(d, parent);
8978 + di_read_unlock(parent, AuLock_IR);
8982 + di_write_unlock(d);
8984 + if (unlikely(err))
8992 + * if valid returns 1, otherwise 0.
8994 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8997 + unsigned int sigen;
8998 + unsigned char do_udba, dirren;
8999 + struct super_block *sb;
9000 + struct inode *inode;
9002 + /* todo: support rcu-walk? */
9003 + if (flags & LOOKUP_RCU)
9007 + if (unlikely(!au_di(dentry)))
9011 + sb = dentry->d_sb;
9014 + * i_mutex of parent dir may be held,
9015 + * but we should not return 'invalid' due to busy.
9017 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9018 + if (unlikely(err)) {
9024 + if (d_really_is_positive(dentry))
9025 + inode = d_inode(dentry);
9026 + if (unlikely(inode && au_is_bad_inode(inode))) {
9031 + if (unlikely(au_dbrange_test(dentry))) {
9037 + sigen = au_sigen(sb);
9038 + if (au_digen_test(dentry, sigen)) {
9039 + AuDebugOn(IS_ROOT(dentry));
9040 + err = au_reval_dpath(dentry, sigen);
9041 + if (unlikely(err)) {
9046 + di_downgrade_lock(dentry, AuLock_IR);
9049 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9051 + && !(inode->i_state && I_LINKABLE)
9052 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9057 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9058 + if (do_udba && inode) {
9059 + aufs_bindex_t btop = au_ibtop(inode);
9060 + struct inode *h_inode;
9063 + h_inode = au_h_iptr(inode, btop);
9064 + if (h_inode && au_test_higen(inode, h_inode)) {
9071 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9072 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9073 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9075 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9081 + di_downgrade_lock(dentry, AuLock_IR);
9083 + aufs_read_unlock(dentry, AuLock_IR);
9088 + AuDbg("%pd invalid, %d\n", dentry, valid);
9094 +static void aufs_d_release(struct dentry *dentry)
9096 + if (au_di(dentry)) {
9097 + au_di_fin(dentry);
9098 + au_hn_di_reinit(dentry);
9102 +const struct dentry_operations aufs_dop = {
9103 + .d_revalidate = aufs_d_revalidate,
9104 + .d_weak_revalidate = aufs_d_revalidate,
9105 + .d_release = aufs_d_release
9108 +/* aufs_dop without d_revalidate */
9109 +const struct dentry_operations aufs_dop_noreval = {
9110 + .d_release = aufs_d_release
9112 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9113 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9114 +++ linux/fs/aufs/dentry.h 2018-04-15 08:49:13.397817296 +0200
9117 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9119 + * This program, aufs is free software; you can redistribute it and/or modify
9120 + * it under the terms of the GNU General Public License as published by
9121 + * the Free Software Foundation; either version 2 of the License, or
9122 + * (at your option) any later version.
9124 + * This program is distributed in the hope that it will be useful,
9125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9127 + * GNU General Public License for more details.
9129 + * You should have received a copy of the GNU General Public License
9130 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9134 + * lookup and dentry operations
9137 +#ifndef __AUFS_DENTRY_H__
9138 +#define __AUFS_DENTRY_H__
9142 +#include <linux/dcache.h>
9143 +#include "dirren.h"
9146 +struct au_hdentry {
9147 + struct dentry *hd_dentry;
9148 + aufs_bindex_t hd_id;
9152 + atomic_t di_generation;
9154 + struct au_rwsem di_rwsem;
9155 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9156 + unsigned char di_tmpfile; /* to allow the different name */
9157 + struct au_hdentry *di_hdentry;
9158 +} ____cacheline_aligned_in_smp;
9160 +/* ---------------------------------------------------------------------- */
9162 +/* flags for au_lkup_dentry() */
9163 +#define AuLkup_ALLOW_NEG 1
9164 +#define AuLkup_IGNORE_PERM (1 << 1)
9165 +#define AuLkup_DIRREN (1 << 2)
9166 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9167 +#define au_fset_lkup(flags, name) \
9168 + do { (flags) |= AuLkup_##name; } while (0)
9169 +#define au_fclr_lkup(flags, name) \
9170 + do { (flags) &= ~AuLkup_##name; } while (0)
9172 +#ifndef CONFIG_AUFS_DIRREN
9173 +#undef AuLkup_DIRREN
9174 +#define AuLkup_DIRREN 0
9177 +struct au_do_lookup_args {
9178 + unsigned int flags;
9180 + struct qstr whname, *name;
9181 + struct au_dr_lookup dirren;
9184 +/* ---------------------------------------------------------------------- */
9187 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9189 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9190 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9191 + struct dentry *h_parent, struct au_branch *br);
9193 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9194 + unsigned int flags);
9195 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9196 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9197 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9198 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9201 +void au_di_init_once(void *_di);
9202 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9203 +void au_di_free(struct au_dinfo *dinfo);
9204 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9205 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9206 +int au_di_init(struct dentry *dentry);
9207 +void au_di_fin(struct dentry *dentry);
9208 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9210 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9211 +void di_read_unlock(struct dentry *d, int flags);
9212 +void di_downgrade_lock(struct dentry *d, int flags);
9213 +void di_write_lock(struct dentry *d, unsigned int lsc);
9214 +void di_write_unlock(struct dentry *d);
9215 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9216 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9217 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9219 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9220 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9221 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9222 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9224 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9225 + struct dentry *h_dentry);
9226 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9227 +int au_dbrange_test(struct dentry *dentry);
9228 +void au_update_digen(struct dentry *dentry);
9229 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9230 +void au_update_dbtop(struct dentry *dentry);
9231 +void au_update_dbbot(struct dentry *dentry);
9232 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9234 +/* ---------------------------------------------------------------------- */
9236 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9238 + return dentry->d_fsdata;
9241 +/* ---------------------------------------------------------------------- */
9243 +/* lock subclass for dinfo */
9245 + AuLsc_DI_CHILD, /* child first */
9246 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9247 + AuLsc_DI_CHILD3, /* copyup dirs */
9251 + AuLsc_DI_TMP /* temp for replacing dinfo */
9255 + * di_read_lock_child, di_write_lock_child,
9256 + * di_read_lock_child2, di_write_lock_child2,
9257 + * di_read_lock_child3, di_write_lock_child3,
9258 + * di_read_lock_parent, di_write_lock_parent,
9259 + * di_read_lock_parent2, di_write_lock_parent2,
9260 + * di_read_lock_parent3, di_write_lock_parent3,
9262 +#define AuReadLockFunc(name, lsc) \
9263 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9264 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9266 +#define AuWriteLockFunc(name, lsc) \
9267 +static inline void di_write_lock_##name(struct dentry *d) \
9268 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9270 +#define AuRWLockFuncs(name, lsc) \
9271 + AuReadLockFunc(name, lsc) \
9272 + AuWriteLockFunc(name, lsc)
9274 +AuRWLockFuncs(child, CHILD);
9275 +AuRWLockFuncs(child2, CHILD2);
9276 +AuRWLockFuncs(child3, CHILD3);
9277 +AuRWLockFuncs(parent, PARENT);
9278 +AuRWLockFuncs(parent2, PARENT2);
9279 +AuRWLockFuncs(parent3, PARENT3);
9281 +#undef AuReadLockFunc
9282 +#undef AuWriteLockFunc
9283 +#undef AuRWLockFuncs
9285 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9286 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9287 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9289 +/* ---------------------------------------------------------------------- */
9291 +/* todo: memory barrier? */
9292 +static inline unsigned int au_digen(struct dentry *d)
9294 + return atomic_read(&au_di(d)->di_generation);
9297 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9299 + hdentry->hd_dentry = NULL;
9302 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9303 + aufs_bindex_t bindex)
9305 + return di->di_hdentry + bindex;
9308 +static inline void au_hdput(struct au_hdentry *hd)
9311 + dput(hd->hd_dentry);
9314 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9316 + DiMustAnyLock(dentry);
9317 + return au_di(dentry)->di_btop;
9320 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9322 + DiMustAnyLock(dentry);
9323 + return au_di(dentry)->di_bbot;
9326 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9328 + DiMustAnyLock(dentry);
9329 + return au_di(dentry)->di_bwh;
9332 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9334 + DiMustAnyLock(dentry);
9335 + return au_di(dentry)->di_bdiropq;
9338 +/* todo: hard/soft set? */
9339 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9341 + DiMustWriteLock(dentry);
9342 + au_di(dentry)->di_btop = bindex;
9345 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9347 + DiMustWriteLock(dentry);
9348 + au_di(dentry)->di_bbot = bindex;
9351 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9353 + DiMustWriteLock(dentry);
9354 + /* dbwh can be outside of btop - bbot range */
9355 + au_di(dentry)->di_bwh = bindex;
9358 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9360 + DiMustWriteLock(dentry);
9361 + au_di(dentry)->di_bdiropq = bindex;
9364 +/* ---------------------------------------------------------------------- */
9366 +#ifdef CONFIG_AUFS_HNOTIFY
9367 +static inline void au_digen_dec(struct dentry *d)
9369 + atomic_dec(&au_di(d)->di_generation);
9372 +static inline void au_hn_di_reinit(struct dentry *dentry)
9374 + dentry->d_fsdata = NULL;
9377 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9378 +#endif /* CONFIG_AUFS_HNOTIFY */
9380 +#endif /* __KERNEL__ */
9381 +#endif /* __AUFS_DENTRY_H__ */
9382 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9383 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9384 +++ linux/fs/aufs/dinfo.c 2018-04-15 08:49:13.397817296 +0200
9387 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9389 + * This program, aufs is free software; you can redistribute it and/or modify
9390 + * it under the terms of the GNU General Public License as published by
9391 + * the Free Software Foundation; either version 2 of the License, or
9392 + * (at your option) any later version.
9394 + * This program is distributed in the hope that it will be useful,
9395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9397 + * GNU General Public License for more details.
9399 + * You should have received a copy of the GNU General Public License
9400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9404 + * dentry private data
9409 +void au_di_init_once(void *_dinfo)
9411 + struct au_dinfo *dinfo = _dinfo;
9413 + au_rw_init(&dinfo->di_rwsem);
9416 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9418 + struct au_dinfo *dinfo;
9421 + dinfo = au_cache_alloc_dinfo();
9422 + if (unlikely(!dinfo))
9425 + nbr = au_sbbot(sb) + 1;
9428 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9429 + if (dinfo->di_hdentry) {
9430 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9431 + dinfo->di_btop = -1;
9432 + dinfo->di_bbot = -1;
9433 + dinfo->di_bwh = -1;
9434 + dinfo->di_bdiropq = -1;
9435 + dinfo->di_tmpfile = 0;
9436 + for (i = 0; i < nbr; i++)
9437 + dinfo->di_hdentry[i].hd_id = -1;
9441 + au_cache_free_dinfo(dinfo);
9448 +void au_di_free(struct au_dinfo *dinfo)
9450 + struct au_hdentry *p;
9451 + aufs_bindex_t bbot, bindex;
9453 + /* dentry may not be revalidated */
9454 + bindex = dinfo->di_btop;
9455 + if (bindex >= 0) {
9456 + bbot = dinfo->di_bbot;
9457 + p = au_hdentry(dinfo, bindex);
9458 + while (bindex++ <= bbot)
9461 + kfree(dinfo->di_hdentry);
9462 + au_cache_free_dinfo(dinfo);
9465 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9467 + struct au_hdentry *p;
9470 + AuRwMustWriteLock(&a->di_rwsem);
9471 + AuRwMustWriteLock(&b->di_rwsem);
9473 +#define DiSwap(v, name) \
9475 + v = a->di_##name; \
9476 + a->di_##name = b->di_##name; \
9477 + b->di_##name = v; \
9480 + DiSwap(p, hdentry);
9484 + DiSwap(bi, bdiropq);
9490 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9492 + AuRwMustWriteLock(&dst->di_rwsem);
9493 + AuRwMustWriteLock(&src->di_rwsem);
9495 + dst->di_btop = src->di_btop;
9496 + dst->di_bbot = src->di_bbot;
9497 + dst->di_bwh = src->di_bwh;
9498 + dst->di_bdiropq = src->di_bdiropq;
9502 +int au_di_init(struct dentry *dentry)
9505 + struct super_block *sb;
9506 + struct au_dinfo *dinfo;
9509 + sb = dentry->d_sb;
9510 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9512 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9513 + /* smp_mb(); */ /* atomic_set */
9514 + dentry->d_fsdata = dinfo;
9521 +void au_di_fin(struct dentry *dentry)
9523 + struct au_dinfo *dinfo;
9525 + dinfo = au_di(dentry);
9526 + AuRwDestroy(&dinfo->di_rwsem);
9527 + au_di_free(dinfo);
9530 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9533 + struct au_hdentry *hdp;
9535 + AuRwMustWriteLock(&dinfo->di_rwsem);
9538 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9540 + sz = sizeof(*hdp);
9541 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9544 + dinfo->di_hdentry = hdp;
9551 +/* ---------------------------------------------------------------------- */
9553 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9556 + case AuLsc_DI_CHILD:
9557 + ii_write_lock_child(inode);
9559 + case AuLsc_DI_CHILD2:
9560 + ii_write_lock_child2(inode);
9562 + case AuLsc_DI_CHILD3:
9563 + ii_write_lock_child3(inode);
9565 + case AuLsc_DI_PARENT:
9566 + ii_write_lock_parent(inode);
9568 + case AuLsc_DI_PARENT2:
9569 + ii_write_lock_parent2(inode);
9571 + case AuLsc_DI_PARENT3:
9572 + ii_write_lock_parent3(inode);
9579 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9582 + case AuLsc_DI_CHILD:
9583 + ii_read_lock_child(inode);
9585 + case AuLsc_DI_CHILD2:
9586 + ii_read_lock_child2(inode);
9588 + case AuLsc_DI_CHILD3:
9589 + ii_read_lock_child3(inode);
9591 + case AuLsc_DI_PARENT:
9592 + ii_read_lock_parent(inode);
9594 + case AuLsc_DI_PARENT2:
9595 + ii_read_lock_parent2(inode);
9597 + case AuLsc_DI_PARENT3:
9598 + ii_read_lock_parent3(inode);
9605 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9607 + struct inode *inode;
9609 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9610 + if (d_really_is_positive(d)) {
9611 + inode = d_inode(d);
9612 + if (au_ftest_lock(flags, IW))
9613 + do_ii_write_lock(inode, lsc);
9614 + else if (au_ftest_lock(flags, IR))
9615 + do_ii_read_lock(inode, lsc);
9619 +void di_read_unlock(struct dentry *d, int flags)
9621 + struct inode *inode;
9623 + if (d_really_is_positive(d)) {
9624 + inode = d_inode(d);
9625 + if (au_ftest_lock(flags, IW)) {
9626 + au_dbg_verify_dinode(d);
9627 + ii_write_unlock(inode);
9628 + } else if (au_ftest_lock(flags, IR)) {
9629 + au_dbg_verify_dinode(d);
9630 + ii_read_unlock(inode);
9633 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9636 +void di_downgrade_lock(struct dentry *d, int flags)
9638 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9639 + ii_downgrade_lock(d_inode(d));
9640 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9643 +void di_write_lock(struct dentry *d, unsigned int lsc)
9645 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9646 + if (d_really_is_positive(d))
9647 + do_ii_write_lock(d_inode(d), lsc);
9650 +void di_write_unlock(struct dentry *d)
9652 + au_dbg_verify_dinode(d);
9653 + if (d_really_is_positive(d))
9654 + ii_write_unlock(d_inode(d));
9655 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9658 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9660 + AuDebugOn(d1 == d2
9661 + || d_inode(d1) == d_inode(d2)
9662 + || d1->d_sb != d2->d_sb);
9664 + if ((isdir && au_test_subdir(d1, d2))
9666 + di_write_lock_child(d1);
9667 + di_write_lock_child2(d2);
9669 + di_write_lock_child(d2);
9670 + di_write_lock_child2(d1);
9674 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9676 + AuDebugOn(d1 == d2
9677 + || d_inode(d1) == d_inode(d2)
9678 + || d1->d_sb != d2->d_sb);
9680 + if ((isdir && au_test_subdir(d1, d2))
9682 + di_write_lock_parent(d1);
9683 + di_write_lock_parent2(d2);
9685 + di_write_lock_parent(d2);
9686 + di_write_lock_parent2(d1);
9690 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9692 + di_write_unlock(d1);
9693 + if (d_inode(d1) == d_inode(d2))
9694 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9696 + di_write_unlock(d2);
9699 +/* ---------------------------------------------------------------------- */
9701 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9705 + DiMustAnyLock(dentry);
9707 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9709 + AuDebugOn(bindex < 0);
9710 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9711 + AuDebugOn(d && au_dcount(d) <= 0);
9716 + * extended version of au_h_dptr().
9717 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9720 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9722 + struct dentry *h_dentry;
9723 + struct inode *inode, *h_inode;
9725 + AuDebugOn(d_really_is_negative(dentry));
9728 + if (au_dbtop(dentry) <= bindex
9729 + && bindex <= au_dbbot(dentry))
9730 + h_dentry = au_h_dptr(dentry, bindex);
9731 + if (h_dentry && !au_d_linkable(h_dentry)) {
9733 + goto out; /* success */
9736 + inode = d_inode(dentry);
9737 + AuDebugOn(bindex < au_ibtop(inode));
9738 + AuDebugOn(au_ibbot(inode) < bindex);
9739 + h_inode = au_h_iptr(inode, bindex);
9740 + h_dentry = d_find_alias(h_inode);
9742 + if (!IS_ERR(h_dentry)) {
9743 + if (!au_d_linkable(h_dentry))
9744 + goto out; /* success */
9750 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9751 + h_dentry = au_plink_lkup(inode, bindex);
9752 + AuDebugOn(!h_dentry);
9753 + if (!IS_ERR(h_dentry)) {
9754 + if (!au_d_hashed_positive(h_dentry))
9755 + goto out; /* success */
9762 + AuDbgDentry(h_dentry);
9766 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9768 + aufs_bindex_t bbot, bwh;
9770 + bbot = au_dbbot(dentry);
9772 + bwh = au_dbwh(dentry);
9775 + if (0 < bwh && bwh < bbot)
9781 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9783 + aufs_bindex_t bbot, bopq;
9785 + bbot = au_dbtail(dentry);
9787 + bopq = au_dbdiropq(dentry);
9788 + if (0 <= bopq && bopq < bbot)
9794 +/* ---------------------------------------------------------------------- */
9796 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9797 + struct dentry *h_dentry)
9799 + struct au_dinfo *dinfo;
9800 + struct au_hdentry *hd;
9801 + struct au_branch *br;
9803 + DiMustWriteLock(dentry);
9805 + dinfo = au_di(dentry);
9806 + hd = au_hdentry(dinfo, bindex);
9808 + hd->hd_dentry = h_dentry;
9810 + br = au_sbr(dentry->d_sb, bindex);
9811 + hd->hd_id = br->br_id;
9815 +int au_dbrange_test(struct dentry *dentry)
9818 + aufs_bindex_t btop, bbot;
9821 + btop = au_dbtop(dentry);
9822 + bbot = au_dbbot(dentry);
9824 + AuDebugOn(bbot < 0 && btop > bbot);
9827 + AuDebugOn(bbot >= 0);
9833 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9838 + if (unlikely(au_digen(dentry) != sigen
9839 + || au_iigen_test(d_inode(dentry), sigen)))
9845 +void au_update_digen(struct dentry *dentry)
9847 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9848 + /* smp_mb(); */ /* atomic_set */
9851 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9853 + struct au_dinfo *dinfo;
9854 + struct dentry *h_d;
9855 + struct au_hdentry *hdp;
9856 + aufs_bindex_t bindex, bbot;
9858 + DiMustWriteLock(dentry);
9860 + dinfo = au_di(dentry);
9861 + if (!dinfo || dinfo->di_btop < 0)
9864 + if (do_put_zero) {
9865 + bbot = dinfo->di_bbot;
9866 + bindex = dinfo->di_btop;
9867 + hdp = au_hdentry(dinfo, bindex);
9868 + for (; bindex <= bbot; bindex++, hdp++) {
9869 + h_d = hdp->hd_dentry;
9870 + if (h_d && d_is_negative(h_d))
9871 + au_set_h_dptr(dentry, bindex, NULL);
9875 + dinfo->di_btop = 0;
9876 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9877 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9878 + if (hdp->hd_dentry)
9880 + if (dinfo->di_btop > dinfo->di_bbot) {
9881 + dinfo->di_btop = -1;
9882 + dinfo->di_bbot = -1;
9886 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9887 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9888 + if (hdp->hd_dentry)
9890 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9893 +void au_update_dbtop(struct dentry *dentry)
9895 + aufs_bindex_t bindex, bbot;
9896 + struct dentry *h_dentry;
9898 + bbot = au_dbbot(dentry);
9899 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9900 + h_dentry = au_h_dptr(dentry, bindex);
9903 + if (d_is_positive(h_dentry)) {
9904 + au_set_dbtop(dentry, bindex);
9907 + au_set_h_dptr(dentry, bindex, NULL);
9911 +void au_update_dbbot(struct dentry *dentry)
9913 + aufs_bindex_t bindex, btop;
9914 + struct dentry *h_dentry;
9916 + btop = au_dbtop(dentry);
9917 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9918 + h_dentry = au_h_dptr(dentry, bindex);
9921 + if (d_is_positive(h_dentry)) {
9922 + au_set_dbbot(dentry, bindex);
9925 + au_set_h_dptr(dentry, bindex, NULL);
9929 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9931 + aufs_bindex_t bindex, bbot;
9933 + bbot = au_dbbot(dentry);
9934 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9935 + if (au_h_dptr(dentry, bindex) == h_dentry)
9939 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9940 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9941 +++ linux/fs/aufs/dir.c 2018-04-15 08:49:13.397817296 +0200
9944 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9946 + * This program, aufs is free software; you can redistribute it and/or modify
9947 + * it under the terms of the GNU General Public License as published by
9948 + * the Free Software Foundation; either version 2 of the License, or
9949 + * (at your option) any later version.
9951 + * This program is distributed in the hope that it will be useful,
9952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9954 + * GNU General Public License for more details.
9956 + * You should have received a copy of the GNU General Public License
9957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9961 + * directory operations
9964 +#include <linux/fs_stack.h>
9967 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9969 + unsigned int nlink;
9971 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9973 + nlink = dir->i_nlink;
9974 + nlink += h_dir->i_nlink - 2;
9975 + if (h_dir->i_nlink < 2)
9977 + smp_mb(); /* for i_nlink */
9978 + /* 0 can happen in revaliding */
9979 + set_nlink(dir, nlink);
9982 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9984 + unsigned int nlink;
9986 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9988 + nlink = dir->i_nlink;
9989 + nlink -= h_dir->i_nlink - 2;
9990 + if (h_dir->i_nlink < 2)
9992 + smp_mb(); /* for i_nlink */
9993 + /* nlink == 0 means the branch-fs is broken */
9994 + set_nlink(dir, nlink);
9997 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10000 + aufs_bindex_t bindex, bbot;
10001 + struct file *h_file;
10002 + struct dentry *h_dentry;
10006 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10008 + bbot = au_fbbot_dir(file);
10009 + for (bindex = au_fbtop(file);
10010 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10012 + h_file = au_hf_dir(file, bindex);
10013 + if (h_file && file_inode(h_file))
10014 + sz += vfsub_f_size_read(h_file);
10017 + AuDebugOn(!dentry);
10018 + AuDebugOn(!d_is_dir(dentry));
10020 + bbot = au_dbtaildir(dentry);
10021 + for (bindex = au_dbtop(dentry);
10022 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10024 + h_dentry = au_h_dptr(dentry, bindex);
10025 + if (h_dentry && d_is_positive(h_dentry))
10026 + sz += i_size_read(d_inode(h_dentry));
10029 + if (sz < KMALLOC_MAX_SIZE)
10030 + sz = roundup_pow_of_two(sz);
10031 + if (sz > KMALLOC_MAX_SIZE)
10032 + sz = KMALLOC_MAX_SIZE;
10033 + else if (sz < NAME_MAX) {
10034 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10035 + sz = AUFS_RDBLK_DEF;
10040 +struct au_dir_ts_arg {
10041 + struct dentry *dentry;
10042 + aufs_bindex_t brid;
10045 +static void au_do_dir_ts(void *arg)
10047 + struct au_dir_ts_arg *a = arg;
10048 + struct au_dtime dt;
10049 + struct path h_path;
10050 + struct inode *dir, *h_dir;
10051 + struct super_block *sb;
10052 + struct au_branch *br;
10053 + struct au_hinode *hdir;
10055 + aufs_bindex_t btop, bindex;
10057 + sb = a->dentry->d_sb;
10058 + if (d_really_is_negative(a->dentry))
10060 + /* no dir->i_mutex lock */
10061 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10063 + dir = d_inode(a->dentry);
10064 + btop = au_ibtop(dir);
10065 + bindex = au_br_index(sb, a->brid);
10066 + if (bindex < btop)
10069 + br = au_sbr(sb, bindex);
10070 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10071 + if (!h_path.dentry)
10073 + h_path.mnt = au_br_mnt(br);
10074 + au_dtime_store(&dt, a->dentry, &h_path);
10076 + br = au_sbr(sb, btop);
10077 + if (!au_br_writable(br->br_perm))
10079 + h_path.dentry = au_h_dptr(a->dentry, btop);
10080 + h_path.mnt = au_br_mnt(br);
10081 + err = vfsub_mnt_want_write(h_path.mnt);
10084 + hdir = au_hi(dir, btop);
10085 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10086 + h_dir = au_h_iptr(dir, btop);
10087 + if (h_dir->i_nlink
10088 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10089 + dt.dt_h_path = h_path;
10090 + au_dtime_revert(&dt);
10092 + au_hn_inode_unlock(hdir);
10093 + vfsub_mnt_drop_write(h_path.mnt);
10094 + au_cpup_attr_timesizes(dir);
10097 + aufs_read_unlock(a->dentry, AuLock_DW);
10100 + au_nwt_done(&au_sbi(sb)->si_nowait);
10104 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10106 + int perm, wkq_err;
10107 + aufs_bindex_t btop;
10108 + struct au_dir_ts_arg *arg;
10109 + struct dentry *dentry;
10110 + struct super_block *sb;
10114 + dentry = d_find_any_alias(dir);
10115 + AuDebugOn(!dentry);
10116 + sb = dentry->d_sb;
10117 + btop = au_ibtop(dir);
10118 + if (btop == bindex) {
10119 + au_cpup_attr_timesizes(dir);
10123 + perm = au_sbr_perm(sb, btop);
10124 + if (!au_br_writable(perm))
10127 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10131 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10132 + arg->brid = au_sbr_id(sb, bindex);
10133 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10134 + if (unlikely(wkq_err)) {
10135 + pr_err("wkq %d\n", wkq_err);
10144 +/* ---------------------------------------------------------------------- */
10146 +static int reopen_dir(struct file *file)
10149 + unsigned int flags;
10150 + aufs_bindex_t bindex, btail, btop;
10151 + struct dentry *dentry, *h_dentry;
10152 + struct file *h_file;
10154 + /* open all lower dirs */
10155 + dentry = file->f_path.dentry;
10156 + btop = au_dbtop(dentry);
10157 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10158 + au_set_h_fptr(file, bindex, NULL);
10159 + au_set_fbtop(file, btop);
10161 + btail = au_dbtaildir(dentry);
10162 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10163 + au_set_h_fptr(file, bindex, NULL);
10164 + au_set_fbbot_dir(file, btail);
10166 + flags = vfsub_file_flags(file);
10167 + for (bindex = btop; bindex <= btail; bindex++) {
10168 + h_dentry = au_h_dptr(dentry, bindex);
10171 + h_file = au_hf_dir(file, bindex);
10175 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10176 + err = PTR_ERR(h_file);
10177 + if (IS_ERR(h_file))
10178 + goto out; /* close all? */
10179 + au_set_h_fptr(file, bindex, h_file);
10181 + au_update_figen(file);
10182 + /* todo: necessary? */
10183 + /* file->f_ra = h_file->f_ra; */
10190 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10193 + aufs_bindex_t bindex, btail;
10194 + struct dentry *dentry, *h_dentry;
10195 + struct vfsmount *mnt;
10197 + FiMustWriteLock(file);
10198 + AuDebugOn(h_file);
10201 + mnt = file->f_path.mnt;
10202 + dentry = file->f_path.dentry;
10203 + file->f_version = d_inode(dentry)->i_version;
10204 + bindex = au_dbtop(dentry);
10205 + au_set_fbtop(file, bindex);
10206 + btail = au_dbtaildir(dentry);
10207 + au_set_fbbot_dir(file, btail);
10208 + for (; !err && bindex <= btail; bindex++) {
10209 + h_dentry = au_h_dptr(dentry, bindex);
10213 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10214 + if (unlikely(err))
10216 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10217 + if (IS_ERR(h_file)) {
10218 + err = PTR_ERR(h_file);
10221 + au_set_h_fptr(file, bindex, h_file);
10223 + au_update_figen(file);
10224 + /* todo: necessary? */
10225 + /* file->f_ra = h_file->f_ra; */
10227 + return 0; /* success */
10230 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10231 + au_set_h_fptr(file, bindex, NULL);
10232 + au_set_fbtop(file, -1);
10233 + au_set_fbbot_dir(file, -1);
10238 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10239 + struct file *file)
10242 + struct super_block *sb;
10243 + struct au_fidir *fidir;
10246 + sb = file->f_path.dentry->d_sb;
10247 + si_read_lock(sb, AuLock_FLUSH);
10248 + fidir = au_fidir_alloc(sb);
10250 + struct au_do_open_args args = {
10251 + .open = do_open_dir,
10254 + err = au_do_open(file, &args);
10255 + if (unlikely(err))
10258 + si_read_unlock(sb);
10262 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10263 + struct file *file)
10265 + struct au_vdir *vdir_cache;
10266 + struct au_finfo *finfo;
10267 + struct au_fidir *fidir;
10268 + struct au_hfile *hf;
10269 + aufs_bindex_t bindex, bbot;
10271 + finfo = au_fi(file);
10272 + fidir = finfo->fi_hdir;
10274 + au_hbl_del(&finfo->fi_hlist,
10275 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10276 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10278 + au_vdir_free(vdir_cache);
10280 + bindex = finfo->fi_btop;
10281 + if (bindex >= 0) {
10282 + hf = fidir->fd_hfile + bindex;
10284 + * calls fput() instead of filp_close(),
10285 + * since no dnotify or lock for the lower file.
10287 + bbot = fidir->fd_bbot;
10288 + for (; bindex <= bbot; bindex++, hf++)
10290 + au_hfput(hf, /*execed*/0);
10293 + finfo->fi_hdir = NULL;
10295 + au_finfo_fin(file);
10299 +/* ---------------------------------------------------------------------- */
10301 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10304 + aufs_bindex_t bindex, bbot;
10305 + struct file *h_file;
10308 + bbot = au_fbbot_dir(file);
10309 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10310 + h_file = au_hf_dir(file, bindex);
10312 + err = vfsub_flush(h_file, id);
10317 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10319 + return au_do_flush(file, id, au_do_flush_dir);
10322 +/* ---------------------------------------------------------------------- */
10324 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10327 + aufs_bindex_t bbot, bindex;
10328 + struct inode *inode;
10329 + struct super_block *sb;
10332 + sb = dentry->d_sb;
10333 + inode = d_inode(dentry);
10334 + IMustLock(inode);
10335 + bbot = au_dbbot(dentry);
10336 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10337 + struct path h_path;
10339 + if (au_test_ro(sb, bindex, inode))
10341 + h_path.dentry = au_h_dptr(dentry, bindex);
10342 + if (!h_path.dentry)
10345 + h_path.mnt = au_sbr_mnt(sb, bindex);
10346 + err = vfsub_fsync(NULL, &h_path, datasync);
10352 +static int au_do_fsync_dir(struct file *file, int datasync)
10355 + aufs_bindex_t bbot, bindex;
10356 + struct file *h_file;
10357 + struct super_block *sb;
10358 + struct inode *inode;
10360 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10361 + if (unlikely(err))
10364 + inode = file_inode(file);
10365 + sb = inode->i_sb;
10366 + bbot = au_fbbot_dir(file);
10367 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10368 + h_file = au_hf_dir(file, bindex);
10369 + if (!h_file || au_test_ro(sb, bindex, inode))
10372 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10380 + * @file may be NULL
10382 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10386 + struct dentry *dentry;
10387 + struct inode *inode;
10388 + struct super_block *sb;
10391 + dentry = file->f_path.dentry;
10392 + inode = d_inode(dentry);
10393 + inode_lock(inode);
10394 + sb = dentry->d_sb;
10395 + si_noflush_read_lock(sb);
10397 + err = au_do_fsync_dir(file, datasync);
10399 + di_write_lock_child(dentry);
10400 + err = au_do_fsync_dir_no_file(dentry, datasync);
10402 + au_cpup_attr_timesizes(inode);
10403 + di_write_unlock(dentry);
10405 + fi_write_unlock(file);
10407 + si_read_unlock(sb);
10408 + inode_unlock(inode);
10412 +/* ---------------------------------------------------------------------- */
10414 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10417 + struct dentry *dentry;
10418 + struct inode *inode, *h_inode;
10419 + struct super_block *sb;
10421 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10423 + dentry = file->f_path.dentry;
10424 + inode = d_inode(dentry);
10425 + IMustLock(inode);
10427 + sb = dentry->d_sb;
10428 + si_read_lock(sb, AuLock_FLUSH);
10429 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10430 + if (unlikely(err))
10432 + err = au_alive_dir(dentry);
10434 + err = au_vdir_init(file);
10435 + di_downgrade_lock(dentry, AuLock_IR);
10436 + if (unlikely(err))
10439 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10440 + if (!au_test_nfsd()) {
10441 + err = au_vdir_fill_de(file, ctx);
10442 + fsstack_copy_attr_atime(inode, h_inode);
10445 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10446 + * encode_fh() and others.
10448 + atomic_inc(&h_inode->i_count);
10449 + di_read_unlock(dentry, AuLock_IR);
10450 + si_read_unlock(sb);
10451 + err = au_vdir_fill_de(file, ctx);
10452 + fsstack_copy_attr_atime(inode, h_inode);
10453 + fi_write_unlock(file);
10461 + di_read_unlock(dentry, AuLock_IR);
10462 + fi_write_unlock(file);
10464 + si_read_unlock(sb);
10468 +/* ---------------------------------------------------------------------- */
10470 +#define AuTestEmpty_WHONLY 1
10471 +#define AuTestEmpty_CALLED (1 << 1)
10472 +#define AuTestEmpty_SHWH (1 << 2)
10473 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10474 +#define au_fset_testempty(flags, name) \
10475 + do { (flags) |= AuTestEmpty_##name; } while (0)
10476 +#define au_fclr_testempty(flags, name) \
10477 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10479 +#ifndef CONFIG_AUFS_SHWH
10480 +#undef AuTestEmpty_SHWH
10481 +#define AuTestEmpty_SHWH 0
10484 +struct test_empty_arg {
10485 + struct dir_context ctx;
10486 + struct au_nhash *whlist;
10487 + unsigned int flags;
10489 + aufs_bindex_t bindex;
10492 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10493 + int namelen, loff_t offset __maybe_unused, u64 ino,
10494 + unsigned int d_type)
10496 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10498 + char *name = (void *)__name;
10501 + au_fset_testempty(arg->flags, CALLED);
10503 + if (name[0] == '.'
10504 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10505 + goto out; /* success */
10507 + if (namelen <= AUFS_WH_PFX_LEN
10508 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10509 + if (au_ftest_testempty(arg->flags, WHONLY)
10510 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10511 + arg->err = -ENOTEMPTY;
10515 + name += AUFS_WH_PFX_LEN;
10516 + namelen -= AUFS_WH_PFX_LEN;
10517 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10518 + arg->err = au_nhash_append_wh
10519 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10520 + au_ftest_testempty(arg->flags, SHWH));
10524 + AuTraceErr(arg->err);
10528 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10531 + struct file *h_file;
10533 + h_file = au_h_open(dentry, arg->bindex,
10534 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10535 + /*file*/NULL, /*force_wr*/0);
10536 + err = PTR_ERR(h_file);
10537 + if (IS_ERR(h_file))
10541 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10542 + && !file_inode(h_file)->i_nlink)
10547 + au_fclr_testempty(arg->flags, CALLED);
10549 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10552 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10556 + au_sbr_put(dentry->d_sb, arg->bindex);
10561 +struct do_test_empty_args {
10563 + struct dentry *dentry;
10564 + struct test_empty_arg *arg;
10567 +static void call_do_test_empty(void *args)
10569 + struct do_test_empty_args *a = args;
10570 + *a->errp = do_test_empty(a->dentry, a->arg);
10573 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10575 + int err, wkq_err;
10576 + struct dentry *h_dentry;
10577 + struct inode *h_inode;
10579 + h_dentry = au_h_dptr(dentry, arg->bindex);
10580 + h_inode = d_inode(h_dentry);
10581 + /* todo: i_mode changes anytime? */
10582 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10583 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10584 + inode_unlock_shared(h_inode);
10586 + err = do_test_empty(dentry, arg);
10588 + struct do_test_empty_args args = {
10590 + .dentry = dentry,
10593 + unsigned int flags = arg->flags;
10595 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10596 + if (unlikely(wkq_err))
10598 + arg->flags = flags;
10604 +int au_test_empty_lower(struct dentry *dentry)
10607 + unsigned int rdhash;
10608 + aufs_bindex_t bindex, btop, btail;
10609 + struct au_nhash whlist;
10610 + struct test_empty_arg arg = {
10612 + .actor = test_empty_cb
10615 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10617 + SiMustAnyLock(dentry->d_sb);
10619 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10621 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10622 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10623 + if (unlikely(err))
10627 + arg.whlist = &whlist;
10628 + btop = au_dbtop(dentry);
10629 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10630 + au_fset_testempty(arg.flags, SHWH);
10631 + test_empty = do_test_empty;
10632 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10633 + test_empty = sio_test_empty;
10634 + arg.bindex = btop;
10635 + err = test_empty(dentry, &arg);
10636 + if (unlikely(err))
10639 + au_fset_testempty(arg.flags, WHONLY);
10640 + btail = au_dbtaildir(dentry);
10641 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10642 + struct dentry *h_dentry;
10644 + h_dentry = au_h_dptr(dentry, bindex);
10645 + if (h_dentry && d_is_positive(h_dentry)) {
10646 + arg.bindex = bindex;
10647 + err = test_empty(dentry, &arg);
10652 + au_nhash_wh_free(&whlist);
10657 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10660 + struct test_empty_arg arg = {
10662 + .actor = test_empty_cb
10665 + aufs_bindex_t bindex, btail;
10668 + arg.whlist = whlist;
10669 + arg.flags = AuTestEmpty_WHONLY;
10670 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10671 + au_fset_testempty(arg.flags, SHWH);
10672 + btail = au_dbtaildir(dentry);
10673 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10674 + struct dentry *h_dentry;
10676 + h_dentry = au_h_dptr(dentry, bindex);
10677 + if (h_dentry && d_is_positive(h_dentry)) {
10678 + arg.bindex = bindex;
10679 + err = sio_test_empty(dentry, &arg);
10686 +/* ---------------------------------------------------------------------- */
10688 +const struct file_operations aufs_dir_fop = {
10689 + .owner = THIS_MODULE,
10690 + .llseek = default_llseek,
10691 + .read = generic_read_dir,
10692 + .iterate_shared = aufs_iterate_shared,
10693 + .unlocked_ioctl = aufs_ioctl_dir,
10694 +#ifdef CONFIG_COMPAT
10695 + .compat_ioctl = aufs_compat_ioctl_dir,
10697 + .open = aufs_open_dir,
10698 + .release = aufs_release_dir,
10699 + .flush = aufs_flush_dir,
10700 + .fsync = aufs_fsync_dir
10702 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10703 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10704 +++ linux/fs/aufs/dir.h 2018-04-15 08:49:13.397817296 +0200
10707 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10709 + * This program, aufs is free software; you can redistribute it and/or modify
10710 + * it under the terms of the GNU General Public License as published by
10711 + * the Free Software Foundation; either version 2 of the License, or
10712 + * (at your option) any later version.
10714 + * This program is distributed in the hope that it will be useful,
10715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10717 + * GNU General Public License for more details.
10719 + * You should have received a copy of the GNU General Public License
10720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10724 + * directory operations
10727 +#ifndef __AUFS_DIR_H__
10728 +#define __AUFS_DIR_H__
10732 +#include <linux/fs.h>
10734 +/* ---------------------------------------------------------------------- */
10736 +/* need to be faster and smaller */
10739 + unsigned int nh_num;
10740 + struct hlist_head *nh_head;
10743 +struct au_vdir_destr {
10744 + unsigned char len;
10745 + unsigned char name[0];
10748 +struct au_vdir_dehstr {
10749 + struct hlist_node hash;
10750 + struct au_vdir_destr *str;
10751 +} ____cacheline_aligned_in_smp;
10753 +struct au_vdir_de {
10755 + unsigned char de_type;
10756 + /* caution: packed */
10757 + struct au_vdir_destr de_str;
10760 +struct au_vdir_wh {
10761 + struct hlist_node wh_hash;
10762 +#ifdef CONFIG_AUFS_SHWH
10764 + aufs_bindex_t wh_bindex;
10765 + unsigned char wh_type;
10767 + aufs_bindex_t wh_bindex;
10769 + /* caution: packed */
10770 + struct au_vdir_destr wh_str;
10773 +union au_vdir_deblk_p {
10774 + unsigned char *deblk;
10775 + struct au_vdir_de *de;
10779 + unsigned char **vd_deblk;
10780 + unsigned long vd_nblk;
10782 + unsigned long ul;
10783 + union au_vdir_deblk_p p;
10786 + unsigned long vd_version;
10787 + unsigned int vd_deblk_sz;
10788 + unsigned long vd_jiffy;
10789 +} ____cacheline_aligned_in_smp;
10791 +/* ---------------------------------------------------------------------- */
10794 +extern const struct file_operations aufs_dir_fop;
10795 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10796 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10797 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10798 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10799 +int au_test_empty_lower(struct dentry *dentry);
10800 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10803 +unsigned int au_rdhash_est(loff_t sz);
10804 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10805 +void au_nhash_wh_free(struct au_nhash *whlist);
10806 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10808 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10809 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10810 + unsigned int d_type, aufs_bindex_t bindex,
10811 + unsigned char shwh);
10812 +void au_vdir_free(struct au_vdir *vdir);
10813 +int au_vdir_init(struct file *file);
10814 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10817 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10819 +#ifdef CONFIG_AUFS_RDU
10821 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10822 +#ifdef CONFIG_COMPAT
10823 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10824 + unsigned long arg);
10827 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10828 + unsigned int cmd, unsigned long arg)
10829 +#ifdef CONFIG_COMPAT
10830 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10831 + unsigned int cmd, unsigned long arg)
10835 +#endif /* __KERNEL__ */
10836 +#endif /* __AUFS_DIR_H__ */
10837 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10838 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10839 +++ linux/fs/aufs/dirren.c 2018-04-15 08:49:13.397817296 +0200
10842 + * Copyright (C) 2017-2018 Junjiro R. Okajima
10844 + * This program, aufs is free software; you can redistribute it and/or modify
10845 + * it under the terms of the GNU General Public License as published by
10846 + * the Free Software Foundation; either version 2 of the License, or
10847 + * (at your option) any later version.
10849 + * This program is distributed in the hope that it will be useful,
10850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10852 + * GNU General Public License for more details.
10854 + * You should have received a copy of the GNU General Public License
10855 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10859 + * special handling in renaming a directoy
10860 + * in order to support looking-up the before-renamed name on the lower readonly
10864 +#include <linux/byteorder/generic.h>
10867 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10871 + idx = au_dr_ihash(ent->dr_h_ino);
10872 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10875 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10878 + struct hlist_bl_head *hbl;
10881 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10882 + hbl = dr->dr_h_ino + i;
10883 + hlist_bl_lock(hbl);
10884 + ret &= hlist_bl_empty(hbl);
10885 + hlist_bl_unlock(hbl);
10891 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10893 + struct au_dr_hino *found, *ent;
10894 + struct hlist_bl_head *hbl;
10895 + struct hlist_bl_node *pos;
10899 + idx = au_dr_ihash(ino);
10900 + hbl = dr->dr_h_ino + idx;
10901 + hlist_bl_lock(hbl);
10902 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10903 + if (ent->dr_h_ino == ino) {
10907 + hlist_bl_unlock(hbl);
10912 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10913 + struct au_dr_hino *add_ent)
10916 + struct hlist_bl_head *hbl;
10917 + struct hlist_bl_node *pos;
10918 + struct au_dr_hino *ent;
10921 + idx = au_dr_ihash(ino);
10922 + hbl = dr->dr_h_ino + idx;
10925 + struct hlist_bl_node *tmp;
10927 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10928 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10931 + hlist_bl_lock(hbl);
10932 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10933 + if (ent->dr_h_ino == ino) {
10937 + if (!found && add_ent)
10938 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10939 + hlist_bl_unlock(hbl);
10941 + if (!found && add_ent)
10942 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10947 +void au_dr_hino_free(struct au_dr_br *dr)
10950 + struct hlist_bl_head *hbl;
10951 + struct hlist_bl_node *pos, *tmp;
10952 + struct au_dr_hino *ent;
10954 + /* SiMustWriteLock(sb); */
10956 + for (i = 0; i < AuDirren_NHASH; i++) {
10957 + hbl = dr->dr_h_ino + i;
10958 + /* no spinlock since sbinfo must be write-locked */
10959 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10961 + INIT_HLIST_BL_HEAD(hbl);
10965 +/* returns the number of inodes or an error */
10966 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10967 + struct file *hinofile)
10971 + loff_t pos, oldsize;
10973 + struct inode *hinoinode;
10974 + struct hlist_bl_head *hbl;
10975 + struct hlist_bl_node *n1, *n2;
10976 + struct au_dr_hino *ent;
10978 + SiMustWriteLock(sb);
10979 + AuDebugOn(!au_br_writable(br->br_perm));
10981 + hinoinode = file_inode(hinofile);
10982 + oldsize = i_size_read(hinoinode);
10986 + hbl = br->br_dirren.dr_h_ino;
10987 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
10988 + /* no bit-lock since sbinfo must be write-locked */
10989 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
10990 + AuDbg("hi%llu, %pD2\n",
10991 + (unsigned long long)ent->dr_h_ino, hinofile);
10992 + u64 = cpu_to_be64(ent->dr_h_ino);
10993 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
10994 + if (ssz == sizeof(u64))
10997 + /* write error */
10998 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11005 + /* regardless the error */
11006 + if (pos < oldsize) {
11007 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11015 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11022 + struct au_dr_hino *ent;
11023 + struct inode *hinoinode;
11024 + struct hlist_bl_head *hbl;
11028 + hbl = dr->dr_h_ino;
11029 + hinoinode = file_inode(hinofile);
11030 + sz = i_size_read(hinoinode);
11031 + AuDebugOn(sz % sizeof(u64));
11032 + n = sz / sizeof(u64);
11034 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11035 + if (unlikely(ssz != sizeof(u64))) {
11036 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11043 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11049 + ent->dr_h_ino = be64_to_cpu(u64);
11050 + AuDbg("hi%llu, %pD2\n",
11051 + (unsigned long long)ent->dr_h_ino, hinofile);
11052 + hidx = au_dr_ihash(ent->dr_h_ino);
11053 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11055 + goto out; /* success */
11058 + au_dr_hino_free(dr);
11065 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11066 + * @path is a switch to distinguish load and store.
11068 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11069 + struct au_branch *br, const struct path *path)
11072 + unsigned char load, suspend;
11073 + struct file *hinofile;
11074 + struct au_hinode *hdir;
11075 + struct inode *dir, *delegated;
11076 + struct path hinopath;
11077 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11078 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11080 + AuDebugOn(bindex < 0 && !br);
11081 + AuDebugOn(bindex >= 0 && br);
11086 + br = au_sbr(sb, bindex);
11089 + path = &br->br_path;
11090 + AuDebugOn(!au_br_writable(br->br_perm));
11091 + if (unlikely(!au_br_writable(br->br_perm)))
11097 + dir = d_inode(sb->s_root);
11098 + hdir = au_hinode(au_ii(dir), bindex);
11099 + dir = hdir->hi_inode;
11100 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11102 + dir = d_inode(path->dentry);
11103 + inode_lock_nested(dir, AuLsc_I_CHILD);
11105 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11106 + err = PTR_ERR(hinopath.dentry);
11107 + if (IS_ERR(hinopath.dentry))
11111 + flags = O_RDONLY;
11113 + if (d_is_negative(hinopath.dentry))
11114 + goto out_dput; /* success */
11116 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11117 + if (d_is_positive(hinopath.dentry)) {
11118 + delegated = NULL;
11119 + err = vfsub_unlink(dir, &hinopath, &delegated,
11122 + if (unlikely(err))
11123 + pr_err("ignored err %d, %pd2\n",
11124 + err, hinopath.dentry);
11125 + if (unlikely(err == -EWOULDBLOCK))
11130 + } else if (!d_is_positive(hinopath.dentry)) {
11131 + err = vfsub_create(dir, &hinopath, 0600,
11132 + /*want_excl*/false);
11134 + if (unlikely(err))
11137 + flags = O_WRONLY;
11139 + hinopath.mnt = path->mnt;
11140 + hinofile = vfsub_dentry_open(&hinopath, flags);
11142 + au_hn_inode_unlock(hdir);
11144 + inode_unlock(dir);
11145 + dput(hinopath.dentry);
11146 + AuTraceErrPtr(hinofile);
11147 + if (IS_ERR(hinofile)) {
11148 + err = PTR_ERR(hinofile);
11153 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11155 + err = au_dr_hino_store(sb, br, hinofile);
11160 + dput(hinopath.dentry);
11163 + au_hn_inode_unlock(hdir);
11165 + inode_unlock(dir);
11171 +/* ---------------------------------------------------------------------- */
11173 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11176 + struct kstatfs kstfs;
11178 + struct dentry *dentry;
11179 + struct super_block *sb;
11181 + err = vfs_statfs((void *)path, &kstfs);
11183 + if (unlikely(err))
11186 + /* todo: support for UUID */
11188 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11189 + brid->type = AuBrid_FSID;
11190 + brid->fsid = kstfs.f_fsid;
11192 + dentry = path->dentry;
11193 + sb = dentry->d_sb;
11196 + brid->type = AuBrid_DEV;
11205 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11206 + const struct path *path)
11209 + struct au_dr_br *dr;
11210 + struct hlist_bl_head *hbl;
11212 + dr = &br->br_dirren;
11213 + hbl = dr->dr_h_ino;
11214 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11215 + INIT_HLIST_BL_HEAD(hbl);
11217 + err = au_dr_brid_init(&dr->dr_brid, path);
11218 + if (unlikely(err))
11221 + if (au_opt_test(au_mntflags(sb), DIRREN))
11222 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11229 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11234 + if (au_br_writable(br->br_perm))
11235 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11237 + au_dr_hino_free(&br->br_dirren);
11242 +/* ---------------------------------------------------------------------- */
11244 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11245 + char *buf, size_t sz)
11248 + unsigned int major, minor;
11252 + err = snprintf(p, sz, "%d_", brid->type);
11253 + AuDebugOn(err > sz);
11256 + switch (brid->type) {
11257 + case AuBrid_Unset:
11259 + case AuBrid_UUID:
11260 + err = snprintf(p, sz, "%pU", brid->uuid.__u_bits);
11262 + case AuBrid_FSID:
11263 + err = snprintf(p, sz, "%08x-%08x",
11264 + brid->fsid.val[0], brid->fsid.val[1]);
11267 + major = MAJOR(brid->dev);
11268 + minor = MINOR(brid->dev);
11269 + if (major <= 0xff && minor <= 0xff)
11270 + err = snprintf(p, sz, "%02x%02x", major, minor);
11272 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11275 + AuDebugOn(err > sz);
11278 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11279 + AuDebugOn(err > sz);
11286 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11289 + struct dentry *br_dentry;
11290 + struct inode *br_inode;
11292 + br_dentry = au_br_dentry(br);
11293 + br_inode = d_inode(br_dentry);
11294 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11295 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11296 + AuDebugOn(rlen > len);
11301 +/* ---------------------------------------------------------------------- */
11304 + * from the given @h_dentry, construct drinfo at @*fdata.
11305 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11308 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11309 + struct dentry *h_dentry,
11310 + unsigned char *allocated)
11313 + struct au_drinfo_fdata *f, *p;
11314 + struct au_drinfo *drinfo;
11315 + struct inode *h_inode;
11316 + struct qstr *qname;
11320 + h_inode = d_inode(h_dentry);
11321 + qname = &h_dentry->d_name;
11322 + drinfo = &f->drinfo;
11323 + drinfo->ino = cpu_to_be64(h_inode->i_ino);
11324 + drinfo->oldnamelen = qname->len;
11325 + if (*allocated < sizeof(*f) + qname->len) {
11326 + v = roundup_pow_of_two(*allocated + qname->len);
11327 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11328 + if (unlikely(!p)) {
11336 + drinfo = &f->drinfo;
11338 + memcpy(drinfo->oldname, qname->name, qname->len);
11339 + AuDbg("i%llu, %.*s\n",
11340 + be64_to_cpu(drinfo->ino), drinfo->oldnamelen, drinfo->oldname);
11347 +/* callers have to free the return value */
11348 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11350 + struct au_drinfo *ret, *drinfo;
11351 + struct au_drinfo_fdata fdata;
11356 + ret = ERR_PTR(-EIO);
11358 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11359 + if (unlikely(ssz != sizeof(fdata))) {
11360 + AuIOErr("ssz %zd, %u, %pD2\n",
11361 + ssz, (unsigned int)sizeof(fdata), file);
11365 + fdata.magic = ntohl(fdata.magic);
11366 + switch (fdata.magic) {
11367 + case AUFS_DRINFO_MAGIC_V1:
11370 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11371 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11375 + drinfo = &fdata.drinfo;
11376 + len = drinfo->oldnamelen;
11378 + AuIOErr("broken drinfo %pD2\n", file);
11383 + drinfo->ino = be64_to_cpu(drinfo->ino);
11384 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11385 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11386 + (unsigned long long)drinfo->ino,
11387 + (unsigned long long)h_ino, file);
11388 + goto out; /* success */
11391 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11392 + if (unlikely(!ret)) {
11393 + ret = ERR_PTR(-ENOMEM);
11394 + AuTraceErrPtr(ret);
11399 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11400 + if (unlikely(ssz != len)) {
11402 + ret = ERR_PTR(-EIO);
11403 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11407 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11413 +/* ---------------------------------------------------------------------- */
11415 +/* in order to be revertible */
11416 +struct au_drinfo_rev_elm {
11418 + struct dentry *info_dentry;
11419 + struct au_drinfo *info_last;
11422 +struct au_drinfo_rev {
11423 + unsigned char already;
11424 + aufs_bindex_t nelm;
11425 + struct au_drinfo_rev_elm elm[0];
11428 +/* todo: isn't it too large? */
11429 +struct au_drinfo_store {
11430 + struct path h_ppath;
11431 + struct dentry *h_dentry;
11432 + struct au_drinfo_fdata *fdata;
11433 + char *infoname; /* inside of whname, just after PFX */
11434 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11435 + aufs_bindex_t btgt, btail;
11436 + unsigned char no_sio,
11437 + allocated, /* current size of *fdata */
11438 + infonamelen, /* room size for p */
11439 + whnamelen, /* length of the genarated name */
11440 + renameback; /* renamed back */
11443 +/* on rename(2) error, the caller should revert it using @elm */
11444 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11445 + struct au_drinfo_rev_elm *elm)
11450 + struct path infopath = {
11451 + .mnt = w->h_ppath.mnt
11453 + struct inode *h_dir, *h_inode, *delegated;
11454 + struct file *infofile;
11455 + struct qstr *qname;
11458 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11460 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11462 + AuTraceErrPtr(infopath.dentry);
11463 + if (IS_ERR(infopath.dentry)) {
11464 + err = PTR_ERR(infopath.dentry);
11469 + h_dir = d_inode(w->h_ppath.dentry);
11470 + if (elm && d_is_negative(infopath.dentry)) {
11471 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11473 + if (unlikely(err))
11475 + elm->created = 1;
11476 + elm->info_dentry = dget(infopath.dentry);
11479 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11480 + AuTraceErrPtr(infofile);
11481 + if (IS_ERR(infofile)) {
11482 + err = PTR_ERR(infofile);
11486 + h_inode = d_inode(infopath.dentry);
11487 + if (elm && i_size_read(h_inode)) {
11488 + h_inode = d_inode(w->h_dentry);
11489 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11490 + AuTraceErrPtr(elm->info_last);
11491 + if (IS_ERR(elm->info_last)) {
11492 + err = PTR_ERR(elm->info_last);
11493 + elm->info_last = NULL;
11494 + AuDebugOn(elm->info_dentry);
11499 + if (elm && w->renameback) {
11500 + delegated = NULL;
11501 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11503 + if (unlikely(err == -EWOULDBLOCK))
11509 + qname = &w->h_dentry->d_name;
11510 + len = sizeof(*w->fdata) + qname->len;
11512 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11513 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11514 + if (ssz == len) {
11515 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11516 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11517 + goto out_fput; /* success */
11522 + /* the caller should revert it using @elm */
11528 + dput(infopath.dentry);
11534 +struct au_call_drinfo_do_store_args {
11536 + struct au_drinfo_store *w;
11537 + struct au_drinfo_rev_elm *elm;
11540 +static void au_call_drinfo_do_store(void *args)
11542 + struct au_call_drinfo_do_store_args *a = args;
11544 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11547 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11548 + struct au_drinfo_rev_elm *elm)
11550 + int err, wkq_err;
11553 + err = au_drinfo_do_store(w, elm);
11555 + struct au_call_drinfo_do_store_args a = {
11560 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11561 + if (unlikely(wkq_err))
11569 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11570 + aufs_bindex_t btgt)
11574 + memset(w, 0, sizeof(*w));
11575 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11576 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11577 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11578 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11580 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11583 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11584 + if (unlikely(!w->fdata)) {
11588 + w->fdata->magic = htonl(AUFS_DRINFO_MAGIC_V1);
11595 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11600 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11601 + struct au_drinfo_store *w)
11603 + struct au_drinfo_rev_elm *elm;
11604 + struct inode *h_dir, *delegated;
11606 + struct path infopath = {
11607 + .mnt = w->h_ppath.mnt
11610 + h_dir = d_inode(w->h_ppath.dentry);
11611 + IMustLock(h_dir);
11615 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11616 + AuDebugOn(elm->created && elm->info_last);
11617 + if (elm->created) {
11619 + delegated = NULL;
11620 + infopath.dentry = elm->info_dentry;
11621 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11624 + if (unlikely(err == -EWOULDBLOCK))
11626 + dput(elm->info_dentry);
11627 + } else if (elm->info_last) {
11629 + w->fdata->drinfo = *elm->info_last;
11630 + memcpy(w->fdata->drinfo.oldname,
11631 + elm->info_last->oldname,
11632 + elm->info_last->oldnamelen);
11633 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11634 + kfree(elm->info_last);
11636 + if (unlikely(err))
11637 + AuIOErr("%d, %s\n", err, w->whname);
11638 + /* go on even if err */
11642 +/* caller has to call au_dr_rename_fin() later */
11643 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11644 + struct qstr *dst_name, void *_rev)
11646 + int err, sz, nelm;
11647 + aufs_bindex_t bindex, btail;
11648 + struct au_drinfo_store work;
11649 + struct au_drinfo_rev *rev, **p;
11650 + struct au_drinfo_rev_elm *elm;
11651 + struct super_block *sb;
11652 + struct au_branch *br;
11653 + struct au_hinode *hdir;
11655 + err = au_drinfo_store_work_init(&work, btgt);
11657 + if (unlikely(err))
11661 + btail = au_dbtaildir(dentry);
11662 + nelm = btail - btgt;
11663 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11664 + rev = kcalloc(1, sz, GFP_NOFS);
11665 + if (unlikely(!rev)) {
11669 + rev->nelm = nelm;
11675 + sb = dentry->d_sb;
11676 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11677 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11678 + hdir = au_hi(d_inode(dentry), btgt);
11679 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11680 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11681 + work.h_dentry = au_h_dptr(dentry, bindex);
11682 + if (!work.h_dentry)
11685 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11686 + &work.allocated);
11688 + if (unlikely(err))
11691 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11692 + br = au_sbr(sb, bindex);
11693 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11694 + work.whnamelen += au_drinfo_name(br, work.infoname,
11695 + work.infonamelen);
11696 + AuDbg("whname %.*s, i%llu, %.*s\n",
11697 + work.whnamelen, work.whname,
11698 + be64_to_cpu(work.fdata->drinfo.ino),
11699 + work.fdata->drinfo.oldnamelen,
11700 + work.fdata->drinfo.oldname);
11702 + err = au_drinfo_store_sio(&work, elm);
11704 + if (unlikely(err))
11707 + if (unlikely(err)) {
11708 + /* revert all drinfo */
11709 + au_drinfo_store_rev(rev, &work);
11713 + au_hn_inode_unlock(hdir);
11716 + au_drinfo_store_work_fin(&work);
11721 +/* ---------------------------------------------------------------------- */
11723 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11724 + struct qstr *dst_name, void *_rev)
11726 + int err, already;
11728 + struct super_block *sb;
11729 + struct au_branch *br;
11730 + struct au_dr_br *dr;
11731 + struct dentry *h_dentry;
11732 + struct inode *h_inode;
11733 + struct au_dr_hino *ent;
11734 + struct au_drinfo_rev *rev, **p;
11736 + AuDbg("bindex %d\n", bindex);
11739 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11740 + if (unlikely(!ent))
11744 + br = au_sbr(sb, bindex);
11745 + dr = &br->br_dirren;
11746 + h_dentry = au_h_dptr(src, bindex);
11747 + h_inode = d_inode(h_dentry);
11748 + ino = h_inode->i_ino;
11749 + ent->dr_h_ino = ino;
11750 + already = au_dr_hino_test_add(dr, ino, ent);
11751 + AuDbg("b%d, hi%llu, already %d\n",
11752 + bindex, (unsigned long long)ino, already);
11754 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11759 + rev->already = already;
11760 + goto out; /* success */
11765 + au_dr_hino_del(dr, ent);
11773 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11775 + struct au_drinfo_rev *rev;
11776 + struct au_drinfo_rev_elm *elm;
11781 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11782 + dput(elm->info_dentry);
11783 + kfree(elm->info_last);
11788 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11791 + struct au_drinfo_store work;
11792 + struct au_drinfo_rev *rev = _rev;
11793 + struct super_block *sb;
11794 + struct au_branch *br;
11795 + struct inode *h_inode;
11796 + struct au_dr_br *dr;
11797 + struct au_dr_hino *ent;
11799 + err = au_drinfo_store_work_init(&work, btgt);
11800 + if (unlikely(err))
11804 + br = au_sbr(sb, btgt);
11805 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11806 + work.h_ppath.mnt = au_br_mnt(br);
11807 + au_drinfo_store_rev(rev, &work);
11808 + au_drinfo_store_work_fin(&work);
11809 + if (rev->already)
11812 + dr = &br->br_dirren;
11813 + h_inode = d_inode(work.h_ppath.dentry);
11814 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11816 + au_dr_hino_del(dr, ent);
11821 + if (unlikely(err))
11822 + pr_err("failed to remove dirren info\n");
11825 +/* ---------------------------------------------------------------------- */
11827 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11828 + char *whname, int whnamelen,
11829 + struct dentry **info_dentry)
11831 + struct au_drinfo *drinfo;
11833 + struct inode *h_dir;
11834 + struct path infopath;
11837 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11839 + *info_dentry = NULL;
11842 + h_dir = d_inode(h_ppath->dentry);
11843 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11844 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11846 + if (IS_ERR(infopath.dentry)) {
11847 + drinfo = (void *)infopath.dentry;
11851 + if (d_is_negative(infopath.dentry))
11852 + goto out_dput; /* success */
11854 + infopath.mnt = h_ppath->mnt;
11855 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11856 + inode_unlock_shared(h_dir);
11859 + drinfo = (void *)f;
11863 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11864 + if (IS_ERR_OR_NULL(drinfo))
11867 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11868 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11873 + dput(infopath.dentry);
11876 + inode_unlock_shared(h_dir);
11877 + AuTraceErrPtr(drinfo);
11881 +struct au_drinfo_do_load_args {
11882 + struct au_drinfo **drinfop;
11883 + struct path *h_ppath;
11886 + struct dentry **info_dentry;
11889 +static void au_call_drinfo_do_load(void *args)
11891 + struct au_drinfo_do_load_args *a = args;
11893 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11897 +struct au_drinfo_load {
11898 + struct path h_ppath;
11899 + struct qstr *qname;
11900 + unsigned char no_sio;
11902 + aufs_bindex_t ninfo;
11903 + struct au_drinfo **drinfo;
11906 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11907 + struct au_branch *br)
11909 + int err, wkq_err, whnamelen, e;
11910 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11911 + = AUFS_WH_DR_INFO_PFX;
11912 + struct au_drinfo *drinfo;
11913 + struct qstr oldname;
11914 + struct inode *h_dir, *delegated;
11915 + struct dentry *info_dentry;
11916 + struct path infopath;
11918 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11919 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11920 + sizeof(whname) - whnamelen);
11922 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11925 + struct au_drinfo_do_load_args args = {
11926 + .drinfop = &drinfo,
11927 + .h_ppath = &w->h_ppath,
11928 + .whname = whname,
11929 + .whnamelen = whnamelen,
11930 + .info_dentry = &info_dentry
11932 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11933 + if (unlikely(wkq_err))
11934 + drinfo = ERR_PTR(wkq_err);
11936 + err = PTR_ERR(drinfo);
11937 + if (IS_ERR_OR_NULL(drinfo))
11941 + oldname.len = drinfo->oldnamelen;
11942 + oldname.name = drinfo->oldname;
11943 + if (au_qstreq(w->qname, &oldname)) {
11944 + /* the name is renamed back */
11948 + infopath.dentry = info_dentry;
11949 + infopath.mnt = w->h_ppath.mnt;
11950 + h_dir = d_inode(w->h_ppath.dentry);
11951 + delegated = NULL;
11952 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11953 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11954 + inode_unlock(h_dir);
11956 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11957 + if (unlikely(e == -EWOULDBLOCK))
11960 + kfree(w->drinfo[bindex]);
11961 + w->drinfo[bindex] = drinfo;
11962 + dput(info_dentry);
11969 +/* ---------------------------------------------------------------------- */
11971 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11973 + struct au_drinfo **p = drinfo;
11976 + kfree(*drinfo++);
11980 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11981 + aufs_bindex_t btgt)
11984 + struct au_drinfo_load w;
11985 + aufs_bindex_t bindex, bbot;
11986 + struct au_branch *br;
11987 + struct inode *h_dir;
11988 + struct au_dr_hino *ent;
11989 + struct super_block *sb;
11991 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
11992 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
11993 + AuLNPair(&lkup->whname), btgt);
11995 + sb = dentry->d_sb;
11996 + bbot = au_sbbot(sb);
11997 + w.ninfo = bbot + 1;
11998 + if (!lkup->dirren.drinfo) {
11999 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12000 + sizeof(*lkup->dirren.drinfo),
12002 + if (unlikely(!lkup->dirren.drinfo)) {
12006 + lkup->dirren.ninfo = w.ninfo;
12008 + w.drinfo = lkup->dirren.drinfo;
12009 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12010 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12011 + AuDebugOn(!w.h_ppath.dentry);
12012 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12013 + w.qname = &dentry->d_name;
12016 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12017 + br = au_sbr(sb, bindex);
12018 + err = au_drinfo_load(&w, bindex, br);
12019 + if (unlikely(err))
12021 + if (w.drinfo[bindex])
12025 + br = au_sbr(sb, btgt);
12026 + h_dir = d_inode(w.h_ppath.dentry);
12027 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12029 + au_dr_hino_del(&br->br_dirren, ent);
12032 + goto out; /* success */
12035 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12036 + lkup->dirren.ninfo = 0;
12037 + lkup->dirren.drinfo = NULL;
12043 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12045 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12048 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12051 + struct au_drinfo *drinfo;
12054 + if (!lkup->dirren.drinfo)
12056 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12057 + drinfo = lkup->dirren.drinfo[btgt + 1];
12061 + kfree(lkup->whname.name);
12062 + lkup->whname.name = NULL;
12063 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12064 + lkup->dirren.dr_name.name = drinfo->oldname;
12065 + lkup->name = &lkup->dirren.dr_name;
12066 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12068 + AuDbg("name %.*s, whname %.*s, b%d\n",
12069 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12077 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12081 + struct au_drinfo *drinfo;
12084 + if (!lkup->dirren.drinfo)
12086 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12087 + drinfo = lkup->dirren.drinfo[bindex + 1];
12091 + match = (drinfo->ino == h_ino);
12092 + AuDbg("match %d\n", match);
12098 +/* ---------------------------------------------------------------------- */
12100 +int au_dr_opt_set(struct super_block *sb)
12103 + aufs_bindex_t bindex, bbot;
12104 + struct au_branch *br;
12107 + bbot = au_sbbot(sb);
12108 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12109 + br = au_sbr(sb, bindex);
12110 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12116 +int au_dr_opt_flush(struct super_block *sb)
12119 + aufs_bindex_t bindex, bbot;
12120 + struct au_branch *br;
12123 + bbot = au_sbbot(sb);
12124 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12125 + br = au_sbr(sb, bindex);
12126 + if (au_br_writable(br->br_perm))
12127 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12133 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12136 + aufs_bindex_t bindex, bbot;
12137 + struct au_branch *br;
12141 + err = au_dr_opt_flush(sb);
12142 + if (unlikely(err))
12146 + bbot = au_sbbot(sb);
12147 + for (bindex = 0; bindex <= bbot; bindex++) {
12148 + br = au_sbr(sb, bindex);
12149 + au_dr_hino_free(&br->br_dirren);
12155 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12156 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12157 +++ linux/fs/aufs/dirren.h 2018-04-15 08:49:13.397817296 +0200
12160 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12162 + * This program, aufs is free software; you can redistribute it and/or modify
12163 + * it under the terms of the GNU General Public License as published by
12164 + * the Free Software Foundation; either version 2 of the License, or
12165 + * (at your option) any later version.
12167 + * This program is distributed in the hope that it will be useful,
12168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12170 + * GNU General Public License for more details.
12172 + * You should have received a copy of the GNU General Public License
12173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12177 + * renamed dir info
12180 +#ifndef __AUFS_DIRREN_H__
12181 +#define __AUFS_DIRREN_H__
12185 +#include <linux/dcache.h>
12186 +#include <linux/statfs.h>
12189 +#define AuDirren_NHASH 100
12191 +#ifdef CONFIG_AUFS_DIRREN
12192 +/* copied from linux/fs/xfs/uuid.h */
12194 + unsigned char __u_bits[16];
12197 +#define __UUID_TMPLT "01234567-0123-4567-0123-456701234567"
12199 +enum au_brid_type {
12206 +struct au_dr_brid {
12207 + enum au_brid_type type;
12209 + uuid_t uuid; /* unimplemented yet */
12215 +/* 20 is the max digits length of ulong 64 */
12216 +/* brid-type "_" uuid "_" inum */
12217 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + sizeof(__UUID_TMPLT) + 20)
12218 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12220 +struct au_dr_hino {
12221 + struct hlist_bl_node dr_hnode;
12226 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12227 + struct au_dr_brid dr_brid;
12230 +struct au_dr_lookup {
12231 + /* dr_name is pointed by struct au_do_lookup_args.name */
12232 + struct qstr dr_name; /* subset of dr_info */
12233 + aufs_bindex_t ninfo;
12234 + struct au_drinfo **drinfo;
12237 +struct au_dr_hino;
12239 +struct au_dr_br { };
12240 +struct au_dr_lookup { };
12243 +/* ---------------------------------------------------------------------- */
12246 +struct au_do_lookup_args;
12248 +#ifdef CONFIG_AUFS_DIRREN
12249 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12250 + struct au_dr_hino *add_ent);
12251 +void au_dr_hino_free(struct au_dr_br *dr);
12252 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12253 + const struct path *path);
12254 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12255 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12256 + struct qstr *dst_name, void *_rev);
12257 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12258 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12259 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12260 + aufs_bindex_t bindex);
12261 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12262 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12264 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12265 +int au_dr_opt_set(struct super_block *sb);
12266 +int au_dr_opt_flush(struct super_block *sb);
12267 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12269 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12270 + struct au_dr_hino *add_ent);
12271 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12272 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12273 + const struct path *path);
12274 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12275 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12276 + struct qstr *dst_name, void *_rev);
12277 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12278 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12280 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12281 + aufs_bindex_t bindex);
12282 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12283 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12284 + aufs_bindex_t bindex, ino_t h_ino);
12285 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12286 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12287 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12288 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12291 +/* ---------------------------------------------------------------------- */
12293 +#ifdef CONFIG_AUFS_DIRREN
12294 +static inline int au_dr_ihash(ino_t h_ino)
12296 + return h_ino % AuDirren_NHASH;
12299 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12302 +#endif /* __KERNEL__ */
12303 +#endif /* __AUFS_DIRREN_H__ */
12304 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12305 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12306 +++ linux/fs/aufs/dynop.c 2018-04-15 08:49:13.397817296 +0200
12309 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12311 + * This program, aufs is free software; you can redistribute it and/or modify
12312 + * it under the terms of the GNU General Public License as published by
12313 + * the Free Software Foundation; either version 2 of the License, or
12314 + * (at your option) any later version.
12316 + * This program is distributed in the hope that it will be useful,
12317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12319 + * GNU General Public License for more details.
12321 + * You should have received a copy of the GNU General Public License
12322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12326 + * dynamically customizable operations for regular files
12331 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12334 + * How large will these lists be?
12335 + * Usually just a few elements, 20-30 at most for each, I guess.
12337 +static struct hlist_bl_head dynop[AuDyLast];
12339 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12340 + const void *h_op)
12342 + struct au_dykey *key, *tmp;
12343 + struct hlist_bl_node *pos;
12346 + hlist_bl_lock(hbl);
12347 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12348 + if (tmp->dk_op.dy_hop == h_op) {
12350 + kref_get(&key->dk_kref);
12353 + hlist_bl_unlock(hbl);
12358 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12360 + struct au_dykey **k, *found;
12361 + const void *h_op = key->dk_op.dy_hop;
12365 + k = br->br_dykey;
12366 + for (i = 0; i < AuBrDynOp; i++)
12368 + if (k[i]->dk_op.dy_hop == h_op) {
12375 + spin_lock(&br->br_dykey_lock);
12376 + for (; i < AuBrDynOp; i++)
12378 + if (k[i]->dk_op.dy_hop == h_op) {
12386 + spin_unlock(&br->br_dykey_lock);
12387 + BUG_ON(i == AuBrDynOp); /* expand the array */
12393 +/* kref_get() if @key is already added */
12394 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12396 + struct au_dykey *tmp, *found;
12397 + struct hlist_bl_node *pos;
12398 + const void *h_op = key->dk_op.dy_hop;
12401 + hlist_bl_lock(hbl);
12402 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12403 + if (tmp->dk_op.dy_hop == h_op) {
12404 + kref_get(&tmp->dk_kref);
12409 + hlist_bl_add_head(&key->dk_hnode, hbl);
12410 + hlist_bl_unlock(hbl);
12417 +static void dy_free_rcu(struct rcu_head *rcu)
12419 + struct au_dykey *key;
12421 + key = container_of(rcu, struct au_dykey, dk_rcu);
12426 +static void dy_free(struct kref *kref)
12428 + struct au_dykey *key;
12429 + struct hlist_bl_head *hbl;
12431 + key = container_of(kref, struct au_dykey, dk_kref);
12432 + hbl = dynop + key->dk_op.dy_type;
12433 + au_hbl_del(&key->dk_hnode, hbl);
12434 + call_rcu(&key->dk_rcu, dy_free_rcu);
12437 +void au_dy_put(struct au_dykey *key)
12439 + kref_put(&key->dk_kref, dy_free);
12442 +/* ---------------------------------------------------------------------- */
12444 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12446 +#ifdef CONFIG_AUFS_DEBUG
12447 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12448 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12450 +#define DyDbgDeclare(cnt) do {} while (0)
12451 +#define DyDbgInc(cnt) do {} while (0)
12454 +#define DySet(func, dst, src, h_op, h_sb) do { \
12456 + if (h_op->func) { \
12458 + dst.func = src.func; \
12460 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12464 +#define DySetForce(func, dst, src) do { \
12465 + AuDebugOn(!src.func); \
12467 + dst.func = src.func; \
12470 +#define DySetAop(func) \
12471 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12472 +#define DySetAopForce(func) \
12473 + DySetForce(func, dyaop->da_op, aufs_aop)
12475 +static void dy_aop(struct au_dykey *key, const void *h_op,
12476 + struct super_block *h_sb __maybe_unused)
12478 + struct au_dyaop *dyaop = (void *)key;
12479 + const struct address_space_operations *h_aop = h_op;
12480 + DyDbgDeclare(cnt);
12482 + AuDbg("%s\n", au_sbtype(h_sb));
12484 + DySetAop(writepage);
12485 + DySetAopForce(readpage); /* force */
12486 + DySetAop(writepages);
12487 + DySetAop(set_page_dirty);
12488 + DySetAop(readpages);
12489 + DySetAop(write_begin);
12490 + DySetAop(write_end);
12492 + DySetAop(invalidatepage);
12493 + DySetAop(releasepage);
12494 + DySetAop(freepage);
12495 + /* this one will be changed according to an aufs mount option */
12496 + DySetAop(direct_IO);
12497 + DySetAop(migratepage);
12498 + DySetAop(isolate_page);
12499 + DySetAop(putback_page);
12500 + DySetAop(launder_page);
12501 + DySetAop(is_partially_uptodate);
12502 + DySetAop(is_dirty_writeback);
12503 + DySetAop(error_remove_page);
12504 + DySetAop(swap_activate);
12505 + DySetAop(swap_deactivate);
12507 + DyDbgSize(cnt, *h_aop);
12510 +/* ---------------------------------------------------------------------- */
12512 +static void dy_bug(struct kref *kref)
12517 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12519 + struct au_dykey *key, *old;
12520 + struct hlist_bl_head *hbl;
12523 + void (*set)(struct au_dykey *key, const void *h_op,
12524 + struct super_block *h_sb __maybe_unused);
12526 + static const struct op a[] = {
12528 + .sz = sizeof(struct au_dyaop),
12532 + const struct op *p;
12534 + hbl = dynop + op->dy_type;
12535 + key = dy_gfind_get(hbl, op->dy_hop);
12537 + goto out_add; /* success */
12539 + p = a + op->dy_type;
12540 + key = kzalloc(p->sz, GFP_NOFS);
12541 + if (unlikely(!key)) {
12542 + key = ERR_PTR(-ENOMEM);
12546 + key->dk_op.dy_hop = op->dy_hop;
12547 + kref_init(&key->dk_kref);
12548 + p->set(key, op->dy_hop, au_br_sb(br));
12549 + old = dy_gadd(hbl, key);
12556 + old = dy_bradd(br, key);
12558 + /* its ref-count should never be zero here */
12559 + kref_put(&key->dk_kref, dy_bug);
12564 +/* ---------------------------------------------------------------------- */
12566 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
12567 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12568 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12569 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12570 + * See the aufs manual in detail.
12572 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12575 + dyaop->da_op.direct_IO = NULL;
12577 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12580 +static struct au_dyaop *dy_aget(struct au_branch *br,
12581 + const struct address_space_operations *h_aop,
12584 + struct au_dyaop *dyaop;
12585 + struct au_dynop op;
12587 + op.dy_type = AuDy_AOP;
12588 + op.dy_haop = h_aop;
12589 + dyaop = (void *)dy_get(&op, br);
12590 + if (IS_ERR(dyaop))
12592 + dy_adx(dyaop, do_dx);
12598 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12599 + struct inode *h_inode)
12602 + struct super_block *sb;
12603 + struct au_branch *br;
12604 + struct au_dyaop *dyaop;
12606 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12607 + IiMustWriteLock(inode);
12609 + sb = inode->i_sb;
12610 + br = au_sbr(sb, bindex);
12611 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12612 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12613 + err = PTR_ERR(dyaop);
12614 + if (IS_ERR(dyaop))
12615 + /* unnecessary to call dy_fput() */
12619 + inode->i_mapping->a_ops = &dyaop->da_op;
12626 + * Is it safe to replace a_ops during the inode/file is in operation?
12627 + * Yes, I hope so.
12629 +int au_dy_irefresh(struct inode *inode)
12632 + aufs_bindex_t btop;
12633 + struct inode *h_inode;
12636 + if (S_ISREG(inode->i_mode)) {
12637 + btop = au_ibtop(inode);
12638 + h_inode = au_h_iptr(inode, btop);
12639 + err = au_dy_iaop(inode, btop, h_inode);
12644 +void au_dy_arefresh(int do_dx)
12646 + struct hlist_bl_head *hbl;
12647 + struct hlist_bl_node *pos;
12648 + struct au_dykey *key;
12650 + hbl = dynop + AuDy_AOP;
12651 + hlist_bl_lock(hbl);
12652 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12653 + dy_adx((void *)key, do_dx);
12654 + hlist_bl_unlock(hbl);
12657 +/* ---------------------------------------------------------------------- */
12659 +void __init au_dy_init(void)
12663 + /* make sure that 'struct au_dykey *' can be any type */
12664 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12666 + for (i = 0; i < AuDyLast; i++)
12667 + INIT_HLIST_BL_HEAD(dynop + i);
12670 +void au_dy_fin(void)
12674 + for (i = 0; i < AuDyLast; i++)
12675 + WARN_ON(!hlist_bl_empty(dynop + i));
12677 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12678 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12679 +++ linux/fs/aufs/dynop.h 2018-04-15 08:49:13.397817296 +0200
12682 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12684 + * This program, aufs is free software; you can redistribute it and/or modify
12685 + * it under the terms of the GNU General Public License as published by
12686 + * the Free Software Foundation; either version 2 of the License, or
12687 + * (at your option) any later version.
12689 + * This program is distributed in the hope that it will be useful,
12690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12692 + * GNU General Public License for more details.
12694 + * You should have received a copy of the GNU General Public License
12695 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12699 + * dynamically customizable operations (for regular files only)
12702 +#ifndef __AUFS_DYNOP_H__
12703 +#define __AUFS_DYNOP_H__
12707 +#include <linux/fs.h>
12708 +#include <linux/kref.h>
12710 +enum {AuDy_AOP, AuDyLast};
12715 + const void *dy_hop;
12716 + const struct address_space_operations *dy_haop;
12722 + struct hlist_bl_node dk_hnode;
12723 + struct rcu_head dk_rcu;
12725 + struct au_dynop dk_op;
12728 + * during I am in the branch local array, kref is gotten. when the
12729 + * branch is removed, kref is put.
12731 + struct kref dk_kref;
12734 +/* stop unioning since their sizes are very different from each other */
12736 + struct au_dykey da_key;
12737 + struct address_space_operations da_op; /* not const */
12740 +/* ---------------------------------------------------------------------- */
12744 +void au_dy_put(struct au_dykey *key);
12745 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12746 + struct inode *h_inode);
12747 +int au_dy_irefresh(struct inode *inode);
12748 +void au_dy_arefresh(int do_dio);
12750 +void __init au_dy_init(void);
12751 +void au_dy_fin(void);
12753 +#endif /* __KERNEL__ */
12754 +#endif /* __AUFS_DYNOP_H__ */
12755 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12756 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12757 +++ linux/fs/aufs/export.c 2018-04-15 08:49:13.397817296 +0200
12760 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12762 + * This program, aufs is free software; you can redistribute it and/or modify
12763 + * it under the terms of the GNU General Public License as published by
12764 + * the Free Software Foundation; either version 2 of the License, or
12765 + * (at your option) any later version.
12767 + * This program is distributed in the hope that it will be useful,
12768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12770 + * GNU General Public License for more details.
12772 + * You should have received a copy of the GNU General Public License
12773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12780 +#include <linux/exportfs.h>
12781 +#include <linux/fs_struct.h>
12782 +#include <linux/namei.h>
12783 +#include <linux/nsproxy.h>
12784 +#include <linux/random.h>
12785 +#include <linux/writeback.h>
12789 +#ifdef CONFIG_AUFS_INO_T_64
12797 +static ino_t decode_ino(__u32 *a)
12801 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12803 +#ifdef CONFIG_AUFS_INO_T_64
12809 +static void encode_ino(__u32 *a, ino_t ino)
12815 +#ifdef CONFIG_AUFS_INO_T_64
12820 +/* NFS file handle */
12824 +#ifdef CONFIG_AUFS_INO_T_64
12825 + /* support 64bit inode number */
12838 + Fh_ino = Fh_ino1,
12839 + Fh_dir_ino = Fh_dir_ino1
12842 +static int au_test_anon(struct dentry *dentry)
12844 + /* note: read d_flags without d_lock */
12845 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12848 +int au_test_nfsd(void)
12851 + struct task_struct *tsk = current;
12852 + char comm[sizeof(tsk->comm)];
12855 + if (tsk->flags & PF_KTHREAD) {
12856 + get_task_comm(comm, tsk);
12857 + ret = !strcmp(comm, "nfsd");
12863 +/* ---------------------------------------------------------------------- */
12864 +/* inode generation external table */
12866 +void au_xigen_inc(struct inode *inode)
12871 + struct super_block *sb;
12872 + struct au_sbinfo *sbinfo;
12874 + sb = inode->i_sb;
12875 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12877 + sbinfo = au_sbi(sb);
12878 + pos = inode->i_ino;
12879 + pos *= sizeof(igen);
12880 + igen = inode->i_generation + 1;
12881 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12882 + sizeof(igen), &pos);
12883 + if (sz == sizeof(igen))
12884 + return; /* success */
12886 + if (unlikely(sz >= 0))
12887 + AuIOErr("xigen error (%zd)\n", sz);
12890 +int au_xigen_new(struct inode *inode)
12895 + struct super_block *sb;
12896 + struct au_sbinfo *sbinfo;
12897 + struct file *file;
12900 + /* todo: dirty, at mount time */
12901 + if (inode->i_ino == AUFS_ROOT_INO)
12903 + sb = inode->i_sb;
12904 + SiMustAnyLock(sb);
12905 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12909 + pos = inode->i_ino;
12910 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12911 + AuIOErr1("too large i%lld\n", pos);
12914 + pos *= sizeof(inode->i_generation);
12917 + sbinfo = au_sbi(sb);
12918 + file = sbinfo->si_xigen;
12921 + if (vfsub_f_size_read(file)
12922 + < pos + sizeof(inode->i_generation)) {
12923 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12924 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
12925 + sizeof(inode->i_generation), &pos);
12927 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
12928 + sizeof(inode->i_generation), &pos);
12929 + if (sz == sizeof(inode->i_generation))
12930 + goto out; /* success */
12933 + if (unlikely(sz >= 0)) {
12935 + AuIOErr("xigen error (%zd)\n", sz);
12942 +int au_xigen_set(struct super_block *sb, struct file *base)
12945 + struct au_sbinfo *sbinfo;
12946 + struct file *file;
12948 + SiMustWriteLock(sb);
12950 + sbinfo = au_sbi(sb);
12951 + file = au_xino_create2(base, sbinfo->si_xigen);
12952 + err = PTR_ERR(file);
12953 + if (IS_ERR(file))
12956 + if (sbinfo->si_xigen)
12957 + fput(sbinfo->si_xigen);
12958 + sbinfo->si_xigen = file;
12964 +void au_xigen_clr(struct super_block *sb)
12966 + struct au_sbinfo *sbinfo;
12968 + SiMustWriteLock(sb);
12970 + sbinfo = au_sbi(sb);
12971 + if (sbinfo->si_xigen) {
12972 + fput(sbinfo->si_xigen);
12973 + sbinfo->si_xigen = NULL;
12977 +/* ---------------------------------------------------------------------- */
12979 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12982 + struct dentry *dentry, *d;
12983 + struct inode *inode;
12984 + unsigned int sigen;
12987 + inode = ilookup(sb, ino);
12991 + dentry = ERR_PTR(-ESTALE);
12992 + sigen = au_sigen(sb);
12993 + if (unlikely(au_is_bad_inode(inode)
12994 + || IS_DEADDIR(inode)
12995 + || sigen != au_iigen(inode, NULL)))
12999 + if (!dir_ino || S_ISDIR(inode->i_mode))
13000 + dentry = d_find_alias(inode);
13002 + spin_lock(&inode->i_lock);
13003 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13004 + spin_lock(&d->d_lock);
13005 + if (!au_test_anon(d)
13006 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13007 + dentry = dget_dlock(d);
13008 + spin_unlock(&d->d_lock);
13011 + spin_unlock(&d->d_lock);
13013 + spin_unlock(&inode->i_lock);
13015 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13016 + /* need to refresh */
13024 + AuTraceErrPtr(dentry);
13028 +/* ---------------------------------------------------------------------- */
13030 +/* todo: dirty? */
13031 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13033 +struct au_compare_mnt_args {
13035 + struct super_block *sb;
13038 + struct vfsmount *mnt;
13041 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13043 + struct au_compare_mnt_args *a = arg;
13045 + if (mnt->mnt_sb != a->sb)
13047 + a->mnt = mntget(mnt);
13051 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13054 + struct path root;
13055 + struct au_compare_mnt_args args = {
13059 + get_fs_root(current->fs, &root);
13061 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13062 + rcu_read_unlock();
13065 + AuDebugOn(!args.mnt);
13069 +struct au_nfsd_si_lock {
13070 + unsigned int sigen;
13071 + aufs_bindex_t bindex, br_id;
13072 + unsigned char force_lock;
13075 +static int si_nfsd_read_lock(struct super_block *sb,
13076 + struct au_nfsd_si_lock *nsi_lock)
13079 + aufs_bindex_t bindex;
13081 + si_read_lock(sb, AuLock_FLUSH);
13083 + /* branch id may be wrapped around */
13085 + bindex = au_br_index(sb, nsi_lock->br_id);
13086 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13087 + goto out; /* success */
13091 + if (!nsi_lock->force_lock)
13092 + si_read_unlock(sb);
13095 + nsi_lock->bindex = bindex;
13099 +struct find_name_by_ino {
13100 + struct dir_context ctx;
13101 + int called, found;
13108 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13109 + loff_t offset, u64 ino, unsigned int d_type)
13111 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13115 + if (a->ino != ino)
13118 + memcpy(a->name, name, namelen);
13119 + a->namelen = namelen;
13124 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13125 + struct au_nfsd_si_lock *nsi_lock)
13127 + struct dentry *dentry, *parent;
13128 + struct file *file;
13129 + struct inode *dir;
13130 + struct find_name_by_ino arg = {
13132 + .actor = find_name_by_ino
13137 + parent = path->dentry;
13139 + si_read_unlock(parent->d_sb);
13140 + file = vfsub_dentry_open(path, au_dir_roflags);
13141 + dentry = (void *)file;
13142 + if (IS_ERR(file))
13145 + dentry = ERR_PTR(-ENOMEM);
13146 + arg.name = (void *)__get_free_page(GFP_NOFS);
13147 + if (unlikely(!arg.name))
13154 + err = vfsub_iterate_dir(file, &arg.ctx);
13155 + } while (!err && !arg.found && arg.called);
13156 + dentry = ERR_PTR(err);
13157 + if (unlikely(err))
13159 + /* instead of ENOENT */
13160 + dentry = ERR_PTR(-ESTALE);
13164 + /* do not call vfsub_lkup_one() */
13165 + dir = d_inode(parent);
13166 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13167 + AuTraceErrPtr(dentry);
13168 + if (IS_ERR(dentry))
13170 + AuDebugOn(au_test_anon(dentry));
13171 + if (unlikely(d_really_is_negative(dentry))) {
13173 + dentry = ERR_PTR(-ENOENT);
13177 + free_page((unsigned long)arg.name);
13181 + if (unlikely(nsi_lock
13182 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13183 + if (!IS_ERR(dentry)) {
13185 + dentry = ERR_PTR(-ESTALE);
13187 + AuTraceErrPtr(dentry);
13191 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13193 + struct au_nfsd_si_lock *nsi_lock)
13195 + struct dentry *dentry;
13196 + struct path path;
13198 + if (dir_ino != AUFS_ROOT_INO) {
13199 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13200 + dentry = path.dentry;
13201 + if (!path.dentry || IS_ERR(path.dentry))
13203 + AuDebugOn(au_test_anon(path.dentry));
13205 + path.dentry = dget(sb->s_root);
13207 + path.mnt = au_mnt_get(sb);
13208 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13212 + AuTraceErrPtr(dentry);
13216 +/* ---------------------------------------------------------------------- */
13218 +static int h_acceptable(void *expv, struct dentry *dentry)
13223 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13224 + char *buf, int len, struct super_block *sb)
13228 + struct path path;
13230 + p = d_path(h_rootpath, buf, len);
13235 + path.mnt = h_rootpath->mnt;
13236 + path.dentry = h_parent;
13237 + p = d_path(&path, buf, len);
13243 + path.mnt = au_mnt_get(sb);
13244 + path.dentry = sb->s_root;
13245 + p = d_path(&path, buf, len - strlen(p));
13246 + mntput(path.mnt);
13250 + p[strlen(p)] = '/';
13253 + AuTraceErrPtr(p);
13258 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13259 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13261 + struct dentry *dentry, *h_parent, *root;
13262 + struct super_block *h_sb;
13263 + char *pathname, *p;
13264 + struct vfsmount *h_mnt;
13265 + struct au_branch *br;
13267 + struct path path;
13269 + br = au_sbr(sb, nsi_lock->bindex);
13270 + h_mnt = au_br_mnt(br);
13271 + h_sb = h_mnt->mnt_sb;
13272 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13274 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13275 + fh_len - Fh_tail, fh[Fh_h_type],
13276 + h_acceptable, /*context*/NULL);
13278 + dentry = h_parent;
13279 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13280 + AuWarn1("%s decode_fh failed, %ld\n",
13281 + au_sbtype(h_sb), PTR_ERR(h_parent));
13285 + if (unlikely(au_test_anon(h_parent))) {
13286 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13287 + au_sbtype(h_sb));
13288 + goto out_h_parent;
13291 + dentry = ERR_PTR(-ENOMEM);
13292 + pathname = (void *)__get_free_page(GFP_NOFS);
13293 + if (unlikely(!pathname))
13294 + goto out_h_parent;
13296 + root = sb->s_root;
13297 + path.mnt = h_mnt;
13298 + di_read_lock_parent(root, !AuLock_IR);
13299 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13300 + di_read_unlock(root, !AuLock_IR);
13301 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13302 + dentry = (void *)p;
13304 + goto out_pathname;
13306 + si_read_unlock(sb);
13307 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13308 + dentry = ERR_PTR(err);
13309 + if (unlikely(err))
13312 + dentry = ERR_PTR(-ENOENT);
13313 + AuDebugOn(au_test_anon(path.dentry));
13314 + if (unlikely(d_really_is_negative(path.dentry)))
13317 + if (ino != d_inode(path.dentry)->i_ino)
13318 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13320 + dentry = dget(path.dentry);
13325 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13326 + if (!IS_ERR(dentry)) {
13328 + dentry = ERR_PTR(-ESTALE);
13331 + free_page((unsigned long)pathname);
13335 + AuTraceErrPtr(dentry);
13339 +/* ---------------------------------------------------------------------- */
13341 +static struct dentry *
13342 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13345 + struct dentry *dentry;
13346 + __u32 *fh = fid->raw;
13347 + struct au_branch *br;
13348 + ino_t ino, dir_ino;
13349 + struct au_nfsd_si_lock nsi_lock = {
13353 + dentry = ERR_PTR(-ESTALE);
13354 + /* it should never happen, but the file handle is unreliable */
13355 + if (unlikely(fh_len < Fh_tail))
13357 + nsi_lock.sigen = fh[Fh_sigen];
13358 + nsi_lock.br_id = fh[Fh_br_id];
13360 + /* branch id may be wrapped around */
13362 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13364 + nsi_lock.force_lock = 1;
13366 + /* is this inode still cached? */
13367 + ino = decode_ino(fh + Fh_ino);
13368 + /* it should never happen */
13369 + if (unlikely(ino == AUFS_ROOT_INO))
13372 + dir_ino = decode_ino(fh + Fh_dir_ino);
13373 + dentry = decode_by_ino(sb, ino, dir_ino);
13374 + if (IS_ERR(dentry))
13379 + /* is the parent dir cached? */
13380 + br = au_sbr(sb, nsi_lock.bindex);
13382 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13383 + if (IS_ERR(dentry))
13388 + /* lookup path */
13389 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13390 + if (IS_ERR(dentry))
13392 + if (unlikely(!dentry))
13393 + /* todo?: make it ESTALE */
13397 + if (!au_digen_test(dentry, au_sigen(sb))
13398 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13399 + goto out_unlock; /* success */
13402 + dentry = ERR_PTR(-ESTALE);
13406 + si_read_unlock(sb);
13408 + AuTraceErrPtr(dentry);
13412 +#if 0 /* reserved for future use */
13413 +/* support subtreecheck option */
13414 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13415 + int fh_len, int fh_type)
13417 + struct dentry *parent;
13418 + __u32 *fh = fid->raw;
13421 + dir_ino = decode_ino(fh + Fh_dir_ino);
13422 + parent = decode_by_ino(sb, dir_ino, 0);
13423 + if (IS_ERR(parent))
13426 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13427 + dir_ino, fh, fh_len);
13430 + AuTraceErrPtr(parent);
13435 +/* ---------------------------------------------------------------------- */
13437 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13438 + struct inode *dir)
13441 + aufs_bindex_t bindex;
13442 + struct super_block *sb, *h_sb;
13443 + struct dentry *dentry, *parent, *h_parent;
13444 + struct inode *h_dir;
13445 + struct au_branch *br;
13448 + if (unlikely(*max_len <= Fh_tail)) {
13449 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13453 + err = FILEID_ROOT;
13454 + if (inode->i_ino == AUFS_ROOT_INO) {
13455 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13460 + sb = inode->i_sb;
13461 + err = si_read_lock(sb, AuLock_FLUSH);
13462 + if (unlikely(err))
13465 +#ifdef CONFIG_AUFS_DEBUG
13466 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13467 + AuWarn1("NFS-exporting requires xino\n");
13471 + ii_read_lock_child(inode);
13472 + bindex = au_ibtop(inode);
13474 + dentry = d_find_any_alias(inode);
13475 + if (unlikely(!dentry))
13477 + AuDebugOn(au_test_anon(dentry));
13478 + parent = dget_parent(dentry);
13480 + if (unlikely(!parent))
13482 + if (d_really_is_positive(parent))
13483 + dir = d_inode(parent);
13486 + ii_read_lock_parent(dir);
13487 + h_dir = au_h_iptr(dir, bindex);
13488 + ii_read_unlock(dir);
13489 + if (unlikely(!h_dir))
13491 + h_parent = d_find_any_alias(h_dir);
13492 + if (unlikely(!h_parent))
13493 + goto out_hparent;
13496 + br = au_sbr(sb, bindex);
13497 + h_sb = au_br_sb(br);
13498 + if (unlikely(!h_sb->s_export_op)) {
13499 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13500 + goto out_hparent;
13503 + fh[Fh_br_id] = br->br_id;
13504 + fh[Fh_sigen] = au_sigen(sb);
13505 + encode_ino(fh + Fh_ino, inode->i_ino);
13506 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13507 + fh[Fh_igen] = inode->i_generation;
13509 + *max_len -= Fh_tail;
13510 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13512 + /*connectable or subtreecheck*/0);
13513 + err = fh[Fh_h_type];
13514 + *max_len += Fh_tail;
13515 + /* todo: macros? */
13516 + if (err != FILEID_INVALID)
13519 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13526 + ii_read_unlock(inode);
13527 + si_read_unlock(sb);
13529 + if (unlikely(err < 0))
13530 + err = FILEID_INVALID;
13534 +/* ---------------------------------------------------------------------- */
13536 +static int aufs_commit_metadata(struct inode *inode)
13539 + aufs_bindex_t bindex;
13540 + struct super_block *sb;
13541 + struct inode *h_inode;
13542 + int (*f)(struct inode *inode);
13544 + sb = inode->i_sb;
13545 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13546 + ii_write_lock_child(inode);
13547 + bindex = au_ibtop(inode);
13548 + AuDebugOn(bindex < 0);
13549 + h_inode = au_h_iptr(inode, bindex);
13551 + f = h_inode->i_sb->s_export_op->commit_metadata;
13553 + err = f(h_inode);
13555 + struct writeback_control wbc = {
13556 + .sync_mode = WB_SYNC_ALL,
13557 + .nr_to_write = 0 /* metadata only */
13560 + err = sync_inode(h_inode, &wbc);
13563 + au_cpup_attr_timesizes(inode);
13564 + ii_write_unlock(inode);
13565 + si_read_unlock(sb);
13569 +/* ---------------------------------------------------------------------- */
13571 +static struct export_operations aufs_export_op = {
13572 + .fh_to_dentry = aufs_fh_to_dentry,
13573 + /* .fh_to_parent = aufs_fh_to_parent, */
13574 + .encode_fh = aufs_encode_fh,
13575 + .commit_metadata = aufs_commit_metadata
13578 +void au_export_init(struct super_block *sb)
13580 + struct au_sbinfo *sbinfo;
13583 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13584 + && IS_MODULE(CONFIG_EXPORTFS),
13585 + AUFS_NAME ": unsupported configuration "
13586 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13588 + sb->s_export_op = &aufs_export_op;
13589 + sbinfo = au_sbi(sb);
13590 + sbinfo->si_xigen = NULL;
13591 + get_random_bytes(&u, sizeof(u));
13592 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13593 + atomic_set(&sbinfo->si_xigen_next, u);
13595 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13596 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13597 +++ linux/fs/aufs/fhsm.c 2018-04-15 08:49:13.397817296 +0200
13600 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13602 + * This program, aufs is free software; you can redistribute it and/or modify
13603 + * it under the terms of the GNU General Public License as published by
13604 + * the Free Software Foundation; either version 2 of the License, or
13605 + * (at your option) any later version.
13607 + * This program is distributed in the hope that it will be useful,
13608 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13609 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13610 + * GNU General Public License for more details.
13612 + * You should have received a copy of the GNU General Public License
13613 + * along with this program; if not, write to the Free Software
13614 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13618 + * File-based Hierarchy Storage Management
13621 +#include <linux/anon_inodes.h>
13622 +#include <linux/poll.h>
13623 +#include <linux/seq_file.h>
13624 +#include <linux/statfs.h>
13627 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13629 + struct au_sbinfo *sbinfo;
13630 + struct au_fhsm *fhsm;
13632 + SiMustAnyLock(sb);
13634 + sbinfo = au_sbi(sb);
13635 + fhsm = &sbinfo->si_fhsm;
13636 + AuDebugOn(!fhsm);
13637 + return fhsm->fhsm_bottom;
13640 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13642 + struct au_sbinfo *sbinfo;
13643 + struct au_fhsm *fhsm;
13645 + SiMustWriteLock(sb);
13647 + sbinfo = au_sbi(sb);
13648 + fhsm = &sbinfo->si_fhsm;
13649 + AuDebugOn(!fhsm);
13650 + fhsm->fhsm_bottom = bindex;
13653 +/* ---------------------------------------------------------------------- */
13655 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13657 + struct au_br_fhsm *bf;
13659 + bf = br->br_fhsm;
13660 + MtxMustLock(&bf->bf_lock);
13662 + return !bf->bf_readable
13663 + || time_after(jiffies,
13664 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13667 +/* ---------------------------------------------------------------------- */
13669 +static void au_fhsm_notify(struct super_block *sb, int val)
13671 + struct au_sbinfo *sbinfo;
13672 + struct au_fhsm *fhsm;
13674 + SiMustAnyLock(sb);
13676 + sbinfo = au_sbi(sb);
13677 + fhsm = &sbinfo->si_fhsm;
13678 + if (au_fhsm_pid(fhsm)
13679 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13680 + atomic_set(&fhsm->fhsm_readable, val);
13682 + wake_up(&fhsm->fhsm_wqh);
13686 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13687 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13690 + struct au_branch *br;
13691 + struct au_br_fhsm *bf;
13693 + br = au_sbr(sb, bindex);
13694 + AuDebugOn(au_br_rdonly(br));
13695 + bf = br->br_fhsm;
13699 + mutex_lock(&bf->bf_lock);
13701 + MtxMustLock(&bf->bf_lock);
13703 + /* sb->s_root for NFS is unreliable */
13704 + err = au_br_stfs(br, &bf->bf_stfs);
13705 + if (unlikely(err)) {
13706 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13710 + bf->bf_jiffy = jiffies;
13711 + bf->bf_readable = 1;
13713 + au_fhsm_notify(sb, /*val*/1);
13715 + *rstfs = bf->bf_stfs;
13719 + mutex_unlock(&bf->bf_lock);
13720 + au_fhsm_notify(sb, /*val*/1);
13725 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13728 + struct au_sbinfo *sbinfo;
13729 + struct au_fhsm *fhsm;
13730 + struct au_branch *br;
13731 + struct au_br_fhsm *bf;
13733 + AuDbg("b%d, force %d\n", bindex, force);
13734 + SiMustAnyLock(sb);
13736 + sbinfo = au_sbi(sb);
13737 + fhsm = &sbinfo->si_fhsm;
13738 + if (!au_ftest_si(sbinfo, FHSM)
13739 + || fhsm->fhsm_bottom == bindex)
13742 + br = au_sbr(sb, bindex);
13743 + bf = br->br_fhsm;
13745 + mutex_lock(&bf->bf_lock);
13747 + || au_fhsm_pid(fhsm)
13748 + || au_fhsm_test_jiffy(sbinfo, br))
13749 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13751 + mutex_unlock(&bf->bf_lock);
13754 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13756 + aufs_bindex_t bindex, bbot;
13757 + struct au_branch *br;
13759 + /* exclude the bottom */
13760 + bbot = au_fhsm_bottom(sb);
13761 + for (bindex = 0; bindex < bbot; bindex++) {
13762 + br = au_sbr(sb, bindex);
13763 + if (au_br_fhsm(br->br_perm))
13764 + au_fhsm_wrote(sb, bindex, force);
13768 +/* ---------------------------------------------------------------------- */
13770 +static unsigned int au_fhsm_poll(struct file *file,
13771 + struct poll_table_struct *wait)
13773 + unsigned int mask;
13774 + struct au_sbinfo *sbinfo;
13775 + struct au_fhsm *fhsm;
13778 + sbinfo = file->private_data;
13779 + fhsm = &sbinfo->si_fhsm;
13780 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13781 + if (atomic_read(&fhsm->fhsm_readable))
13782 + mask = POLLIN /* | POLLRDNORM */;
13785 + AuDbg("mask 0x%x\n", mask);
13789 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13790 + struct aufs_stfs *stfs, __s16 brid)
13794 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13796 + err = __put_user(brid, &stbr->brid);
13797 + if (unlikely(err))
13803 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13804 + struct aufs_stbr __user *stbr, size_t count)
13808 + aufs_bindex_t bindex, bbot;
13809 + struct au_branch *br;
13810 + struct au_br_fhsm *bf;
13812 + /* except the bottom branch */
13815 + bbot = au_fhsm_bottom(sb);
13816 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13817 + br = au_sbr(sb, bindex);
13818 + if (!au_br_fhsm(br->br_perm))
13821 + bf = br->br_fhsm;
13822 + mutex_lock(&bf->bf_lock);
13823 + if (bf->bf_readable) {
13825 + if (count >= sizeof(*stbr))
13826 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13829 + bf->bf_readable = 0;
13830 + count -= sizeof(*stbr);
13834 + mutex_unlock(&bf->bf_lock);
13837 + err = sizeof(*stbr) * nstbr;
13842 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13847 + aufs_bindex_t nfhsm, bindex, bbot;
13848 + struct au_sbinfo *sbinfo;
13849 + struct au_fhsm *fhsm;
13850 + struct au_branch *br;
13851 + struct super_block *sb;
13854 + sbinfo = file->private_data;
13855 + fhsm = &sbinfo->si_fhsm;
13857 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13858 + if (!atomic_read(&fhsm->fhsm_readable)) {
13859 + if (vfsub_file_flags(file) & O_NONBLOCK)
13862 + err = wait_event_interruptible_locked_irq
13864 + atomic_read(&fhsm->fhsm_readable));
13866 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13867 + if (unlikely(err))
13870 + /* sb may already be dead */
13871 + au_rw_read_lock(&sbinfo->si_rwsem);
13872 + readable = atomic_read(&fhsm->fhsm_readable);
13873 + if (readable > 0) {
13874 + sb = sbinfo->si_sb;
13876 + /* exclude the bottom branch */
13878 + bbot = au_fhsm_bottom(sb);
13879 + for (bindex = 0; bindex < bbot; bindex++) {
13880 + br = au_sbr(sb, bindex);
13881 + if (au_br_fhsm(br->br_perm))
13885 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13886 + atomic_set(&fhsm->fhsm_readable, 0);
13887 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13891 + au_rw_read_unlock(&sbinfo->si_rwsem);
13899 +static int au_fhsm_release(struct inode *inode, struct file *file)
13901 + struct au_sbinfo *sbinfo;
13902 + struct au_fhsm *fhsm;
13904 + /* sb may already be dead */
13905 + sbinfo = file->private_data;
13906 + fhsm = &sbinfo->si_fhsm;
13907 + spin_lock(&fhsm->fhsm_spin);
13908 + fhsm->fhsm_pid = 0;
13909 + spin_unlock(&fhsm->fhsm_spin);
13910 + kobject_put(&sbinfo->si_kobj);
13915 +static const struct file_operations au_fhsm_fops = {
13916 + .owner = THIS_MODULE,
13917 + .llseek = noop_llseek,
13918 + .read = au_fhsm_read,
13919 + .poll = au_fhsm_poll,
13920 + .release = au_fhsm_release
13923 +int au_fhsm_fd(struct super_block *sb, int oflags)
13926 + struct au_sbinfo *sbinfo;
13927 + struct au_fhsm *fhsm;
13930 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13934 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13938 + sbinfo = au_sbi(sb);
13939 + fhsm = &sbinfo->si_fhsm;
13940 + spin_lock(&fhsm->fhsm_spin);
13941 + if (!fhsm->fhsm_pid)
13942 + fhsm->fhsm_pid = current->pid;
13945 + spin_unlock(&fhsm->fhsm_spin);
13946 + if (unlikely(err))
13949 + oflags |= O_RDONLY;
13950 + /* oflags |= FMODE_NONOTIFY; */
13951 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13953 + if (unlikely(fd < 0))
13956 + /* succeed reglardless 'fhsm' status */
13957 + kobject_get(&sbinfo->si_kobj);
13958 + si_noflush_read_lock(sb);
13959 + if (au_ftest_si(sbinfo, FHSM))
13960 + au_fhsm_wrote_all(sb, /*force*/0);
13961 + si_read_unlock(sb);
13962 + goto out; /* success */
13965 + spin_lock(&fhsm->fhsm_spin);
13966 + fhsm->fhsm_pid = 0;
13967 + spin_unlock(&fhsm->fhsm_spin);
13973 +/* ---------------------------------------------------------------------- */
13975 +int au_fhsm_br_alloc(struct au_branch *br)
13980 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13982 + au_br_fhsm_init(br->br_fhsm);
13989 +/* ---------------------------------------------------------------------- */
13991 +void au_fhsm_fin(struct super_block *sb)
13993 + au_fhsm_notify(sb, /*val*/-1);
13996 +void au_fhsm_init(struct au_sbinfo *sbinfo)
13998 + struct au_fhsm *fhsm;
14000 + fhsm = &sbinfo->si_fhsm;
14001 + spin_lock_init(&fhsm->fhsm_spin);
14002 + init_waitqueue_head(&fhsm->fhsm_wqh);
14003 + atomic_set(&fhsm->fhsm_readable, 0);
14004 + fhsm->fhsm_expire
14005 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14006 + fhsm->fhsm_bottom = -1;
14009 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14011 + sbinfo->si_fhsm.fhsm_expire
14012 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14015 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14019 + if (!au_ftest_si(sbinfo, FHSM))
14022 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14023 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14024 + seq_printf(seq, ",fhsm_sec=%u", u);
14026 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14027 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14028 +++ linux/fs/aufs/file.c 2018-04-15 08:49:13.397817296 +0200
14031 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14033 + * This program, aufs is free software; you can redistribute it and/or modify
14034 + * it under the terms of the GNU General Public License as published by
14035 + * the Free Software Foundation; either version 2 of the License, or
14036 + * (at your option) any later version.
14038 + * This program is distributed in the hope that it will be useful,
14039 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14040 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14041 + * GNU General Public License for more details.
14043 + * You should have received a copy of the GNU General Public License
14044 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14048 + * handling file/dir, and address_space operation
14051 +#ifdef CONFIG_AUFS_DEBUG
14052 +#include <linux/migrate.h>
14054 +#include <linux/pagemap.h>
14057 +/* drop flags for writing */
14058 +unsigned int au_file_roflags(unsigned int flags)
14060 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14061 + flags |= O_RDONLY | O_NOATIME;
14065 +/* common functions to regular file and dir */
14066 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14067 + struct file *file, int force_wr)
14069 + struct file *h_file;
14070 + struct dentry *h_dentry;
14071 + struct inode *h_inode;
14072 + struct super_block *sb;
14073 + struct au_branch *br;
14074 + struct path h_path;
14077 + /* a race condition can happen between open and unlink/rmdir */
14078 + h_file = ERR_PTR(-ENOENT);
14079 + h_dentry = au_h_dptr(dentry, bindex);
14080 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14082 + h_inode = d_inode(h_dentry);
14083 + spin_lock(&h_dentry->d_lock);
14084 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14085 + /* || !d_inode(dentry)->i_nlink */
14087 + spin_unlock(&h_dentry->d_lock);
14088 + if (unlikely(err))
14091 + sb = dentry->d_sb;
14092 + br = au_sbr(sb, bindex);
14093 + err = au_br_test_oflag(flags, br);
14094 + h_file = ERR_PTR(err);
14095 + if (unlikely(err))
14098 + /* drop flags for writing */
14099 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14100 + if (force_wr && !(flags & O_WRONLY))
14102 + flags = au_file_roflags(flags);
14104 + h_file = ERR_PTR(-EROFS);
14105 + flags = au_file_roflags(flags);
14106 + if (unlikely(vfsub_native_ro(h_inode)
14107 + || IS_APPEND(h_inode)))
14109 + flags &= ~O_ACCMODE;
14110 + flags |= O_WRONLY;
14113 + flags &= ~O_CREAT;
14115 + h_path.dentry = h_dentry;
14116 + h_path.mnt = au_br_mnt(br);
14117 + h_file = vfsub_dentry_open(&h_path, flags);
14118 + if (IS_ERR(h_file))
14121 + if (flags & __FMODE_EXEC) {
14122 + err = deny_write_access(h_file);
14123 + if (unlikely(err)) {
14125 + h_file = ERR_PTR(err);
14129 + fsnotify_open(h_file);
14130 + goto out; /* success */
14138 +static int au_cmoo(struct dentry *dentry)
14140 + int err, cmoo, matched;
14141 + unsigned int udba;
14142 + struct path h_path;
14143 + struct au_pin pin;
14144 + struct au_cp_generic cpg = {
14145 + .dentry = dentry,
14150 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14152 + struct inode *delegated;
14153 + struct super_block *sb;
14154 + struct au_sbinfo *sbinfo;
14155 + struct au_fhsm *fhsm;
14157 + struct au_branch *br;
14158 + struct dentry *parent;
14159 + struct au_hinode *hdir;
14161 + DiMustWriteLock(dentry);
14162 + IiMustWriteLock(d_inode(dentry));
14165 + if (IS_ROOT(dentry))
14167 + cpg.bsrc = au_dbtop(dentry);
14171 + sb = dentry->d_sb;
14172 + sbinfo = au_sbi(sb);
14173 + fhsm = &sbinfo->si_fhsm;
14174 + pid = au_fhsm_pid(fhsm);
14177 + && (current->pid == pid
14178 + || rcu_dereference(current->real_parent)->pid == pid));
14179 + rcu_read_unlock();
14183 + br = au_sbr(sb, cpg.bsrc);
14184 + cmoo = au_br_cmoo(br->br_perm);
14187 + if (!d_is_reg(dentry))
14188 + cmoo &= AuBrAttr_COO_ALL;
14192 + parent = dget_parent(dentry);
14193 + di_write_lock_parent(parent);
14194 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14196 + if (unlikely(err < 0)) {
14197 + err = 0; /* there is no upper writable branch */
14200 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14202 + /* do not respect the coo attrib for the target branch */
14203 + err = au_cpup_dirs(dentry, cpg.bdst);
14204 + if (unlikely(err))
14207 + di_downgrade_lock(parent, AuLock_IR);
14208 + udba = au_opt_udba(sb);
14209 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14210 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14211 + if (unlikely(err))
14214 + err = au_sio_cpup_simple(&cpg);
14216 + if (unlikely(err))
14218 + if (!(cmoo & AuBrWAttr_MOO))
14219 + goto out_parent; /* success */
14221 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14222 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14223 + if (unlikely(err))
14226 + h_path.mnt = au_br_mnt(br);
14227 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14228 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14229 + delegated = NULL;
14230 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14232 + /* todo: keep h_dentry or not? */
14233 + if (unlikely(err == -EWOULDBLOCK)) {
14234 + pr_warn("cannot retry for NFSv4 delegation"
14235 + " for an internal unlink\n");
14238 + if (unlikely(err)) {
14239 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14243 + goto out_parent; /* success */
14246 + di_downgrade_lock(parent, AuLock_IR);
14248 + di_read_unlock(parent, AuLock_IR);
14255 +int au_do_open(struct file *file, struct au_do_open_args *args)
14257 + int err, aopen = args->aopen;
14258 + struct dentry *dentry;
14259 + struct au_finfo *finfo;
14262 + err = au_finfo_init(file, args->fidir);
14265 + err = au_finfo_init(file, args->fidir);
14268 + if (unlikely(err))
14271 + dentry = file->f_path.dentry;
14272 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14273 + di_write_lock_child(dentry);
14274 + err = au_cmoo(dentry);
14275 + di_downgrade_lock(dentry, AuLock_IR);
14277 + err = args->open(file, vfsub_file_flags(file), NULL);
14278 + di_read_unlock(dentry, AuLock_IR);
14280 + finfo = au_fi(file);
14282 + finfo->fi_file = file;
14283 + au_hbl_add(&finfo->fi_hlist,
14284 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14287 + fi_write_unlock(file);
14290 + fi_write_unlock(file);
14293 + if (unlikely(err)) {
14294 + finfo->fi_hdir = NULL;
14295 + au_finfo_fin(file);
14302 +int au_reopen_nondir(struct file *file)
14305 + aufs_bindex_t btop;
14306 + struct dentry *dentry;
14307 + struct file *h_file, *h_file_tmp;
14309 + dentry = file->f_path.dentry;
14310 + btop = au_dbtop(dentry);
14311 + h_file_tmp = NULL;
14312 + if (au_fbtop(file) == btop) {
14313 + h_file = au_hf_top(file);
14314 + if (file->f_mode == h_file->f_mode)
14315 + return 0; /* success */
14316 + h_file_tmp = h_file;
14317 + get_file(h_file_tmp);
14318 + au_set_h_fptr(file, btop, NULL);
14320 + AuDebugOn(au_fi(file)->fi_hdir);
14323 + * file exists on both of rw and ro
14324 + * open --> dbtop and fbtop are both 0
14325 + * prepend a branch as rw, "rw" become ro
14327 + * delete the top branch, "rw" becomes rw again
14328 + * --> dbtop is 1, fbtop is still 0
14329 + * write --> fbtop is 0 but dbtop is 1
14331 + /* AuDebugOn(au_fbtop(file) < btop); */
14333 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14334 + file, /*force_wr*/0);
14335 + err = PTR_ERR(h_file);
14336 + if (IS_ERR(h_file)) {
14337 + if (h_file_tmp) {
14338 + au_sbr_get(dentry->d_sb, btop);
14339 + au_set_h_fptr(file, btop, h_file_tmp);
14340 + h_file_tmp = NULL;
14342 + goto out; /* todo: close all? */
14346 + au_set_fbtop(file, btop);
14347 + au_set_h_fptr(file, btop, h_file);
14348 + au_update_figen(file);
14349 + /* todo: necessary? */
14350 + /* file->f_ra = h_file->f_ra; */
14354 + fput(h_file_tmp);
14358 +/* ---------------------------------------------------------------------- */
14360 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14361 + struct dentry *hi_wh)
14364 + aufs_bindex_t btop;
14365 + struct au_dinfo *dinfo;
14366 + struct dentry *h_dentry;
14367 + struct au_hdentry *hdp;
14369 + dinfo = au_di(file->f_path.dentry);
14370 + AuRwMustWriteLock(&dinfo->di_rwsem);
14372 + btop = dinfo->di_btop;
14373 + dinfo->di_btop = btgt;
14374 + hdp = au_hdentry(dinfo, btgt);
14375 + h_dentry = hdp->hd_dentry;
14376 + hdp->hd_dentry = hi_wh;
14377 + err = au_reopen_nondir(file);
14378 + hdp->hd_dentry = h_dentry;
14379 + dinfo->di_btop = btop;
14384 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14385 + aufs_bindex_t bcpup, struct au_pin *pin)
14388 + struct inode *inode, *h_inode;
14389 + struct dentry *h_dentry, *hi_wh;
14390 + struct au_cp_generic cpg = {
14391 + .dentry = file->f_path.dentry,
14398 + au_update_dbtop(cpg.dentry);
14399 + inode = d_inode(cpg.dentry);
14401 + if (au_dbtop(cpg.dentry) <= bcpup
14402 + && au_dbbot(cpg.dentry) >= bcpup) {
14403 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14404 + if (h_dentry && d_is_positive(h_dentry))
14405 + h_inode = d_inode(h_dentry);
14407 + hi_wh = au_hi_wh(inode, bcpup);
14408 + if (!hi_wh && !h_inode)
14409 + err = au_sio_cpup_wh(&cpg, file);
14411 + /* already copied-up after unlink */
14412 + err = au_reopen_wh(file, bcpup, hi_wh);
14415 + && (inode->i_nlink > 1
14416 + || (inode->i_state & I_LINKABLE))
14417 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14418 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14424 + * prepare the @file for writing.
14426 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14429 + aufs_bindex_t dbtop;
14430 + struct dentry *parent;
14431 + struct inode *inode;
14432 + struct super_block *sb;
14433 + struct file *h_file;
14434 + struct au_cp_generic cpg = {
14435 + .dentry = file->f_path.dentry,
14440 + .flags = AuCpup_DTIME
14443 + sb = cpg.dentry->d_sb;
14444 + inode = d_inode(cpg.dentry);
14445 + cpg.bsrc = au_fbtop(file);
14446 + err = au_test_ro(sb, cpg.bsrc, inode);
14447 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14448 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14453 + /* need to cpup or reopen */
14454 + parent = dget_parent(cpg.dentry);
14455 + di_write_lock_parent(parent);
14456 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14458 + if (unlikely(err < 0))
14462 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14463 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14464 + if (unlikely(err))
14468 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14469 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14470 + if (unlikely(err))
14473 + dbtop = au_dbtop(cpg.dentry);
14474 + if (dbtop <= cpg.bdst)
14475 + cpg.bsrc = cpg.bdst;
14477 + if (dbtop <= cpg.bdst /* just reopen */
14478 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14480 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14481 + if (IS_ERR(h_file))
14482 + err = PTR_ERR(h_file);
14484 + di_downgrade_lock(parent, AuLock_IR);
14485 + if (dbtop > cpg.bdst)
14486 + err = au_sio_cpup_simple(&cpg);
14488 + err = au_reopen_nondir(file);
14489 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14491 + } else { /* copyup as wh and reopen */
14493 + * since writable hfsplus branch is not supported,
14494 + * h_open_pre/post() are unnecessary.
14496 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14497 + di_downgrade_lock(parent, AuLock_IR);
14501 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14502 + goto out_dput; /* success */
14508 + di_downgrade_lock(parent, AuLock_IR);
14510 + di_read_unlock(parent, AuLock_IR);
14517 +/* ---------------------------------------------------------------------- */
14519 +int au_do_flush(struct file *file, fl_owner_t id,
14520 + int (*flush)(struct file *file, fl_owner_t id))
14523 + struct super_block *sb;
14524 + struct inode *inode;
14526 + inode = file_inode(file);
14527 + sb = inode->i_sb;
14528 + si_noflush_read_lock(sb);
14529 + fi_read_lock(file);
14530 + ii_read_lock_child(inode);
14532 + err = flush(file, id);
14533 + au_cpup_attr_timesizes(inode);
14535 + ii_read_unlock(inode);
14536 + fi_read_unlock(file);
14537 + si_read_unlock(sb);
14541 +/* ---------------------------------------------------------------------- */
14543 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14546 + struct au_pin pin;
14547 + struct au_finfo *finfo;
14548 + struct dentry *parent, *hi_wh;
14549 + struct inode *inode;
14550 + struct super_block *sb;
14551 + struct au_cp_generic cpg = {
14552 + .dentry = file->f_path.dentry,
14557 + .flags = AuCpup_DTIME
14560 + FiMustWriteLock(file);
14563 + finfo = au_fi(file);
14564 + sb = cpg.dentry->d_sb;
14565 + inode = d_inode(cpg.dentry);
14566 + cpg.bdst = au_ibtop(inode);
14567 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14570 + parent = dget_parent(cpg.dentry);
14571 + if (au_test_ro(sb, cpg.bdst, inode)) {
14572 + di_read_lock_parent(parent, !AuLock_IR);
14573 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14575 + di_read_unlock(parent, !AuLock_IR);
14576 + if (unlikely(err < 0))
14581 + di_read_lock_parent(parent, AuLock_IR);
14582 + hi_wh = au_hi_wh(inode, cpg.bdst);
14583 + if (!S_ISDIR(inode->i_mode)
14584 + && au_opt_test(au_mntflags(sb), PLINK)
14585 + && au_plink_test(inode)
14586 + && !d_unhashed(cpg.dentry)
14587 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14588 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14589 + if (unlikely(err))
14592 + /* always superio. */
14593 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14594 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14596 + err = au_sio_cpup_simple(&cpg);
14599 + } else if (hi_wh) {
14600 + /* already copied-up after unlink */
14601 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14602 + *need_reopen = 0;
14606 + di_read_unlock(parent, AuLock_IR);
14613 +static void au_do_refresh_dir(struct file *file)
14615 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14616 + struct au_hfile *p, tmp, *q;
14617 + struct au_finfo *finfo;
14618 + struct super_block *sb;
14619 + struct au_fidir *fidir;
14621 + FiMustWriteLock(file);
14623 + sb = file->f_path.dentry->d_sb;
14624 + finfo = au_fi(file);
14625 + fidir = finfo->fi_hdir;
14626 + AuDebugOn(!fidir);
14627 + p = fidir->fd_hfile + finfo->fi_btop;
14628 + brid = p->hf_br->br_id;
14629 + bbot = fidir->fd_bbot;
14630 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14634 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14635 + if (new_bindex == bindex)
14637 + if (new_bindex < 0) {
14638 + au_set_h_fptr(file, bindex, NULL);
14642 + /* swap two lower inode, and loop again */
14643 + q = fidir->fd_hfile + new_bindex;
14647 + if (tmp.hf_file) {
14653 + p = fidir->fd_hfile;
14654 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14655 + bbot = au_sbbot(sb);
14656 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14657 + finfo->fi_btop++, p++)
14658 + if (p->hf_file) {
14659 + if (file_inode(p->hf_file))
14661 + au_hfput(p, /*execed*/0);
14664 + bbot = au_br_index(sb, brid);
14665 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14666 + finfo->fi_btop++, p++)
14668 + au_hfput(p, /*execed*/0);
14669 + bbot = au_sbbot(sb);
14672 + p = fidir->fd_hfile + bbot;
14673 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14674 + fidir->fd_bbot--, p--)
14675 + if (p->hf_file) {
14676 + if (file_inode(p->hf_file))
14678 + au_hfput(p, /*execed*/0);
14680 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14684 + * after branch manipulating, refresh the file.
14686 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14688 + int err, need_reopen, nbr;
14689 + aufs_bindex_t bbot, bindex;
14690 + struct dentry *dentry;
14691 + struct super_block *sb;
14692 + struct au_finfo *finfo;
14693 + struct au_hfile *hfile;
14695 + dentry = file->f_path.dentry;
14696 + sb = dentry->d_sb;
14697 + nbr = au_sbbot(sb) + 1;
14698 + finfo = au_fi(file);
14699 + if (!finfo->fi_hdir) {
14700 + hfile = &finfo->fi_htop;
14701 + AuDebugOn(!hfile->hf_file);
14702 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14703 + AuDebugOn(bindex < 0);
14704 + if (bindex != finfo->fi_btop)
14705 + au_set_fbtop(file, bindex);
14707 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14708 + if (unlikely(err))
14710 + au_do_refresh_dir(file);
14715 + if (!au_test_mmapped(file))
14716 + err = au_file_refresh_by_inode(file, &need_reopen);
14717 + if (finfo->fi_hdir)
14718 + /* harmless if err */
14719 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14720 + if (!err && need_reopen && !d_unlinked(dentry))
14721 + err = reopen(file);
14723 + au_update_figen(file);
14724 + goto out; /* success */
14727 + /* error, close all lower files */
14728 + if (finfo->fi_hdir) {
14729 + bbot = au_fbbot_dir(file);
14730 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14731 + au_set_h_fptr(file, bindex, NULL);
14738 +/* common function to regular file and dir */
14739 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14740 + int wlock, unsigned int fi_lsc)
14743 + unsigned int sigen, figen;
14744 + aufs_bindex_t btop;
14745 + unsigned char pseudo_link;
14746 + struct dentry *dentry;
14747 + struct inode *inode;
14750 + dentry = file->f_path.dentry;
14751 + inode = d_inode(dentry);
14752 + sigen = au_sigen(dentry->d_sb);
14753 + fi_write_lock_nested(file, fi_lsc);
14754 + figen = au_figen(file);
14756 + di_write_lock_child(dentry);
14758 + di_write_lock_child2(dentry);
14759 + btop = au_dbtop(dentry);
14760 + pseudo_link = (btop != au_ibtop(inode));
14761 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14763 + di_downgrade_lock(dentry, AuLock_IR);
14764 + fi_downgrade_lock(file);
14766 + goto out; /* success */
14769 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14770 + if (au_digen_test(dentry, sigen)) {
14771 + err = au_reval_dpath(dentry, sigen);
14772 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14776 + err = refresh_file(file, reopen);
14779 + di_downgrade_lock(dentry, AuLock_IR);
14780 + fi_downgrade_lock(file);
14783 + di_write_unlock(dentry);
14784 + fi_write_unlock(file);
14791 +/* ---------------------------------------------------------------------- */
14793 +/* cf. aufs_nopage() */
14794 +/* for madvise(2) */
14795 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14797 + unlock_page(page);
14801 +/* it will never be called, but necessary to support O_DIRECT */
14802 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14803 +{ BUG(); return 0; }
14805 +/* they will never be called. */
14806 +#ifdef CONFIG_AUFS_DEBUG
14807 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14808 + loff_t pos, unsigned len, unsigned flags,
14809 + struct page **pagep, void **fsdata)
14810 +{ AuUnsupport(); return 0; }
14811 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14812 + loff_t pos, unsigned len, unsigned copied,
14813 + struct page *page, void *fsdata)
14814 +{ AuUnsupport(); return 0; }
14815 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14816 +{ AuUnsupport(); return 0; }
14818 +static int aufs_set_page_dirty(struct page *page)
14819 +{ AuUnsupport(); return 0; }
14820 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14821 + unsigned int length)
14822 +{ AuUnsupport(); }
14823 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14824 +{ AuUnsupport(); return 0; }
14825 +#if 0 /* called by memory compaction regardless file */
14826 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14827 + struct page *page, enum migrate_mode mode)
14828 +{ AuUnsupport(); return 0; }
14830 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14831 +{ AuUnsupport(); return true; }
14832 +static void aufs_putback_page(struct page *page)
14833 +{ AuUnsupport(); }
14834 +static int aufs_launder_page(struct page *page)
14835 +{ AuUnsupport(); return 0; }
14836 +static int aufs_is_partially_uptodate(struct page *page,
14837 + unsigned long from,
14838 + unsigned long count)
14839 +{ AuUnsupport(); return 0; }
14840 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14842 +{ AuUnsupport(); }
14843 +static int aufs_error_remove_page(struct address_space *mapping,
14844 + struct page *page)
14845 +{ AuUnsupport(); return 0; }
14846 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14848 +{ AuUnsupport(); return 0; }
14849 +static void aufs_swap_deactivate(struct file *file)
14850 +{ AuUnsupport(); }
14851 +#endif /* CONFIG_AUFS_DEBUG */
14853 +const struct address_space_operations aufs_aop = {
14854 + .readpage = aufs_readpage,
14855 + .direct_IO = aufs_direct_IO,
14856 +#ifdef CONFIG_AUFS_DEBUG
14857 + .writepage = aufs_writepage,
14858 + /* no writepages, because of writepage */
14859 + .set_page_dirty = aufs_set_page_dirty,
14860 + /* no readpages, because of readpage */
14861 + .write_begin = aufs_write_begin,
14862 + .write_end = aufs_write_end,
14863 + /* no bmap, no block device */
14864 + .invalidatepage = aufs_invalidatepage,
14865 + .releasepage = aufs_releasepage,
14866 + /* is fallback_migrate_page ok? */
14867 + /* .migratepage = aufs_migratepage, */
14868 + .isolate_page = aufs_isolate_page,
14869 + .putback_page = aufs_putback_page,
14870 + .launder_page = aufs_launder_page,
14871 + .is_partially_uptodate = aufs_is_partially_uptodate,
14872 + .is_dirty_writeback = aufs_is_dirty_writeback,
14873 + .error_remove_page = aufs_error_remove_page,
14874 + .swap_activate = aufs_swap_activate,
14875 + .swap_deactivate = aufs_swap_deactivate
14876 +#endif /* CONFIG_AUFS_DEBUG */
14878 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14879 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14880 +++ linux/fs/aufs/file.h 2018-04-15 08:49:13.397817296 +0200
14883 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14885 + * This program, aufs is free software; you can redistribute it and/or modify
14886 + * it under the terms of the GNU General Public License as published by
14887 + * the Free Software Foundation; either version 2 of the License, or
14888 + * (at your option) any later version.
14890 + * This program is distributed in the hope that it will be useful,
14891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14893 + * GNU General Public License for more details.
14895 + * You should have received a copy of the GNU General Public License
14896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14900 + * file operations
14903 +#ifndef __AUFS_FILE_H__
14904 +#define __AUFS_FILE_H__
14908 +#include <linux/file.h>
14909 +#include <linux/fs.h>
14910 +#include <linux/poll.h>
14911 +#include "rwsem.h"
14915 + struct file *hf_file;
14916 + struct au_branch *hf_br;
14921 + aufs_bindex_t fd_bbot;
14922 + aufs_bindex_t fd_nent;
14923 + struct au_vdir *fd_vdir_cache;
14924 + struct au_hfile fd_hfile[];
14927 +static inline int au_fidir_sz(int nent)
14929 + AuDebugOn(nent < 0);
14930 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14934 + atomic_t fi_generation;
14936 + struct au_rwsem fi_rwsem;
14937 + aufs_bindex_t fi_btop;
14939 + /* do not union them */
14940 + struct { /* for non-dir */
14941 + struct au_hfile fi_htop;
14942 + atomic_t fi_mmapped;
14944 + struct au_fidir *fi_hdir; /* for dir only */
14946 + struct hlist_bl_node fi_hlist;
14947 + struct file *fi_file; /* very ugly */
14948 +} ____cacheline_aligned_in_smp;
14950 +/* ---------------------------------------------------------------------- */
14953 +extern const struct address_space_operations aufs_aop;
14954 +unsigned int au_file_roflags(unsigned int flags);
14955 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14956 + struct file *file, int force_wr);
14957 +struct au_do_open_args {
14959 + int (*open)(struct file *file, int flags,
14960 + struct file *h_file);
14961 + struct au_fidir *fidir;
14962 + struct file *h_file;
14964 +int au_do_open(struct file *file, struct au_do_open_args *args);
14965 +int au_reopen_nondir(struct file *file);
14967 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14968 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14969 + int wlock, unsigned int fi_lsc);
14970 +int au_do_flush(struct file *file, fl_owner_t id,
14971 + int (*flush)(struct file *file, fl_owner_t id));
14974 +#ifdef CONFIG_AUFS_POLL
14975 +unsigned int aufs_poll(struct file *file, poll_table *wait);
14978 +#ifdef CONFIG_AUFS_BR_HFSPLUS
14980 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14982 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14983 + struct file *h_file);
14985 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
14986 + aufs_bindex_t bindex, int force_wr)
14987 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
14988 + struct file *h_file);
14992 +extern const struct file_operations aufs_file_fop;
14993 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
14994 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
14995 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
14998 +void au_hfput(struct au_hfile *hf, int execed);
14999 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15000 + struct file *h_file);
15002 +void au_update_figen(struct file *file);
15003 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15004 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15006 +void au_fi_init_once(void *_fi);
15007 +void au_finfo_fin(struct file *file);
15008 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15011 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15012 +#ifdef CONFIG_COMPAT
15013 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15014 + unsigned long arg);
15015 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15016 + unsigned long arg);
15019 +/* ---------------------------------------------------------------------- */
15021 +static inline struct au_finfo *au_fi(struct file *file)
15023 + return file->private_data;
15026 +/* ---------------------------------------------------------------------- */
15029 + * fi_read_lock, fi_write_lock,
15030 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
15032 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
15034 +/* lock subclass for finfo */
15040 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15042 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15045 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15047 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15051 + * fi_read_lock_1, fi_write_lock_1,
15052 + * fi_read_lock_2, fi_write_lock_2
15054 +#define AuReadLockFunc(name) \
15055 +static inline void fi_read_lock_##name(struct file *f) \
15056 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15058 +#define AuWriteLockFunc(name) \
15059 +static inline void fi_write_lock_##name(struct file *f) \
15060 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15062 +#define AuRWLockFuncs(name) \
15063 + AuReadLockFunc(name) \
15064 + AuWriteLockFunc(name)
15069 +#undef AuReadLockFunc
15070 +#undef AuWriteLockFunc
15071 +#undef AuRWLockFuncs
15073 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15074 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15075 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15077 +/* ---------------------------------------------------------------------- */
15079 +/* todo: hard/soft set? */
15080 +static inline aufs_bindex_t au_fbtop(struct file *file)
15082 + FiMustAnyLock(file);
15083 + return au_fi(file)->fi_btop;
15086 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15088 + FiMustAnyLock(file);
15089 + AuDebugOn(!au_fi(file)->fi_hdir);
15090 + return au_fi(file)->fi_hdir->fd_bbot;
15093 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15095 + FiMustAnyLock(file);
15096 + AuDebugOn(!au_fi(file)->fi_hdir);
15097 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15100 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15102 + FiMustWriteLock(file);
15103 + au_fi(file)->fi_btop = bindex;
15106 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15108 + FiMustWriteLock(file);
15109 + AuDebugOn(!au_fi(file)->fi_hdir);
15110 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15113 +static inline void au_set_fvdir_cache(struct file *file,
15114 + struct au_vdir *vdir_cache)
15116 + FiMustWriteLock(file);
15117 + AuDebugOn(!au_fi(file)->fi_hdir);
15118 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15121 +static inline struct file *au_hf_top(struct file *file)
15123 + FiMustAnyLock(file);
15124 + AuDebugOn(au_fi(file)->fi_hdir);
15125 + return au_fi(file)->fi_htop.hf_file;
15128 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15130 + FiMustAnyLock(file);
15131 + AuDebugOn(!au_fi(file)->fi_hdir);
15132 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15135 +/* todo: memory barrier? */
15136 +static inline unsigned int au_figen(struct file *f)
15138 + return atomic_read(&au_fi(f)->fi_generation);
15141 +static inline void au_set_mmapped(struct file *f)
15143 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15145 + pr_warn("fi_mmapped wrapped around\n");
15146 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15150 +static inline void au_unset_mmapped(struct file *f)
15152 + atomic_dec(&au_fi(f)->fi_mmapped);
15155 +static inline int au_test_mmapped(struct file *f)
15157 + return atomic_read(&au_fi(f)->fi_mmapped);
15160 +/* customize vma->vm_file */
15162 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15163 + struct file *file)
15167 + f = vma->vm_file;
15169 + vma->vm_file = file;
15174 +#define AuDbgVmRegion(file, vma) do {} while (0)
15176 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15177 + struct file *file)
15179 + au_do_vm_file_reset(vma, file);
15182 +#define AuDbgVmRegion(file, vma) \
15183 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15185 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15186 + struct file *file)
15190 + au_do_vm_file_reset(vma, file);
15191 + f = vma->vm_region->vm_file;
15193 + vma->vm_region->vm_file = file;
15196 +#endif /* CONFIG_MMU */
15198 +/* handle vma->vm_prfile */
15199 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15200 + struct file *file)
15203 + vma->vm_prfile = file;
15204 +#ifndef CONFIG_MMU
15206 + vma->vm_region->vm_prfile = file;
15210 +#endif /* __KERNEL__ */
15211 +#endif /* __AUFS_FILE_H__ */
15212 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15213 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15214 +++ linux/fs/aufs/finfo.c 2018-04-15 08:49:13.397817296 +0200
15217 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15219 + * This program, aufs is free software; you can redistribute it and/or modify
15220 + * it under the terms of the GNU General Public License as published by
15221 + * the Free Software Foundation; either version 2 of the License, or
15222 + * (at your option) any later version.
15224 + * This program is distributed in the hope that it will be useful,
15225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15227 + * GNU General Public License for more details.
15229 + * You should have received a copy of the GNU General Public License
15230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15234 + * file private data
15239 +void au_hfput(struct au_hfile *hf, int execed)
15242 + allow_write_access(hf->hf_file);
15243 + fput(hf->hf_file);
15244 + hf->hf_file = NULL;
15245 + au_br_put(hf->hf_br);
15246 + hf->hf_br = NULL;
15249 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15251 + struct au_finfo *finfo = au_fi(file);
15252 + struct au_hfile *hf;
15253 + struct au_fidir *fidir;
15255 + fidir = finfo->fi_hdir;
15257 + AuDebugOn(finfo->fi_btop != bindex);
15258 + hf = &finfo->fi_htop;
15260 + hf = fidir->fd_hfile + bindex;
15262 + if (hf && hf->hf_file)
15263 + au_hfput(hf, vfsub_file_execed(file));
15265 + FiMustWriteLock(file);
15266 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15267 + hf->hf_file = val;
15268 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15272 +void au_update_figen(struct file *file)
15274 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15275 + /* smp_mb(); */ /* atomic_set */
15278 +/* ---------------------------------------------------------------------- */
15280 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15282 + struct au_fidir *fidir;
15285 + nbr = au_sbbot(sb) + 1;
15287 + nbr = 2; /* initial allocate for 2 branches */
15288 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15290 + fidir->fd_bbot = -1;
15291 + fidir->fd_nent = nbr;
15297 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15300 + struct au_fidir *fidir, *p;
15302 + AuRwMustWriteLock(&finfo->fi_rwsem);
15303 + fidir = finfo->fi_hdir;
15304 + AuDebugOn(!fidir);
15307 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15308 + GFP_NOFS, may_shrink);
15310 + p->fd_nent = nbr;
15311 + finfo->fi_hdir = p;
15318 +/* ---------------------------------------------------------------------- */
15320 +void au_finfo_fin(struct file *file)
15322 + struct au_finfo *finfo;
15324 + au_nfiles_dec(file->f_path.dentry->d_sb);
15326 + finfo = au_fi(file);
15327 + AuDebugOn(finfo->fi_hdir);
15328 + AuRwDestroy(&finfo->fi_rwsem);
15329 + au_cache_free_finfo(finfo);
15332 +void au_fi_init_once(void *_finfo)
15334 + struct au_finfo *finfo = _finfo;
15336 + au_rw_init(&finfo->fi_rwsem);
15339 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15342 + struct au_finfo *finfo;
15343 + struct dentry *dentry;
15346 + dentry = file->f_path.dentry;
15347 + finfo = au_cache_alloc_finfo();
15348 + if (unlikely(!finfo))
15352 + au_nfiles_inc(dentry->d_sb);
15353 + au_rw_write_lock(&finfo->fi_rwsem);
15354 + finfo->fi_btop = -1;
15355 + finfo->fi_hdir = fidir;
15356 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15357 + /* smp_mb(); */ /* atomic_set */
15359 + file->private_data = finfo;
15364 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15365 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15366 +++ linux/fs/aufs/f_op.c 2018-04-15 08:49:13.397817296 +0200
15369 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15371 + * This program, aufs is free software; you can redistribute it and/or modify
15372 + * it under the terms of the GNU General Public License as published by
15373 + * the Free Software Foundation; either version 2 of the License, or
15374 + * (at your option) any later version.
15376 + * This program is distributed in the hope that it will be useful,
15377 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15378 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15379 + * GNU General Public License for more details.
15381 + * You should have received a copy of the GNU General Public License
15382 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15386 + * file and vm operations
15389 +#include <linux/aio.h>
15390 +#include <linux/fs_stack.h>
15391 +#include <linux/mman.h>
15392 +#include <linux/security.h>
15395 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15398 + aufs_bindex_t bindex;
15399 + struct dentry *dentry, *h_dentry;
15400 + struct au_finfo *finfo;
15401 + struct inode *h_inode;
15403 + FiMustWriteLock(file);
15406 + dentry = file->f_path.dentry;
15407 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15408 + finfo = au_fi(file);
15409 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15410 + atomic_set(&finfo->fi_mmapped, 0);
15411 + bindex = au_dbtop(dentry);
15413 + h_dentry = au_h_dptr(dentry, bindex);
15414 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15415 + if (unlikely(err))
15417 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15419 + h_dentry = h_file->f_path.dentry;
15420 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15421 + if (unlikely(err))
15423 + get_file(h_file);
15425 + if (IS_ERR(h_file))
15426 + err = PTR_ERR(h_file);
15428 + if ((flags & __O_TMPFILE)
15429 + && !(flags & O_EXCL)) {
15430 + h_inode = file_inode(h_file);
15431 + spin_lock(&h_inode->i_lock);
15432 + h_inode->i_state |= I_LINKABLE;
15433 + spin_unlock(&h_inode->i_lock);
15435 + au_set_fbtop(file, bindex);
15436 + au_set_h_fptr(file, bindex, h_file);
15437 + au_update_figen(file);
15438 + /* todo: necessary? */
15439 + /* file->f_ra = h_file->f_ra; */
15446 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15447 + struct file *file)
15450 + struct super_block *sb;
15451 + struct au_do_open_args args = {
15452 + .open = au_do_open_nondir
15455 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15456 + file, vfsub_file_flags(file), file->f_mode);
15458 + sb = file->f_path.dentry->d_sb;
15459 + si_read_lock(sb, AuLock_FLUSH);
15460 + err = au_do_open(file, &args);
15461 + si_read_unlock(sb);
15465 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15467 + struct au_finfo *finfo;
15468 + aufs_bindex_t bindex;
15470 + finfo = au_fi(file);
15471 + au_hbl_del(&finfo->fi_hlist,
15472 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15473 + bindex = finfo->fi_btop;
15475 + au_set_h_fptr(file, bindex, NULL);
15477 + au_finfo_fin(file);
15481 +/* ---------------------------------------------------------------------- */
15483 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15486 + struct file *h_file;
15489 + h_file = au_hf_top(file);
15491 + err = vfsub_flush(h_file, id);
15495 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15497 + return au_do_flush(file, id, au_do_flush_nondir);
15500 +/* ---------------------------------------------------------------------- */
15502 + * read and write functions acquire [fdi]_rwsem once, but release before
15503 + * mmap_sem. This is because to stop a race condition between mmap(2).
15504 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
15505 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15506 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15509 +/* Callers should call au_read_post() or fput() in the end */
15510 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15512 + struct file *h_file;
15515 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15517 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15518 + h_file = au_hf_top(file);
15519 + get_file(h_file);
15521 + fi_read_unlock(file);
15523 + h_file = ERR_PTR(err);
15528 +static void au_read_post(struct inode *inode, struct file *h_file)
15530 + /* update without lock, I don't think it a problem */
15531 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15535 +struct au_write_pre {
15537 + unsigned int lsc;
15541 + aufs_bindex_t btop;
15545 + * return with iinfo is write-locked
15546 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15549 +static struct file *au_write_pre(struct file *file, int do_ready,
15550 + struct au_write_pre *wpre)
15552 + struct file *h_file;
15553 + struct dentry *dentry;
15555 + unsigned int lsc;
15556 + struct au_pin pin;
15561 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15562 + h_file = ERR_PTR(err);
15563 + if (unlikely(err))
15566 + dentry = file->f_path.dentry;
15568 + err = au_ready_to_write(file, -1, &pin);
15569 + if (unlikely(err)) {
15570 + h_file = ERR_PTR(err);
15571 + di_write_unlock(dentry);
15576 + di_downgrade_lock(dentry, /*flags*/0);
15578 + wpre->btop = au_fbtop(file);
15579 + h_file = au_hf_top(file);
15580 + get_file(h_file);
15582 + wpre->blks = file_inode(h_file)->i_blocks;
15585 + di_read_unlock(dentry, /*flags*/0);
15588 + fi_write_unlock(file);
15593 +static void au_write_post(struct inode *inode, struct file *h_file,
15594 + struct au_write_pre *wpre, ssize_t written)
15596 + struct inode *h_inode;
15598 + au_cpup_attr_timesizes(inode);
15599 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15600 + h_inode = file_inode(h_file);
15601 + inode->i_mode = h_inode->i_mode;
15602 + ii_write_unlock(inode);
15603 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15605 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15606 + /*force*/h_inode->i_blocks > wpre->blks);
15610 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15614 + struct inode *inode;
15615 + struct file *h_file;
15616 + struct super_block *sb;
15618 + inode = file_inode(file);
15619 + sb = inode->i_sb;
15620 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15622 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15623 + err = PTR_ERR(h_file);
15624 + if (IS_ERR(h_file))
15627 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15628 + err = vfsub_read_u(h_file, buf, count, ppos);
15629 + /* todo: necessary? */
15630 + /* file->f_ra = h_file->f_ra; */
15631 + au_read_post(inode, h_file);
15634 + si_read_unlock(sb);
15639 + * todo: very ugly
15640 + * it locks both of i_mutex and si_rwsem for read in safe.
15641 + * if the plink maintenance mode continues forever (that is the problem),
15642 + * may loop forever.
15644 +static void au_mtx_and_read_lock(struct inode *inode)
15647 + struct super_block *sb = inode->i_sb;
15650 + inode_lock(inode);
15651 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15654 + inode_unlock(inode);
15655 + si_read_lock(sb, AuLock_NOPLMW);
15656 + si_read_unlock(sb);
15660 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15661 + size_t count, loff_t *ppos)
15664 + struct au_write_pre wpre;
15665 + struct inode *inode;
15666 + struct file *h_file;
15667 + char __user *buf = (char __user *)ubuf;
15669 + inode = file_inode(file);
15670 + au_mtx_and_read_lock(inode);
15673 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15674 + err = PTR_ERR(h_file);
15675 + if (IS_ERR(h_file))
15678 + err = vfsub_write_u(h_file, buf, count, ppos);
15679 + au_write_post(inode, h_file, &wpre, err);
15682 + si_read_unlock(inode->i_sb);
15683 + inode_unlock(inode);
15687 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15688 + struct iov_iter *iov_iter)
15691 + struct file *file;
15692 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15694 + err = security_file_permission(h_file, rw);
15695 + if (unlikely(err))
15700 + if (rw == MAY_READ)
15701 + iter = h_file->f_op->read_iter;
15702 + else if (rw == MAY_WRITE)
15703 + iter = h_file->f_op->write_iter;
15705 + file = kio->ki_filp;
15706 + kio->ki_filp = h_file;
15709 + err = iter(kio, iov_iter);
15712 + /* currently there is no such fs */
15714 + kio->ki_filp = file;
15720 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15723 + struct file *file, *h_file;
15724 + struct inode *inode;
15725 + struct super_block *sb;
15727 + file = kio->ki_filp;
15728 + inode = file_inode(file);
15729 + sb = inode->i_sb;
15730 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15732 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15733 + err = PTR_ERR(h_file);
15734 + if (IS_ERR(h_file))
15737 + if (au_test_loopback_kthread()) {
15738 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15739 + if (file->f_mapping != h_file->f_mapping) {
15740 + file->f_mapping = h_file->f_mapping;
15741 + smp_mb(); /* unnecessary? */
15744 + fi_read_unlock(file);
15746 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15747 + /* todo: necessary? */
15748 + /* file->f_ra = h_file->f_ra; */
15749 + au_read_post(inode, h_file);
15752 + si_read_unlock(sb);
15756 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15759 + struct au_write_pre wpre;
15760 + struct inode *inode;
15761 + struct file *file, *h_file;
15763 + file = kio->ki_filp;
15764 + inode = file_inode(file);
15765 + au_mtx_and_read_lock(inode);
15768 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15769 + err = PTR_ERR(h_file);
15770 + if (IS_ERR(h_file))
15773 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15774 + au_write_post(inode, h_file, &wpre, err);
15777 + si_read_unlock(inode->i_sb);
15778 + inode_unlock(inode);
15782 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15783 + struct pipe_inode_info *pipe, size_t len,
15784 + unsigned int flags)
15787 + struct file *h_file;
15788 + struct inode *inode;
15789 + struct super_block *sb;
15791 + inode = file_inode(file);
15792 + sb = inode->i_sb;
15793 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15795 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15796 + err = PTR_ERR(h_file);
15797 + if (IS_ERR(h_file))
15800 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15801 + /* todo: necessasry? */
15802 + /* file->f_ra = h_file->f_ra; */
15803 + au_read_post(inode, h_file);
15806 + si_read_unlock(sb);
15811 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15812 + size_t len, unsigned int flags)
15815 + struct au_write_pre wpre;
15816 + struct inode *inode;
15817 + struct file *h_file;
15819 + inode = file_inode(file);
15820 + au_mtx_and_read_lock(inode);
15823 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15824 + err = PTR_ERR(h_file);
15825 + if (IS_ERR(h_file))
15828 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15829 + au_write_post(inode, h_file, &wpre, err);
15832 + si_read_unlock(inode->i_sb);
15833 + inode_unlock(inode);
15837 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15841 + struct au_write_pre wpre;
15842 + struct inode *inode;
15843 + struct file *h_file;
15845 + inode = file_inode(file);
15846 + au_mtx_and_read_lock(inode);
15849 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15850 + err = PTR_ERR(h_file);
15851 + if (IS_ERR(h_file))
15855 + err = vfs_fallocate(h_file, mode, offset, len);
15857 + au_write_post(inode, h_file, &wpre, /*written*/1);
15860 + si_read_unlock(inode->i_sb);
15861 + inode_unlock(inode);
15865 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15866 + struct file *dst, loff_t dst_pos,
15867 + size_t len, unsigned int flags)
15870 + struct au_write_pre wpre;
15871 + enum { SRC, DST };
15873 + struct inode *inode;
15874 + struct file *h_file;
15875 + struct super_block *h_sb;
15877 +#define a_src a[SRC]
15878 +#define a_dst a[DST]
15881 + a_src.inode = file_inode(src);
15882 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15884 + a_dst.inode = file_inode(dst);
15885 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15888 + au_mtx_and_read_lock(a_dst.inode);
15890 + * in order to match the order in di_write_lock2_{child,parent}(),
15891 + * use f_path.dentry for this comparision.
15893 + if (src->f_path.dentry < dst->f_path.dentry) {
15894 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15895 + err = PTR_ERR(a_src.h_file);
15896 + if (IS_ERR(a_src.h_file))
15899 + wpre.lsc = AuLsc_FI_2;
15900 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15901 + err = PTR_ERR(a_dst.h_file);
15902 + if (IS_ERR(a_dst.h_file)) {
15903 + au_read_post(a_src.inode, a_src.h_file);
15907 + wpre.lsc = AuLsc_FI_1;
15908 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15909 + err = PTR_ERR(a_dst.h_file);
15910 + if (IS_ERR(a_dst.h_file))
15913 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15914 + err = PTR_ERR(a_src.h_file);
15915 + if (IS_ERR(a_src.h_file)) {
15916 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15923 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15924 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15925 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15931 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15932 + dst_pos, len, flags);
15935 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15936 + fi_read_unlock(src);
15937 + au_read_post(a_src.inode, a_src.h_file);
15939 + si_read_unlock(a_dst.inode->i_sb);
15940 + inode_unlock(a_dst.inode);
15947 +/* ---------------------------------------------------------------------- */
15950 + * The locking order around current->mmap_sem.
15951 + * - in most and regular cases
15952 + * file I/O syscall -- aufs_read() or something
15953 + * -- si_rwsem for read -- mmap_sem
15954 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15956 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15957 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
15958 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
15959 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15960 + * It means that when aufs acquires si_rwsem for write, the process should never
15961 + * acquire mmap_sem.
15963 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15964 + * problem either since any directory is not able to be mmap-ed.
15965 + * The similar scenario is applied to aufs_readlink() too.
15968 +#if 0 /* stop calling security_file_mmap() */
15969 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15970 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15972 +static unsigned long au_arch_prot_conv(unsigned long flags)
15974 + /* currently ppc64 only */
15975 +#ifdef CONFIG_PPC64
15976 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15977 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15978 + return AuConv_VM_PROT(flags, SAO);
15980 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15985 +static unsigned long au_prot_conv(unsigned long flags)
15987 + return AuConv_VM_PROT(flags, READ)
15988 + | AuConv_VM_PROT(flags, WRITE)
15989 + | AuConv_VM_PROT(flags, EXEC)
15990 + | au_arch_prot_conv(flags);
15993 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15994 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15996 +static unsigned long au_flag_conv(unsigned long flags)
15998 + return AuConv_VM_MAP(flags, GROWSDOWN)
15999 + | AuConv_VM_MAP(flags, DENYWRITE)
16000 + | AuConv_VM_MAP(flags, LOCKED);
16004 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16007 + const unsigned char wlock
16008 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16009 + struct super_block *sb;
16010 + struct file *h_file;
16011 + struct inode *inode;
16013 + AuDbgVmRegion(file, vma);
16015 + inode = file_inode(file);
16016 + sb = inode->i_sb;
16018 + si_read_lock(sb, AuLock_NOPLMW);
16020 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16022 + err = PTR_ERR(h_file);
16023 + if (IS_ERR(h_file))
16027 + au_set_mmapped(file);
16028 + au_vm_file_reset(vma, h_file);
16030 + * we cannot call security_mmap_file() here since it may acquire
16031 + * mmap_sem or i_mutex.
16033 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16034 + * au_flag_conv(vma->vm_flags));
16037 + err = h_file->f_op->mmap(h_file, vma);
16039 + au_vm_prfile_set(vma, file);
16040 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16041 + goto out_fput; /* success */
16043 + au_unset_mmapped(file);
16044 + au_vm_file_reset(vma, file);
16048 + ii_write_unlock(inode);
16053 + si_read_unlock(sb);
16059 +/* ---------------------------------------------------------------------- */
16061 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16065 + struct au_write_pre wpre;
16066 + struct inode *inode;
16067 + struct file *h_file;
16069 + err = 0; /* -EBADF; */ /* posix? */
16070 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16073 + inode = file_inode(file);
16074 + au_mtx_and_read_lock(inode);
16077 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16078 + err = PTR_ERR(h_file);
16079 + if (IS_ERR(h_file))
16082 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16083 + au_write_post(inode, h_file, &wpre, /*written*/0);
16086 + si_read_unlock(inode->i_sb);
16087 + inode_unlock(inode);
16092 +static int aufs_fasync(int fd, struct file *file, int flag)
16095 + struct file *h_file;
16096 + struct super_block *sb;
16098 + sb = file->f_path.dentry->d_sb;
16099 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16101 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16102 + err = PTR_ERR(h_file);
16103 + if (IS_ERR(h_file))
16106 + if (h_file->f_op->fasync)
16107 + err = h_file->f_op->fasync(fd, h_file, flag);
16108 + fput(h_file); /* instead of au_read_post() */
16111 + si_read_unlock(sb);
16115 +static int aufs_setfl(struct file *file, unsigned long arg)
16118 + struct file *h_file;
16119 + struct super_block *sb;
16121 + sb = file->f_path.dentry->d_sb;
16122 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16124 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16125 + err = PTR_ERR(h_file);
16126 + if (IS_ERR(h_file))
16129 + /* stop calling h_file->fasync */
16130 + arg |= vfsub_file_flags(file) & FASYNC;
16131 + err = setfl(/*unused fd*/-1, h_file, arg);
16132 + fput(h_file); /* instead of au_read_post() */
16135 + si_read_unlock(sb);
16139 +/* ---------------------------------------------------------------------- */
16141 +/* no one supports this operation, currently */
16143 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16144 + size_t len, loff_t *pos, int more)
16149 +/* ---------------------------------------------------------------------- */
16151 +const struct file_operations aufs_file_fop = {
16152 + .owner = THIS_MODULE,
16154 + .llseek = default_llseek,
16156 + .read = aufs_read,
16157 + .write = aufs_write,
16158 + .read_iter = aufs_read_iter,
16159 + .write_iter = aufs_write_iter,
16161 +#ifdef CONFIG_AUFS_POLL
16162 + .poll = aufs_poll,
16164 + .unlocked_ioctl = aufs_ioctl_nondir,
16165 +#ifdef CONFIG_COMPAT
16166 + .compat_ioctl = aufs_compat_ioctl_nondir,
16168 + .mmap = aufs_mmap,
16169 + .open = aufs_open_nondir,
16170 + .flush = aufs_flush_nondir,
16171 + .release = aufs_release_nondir,
16172 + .fsync = aufs_fsync_nondir,
16173 + .fasync = aufs_fasync,
16174 + /* .sendpage = aufs_sendpage, */
16175 + .setfl = aufs_setfl,
16176 + .splice_write = aufs_splice_write,
16177 + .splice_read = aufs_splice_read,
16179 + .aio_splice_write = aufs_aio_splice_write,
16180 + .aio_splice_read = aufs_aio_splice_read,
16182 + .fallocate = aufs_fallocate,
16183 + .copy_file_range = aufs_copy_file_range
16185 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16186 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16187 +++ linux/fs/aufs/fstype.h 2018-04-15 08:49:13.397817296 +0200
16190 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16192 + * This program, aufs is free software; you can redistribute it and/or modify
16193 + * it under the terms of the GNU General Public License as published by
16194 + * the Free Software Foundation; either version 2 of the License, or
16195 + * (at your option) any later version.
16197 + * This program is distributed in the hope that it will be useful,
16198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16200 + * GNU General Public License for more details.
16202 + * You should have received a copy of the GNU General Public License
16203 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16207 + * judging filesystem type
16210 +#ifndef __AUFS_FSTYPE_H__
16211 +#define __AUFS_FSTYPE_H__
16215 +#include <linux/fs.h>
16216 +#include <linux/magic.h>
16217 +#include <linux/nfs_fs.h>
16218 +#include <linux/romfs_fs.h>
16220 +static inline int au_test_aufs(struct super_block *sb)
16222 + return sb->s_magic == AUFS_SUPER_MAGIC;
16225 +static inline const char *au_sbtype(struct super_block *sb)
16227 + return sb->s_type->name;
16230 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16232 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16233 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16239 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16241 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16242 + return sb->s_magic == ROMFS_MAGIC;
16248 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16250 +#if IS_ENABLED(CONFIG_CRAMFS)
16251 + return sb->s_magic == CRAMFS_MAGIC;
16256 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16258 +#if IS_ENABLED(CONFIG_NFS_FS)
16259 + return sb->s_magic == NFS_SUPER_MAGIC;
16265 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16267 +#if IS_ENABLED(CONFIG_FUSE_FS)
16268 + return sb->s_magic == FUSE_SUPER_MAGIC;
16274 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16276 +#if IS_ENABLED(CONFIG_XFS_FS)
16277 + return sb->s_magic == XFS_SB_MAGIC;
16283 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16285 +#ifdef CONFIG_TMPFS
16286 + return sb->s_magic == TMPFS_MAGIC;
16292 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16294 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16295 + return !strcmp(au_sbtype(sb), "ecryptfs");
16301 +static inline int au_test_ramfs(struct super_block *sb)
16303 + return sb->s_magic == RAMFS_MAGIC;
16306 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16308 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16309 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16315 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16317 +#ifdef CONFIG_PROC_FS
16318 + return sb->s_magic == PROC_SUPER_MAGIC;
16324 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16326 +#ifdef CONFIG_SYSFS
16327 + return sb->s_magic == SYSFS_MAGIC;
16333 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16335 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16336 + return sb->s_magic == CONFIGFS_MAGIC;
16342 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16344 +#if IS_ENABLED(CONFIG_MINIX_FS)
16345 + return sb->s_magic == MINIX3_SUPER_MAGIC
16346 + || sb->s_magic == MINIX2_SUPER_MAGIC
16347 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16348 + || sb->s_magic == MINIX_SUPER_MAGIC
16349 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16355 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16357 +#if IS_ENABLED(CONFIG_FAT_FS)
16358 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16364 +static inline int au_test_msdos(struct super_block *sb)
16366 + return au_test_fat(sb);
16369 +static inline int au_test_vfat(struct super_block *sb)
16371 + return au_test_fat(sb);
16374 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16376 +#ifdef CONFIG_SECURITYFS
16377 + return sb->s_magic == SECURITYFS_MAGIC;
16383 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16385 +#if IS_ENABLED(CONFIG_SQUASHFS)
16386 + return sb->s_magic == SQUASHFS_MAGIC;
16392 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16394 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16395 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16401 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16403 +#if IS_ENABLED(CONFIG_XENFS)
16404 + return sb->s_magic == XENFS_SUPER_MAGIC;
16410 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16412 +#ifdef CONFIG_DEBUG_FS
16413 + return sb->s_magic == DEBUGFS_MAGIC;
16419 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16421 +#if IS_ENABLED(CONFIG_NILFS)
16422 + return sb->s_magic == NILFS_SUPER_MAGIC;
16428 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16430 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16431 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16437 +/* ---------------------------------------------------------------------- */
16439 + * they can't be an aufs branch.
16441 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16444 +#ifndef CONFIG_AUFS_BR_RAMFS
16445 + au_test_ramfs(sb) ||
16447 + au_test_procfs(sb)
16448 + || au_test_sysfs(sb)
16449 + || au_test_configfs(sb)
16450 + || au_test_debugfs(sb)
16451 + || au_test_securityfs(sb)
16452 + || au_test_xenfs(sb)
16453 + || au_test_ecryptfs(sb)
16454 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16455 + || au_test_aufs(sb); /* will be supported in next version */
16458 +static inline int au_test_fs_remote(struct super_block *sb)
16460 + return !au_test_tmpfs(sb)
16461 +#ifdef CONFIG_AUFS_BR_RAMFS
16462 + && !au_test_ramfs(sb)
16464 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16467 +/* ---------------------------------------------------------------------- */
16470 + * Note: these functions (below) are created after reading ->getattr() in all
16471 + * filesystems under linux/fs. it means we have to do so in every update...
16475 + * some filesystems require getattr to refresh the inode attributes before
16477 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16478 + * and leave the work for d_revalidate()
16480 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16482 + return au_test_nfs(sb)
16483 + || au_test_fuse(sb)
16484 + /* || au_test_btrfs(sb) */ /* untested */
16489 + * filesystems which don't maintain i_size or i_blocks.
16491 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16493 + return au_test_xfs(sb)
16494 + || au_test_btrfs(sb)
16495 + || au_test_ubifs(sb)
16496 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16497 + /* || au_test_minix(sb) */ /* untested */
16502 + * filesystems which don't store the correct value in some of their inode
16505 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16507 + return au_test_fs_bad_iattr_size(sb)
16508 + || au_test_fat(sb)
16509 + || au_test_msdos(sb)
16510 + || au_test_vfat(sb);
16513 +/* they don't check i_nlink in link(2) */
16514 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16516 + return au_test_tmpfs(sb)
16517 +#ifdef CONFIG_AUFS_BR_RAMFS
16518 + || au_test_ramfs(sb)
16520 + || au_test_ubifs(sb)
16521 + || au_test_hfsplus(sb);
16525 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16527 +static inline int au_test_fs_notime(struct super_block *sb)
16529 + return au_test_nfs(sb)
16530 + || au_test_fuse(sb)
16531 + || au_test_ubifs(sb)
16535 +/* temporary support for i#1 in cramfs */
16536 +static inline int au_test_fs_unique_ino(struct inode *inode)
16538 + if (au_test_cramfs(inode->i_sb))
16539 + return inode->i_ino != 1;
16543 +/* ---------------------------------------------------------------------- */
16546 + * the filesystem where the xino files placed must support i/o after unlink and
16547 + * maintain i_size and i_blocks.
16549 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16551 + return au_test_fs_remote(sb)
16552 + || au_test_fs_bad_iattr_size(sb)
16553 + /* don't want unnecessary work for xino */
16554 + || au_test_aufs(sb)
16555 + || au_test_ecryptfs(sb)
16556 + || au_test_nilfs(sb);
16559 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16561 + return au_test_tmpfs(sb)
16562 + || au_test_ramfs(sb);
16566 + * test if the @sb is real-readonly.
16568 +static inline int au_test_fs_rr(struct super_block *sb)
16570 + return au_test_squashfs(sb)
16571 + || au_test_iso9660(sb)
16572 + || au_test_cramfs(sb)
16573 + || au_test_romfs(sb);
16577 + * test if the @inode is nfs with 'noacl' option
16578 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
16580 +static inline int au_test_nfs_noacl(struct inode *inode)
16582 + return au_test_nfs(inode->i_sb)
16583 + /* && IS_POSIXACL(inode) */
16584 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16587 +#endif /* __KERNEL__ */
16588 +#endif /* __AUFS_FSTYPE_H__ */
16589 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16590 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16591 +++ linux/fs/aufs/hbl.h 2018-04-15 08:49:13.401150731 +0200
16594 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16596 + * This program, aufs is free software; you can redistribute it and/or modify
16597 + * it under the terms of the GNU General Public License as published by
16598 + * the Free Software Foundation; either version 2 of the License, or
16599 + * (at your option) any later version.
16601 + * This program is distributed in the hope that it will be useful,
16602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16604 + * GNU General Public License for more details.
16606 + * You should have received a copy of the GNU General Public License
16607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16611 + * helpers for hlist_bl.h
16614 +#ifndef __AUFS_HBL_H__
16615 +#define __AUFS_HBL_H__
16619 +#include <linux/list_bl.h>
16621 +static inline void au_hbl_add(struct hlist_bl_node *node,
16622 + struct hlist_bl_head *hbl)
16624 + hlist_bl_lock(hbl);
16625 + hlist_bl_add_head(node, hbl);
16626 + hlist_bl_unlock(hbl);
16629 +static inline void au_hbl_del(struct hlist_bl_node *node,
16630 + struct hlist_bl_head *hbl)
16632 + hlist_bl_lock(hbl);
16633 + hlist_bl_del(node);
16634 + hlist_bl_unlock(hbl);
16637 +#define au_hbl_for_each(pos, head) \
16638 + for (pos = hlist_bl_first(head); \
16642 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16644 + unsigned long cnt;
16645 + struct hlist_bl_node *pos;
16648 + hlist_bl_lock(hbl);
16649 + au_hbl_for_each(pos, hbl)
16651 + hlist_bl_unlock(hbl);
16655 +#endif /* __KERNEL__ */
16656 +#endif /* __AUFS_HBL_H__ */
16657 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16658 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16659 +++ linux/fs/aufs/hfsnotify.c 2018-04-15 08:49:13.401150731 +0200
16662 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16664 + * This program, aufs is free software; you can redistribute it and/or modify
16665 + * it under the terms of the GNU General Public License as published by
16666 + * the Free Software Foundation; either version 2 of the License, or
16667 + * (at your option) any later version.
16669 + * This program is distributed in the hope that it will be useful,
16670 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16671 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16672 + * GNU General Public License for more details.
16674 + * You should have received a copy of the GNU General Public License
16675 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16679 + * fsnotify for the lower directories
16684 +/* FS_IN_IGNORED is unnecessary */
16685 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16686 + | FS_CREATE | FS_EVENT_ON_CHILD);
16687 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16688 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16690 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16692 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16694 + /* AuDbg("here\n"); */
16695 + au_cache_free_hnotify(hn);
16696 + smp_mb__before_atomic(); /* for atomic64_dec */
16697 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16698 + wake_up(&au_hfsn_wq);
16701 +static int au_hfsn_alloc(struct au_hinode *hinode)
16704 + struct au_hnotify *hn;
16705 + struct super_block *sb;
16706 + struct au_branch *br;
16707 + struct fsnotify_mark *mark;
16708 + aufs_bindex_t bindex;
16710 + hn = hinode->hi_notify;
16711 + sb = hn->hn_aufs_inode->i_sb;
16712 + bindex = au_br_index(sb, hinode->hi_id);
16713 + br = au_sbr(sb, bindex);
16714 + AuDebugOn(!br->br_hfsn);
16716 + mark = &hn->hn_mark;
16717 + fsnotify_init_mark(mark, au_hfsn_free_mark);
16718 + mark->mask = AuHfsnMask;
16720 + * by udba rename or rmdir, aufs assign a new inode to the known
16721 + * h_inode, so specify 1 to allow dups.
16724 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
16725 + /*mnt*/NULL, /*allow_dups*/1);
16731 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16733 + struct fsnotify_mark *mark;
16734 + unsigned long long ull;
16735 + struct fsnotify_group *group;
16737 + ull = atomic64_inc_return(&au_hfsn_ifree);
16740 + mark = &hn->hn_mark;
16741 + spin_lock(&mark->lock);
16742 + group = mark->group;
16743 + fsnotify_get_group(group);
16744 + spin_unlock(&mark->lock);
16746 + fsnotify_destroy_mark(mark, group);
16747 + fsnotify_put_mark(mark);
16748 + fsnotify_put_group(group);
16751 + /* free hn by myself */
16755 +/* ---------------------------------------------------------------------- */
16757 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16759 + struct fsnotify_mark *mark;
16761 + mark = &hinode->hi_notify->hn_mark;
16762 + spin_lock(&mark->lock);
16764 + AuDebugOn(mark->mask & AuHfsnMask);
16765 + mark->mask |= AuHfsnMask;
16767 + AuDebugOn(!(mark->mask & AuHfsnMask));
16768 + mark->mask &= ~AuHfsnMask;
16770 + spin_unlock(&mark->lock);
16771 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16774 +/* ---------------------------------------------------------------------- */
16776 +/* #define AuDbgHnotify */
16777 +#ifdef AuDbgHnotify
16778 +static char *au_hfsn_name(u32 mask)
16780 +#ifdef CONFIG_AUFS_DEBUG
16781 +#define test_ret(flag) \
16783 + if (mask & flag) \
16786 + test_ret(FS_ACCESS);
16787 + test_ret(FS_MODIFY);
16788 + test_ret(FS_ATTRIB);
16789 + test_ret(FS_CLOSE_WRITE);
16790 + test_ret(FS_CLOSE_NOWRITE);
16791 + test_ret(FS_OPEN);
16792 + test_ret(FS_MOVED_FROM);
16793 + test_ret(FS_MOVED_TO);
16794 + test_ret(FS_CREATE);
16795 + test_ret(FS_DELETE);
16796 + test_ret(FS_DELETE_SELF);
16797 + test_ret(FS_MOVE_SELF);
16798 + test_ret(FS_UNMOUNT);
16799 + test_ret(FS_Q_OVERFLOW);
16800 + test_ret(FS_IN_IGNORED);
16801 + test_ret(FS_ISDIR);
16802 + test_ret(FS_IN_ONESHOT);
16803 + test_ret(FS_EVENT_ON_CHILD);
16812 +/* ---------------------------------------------------------------------- */
16814 +static void au_hfsn_free_group(struct fsnotify_group *group)
16816 + struct au_br_hfsnotify *hfsn = group->private;
16818 + /* AuDbg("here\n"); */
16822 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16823 + struct inode *inode,
16824 + struct fsnotify_mark *inode_mark,
16825 + struct fsnotify_mark *vfsmount_mark,
16826 + u32 mask, void *data, int data_type,
16827 + const unsigned char *file_name, u32 cookie)
16830 + struct au_hnotify *hnotify;
16831 + struct inode *h_dir, *h_inode;
16832 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
16834 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16837 + /* if FS_UNMOUNT happens, there must be another bug */
16838 + AuDebugOn(mask & FS_UNMOUNT);
16839 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16844 +#ifdef AuDbgHnotify
16846 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16847 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16848 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16849 + h_dir->i_ino, mask, au_hfsn_name(mask),
16850 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16851 + /* WARN_ON(1); */
16856 + AuDebugOn(!inode_mark);
16857 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16858 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
16864 +static struct fsnotify_ops au_hfsn_ops = {
16865 + .handle_event = au_hfsn_handle_event,
16866 + .free_group_priv = au_hfsn_free_group
16869 +/* ---------------------------------------------------------------------- */
16871 +static void au_hfsn_fin_br(struct au_branch *br)
16873 + struct au_br_hfsnotify *hfsn;
16875 + hfsn = br->br_hfsn;
16878 + fsnotify_put_group(hfsn->hfsn_group);
16883 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16886 + struct fsnotify_group *group;
16887 + struct au_br_hfsnotify *hfsn;
16890 + br->br_hfsn = NULL;
16891 + if (!au_br_hnotifyable(perm))
16895 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16896 + if (unlikely(!hfsn))
16900 + group = fsnotify_alloc_group(&au_hfsn_ops);
16901 + if (IS_ERR(group)) {
16902 + err = PTR_ERR(group);
16903 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16907 + group->private = hfsn;
16908 + hfsn->hfsn_group = group;
16909 + br->br_hfsn = hfsn;
16910 + goto out; /* success */
16918 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16923 + if (!br->br_hfsn)
16924 + err = au_hfsn_init_br(br, perm);
16929 +/* ---------------------------------------------------------------------- */
16931 +static void au_hfsn_fin(void)
16933 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16934 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16937 +const struct au_hnotify_op au_hnotify_op = {
16938 + .ctl = au_hfsn_ctl,
16939 + .alloc = au_hfsn_alloc,
16940 + .free = au_hfsn_free,
16942 + .fin = au_hfsn_fin,
16944 + .reset_br = au_hfsn_reset_br,
16945 + .fin_br = au_hfsn_fin_br,
16946 + .init_br = au_hfsn_init_br
16948 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16949 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16950 +++ linux/fs/aufs/hfsplus.c 2018-04-15 08:49:13.401150731 +0200
16953 + * Copyright (C) 2010-2018 Junjiro R. Okajima
16955 + * This program, aufs is free software; you can redistribute it and/or modify
16956 + * it under the terms of the GNU General Public License as published by
16957 + * the Free Software Foundation; either version 2 of the License, or
16958 + * (at your option) any later version.
16960 + * This program is distributed in the hope that it will be useful,
16961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16963 + * GNU General Public License for more details.
16965 + * You should have received a copy of the GNU General Public License
16966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16970 + * special support for filesystems which aqucires an inode mutex
16971 + * at final closing a file, eg, hfsplus.
16973 + * This trick is very simple and stupid, just to open the file before really
16974 + * neceeary open to tell hfsplus that this is not the final closing.
16975 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16976 + * and au_h_open_post() after releasing it.
16981 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16984 + struct file *h_file;
16985 + struct dentry *h_dentry;
16987 + h_dentry = au_h_dptr(dentry, bindex);
16988 + AuDebugOn(!h_dentry);
16989 + AuDebugOn(d_is_negative(h_dentry));
16992 + if (au_test_hfsplus(h_dentry->d_sb)
16993 + && d_is_reg(h_dentry))
16994 + h_file = au_h_open(dentry, bindex,
16995 + O_RDONLY | O_NOATIME | O_LARGEFILE,
16996 + /*file*/NULL, force_wr);
17000 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17001 + struct file *h_file)
17005 + au_sbr_put(dentry->d_sb, bindex);
17008 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17009 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17010 +++ linux/fs/aufs/hnotify.c 2018-04-15 08:49:13.401150731 +0200
17013 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17015 + * This program, aufs is free software; you can redistribute it and/or modify
17016 + * it under the terms of the GNU General Public License as published by
17017 + * the Free Software Foundation; either version 2 of the License, or
17018 + * (at your option) any later version.
17020 + * This program is distributed in the hope that it will be useful,
17021 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17022 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17023 + * GNU General Public License for more details.
17025 + * You should have received a copy of the GNU General Public License
17026 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17030 + * abstraction to notify the direct changes on lower directories
17035 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17038 + struct au_hnotify *hn;
17041 + hn = au_cache_alloc_hnotify();
17043 + hn->hn_aufs_inode = inode;
17044 + hinode->hi_notify = hn;
17045 + err = au_hnotify_op.alloc(hinode);
17047 + if (unlikely(err)) {
17048 + hinode->hi_notify = NULL;
17049 + au_cache_free_hnotify(hn);
17051 + * The upper dir was removed by udba, but the same named
17052 + * dir left. In this case, aufs assignes a new inode
17053 + * number and set the monitor again.
17054 + * For the lower dir, the old monitnor is still left.
17056 + if (err == -EEXIST)
17065 +void au_hn_free(struct au_hinode *hinode)
17067 + struct au_hnotify *hn;
17069 + hn = hinode->hi_notify;
17071 + hinode->hi_notify = NULL;
17072 + if (au_hnotify_op.free(hinode, hn))
17073 + au_cache_free_hnotify(hn);
17077 +/* ---------------------------------------------------------------------- */
17079 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17081 + if (hinode->hi_notify)
17082 + au_hnotify_op.ctl(hinode, do_set);
17085 +void au_hn_reset(struct inode *inode, unsigned int flags)
17087 + aufs_bindex_t bindex, bbot;
17088 + struct inode *hi;
17089 + struct dentry *iwhdentry;
17091 + bbot = au_ibbot(inode);
17092 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17093 + hi = au_h_iptr(inode, bindex);
17097 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17098 + iwhdentry = au_hi_wh(inode, bindex);
17102 + au_set_h_iptr(inode, bindex, NULL, 0);
17103 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17104 + flags & ~AuHi_XINO);
17107 + /* inode_unlock(hi); */
17111 +/* ---------------------------------------------------------------------- */
17113 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17116 + aufs_bindex_t bindex, bbot, bfound, btop;
17117 + struct inode *h_i;
17120 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17121 + pr_warn("branch root dir was changed\n");
17126 + bbot = au_ibbot(inode);
17127 + btop = au_ibtop(inode);
17128 +#if 0 /* reserved for future use */
17129 + if (bindex == bbot) {
17130 + /* keep this ino in rename case */
17134 + for (bindex = btop; bindex <= bbot; bindex++)
17135 + if (au_h_iptr(inode, bindex) == h_inode) {
17142 + for (bindex = btop; bindex <= bbot; bindex++) {
17143 + h_i = au_h_iptr(inode, bindex);
17147 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17148 + /* ignore this error */
17149 + /* bad action? */
17152 + /* children inode number will be broken */
17159 +static int hn_gen_tree(struct dentry *dentry)
17161 + int err, i, j, ndentry;
17162 + struct au_dcsub_pages dpages;
17163 + struct au_dpage *dpage;
17164 + struct dentry **dentries;
17166 + err = au_dpages_init(&dpages, GFP_NOFS);
17167 + if (unlikely(err))
17169 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17170 + if (unlikely(err))
17173 + for (i = 0; i < dpages.ndpage; i++) {
17174 + dpage = dpages.dpages + i;
17175 + dentries = dpage->dentries;
17176 + ndentry = dpage->ndentry;
17177 + for (j = 0; j < ndentry; j++) {
17178 + struct dentry *d;
17185 + if (d_really_is_positive(d))
17186 + /* todo: reset children xino?
17187 + cached children only? */
17188 + au_iigen_dec(d_inode(d));
17193 + au_dpages_free(&dpages);
17196 + /* discard children */
17197 + dentry_unhash(dentry);
17205 + * return 0 if processed.
17207 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17208 + const unsigned int isdir)
17211 + struct dentry *d;
17212 + struct qstr *dname;
17215 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17216 + pr_warn("branch root dir was changed\n");
17222 + AuDebugOn(!name);
17223 + au_iigen_dec(inode);
17224 + spin_lock(&inode->i_lock);
17225 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17226 + spin_lock(&d->d_lock);
17227 + dname = &d->d_name;
17228 + if (dname->len != nlen
17229 + && memcmp(dname->name, name, nlen)) {
17230 + spin_unlock(&d->d_lock);
17235 + spin_unlock(&d->d_lock);
17238 + spin_unlock(&inode->i_lock);
17240 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17241 + d = d_find_any_alias(inode);
17243 + au_iigen_dec(inode);
17247 + spin_lock(&d->d_lock);
17248 + dname = &d->d_name;
17249 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17250 + spin_unlock(&d->d_lock);
17251 + err = hn_gen_tree(d);
17252 + spin_lock(&d->d_lock);
17254 + spin_unlock(&d->d_lock);
17263 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17267 + if (IS_ROOT(dentry)) {
17268 + pr_warn("branch root dir was changed\n");
17274 + au_digen_dec(dentry);
17275 + if (d_really_is_positive(dentry))
17276 + au_iigen_dec(d_inode(dentry));
17278 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17279 + if (d_really_is_positive(dentry))
17280 + err = hn_gen_tree(dentry);
17287 +/* ---------------------------------------------------------------------- */
17289 +/* hnotify job flags */
17290 +#define AuHnJob_XINO0 1
17291 +#define AuHnJob_GEN (1 << 1)
17292 +#define AuHnJob_DIRENT (1 << 2)
17293 +#define AuHnJob_ISDIR (1 << 3)
17294 +#define AuHnJob_TRYXINO0 (1 << 4)
17295 +#define AuHnJob_MNTPNT (1 << 5)
17296 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17297 +#define au_fset_hnjob(flags, name) \
17298 + do { (flags) |= AuHnJob_##name; } while (0)
17299 +#define au_fclr_hnjob(flags, name) \
17300 + do { (flags) &= ~AuHnJob_##name; } while (0)
17308 +struct au_hnotify_args {
17309 + struct inode *h_dir, *dir, *h_child_inode;
17311 + unsigned int flags[AuHnLast];
17312 + unsigned int h_child_nlen;
17313 + char h_child_name[];
17316 +struct hn_job_args {
17317 + unsigned int flags;
17318 + struct inode *inode, *h_inode, *dir, *h_dir;
17319 + struct dentry *dentry;
17324 +static int hn_job(struct hn_job_args *a)
17326 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17330 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17331 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17333 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17336 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17337 + if (!a->h_inode->i_nlink
17338 + && !(a->h_inode->i_state & I_LINKABLE))
17339 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17340 + inode_unlock_shared(a->h_inode);
17343 + /* make the generation obsolete */
17344 + if (au_ftest_hnjob(a->flags, GEN)) {
17347 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17349 + if (e && a->dentry)
17350 + hn_gen_by_name(a->dentry, isdir);
17351 + /* ignore this error */
17354 + /* make dir entries obsolete */
17355 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17356 + struct au_vdir *vdir;
17358 + vdir = au_ivdir(a->inode);
17360 + vdir->vd_jiffy = 0;
17361 + /* IMustLock(a->inode); */
17362 + /* a->inode->i_version++; */
17365 + /* can do nothing but warn */
17366 + if (au_ftest_hnjob(a->flags, MNTPNT)
17368 + && d_mountpoint(a->dentry))
17369 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17374 +/* ---------------------------------------------------------------------- */
17376 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17377 + struct inode *dir)
17379 + struct dentry *dentry, *d, *parent;
17380 + struct qstr *dname;
17382 + parent = d_find_any_alias(dir);
17387 + spin_lock(&parent->d_lock);
17388 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17389 + /* AuDbg("%pd\n", d); */
17390 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17391 + dname = &d->d_name;
17392 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17393 + goto cont_unlock;
17397 + goto cont_unlock;
17398 + if (au_dcount(d) > 0) {
17399 + dentry = dget_dlock(d);
17400 + spin_unlock(&d->d_lock);
17405 + spin_unlock(&d->d_lock);
17407 + spin_unlock(&parent->d_lock);
17411 + di_write_lock_child(dentry);
17416 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17417 + aufs_bindex_t bindex, ino_t h_ino)
17419 + struct inode *inode;
17424 + err = au_xino_read(sb, bindex, h_ino, &ino);
17426 + inode = ilookup(sb, ino);
17430 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17431 + pr_warn("wrong root branch\n");
17437 + ii_write_lock_child(inode);
17443 +static void au_hn_bh(void *_args)
17445 + struct au_hnotify_args *a = _args;
17446 + struct super_block *sb;
17447 + aufs_bindex_t bindex, bbot, bfound;
17448 + unsigned char xino, try_iput;
17450 + struct inode *inode;
17452 + struct hn_job_args args;
17453 + struct dentry *dentry;
17454 + struct au_sbinfo *sbinfo;
17456 + AuDebugOn(!_args);
17457 + AuDebugOn(!a->h_dir);
17458 + AuDebugOn(!a->dir);
17459 + AuDebugOn(!a->mask);
17460 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17461 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17462 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17467 + * do not lock a->dir->i_mutex here
17468 + * because of d_revalidate() may cause a deadlock.
17470 + sb = a->dir->i_sb;
17472 + sbinfo = au_sbi(sb);
17473 + AuDebugOn(!sbinfo);
17474 + si_write_lock(sb, AuLock_NOPLMW);
17476 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17477 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17478 + case FS_MOVED_FROM:
17479 + case FS_MOVED_TO:
17480 + AuWarn1("DIRREN with UDBA may not work correctly "
17481 + "for the direct rename(2)\n");
17484 + ii_read_lock_parent(a->dir);
17486 + bbot = au_ibbot(a->dir);
17487 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17488 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17492 + ii_read_unlock(a->dir);
17493 + if (unlikely(bfound < 0))
17496 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17498 + if (a->h_child_inode)
17499 + h_ino = a->h_child_inode->i_ino;
17501 + if (a->h_child_nlen
17502 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17503 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17504 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17507 + if (dentry && d_really_is_positive(dentry))
17508 + inode = d_inode(dentry);
17509 + if (xino && !inode && h_ino
17510 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17511 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17512 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17513 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17517 + args.flags = a->flags[AuHn_CHILD];
17518 + args.dentry = dentry;
17519 + args.inode = inode;
17520 + args.h_inode = a->h_child_inode;
17521 + args.dir = a->dir;
17522 + args.h_dir = a->h_dir;
17523 + args.h_name = a->h_child_name;
17524 + args.h_nlen = a->h_child_nlen;
17525 + err = hn_job(&args);
17527 + if (au_di(dentry))
17528 + di_write_unlock(dentry);
17531 + if (inode && try_iput) {
17532 + ii_write_unlock(inode);
17536 + ii_write_lock_parent(a->dir);
17537 + args.flags = a->flags[AuHn_PARENT];
17538 + args.dentry = NULL;
17539 + args.inode = a->dir;
17540 + args.h_inode = a->h_dir;
17542 + args.h_dir = NULL;
17543 + args.h_name = NULL;
17545 + err = hn_job(&args);
17546 + ii_write_unlock(a->dir);
17549 + iput(a->h_child_inode);
17552 + si_write_unlock(sb);
17553 + au_nwt_done(&sbinfo->si_nowait);
17557 +/* ---------------------------------------------------------------------- */
17559 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17560 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17563 + unsigned int flags[AuHnLast], f;
17564 + unsigned char isdir, isroot, wh;
17565 + struct inode *dir;
17566 + struct au_hnotify_args *args;
17567 + char *p, *h_child_name;
17570 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17571 + dir = igrab(hnotify->hn_aufs_inode);
17575 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17577 + h_child_name = (void *)h_child_qstr->name;
17578 + len = h_child_qstr->len;
17579 + if (h_child_name) {
17580 + if (len > AUFS_WH_PFX_LEN
17581 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17582 + h_child_name += AUFS_WH_PFX_LEN;
17583 + len -= AUFS_WH_PFX_LEN;
17589 + if (h_child_inode)
17590 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17591 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17592 + flags[AuHn_CHILD] = 0;
17594 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17595 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17596 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17597 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17598 + case FS_MOVED_FROM:
17599 + case FS_MOVED_TO:
17600 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17601 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17604 + AuDebugOn(!h_child_name);
17609 + * aufs never be able to get this child inode.
17610 + * revalidation should be in d_revalidate()
17611 + * by checking i_nlink, i_generation or d_unhashed().
17613 + AuDebugOn(!h_child_name);
17614 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17615 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17623 + h_child_inode = NULL;
17626 + /* iput() and kfree() will be called in au_hnotify() */
17627 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17628 + if (unlikely(!args)) {
17629 + AuErr1("no memory\n");
17633 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17634 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17635 + args->mask = mask;
17637 + args->h_dir = igrab(h_dir);
17638 + if (h_child_inode)
17639 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17640 + args->h_child_inode = h_child_inode;
17641 + args->h_child_nlen = len;
17643 + p = (void *)args;
17644 + p += sizeof(*args);
17645 + memcpy(p, h_child_name, len);
17649 + /* NFS fires the event for silly-renamed one from kworker */
17651 + if (!dir->i_nlink
17652 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17654 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17655 + if (unlikely(err)) {
17656 + pr_err("wkq %d\n", err);
17657 + iput(args->h_child_inode);
17658 + iput(args->h_dir);
17667 +/* ---------------------------------------------------------------------- */
17669 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17673 + AuDebugOn(!(udba & AuOptMask_UDBA));
17676 + if (au_hnotify_op.reset_br)
17677 + err = au_hnotify_op.reset_br(udba, br, perm);
17682 +int au_hnotify_init_br(struct au_branch *br, int perm)
17687 + if (au_hnotify_op.init_br)
17688 + err = au_hnotify_op.init_br(br, perm);
17693 +void au_hnotify_fin_br(struct au_branch *br)
17695 + if (au_hnotify_op.fin_br)
17696 + au_hnotify_op.fin_br(br);
17699 +static void au_hn_destroy_cache(void)
17701 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17702 + au_cache[AuCache_HNOTIFY] = NULL;
17705 +int __init au_hnotify_init(void)
17710 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17711 + if (au_cache[AuCache_HNOTIFY]) {
17713 + if (au_hnotify_op.init)
17714 + err = au_hnotify_op.init();
17715 + if (unlikely(err))
17716 + au_hn_destroy_cache();
17722 +void au_hnotify_fin(void)
17724 + if (au_hnotify_op.fin)
17725 + au_hnotify_op.fin();
17727 + /* cf. au_cache_fin() */
17728 + if (au_cache[AuCache_HNOTIFY])
17729 + au_hn_destroy_cache();
17731 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17732 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17733 +++ linux/fs/aufs/iinfo.c 2018-04-15 08:49:13.401150731 +0200
17736 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17738 + * This program, aufs is free software; you can redistribute it and/or modify
17739 + * it under the terms of the GNU General Public License as published by
17740 + * the Free Software Foundation; either version 2 of the License, or
17741 + * (at your option) any later version.
17743 + * This program is distributed in the hope that it will be useful,
17744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17746 + * GNU General Public License for more details.
17748 + * You should have received a copy of the GNU General Public License
17749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17753 + * inode private data
17758 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17760 + struct inode *h_inode;
17761 + struct au_hinode *hinode;
17763 + IiMustAnyLock(inode);
17765 + hinode = au_hinode(au_ii(inode), bindex);
17766 + h_inode = hinode->hi_inode;
17767 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17771 +/* todo: hard/soft set? */
17772 +void au_hiput(struct au_hinode *hinode)
17774 + au_hn_free(hinode);
17775 + dput(hinode->hi_whdentry);
17776 + iput(hinode->hi_inode);
17779 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17781 + unsigned int flags;
17782 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17785 + if (au_opt_test(mnt_flags, XINO))
17786 + au_fset_hi(flags, XINO);
17787 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17788 + au_fset_hi(flags, HNOTIFY);
17792 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17793 + struct inode *h_inode, unsigned int flags)
17795 + struct au_hinode *hinode;
17796 + struct inode *hi;
17797 + struct au_iinfo *iinfo = au_ii(inode);
17799 + IiMustWriteLock(inode);
17801 + hinode = au_hinode(iinfo, bindex);
17802 + hi = hinode->hi_inode;
17803 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17806 + au_hiput(hinode);
17807 + hinode->hi_inode = h_inode;
17810 + struct super_block *sb = inode->i_sb;
17811 + struct au_branch *br;
17813 + AuDebugOn(inode->i_mode
17814 + && (h_inode->i_mode & S_IFMT)
17815 + != (inode->i_mode & S_IFMT));
17816 + if (bindex == iinfo->ii_btop)
17817 + au_cpup_igen(inode, h_inode);
17818 + br = au_sbr(sb, bindex);
17819 + hinode->hi_id = br->br_id;
17820 + if (au_ftest_hi(flags, XINO)) {
17821 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17823 + if (unlikely(err))
17824 + AuIOErr1("failed au_xino_write() %d\n", err);
17827 + if (au_ftest_hi(flags, HNOTIFY)
17828 + && au_br_hnotifyable(br->br_perm)) {
17829 + err = au_hn_alloc(hinode, inode);
17830 + if (unlikely(err))
17831 + AuIOErr1("au_hn_alloc() %d\n", err);
17836 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17837 + struct dentry *h_wh)
17839 + struct au_hinode *hinode;
17841 + IiMustWriteLock(inode);
17843 + hinode = au_hinode(au_ii(inode), bindex);
17844 + AuDebugOn(hinode->hi_whdentry);
17845 + hinode->hi_whdentry = h_wh;
17848 +void au_update_iigen(struct inode *inode, int half)
17850 + struct au_iinfo *iinfo;
17851 + struct au_iigen *iigen;
17852 + unsigned int sigen;
17854 + sigen = au_sigen(inode->i_sb);
17855 + iinfo = au_ii(inode);
17856 + iigen = &iinfo->ii_generation;
17857 + spin_lock(&iigen->ig_spin);
17858 + iigen->ig_generation = sigen;
17860 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17862 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17863 + spin_unlock(&iigen->ig_spin);
17866 +/* it may be called at remount time, too */
17867 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17869 + struct au_iinfo *iinfo;
17870 + aufs_bindex_t bindex, bbot;
17872 + AuDebugOn(au_is_bad_inode(inode));
17873 + IiMustWriteLock(inode);
17875 + iinfo = au_ii(inode);
17876 + if (do_put_zero && iinfo->ii_btop >= 0) {
17877 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17879 + struct inode *h_i;
17881 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17884 + && !(h_i->i_state & I_LINKABLE))
17885 + au_set_h_iptr(inode, bindex, NULL, 0);
17889 + iinfo->ii_btop = -1;
17890 + iinfo->ii_bbot = -1;
17891 + bbot = au_sbbot(inode->i_sb);
17892 + for (bindex = 0; bindex <= bbot; bindex++)
17893 + if (au_hinode(iinfo, bindex)->hi_inode) {
17894 + iinfo->ii_btop = bindex;
17897 + if (iinfo->ii_btop >= 0)
17898 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17899 + if (au_hinode(iinfo, bindex)->hi_inode) {
17900 + iinfo->ii_bbot = bindex;
17903 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17906 +/* ---------------------------------------------------------------------- */
17908 +void au_icntnr_init_once(void *_c)
17910 + struct au_icntnr *c = _c;
17911 + struct au_iinfo *iinfo = &c->iinfo;
17913 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17914 + au_rw_init(&iinfo->ii_rwsem);
17915 + inode_init_once(&c->vfs_inode);
17918 +void au_hinode_init(struct au_hinode *hinode)
17920 + hinode->hi_inode = NULL;
17921 + hinode->hi_id = -1;
17922 + au_hn_init(hinode);
17923 + hinode->hi_whdentry = NULL;
17926 +int au_iinfo_init(struct inode *inode)
17928 + struct au_iinfo *iinfo;
17929 + struct super_block *sb;
17930 + struct au_hinode *hi;
17933 + sb = inode->i_sb;
17934 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17935 + nbr = au_sbbot(sb) + 1;
17936 + if (unlikely(nbr <= 0))
17938 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17940 + au_ninodes_inc(sb);
17942 + iinfo->ii_hinode = hi;
17943 + for (i = 0; i < nbr; i++, hi++)
17944 + au_hinode_init(hi);
17946 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17947 + iinfo->ii_btop = -1;
17948 + iinfo->ii_bbot = -1;
17949 + iinfo->ii_vdir = NULL;
17955 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17958 + struct au_hinode *hip;
17960 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17963 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17966 + iinfo->ii_hinode = hip;
17967 + i = iinfo->ii_bbot + 1;
17969 + for (; i < nbr; i++, hip++)
17970 + au_hinode_init(hip);
17977 +void au_iinfo_fin(struct inode *inode)
17979 + struct au_iinfo *iinfo;
17980 + struct au_hinode *hi;
17981 + struct super_block *sb;
17982 + aufs_bindex_t bindex, bbot;
17983 + const unsigned char unlinked = !inode->i_nlink;
17985 + AuDebugOn(au_is_bad_inode(inode));
17987 + sb = inode->i_sb;
17988 + au_ninodes_dec(sb);
17989 + if (si_pid_test(sb))
17990 + au_xino_delete_inode(inode, unlinked);
17993 + * it is safe to hide the dependency between sbinfo and
17997 + si_noflush_read_lock(sb);
17998 + au_xino_delete_inode(inode, unlinked);
17999 + si_read_unlock(sb);
18003 + iinfo = au_ii(inode);
18004 + if (iinfo->ii_vdir)
18005 + au_vdir_free(iinfo->ii_vdir);
18007 + bindex = iinfo->ii_btop;
18008 + if (bindex >= 0) {
18009 + hi = au_hinode(iinfo, bindex);
18010 + bbot = iinfo->ii_bbot;
18011 + while (bindex++ <= bbot) {
18012 + if (hi->hi_inode)
18017 + kfree(iinfo->ii_hinode);
18018 + AuRwDestroy(&iinfo->ii_rwsem);
18020 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18021 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18022 +++ linux/fs/aufs/inode.c 2018-04-15 08:49:13.401150731 +0200
18025 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18027 + * This program, aufs is free software; you can redistribute it and/or modify
18028 + * it under the terms of the GNU General Public License as published by
18029 + * the Free Software Foundation; either version 2 of the License, or
18030 + * (at your option) any later version.
18032 + * This program is distributed in the hope that it will be useful,
18033 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18034 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18035 + * GNU General Public License for more details.
18037 + * You should have received a copy of the GNU General Public License
18038 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18042 + * inode functions
18047 +struct inode *au_igrab(struct inode *inode)
18050 + AuDebugOn(!atomic_read(&inode->i_count));
18056 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18058 + au_cpup_attr_all(inode, /*force*/0);
18059 + au_update_iigen(inode, /*half*/1);
18061 + inode->i_version++;
18064 +static int au_ii_refresh(struct inode *inode, int *update)
18068 + aufs_bindex_t bindex, new_bindex;
18069 + struct super_block *sb;
18070 + struct au_iinfo *iinfo;
18071 + struct au_hinode *p, *q, tmp;
18073 + AuDebugOn(au_is_bad_inode(inode));
18074 + IiMustWriteLock(inode);
18077 + sb = inode->i_sb;
18078 + nbr = au_sbbot(sb) + 1;
18079 + type = inode->i_mode & S_IFMT;
18080 + iinfo = au_ii(inode);
18081 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18082 + if (unlikely(err))
18085 + AuDebugOn(iinfo->ii_btop < 0);
18086 + p = au_hinode(iinfo, iinfo->ii_btop);
18087 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18089 + if (!p->hi_inode)
18092 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18093 + new_bindex = au_br_index(sb, p->hi_id);
18094 + if (new_bindex == bindex)
18097 + if (new_bindex < 0) {
18100 + p->hi_inode = NULL;
18104 + if (new_bindex < iinfo->ii_btop)
18105 + iinfo->ii_btop = new_bindex;
18106 + if (iinfo->ii_bbot < new_bindex)
18107 + iinfo->ii_bbot = new_bindex;
18108 + /* swap two lower inode, and loop again */
18109 + q = au_hinode(iinfo, new_bindex);
18113 + if (tmp.hi_inode) {
18118 + au_update_ibrange(inode, /*do_put_zero*/0);
18119 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18120 + e = au_dy_irefresh(inode);
18121 + if (unlikely(e && !err))
18129 +void au_refresh_iop(struct inode *inode, int force_getattr)
18132 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18133 + const struct inode_operations *iop
18134 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18136 + if (inode->i_op == iop)
18139 + switch (inode->i_mode & S_IFMT) {
18141 + type = AuIop_DIR;
18144 + type = AuIop_SYMLINK;
18147 + type = AuIop_OTHER;
18151 + inode->i_op = iop + type;
18152 + /* unnecessary smp_wmb() */
18155 +int au_refresh_hinode_self(struct inode *inode)
18159 + err = au_ii_refresh(inode, &update);
18161 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18167 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18169 + int err, e, update;
18170 + unsigned int flags;
18172 + aufs_bindex_t bindex, bbot;
18173 + unsigned char isdir;
18174 + struct au_hinode *p;
18175 + struct au_iinfo *iinfo;
18177 + err = au_ii_refresh(inode, &update);
18178 + if (unlikely(err))
18182 + iinfo = au_ii(inode);
18183 + p = au_hinode(iinfo, iinfo->ii_btop);
18184 + mode = (inode->i_mode & S_IFMT);
18185 + isdir = S_ISDIR(mode);
18186 + flags = au_hi_flags(inode, isdir);
18187 + bbot = au_dbbot(dentry);
18188 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18189 + struct inode *h_i, *h_inode;
18190 + struct dentry *h_d;
18192 + h_d = au_h_dptr(dentry, bindex);
18193 + if (!h_d || d_is_negative(h_d))
18196 + h_inode = d_inode(h_d);
18197 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18198 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18199 + h_i = au_h_iptr(inode, bindex);
18201 + if (h_i == h_inode)
18207 + if (bindex < iinfo->ii_btop)
18208 + iinfo->ii_btop = bindex;
18209 + if (iinfo->ii_bbot < bindex)
18210 + iinfo->ii_bbot = bindex;
18211 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18214 + au_update_ibrange(inode, /*do_put_zero*/0);
18215 + e = au_dy_irefresh(inode);
18216 + if (unlikely(e && !err))
18219 + au_refresh_hinode_attr(inode, update && isdir);
18226 +static int set_inode(struct inode *inode, struct dentry *dentry)
18229 + unsigned int flags;
18231 + aufs_bindex_t bindex, btop, btail;
18232 + unsigned char isdir;
18233 + struct dentry *h_dentry;
18234 + struct inode *h_inode;
18235 + struct au_iinfo *iinfo;
18236 + struct inode_operations *iop;
18238 + IiMustWriteLock(inode);
18242 + iop = au_sbi(inode->i_sb)->si_iop_array;
18243 + btop = au_dbtop(dentry);
18244 + h_dentry = au_h_dptr(dentry, btop);
18245 + h_inode = d_inode(h_dentry);
18246 + mode = h_inode->i_mode;
18247 + switch (mode & S_IFMT) {
18249 + btail = au_dbtail(dentry);
18250 + inode->i_op = iop + AuIop_OTHER;
18251 + inode->i_fop = &aufs_file_fop;
18252 + err = au_dy_iaop(inode, btop, h_inode);
18253 + if (unlikely(err))
18258 + btail = au_dbtaildir(dentry);
18259 + inode->i_op = iop + AuIop_DIR;
18260 + inode->i_fop = &aufs_dir_fop;
18263 + btail = au_dbtail(dentry);
18264 + inode->i_op = iop + AuIop_SYMLINK;
18270 + btail = au_dbtail(dentry);
18271 + inode->i_op = iop + AuIop_OTHER;
18272 + init_special_inode(inode, mode, h_inode->i_rdev);
18275 + AuIOErr("Unknown file type 0%o\n", mode);
18280 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18281 + flags = au_hi_flags(inode, isdir);
18282 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18283 + && au_ftest_hi(flags, HNOTIFY)
18284 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18285 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18286 + au_fclr_hi(flags, HNOTIFY);
18287 + iinfo = au_ii(inode);
18288 + iinfo->ii_btop = btop;
18289 + iinfo->ii_bbot = btail;
18290 + for (bindex = btop; bindex <= btail; bindex++) {
18291 + h_dentry = au_h_dptr(dentry, bindex);
18293 + au_set_h_iptr(inode, bindex,
18294 + au_igrab(d_inode(h_dentry)), flags);
18296 + au_cpup_attr_all(inode, /*force*/1);
18298 + * to force calling aufs_get_acl() every time,
18299 + * do not call cache_no_acl() for aufs inode.
18307 + * successful returns with iinfo write_locked
18309 + * zero: success, matched
18310 + * plus: no error, but unmatched
18312 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18315 + unsigned int gen, igflags;
18316 + aufs_bindex_t bindex, bbot;
18317 + struct inode *h_inode, *h_dinode;
18318 + struct dentry *h_dentry;
18321 + * before this function, if aufs got any iinfo lock, it must be only
18322 + * one, the parent dir.
18323 + * it can happen by UDBA and the obsoleted inode number.
18326 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18330 + ii_write_lock_new_child(inode);
18331 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18332 + h_dinode = d_inode(h_dentry);
18333 + bbot = au_ibbot(inode);
18334 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18335 + h_inode = au_h_iptr(inode, bindex);
18336 + if (!h_inode || h_inode != h_dinode)
18340 + gen = au_iigen(inode, &igflags);
18341 + if (gen == au_digen(dentry)
18342 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18345 + /* fully refresh inode using dentry */
18346 + err = au_refresh_hinode(inode, dentry);
18348 + au_update_iigen(inode, /*half*/0);
18352 + if (unlikely(err))
18353 + ii_write_unlock(inode);
18358 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18359 + unsigned int d_type, ino_t *ino)
18362 + const int isnondir = d_type != DT_DIR;
18364 + /* prevent hardlinked inode number from race condition */
18366 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18367 + if (unlikely(err))
18371 + err = au_xino_read(sb, bindex, h_ino, ino);
18372 + if (unlikely(err))
18373 + goto out_xinondir;
18377 + *ino = au_xino_new_ino(sb);
18378 + if (unlikely(!*ino))
18379 + goto out_xinondir;
18380 + err = au_xino_write(sb, bindex, h_ino, *ino);
18381 + if (unlikely(err))
18382 + goto out_xinondir;
18386 + if (isnondir && idx >= 0)
18387 + au_xinondir_leave(sb, bindex, h_ino, idx);
18392 +/* successful returns with iinfo write_locked */
18393 +/* todo: return with unlocked? */
18394 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18396 + struct inode *inode, *h_inode;
18397 + struct dentry *h_dentry;
18398 + struct super_block *sb;
18399 + ino_t h_ino, ino;
18400 + int err, idx, hlinked;
18401 + aufs_bindex_t btop;
18403 + sb = dentry->d_sb;
18404 + btop = au_dbtop(dentry);
18405 + h_dentry = au_h_dptr(dentry, btop);
18406 + h_inode = d_inode(h_dentry);
18407 + h_ino = h_inode->i_ino;
18408 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18412 + * stop 'race'-ing between hardlinks under different
18416 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18417 + inode = ERR_PTR(err);
18418 + if (unlikely(err))
18422 + err = au_xino_read(sb, btop, h_ino, &ino);
18423 + inode = ERR_PTR(err);
18424 + if (unlikely(err))
18425 + goto out_xinondir;
18428 + ino = au_xino_new_ino(sb);
18429 + if (unlikely(!ino)) {
18430 + inode = ERR_PTR(-EIO);
18431 + goto out_xinondir;
18435 + AuDbg("i%lu\n", (unsigned long)ino);
18436 + inode = au_iget_locked(sb, ino);
18437 + err = PTR_ERR(inode);
18438 + if (IS_ERR(inode))
18439 + goto out_xinondir;
18441 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18442 + if (inode->i_state & I_NEW) {
18443 + ii_write_lock_new_child(inode);
18444 + err = set_inode(inode, dentry);
18446 + unlock_new_inode(inode);
18447 + goto out_xinondir; /* success */
18451 + * iget_failed() calls iput(), but we need to call
18452 + * ii_write_unlock() after iget_failed(). so dirty hack for
18455 + atomic_inc(&inode->i_count);
18456 + iget_failed(inode);
18457 + ii_write_unlock(inode);
18458 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18459 + /* ignore this error */
18461 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18463 + * horrible race condition between lookup, readdir and copyup
18464 + * (or something).
18466 + if (hlinked && idx >= 0)
18467 + au_xinondir_leave(sb, btop, h_ino, idx);
18468 + err = reval_inode(inode, dentry);
18469 + if (unlikely(err < 0)) {
18474 + goto out; /* success */
18475 + else if (hlinked && idx >= 0) {
18476 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18477 + if (unlikely(err)) {
18479 + inode = ERR_PTR(err);
18485 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18486 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18487 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18488 + btop, au_sbtype(h_dentry->d_sb), dentry,
18489 + (unsigned long)h_ino, (unsigned long)ino);
18491 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18494 + if (hlinked && idx >= 0)
18495 + au_xinondir_leave(sb, btop, h_ino, idx);
18501 + inode = ERR_PTR(err);
18503 + if (hlinked && idx >= 0)
18504 + au_xinondir_leave(sb, btop, h_ino, idx);
18509 +/* ---------------------------------------------------------------------- */
18511 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18512 + struct inode *inode)
18515 + struct inode *hi;
18517 + err = au_br_rdonly(au_sbr(sb, bindex));
18519 + /* pseudo-link after flushed may happen out of bounds */
18522 + && au_ibtop(inode) <= bindex
18523 + && bindex <= au_ibbot(inode)) {
18525 + * permission check is unnecessary since vfsub routine
18526 + * will be called later
18528 + hi = au_h_iptr(inode, bindex);
18530 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18536 +int au_test_h_perm(struct inode *h_inode, int mask)
18538 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18540 + return inode_permission(h_inode, mask);
18543 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18545 + if (au_test_nfs(h_inode->i_sb)
18546 + && (mask & MAY_WRITE)
18547 + && S_ISDIR(h_inode->i_mode))
18548 + mask |= MAY_READ; /* force permission check */
18549 + return au_test_h_perm(h_inode, mask);
18551 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18552 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18553 +++ linux/fs/aufs/inode.h 2018-04-15 08:49:13.401150731 +0200
18556 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18558 + * This program, aufs is free software; you can redistribute it and/or modify
18559 + * it under the terms of the GNU General Public License as published by
18560 + * the Free Software Foundation; either version 2 of the License, or
18561 + * (at your option) any later version.
18563 + * This program is distributed in the hope that it will be useful,
18564 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18565 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18566 + * GNU General Public License for more details.
18568 + * You should have received a copy of the GNU General Public License
18569 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18573 + * inode operations
18576 +#ifndef __AUFS_INODE_H__
18577 +#define __AUFS_INODE_H__
18581 +#include <linux/fsnotify.h>
18582 +#include "rwsem.h"
18586 +struct au_hnotify {
18587 +#ifdef CONFIG_AUFS_HNOTIFY
18588 +#ifdef CONFIG_AUFS_HFSNOTIFY
18589 + /* never use fsnotify_add_vfsmount_mark() */
18590 + struct fsnotify_mark hn_mark;
18592 + struct inode *hn_aufs_inode; /* no get/put */
18594 +} ____cacheline_aligned_in_smp;
18596 +struct au_hinode {
18597 + struct inode *hi_inode;
18598 + aufs_bindex_t hi_id;
18599 +#ifdef CONFIG_AUFS_HNOTIFY
18600 + struct au_hnotify *hi_notify;
18603 + /* reference to the copied-up whiteout with get/put */
18604 + struct dentry *hi_whdentry;
18608 +#define AuIG_HALF_REFRESHED 1
18609 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18610 +#define au_ig_fset(flags, name) \
18611 + do { (flags) |= AuIG_##name; } while (0)
18612 +#define au_ig_fclr(flags, name) \
18613 + do { (flags) &= ~AuIG_##name; } while (0)
18616 + spinlock_t ig_spin;
18617 + __u32 ig_generation, ig_flags;
18622 + struct au_iigen ii_generation;
18623 + struct super_block *ii_hsb1; /* no get/put */
18625 + struct au_rwsem ii_rwsem;
18626 + aufs_bindex_t ii_btop, ii_bbot;
18628 + struct au_hinode *ii_hinode;
18629 + struct au_vdir *ii_vdir;
18632 +struct au_icntnr {
18633 + struct au_iinfo iinfo;
18634 + struct inode vfs_inode;
18635 + struct hlist_bl_node plink;
18636 +} ____cacheline_aligned_in_smp;
18638 +/* au_pin flags */
18639 +#define AuPin_DI_LOCKED 1
18640 +#define AuPin_MNT_WRITE (1 << 1)
18641 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18642 +#define au_fset_pin(flags, name) \
18643 + do { (flags) |= AuPin_##name; } while (0)
18644 +#define au_fclr_pin(flags, name) \
18645 + do { (flags) &= ~AuPin_##name; } while (0)
18649 + struct dentry *dentry;
18650 + unsigned int udba;
18651 + unsigned char lsc_di, lsc_hi, flags;
18652 + aufs_bindex_t bindex;
18655 + struct dentry *parent;
18656 + struct au_hinode *hdir;
18657 + struct vfsmount *h_mnt;
18659 + /* temporary unlock/relock for copyup */
18660 + struct dentry *h_dentry, *h_parent;
18661 + struct au_branch *br;
18662 + struct task_struct *task;
18665 +void au_pin_hdir_unlock(struct au_pin *p);
18666 +int au_pin_hdir_lock(struct au_pin *p);
18667 +int au_pin_hdir_relock(struct au_pin *p);
18668 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18669 +void au_pin_hdir_release(struct au_pin *p);
18671 +/* ---------------------------------------------------------------------- */
18673 +static inline struct au_iinfo *au_ii(struct inode *inode)
18675 + BUG_ON(is_bad_inode(inode));
18676 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18679 +/* ---------------------------------------------------------------------- */
18682 +struct inode *au_igrab(struct inode *inode);
18683 +void au_refresh_iop(struct inode *inode, int force_getattr);
18684 +int au_refresh_hinode_self(struct inode *inode);
18685 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18686 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18687 + unsigned int d_type, ino_t *ino);
18688 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18689 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18690 + struct inode *inode);
18691 +int au_test_h_perm(struct inode *h_inode, int mask);
18692 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18694 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18695 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18697 +#ifdef CONFIG_AUFS_SHWH
18698 + return au_ino(sb, bindex, h_ino, d_type, ino);
18711 +extern struct inode_operations aufs_iop[AuIop_Last],
18712 + aufs_iop_nogetattr[AuIop_Last];
18714 +/* au_wr_dir flags */
18715 +#define AuWrDir_ADD_ENTRY 1
18716 +#define AuWrDir_ISDIR (1 << 1)
18717 +#define AuWrDir_TMPFILE (1 << 2)
18718 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18719 +#define au_fset_wrdir(flags, name) \
18720 + do { (flags) |= AuWrDir_##name; } while (0)
18721 +#define au_fclr_wrdir(flags, name) \
18722 + do { (flags) &= ~AuWrDir_##name; } while (0)
18724 +struct au_wr_dir_args {
18725 + aufs_bindex_t force_btgt;
18726 + unsigned char flags;
18728 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18729 + struct au_wr_dir_args *args);
18731 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18732 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18733 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18734 + unsigned int udba, unsigned char flags);
18735 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18736 + unsigned int udba, unsigned char flags) __must_check;
18737 +int au_do_pin(struct au_pin *pin) __must_check;
18738 +void au_unpin(struct au_pin *pin);
18739 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18741 +#define AuIcpup_DID_CPUP 1
18742 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18743 +#define au_fset_icpup(flags, name) \
18744 + do { (flags) |= AuIcpup_##name; } while (0)
18745 +#define au_fclr_icpup(flags, name) \
18746 + do { (flags) &= ~AuIcpup_##name; } while (0)
18748 +struct au_icpup_args {
18749 + unsigned char flags;
18750 + unsigned char pin_flags;
18751 + aufs_bindex_t btgt;
18752 + unsigned int udba;
18753 + struct au_pin pin;
18754 + struct path h_path;
18755 + struct inode *h_inode;
18758 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18759 + struct au_icpup_args *a);
18761 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18765 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18766 + struct dentry *h_parent, int isdir);
18767 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18769 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18770 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18772 +struct vfsub_aopen_args;
18773 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18774 + struct vfsub_aopen_args *args);
18775 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18776 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18777 + struct dentry *dentry);
18778 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18781 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18782 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18783 + struct dentry *h_parent, int isdir);
18784 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18785 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18788 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18789 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18790 + struct inode *dir, struct dentry *dentry,
18791 + unsigned int flags);
18794 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18795 +void au_hiput(struct au_hinode *hinode);
18796 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18797 + struct dentry *h_wh);
18798 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18800 +/* hinode flags */
18801 +#define AuHi_XINO 1
18802 +#define AuHi_HNOTIFY (1 << 1)
18803 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18804 +#define au_fset_hi(flags, name) \
18805 + do { (flags) |= AuHi_##name; } while (0)
18806 +#define au_fclr_hi(flags, name) \
18807 + do { (flags) &= ~AuHi_##name; } while (0)
18809 +#ifndef CONFIG_AUFS_HNOTIFY
18810 +#undef AuHi_HNOTIFY
18811 +#define AuHi_HNOTIFY 0
18814 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18815 + struct inode *h_inode, unsigned int flags);
18817 +void au_update_iigen(struct inode *inode, int half);
18818 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18820 +void au_icntnr_init_once(void *_c);
18821 +void au_hinode_init(struct au_hinode *hinode);
18822 +int au_iinfo_init(struct inode *inode);
18823 +void au_iinfo_fin(struct inode *inode);
18824 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18826 +#ifdef CONFIG_PROC_FS
18828 +int au_plink_maint(struct super_block *sb, int flags);
18830 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18831 +int au_plink_maint_enter(struct super_block *sb);
18832 +#ifdef CONFIG_AUFS_DEBUG
18833 +void au_plink_list(struct super_block *sb);
18835 +AuStubVoid(au_plink_list, struct super_block *sb)
18837 +int au_plink_test(struct inode *inode);
18838 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18839 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18840 + struct dentry *h_dentry);
18841 +void au_plink_put(struct super_block *sb, int verbose);
18842 +void au_plink_clean(struct super_block *sb, int verbose);
18843 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18845 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18846 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18847 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18848 +AuStubVoid(au_plink_list, struct super_block *sb);
18849 +AuStubInt0(au_plink_test, struct inode *inode);
18850 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18851 + struct inode *inode, aufs_bindex_t bindex);
18852 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18853 + struct dentry *h_dentry);
18854 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18855 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18856 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18857 +#endif /* CONFIG_PROC_FS */
18859 +#ifdef CONFIG_AUFS_XATTR
18861 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18862 + unsigned int verbose);
18863 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18864 +void au_xattr_init(struct super_block *sb);
18866 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18867 + int ignore_flags, unsigned int verbose);
18868 +AuStubVoid(au_xattr_init, struct super_block *sb);
18871 +#ifdef CONFIG_FS_POSIX_ACL
18872 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18873 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18876 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18882 +struct au_sxattr {
18886 + const char *name;
18887 + const void *value;
18892 + struct posix_acl *acl;
18897 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18898 + struct au_sxattr *arg);
18901 +/* ---------------------------------------------------------------------- */
18903 +/* lock subclass for iinfo */
18905 + AuLsc_II_CHILD, /* child first */
18906 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18907 + AuLsc_II_CHILD3, /* copyup dirs */
18908 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18909 + AuLsc_II_PARENT2,
18910 + AuLsc_II_PARENT3, /* copyup dirs */
18911 + AuLsc_II_NEW_CHILD
18915 + * ii_read_lock_child, ii_write_lock_child,
18916 + * ii_read_lock_child2, ii_write_lock_child2,
18917 + * ii_read_lock_child3, ii_write_lock_child3,
18918 + * ii_read_lock_parent, ii_write_lock_parent,
18919 + * ii_read_lock_parent2, ii_write_lock_parent2,
18920 + * ii_read_lock_parent3, ii_write_lock_parent3,
18921 + * ii_read_lock_new_child, ii_write_lock_new_child,
18923 +#define AuReadLockFunc(name, lsc) \
18924 +static inline void ii_read_lock_##name(struct inode *i) \
18926 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18929 +#define AuWriteLockFunc(name, lsc) \
18930 +static inline void ii_write_lock_##name(struct inode *i) \
18932 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18935 +#define AuRWLockFuncs(name, lsc) \
18936 + AuReadLockFunc(name, lsc) \
18937 + AuWriteLockFunc(name, lsc)
18939 +AuRWLockFuncs(child, CHILD);
18940 +AuRWLockFuncs(child2, CHILD2);
18941 +AuRWLockFuncs(child3, CHILD3);
18942 +AuRWLockFuncs(parent, PARENT);
18943 +AuRWLockFuncs(parent2, PARENT2);
18944 +AuRWLockFuncs(parent3, PARENT3);
18945 +AuRWLockFuncs(new_child, NEW_CHILD);
18947 +#undef AuReadLockFunc
18948 +#undef AuWriteLockFunc
18949 +#undef AuRWLockFuncs
18952 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
18954 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
18956 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18957 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18958 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18960 +/* ---------------------------------------------------------------------- */
18962 +static inline void au_icntnr_init(struct au_icntnr *c)
18964 +#ifdef CONFIG_AUFS_DEBUG
18965 + c->vfs_inode.i_mode = 0;
18969 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18971 + unsigned int gen;
18972 + struct au_iinfo *iinfo;
18973 + struct au_iigen *iigen;
18975 + iinfo = au_ii(inode);
18976 + iigen = &iinfo->ii_generation;
18977 + spin_lock(&iigen->ig_spin);
18979 + *igflags = iigen->ig_flags;
18980 + gen = iigen->ig_generation;
18981 + spin_unlock(&iigen->ig_spin);
18986 +/* tiny test for inode number */
18987 +/* tmpfs generation is too rough */
18988 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
18990 + struct au_iinfo *iinfo;
18992 + iinfo = au_ii(inode);
18993 + AuRwMustAnyLock(&iinfo->ii_rwsem);
18994 + return !(iinfo->ii_hsb1 == h_inode->i_sb
18995 + && iinfo->ii_higen == h_inode->i_generation);
18998 +static inline void au_iigen_dec(struct inode *inode)
19000 + struct au_iinfo *iinfo;
19001 + struct au_iigen *iigen;
19003 + iinfo = au_ii(inode);
19004 + iigen = &iinfo->ii_generation;
19005 + spin_lock(&iigen->ig_spin);
19006 + iigen->ig_generation--;
19007 + spin_unlock(&iigen->ig_spin);
19010 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19015 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19021 +/* ---------------------------------------------------------------------- */
19023 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19024 + aufs_bindex_t bindex)
19026 + return iinfo->ii_hinode + bindex;
19029 +static inline int au_is_bad_inode(struct inode *inode)
19031 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19034 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19035 + aufs_bindex_t bindex)
19037 + IiMustAnyLock(inode);
19038 + return au_hinode(au_ii(inode), bindex)->hi_id;
19041 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19043 + IiMustAnyLock(inode);
19044 + return au_ii(inode)->ii_btop;
19047 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19049 + IiMustAnyLock(inode);
19050 + return au_ii(inode)->ii_bbot;
19053 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19055 + IiMustAnyLock(inode);
19056 + return au_ii(inode)->ii_vdir;
19059 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19061 + IiMustAnyLock(inode);
19062 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19065 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19067 + IiMustWriteLock(inode);
19068 + au_ii(inode)->ii_btop = bindex;
19071 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19073 + IiMustWriteLock(inode);
19074 + au_ii(inode)->ii_bbot = bindex;
19077 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19079 + IiMustWriteLock(inode);
19080 + au_ii(inode)->ii_vdir = vdir;
19083 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19085 + IiMustAnyLock(inode);
19086 + return au_hinode(au_ii(inode), bindex);
19089 +/* ---------------------------------------------------------------------- */
19091 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19094 + return pin->parent;
19098 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19100 + if (pin && pin->hdir)
19101 + return pin->hdir->hi_inode;
19105 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19108 + return pin->hdir;
19112 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19115 + pin->dentry = dentry;
19118 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19119 + unsigned char lflag)
19123 + au_fset_pin(pin->flags, DI_LOCKED);
19125 + au_fclr_pin(pin->flags, DI_LOCKED);
19129 +#if 0 /* reserved */
19130 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19133 + dput(pin->parent);
19134 + pin->parent = dget(parent);
19139 +/* ---------------------------------------------------------------------- */
19142 +#ifdef CONFIG_AUFS_HNOTIFY
19143 +struct au_hnotify_op {
19144 + void (*ctl)(struct au_hinode *hinode, int do_set);
19145 + int (*alloc)(struct au_hinode *hinode);
19148 + * if it returns true, the the caller should free hinode->hi_notify,
19149 + * otherwise ->free() frees it.
19151 + int (*free)(struct au_hinode *hinode,
19152 + struct au_hnotify *hn) __must_check;
19154 + void (*fin)(void);
19155 + int (*init)(void);
19157 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19158 + void (*fin_br)(struct au_branch *br);
19159 + int (*init_br)(struct au_branch *br, int perm);
19163 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19164 +void au_hn_free(struct au_hinode *hinode);
19165 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19166 +void au_hn_reset(struct inode *inode, unsigned int flags);
19167 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19168 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19169 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19170 +int au_hnotify_init_br(struct au_branch *br, int perm);
19171 +void au_hnotify_fin_br(struct au_branch *br);
19172 +int __init au_hnotify_init(void);
19173 +void au_hnotify_fin(void);
19176 +extern const struct au_hnotify_op au_hnotify_op;
19179 +void au_hn_init(struct au_hinode *hinode)
19181 + hinode->hi_notify = NULL;
19184 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19186 + return hinode->hi_notify;
19190 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19191 + struct au_hinode *hinode __maybe_unused,
19192 + struct inode *inode __maybe_unused)
19193 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19194 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19195 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19196 + int do_set __maybe_unused)
19197 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19198 + unsigned int flags __maybe_unused)
19199 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19200 + struct au_branch *br __maybe_unused,
19201 + int perm __maybe_unused)
19202 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19203 + int perm __maybe_unused)
19204 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19205 +AuStubInt0(__init au_hnotify_init, void)
19206 +AuStubVoid(au_hnotify_fin, void)
19207 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19208 +#endif /* CONFIG_AUFS_HNOTIFY */
19210 +static inline void au_hn_suspend(struct au_hinode *hdir)
19212 + au_hn_ctl(hdir, /*do_set*/0);
19215 +static inline void au_hn_resume(struct au_hinode *hdir)
19217 + au_hn_ctl(hdir, /*do_set*/1);
19220 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19222 + inode_lock(hdir->hi_inode);
19223 + au_hn_suspend(hdir);
19226 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19227 + unsigned int sc __maybe_unused)
19229 + inode_lock_nested(hdir->hi_inode, sc);
19230 + au_hn_suspend(hdir);
19233 +#if 0 /* unused */
19234 +#include "vfsub.h"
19235 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19238 + vfsub_inode_lock_shared_nested(hdir->hi_inode, sc);
19239 + au_hn_suspend(hdir);
19243 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19245 + au_hn_resume(hdir);
19246 + inode_unlock(hdir->hi_inode);
19249 +#endif /* __KERNEL__ */
19250 +#endif /* __AUFS_INODE_H__ */
19251 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19252 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19253 +++ linux/fs/aufs/ioctl.c 2018-04-15 08:49:13.401150731 +0200
19256 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19258 + * This program, aufs is free software; you can redistribute it and/or modify
19259 + * it under the terms of the GNU General Public License as published by
19260 + * the Free Software Foundation; either version 2 of the License, or
19261 + * (at your option) any later version.
19263 + * This program is distributed in the hope that it will be useful,
19264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19266 + * GNU General Public License for more details.
19268 + * You should have received a copy of the GNU General Public License
19269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19274 + * plink-management and readdir in userspace.
19275 + * assist the pathconf(3) wrapper library.
19277 + * File-based Hierarchical Storage Management.
19280 +#include <linux/compat.h>
19281 +#include <linux/file.h>
19284 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19287 + aufs_bindex_t wbi, bindex, bbot;
19288 + struct file *h_file;
19289 + struct super_block *sb;
19290 + struct dentry *root;
19291 + struct au_branch *br;
19292 + struct aufs_wbr_fd wbrfd = {
19293 + .oflags = au_dir_roflags,
19296 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19297 + | O_NOATIME | O_CLOEXEC;
19299 + AuDebugOn(wbrfd.oflags & ~valid);
19302 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19303 + if (unlikely(err)) {
19309 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19310 + wbrfd.oflags |= au_dir_roflags;
19311 + AuDbg("0%o\n", wbrfd.oflags);
19312 + if (unlikely(wbrfd.oflags & ~valid))
19316 + fd = get_unused_fd_flags(0);
19318 + if (unlikely(fd < 0))
19321 + h_file = ERR_PTR(-EINVAL);
19324 + sb = path->dentry->d_sb;
19325 + root = sb->s_root;
19326 + aufs_read_lock(root, AuLock_IR);
19327 + bbot = au_sbbot(sb);
19328 + if (wbrfd.brid >= 0) {
19329 + wbi = au_br_index(sb, wbrfd.brid);
19330 + if (unlikely(wbi < 0 || wbi > bbot))
19334 + h_file = ERR_PTR(-ENOENT);
19335 + br = au_sbr(sb, wbi);
19336 + if (!au_br_writable(br->br_perm)) {
19340 + bindex = wbi + 1;
19342 + for (; bindex <= bbot; bindex++) {
19343 + br = au_sbr(sb, bindex);
19344 + if (au_br_writable(br->br_perm)) {
19346 + br = au_sbr(sb, wbi);
19351 + AuDbg("wbi %d\n", wbi);
19353 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19357 + aufs_read_unlock(root, AuLock_IR);
19358 + err = PTR_ERR(h_file);
19359 + if (IS_ERR(h_file))
19362 + au_br_put(br); /* cf. au_h_open() */
19363 + fd_install(fd, h_file);
19365 + goto out; /* success */
19368 + put_unused_fd(fd);
19374 +/* ---------------------------------------------------------------------- */
19376 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19379 + struct dentry *dentry;
19382 + case AUFS_CTL_RDU:
19383 + case AUFS_CTL_RDU_INO:
19384 + err = au_rdu_ioctl(file, cmd, arg);
19387 + case AUFS_CTL_WBR_FD:
19388 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19391 + case AUFS_CTL_IBUSY:
19392 + err = au_ibusy_ioctl(file, arg);
19395 + case AUFS_CTL_BRINFO:
19396 + err = au_brinfo_ioctl(file, arg);
19399 + case AUFS_CTL_FHSM_FD:
19400 + dentry = file->f_path.dentry;
19401 + if (IS_ROOT(dentry))
19402 + err = au_fhsm_fd(dentry->d_sb, arg);
19408 + /* do not call the lower */
19409 + AuDbg("0x%x\n", cmd);
19417 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19422 + case AUFS_CTL_MVDOWN:
19423 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19426 + case AUFS_CTL_WBR_FD:
19427 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19431 + /* do not call the lower */
19432 + AuDbg("0x%x\n", cmd);
19440 +#ifdef CONFIG_COMPAT
19441 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19442 + unsigned long arg)
19447 + case AUFS_CTL_RDU:
19448 + case AUFS_CTL_RDU_INO:
19449 + err = au_rdu_compat_ioctl(file, cmd, arg);
19452 + case AUFS_CTL_IBUSY:
19453 + err = au_ibusy_compat_ioctl(file, arg);
19456 + case AUFS_CTL_BRINFO:
19457 + err = au_brinfo_compat_ioctl(file, arg);
19461 + err = aufs_ioctl_dir(file, cmd, arg);
19468 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19469 + unsigned long arg)
19471 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19474 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19475 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19476 +++ linux/fs/aufs/i_op_add.c 2018-04-15 08:49:13.401150731 +0200
19479 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19481 + * This program, aufs is free software; you can redistribute it and/or modify
19482 + * it under the terms of the GNU General Public License as published by
19483 + * the Free Software Foundation; either version 2 of the License, or
19484 + * (at your option) any later version.
19486 + * This program is distributed in the hope that it will be useful,
19487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19489 + * GNU General Public License for more details.
19491 + * You should have received a copy of the GNU General Public License
19492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19496 + * inode operations (add entry)
19502 + * final procedure of adding a new entry, except link(2).
19503 + * remove whiteout, instantiate, copyup the parent dir's times and size
19504 + * and update version.
19505 + * if it failed, re-create the removed whiteout.
19507 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19508 + struct dentry *wh_dentry, struct dentry *dentry)
19511 + aufs_bindex_t bwh;
19512 + struct path h_path;
19513 + struct super_block *sb;
19514 + struct inode *inode, *h_dir;
19515 + struct dentry *wh;
19520 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19521 + IMustLock(h_dir);
19522 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19523 + bwh = au_dbwh(dentry);
19524 + h_path.dentry = wh_dentry;
19525 + h_path.mnt = au_sbr_mnt(sb, bindex);
19526 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19528 + if (unlikely(err))
19532 + inode = au_new_inode(dentry, /*must_new*/1);
19533 + if (!IS_ERR(inode)) {
19534 + d_instantiate(dentry, inode);
19535 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19537 + au_dir_ts(dir, bindex);
19538 + dir->i_version++;
19539 + au_fhsm_wrote(sb, bindex, /*force*/0);
19540 + return 0; /* success */
19543 + err = PTR_ERR(inode);
19548 + /* dir inode is locked */
19549 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19550 + rerr = PTR_ERR(wh);
19551 + if (IS_ERR(wh)) {
19552 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19553 + dentry, err, rerr);
19562 +static int au_d_may_add(struct dentry *dentry)
19567 + if (unlikely(d_unhashed(dentry)))
19569 + if (unlikely(d_really_is_positive(dentry)))
19575 + * simple tests for the adding inode operations.
19576 + * following the checks in vfs, plus the parent-child relationship.
19578 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19579 + struct dentry *h_parent, int isdir)
19583 + struct dentry *h_dentry;
19584 + struct inode *h_inode;
19586 + err = -ENAMETOOLONG;
19587 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19590 + h_dentry = au_h_dptr(dentry, bindex);
19591 + if (d_really_is_negative(dentry)) {
19593 + if (unlikely(d_is_positive(h_dentry)))
19596 + /* rename(2) case */
19598 + if (unlikely(d_is_negative(h_dentry)))
19600 + h_inode = d_inode(h_dentry);
19601 + if (unlikely(!h_inode->i_nlink))
19604 + h_mode = h_inode->i_mode;
19607 + if (unlikely(S_ISDIR(h_mode)))
19609 + } else if (unlikely(!S_ISDIR(h_mode))) {
19616 + /* expected parent dir is locked */
19617 + if (unlikely(h_parent != h_dentry->d_parent))
19626 + * initial procedure of adding a new entry.
19627 + * prepare writable branch and the parent dir, lock it,
19628 + * and lookup whiteout for the new entry.
19630 +static struct dentry*
19631 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19632 + struct dentry *src_dentry, struct au_pin *pin,
19633 + struct au_wr_dir_args *wr_dir_args)
19635 + struct dentry *wh_dentry, *h_parent;
19636 + struct super_block *sb;
19637 + struct au_branch *br;
19639 + unsigned int udba;
19640 + aufs_bindex_t bcpup;
19642 + AuDbg("%pd\n", dentry);
19644 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19646 + wh_dentry = ERR_PTR(err);
19647 + if (unlikely(err < 0))
19650 + sb = dentry->d_sb;
19651 + udba = au_opt_udba(sb);
19652 + err = au_pin(pin, dentry, bcpup, udba,
19653 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19654 + wh_dentry = ERR_PTR(err);
19655 + if (unlikely(err))
19658 + h_parent = au_pinned_h_parent(pin);
19659 + if (udba != AuOpt_UDBA_NONE
19660 + && au_dbtop(dentry) == bcpup)
19661 + err = au_may_add(dentry, bcpup, h_parent,
19662 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19663 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19664 + err = -ENAMETOOLONG;
19665 + wh_dentry = ERR_PTR(err);
19666 + if (unlikely(err))
19669 + br = au_sbr(sb, bcpup);
19671 + struct path tmp = {
19672 + .dentry = h_parent,
19673 + .mnt = au_br_mnt(br)
19675 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19678 + wh_dentry = NULL;
19679 + if (bcpup != au_dbwh(dentry))
19680 + goto out; /* success */
19683 + * ENAMETOOLONG here means that if we allowed create such name, then it
19684 + * would not be able to removed in the future. So we don't allow such
19685 + * name here and we don't handle ENAMETOOLONG differently here.
19687 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19690 + if (IS_ERR(wh_dentry))
19693 + return wh_dentry;
19696 +/* ---------------------------------------------------------------------- */
19698 +enum { Mknod, Symlink, Creat };
19699 +struct simple_arg {
19706 + struct vfsub_aopen_args *aopen;
19709 + const char *symname;
19718 +static int add_simple(struct inode *dir, struct dentry *dentry,
19719 + struct simple_arg *arg)
19722 + aufs_bindex_t btop;
19723 + unsigned char created;
19724 + const unsigned char try_aopen
19725 + = (arg->type == Creat && arg->u.c.try_aopen);
19726 + struct dentry *wh_dentry, *parent;
19727 + struct inode *h_dir;
19728 + struct super_block *sb;
19729 + struct au_branch *br;
19730 + /* to reuduce stack size */
19732 + struct au_dtime dt;
19733 + struct au_pin pin;
19734 + struct path h_path;
19735 + struct au_wr_dir_args wr_dir_args;
19738 + AuDbg("%pd\n", dentry);
19742 + a = kmalloc(sizeof(*a), GFP_NOFS);
19743 + if (unlikely(!a))
19745 + a->wr_dir_args.force_btgt = -1;
19746 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19748 + parent = dentry->d_parent; /* dir inode is locked */
19749 + if (!try_aopen) {
19750 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19751 + if (unlikely(err))
19754 + err = au_d_may_add(dentry);
19755 + if (unlikely(err))
19758 + di_write_lock_parent(parent);
19759 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19760 + &a->pin, &a->wr_dir_args);
19761 + err = PTR_ERR(wh_dentry);
19762 + if (IS_ERR(wh_dentry))
19765 + btop = au_dbtop(dentry);
19766 + sb = dentry->d_sb;
19767 + br = au_sbr(sb, btop);
19768 + a->h_path.dentry = au_h_dptr(dentry, btop);
19769 + a->h_path.mnt = au_br_mnt(br);
19770 + h_dir = au_pinned_h_dir(&a->pin);
19771 + switch (arg->type) {
19774 + if (!try_aopen || !h_dir->i_op->atomic_open)
19775 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19776 + arg->u.c.want_excl);
19778 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
19779 + arg->u.c.aopen, br);
19782 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19785 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19793 + err = epilog(dir, btop, wh_dentry, dentry);
19796 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
19797 + /* no delegation since it is just created */
19798 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19801 + AuIOErr("%pd revert failure(%d, %d)\n",
19802 + dentry, err, rerr);
19805 + au_dtime_revert(&a->dt);
19808 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
19809 + *arg->u.c.aopen->opened |= FILE_CREATED;
19811 + au_unpin(&a->pin);
19816 + di_write_unlock(parent);
19818 + if (unlikely(err)) {
19819 + au_update_dbtop(dentry);
19823 + aufs_read_unlock(dentry, AuLock_DW);
19830 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19833 + struct simple_arg arg = {
19840 + return add_simple(dir, dentry, &arg);
19843 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19845 + struct simple_arg arg = {
19847 + .u.s.symname = symname
19849 + return add_simple(dir, dentry, &arg);
19852 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19855 + struct simple_arg arg = {
19859 + .want_excl = want_excl
19862 + return add_simple(dir, dentry, &arg);
19865 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19866 + struct vfsub_aopen_args *aopen_args)
19868 + struct simple_arg arg = {
19871 + .mode = aopen_args->create_mode,
19872 + .want_excl = aopen_args->open_flag & O_EXCL,
19873 + .try_aopen = true,
19874 + .aopen = aopen_args
19877 + return add_simple(dir, dentry, &arg);
19880 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19883 + aufs_bindex_t bindex;
19884 + struct super_block *sb;
19885 + struct dentry *parent, *h_parent, *h_dentry;
19886 + struct inode *h_dir, *inode;
19887 + struct vfsmount *h_mnt;
19888 + struct au_wr_dir_args wr_dir_args = {
19889 + .force_btgt = -1,
19890 + .flags = AuWrDir_TMPFILE
19893 + /* copy-up may happen */
19897 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19898 + if (unlikely(err))
19901 + err = au_di_init(dentry);
19902 + if (unlikely(err))
19906 + parent = d_find_any_alias(dir);
19907 + AuDebugOn(!parent);
19908 + di_write_lock_parent(parent);
19909 + if (unlikely(d_inode(parent) != dir))
19912 + err = au_digen_test(parent, au_sigen(sb));
19913 + if (unlikely(err))
19916 + bindex = au_dbtop(parent);
19917 + au_set_dbtop(dentry, bindex);
19918 + au_set_dbbot(dentry, bindex);
19919 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19921 + if (unlikely(err < 0))
19924 + err = -EOPNOTSUPP;
19925 + h_dir = au_h_iptr(dir, bindex);
19926 + if (unlikely(!h_dir->i_op->tmpfile))
19929 + h_mnt = au_sbr_mnt(sb, bindex);
19930 + err = vfsub_mnt_want_write(h_mnt);
19931 + if (unlikely(err))
19934 + h_parent = au_h_dptr(parent, bindex);
19935 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
19936 + if (unlikely(err))
19940 + h_dentry = d_alloc(h_parent, &dentry->d_name);
19941 + if (unlikely(!h_dentry))
19944 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
19945 + if (unlikely(err))
19948 + au_set_dbtop(dentry, bindex);
19949 + au_set_dbbot(dentry, bindex);
19950 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19951 + inode = au_new_inode(dentry, /*must_new*/1);
19952 + if (IS_ERR(inode)) {
19953 + err = PTR_ERR(inode);
19954 + au_set_h_dptr(dentry, bindex, NULL);
19955 + au_set_dbtop(dentry, -1);
19956 + au_set_dbbot(dentry, -1);
19958 + if (!inode->i_nlink)
19959 + set_nlink(inode, 1);
19960 + d_tmpfile(dentry, inode);
19961 + au_di(dentry)->di_tmpfile = 1;
19963 + /* update without i_mutex */
19964 + if (au_ibtop(dir) == au_dbtop(dentry))
19965 + au_cpup_attr_timesizes(dir);
19971 + vfsub_mnt_drop_write(h_mnt);
19973 + di_write_unlock(parent);
19975 + di_write_unlock(dentry);
19976 + if (unlikely(err)) {
19977 + au_di_fin(dentry);
19978 + dentry->d_fsdata = NULL;
19981 + si_read_unlock(sb);
19983 + inode_unlock(dir);
19987 +/* ---------------------------------------------------------------------- */
19989 +struct au_link_args {
19990 + aufs_bindex_t bdst, bsrc;
19991 + struct au_pin pin;
19992 + struct path h_path;
19993 + struct dentry *src_parent, *parent;
19996 +static int au_cpup_before_link(struct dentry *src_dentry,
19997 + struct au_link_args *a)
20000 + struct dentry *h_src_dentry;
20001 + struct au_cp_generic cpg = {
20002 + .dentry = src_dentry,
20007 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20010 + di_read_lock_parent(a->src_parent, AuLock_IR);
20011 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20012 + if (unlikely(err))
20015 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20016 + err = au_pin(&a->pin, src_dentry, a->bdst,
20017 + au_opt_udba(src_dentry->d_sb),
20018 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20019 + if (unlikely(err))
20022 + err = au_sio_cpup_simple(&cpg);
20023 + au_unpin(&a->pin);
20026 + di_read_unlock(a->src_parent, AuLock_IR);
20030 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20031 + struct au_link_args *a)
20034 + unsigned char plink;
20035 + aufs_bindex_t bbot;
20036 + struct dentry *h_src_dentry;
20037 + struct inode *h_inode, *inode, *delegated;
20038 + struct super_block *sb;
20039 + struct file *h_file;
20043 + sb = src_dentry->d_sb;
20044 + inode = d_inode(src_dentry);
20045 + if (au_ibtop(inode) <= a->bdst)
20046 + h_inode = au_h_iptr(inode, a->bdst);
20047 + if (!h_inode || !h_inode->i_nlink) {
20048 + /* copyup src_dentry as the name of dentry. */
20049 + bbot = au_dbbot(dentry);
20050 + if (bbot < a->bsrc)
20051 + au_set_dbbot(dentry, a->bsrc);
20052 + au_set_h_dptr(dentry, a->bsrc,
20053 + dget(au_h_dptr(src_dentry, a->bsrc)));
20054 + dget(a->h_path.dentry);
20055 + au_set_h_dptr(dentry, a->bdst, NULL);
20056 + AuDbg("temporary d_inode...\n");
20057 + spin_lock(&dentry->d_lock);
20058 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20059 + spin_unlock(&dentry->d_lock);
20060 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20061 + if (IS_ERR(h_file))
20062 + err = PTR_ERR(h_file);
20064 + struct au_cp_generic cpg = {
20065 + .dentry = dentry,
20070 + .flags = AuCpup_KEEPLINO
20072 + err = au_sio_cpup_simple(&cpg);
20073 + au_h_open_post(dentry, a->bsrc, h_file);
20075 + dput(a->h_path.dentry);
20076 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20078 + au_set_h_dptr(dentry, a->bdst,
20079 + a->h_path.dentry);
20081 + spin_lock(&dentry->d_lock);
20082 + dentry->d_inode = NULL; /* restore */
20083 + spin_unlock(&dentry->d_lock);
20084 + AuDbg("temporary d_inode...done\n");
20085 + au_set_h_dptr(dentry, a->bsrc, NULL);
20086 + au_set_dbbot(dentry, bbot);
20088 + /* the inode of src_dentry already exists on a.bdst branch */
20089 + h_src_dentry = d_find_alias(h_inode);
20090 + if (!h_src_dentry && au_plink_test(inode)) {
20092 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20093 + err = PTR_ERR(h_src_dentry);
20094 + if (IS_ERR(h_src_dentry))
20097 + if (unlikely(d_is_negative(h_src_dentry))) {
20098 + dput(h_src_dentry);
20099 + h_src_dentry = NULL;
20103 + if (h_src_dentry) {
20104 + delegated = NULL;
20105 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20106 + &a->h_path, &delegated);
20107 + if (unlikely(err == -EWOULDBLOCK)) {
20108 + pr_warn("cannot retry for NFSv4 delegation"
20109 + " for an internal link\n");
20112 + dput(h_src_dentry);
20114 + AuIOErr("no dentry found for hi%lu on b%d\n",
20115 + h_inode->i_ino, a->bdst);
20120 + if (!err && !plink)
20121 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20128 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20129 + struct dentry *dentry)
20132 + struct au_dtime dt;
20133 + struct au_link_args *a;
20134 + struct dentry *wh_dentry, *h_src_dentry;
20135 + struct inode *inode, *delegated;
20136 + struct super_block *sb;
20137 + struct au_wr_dir_args wr_dir_args = {
20138 + /* .force_btgt = -1, */
20139 + .flags = AuWrDir_ADD_ENTRY
20143 + inode = d_inode(src_dentry);
20144 + IMustLock(inode);
20147 + a = kzalloc(sizeof(*a), GFP_NOFS);
20148 + if (unlikely(!a))
20151 + a->parent = dentry->d_parent; /* dir inode is locked */
20152 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20153 + AuLock_NOPLM | AuLock_GEN);
20154 + if (unlikely(err))
20156 + err = au_d_linkable(src_dentry);
20157 + if (unlikely(err))
20159 + err = au_d_may_add(dentry);
20160 + if (unlikely(err))
20163 + a->src_parent = dget_parent(src_dentry);
20164 + wr_dir_args.force_btgt = au_ibtop(inode);
20166 + di_write_lock_parent(a->parent);
20167 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20168 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20170 + err = PTR_ERR(wh_dentry);
20171 + if (IS_ERR(wh_dentry))
20175 + sb = dentry->d_sb;
20176 + a->bdst = au_dbtop(dentry);
20177 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20178 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20179 + a->bsrc = au_ibtop(inode);
20180 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20181 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20182 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20183 + if (!h_src_dentry) {
20184 + a->bsrc = au_dbtop(src_dentry);
20185 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20186 + AuDebugOn(!h_src_dentry);
20187 + } else if (IS_ERR(h_src_dentry)) {
20188 + err = PTR_ERR(h_src_dentry);
20193 + * aufs doesn't touch the credential so
20194 + * security_dentry_create_files_as() is unnecrssary.
20196 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20197 + if (a->bdst < a->bsrc
20198 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20199 + err = au_cpup_or_link(src_dentry, dentry, a);
20201 + delegated = NULL;
20202 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20203 + &a->h_path, &delegated);
20204 + if (unlikely(err == -EWOULDBLOCK)) {
20205 + pr_warn("cannot retry for NFSv4 delegation"
20206 + " for an internal link\n");
20210 + dput(h_src_dentry);
20213 + * copyup src_dentry to the branch we process,
20214 + * and then link(2) to it.
20216 + dput(h_src_dentry);
20217 + if (a->bdst < a->bsrc
20218 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20219 + au_unpin(&a->pin);
20220 + di_write_unlock(a->parent);
20221 + err = au_cpup_before_link(src_dentry, a);
20222 + di_write_lock_parent(a->parent);
20224 + err = au_pin(&a->pin, dentry, a->bdst,
20226 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20227 + if (unlikely(err))
20231 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20233 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20234 + delegated = NULL;
20235 + err = vfsub_link(h_src_dentry,
20236 + au_pinned_h_dir(&a->pin),
20237 + &a->h_path, &delegated);
20238 + if (unlikely(err == -EWOULDBLOCK)) {
20239 + pr_warn("cannot retry"
20240 + " for NFSv4 delegation"
20241 + " for an internal link\n");
20247 + if (unlikely(err))
20251 + a->h_path.dentry = wh_dentry;
20252 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20254 + if (unlikely(err))
20258 + au_dir_ts(dir, a->bdst);
20259 + dir->i_version++;
20260 + inc_nlink(inode);
20261 + inode->i_ctime = dir->i_ctime;
20262 + d_instantiate(dentry, au_igrab(inode));
20263 + if (d_unhashed(a->h_path.dentry))
20264 + /* some filesystem calls d_drop() */
20266 + /* some filesystems consume an inode even hardlink */
20267 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20268 + goto out_unpin; /* success */
20271 + /* no delegation since it is just created */
20272 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20273 + /*delegated*/NULL, /*force*/0);
20274 + if (unlikely(rerr)) {
20275 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20278 + au_dtime_revert(&dt);
20280 + au_unpin(&a->pin);
20284 + di_write_unlock(a->parent);
20285 + dput(a->src_parent);
20287 + if (unlikely(err)) {
20288 + au_update_dbtop(dentry);
20291 + aufs_read_and_write_unlock2(dentry, src_dentry);
20299 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20302 + aufs_bindex_t bindex;
20303 + unsigned char diropq;
20304 + struct path h_path;
20305 + struct dentry *wh_dentry, *parent, *opq_dentry;
20306 + struct inode *h_inode;
20307 + struct super_block *sb;
20309 + struct au_pin pin;
20310 + struct au_dtime dt;
20311 + } *a; /* reduce the stack usage */
20312 + struct au_wr_dir_args wr_dir_args = {
20313 + .force_btgt = -1,
20314 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20320 + a = kmalloc(sizeof(*a), GFP_NOFS);
20321 + if (unlikely(!a))
20324 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20325 + if (unlikely(err))
20327 + err = au_d_may_add(dentry);
20328 + if (unlikely(err))
20331 + parent = dentry->d_parent; /* dir inode is locked */
20332 + di_write_lock_parent(parent);
20333 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20334 + &a->pin, &wr_dir_args);
20335 + err = PTR_ERR(wh_dentry);
20336 + if (IS_ERR(wh_dentry))
20339 + sb = dentry->d_sb;
20340 + bindex = au_dbtop(dentry);
20341 + h_path.dentry = au_h_dptr(dentry, bindex);
20342 + h_path.mnt = au_sbr_mnt(sb, bindex);
20343 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20344 + if (unlikely(err))
20347 + /* make the dir opaque */
20349 + h_inode = d_inode(h_path.dentry);
20351 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20352 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20353 + opq_dentry = au_diropq_create(dentry, bindex);
20354 + inode_unlock(h_inode);
20355 + err = PTR_ERR(opq_dentry);
20356 + if (IS_ERR(opq_dentry))
20358 + dput(opq_dentry);
20362 + err = epilog(dir, bindex, wh_dentry, dentry);
20365 + goto out_unpin; /* success */
20370 + AuLabel(revert opq);
20371 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20372 + rerr = au_diropq_remove(dentry, bindex);
20373 + inode_unlock(h_inode);
20375 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20376 + dentry, err, rerr);
20382 + AuLabel(revert dir);
20383 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20385 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20386 + dentry, err, rerr);
20389 + au_dtime_revert(&a->dt);
20391 + au_unpin(&a->pin);
20394 + di_write_unlock(parent);
20396 + if (unlikely(err)) {
20397 + au_update_dbtop(dentry);
20400 + aufs_read_unlock(dentry, AuLock_DW);
20406 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20407 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20408 +++ linux/fs/aufs/i_op.c 2018-04-15 08:49:13.401150731 +0200
20411 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20413 + * This program, aufs is free software; you can redistribute it and/or modify
20414 + * it under the terms of the GNU General Public License as published by
20415 + * the Free Software Foundation; either version 2 of the License, or
20416 + * (at your option) any later version.
20418 + * This program is distributed in the hope that it will be useful,
20419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20421 + * GNU General Public License for more details.
20423 + * You should have received a copy of the GNU General Public License
20424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20428 + * inode operations (except add/del/rename)
20431 +#include <linux/device_cgroup.h>
20432 +#include <linux/fs_stack.h>
20433 +#include <linux/namei.h>
20434 +#include <linux/security.h>
20437 +static int h_permission(struct inode *h_inode, int mask,
20438 + struct path *h_path, int brperm)
20441 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20444 + if (write_mask && IS_IMMUTABLE(h_inode))
20448 + if (((mask & MAY_EXEC)
20449 + && S_ISREG(h_inode->i_mode)
20450 + && (path_noexec(h_path)
20451 + || !(h_inode->i_mode & S_IXUGO))))
20455 + * - skip the lower fs test in the case of write to ro branch.
20456 + * - nfs dir permission write check is optimized, but a policy for
20457 + * link/rename requires a real check.
20458 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
20459 + * in this case, generic_permission() returns -EOPNOTSUPP.
20461 + if ((write_mask && !au_br_writable(brperm))
20462 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20463 + && write_mask && !(mask & MAY_READ))
20464 + || !h_inode->i_op->permission) {
20465 + /* AuLabel(generic_permission); */
20466 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
20467 + err = generic_permission(h_inode, mask);
20468 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20469 + err = h_inode->i_op->permission(h_inode, mask);
20472 + /* AuLabel(h_inode->permission); */
20473 + err = h_inode->i_op->permission(h_inode, mask);
20478 + err = devcgroup_inode_permission(h_inode, mask);
20480 + err = security_inode_permission(h_inode, mask);
20484 + /* todo: do we need to call ima_path_check()? */
20485 + struct path h_path = {
20489 + err = ima_path_check(&h_path,
20490 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20491 + IMA_COUNT_LEAVE);
20499 +static int aufs_permission(struct inode *inode, int mask)
20502 + aufs_bindex_t bindex, bbot;
20503 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20504 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20505 + struct inode *h_inode;
20506 + struct super_block *sb;
20507 + struct au_branch *br;
20509 + /* todo: support rcu-walk? */
20510 + if (mask & MAY_NOT_BLOCK)
20513 + sb = inode->i_sb;
20514 + si_read_lock(sb, AuLock_FLUSH);
20515 + ii_read_lock_child(inode);
20517 + err = au_iigen_test(inode, au_sigen(sb));
20518 + if (unlikely(err))
20524 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20525 + err = au_busy_or_stale();
20526 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20527 + if (unlikely(!h_inode
20528 + || (h_inode->i_mode & S_IFMT)
20529 + != (inode->i_mode & S_IFMT)))
20533 + bindex = au_ibtop(inode);
20534 + br = au_sbr(sb, bindex);
20535 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20538 + && !special_file(h_inode->i_mode)) {
20539 + /* test whether the upper writable branch exists */
20541 + for (; bindex >= 0; bindex--)
20542 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20550 + /* non-write to dir */
20552 + bbot = au_ibbot(inode);
20553 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20554 + h_inode = au_h_iptr(inode, bindex);
20556 + err = au_busy_or_stale();
20557 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20560 + br = au_sbr(sb, bindex);
20561 + err = h_permission(h_inode, mask, &br->br_path,
20567 + ii_read_unlock(inode);
20568 + si_read_unlock(sb);
20572 +/* ---------------------------------------------------------------------- */
20574 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20575 + unsigned int flags)
20577 + struct dentry *ret, *parent;
20578 + struct inode *inode;
20579 + struct super_block *sb;
20580 + int err, npositive;
20584 + /* todo: support rcu-walk? */
20585 + ret = ERR_PTR(-ECHILD);
20586 + if (flags & LOOKUP_RCU)
20589 + ret = ERR_PTR(-ENAMETOOLONG);
20590 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20594 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20595 + ret = ERR_PTR(err);
20596 + if (unlikely(err))
20599 + err = au_di_init(dentry);
20600 + ret = ERR_PTR(err);
20601 + if (unlikely(err))
20605 + npositive = 0; /* suppress a warning */
20606 + parent = dentry->d_parent; /* dir inode is locked */
20607 + di_read_lock_parent(parent, AuLock_IR);
20608 + err = au_alive_dir(parent);
20610 + err = au_digen_test(parent, au_sigen(sb));
20612 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20613 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20614 + AuLkup_ALLOW_NEG);
20617 + di_read_unlock(parent, AuLock_IR);
20618 + ret = ERR_PTR(err);
20619 + if (unlikely(err < 0))
20623 + inode = au_new_inode(dentry, /*must_new*/0);
20624 + if (IS_ERR(inode)) {
20625 + ret = (void *)inode;
20632 + atomic_inc(&inode->i_count);
20633 + ret = d_splice_alias(inode, dentry);
20635 + if (unlikely(d_need_lookup(dentry))) {
20636 + spin_lock(&dentry->d_lock);
20637 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20638 + spin_unlock(&dentry->d_lock);
20642 + if (!IS_ERR(ret)) {
20644 + if (ret && ret != dentry)
20645 + ii_write_unlock(inode);
20647 + ii_write_unlock(inode);
20654 + di_write_unlock(dentry);
20656 + si_read_unlock(sb);
20661 +/* ---------------------------------------------------------------------- */
20663 +struct aopen_node {
20664 + struct hlist_bl_node hblist;
20665 + struct file *file, *h_file;
20668 +static int au_do_aopen(struct inode *inode, struct file *file)
20670 + struct hlist_bl_head *aopen;
20671 + struct hlist_bl_node *pos;
20672 + struct aopen_node *node;
20673 + struct au_do_open_args args = {
20675 + .open = au_do_open_nondir
20678 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20679 + hlist_bl_lock(aopen);
20680 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20681 + if (node->file == file) {
20682 + args.h_file = node->h_file;
20685 + hlist_bl_unlock(aopen);
20686 + /* AuDebugOn(!args.h_file); */
20688 + return au_do_open(file, &args);
20691 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20692 + struct file *file, unsigned int open_flag,
20693 + umode_t create_mode, int *opened)
20695 + int err, unlocked, h_opened = *opened;
20696 + unsigned int lkup_flags;
20697 + struct dentry *parent, *d;
20698 + struct hlist_bl_head *aopen;
20699 + struct vfsub_aopen_args args = {
20700 + .open_flag = open_flag,
20701 + .create_mode = create_mode,
20702 + .opened = &h_opened
20704 + struct aopen_node aopen_node = {
20709 + AuDbg("open_flag 0%o\n", open_flag);
20710 + AuDbgDentry(dentry);
20713 + if (!au_di(dentry)) {
20714 + lkup_flags = LOOKUP_OPEN;
20715 + if (open_flag & O_CREAT)
20716 + lkup_flags |= LOOKUP_CREATE;
20717 + d = aufs_lookup(dir, dentry, lkup_flags);
20719 + err = PTR_ERR(d);
20724 + * obsoleted dentry found.
20725 + * another error will be returned later.
20731 + AuDbgDentry(dentry);
20734 + if (d_is_positive(dentry)
20735 + || d_unhashed(dentry)
20736 + || d_unlinked(dentry)
20737 + || !(open_flag & O_CREAT))
20738 + goto out_no_open;
20741 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20742 + if (unlikely(err))
20745 + parent = dentry->d_parent; /* dir is locked */
20746 + di_write_lock_parent(parent);
20747 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20748 + if (unlikely(err))
20751 + AuDbgDentry(dentry);
20752 + if (d_is_positive(dentry))
20755 + args.file = get_empty_filp();
20756 + err = PTR_ERR(args.file);
20757 + if (IS_ERR(args.file))
20760 + args.file->f_flags = file->f_flags;
20761 + err = au_aopen_or_create(dir, dentry, &args);
20763 + AuDbgFile(args.file);
20764 + if (unlikely(err < 0)) {
20765 + if (h_opened & FILE_OPENED)
20768 + put_filp(args.file);
20771 + di_write_unlock(parent);
20772 + di_write_unlock(dentry);
20775 + /* some filesystems don't set FILE_CREATED while succeeded? */
20776 + *opened |= FILE_CREATED;
20777 + if (h_opened & FILE_OPENED)
20778 + aopen_node.h_file = args.file;
20780 + put_filp(args.file);
20781 + args.file = NULL;
20783 + aopen = &au_sbi(dir->i_sb)->si_aopen;
20784 + au_hbl_add(&aopen_node.hblist, aopen);
20785 + err = finish_open(file, dentry, au_do_aopen, opened);
20786 + au_hbl_del(&aopen_node.hblist, aopen);
20789 + if (aopen_node.h_file)
20790 + fput(aopen_node.h_file);
20794 + si_read_unlock(dentry->d_sb);
20796 + di_write_unlock(parent);
20797 + aufs_read_unlock(dentry, AuLock_DW);
20799 + AuDbgDentry(dentry);
20800 + if (unlikely(err < 0))
20803 + if (err >= 0 && !(*opened & FILE_CREATED)) {
20804 + AuLabel(out_no_open);
20806 + err = finish_no_open(file, dentry);
20809 + AuDbg("%pd%s%s\n", dentry,
20810 + (*opened & FILE_CREATED) ? " created" : "",
20811 + (*opened & FILE_OPENED) ? " opened" : "");
20817 +/* ---------------------------------------------------------------------- */
20819 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20820 + const unsigned char add_entry, aufs_bindex_t bcpup,
20821 + aufs_bindex_t btop)
20824 + struct dentry *h_parent;
20825 + struct inode *h_dir;
20828 + IMustLock(d_inode(parent));
20830 + di_write_lock_parent(parent);
20833 + if (!au_h_dptr(parent, bcpup)) {
20834 + if (btop > bcpup)
20835 + err = au_cpup_dirs(dentry, bcpup);
20836 + else if (btop < bcpup)
20837 + err = au_cpdown_dirs(dentry, bcpup);
20841 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20842 + h_parent = au_h_dptr(parent, bcpup);
20843 + h_dir = d_inode(h_parent);
20844 + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20845 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20846 + /* todo: no unlock here */
20847 + inode_unlock_shared(h_dir);
20849 + AuDbg("bcpup %d\n", bcpup);
20851 + if (d_really_is_negative(dentry))
20852 + au_set_h_dptr(dentry, btop, NULL);
20853 + au_update_dbrange(dentry, /*do_put_zero*/0);
20858 + di_write_unlock(parent);
20860 + err = bcpup; /* success */
20867 + * decide the branch and the parent dir where we will create a new entry.
20868 + * returns new bindex or an error.
20869 + * copyup the parent dir if needed.
20871 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20872 + struct au_wr_dir_args *args)
20875 + unsigned int flags;
20876 + aufs_bindex_t bcpup, btop, src_btop;
20877 + const unsigned char add_entry
20878 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20879 + | au_ftest_wrdir(args->flags, TMPFILE);
20880 + struct super_block *sb;
20881 + struct dentry *parent;
20882 + struct au_sbinfo *sbinfo;
20884 + sb = dentry->d_sb;
20885 + sbinfo = au_sbi(sb);
20886 + parent = dget_parent(dentry);
20887 + btop = au_dbtop(dentry);
20889 + if (args->force_btgt < 0) {
20890 + if (src_dentry) {
20891 + src_btop = au_dbtop(src_dentry);
20892 + if (src_btop < btop)
20893 + bcpup = src_btop;
20894 + } else if (add_entry) {
20896 + if (au_ftest_wrdir(args->flags, ISDIR))
20897 + au_fset_wbr(flags, DIR);
20898 + err = AuWbrCreate(sbinfo, dentry, flags);
20902 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20904 + err = AuWbrCopyup(sbinfo, dentry);
20906 + if (!IS_ROOT(dentry)) {
20907 + di_read_lock_parent(parent, !AuLock_IR);
20908 + err = AuWbrCopyup(sbinfo, dentry);
20909 + di_read_unlock(parent, !AuLock_IR);
20911 + err = AuWbrCopyup(sbinfo, dentry);
20914 + if (unlikely(err < 0))
20918 + bcpup = args->force_btgt;
20919 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20922 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20924 + if (bcpup == btop)
20925 + goto out; /* success */
20927 + /* copyup the new parent into the branch we process */
20928 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20930 + if (d_really_is_negative(dentry)) {
20931 + au_set_h_dptr(dentry, btop, NULL);
20932 + au_set_dbtop(dentry, bcpup);
20933 + au_set_dbbot(dentry, bcpup);
20935 + AuDebugOn(add_entry
20936 + && !au_ftest_wrdir(args->flags, TMPFILE)
20937 + && !au_h_dptr(dentry, bcpup));
20945 +/* ---------------------------------------------------------------------- */
20947 +void au_pin_hdir_unlock(struct au_pin *p)
20950 + au_hn_inode_unlock(p->hdir);
20953 +int au_pin_hdir_lock(struct au_pin *p)
20961 + /* even if an error happens later, keep this lock */
20962 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
20965 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
20970 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
20971 + p->h_parent, p->br);
20977 +int au_pin_hdir_relock(struct au_pin *p)
20980 + struct inode *h_i;
20981 + struct dentry *h_d[] = {
20986 + err = au_pin_hdir_lock(p);
20987 + if (unlikely(err))
20990 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
20993 + if (d_is_positive(h_d[i])) {
20994 + h_i = d_inode(h_d[i]);
20995 + err = !h_i->i_nlink;
21003 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21005 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21006 + p->hdir->hi_inode->i_rwsem.owner = task;
21010 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21013 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21014 + p->lsc_hi, 0, NULL, _RET_IP_);
21015 + au_pin_hdir_set_owner(p, current);
21019 +void au_pin_hdir_release(struct au_pin *p)
21022 + au_pin_hdir_set_owner(p, p->task);
21023 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21027 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21029 + if (pin && pin->parent)
21030 + return au_h_dptr(pin->parent, pin->bindex);
21034 +void au_unpin(struct au_pin *p)
21037 + au_pin_hdir_unlock(p);
21038 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21039 + vfsub_mnt_drop_write(p->h_mnt);
21043 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21044 + di_read_unlock(p->parent, AuLock_IR);
21045 + iput(p->hdir->hi_inode);
21047 + p->parent = NULL;
21050 + /* do not clear p->task */
21053 +int au_do_pin(struct au_pin *p)
21056 + struct super_block *sb;
21057 + struct inode *h_dir;
21060 + sb = p->dentry->d_sb;
21061 + p->br = au_sbr(sb, p->bindex);
21062 + if (IS_ROOT(p->dentry)) {
21063 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21064 + p->h_mnt = au_br_mnt(p->br);
21065 + err = vfsub_mnt_want_write(p->h_mnt);
21066 + if (unlikely(err)) {
21067 + au_fclr_pin(p->flags, MNT_WRITE);
21074 + p->h_dentry = NULL;
21075 + if (p->bindex <= au_dbbot(p->dentry))
21076 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21078 + p->parent = dget_parent(p->dentry);
21079 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21080 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21083 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21084 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21086 + h_dir = p->hdir->hi_inode;
21090 + * if DI_LOCKED is not set, then p->parent may be different
21091 + * and h_parent can be NULL.
21093 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21095 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21096 + di_read_unlock(p->parent, AuLock_IR);
21098 + p->parent = NULL;
21102 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21103 + p->h_mnt = au_br_mnt(p->br);
21104 + err = vfsub_mnt_want_write(p->h_mnt);
21105 + if (unlikely(err)) {
21106 + au_fclr_pin(p->flags, MNT_WRITE);
21107 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21108 + di_read_unlock(p->parent, AuLock_IR);
21110 + p->parent = NULL;
21116 + err = au_pin_hdir_lock(p);
21118 + goto out; /* success */
21123 + pr_err("err %d\n", err);
21124 + err = au_busy_or_stale();
21129 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21130 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21131 + unsigned int udba, unsigned char flags)
21133 + p->dentry = dentry;
21135 + p->lsc_di = lsc_di;
21136 + p->lsc_hi = lsc_hi;
21137 + p->flags = flags;
21138 + p->bindex = bindex;
21140 + p->parent = NULL;
21144 + p->h_dentry = NULL;
21145 + p->h_parent = NULL;
21147 + p->task = current;
21150 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21151 + unsigned int udba, unsigned char flags)
21153 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21155 + return au_do_pin(pin);
21158 +/* ---------------------------------------------------------------------- */
21161 + * ->setattr() and ->getattr() are called in various cases.
21162 + * chmod, stat: dentry is revalidated.
21163 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21165 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21167 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21168 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21171 + struct dentry *parent;
21174 + if (au_digen_test(dentry, sigen)) {
21175 + parent = dget_parent(dentry);
21176 + di_read_lock_parent(parent, AuLock_IR);
21177 + err = au_refresh_dentry(dentry, parent);
21178 + di_read_unlock(parent, AuLock_IR);
21186 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21187 + struct au_icpup_args *a)
21191 + aufs_bindex_t btop, ibtop;
21192 + struct dentry *hi_wh, *parent;
21193 + struct inode *inode;
21194 + struct au_wr_dir_args wr_dir_args = {
21195 + .force_btgt = -1,
21199 + if (d_is_dir(dentry))
21200 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21201 + /* plink or hi_wh() case */
21202 + btop = au_dbtop(dentry);
21203 + inode = d_inode(dentry);
21204 + ibtop = au_ibtop(inode);
21205 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21206 + wr_dir_args.force_btgt = ibtop;
21207 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21208 + if (unlikely(err < 0))
21212 + au_fset_icpup(a->flags, DID_CPUP);
21215 + a->pin_flags = AuPin_MNT_WRITE;
21217 + if (!IS_ROOT(dentry)) {
21218 + au_fset_pin(a->pin_flags, DI_LOCKED);
21219 + parent = dget_parent(dentry);
21220 + di_write_lock_parent(parent);
21223 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21224 + if (unlikely(err))
21228 + a->h_path.dentry = au_h_dptr(dentry, btop);
21229 + a->h_inode = d_inode(a->h_path.dentry);
21230 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21231 + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21232 + if (ia->ia_size < i_size_read(a->h_inode))
21233 + sz = ia->ia_size;
21234 + inode_unlock_shared(a->h_inode);
21238 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21239 + hi_wh = au_hi_wh(inode, a->btgt);
21241 + struct au_cp_generic cpg = {
21242 + .dentry = dentry,
21248 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21249 + if (unlikely(err))
21251 + hi_wh = au_hi_wh(inode, a->btgt);
21252 + /* todo: revalidate hi_wh? */
21257 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21258 + di_downgrade_lock(parent, AuLock_IR);
21262 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21263 + goto out; /* success */
21265 + if (!d_unhashed(dentry)) {
21266 + struct au_cp_generic cpg = {
21267 + .dentry = dentry,
21272 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21274 + err = au_sio_cpup_simple(&cpg);
21276 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21277 + } else if (!hi_wh)
21278 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21280 + a->h_path.dentry = hi_wh; /* do not dget here */
21283 + a->h_inode = d_inode(a->h_path.dentry);
21285 + goto out; /* success */
21286 + au_unpin(&a->pin);
21289 + di_write_unlock(parent);
21294 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21298 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21301 + struct inode *inode, *delegated;
21302 + struct super_block *sb;
21303 + struct file *file;
21304 + struct au_icpup_args *a;
21306 + inode = d_inode(dentry);
21307 + IMustLock(inode);
21309 + err = setattr_prepare(dentry, ia);
21310 + if (unlikely(err))
21314 + a = kzalloc(sizeof(*a), GFP_NOFS);
21315 + if (unlikely(!a))
21318 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21319 + ia->ia_valid &= ~ATTR_MODE;
21322 + sb = dentry->d_sb;
21323 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21324 + if (unlikely(err))
21327 + if (ia->ia_valid & ATTR_FILE) {
21328 + /* currently ftruncate(2) only */
21329 + AuDebugOn(!d_is_reg(dentry));
21330 + file = ia->ia_file;
21331 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21333 + if (unlikely(err))
21335 + ia->ia_file = au_hf_top(file);
21336 + a->udba = AuOpt_UDBA_NONE;
21338 + /* fchmod() doesn't pass ia_file */
21339 + a->udba = au_opt_udba(sb);
21340 + di_write_lock_child(dentry);
21341 + /* no d_unlinked(), to set UDBA_NONE for root */
21342 + if (d_unhashed(dentry))
21343 + a->udba = AuOpt_UDBA_NONE;
21344 + if (a->udba != AuOpt_UDBA_NONE) {
21345 + AuDebugOn(IS_ROOT(dentry));
21346 + err = au_reval_for_attr(dentry, au_sigen(sb));
21347 + if (unlikely(err))
21352 + err = au_pin_and_icpup(dentry, ia, a);
21353 + if (unlikely(err < 0))
21355 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21356 + ia->ia_file = NULL;
21357 + ia->ia_valid &= ~ATTR_FILE;
21360 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21361 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21362 + == (ATTR_MODE | ATTR_CTIME)) {
21363 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21364 + if (unlikely(err))
21366 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21367 + && (ia->ia_valid & ATTR_CTIME)) {
21368 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21369 + if (unlikely(err))
21373 + if (ia->ia_valid & ATTR_SIZE) {
21376 + if (ia->ia_size < i_size_read(inode))
21378 + truncate_setsize(inode, ia->ia_size);
21381 + if (ia->ia_valid & ATTR_FILE)
21383 + inode_unlock(a->h_inode);
21384 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21385 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21387 + delegated = NULL;
21389 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21391 + err = break_deleg_wait(&delegated);
21399 + * regardless aufs 'acl' option setting.
21400 + * why don't all acl-aware fs call this func from their ->setattr()?
21402 + if (!err && (ia->ia_valid & ATTR_MODE))
21403 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21405 + au_cpup_attr_changeable(inode);
21408 + inode_unlock(a->h_inode);
21409 + au_unpin(&a->pin);
21410 + if (unlikely(err))
21411 + au_update_dbtop(dentry);
21413 + di_write_unlock(dentry);
21415 + fi_write_unlock(file);
21416 + ia->ia_file = file;
21417 + ia->ia_valid |= ATTR_FILE;
21420 + si_read_unlock(sb);
21428 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21429 +static int au_h_path_to_set_attr(struct dentry *dentry,
21430 + struct au_icpup_args *a, struct path *h_path)
21433 + struct super_block *sb;
21435 + sb = dentry->d_sb;
21436 + a->udba = au_opt_udba(sb);
21437 + /* no d_unlinked(), to set UDBA_NONE for root */
21438 + if (d_unhashed(dentry))
21439 + a->udba = AuOpt_UDBA_NONE;
21440 + if (a->udba != AuOpt_UDBA_NONE) {
21441 + AuDebugOn(IS_ROOT(dentry));
21442 + err = au_reval_for_attr(dentry, au_sigen(sb));
21443 + if (unlikely(err))
21446 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21447 + if (unlikely(err < 0))
21450 + h_path->dentry = a->h_path.dentry;
21451 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21457 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21458 + struct au_sxattr *arg)
21461 + struct path h_path;
21462 + struct super_block *sb;
21463 + struct au_icpup_args *a;
21464 + struct inode *h_inode;
21466 + IMustLock(inode);
21469 + a = kzalloc(sizeof(*a), GFP_NOFS);
21470 + if (unlikely(!a))
21473 + sb = dentry->d_sb;
21474 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21475 + if (unlikely(err))
21478 + h_path.dentry = NULL; /* silence gcc */
21479 + di_write_lock_child(dentry);
21480 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21481 + if (unlikely(err))
21484 + inode_unlock(a->h_inode);
21485 + switch (arg->type) {
21486 + case AU_XATTR_SET:
21487 + AuDebugOn(d_is_negative(h_path.dentry));
21488 + err = vfsub_setxattr(h_path.dentry,
21489 + arg->u.set.name, arg->u.set.value,
21490 + arg->u.set.size, arg->u.set.flags);
21493 + err = -EOPNOTSUPP;
21494 + h_inode = d_inode(h_path.dentry);
21495 + if (h_inode->i_op->set_acl)
21496 + /* this will call posix_acl_update_mode */
21497 + err = h_inode->i_op->set_acl(h_inode,
21498 + arg->u.acl_set.acl,
21499 + arg->u.acl_set.type);
21503 + au_cpup_attr_timesizes(inode);
21505 + au_unpin(&a->pin);
21506 + if (unlikely(err))
21507 + au_update_dbtop(dentry);
21510 + di_write_unlock(dentry);
21511 + si_read_unlock(sb);
21520 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21521 + unsigned int nlink)
21525 + inode->i_mode = st->mode;
21526 + /* don't i_[ug]id_write() here */
21527 + inode->i_uid = st->uid;
21528 + inode->i_gid = st->gid;
21529 + inode->i_atime = st->atime;
21530 + inode->i_mtime = st->mtime;
21531 + inode->i_ctime = st->ctime;
21533 + au_cpup_attr_nlink(inode, /*force*/0);
21534 + if (S_ISDIR(inode->i_mode)) {
21535 + n = inode->i_nlink;
21538 + smp_mb(); /* for i_nlink */
21539 + /* 0 can happen */
21540 + set_nlink(inode, n);
21543 + spin_lock(&inode->i_lock);
21544 + inode->i_blocks = st->blocks;
21545 + i_size_write(inode, st->size);
21546 + spin_unlock(&inode->i_lock);
21550 + * common routine for aufs_getattr() and au_getxattr().
21551 + * returns zero or negative (an error).
21552 + * @dentry will be read-locked in success.
21554 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21558 + unsigned int mnt_flags, sigen;
21559 + unsigned char udba_none;
21560 + aufs_bindex_t bindex;
21561 + struct super_block *sb, *h_sb;
21562 + struct inode *inode;
21564 + h_path->mnt = NULL;
21565 + h_path->dentry = NULL;
21568 + sb = dentry->d_sb;
21569 + mnt_flags = au_mntflags(sb);
21570 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21572 + if (unlikely(locked))
21573 + goto body; /* skip locking dinfo */
21575 + /* support fstat(2) */
21576 + if (!d_unlinked(dentry) && !udba_none) {
21577 + sigen = au_sigen(sb);
21578 + err = au_digen_test(dentry, sigen);
21580 + di_read_lock_child(dentry, AuLock_IR);
21581 + err = au_dbrange_test(dentry);
21582 + if (unlikely(err)) {
21583 + di_read_unlock(dentry, AuLock_IR);
21587 + AuDebugOn(IS_ROOT(dentry));
21588 + di_write_lock_child(dentry);
21589 + err = au_dbrange_test(dentry);
21591 + err = au_reval_for_attr(dentry, sigen);
21593 + di_downgrade_lock(dentry, AuLock_IR);
21595 + di_write_unlock(dentry);
21600 + di_read_lock_child(dentry, AuLock_IR);
21603 + inode = d_inode(dentry);
21604 + bindex = au_ibtop(inode);
21605 + h_path->mnt = au_sbr_mnt(sb, bindex);
21606 + h_sb = h_path->mnt->mnt_sb;
21608 + && !au_test_fs_bad_iattr(h_sb)
21610 + goto out; /* success */
21612 + if (au_dbtop(dentry) == bindex)
21613 + h_path->dentry = au_h_dptr(dentry, bindex);
21614 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21615 + h_path->dentry = au_plink_lkup(inode, bindex);
21616 + if (IS_ERR(h_path->dentry))
21617 + /* pretending success */
21618 + h_path->dentry = NULL;
21620 + dput(h_path->dentry);
21627 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
21628 + struct dentry *dentry, struct kstat *st)
21631 + unsigned char positive;
21632 + struct path h_path;
21633 + struct inode *inode;
21634 + struct super_block *sb;
21636 + inode = d_inode(dentry);
21637 + sb = dentry->d_sb;
21638 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21639 + if (unlikely(err))
21641 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21642 + if (unlikely(err))
21644 + if (unlikely(!h_path.dentry))
21645 + /* illegally overlapped or something */
21646 + goto out_fill; /* pretending success */
21648 + positive = d_is_positive(h_path.dentry);
21650 + err = vfs_getattr(&h_path, st);
21653 + au_refresh_iattr(inode, st,
21654 + d_inode(h_path.dentry)->i_nlink);
21655 + goto out_fill; /* success */
21661 + generic_fillattr(inode, st);
21663 + di_read_unlock(dentry, AuLock_IR);
21665 + si_read_unlock(sb);
21671 +/* ---------------------------------------------------------------------- */
21673 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21674 + struct delayed_call *done)
21677 + struct dentry *h_dentry;
21678 + struct inode *h_inode;
21680 + aufs_bindex_t bindex;
21682 + ret = NULL; /* suppress a warning */
21687 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21688 + if (unlikely(err))
21691 + err = au_d_hashed_positive(dentry);
21692 + if (unlikely(err))
21696 + inode = d_inode(dentry);
21697 + bindex = au_ibtop(inode);
21698 + h_inode = au_h_iptr(inode, bindex);
21699 + if (unlikely(!h_inode->i_op->get_link))
21704 + if (au_dbtop(dentry) <= bindex) {
21705 + h_dentry = au_h_dptr(dentry, bindex);
21710 + h_dentry = d_find_any_alias(h_inode);
21711 + if (IS_ERR(h_dentry)) {
21712 + err = PTR_ERR(h_dentry);
21716 + if (unlikely(!h_dentry))
21720 + AuDbg("%pf\n", h_inode->i_op->get_link);
21721 + AuDbgDentry(h_dentry);
21722 + ret = vfs_get_link(h_dentry, done);
21725 + err = PTR_ERR(ret);
21728 + aufs_read_unlock(dentry, AuLock_IR);
21730 + if (unlikely(err))
21731 + ret = ERR_PTR(err);
21732 + AuTraceErrPtr(ret);
21736 +/* ---------------------------------------------------------------------- */
21738 +static int au_is_special(struct inode *inode)
21740 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21743 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
21746 + aufs_bindex_t bindex;
21747 + struct super_block *sb;
21748 + struct inode *h_inode;
21749 + struct vfsmount *h_mnt;
21751 + sb = inode->i_sb;
21752 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21753 + "unexpected s_flags 0x%lx", sb->s_flags);
21755 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21757 + si_read_lock(sb, AuLock_FLUSH);
21758 + ii_write_lock_child(inode);
21762 + bindex = au_ibtop(inode);
21763 + h_inode = au_h_iptr(inode, bindex);
21764 + if (!au_test_ro(sb, bindex, inode)) {
21765 + h_mnt = au_sbr_mnt(sb, bindex);
21766 + err = vfsub_mnt_want_write(h_mnt);
21768 + err = vfsub_update_time(h_inode, ts, flags);
21769 + vfsub_mnt_drop_write(h_mnt);
21771 + } else if (au_is_special(h_inode)) {
21773 + * Never copy-up here.
21774 + * These special files may already be opened and used for
21775 + * communicating. If we copied it up, then the communication
21776 + * would be corrupted.
21778 + AuWarn1("timestamps for i%lu are ignored "
21779 + "since it is on readonly branch (hi%lu).\n",
21780 + inode->i_ino, h_inode->i_ino);
21781 + } else if (flags & ~S_ATIME) {
21783 + AuIOErr1("unexpected flags 0x%x\n", flags);
21789 + au_cpup_attr_timesizes(inode);
21790 + ii_write_unlock(inode);
21791 + si_read_unlock(sb);
21794 + if (!err && (flags & S_VERSION))
21795 + inode_inc_iversion(inode);
21800 +/* ---------------------------------------------------------------------- */
21802 +/* no getattr version will be set by module.c:aufs_init() */
21803 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21805 + [AuIop_SYMLINK] = {
21806 + .permission = aufs_permission,
21807 +#ifdef CONFIG_FS_POSIX_ACL
21808 + .get_acl = aufs_get_acl,
21809 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21812 + .setattr = aufs_setattr,
21813 + .getattr = aufs_getattr,
21815 +#ifdef CONFIG_AUFS_XATTR
21816 + .listxattr = aufs_listxattr,
21819 + .readlink = generic_readlink,
21820 + .get_link = aufs_get_link,
21822 + /* .update_time = aufs_update_time */
21825 + .create = aufs_create,
21826 + .lookup = aufs_lookup,
21827 + .link = aufs_link,
21828 + .unlink = aufs_unlink,
21829 + .symlink = aufs_symlink,
21830 + .mkdir = aufs_mkdir,
21831 + .rmdir = aufs_rmdir,
21832 + .mknod = aufs_mknod,
21833 + .rename = aufs_rename,
21835 + .permission = aufs_permission,
21836 +#ifdef CONFIG_FS_POSIX_ACL
21837 + .get_acl = aufs_get_acl,
21838 + .set_acl = aufs_set_acl,
21841 + .setattr = aufs_setattr,
21842 + .getattr = aufs_getattr,
21844 +#ifdef CONFIG_AUFS_XATTR
21845 + .listxattr = aufs_listxattr,
21848 + .update_time = aufs_update_time,
21849 + .atomic_open = aufs_atomic_open,
21850 + .tmpfile = aufs_tmpfile
21852 + [AuIop_OTHER] = {
21853 + .permission = aufs_permission,
21854 +#ifdef CONFIG_FS_POSIX_ACL
21855 + .get_acl = aufs_get_acl,
21856 + .set_acl = aufs_set_acl,
21859 + .setattr = aufs_setattr,
21860 + .getattr = aufs_getattr,
21862 +#ifdef CONFIG_AUFS_XATTR
21863 + .listxattr = aufs_listxattr,
21866 + .update_time = aufs_update_time
21869 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21870 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21871 +++ linux/fs/aufs/i_op_del.c 2018-04-15 08:49:13.401150731 +0200
21874 + * Copyright (C) 2005-2018 Junjiro R. Okajima
21876 + * This program, aufs is free software; you can redistribute it and/or modify
21877 + * it under the terms of the GNU General Public License as published by
21878 + * the Free Software Foundation; either version 2 of the License, or
21879 + * (at your option) any later version.
21881 + * This program is distributed in the hope that it will be useful,
21882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21884 + * GNU General Public License for more details.
21886 + * You should have received a copy of the GNU General Public License
21887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21891 + * inode operations (del entry)
21897 + * decide if a new whiteout for @dentry is necessary or not.
21898 + * when it is necessary, prepare the parent dir for the upper branch whose
21899 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21900 + * be done by caller.
21902 + * 0: wh is unnecessary
21903 + * plus: wh is necessary
21906 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21908 + int need_wh, err;
21909 + aufs_bindex_t btop;
21910 + struct super_block *sb;
21912 + sb = dentry->d_sb;
21913 + btop = au_dbtop(dentry);
21914 + if (*bcpup < 0) {
21916 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21917 + err = AuWbrCopyup(au_sbi(sb), dentry);
21919 + if (unlikely(err < 0))
21923 + AuDebugOn(btop < *bcpup
21924 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21925 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21927 + if (*bcpup != btop) {
21928 + err = au_cpup_dirs(dentry, *bcpup);
21929 + if (unlikely(err))
21933 + struct au_dinfo *dinfo, *tmp;
21935 + need_wh = -ENOMEM;
21936 + dinfo = au_di(dentry);
21937 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
21939 + au_di_cp(tmp, dinfo);
21940 + au_di_swap(tmp, dinfo);
21941 + /* returns the number of positive dentries */
21942 + need_wh = au_lkup_dentry(dentry, btop + 1,
21943 + /* AuLkup_IGNORE_PERM */ 0);
21944 + au_di_swap(tmp, dinfo);
21945 + au_rw_write_unlock(&tmp->di_rwsem);
21949 + AuDbg("need_wh %d\n", need_wh);
21957 + * simple tests for the del-entry operations.
21958 + * following the checks in vfs, plus the parent-child relationship.
21960 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
21961 + struct dentry *h_parent, int isdir)
21965 + struct dentry *h_dentry, *h_latest;
21966 + struct inode *h_inode;
21968 + h_dentry = au_h_dptr(dentry, bindex);
21969 + if (d_really_is_positive(dentry)) {
21971 + if (unlikely(d_is_negative(h_dentry)))
21973 + h_inode = d_inode(h_dentry);
21974 + if (unlikely(!h_inode->i_nlink))
21977 + h_mode = h_inode->i_mode;
21980 + if (unlikely(S_ISDIR(h_mode)))
21982 + } else if (unlikely(!S_ISDIR(h_mode))) {
21987 + /* rename(2) case */
21989 + if (unlikely(d_is_positive(h_dentry)))
21994 + /* expected parent dir is locked */
21995 + if (unlikely(h_parent != h_dentry->d_parent))
22000 + * rmdir a dir may break the consistency on some filesystem.
22001 + * let's try heavy test.
22004 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22005 + && au_test_h_perm(d_inode(h_parent),
22006 + MAY_EXEC | MAY_WRITE)))
22009 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22011 + if (IS_ERR(h_latest))
22013 + if (h_latest == h_dentry)
22022 + * decide the branch where we operate for @dentry. the branch index will be set
22023 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
22024 + * dir for reverting.
22025 + * when a new whiteout is necessary, create it.
22027 +static struct dentry*
22028 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22029 + struct au_dtime *dt, struct au_pin *pin)
22031 + struct dentry *wh_dentry;
22032 + struct super_block *sb;
22033 + struct path h_path;
22034 + int err, need_wh;
22035 + unsigned int udba;
22036 + aufs_bindex_t bcpup;
22038 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22039 + wh_dentry = ERR_PTR(need_wh);
22040 + if (unlikely(need_wh < 0))
22043 + sb = dentry->d_sb;
22044 + udba = au_opt_udba(sb);
22046 + err = au_pin(pin, dentry, bcpup, udba,
22047 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22048 + wh_dentry = ERR_PTR(err);
22049 + if (unlikely(err))
22052 + h_path.dentry = au_pinned_h_parent(pin);
22053 + if (udba != AuOpt_UDBA_NONE
22054 + && au_dbtop(dentry) == bcpup) {
22055 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22056 + wh_dentry = ERR_PTR(err);
22057 + if (unlikely(err))
22061 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22062 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22063 + wh_dentry = NULL;
22065 + goto out; /* success, no need to create whiteout */
22067 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22068 + if (IS_ERR(wh_dentry))
22071 + /* returns with the parent is locked and wh_dentry is dget-ed */
22072 + goto out; /* success */
22077 + return wh_dentry;
22081 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22082 + * in order to be revertible and save time for removing many child whiteouts
22084 + * returns 1 when there are too many child whiteout and caller should remove
22085 + * them asynchronously. returns 0 when the number of children is enough small to
22086 + * remove now or the branch fs is a remote fs.
22087 + * otherwise return an error.
22089 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22090 + struct au_nhash *whlist, struct inode *dir)
22092 + int rmdir_later, err, dirwh;
22093 + struct dentry *h_dentry;
22094 + struct super_block *sb;
22095 + struct inode *inode;
22097 + sb = dentry->d_sb;
22098 + SiMustAnyLock(sb);
22099 + h_dentry = au_h_dptr(dentry, bindex);
22100 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22101 + if (unlikely(err))
22104 + /* stop monitoring */
22105 + inode = d_inode(dentry);
22106 + au_hn_free(au_hi(inode, bindex));
22108 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22109 + dirwh = au_sbi(sb)->si_dirwh;
22110 + rmdir_later = (dirwh <= 1);
22111 + if (!rmdir_later)
22112 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22115 + return rmdir_later;
22118 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22119 + if (unlikely(err)) {
22120 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22121 + h_dentry, bindex, err);
22131 + * final procedure for deleting a entry.
22132 + * maintain dentry and iattr.
22134 +static void epilog(struct inode *dir, struct dentry *dentry,
22135 + aufs_bindex_t bindex)
22137 + struct inode *inode;
22139 + inode = d_inode(dentry);
22141 + inode->i_ctime = dir->i_ctime;
22143 + au_dir_ts(dir, bindex);
22144 + dir->i_version++;
22148 + * when an error happened, remove the created whiteout and revert everything.
22150 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22151 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22152 + struct dentry *dentry, struct au_dtime *dt)
22155 + struct path h_path = {
22156 + .dentry = wh_dentry,
22157 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22160 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22162 + au_set_dbwh(dentry, bwh);
22163 + au_dtime_revert(dt);
22167 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22171 +/* ---------------------------------------------------------------------- */
22173 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22176 + aufs_bindex_t bwh, bindex, btop;
22177 + struct inode *inode, *h_dir, *delegated;
22178 + struct dentry *parent, *wh_dentry;
22179 + /* to reuduce stack size */
22181 + struct au_dtime dt;
22182 + struct au_pin pin;
22183 + struct path h_path;
22189 + a = kmalloc(sizeof(*a), GFP_NOFS);
22190 + if (unlikely(!a))
22193 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22194 + if (unlikely(err))
22196 + err = au_d_hashed_positive(dentry);
22197 + if (unlikely(err))
22199 + inode = d_inode(dentry);
22200 + IMustLock(inode);
22202 + if (unlikely(d_is_dir(dentry)))
22203 + goto out_unlock; /* possible? */
22205 + btop = au_dbtop(dentry);
22206 + bwh = au_dbwh(dentry);
22208 + parent = dentry->d_parent; /* dir inode is locked */
22209 + di_write_lock_parent(parent);
22210 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22212 + err = PTR_ERR(wh_dentry);
22213 + if (IS_ERR(wh_dentry))
22216 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22217 + a->h_path.dentry = au_h_dptr(dentry, btop);
22218 + dget(a->h_path.dentry);
22219 + if (bindex == btop) {
22220 + h_dir = au_pinned_h_dir(&a->pin);
22221 + delegated = NULL;
22222 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22223 + if (unlikely(err == -EWOULDBLOCK)) {
22224 + pr_warn("cannot retry for NFSv4 delegation"
22225 + " for an internal unlink\n");
22229 + /* dir inode is locked */
22230 + h_dir = d_inode(wh_dentry->d_parent);
22231 + IMustLock(h_dir);
22236 + vfsub_drop_nlink(inode);
22237 + epilog(dir, dentry, bindex);
22239 + /* update target timestamps */
22240 + if (bindex == btop) {
22241 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22243 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22245 + /* todo: this timestamp may be reverted later */
22246 + inode->i_ctime = h_dir->i_ctime;
22247 + goto out_unpin; /* success */
22254 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22261 + au_unpin(&a->pin);
22263 + dput(a->h_path.dentry);
22265 + di_write_unlock(parent);
22267 + aufs_read_unlock(dentry, AuLock_DW);
22274 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22276 + int err, rmdir_later;
22277 + aufs_bindex_t bwh, bindex, btop;
22278 + struct inode *inode;
22279 + struct dentry *parent, *wh_dentry, *h_dentry;
22280 + struct au_whtmp_rmdir *args;
22281 + /* to reuduce stack size */
22283 + struct au_dtime dt;
22284 + struct au_pin pin;
22290 + a = kmalloc(sizeof(*a), GFP_NOFS);
22291 + if (unlikely(!a))
22294 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22295 + if (unlikely(err))
22297 + err = au_alive_dir(dentry);
22298 + if (unlikely(err))
22300 + inode = d_inode(dentry);
22301 + IMustLock(inode);
22303 + if (unlikely(!d_is_dir(dentry)))
22304 + goto out_unlock; /* possible? */
22307 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22308 + if (unlikely(!args))
22311 + parent = dentry->d_parent; /* dir inode is locked */
22312 + di_write_lock_parent(parent);
22313 + err = au_test_empty(dentry, &args->whlist);
22314 + if (unlikely(err))
22317 + btop = au_dbtop(dentry);
22318 + bwh = au_dbwh(dentry);
22320 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22322 + err = PTR_ERR(wh_dentry);
22323 + if (IS_ERR(wh_dentry))
22326 + h_dentry = au_h_dptr(dentry, btop);
22329 + if (bindex == btop) {
22330 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22332 + rmdir_later = err;
22336 + /* stop monitoring */
22337 + au_hn_free(au_hi(inode, btop));
22339 + /* dir inode is locked */
22340 + IMustLock(d_inode(wh_dentry->d_parent));
22345 + vfsub_dead_dir(inode);
22346 + au_set_dbdiropq(dentry, -1);
22347 + epilog(dir, dentry, bindex);
22349 + if (rmdir_later) {
22350 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22354 + goto out_unpin; /* success */
22362 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22369 + au_unpin(&a->pin);
22373 + di_write_unlock(parent);
22375 + au_whtmp_rmdir_free(args);
22377 + aufs_read_unlock(dentry, AuLock_DW);
22384 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22385 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22386 +++ linux/fs/aufs/i_op_ren.c 2018-04-15 08:49:13.401150731 +0200
22389 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22391 + * This program, aufs is free software; you can redistribute it and/or modify
22392 + * it under the terms of the GNU General Public License as published by
22393 + * the Free Software Foundation; either version 2 of the License, or
22394 + * (at your option) any later version.
22396 + * This program is distributed in the hope that it will be useful,
22397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22399 + * GNU General Public License for more details.
22401 + * You should have received a copy of the GNU General Public License
22402 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22406 + * inode operation (rename entry)
22407 + * todo: this is crazy monster
22412 +enum { AuSRC, AuDST, AuSrcDst };
22413 +enum { AuPARENT, AuCHILD, AuParentChild };
22415 +#define AuRen_ISDIR_SRC 1
22416 +#define AuRen_ISDIR_DST (1 << 1)
22417 +#define AuRen_ISSAMEDIR (1 << 2)
22418 +#define AuRen_WHSRC (1 << 3)
22419 +#define AuRen_WHDST (1 << 4)
22420 +#define AuRen_MNT_WRITE (1 << 5)
22421 +#define AuRen_DT_DSTDIR (1 << 6)
22422 +#define AuRen_DIROPQ_SRC (1 << 7)
22423 +#define AuRen_DIROPQ_DST (1 << 8)
22424 +#define AuRen_DIRREN (1 << 9)
22425 +#define AuRen_DROPPED_SRC (1 << 10)
22426 +#define AuRen_DROPPED_DST (1 << 11)
22427 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22428 +#define au_fset_ren(flags, name) \
22429 + do { (flags) |= AuRen_##name; } while (0)
22430 +#define au_fclr_ren(flags, name) \
22431 + do { (flags) &= ~AuRen_##name; } while (0)
22433 +#ifndef CONFIG_AUFS_DIRREN
22434 +#undef AuRen_DIRREN
22435 +#define AuRen_DIRREN 0
22438 +struct au_ren_args {
22440 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22442 + struct inode *dir, *inode;
22443 + struct au_hinode *hdir, *hinode;
22444 + struct au_dtime dt[AuParentChild];
22445 + aufs_bindex_t btop, bdiropq;
22448 +#define src_dentry sd[AuSRC].dentry
22449 +#define src_dir sd[AuSRC].dir
22450 +#define src_inode sd[AuSRC].inode
22451 +#define src_h_dentry sd[AuSRC].h_dentry
22452 +#define src_parent sd[AuSRC].parent
22453 +#define src_h_parent sd[AuSRC].h_parent
22454 +#define src_wh_dentry sd[AuSRC].wh_dentry
22455 +#define src_hdir sd[AuSRC].hdir
22456 +#define src_hinode sd[AuSRC].hinode
22457 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22458 +#define src_dt sd[AuSRC].dt
22459 +#define src_btop sd[AuSRC].btop
22460 +#define src_bdiropq sd[AuSRC].bdiropq
22462 +#define dst_dentry sd[AuDST].dentry
22463 +#define dst_dir sd[AuDST].dir
22464 +#define dst_inode sd[AuDST].inode
22465 +#define dst_h_dentry sd[AuDST].h_dentry
22466 +#define dst_parent sd[AuDST].parent
22467 +#define dst_h_parent sd[AuDST].h_parent
22468 +#define dst_wh_dentry sd[AuDST].wh_dentry
22469 +#define dst_hdir sd[AuDST].hdir
22470 +#define dst_hinode sd[AuDST].hinode
22471 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22472 +#define dst_dt sd[AuDST].dt
22473 +#define dst_btop sd[AuDST].btop
22474 +#define dst_bdiropq sd[AuDST].bdiropq
22476 + struct dentry *h_trap;
22477 + struct au_branch *br;
22478 + struct path h_path;
22479 + struct au_nhash whlist;
22480 + aufs_bindex_t btgt, src_bwh;
22483 + unsigned short auren_flags;
22484 + unsigned char flags; /* syscall parameter */
22485 + unsigned char exchange;
22488 + struct au_whtmp_rmdir *thargs;
22489 + struct dentry *h_dst;
22490 + struct au_hinode *h_root;
22493 +/* ---------------------------------------------------------------------- */
22496 + * functions for reverting.
22497 + * when an error happened in a single rename systemcall, we should revert
22498 + * everything as if nothing happened.
22499 + * we don't need to revert the copied-up/down the parent dir since they are
22503 +#define RevertFailure(fmt, ...) do { \
22504 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22505 + ##__VA_ARGS__, err, rerr); \
22509 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22512 + struct dentry *d;
22513 +#define src_or_dst(member) a->sd[idx].member
22515 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22516 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22517 + rerr = au_diropq_remove(d, a->btgt);
22518 + au_hn_inode_unlock(src_or_dst(hinode));
22519 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22521 + RevertFailure("remove diropq %pd", d);
22523 +#undef src_or_dst_
22526 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22528 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22529 + au_ren_do_rev_diropq(err, a, AuSRC);
22530 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22531 + au_ren_do_rev_diropq(err, a, AuDST);
22534 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22537 + struct inode *delegated;
22539 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22540 + a->src_h_parent);
22541 + rerr = PTR_ERR(a->h_path.dentry);
22542 + if (IS_ERR(a->h_path.dentry)) {
22543 + RevertFailure("lkup one %pd", a->src_dentry);
22547 + delegated = NULL;
22548 + rerr = vfsub_rename(a->dst_h_dir,
22549 + au_h_dptr(a->src_dentry, a->btgt),
22550 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22551 + if (unlikely(rerr == -EWOULDBLOCK)) {
22552 + pr_warn("cannot retry for NFSv4 delegation"
22553 + " for an internal rename\n");
22556 + d_drop(a->h_path.dentry);
22557 + dput(a->h_path.dentry);
22558 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22560 + RevertFailure("rename %pd", a->src_dentry);
22563 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22566 + struct inode *delegated;
22568 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22569 + a->dst_h_parent);
22570 + rerr = PTR_ERR(a->h_path.dentry);
22571 + if (IS_ERR(a->h_path.dentry)) {
22572 + RevertFailure("lkup one %pd", a->dst_dentry);
22575 + if (d_is_positive(a->h_path.dentry)) {
22576 + d_drop(a->h_path.dentry);
22577 + dput(a->h_path.dentry);
22581 + delegated = NULL;
22582 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22583 + &delegated, a->flags);
22584 + if (unlikely(rerr == -EWOULDBLOCK)) {
22585 + pr_warn("cannot retry for NFSv4 delegation"
22586 + " for an internal rename\n");
22589 + d_drop(a->h_path.dentry);
22590 + dput(a->h_path.dentry);
22592 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22594 + RevertFailure("rename %pd", a->h_dst);
22597 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22601 + a->h_path.dentry = a->src_wh_dentry;
22602 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22603 + au_set_dbwh(a->src_dentry, a->src_bwh);
22605 + RevertFailure("unlink %pd", a->src_wh_dentry);
22607 +#undef RevertFailure
22609 +/* ---------------------------------------------------------------------- */
22612 + * when we have to copyup the renaming entry, do it with the rename-target name
22613 + * in order to minimize the cost (the later actual rename is unnecessary).
22614 + * otherwise rename it on the target branch.
22616 +static int au_ren_or_cpup(struct au_ren_args *a)
22619 + struct dentry *d;
22620 + struct inode *delegated;
22622 + d = a->src_dentry;
22623 + if (au_dbtop(d) == a->btgt) {
22624 + a->h_path.dentry = a->dst_h_dentry;
22625 + AuDebugOn(au_dbtop(d) != a->btgt);
22626 + delegated = NULL;
22627 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22628 + a->dst_h_dir, &a->h_path, &delegated,
22630 + if (unlikely(err == -EWOULDBLOCK)) {
22631 + pr_warn("cannot retry for NFSv4 delegation"
22632 + " for an internal rename\n");
22638 + if (!err && a->h_dst)
22639 + /* it will be set to dinfo later */
22645 +/* cf. aufs_rmdir() */
22646 +static int au_ren_del_whtmp(struct au_ren_args *a)
22649 + struct inode *dir;
22651 + dir = a->dst_dir;
22652 + SiMustAnyLock(dir->i_sb);
22653 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22654 + au_sbi(dir->i_sb)->si_dirwh)
22655 + || au_test_fs_remote(a->h_dst->d_sb)) {
22656 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22657 + if (unlikely(err))
22658 + pr_warn("failed removing whtmp dir %pd (%d), "
22659 + "ignored.\n", a->h_dst, err);
22661 + au_nhash_wh_free(&a->thargs->whlist);
22662 + a->thargs->whlist = a->whlist;
22663 + a->whlist.nh_num = 0;
22664 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22666 + a->thargs = NULL;
22672 +/* make it 'opaque' dir. */
22673 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22676 + struct dentry *d, *diropq;
22677 +#define src_or_dst(member) a->sd[idx].member
22680 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22681 + src_or_dst(bdiropq) = au_dbdiropq(d);
22682 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22683 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22684 + diropq = au_diropq_create(d, a->btgt);
22685 + au_hn_inode_unlock(src_or_dst(hinode));
22686 + if (IS_ERR(diropq))
22687 + err = PTR_ERR(diropq);
22691 +#undef src_or_dst_
22695 +static int au_ren_diropq(struct au_ren_args *a)
22698 + unsigned char always;
22699 + struct dentry *d;
22702 + d = a->dst_dentry; /* already renamed on the branch */
22703 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22704 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22705 + && !au_ftest_ren(a->auren_flags, DIRREN)
22706 + && a->btgt != au_dbdiropq(a->src_dentry)
22707 + && (a->dst_wh_dentry
22708 + || a->btgt <= au_dbdiropq(d)
22709 + /* hide the lower to keep xino */
22710 + /* the lowers may not be a dir, but we hide them anyway */
22711 + || a->btgt < au_dbbot(d)
22714 + err = au_ren_do_diropq(a, AuSRC);
22715 + if (unlikely(err))
22717 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22719 + if (!a->exchange)
22720 + goto out; /* success */
22722 + d = a->src_dentry; /* already renamed on the branch */
22723 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22724 + && a->btgt != au_dbdiropq(a->dst_dentry)
22725 + && (a->btgt < au_dbdiropq(d)
22726 + || a->btgt < au_dbbot(d)
22728 + AuDbgDentry(a->src_dentry);
22729 + AuDbgDentry(a->dst_dentry);
22730 + err = au_ren_do_diropq(a, AuDST);
22731 + if (unlikely(err))
22732 + goto out_rev_src;
22733 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22735 + goto out; /* success */
22738 + AuDbg("err %d, reverting src\n", err);
22739 + au_ren_rev_diropq(err, a);
22744 +static int do_rename(struct au_ren_args *a)
22747 + struct dentry *d, *h_d;
22749 + if (!a->exchange) {
22750 + /* prepare workqueue args for asynchronous rmdir */
22751 + h_d = a->dst_h_dentry;
22752 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22753 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22754 + && d_is_positive(h_d)) {
22756 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22758 + if (unlikely(!a->thargs))
22760 + a->h_dst = dget(h_d);
22763 + /* create whiteout for src_dentry */
22764 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22765 + a->src_bwh = au_dbwh(a->src_dentry);
22766 + AuDebugOn(a->src_bwh >= 0);
22767 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22768 + a->src_h_parent);
22769 + err = PTR_ERR(a->src_wh_dentry);
22770 + if (IS_ERR(a->src_wh_dentry))
22774 + /* lookup whiteout for dentry */
22775 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22776 + h_d = au_wh_lkup(a->dst_h_parent,
22777 + &a->dst_dentry->d_name, a->br);
22778 + err = PTR_ERR(h_d);
22781 + if (d_is_negative(h_d))
22784 + a->dst_wh_dentry = h_d;
22787 + /* rename dentry to tmpwh */
22789 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22790 + if (unlikely(err))
22793 + d = a->dst_dentry;
22794 + au_set_h_dptr(d, a->btgt, NULL);
22795 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22796 + if (unlikely(err))
22798 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22802 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22804 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22805 + && d_is_positive(a->dst_h_dentry)
22806 + && a->src_btop != a->btgt);
22809 + /* rename by vfs_rename or cpup */
22810 + err = au_ren_or_cpup(a);
22811 + if (unlikely(err))
22812 + /* leave the copied-up one */
22815 + /* make dir opaque */
22816 + err = au_ren_diropq(a);
22817 + if (unlikely(err))
22820 + /* update target timestamps */
22821 + if (a->exchange) {
22822 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22823 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22824 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22825 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22827 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22828 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22829 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22830 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22832 + if (!a->exchange) {
22833 + /* remove whiteout for dentry */
22834 + if (a->dst_wh_dentry) {
22835 + a->h_path.dentry = a->dst_wh_dentry;
22836 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22838 + if (unlikely(err))
22842 + /* remove whtmp */
22844 + au_ren_del_whtmp(a); /* ignore this error */
22846 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22849 + goto out_success;
22852 + au_ren_rev_diropq(err, a);
22854 + au_ren_rev_rename(err, a);
22858 + au_ren_rev_whtmp(err, a);
22860 + dput(a->dst_wh_dentry);
22861 + a->dst_wh_dentry = NULL;
22863 + if (a->src_wh_dentry)
22864 + au_ren_rev_whsrc(err, a);
22866 + dput(a->src_wh_dentry);
22867 + dput(a->dst_wh_dentry);
22871 + au_whtmp_rmdir_free(a->thargs);
22872 + a->thargs = NULL;
22878 +/* ---------------------------------------------------------------------- */
22881 + * test if @dentry dir can be rename destination or not.
22882 + * success means, it is a logically empty dir.
22884 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22886 + return au_test_empty(dentry, whlist);
22890 + * test if @a->src_dentry dir can be rename source or not.
22891 + * if it can, return 0.
22893 + * - it is a logically empty dir.
22894 + * - or, it exists on writable branch and has no children including whiteouts
22895 + * on the lower branch unless DIRREN is on.
22897 +static int may_rename_srcdir(struct au_ren_args *a)
22900 + unsigned int rdhash;
22901 + aufs_bindex_t btop, btgt;
22902 + struct dentry *dentry;
22903 + struct super_block *sb;
22904 + struct au_sbinfo *sbinfo;
22906 + dentry = a->src_dentry;
22907 + sb = dentry->d_sb;
22908 + sbinfo = au_sbi(sb);
22909 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22910 + au_fset_ren(a->auren_flags, DIRREN);
22913 + btop = au_dbtop(dentry);
22914 + if (btop != btgt) {
22915 + struct au_nhash whlist;
22917 + SiMustAnyLock(sb);
22918 + rdhash = sbinfo->si_rdhash;
22920 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22922 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22923 + if (unlikely(err))
22925 + err = au_test_empty(dentry, &whlist);
22926 + au_nhash_wh_free(&whlist);
22930 + if (btop == au_dbtaildir(dentry))
22931 + return 0; /* success */
22933 + err = au_test_empty_lower(dentry);
22936 + if (err == -ENOTEMPTY) {
22937 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
22940 + AuWarn1("renaming dir who has child(ren) on multiple "
22941 + "branches, is not supported\n");
22948 +/* side effect: sets whlist and h_dentry */
22949 +static int au_ren_may_dir(struct au_ren_args *a)
22952 + unsigned int rdhash;
22953 + struct dentry *d;
22955 + d = a->dst_dentry;
22956 + SiMustAnyLock(d->d_sb);
22959 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
22960 + rdhash = au_sbi(d->d_sb)->si_rdhash;
22962 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
22963 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
22964 + if (unlikely(err))
22967 + if (!a->exchange) {
22968 + au_set_dbtop(d, a->dst_btop);
22969 + err = may_rename_dstdir(d, &a->whlist);
22970 + au_set_dbtop(d, a->btgt);
22972 + err = may_rename_srcdir(a);
22974 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
22975 + if (unlikely(err))
22978 + d = a->src_dentry;
22979 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
22980 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
22981 + err = may_rename_srcdir(a);
22982 + if (unlikely(err)) {
22983 + au_nhash_wh_free(&a->whlist);
22984 + a->whlist.nh_num = 0;
22991 +/* ---------------------------------------------------------------------- */
22994 + * simple tests for rename.
22995 + * following the checks in vfs, plus the parent-child relationship.
22997 +static int au_may_ren(struct au_ren_args *a)
23000 + struct inode *h_inode;
23002 + if (a->src_btop == a->btgt) {
23003 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23004 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23005 + if (unlikely(err))
23008 + if (unlikely(a->src_h_dentry == a->h_trap))
23013 + if (a->dst_btop != a->btgt)
23016 + err = -ENOTEMPTY;
23017 + if (unlikely(a->dst_h_dentry == a->h_trap))
23021 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23022 + if (d_really_is_negative(a->dst_dentry)) {
23023 + if (d_is_negative(a->dst_h_dentry))
23024 + err = au_may_add(a->dst_dentry, a->btgt,
23025 + a->dst_h_parent, isdir);
23027 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23029 + h_inode = d_inode(a->dst_h_dentry);
23030 + if (h_inode->i_nlink)
23031 + err = au_may_del(a->dst_dentry, a->btgt,
23032 + a->dst_h_parent, isdir);
23036 + if (unlikely(err == -ENOENT || err == -EEXIST))
23042 +/* ---------------------------------------------------------------------- */
23047 + * - src_dir and dir by lock_rename()
23048 + * - inode if exitsts
23051 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23053 + * + di_write_lock2_child()
23054 + * + di_write_lock_child()
23055 + * + ii_write_lock_child()
23056 + * + di_write_lock_child2()
23057 + * + ii_write_lock_child2()
23058 + * + src_parent and parent
23059 + * + di_write_lock_parent()
23060 + * + ii_write_lock_parent()
23061 + * + di_write_lock_parent2()
23062 + * + ii_write_lock_parent2()
23063 + * + lower src_dir and dir by vfsub_lock_rename()
23064 + * + verify the every relationships between child and parent. if any
23065 + * of them failed, unlock all and return -EBUSY.
23067 +static void au_ren_unlock(struct au_ren_args *a)
23069 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23070 + a->dst_h_parent, a->dst_hdir);
23071 + if (au_ftest_ren(a->auren_flags, DIRREN)
23073 + au_hn_inode_unlock(a->h_root);
23074 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23075 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23078 +static int au_ren_lock(struct au_ren_args *a)
23081 + unsigned int udba;
23084 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23085 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23086 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23087 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23089 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23090 + if (unlikely(err))
23092 + au_fset_ren(a->auren_flags, MNT_WRITE);
23093 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23094 + struct dentry *root;
23095 + struct inode *dir;
23098 + * sbinfo is already locked, so this ii_read_lock is
23099 + * unnecessary. but our debugging feature checks it.
23101 + root = a->src_inode->i_sb->s_root;
23102 + if (root != a->src_parent && root != a->dst_parent) {
23103 + dir = d_inode(root);
23104 + ii_read_lock_parent3(dir);
23105 + a->h_root = au_hi(dir, a->btgt);
23106 + ii_read_unlock(dir);
23107 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23110 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23111 + a->dst_h_parent, a->dst_hdir);
23112 + udba = au_opt_udba(a->src_dentry->d_sb);
23113 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23114 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23115 + err = au_busy_or_stale();
23116 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23117 + err = au_h_verify(a->src_h_dentry, udba,
23118 + d_inode(a->src_h_parent), a->src_h_parent,
23120 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23121 + err = au_h_verify(a->dst_h_dentry, udba,
23122 + d_inode(a->dst_h_parent), a->dst_h_parent,
23125 + goto out; /* success */
23127 + err = au_busy_or_stale();
23128 + au_ren_unlock(a);
23134 +/* ---------------------------------------------------------------------- */
23136 +static void au_ren_refresh_dir(struct au_ren_args *a)
23138 + struct inode *dir;
23140 + dir = a->dst_dir;
23141 + dir->i_version++;
23142 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23143 + /* is this updating defined in POSIX? */
23144 + au_cpup_attr_timesizes(a->src_inode);
23145 + au_cpup_attr_nlink(dir, /*force*/1);
23147 + au_dir_ts(dir, a->btgt);
23149 + if (a->exchange) {
23150 + dir = a->src_dir;
23151 + dir->i_version++;
23152 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23153 + /* is this updating defined in POSIX? */
23154 + au_cpup_attr_timesizes(a->dst_inode);
23155 + au_cpup_attr_nlink(dir, /*force*/1);
23157 + au_dir_ts(dir, a->btgt);
23160 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23163 + dir = a->src_dir;
23164 + dir->i_version++;
23165 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23166 + au_cpup_attr_nlink(dir, /*force*/1);
23167 + au_dir_ts(dir, a->btgt);
23170 +static void au_ren_refresh(struct au_ren_args *a)
23172 + aufs_bindex_t bbot, bindex;
23173 + struct dentry *d, *h_d;
23174 + struct inode *i, *h_i;
23175 + struct super_block *sb;
23177 + d = a->dst_dentry;
23180 + /* already dget-ed by au_ren_or_cpup() */
23181 + au_set_h_dptr(d, a->btgt, a->h_dst);
23183 + i = a->dst_inode;
23185 + if (!a->exchange) {
23186 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23187 + vfsub_drop_nlink(i);
23189 + vfsub_dead_dir(i);
23190 + au_cpup_attr_timesizes(i);
23192 + au_update_dbrange(d, /*do_put_zero*/1);
23194 + au_cpup_attr_nlink(i, /*force*/1);
23197 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23198 + au_set_h_dptr(d, bindex, NULL);
23199 + bbot = au_dbbot(d);
23200 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23201 + au_set_h_dptr(d, bindex, NULL);
23202 + au_update_dbrange(d, /*do_put_zero*/0);
23206 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23207 + d_drop(a->src_dentry);
23208 + if (au_ftest_ren(a->auren_flags, DIRREN))
23209 + au_set_dbwh(a->src_dentry, -1);
23213 + d = a->src_dentry;
23214 + au_set_dbwh(d, -1);
23215 + bbot = au_dbbot(d);
23216 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23217 + h_d = au_h_dptr(d, bindex);
23219 + au_set_h_dptr(d, bindex, NULL);
23221 + au_set_dbbot(d, a->btgt);
23224 + i = a->src_inode;
23225 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23226 + return; /* success */
23228 + bbot = au_ibbot(i);
23229 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23230 + h_i = au_h_iptr(i, bindex);
23232 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23233 + /* ignore this error */
23234 + au_set_h_iptr(i, bindex, NULL, 0);
23237 + au_set_ibbot(i, a->btgt);
23240 +/* ---------------------------------------------------------------------- */
23242 +/* mainly for link(2) and rename(2) */
23243 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23245 + aufs_bindex_t bdiropq, bwh;
23246 + struct dentry *parent;
23247 + struct au_branch *br;
23249 + parent = dentry->d_parent;
23250 + IMustLock(d_inode(parent)); /* dir is locked */
23252 + bdiropq = au_dbdiropq(parent);
23253 + bwh = au_dbwh(dentry);
23254 + br = au_sbr(dentry->d_sb, btgt);
23255 + if (au_br_rdonly(br)
23256 + || (0 <= bdiropq && bdiropq < btgt)
23257 + || (0 <= bwh && bwh < btgt))
23260 + AuDbg("btgt %d\n", btgt);
23264 +/* sets src_btop, dst_btop and btgt */
23265 +static int au_ren_wbr(struct au_ren_args *a)
23268 + struct au_wr_dir_args wr_dir_args = {
23269 + /* .force_btgt = -1, */
23270 + .flags = AuWrDir_ADD_ENTRY
23273 + a->src_btop = au_dbtop(a->src_dentry);
23274 + a->dst_btop = au_dbtop(a->dst_dentry);
23275 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23276 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23277 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23278 + wr_dir_args.force_btgt = a->src_btop;
23279 + if (a->dst_inode && a->dst_btop < a->src_btop)
23280 + wr_dir_args.force_btgt = a->dst_btop;
23281 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23282 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23285 + au_update_dbtop(a->dst_dentry);
23290 +static void au_ren_dt(struct au_ren_args *a)
23292 + a->h_path.dentry = a->src_h_parent;
23293 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23294 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23295 + a->h_path.dentry = a->dst_h_parent;
23296 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23299 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23300 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23304 + a->h_path.dentry = a->src_h_dentry;
23305 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23306 + if (d_is_positive(a->dst_h_dentry)) {
23307 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23308 + a->h_path.dentry = a->dst_h_dentry;
23309 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23313 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23315 + struct dentry *h_d;
23316 + struct inode *h_inode;
23318 + au_dtime_revert(a->src_dt + AuPARENT);
23319 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23320 + au_dtime_revert(a->dst_dt + AuPARENT);
23322 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23323 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23324 + h_inode = d_inode(h_d);
23325 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23326 + au_dtime_revert(a->src_dt + AuCHILD);
23327 + inode_unlock(h_inode);
23329 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23330 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23331 + h_inode = d_inode(h_d);
23332 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23333 + au_dtime_revert(a->dst_dt + AuCHILD);
23334 + inode_unlock(h_inode);
23339 +/* ---------------------------------------------------------------------- */
23341 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23342 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23343 + unsigned int _flags)
23345 + int err, lock_flags;
23347 + /* reduce stack space */
23348 + struct au_ren_args *a;
23349 + struct au_pin pin;
23351 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23352 + IMustLock(_src_dir);
23353 + IMustLock(_dst_dir);
23356 + if (unlikely(_flags & RENAME_WHITEOUT))
23360 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23361 + a = kzalloc(sizeof(*a), GFP_NOFS);
23362 + if (unlikely(!a))
23365 + a->flags = _flags;
23366 + a->exchange = _flags & RENAME_EXCHANGE;
23367 + a->src_dir = _src_dir;
23368 + a->src_dentry = _src_dentry;
23369 + a->src_inode = NULL;
23370 + if (d_really_is_positive(a->src_dentry))
23371 + a->src_inode = d_inode(a->src_dentry);
23372 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23373 + a->dst_dir = _dst_dir;
23374 + a->dst_dentry = _dst_dentry;
23375 + a->dst_inode = NULL;
23376 + if (d_really_is_positive(a->dst_dentry))
23377 + a->dst_inode = d_inode(a->dst_dentry);
23378 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23379 + if (a->dst_inode) {
23381 + * if EXCHANGE && src is non-dir && dst is dir,
23382 + * dst is not locked.
23384 + /* IMustLock(a->dst_inode); */
23385 + au_igrab(a->dst_inode);
23389 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23390 + if (d_is_dir(a->src_dentry)) {
23391 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23392 + if (unlikely(!a->exchange
23393 + && d_really_is_positive(a->dst_dentry)
23394 + && !d_is_dir(a->dst_dentry)))
23396 + lock_flags |= AuLock_DIRS;
23398 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23399 + au_fset_ren(a->auren_flags, ISDIR_DST);
23400 + if (unlikely(!a->exchange
23401 + && d_really_is_positive(a->src_dentry)
23402 + && !d_is_dir(a->src_dentry)))
23404 + lock_flags |= AuLock_DIRS;
23406 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23408 + if (unlikely(err))
23411 + err = au_d_hashed_positive(a->src_dentry);
23412 + if (unlikely(err))
23415 + if (a->dst_inode) {
23417 + * If it is a dir, VFS unhash it before this
23418 + * function. It means we cannot rely upon d_unhashed().
23420 + if (unlikely(!a->dst_inode->i_nlink))
23422 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23423 + err = au_d_hashed_positive(a->dst_dentry);
23424 + if (unlikely(err && !a->exchange))
23426 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23428 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23432 + * is it possible?
23433 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23434 + * there may exist a problem somewhere else.
23437 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23440 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23441 + di_write_lock_parent(a->dst_parent);
23443 + /* which branch we process */
23444 + err = au_ren_wbr(a);
23445 + if (unlikely(err < 0))
23447 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23448 + a->h_path.mnt = au_br_mnt(a->br);
23450 + /* are they available to be renamed */
23451 + err = au_ren_may_dir(a);
23452 + if (unlikely(err))
23453 + goto out_children;
23455 + /* prepare the writable parent dir on the same branch */
23456 + if (a->dst_btop == a->btgt) {
23457 + au_fset_ren(a->auren_flags, WHDST);
23459 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23460 + if (unlikely(err))
23461 + goto out_children;
23465 + if (!a->exchange) {
23466 + if (a->src_dir != a->dst_dir) {
23468 + * this temporary unlock is safe,
23469 + * because both dir->i_mutex are locked.
23471 + di_write_unlock(a->dst_parent);
23472 + di_write_lock_parent(a->src_parent);
23473 + err = au_wr_dir_need_wh(a->src_dentry,
23474 + au_ftest_ren(a->auren_flags,
23477 + di_write_unlock(a->src_parent);
23478 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23480 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23482 + err = au_wr_dir_need_wh(a->src_dentry,
23483 + au_ftest_ren(a->auren_flags,
23487 + if (unlikely(err < 0))
23488 + goto out_children;
23490 + au_fset_ren(a->auren_flags, WHSRC);
23493 + if (a->src_btop != a->btgt) {
23494 + err = au_pin(&pin, a->src_dentry, a->btgt,
23495 + au_opt_udba(a->src_dentry->d_sb),
23496 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23498 + struct au_cp_generic cpg = {
23499 + .dentry = a->src_dentry,
23501 + .bsrc = a->src_btop,
23504 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23506 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23507 + err = au_sio_cpup_simple(&cpg);
23510 + if (unlikely(err))
23511 + goto out_children;
23512 + a->src_btop = a->btgt;
23513 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23514 + if (!a->exchange)
23515 + au_fset_ren(a->auren_flags, WHSRC);
23519 + if (a->exchange && a->dst_inode
23520 + && a->dst_btop != a->btgt) {
23521 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23522 + au_opt_udba(a->dst_dentry->d_sb),
23523 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23525 + struct au_cp_generic cpg = {
23526 + .dentry = a->dst_dentry,
23528 + .bsrc = a->dst_btop,
23531 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23533 + err = au_sio_cpup_simple(&cpg);
23536 + if (unlikely(err))
23537 + goto out_children;
23538 + a->dst_btop = a->btgt;
23539 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23542 + /* lock them all */
23543 + err = au_ren_lock(a);
23544 + if (unlikely(err))
23545 + /* leave the copied-up one */
23546 + goto out_children;
23548 + if (!a->exchange) {
23549 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23550 + err = au_may_ren(a);
23551 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23552 + err = -ENAMETOOLONG;
23553 + if (unlikely(err))
23557 + /* store timestamps to be revertible */
23560 + /* store dirren info */
23561 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23562 + err = au_dr_rename(a->src_dentry, a->btgt,
23563 + &a->dst_dentry->d_name, &rev);
23565 + if (unlikely(err))
23570 + err = do_rename(a);
23571 + if (unlikely(err))
23574 + if (au_ftest_ren(a->auren_flags, DIRREN))
23575 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23577 + /* update dir attributes */
23578 + au_ren_refresh_dir(a);
23580 + /* dput/iput all lower dentries */
23581 + au_ren_refresh(a);
23583 + goto out_hdir; /* success */
23586 + if (au_ftest_ren(a->auren_flags, DIRREN))
23587 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23589 + au_ren_rev_dt(err, a);
23591 + au_ren_unlock(a);
23593 + au_nhash_wh_free(&a->whlist);
23594 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23595 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23596 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23597 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23601 + if (d_unhashed(a->src_dentry))
23602 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23603 + if (d_unhashed(a->dst_dentry))
23604 + au_fset_ren(a->auren_flags, DROPPED_DST);
23605 + if (!a->exchange)
23606 + d_move(a->src_dentry, a->dst_dentry);
23608 + d_exchange(a->src_dentry, a->dst_dentry);
23609 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23610 + d_drop(a->dst_dentry);
23612 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23613 + d_drop(a->src_dentry);
23615 + au_update_dbtop(a->dst_dentry);
23616 + if (!a->dst_inode)
23617 + d_drop(a->dst_dentry);
23619 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23620 + di_write_unlock(a->dst_parent);
23622 + di_write_unlock2(a->src_parent, a->dst_parent);
23624 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23626 + iput(a->dst_inode);
23628 + au_whtmp_rmdir_free(a->thargs);
23634 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23635 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23636 +++ linux/fs/aufs/Kconfig 2018-04-15 08:49:13.394483860 +0200
23639 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23641 + Aufs is a stackable unification filesystem such as Unionfs,
23642 + which unifies several directories and provides a merged single
23644 + In the early days, aufs was entirely re-designed and
23645 + re-implemented Unionfs Version 1.x series. Introducing many
23646 + original ideas, approaches and improvements, it becomes totally
23647 + different from Unionfs while keeping the basic features.
23651 + prompt "Maximum number of branches"
23652 + default AUFS_BRANCH_MAX_127
23654 + Specifies the maximum number of branches (or member directories)
23655 + in a single aufs. The larger value consumes more system
23656 + resources and has a minor impact to performance.
23657 +config AUFS_BRANCH_MAX_127
23660 + Specifies the maximum number of branches (or member directories)
23661 + in a single aufs. The larger value consumes more system
23662 + resources and has a minor impact to performance.
23663 +config AUFS_BRANCH_MAX_511
23666 + Specifies the maximum number of branches (or member directories)
23667 + in a single aufs. The larger value consumes more system
23668 + resources and has a minor impact to performance.
23669 +config AUFS_BRANCH_MAX_1023
23672 + Specifies the maximum number of branches (or member directories)
23673 + in a single aufs. The larger value consumes more system
23674 + resources and has a minor impact to performance.
23675 +config AUFS_BRANCH_MAX_32767
23678 + Specifies the maximum number of branches (or member directories)
23679 + in a single aufs. The larger value consumes more system
23680 + resources and has a minor impact to performance.
23683 +config AUFS_SBILIST
23685 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23688 + Automatic configuration for internal use.
23689 + When aufs supports Magic SysRq or /proc, enabled automatically.
23691 +config AUFS_HNOTIFY
23692 + bool "Detect direct branch access (bypassing aufs)"
23694 + If you want to modify files on branches directly, eg. bypassing aufs,
23695 + and want aufs to detect the changes of them fully, then enable this
23696 + option and use 'udba=notify' mount option.
23697 + Currently there is only one available configuration, "fsnotify".
23698 + It will have a negative impact to the performance.
23699 + See detail in aufs.5.
23702 + prompt "method" if AUFS_HNOTIFY
23703 + default AUFS_HFSNOTIFY
23704 +config AUFS_HFSNOTIFY
23709 +config AUFS_EXPORT
23710 + bool "NFS-exportable aufs"
23711 + depends on EXPORTFS
23713 + If you want to export your mounted aufs via NFS, then enable this
23714 + option. There are several requirements for this configuration.
23715 + See detail in aufs.5.
23717 +config AUFS_INO_T_64
23719 + depends on AUFS_EXPORT
23720 + depends on 64BIT && !(ALPHA || S390)
23723 + Automatic configuration for internal use.
23724 + /* typedef unsigned long/int __kernel_ino_t */
23725 + /* alpha and s390x are int */
23728 + bool "support for XATTR/EA (including Security Labels)"
23730 + If your branch fs supports XATTR/EA and you want to make them
23731 + available in aufs too, then enable this opsion and specify the
23732 + branch attributes for EA.
23733 + See detail in aufs.5.
23736 + bool "File-based Hierarchical Storage Management"
23738 + Hierarchical Storage Management (or HSM) is a well-known feature
23739 + in the storage world. Aufs provides this feature as file-based.
23740 + with multiple branches.
23741 + These multiple branches are prioritized, ie. the topmost one
23742 + should be the fastest drive and be used heavily.
23745 + bool "Readdir in userspace"
23747 + Aufs has two methods to provide a merged view for a directory,
23748 + by a user-space library and by kernel-space natively. The latter
23749 + is always enabled but sometimes large and slow.
23750 + If you enable this option, install the library in aufs2-util
23751 + package, and set some environment variables for your readdir(3),
23752 + then the work will be handled in user-space which generally
23753 + shows better performance in most cases.
23754 + See detail in aufs.5.
23756 +config AUFS_DIRREN
23757 + bool "Workaround for rename(2)-ing a directory"
23759 + By default, aufs returns EXDEV error in renameing a dir who has
23760 + his child on the lower branch, since it is a bad idea to issue
23761 + rename(2) internally for every lower branch. But user may not
23762 + accept this behaviour. So here is a workaround to allow such
23763 + rename(2) and store some extra infromation on the writable
23764 + branch. Obviously this costs high (and I don't like it).
23765 + To use this feature, you need to enable this configuration AND
23766 + to specify the mount option `dirren.'
23767 + See details in aufs.5 and the design documents.
23770 + bool "Show whiteouts"
23772 + If you want to make the whiteouts in aufs visible, then enable
23773 + this option and specify 'shwh' mount option. Although it may
23774 + sounds like philosophy or something, but in technically it
23775 + simply shows the name of whiteout with keeping its behaviour.
23777 +config AUFS_BR_RAMFS
23778 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23780 + If you want to use ramfs as an aufs branch fs, then enable this
23781 + option. Generally tmpfs is recommended.
23782 + Aufs prohibited them to be a branch fs by default, because
23783 + initramfs becomes unusable after switch_root or something
23784 + generally. If you sets initramfs as an aufs branch and boot your
23785 + system by switch_root, you will meet a problem easily since the
23786 + files in initramfs may be inaccessible.
23787 + Unless you are going to use ramfs as an aufs branch fs without
23788 + switch_root or something, leave it N.
23790 +config AUFS_BR_FUSE
23791 + bool "Fuse fs as an aufs branch"
23792 + depends on FUSE_FS
23795 + If you want to use fuse-based userspace filesystem as an aufs
23796 + branch fs, then enable this option.
23797 + It implements the internal poll(2) operation which is
23798 + implemented by fuse only (curretnly).
23803 + Automatic configuration for internal use.
23805 +config AUFS_BR_HFSPLUS
23806 + bool "Hfsplus as an aufs branch"
23807 + depends on HFSPLUS_FS
23810 + If you want to use hfsplus fs as an aufs branch fs, then enable
23811 + this option. This option introduces a small overhead at
23812 + copying-up a file on hfsplus.
23814 +config AUFS_BDEV_LOOP
23816 + depends on BLK_DEV_LOOP
23819 + Automatic configuration for internal use.
23820 + Convert =[ym] into =y.
23823 + bool "Debug aufs"
23825 + Enable this to compile aufs internal debug code.
23826 + It will have a negative impact to the performance.
23828 +config AUFS_MAGIC_SYSRQ
23830 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23833 + Automatic configuration for internal use.
23834 + When aufs supports Magic SysRq, enabled automatically.
23836 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
23837 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
23838 +++ linux/fs/aufs/loop.c 2018-04-15 08:49:13.401150731 +0200
23841 + * Copyright (C) 2005-2018 Junjiro R. Okajima
23843 + * This program, aufs is free software; you can redistribute it and/or modify
23844 + * it under the terms of the GNU General Public License as published by
23845 + * the Free Software Foundation; either version 2 of the License, or
23846 + * (at your option) any later version.
23848 + * This program is distributed in the hope that it will be useful,
23849 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23850 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23851 + * GNU General Public License for more details.
23853 + * You should have received a copy of the GNU General Public License
23854 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23858 + * support for loopback block device as a branch
23863 +/* added into drivers/block/loop.c */
23864 +static struct file *(*backing_file_func)(struct super_block *sb);
23867 + * test if two lower dentries have overlapping branches.
23869 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
23871 + struct super_block *h_sb;
23872 + struct file *backing_file;
23874 + if (unlikely(!backing_file_func)) {
23875 + /* don't load "loop" module here */
23876 + backing_file_func = symbol_get(loop_backing_file);
23877 + if (unlikely(!backing_file_func))
23878 + /* "loop" module is not loaded */
23882 + h_sb = h_adding->d_sb;
23883 + backing_file = backing_file_func(h_sb);
23884 + if (!backing_file)
23887 + h_adding = backing_file->f_path.dentry;
23889 + * h_adding can be local NFS.
23890 + * in this case aufs cannot detect the loop.
23892 + if (unlikely(h_adding->d_sb == sb))
23894 + return !!au_test_subdir(h_adding, sb->s_root);
23897 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
23898 +int au_test_loopback_kthread(void)
23901 + struct task_struct *tsk = current;
23902 + char c, comm[sizeof(tsk->comm)];
23905 + if (tsk->flags & PF_KTHREAD) {
23906 + get_task_comm(comm, tsk);
23908 + ret = ('0' <= c && c <= '9'
23909 + && !strncmp(comm, "loop", 4));
23915 +/* ---------------------------------------------------------------------- */
23917 +#define au_warn_loopback_step 16
23918 +static int au_warn_loopback_nelem = au_warn_loopback_step;
23919 +static unsigned long *au_warn_loopback_array;
23921 +void au_warn_loopback(struct super_block *h_sb)
23923 + int i, new_nelem;
23924 + unsigned long *a, magic;
23925 + static DEFINE_SPINLOCK(spin);
23927 + magic = h_sb->s_magic;
23928 + spin_lock(&spin);
23929 + a = au_warn_loopback_array;
23930 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
23931 + if (a[i] == magic) {
23932 + spin_unlock(&spin);
23936 + /* h_sb is new to us, print it */
23937 + if (i < au_warn_loopback_nelem) {
23942 + /* expand the array */
23943 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
23944 + a = au_kzrealloc(au_warn_loopback_array,
23945 + au_warn_loopback_nelem * sizeof(unsigned long),
23946 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
23947 + /*may_shrink*/0);
23949 + au_warn_loopback_nelem = new_nelem;
23950 + au_warn_loopback_array = a;
23955 + spin_unlock(&spin);
23956 + AuWarn1("realloc failed, ignored\n");
23960 + spin_unlock(&spin);
23961 + pr_warn("you may want to try another patch for loopback file "
23962 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
23965 +int au_loopback_init(void)
23968 + struct super_block *sb __maybe_unused;
23970 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
23973 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
23974 + sizeof(unsigned long), GFP_NOFS);
23975 + if (unlikely(!au_warn_loopback_array))
23981 +void au_loopback_fin(void)
23983 + if (backing_file_func)
23984 + symbol_put(loop_backing_file);
23985 + kfree(au_warn_loopback_array);
23987 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
23988 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
23989 +++ linux/fs/aufs/loop.h 2018-04-15 08:49:13.401150731 +0200
23992 + * Copyright (C) 2005-2018 Junjiro R. Okajima
23994 + * This program, aufs is free software; you can redistribute it and/or modify
23995 + * it under the terms of the GNU General Public License as published by
23996 + * the Free Software Foundation; either version 2 of the License, or
23997 + * (at your option) any later version.
23999 + * This program is distributed in the hope that it will be useful,
24000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24002 + * GNU General Public License for more details.
24004 + * You should have received a copy of the GNU General Public License
24005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24009 + * support for loopback mount as a branch
24012 +#ifndef __AUFS_LOOP_H__
24013 +#define __AUFS_LOOP_H__
24018 +struct super_block;
24020 +#ifdef CONFIG_AUFS_BDEV_LOOP
24021 +/* drivers/block/loop.c */
24022 +struct file *loop_backing_file(struct super_block *sb);
24025 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24026 +int au_test_loopback_kthread(void);
24027 +void au_warn_loopback(struct super_block *h_sb);
24029 +int au_loopback_init(void);
24030 +void au_loopback_fin(void);
24032 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24033 + struct dentry *h_adding)
24034 +AuStubInt0(au_test_loopback_kthread, void)
24035 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24037 +AuStubInt0(au_loopback_init, void)
24038 +AuStubVoid(au_loopback_fin, void)
24039 +#endif /* BLK_DEV_LOOP */
24041 +#endif /* __KERNEL__ */
24042 +#endif /* __AUFS_LOOP_H__ */
24043 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24044 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24045 +++ linux/fs/aufs/magic.mk 2018-04-15 08:49:11.027744356 +0200
24048 +# defined in ${srctree}/fs/fuse/inode.c
24050 +ifdef CONFIG_FUSE_FS
24051 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24054 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24056 +ifdef CONFIG_XFS_FS
24057 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24060 +# defined in ${srctree}/fs/configfs/mount.c
24062 +ifdef CONFIG_CONFIGFS_FS
24063 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24066 +# defined in ${srctree}/fs/ubifs/ubifs.h
24068 +ifdef CONFIG_UBIFS_FS
24069 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24072 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24074 +ifdef CONFIG_HFSPLUS_FS
24075 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24077 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24078 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24079 +++ linux/fs/aufs/Makefile 2018-04-15 08:49:13.394483860 +0200
24082 +include ${src}/magic.mk
24083 +ifeq (${CONFIG_AUFS_FS},m)
24084 +include ${src}/conf.mk
24086 +-include ${src}/priv_def.mk
24088 +# cf. include/linux/kernel.h
24090 +ccflags-y += -DDEBUG
24091 +# sparse requires the full pathname
24093 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24095 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24098 +obj-$(CONFIG_AUFS_FS) += aufs.o
24099 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24100 + wkq.o vfsub.o dcsub.o \
24101 + cpup.o whout.o wbr_policy.o \
24102 + dinfo.o dentry.o \
24104 + finfo.o file.o f_op.o \
24106 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24110 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24111 +aufs-$(CONFIG_SYSFS) += sysfs.o
24112 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24113 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24114 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24115 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24116 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24117 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24118 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24119 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24120 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24121 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24122 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24123 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24124 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24125 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24126 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24127 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24128 +++ linux/fs/aufs/module.c 2018-04-15 08:49:13.401150731 +0200
24131 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24133 + * This program, aufs is free software; you can redistribute it and/or modify
24134 + * it under the terms of the GNU General Public License as published by
24135 + * the Free Software Foundation; either version 2 of the License, or
24136 + * (at your option) any later version.
24138 + * This program is distributed in the hope that it will be useful,
24139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24141 + * GNU General Public License for more details.
24143 + * You should have received a copy of the GNU General Public License
24144 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24148 + * module global variables and operations
24151 +#include <linux/module.h>
24152 +#include <linux/seq_file.h>
24155 +/* shrinkable realloc */
24156 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24164 +#if 0 /* unused */
24171 + AuDebugOn(!new_sz);
24174 + diff = au_kmidx_sub(sz, new_sz);
24180 + /* expand or SLOB */
24181 + p = krealloc(p, new_sz, gfp);
24182 + else if (new_sz < sz && may_shrink) {
24186 + q = kmalloc(new_sz, gfp);
24189 + memcpy(q, p, new_sz);
24201 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24204 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24205 + if (p && new_sz > nused)
24206 + memset(p + nused, 0, new_sz - nused);
24210 +/* ---------------------------------------------------------------------- */
24214 +struct kmem_cache *au_cache[AuCache_Last];
24216 +static void au_cache_fin(void)
24221 + * Make sure all delayed rcu free inodes are flushed before we
24226 + /* excluding AuCache_HNOTIFY */
24227 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24228 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24229 + kmem_cache_destroy(au_cache[i]);
24230 + au_cache[i] = NULL;
24234 +static int __init au_cache_init(void)
24236 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24237 + if (au_cache[AuCache_DINFO])
24238 + /* SLAB_DESTROY_BY_RCU */
24239 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24240 + au_icntnr_init_once);
24241 + if (au_cache[AuCache_ICNTNR])
24242 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24243 + au_fi_init_once);
24244 + if (au_cache[AuCache_FINFO])
24245 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24246 + if (au_cache[AuCache_VDIR])
24247 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24248 + if (au_cache[AuCache_DEHSTR])
24255 +/* ---------------------------------------------------------------------- */
24257 +int au_dir_roflags;
24259 +#ifdef CONFIG_AUFS_SBILIST
24261 + * iterate_supers_type() doesn't protect us from
24262 + * remounting (branch management)
24264 +struct hlist_bl_head au_sbilist;
24268 + * functions for module interface.
24270 +MODULE_LICENSE("GPL");
24271 +/* MODULE_LICENSE("GPL v2"); */
24272 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24273 +MODULE_DESCRIPTION(AUFS_NAME
24274 + " -- Advanced multi layered unification filesystem");
24275 +MODULE_VERSION(AUFS_VERSION);
24276 +MODULE_ALIAS_FS(AUFS_NAME);
24278 +/* this module parameter has no meaning when SYSFS is disabled */
24279 +int sysaufs_brs = 1;
24280 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24281 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
24283 +/* this module parameter has no meaning when USER_NS is disabled */
24285 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24286 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
24288 +/* ---------------------------------------------------------------------- */
24290 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24292 +int au_seq_path(struct seq_file *seq, struct path *path)
24296 + err = seq_path(seq, path, au_esc_chars);
24305 +/* ---------------------------------------------------------------------- */
24307 +static int __init aufs_init(void)
24312 + p = au_esc_chars;
24313 + for (i = 1; i <= ' '; i++)
24319 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24321 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24322 + for (i = 0; i < AuIop_Last; i++)
24323 + aufs_iop_nogetattr[i].getattr = NULL;
24325 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24327 + au_sbilist_init();
24328 + sysaufs_brs_init();
24331 + err = sysaufs_init();
24332 + if (unlikely(err))
24334 + err = au_procfs_init();
24335 + if (unlikely(err))
24336 + goto out_sysaufs;
24337 + err = au_wkq_init();
24338 + if (unlikely(err))
24340 + err = au_loopback_init();
24341 + if (unlikely(err))
24343 + err = au_hnotify_init();
24344 + if (unlikely(err))
24345 + goto out_loopback;
24346 + err = au_sysrq_init();
24347 + if (unlikely(err))
24349 + err = au_cache_init();
24350 + if (unlikely(err))
24353 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24354 + err = register_filesystem(&aufs_fs_type);
24355 + if (unlikely(err))
24358 + /* since we define pr_fmt, call printk directly */
24359 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24360 + goto out; /* success */
24367 + au_hnotify_fin();
24369 + au_loopback_fin();
24381 +static void __exit aufs_exit(void)
24383 + unregister_filesystem(&aufs_fs_type);
24386 + au_hnotify_fin();
24387 + au_loopback_fin();
24394 +module_init(aufs_init);
24395 +module_exit(aufs_exit);
24396 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24397 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24398 +++ linux/fs/aufs/module.h 2018-04-15 08:49:13.401150731 +0200
24401 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24403 + * This program, aufs is free software; you can redistribute it and/or modify
24404 + * it under the terms of the GNU General Public License as published by
24405 + * the Free Software Foundation; either version 2 of the License, or
24406 + * (at your option) any later version.
24408 + * This program is distributed in the hope that it will be useful,
24409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24411 + * GNU General Public License for more details.
24413 + * You should have received a copy of the GNU General Public License
24414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24418 + * module initialization and module-global
24421 +#ifndef __AUFS_MODULE_H__
24422 +#define __AUFS_MODULE_H__
24426 +#include <linux/slab.h>
24431 +/* module parameters */
24432 +extern int sysaufs_brs;
24433 +extern bool au_userns;
24435 +/* ---------------------------------------------------------------------- */
24437 +extern int au_dir_roflags;
24439 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24440 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24443 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24445 +#ifndef CONFIG_SLOB
24446 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24448 + return -1; /* SLOB is untested */
24452 +int au_seq_path(struct seq_file *seq, struct path *path);
24454 +#ifdef CONFIG_PROC_FS
24456 +int __init au_procfs_init(void);
24457 +void au_procfs_fin(void);
24459 +AuStubInt0(au_procfs_init, void);
24460 +AuStubVoid(au_procfs_fin, void);
24463 +/* ---------------------------------------------------------------------- */
24472 + AuCache_HNOTIFY, /* must be last */
24476 +extern struct kmem_cache *au_cache[AuCache_Last];
24478 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24479 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24480 +#define AuCacheCtor(type, ctor) \
24481 + kmem_cache_create(#type, sizeof(struct type), \
24482 + __alignof__(struct type), AuCacheFlags, ctor)
24484 +#define AuCacheFuncs(name, index) \
24485 +static inline struct au_##name *au_cache_alloc_##name(void) \
24486 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24487 +static inline void au_cache_free_##name(struct au_##name *p) \
24488 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24490 +AuCacheFuncs(dinfo, DINFO);
24491 +AuCacheFuncs(icntnr, ICNTNR);
24492 +AuCacheFuncs(finfo, FINFO);
24493 +AuCacheFuncs(vdir, VDIR);
24494 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24495 +#ifdef CONFIG_AUFS_HNOTIFY
24496 +AuCacheFuncs(hnotify, HNOTIFY);
24499 +#endif /* __KERNEL__ */
24500 +#endif /* __AUFS_MODULE_H__ */
24501 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24502 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24503 +++ linux/fs/aufs/mvdown.c 2018-04-15 08:49:13.401150731 +0200
24506 + * Copyright (C) 2011-2018 Junjiro R. Okajima
24508 + * This program, aufs is free software; you can redistribute it and/or modify
24509 + * it under the terms of the GNU General Public License as published by
24510 + * the Free Software Foundation; either version 2 of the License, or
24511 + * (at your option) any later version.
24513 + * This program is distributed in the hope that it will be useful,
24514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24516 + * GNU General Public License for more details.
24518 + * You should have received a copy of the GNU General Public License
24519 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24523 + * move-down, opposite of copy-up
24528 +struct au_mvd_args {
24530 + struct super_block *h_sb;
24531 + struct dentry *h_parent;
24532 + struct au_hinode *hdir;
24533 + struct inode *h_dir, *h_inode;
24534 + struct au_pin pin;
24535 + } info[AUFS_MVDOWN_NARRAY];
24537 + struct aufs_mvdown mvdown;
24538 + struct dentry *dentry, *parent;
24539 + struct inode *inode, *dir;
24540 + struct super_block *sb;
24541 + aufs_bindex_t bopq, bwh, bfound;
24542 + unsigned char rename_lock;
24545 +#define mvd_errno mvdown.au_errno
24546 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24547 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24548 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24549 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24551 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24552 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24553 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24554 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24555 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24556 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24558 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24559 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24560 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24561 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24562 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24563 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24565 +#define AU_MVD_PR(flag, ...) do { \
24567 + pr_err(__VA_ARGS__); \
24570 +static int find_lower_writable(struct au_mvd_args *a)
24572 + struct super_block *sb;
24573 + aufs_bindex_t bindex, bbot;
24574 + struct au_branch *br;
24577 + bindex = a->mvd_bsrc;
24578 + bbot = au_sbbot(sb);
24579 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24580 + for (bindex++; bindex <= bbot; bindex++) {
24581 + br = au_sbr(sb, bindex);
24582 + if (au_br_fhsm(br->br_perm)
24583 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
24586 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24587 + for (bindex++; bindex <= bbot; bindex++) {
24588 + br = au_sbr(sb, bindex);
24589 + if (!au_br_rdonly(br))
24593 + for (bindex++; bindex <= bbot; bindex++) {
24594 + br = au_sbr(sb, bindex);
24595 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
24596 + if (au_br_rdonly(br))
24598 + |= AUFS_MVDOWN_ROLOWER_R;
24606 +/* make the parent dir on bdst */
24607 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24612 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24613 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24614 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24615 + a->mvd_h_dst_parent = NULL;
24616 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24617 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24618 + if (!a->mvd_h_dst_parent) {
24619 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24620 + if (unlikely(err)) {
24621 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24624 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24632 +/* lock them all */
24633 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24636 + struct dentry *h_trap;
24638 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24639 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24640 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24641 + au_opt_udba(a->sb),
24642 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24644 + if (unlikely(err)) {
24645 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24649 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24650 + a->rename_lock = 0;
24651 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24652 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24653 + au_opt_udba(a->sb),
24654 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24655 + err = au_do_pin(&a->mvd_pin_src);
24657 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24658 + if (unlikely(err)) {
24659 + AU_MVD_PR(dmsg, "pin_src failed\n");
24662 + goto out; /* success */
24665 + a->rename_lock = 1;
24666 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24667 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24668 + au_opt_udba(a->sb),
24669 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24671 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24672 + if (unlikely(err)) {
24673 + AU_MVD_PR(dmsg, "pin_src failed\n");
24674 + au_pin_hdir_lock(&a->mvd_pin_dst);
24677 + au_pin_hdir_unlock(&a->mvd_pin_src);
24678 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24679 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24681 + err = (h_trap != a->mvd_h_src_parent);
24683 + err = (h_trap != a->mvd_h_dst_parent);
24685 + BUG_ON(err); /* it should never happen */
24686 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24689 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24690 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24691 + au_pin_hdir_lock(&a->mvd_pin_src);
24692 + au_unpin(&a->mvd_pin_src);
24693 + au_pin_hdir_lock(&a->mvd_pin_dst);
24696 + goto out; /* success */
24699 + au_unpin(&a->mvd_pin_dst);
24705 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
24707 + if (!a->rename_lock)
24708 + au_unpin(&a->mvd_pin_src);
24710 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24711 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24712 + au_pin_hdir_lock(&a->mvd_pin_src);
24713 + au_unpin(&a->mvd_pin_src);
24714 + au_pin_hdir_lock(&a->mvd_pin_dst);
24716 + au_unpin(&a->mvd_pin_dst);
24719 +/* copy-down the file */
24720 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
24723 + struct au_cp_generic cpg = {
24724 + .dentry = a->dentry,
24725 + .bdst = a->mvd_bdst,
24726 + .bsrc = a->mvd_bsrc,
24728 + .pin = &a->mvd_pin_dst,
24729 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24732 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
24733 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
24734 + au_fset_cpup(cpg.flags, OVERWRITE);
24735 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
24736 + au_fset_cpup(cpg.flags, RWDST);
24737 + err = au_sio_cpdown_simple(&cpg);
24738 + if (unlikely(err))
24739 + AU_MVD_PR(dmsg, "cpdown failed\n");
24746 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
24749 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
24752 + struct path h_path;
24753 + struct au_branch *br;
24754 + struct inode *delegated;
24756 + br = au_sbr(a->sb, a->mvd_bdst);
24757 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
24758 + err = PTR_ERR(h_path.dentry);
24759 + if (IS_ERR(h_path.dentry)) {
24760 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
24765 + if (d_is_positive(h_path.dentry)) {
24766 + h_path.mnt = au_br_mnt(br);
24767 + delegated = NULL;
24768 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
24769 + &delegated, /*force*/0);
24770 + if (unlikely(err == -EWOULDBLOCK)) {
24771 + pr_warn("cannot retry for NFSv4 delegation"
24772 + " for an internal unlink\n");
24775 + if (unlikely(err))
24776 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
24778 + dput(h_path.dentry);
24786 + * unlink the topmost h_dentry
24788 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
24791 + struct path h_path;
24792 + struct inode *delegated;
24794 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
24795 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
24796 + delegated = NULL;
24797 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
24798 + if (unlikely(err == -EWOULDBLOCK)) {
24799 + pr_warn("cannot retry for NFSv4 delegation"
24800 + " for an internal unlink\n");
24803 + if (unlikely(err))
24804 + AU_MVD_PR(dmsg, "unlink failed\n");
24810 +/* Since mvdown succeeded, we ignore an error of this function */
24811 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
24814 + struct au_branch *br;
24816 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
24817 + br = au_sbr(a->sb, a->mvd_bsrc);
24818 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
24820 + br = au_sbr(a->sb, a->mvd_bdst);
24821 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
24822 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
24825 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
24827 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
24831 + * copy-down the file and unlink the bsrc file.
24832 + * - unlink the bdst whout if exist
24833 + * - copy-down the file (with whtmp name and rename)
24834 + * - unlink the bsrc file
24836 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
24840 + err = au_do_mkdir(dmsg, a);
24842 + err = au_do_lock(dmsg, a);
24843 + if (unlikely(err))
24847 + * do not revert the activities we made on bdst since they should be
24848 + * harmless in aufs.
24851 + err = au_do_cpdown(dmsg, a);
24853 + err = au_do_unlink_wh(dmsg, a);
24854 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
24855 + err = au_do_unlink(dmsg, a);
24856 + if (unlikely(err))
24859 + AuDbg("%pd2, 0x%x, %d --> %d\n",
24860 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
24861 + if (find_lower_writable(a) < 0)
24862 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
24864 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
24865 + au_do_stfs(dmsg, a);
24867 + /* maintain internal array */
24868 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
24869 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
24870 + au_set_dbtop(a->dentry, a->mvd_bdst);
24871 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
24872 + au_set_ibtop(a->inode, a->mvd_bdst);
24874 + /* hide the lower */
24875 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
24876 + au_set_dbbot(a->dentry, a->mvd_bsrc);
24877 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
24878 + au_set_ibbot(a->inode, a->mvd_bsrc);
24880 + if (au_dbbot(a->dentry) < a->mvd_bdst)
24881 + au_set_dbbot(a->dentry, a->mvd_bdst);
24882 + if (au_ibbot(a->inode) < a->mvd_bdst)
24883 + au_set_ibbot(a->inode, a->mvd_bdst);
24886 + au_do_unlock(dmsg, a);
24892 +/* ---------------------------------------------------------------------- */
24894 +/* make sure the file is idle */
24895 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
24897 + int err, plinked;
24900 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
24901 + if (au_dbtop(a->dentry) == a->mvd_bsrc
24902 + && au_dcount(a->dentry) == 1
24903 + && atomic_read(&a->inode->i_count) == 1
24904 + /* && a->mvd_h_src_inode->i_nlink == 1 */
24905 + && (!plinked || !au_plink_test(a->inode))
24906 + && a->inode->i_nlink == 1)
24911 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
24912 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
24913 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
24914 + a->mvd_h_src_inode->i_nlink,
24915 + plinked, plinked ? au_plink_test(a->inode) : 0);
24922 +/* make sure the parent dir is fine */
24923 +static int au_mvd_args_parent(const unsigned char dmsg,
24924 + struct au_mvd_args *a)
24927 + aufs_bindex_t bindex;
24930 + if (unlikely(au_alive_dir(a->parent))) {
24932 + AU_MVD_PR(dmsg, "parent dir is dead\n");
24936 + a->bopq = au_dbdiropq(a->parent);
24937 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
24938 + AuDbg("b%d\n", bindex);
24939 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
24940 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
24942 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
24943 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
24944 + a->bopq, a->mvd_bdst);
24952 +static int au_mvd_args_intermediate(const unsigned char dmsg,
24953 + struct au_mvd_args *a)
24956 + struct au_dinfo *dinfo, *tmp;
24958 + /* lookup the next lower positive entry */
24960 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
24961 + if (unlikely(!tmp))
24966 + dinfo = au_di(a->dentry);
24967 + au_di_cp(tmp, dinfo);
24968 + au_di_swap(tmp, dinfo);
24970 + /* returns the number of positive dentries */
24971 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
24972 + /* AuLkup_IGNORE_PERM */ 0);
24974 + a->bwh = au_dbwh(a->dentry);
24975 + else if (err > 0)
24976 + a->bfound = au_dbtop(a->dentry);
24978 + au_di_swap(tmp, dinfo);
24979 + au_rw_write_unlock(&tmp->di_rwsem);
24981 + if (unlikely(err < 0))
24982 + AU_MVD_PR(dmsg, "failed look-up lower\n");
24985 + * here, we have these cases.
24987 + * no positive dentry under bsrc. there are more sub-cases.
24989 + * there no whiteout, we can safely move-down.
24992 + * bsrc < bwh && bwh < bdst
24993 + * there is a whiteout on RO branch. cannot proceed.
24995 + * there is a whiteout on the RW target branch. it should
24998 + * there is a whiteout somewhere unrelated branch.
24999 + * -1 < bfound && bfound <= bsrc
25002 + * found, but it is on RO branch between bsrc and bdst. cannot
25005 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25008 + * found, after we create the file on bdst, it will be hidden.
25011 + AuDebugOn(a->bfound == -1
25013 + && a->bwh <= a->mvd_bsrc);
25014 + AuDebugOn(-1 < a->bfound
25015 + && a->bfound <= a->mvd_bsrc);
25018 + if (a->bfound == -1
25019 + && a->mvd_bsrc < a->bwh
25021 + && a->bwh < a->mvd_bdst) {
25022 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25023 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25024 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25026 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25027 + a->mvd_errno = EAU_MVDOWN_UPPER;
25028 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25029 + a->mvd_bdst, a->bfound);
25033 + err = 0; /* success */
25040 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25045 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25046 + && a->bfound == a->mvd_bdst)
25052 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25055 + struct au_branch *br;
25058 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25062 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25063 + a->mvd_bsrc = au_ibtop(a->inode);
25065 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25066 + if (unlikely(a->mvd_bsrc < 0
25067 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25068 + || au_dbbot(a->dentry) < a->mvd_bsrc
25069 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25070 + || (a->mvd_bsrc < au_ibtop(a->inode)
25071 + || au_ibbot(a->inode) < a->mvd_bsrc
25072 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25073 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25074 + AU_MVD_PR(dmsg, "no upper\n");
25078 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25079 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25080 + AU_MVD_PR(dmsg, "on the bottom\n");
25083 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25084 + br = au_sbr(a->sb, a->mvd_bsrc);
25085 + err = au_br_rdonly(br);
25086 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25087 + if (unlikely(err))
25089 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25090 + || IS_APPEND(a->mvd_h_src_inode))) {
25092 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25098 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25099 + a->mvd_bdst = find_lower_writable(a);
25100 + if (unlikely(a->mvd_bdst < 0)) {
25101 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25102 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25106 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25107 + if (unlikely(a->mvd_bdst < 0
25108 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25109 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25110 + AU_MVD_PR(dmsg, "no lower brid\n");
25115 + err = au_mvd_args_busy(dmsg, a);
25117 + err = au_mvd_args_parent(dmsg, a);
25119 + err = au_mvd_args_intermediate(dmsg, a);
25121 + err = au_mvd_args_exist(dmsg, a);
25123 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25130 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25133 + unsigned char dmsg;
25134 + struct au_mvd_args *args;
25135 + struct inode *inode;
25137 + inode = d_inode(dentry);
25139 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25143 + args = kmalloc(sizeof(*args), GFP_NOFS);
25144 + if (unlikely(!args))
25147 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25149 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25150 + if (unlikely(err)) {
25155 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25156 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25157 + args->mvdown.au_errno = 0;
25158 + args->dentry = dentry;
25159 + args->inode = inode;
25160 + args->sb = dentry->d_sb;
25163 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25164 + args->parent = dget_parent(dentry);
25165 + args->dir = d_inode(args->parent);
25166 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25167 + dput(args->parent);
25168 + if (unlikely(args->parent != dentry->d_parent)) {
25169 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25173 + inode_lock_nested(inode, I_MUTEX_CHILD);
25174 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25175 + if (unlikely(err))
25178 + di_write_lock_parent(args->parent);
25179 + err = au_mvd_args(dmsg, args);
25180 + if (unlikely(err))
25183 + err = au_do_mvdown(dmsg, args);
25184 + if (unlikely(err))
25187 + au_cpup_attr_timesizes(args->dir);
25188 + au_cpup_attr_timesizes(inode);
25189 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25190 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25191 + /* au_digen_dec(dentry); */
25194 + di_write_unlock(args->parent);
25195 + aufs_read_unlock(dentry, AuLock_DW);
25197 + inode_unlock(inode);
25199 + inode_unlock(args->dir);
25201 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25209 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25210 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25211 +++ linux/fs/aufs/opts.c 2018-04-15 08:49:13.401150731 +0200
25214 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25216 + * This program, aufs is free software; you can redistribute it and/or modify
25217 + * it under the terms of the GNU General Public License as published by
25218 + * the Free Software Foundation; either version 2 of the License, or
25219 + * (at your option) any later version.
25221 + * This program is distributed in the hope that it will be useful,
25222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25224 + * GNU General Public License for more details.
25226 + * You should have received a copy of the GNU General Public License
25227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25231 + * mount options/flags
25234 +#include <linux/namei.h>
25235 +#include <linux/types.h> /* a distribution requires */
25236 +#include <linux/parser.h>
25239 +/* ---------------------------------------------------------------------- */
25243 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25244 + Opt_idel, Opt_imod,
25245 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25246 + Opt_rdblk_def, Opt_rdhash_def,
25247 + Opt_xino, Opt_noxino,
25248 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25249 + Opt_trunc_xino_path, Opt_itrunc_xino,
25250 + Opt_trunc_xib, Opt_notrunc_xib,
25251 + Opt_shwh, Opt_noshwh,
25252 + Opt_plink, Opt_noplink, Opt_list_plink,
25254 + Opt_dio, Opt_nodio,
25255 + Opt_diropq_a, Opt_diropq_w,
25256 + Opt_warn_perm, Opt_nowarn_perm,
25257 + Opt_wbr_copyup, Opt_wbr_create,
25259 + Opt_verbose, Opt_noverbose,
25260 + Opt_sum, Opt_nosum, Opt_wsum,
25261 + Opt_dirperm1, Opt_nodirperm1,
25262 + Opt_dirren, Opt_nodirren,
25263 + Opt_acl, Opt_noacl,
25264 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25267 +static match_table_t options = {
25268 + {Opt_br, "br=%s"},
25269 + {Opt_br, "br:%s"},
25271 + {Opt_add, "add=%d:%s"},
25272 + {Opt_add, "add:%d:%s"},
25273 + {Opt_add, "ins=%d:%s"},
25274 + {Opt_add, "ins:%d:%s"},
25275 + {Opt_append, "append=%s"},
25276 + {Opt_append, "append:%s"},
25277 + {Opt_prepend, "prepend=%s"},
25278 + {Opt_prepend, "prepend:%s"},
25280 + {Opt_del, "del=%s"},
25281 + {Opt_del, "del:%s"},
25282 + /* {Opt_idel, "idel:%d"}, */
25283 + {Opt_mod, "mod=%s"},
25284 + {Opt_mod, "mod:%s"},
25285 + /* {Opt_imod, "imod:%d:%s"}, */
25287 + {Opt_dirwh, "dirwh=%d"},
25289 + {Opt_xino, "xino=%s"},
25290 + {Opt_noxino, "noxino"},
25291 + {Opt_trunc_xino, "trunc_xino"},
25292 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25293 + {Opt_notrunc_xino, "notrunc_xino"},
25294 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25295 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25296 + /* {Opt_zxino, "zxino=%s"}, */
25297 + {Opt_trunc_xib, "trunc_xib"},
25298 + {Opt_notrunc_xib, "notrunc_xib"},
25300 +#ifdef CONFIG_PROC_FS
25301 + {Opt_plink, "plink"},
25303 + {Opt_ignore_silent, "plink"},
25306 + {Opt_noplink, "noplink"},
25308 +#ifdef CONFIG_AUFS_DEBUG
25309 + {Opt_list_plink, "list_plink"},
25312 + {Opt_udba, "udba=%s"},
25314 + {Opt_dio, "dio"},
25315 + {Opt_nodio, "nodio"},
25317 +#ifdef CONFIG_AUFS_DIRREN
25318 + {Opt_dirren, "dirren"},
25319 + {Opt_nodirren, "nodirren"},
25321 + {Opt_ignore, "dirren"},
25322 + {Opt_ignore_silent, "nodirren"},
25325 +#ifdef CONFIG_AUFS_FHSM
25326 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25328 + {Opt_ignore, "fhsm_sec=%d"},
25331 + {Opt_diropq_a, "diropq=always"},
25332 + {Opt_diropq_a, "diropq=a"},
25333 + {Opt_diropq_w, "diropq=whiteouted"},
25334 + {Opt_diropq_w, "diropq=w"},
25336 + {Opt_warn_perm, "warn_perm"},
25337 + {Opt_nowarn_perm, "nowarn_perm"},
25339 + /* keep them temporary */
25340 + {Opt_ignore_silent, "nodlgt"},
25341 + {Opt_ignore, "clean_plink"},
25343 +#ifdef CONFIG_AUFS_SHWH
25344 + {Opt_shwh, "shwh"},
25346 + {Opt_noshwh, "noshwh"},
25348 + {Opt_dirperm1, "dirperm1"},
25349 + {Opt_nodirperm1, "nodirperm1"},
25351 + {Opt_verbose, "verbose"},
25352 + {Opt_verbose, "v"},
25353 + {Opt_noverbose, "noverbose"},
25354 + {Opt_noverbose, "quiet"},
25355 + {Opt_noverbose, "q"},
25356 + {Opt_noverbose, "silent"},
25358 + {Opt_sum, "sum"},
25359 + {Opt_nosum, "nosum"},
25360 + {Opt_wsum, "wsum"},
25362 + {Opt_rdcache, "rdcache=%d"},
25363 + {Opt_rdblk, "rdblk=%d"},
25364 + {Opt_rdblk_def, "rdblk=def"},
25365 + {Opt_rdhash, "rdhash=%d"},
25366 + {Opt_rdhash_def, "rdhash=def"},
25368 + {Opt_wbr_create, "create=%s"},
25369 + {Opt_wbr_create, "create_policy=%s"},
25370 + {Opt_wbr_copyup, "cpup=%s"},
25371 + {Opt_wbr_copyup, "copyup=%s"},
25372 + {Opt_wbr_copyup, "copyup_policy=%s"},
25374 + /* generic VFS flag */
25375 +#ifdef CONFIG_FS_POSIX_ACL
25376 + {Opt_acl, "acl"},
25377 + {Opt_noacl, "noacl"},
25379 + {Opt_ignore, "acl"},
25380 + {Opt_ignore_silent, "noacl"},
25383 + /* internal use for the scripts */
25384 + {Opt_ignore_silent, "si=%s"},
25386 + {Opt_br, "dirs=%s"},
25387 + {Opt_ignore, "debug=%d"},
25388 + {Opt_ignore, "delete=whiteout"},
25389 + {Opt_ignore, "delete=all"},
25390 + {Opt_ignore, "imap=%s"},
25392 + /* temporary workaround, due to old mount(8)? */
25393 + {Opt_ignore_silent, "relatime"},
25398 +/* ---------------------------------------------------------------------- */
25400 +static const char *au_parser_pattern(int val, match_table_t tbl)
25402 + struct match_token *p;
25405 + while (p->pattern) {
25406 + if (p->token == val)
25407 + return p->pattern;
25414 +static const char *au_optstr(int *val, match_table_t tbl)
25416 + struct match_token *p;
25423 + while (p->pattern) {
25425 + && (v & p->token) == p->token) {
25426 + *val &= ~p->token;
25427 + return p->pattern;
25436 +/* ---------------------------------------------------------------------- */
25438 +static match_table_t brperm = {
25439 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25440 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25441 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25445 +static match_table_t brattr = {
25447 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25448 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25449 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25450 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25451 +#ifdef CONFIG_AUFS_FHSM
25452 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25454 +#ifdef CONFIG_AUFS_XATTR
25455 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25456 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25457 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25458 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25459 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25460 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25463 + /* ro/rr branch */
25464 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25467 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25468 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25473 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25480 + p = strchr(str, '+');
25483 + v = match_token(str, table, args);
25485 + if (v & AuBrAttr_CMOO_Mask)
25486 + attr &= ~AuBrAttr_CMOO_Mask;
25491 + pr_warn("ignored branch attribute %s\n", str);
25501 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25509 + p = au_optstr(&perm, brattr);
25512 + memcpy(q, p, sz + 1);
25518 + p = au_optstr(&perm, brattr);
25522 + memcpy(q, p, sz + 1);
25528 + return q - str->a;
25531 +static int noinline_for_stack br_perm_val(char *perm)
25533 + int val, bad, sz;
25535 + substring_t args[MAX_OPT_ARGS];
25536 + au_br_perm_str_t attr;
25538 + p = strchr(perm, '+');
25541 + val = match_token(perm, brperm, args);
25545 + pr_warn("ignored branch permission %s\n", perm);
25546 + val = AuBrPerm_RO;
25552 + val |= br_attr_val(p + 1, brattr, args);
25555 + switch (val & AuBrPerm_Mask) {
25556 + case AuBrPerm_RO:
25557 + case AuBrPerm_RR:
25558 + bad = val & AuBrWAttr_Mask;
25559 + val &= ~AuBrWAttr_Mask;
25561 + case AuBrPerm_RW:
25562 + bad = val & AuBrRAttr_Mask;
25563 + val &= ~AuBrRAttr_Mask;
25568 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25569 + * does not treat it as an error, just warning.
25570 + * this is a tiny guard for the user operation.
25572 + if (val & AuBrAttr_UNPIN) {
25573 + bad |= AuBrAttr_UNPIN;
25574 + val &= ~AuBrAttr_UNPIN;
25577 + if (unlikely(bad)) {
25578 + sz = au_do_optstr_br_attr(&attr, bad);
25580 + pr_warn("ignored branch attribute %s\n", attr.a);
25587 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25589 + au_br_perm_str_t attr;
25595 + p = au_optstr(&perm, brperm);
25596 + AuDebugOn(!p || !*p);
25598 + memcpy(q, p, sz + 1);
25601 + sz = au_do_optstr_br_attr(&attr, perm);
25604 + memcpy(q, attr.a, sz + 1);
25607 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25610 +/* ---------------------------------------------------------------------- */
25612 +static match_table_t udbalevel = {
25613 + {AuOpt_UDBA_REVAL, "reval"},
25614 + {AuOpt_UDBA_NONE, "none"},
25615 +#ifdef CONFIG_AUFS_HNOTIFY
25616 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25617 +#ifdef CONFIG_AUFS_HFSNOTIFY
25618 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25624 +static int noinline_for_stack udba_val(char *str)
25626 + substring_t args[MAX_OPT_ARGS];
25628 + return match_token(str, udbalevel, args);
25631 +const char *au_optstr_udba(int udba)
25633 + return au_parser_pattern(udba, udbalevel);
25636 +/* ---------------------------------------------------------------------- */
25638 +static match_table_t au_wbr_create_policy = {
25639 + {AuWbrCreate_TDP, "tdp"},
25640 + {AuWbrCreate_TDP, "top-down-parent"},
25641 + {AuWbrCreate_RR, "rr"},
25642 + {AuWbrCreate_RR, "round-robin"},
25643 + {AuWbrCreate_MFS, "mfs"},
25644 + {AuWbrCreate_MFS, "most-free-space"},
25645 + {AuWbrCreate_MFSV, "mfs:%d"},
25646 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25648 + /* top-down regardless the parent, and then mfs */
25649 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25650 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25652 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25653 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25654 + {AuWbrCreate_PMFS, "pmfs"},
25655 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25656 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25657 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25663 + * cf. linux/lib/parser.c and cmdline.c
25664 + * gave up calling memparse() since it uses simple_strtoull() instead of
25667 +static int noinline_for_stack
25668 +au_match_ull(substring_t *s, unsigned long long *result)
25671 + unsigned int len;
25675 + len = s->to - s->from;
25676 + if (len + 1 <= sizeof(a)) {
25677 + memcpy(a, s->from, len);
25679 + err = kstrtoull(a, 0, result);
25684 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25685 + struct au_opt_wbr_create *create)
25688 + unsigned long long ull;
25691 + if (!au_match_ull(arg, &ull))
25692 + create->mfsrr_watermark = ull;
25694 + pr_err("bad integer in %s\n", str);
25701 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25702 + struct au_opt_wbr_create *create)
25707 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25708 + create->mfs_second = n;
25710 + pr_err("bad integer in %s\n", str);
25717 +static int noinline_for_stack
25718 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
25721 + substring_t args[MAX_OPT_ARGS];
25723 + err = match_token(str, au_wbr_create_policy, args);
25724 + create->wbr_create = err;
25726 + case AuWbrCreate_MFSRRV:
25727 + case AuWbrCreate_TDMFSV:
25728 + case AuWbrCreate_PMFSRRV:
25729 + e = au_wbr_mfs_wmark(&args[0], str, create);
25731 + e = au_wbr_mfs_sec(&args[1], str, create);
25735 + case AuWbrCreate_MFSRR:
25736 + case AuWbrCreate_TDMFS:
25737 + case AuWbrCreate_PMFSRR:
25738 + e = au_wbr_mfs_wmark(&args[0], str, create);
25739 + if (unlikely(e)) {
25744 + case AuWbrCreate_MFS:
25745 + case AuWbrCreate_PMFS:
25746 + create->mfs_second = AUFS_MFS_DEF_SEC;
25748 + case AuWbrCreate_MFSV:
25749 + case AuWbrCreate_PMFSV:
25750 + e = au_wbr_mfs_sec(&args[0], str, create);
25759 +const char *au_optstr_wbr_create(int wbr_create)
25761 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
25764 +static match_table_t au_wbr_copyup_policy = {
25765 + {AuWbrCopyup_TDP, "tdp"},
25766 + {AuWbrCopyup_TDP, "top-down-parent"},
25767 + {AuWbrCopyup_BUP, "bup"},
25768 + {AuWbrCopyup_BUP, "bottom-up-parent"},
25769 + {AuWbrCopyup_BU, "bu"},
25770 + {AuWbrCopyup_BU, "bottom-up"},
25774 +static int noinline_for_stack au_wbr_copyup_val(char *str)
25776 + substring_t args[MAX_OPT_ARGS];
25778 + return match_token(str, au_wbr_copyup_policy, args);
25781 +const char *au_optstr_wbr_copyup(int wbr_copyup)
25783 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
25786 +/* ---------------------------------------------------------------------- */
25788 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
25790 +static void dump_opts(struct au_opts *opts)
25792 +#ifdef CONFIG_AUFS_DEBUG
25793 + /* reduce stack space */
25795 + struct au_opt_add *add;
25796 + struct au_opt_del *del;
25797 + struct au_opt_mod *mod;
25798 + struct au_opt_xino *xino;
25799 + struct au_opt_xino_itrunc *xino_itrunc;
25800 + struct au_opt_wbr_create *create;
25802 + struct au_opt *opt;
25805 + while (opt->type != Opt_tail) {
25806 + switch (opt->type) {
25808 + u.add = &opt->add;
25809 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
25810 + u.add->bindex, u.add->pathname, u.add->perm,
25811 + u.add->path.dentry);
25815 + u.del = &opt->del;
25816 + AuDbg("del {%s, %p}\n",
25817 + u.del->pathname, u.del->h_path.dentry);
25821 + u.mod = &opt->mod;
25822 + AuDbg("mod {%s, 0x%x, %p}\n",
25823 + u.mod->path, u.mod->perm, u.mod->h_root);
25826 + u.add = &opt->add;
25827 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
25828 + u.add->bindex, u.add->pathname, u.add->perm,
25829 + u.add->path.dentry);
25831 + case Opt_prepend:
25832 + u.add = &opt->add;
25833 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
25834 + u.add->bindex, u.add->pathname, u.add->perm,
25835 + u.add->path.dentry);
25838 + AuDbg("dirwh %d\n", opt->dirwh);
25840 + case Opt_rdcache:
25841 + AuDbg("rdcache %d\n", opt->rdcache);
25844 + AuDbg("rdblk %u\n", opt->rdblk);
25846 + case Opt_rdblk_def:
25847 + AuDbg("rdblk_def\n");
25850 + AuDbg("rdhash %u\n", opt->rdhash);
25852 + case Opt_rdhash_def:
25853 + AuDbg("rdhash_def\n");
25856 + u.xino = &opt->xino;
25857 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
25859 + case Opt_trunc_xino:
25860 + AuLabel(trunc_xino);
25862 + case Opt_notrunc_xino:
25863 + AuLabel(notrunc_xino);
25865 + case Opt_trunc_xino_path:
25866 + case Opt_itrunc_xino:
25867 + u.xino_itrunc = &opt->xino_itrunc;
25868 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
25873 + case Opt_trunc_xib:
25874 + AuLabel(trunc_xib);
25876 + case Opt_notrunc_xib:
25877 + AuLabel(notrunc_xib);
25885 + case Opt_dirperm1:
25886 + AuLabel(dirperm1);
25888 + case Opt_nodirperm1:
25889 + AuLabel(nodirperm1);
25894 + case Opt_noplink:
25895 + AuLabel(noplink);
25897 + case Opt_list_plink:
25898 + AuLabel(list_plink);
25901 + AuDbg("udba %d, %s\n",
25902 + opt->udba, au_optstr_udba(opt->udba));
25910 + case Opt_diropq_a:
25911 + AuLabel(diropq_a);
25913 + case Opt_diropq_w:
25914 + AuLabel(diropq_w);
25916 + case Opt_warn_perm:
25917 + AuLabel(warn_perm);
25919 + case Opt_nowarn_perm:
25920 + AuLabel(nowarn_perm);
25922 + case Opt_verbose:
25923 + AuLabel(verbose);
25925 + case Opt_noverbose:
25926 + AuLabel(noverbose);
25937 + case Opt_wbr_create:
25938 + u.create = &opt->wbr_create;
25939 + AuDbg("create %d, %s\n", u.create->wbr_create,
25940 + au_optstr_wbr_create(u.create->wbr_create));
25941 + switch (u.create->wbr_create) {
25942 + case AuWbrCreate_MFSV:
25943 + case AuWbrCreate_PMFSV:
25944 + AuDbg("%d sec\n", u.create->mfs_second);
25946 + case AuWbrCreate_MFSRR:
25947 + case AuWbrCreate_TDMFS:
25948 + AuDbg("%llu watermark\n",
25949 + u.create->mfsrr_watermark);
25951 + case AuWbrCreate_MFSRRV:
25952 + case AuWbrCreate_TDMFSV:
25953 + case AuWbrCreate_PMFSRRV:
25954 + AuDbg("%llu watermark, %d sec\n",
25955 + u.create->mfsrr_watermark,
25956 + u.create->mfs_second);
25960 + case Opt_wbr_copyup:
25961 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
25962 + au_optstr_wbr_copyup(opt->wbr_copyup));
25964 + case Opt_fhsm_sec:
25965 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
25970 + case Opt_nodirren:
25971 + AuLabel(nodirren);
25987 +void au_opts_free(struct au_opts *opts)
25989 + struct au_opt *opt;
25992 + while (opt->type != Opt_tail) {
25993 + switch (opt->type) {
25996 + case Opt_prepend:
25997 + path_put(&opt->add.path);
26001 + path_put(&opt->del.h_path);
26005 + dput(opt->mod.h_root);
26008 + fput(opt->xino.file);
26015 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26016 + aufs_bindex_t bindex)
26019 + struct au_opt_add *add = &opt->add;
26022 + add->bindex = bindex;
26023 + add->perm = AuBrPerm_RO;
26024 + add->pathname = opt_str;
26025 + p = strchr(opt_str, '=');
26029 + add->perm = br_perm_val(p);
26032 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26035 + add->perm = AuBrPerm_RO;
26036 + if (au_test_fs_rr(add->path.dentry->d_sb))
26037 + add->perm = AuBrPerm_RR;
26038 + else if (!bindex && !(sb_flags & MS_RDONLY))
26039 + add->perm = AuBrPerm_RW;
26041 + opt->type = Opt_add;
26044 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26051 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26055 + del->pathname = args[0].from;
26056 + AuDbg("del path %s\n", del->pathname);
26058 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26059 + if (unlikely(err))
26060 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26065 +#if 0 /* reserved for future use */
26066 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26067 + struct au_opt_del *del, substring_t args[])
26070 + struct dentry *root;
26073 + root = sb->s_root;
26074 + aufs_read_lock(root, AuLock_FLUSH);
26075 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26076 + pr_err("out of bounds, %d\n", bindex);
26081 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26082 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26085 + aufs_read_unlock(root, !AuLock_IR);
26090 +static int noinline_for_stack
26091 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26094 + struct path path;
26098 + mod->path = args[0].from;
26099 + p = strchr(mod->path, '=');
26100 + if (unlikely(!p)) {
26101 + pr_err("no permssion %s\n", args[0].from);
26106 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26107 + if (unlikely(err)) {
26108 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26112 + mod->perm = br_perm_val(p);
26113 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26114 + mod->h_root = dget(path.dentry);
26121 +#if 0 /* reserved for future use */
26122 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26123 + struct au_opt_mod *mod, substring_t args[])
26126 + struct dentry *root;
26129 + root = sb->s_root;
26130 + aufs_read_lock(root, AuLock_FLUSH);
26131 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26132 + pr_err("out of bounds, %d\n", bindex);
26137 + mod->perm = br_perm_val(args[1].from);
26138 + AuDbg("mod path %s, perm 0x%x, %s\n",
26139 + mod->path, mod->perm, args[1].from);
26140 + mod->h_root = dget(au_h_dptr(root, bindex));
26143 + aufs_read_unlock(root, !AuLock_IR);
26148 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26149 + substring_t args[])
26152 + struct file *file;
26154 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26155 + err = PTR_ERR(file);
26156 + if (IS_ERR(file))
26160 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26162 + pr_err("%s must be outside\n", args[0].from);
26167 + xino->file = file;
26168 + xino->path = args[0].from;
26174 +static int noinline_for_stack
26175 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26176 + struct au_opt_xino_itrunc *xino_itrunc,
26177 + substring_t args[])
26180 + aufs_bindex_t bbot, bindex;
26181 + struct path path;
26182 + struct dentry *root;
26184 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26185 + if (unlikely(err)) {
26186 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26190 + xino_itrunc->bindex = -1;
26191 + root = sb->s_root;
26192 + aufs_read_lock(root, AuLock_FLUSH);
26193 + bbot = au_sbbot(sb);
26194 + for (bindex = 0; bindex <= bbot; bindex++) {
26195 + if (au_h_dptr(root, bindex) == path.dentry) {
26196 + xino_itrunc->bindex = bindex;
26200 + aufs_read_unlock(root, !AuLock_IR);
26203 + if (unlikely(xino_itrunc->bindex < 0)) {
26204 + pr_err("no such branch %s\n", args[0].from);
26212 +/* called without aufs lock */
26213 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26215 + int err, n, token;
26216 + aufs_bindex_t bindex;
26217 + unsigned char skipped;
26218 + struct dentry *root;
26219 + struct au_opt *opt, *opt_tail;
26221 + /* reduce the stack space */
26223 + struct au_opt_xino_itrunc *xino_itrunc;
26224 + struct au_opt_wbr_create *create;
26227 + substring_t args[MAX_OPT_ARGS];
26231 + a = kmalloc(sizeof(*a), GFP_NOFS);
26232 + if (unlikely(!a))
26235 + root = sb->s_root;
26239 + opt_tail = opt + opts->max_opt - 1;
26240 + opt->type = Opt_tail;
26241 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26244 + token = match_token(opt_str, options, a->args);
26248 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26250 + err = opt_add(opt, opt_str, opts->sb_flags,
26252 + if (unlikely(!err && ++opt > opt_tail)) {
26256 + opt->type = Opt_tail;
26261 + if (unlikely(match_int(&a->args[0], &n))) {
26262 + pr_err("bad integer in %s\n", opt_str);
26266 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26269 + opt->type = token;
26272 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26273 + /*dummy bindex*/1);
26275 + opt->type = token;
26277 + case Opt_prepend:
26278 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26281 + opt->type = token;
26284 + err = au_opts_parse_del(&opt->del, a->args);
26286 + opt->type = token;
26288 +#if 0 /* reserved for future use */
26290 + del->pathname = "(indexed)";
26291 + if (unlikely(match_int(&args[0], &n))) {
26292 + pr_err("bad integer in %s\n", opt_str);
26295 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26297 + opt->type = token;
26301 + err = au_opts_parse_mod(&opt->mod, a->args);
26303 + opt->type = token;
26305 +#ifdef IMOD /* reserved for future use */
26307 + u.mod->path = "(indexed)";
26308 + if (unlikely(match_int(&a->args[0], &n))) {
26309 + pr_err("bad integer in %s\n", opt_str);
26312 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26314 + opt->type = token;
26318 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26320 + opt->type = token;
26323 + case Opt_trunc_xino_path:
26324 + err = au_opts_parse_xino_itrunc_path
26325 + (sb, &opt->xino_itrunc, a->args);
26327 + opt->type = token;
26330 + case Opt_itrunc_xino:
26331 + u.xino_itrunc = &opt->xino_itrunc;
26332 + if (unlikely(match_int(&a->args[0], &n))) {
26333 + pr_err("bad integer in %s\n", opt_str);
26336 + u.xino_itrunc->bindex = n;
26337 + aufs_read_lock(root, AuLock_FLUSH);
26338 + if (n < 0 || au_sbbot(sb) < n) {
26339 + pr_err("out of bounds, %d\n", n);
26340 + aufs_read_unlock(root, !AuLock_IR);
26343 + aufs_read_unlock(root, !AuLock_IR);
26345 + opt->type = token;
26349 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26352 + opt->type = token;
26355 + case Opt_rdcache:
26356 + if (unlikely(match_int(&a->args[0], &n))) {
26357 + pr_err("bad integer in %s\n", opt_str);
26360 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26361 + pr_err("rdcache must be smaller than %d\n",
26362 + AUFS_RDCACHE_MAX);
26365 + opt->rdcache = n;
26367 + opt->type = token;
26370 + if (unlikely(match_int(&a->args[0], &n)
26372 + || n > KMALLOC_MAX_SIZE)) {
26373 + pr_err("bad integer in %s\n", opt_str);
26376 + if (unlikely(n && n < NAME_MAX)) {
26377 + pr_err("rdblk must be larger than %d\n",
26383 + opt->type = token;
26386 + if (unlikely(match_int(&a->args[0], &n)
26388 + || n * sizeof(struct hlist_head)
26389 + > KMALLOC_MAX_SIZE)) {
26390 + pr_err("bad integer in %s\n", opt_str);
26395 + opt->type = token;
26398 + case Opt_trunc_xino:
26399 + case Opt_notrunc_xino:
26401 + case Opt_trunc_xib:
26402 + case Opt_notrunc_xib:
26405 + case Opt_dirperm1:
26406 + case Opt_nodirperm1:
26408 + case Opt_noplink:
26409 + case Opt_list_plink:
26412 + case Opt_diropq_a:
26413 + case Opt_diropq_w:
26414 + case Opt_warn_perm:
26415 + case Opt_nowarn_perm:
26416 + case Opt_verbose:
26417 + case Opt_noverbose:
26421 + case Opt_rdblk_def:
26422 + case Opt_rdhash_def:
26424 + case Opt_nodirren:
26428 + opt->type = token;
26432 + opt->udba = udba_val(a->args[0].from);
26433 + if (opt->udba >= 0) {
26435 + opt->type = token;
26437 + pr_err("wrong value, %s\n", opt_str);
26440 + case Opt_wbr_create:
26441 + u.create = &opt->wbr_create;
26442 + u.create->wbr_create
26443 + = au_wbr_create_val(a->args[0].from, u.create);
26444 + if (u.create->wbr_create >= 0) {
26446 + opt->type = token;
26448 + pr_err("wrong value, %s\n", opt_str);
26450 + case Opt_wbr_copyup:
26451 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26452 + if (opt->wbr_copyup >= 0) {
26454 + opt->type = token;
26456 + pr_err("wrong value, %s\n", opt_str);
26459 + case Opt_fhsm_sec:
26460 + if (unlikely(match_int(&a->args[0], &n)
26462 + pr_err("bad integer in %s\n", opt_str);
26465 + if (sysaufs_brs) {
26466 + opt->fhsm_second = n;
26467 + opt->type = token;
26469 + pr_warn("ignored %s\n", opt_str);
26474 + pr_warn("ignored %s\n", opt_str);
26476 + case Opt_ignore_silent:
26481 + pr_err("unknown option %s\n", opt_str);
26485 + if (!err && !skipped) {
26486 + if (unlikely(++opt > opt_tail)) {
26489 + opt->type = Opt_tail;
26492 + opt->type = Opt_tail;
26498 + if (unlikely(err))
26499 + au_opts_free(opts);
26505 +static int au_opt_wbr_create(struct super_block *sb,
26506 + struct au_opt_wbr_create *create)
26509 + struct au_sbinfo *sbinfo;
26511 + SiMustWriteLock(sb);
26513 + err = 1; /* handled */
26514 + sbinfo = au_sbi(sb);
26515 + if (sbinfo->si_wbr_create_ops->fin) {
26516 + err = sbinfo->si_wbr_create_ops->fin(sb);
26521 + sbinfo->si_wbr_create = create->wbr_create;
26522 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26523 + switch (create->wbr_create) {
26524 + case AuWbrCreate_MFSRRV:
26525 + case AuWbrCreate_MFSRR:
26526 + case AuWbrCreate_TDMFS:
26527 + case AuWbrCreate_TDMFSV:
26528 + case AuWbrCreate_PMFSRR:
26529 + case AuWbrCreate_PMFSRRV:
26530 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26532 + case AuWbrCreate_MFS:
26533 + case AuWbrCreate_MFSV:
26534 + case AuWbrCreate_PMFS:
26535 + case AuWbrCreate_PMFSV:
26536 + sbinfo->si_wbr_mfs.mfs_expire
26537 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26541 + if (sbinfo->si_wbr_create_ops->init)
26542 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26549 + * plus: processed without an error
26550 + * zero: unprocessed
26552 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26553 + struct au_opts *opts)
26556 + struct au_sbinfo *sbinfo;
26558 + SiMustWriteLock(sb);
26560 + err = 1; /* handled */
26561 + sbinfo = au_sbi(sb);
26562 + switch (opt->type) {
26564 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26565 + sbinfo->si_mntflags |= opt->udba;
26566 + opts->given_udba |= opt->udba;
26570 + au_opt_set(sbinfo->si_mntflags, PLINK);
26572 + case Opt_noplink:
26573 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26574 + au_plink_put(sb, /*verbose*/1);
26575 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26577 + case Opt_list_plink:
26578 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26579 + au_plink_list(sb);
26583 + au_opt_set(sbinfo->si_mntflags, DIO);
26584 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26587 + au_opt_clr(sbinfo->si_mntflags, DIO);
26588 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26591 + case Opt_fhsm_sec:
26592 + au_fhsm_set(sbinfo, opt->fhsm_second);
26595 + case Opt_diropq_a:
26596 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26598 + case Opt_diropq_w:
26599 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26602 + case Opt_warn_perm:
26603 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26605 + case Opt_nowarn_perm:
26606 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26609 + case Opt_verbose:
26610 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26612 + case Opt_noverbose:
26613 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26617 + au_opt_set(sbinfo->si_mntflags, SUM);
26620 + au_opt_clr(sbinfo->si_mntflags, SUM);
26621 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26623 + au_opt_clr(sbinfo->si_mntflags, SUM);
26624 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26627 + case Opt_wbr_create:
26628 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26630 + case Opt_wbr_copyup:
26631 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26632 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26636 + sbinfo->si_dirwh = opt->dirwh;
26639 + case Opt_rdcache:
26640 + sbinfo->si_rdcache
26641 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26644 + sbinfo->si_rdblk = opt->rdblk;
26646 + case Opt_rdblk_def:
26647 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26650 + sbinfo->si_rdhash = opt->rdhash;
26652 + case Opt_rdhash_def:
26653 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26657 + au_opt_set(sbinfo->si_mntflags, SHWH);
26660 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26663 + case Opt_dirperm1:
26664 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26666 + case Opt_nodirperm1:
26667 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26670 + case Opt_trunc_xino:
26671 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26673 + case Opt_notrunc_xino:
26674 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26677 + case Opt_trunc_xino_path:
26678 + case Opt_itrunc_xino:
26679 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
26684 + case Opt_trunc_xib:
26685 + au_fset_opts(opts->flags, TRUNC_XIB);
26687 + case Opt_notrunc_xib:
26688 + au_fclr_opts(opts->flags, TRUNC_XIB);
26693 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26694 + err = au_dr_opt_set(sb);
26699 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26701 + case Opt_nodirren:
26703 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26704 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26710 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26714 + sb->s_flags |= MS_POSIXACL;
26717 + sb->s_flags &= ~MS_POSIXACL;
26729 + * returns tri-state.
26730 + * plus: processed without an error
26731 + * zero: unprocessed
26734 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
26735 + struct au_opts *opts)
26737 + int err, do_refresh;
26740 + switch (opt->type) {
26742 + opt->add.bindex = au_sbbot(sb) + 1;
26743 + if (opt->add.bindex < 0)
26744 + opt->add.bindex = 0;
26746 + case Opt_prepend:
26747 + opt->add.bindex = 0;
26748 + add: /* indented label */
26750 + err = au_br_add(sb, &opt->add,
26751 + au_ftest_opts(opts->flags, REMOUNT));
26754 + au_fset_opts(opts->flags, REFRESH);
26760 + err = au_br_del(sb, &opt->del,
26761 + au_ftest_opts(opts->flags, REMOUNT));
26764 + au_fset_opts(opts->flags, TRUNC_XIB);
26765 + au_fset_opts(opts->flags, REFRESH);
26771 + err = au_br_mod(sb, &opt->mod,
26772 + au_ftest_opts(opts->flags, REMOUNT),
26777 + au_fset_opts(opts->flags, REFRESH);
26784 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
26785 + struct au_opt_xino **opt_xino,
26786 + struct au_opts *opts)
26789 + aufs_bindex_t bbot, bindex;
26790 + struct dentry *root, *parent, *h_root;
26793 + switch (opt->type) {
26795 + err = au_xino_set(sb, &opt->xino,
26796 + !!au_ftest_opts(opts->flags, REMOUNT));
26797 + if (unlikely(err))
26800 + *opt_xino = &opt->xino;
26801 + au_xino_brid_set(sb, -1);
26803 + /* safe d_parent access */
26804 + parent = opt->xino.file->f_path.dentry->d_parent;
26805 + root = sb->s_root;
26806 + bbot = au_sbbot(sb);
26807 + for (bindex = 0; bindex <= bbot; bindex++) {
26808 + h_root = au_h_dptr(root, bindex);
26809 + if (h_root == parent) {
26810 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
26818 + au_xino_brid_set(sb, -1);
26819 + *opt_xino = (void *)-1;
26826 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
26827 + unsigned int pending)
26830 + aufs_bindex_t bindex, bbot;
26831 + unsigned char do_plink, skip, do_free, can_no_dreval;
26832 + struct au_branch *br;
26833 + struct au_wbr *wbr;
26834 + struct dentry *root, *dentry;
26835 + struct inode *dir, *h_dir;
26836 + struct au_sbinfo *sbinfo;
26837 + struct au_hinode *hdir;
26839 + SiMustAnyLock(sb);
26841 + sbinfo = au_sbi(sb);
26842 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
26844 + if (!(sb_flags & MS_RDONLY)) {
26845 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
26846 + pr_warn("first branch should be rw\n");
26847 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
26848 + pr_warn_once("shwh should be used with ro\n");
26851 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
26852 + && !au_opt_test(sbinfo->si_mntflags, XINO))
26853 + pr_warn_once("udba=*notify requires xino\n");
26855 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
26856 + pr_warn_once("dirperm1 breaks the protection"
26857 + " by the permission bits on the lower branch\n");
26861 + root = sb->s_root;
26862 + dir = d_inode(root);
26863 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
26864 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
26866 + bbot = au_sbbot(sb);
26867 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
26869 + h_dir = au_h_iptr(dir, bindex);
26870 + br = au_sbr(sb, bindex);
26872 + if ((br->br_perm & AuBrAttr_ICEX)
26873 + && !h_dir->i_op->listxattr)
26874 + br->br_perm &= ~AuBrAttr_ICEX;
26876 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
26877 + && (au_br_sb(br)->s_flags & MS_NOSEC))
26878 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
26882 + wbr = br->br_wbr;
26884 + wbr_wh_read_lock(wbr);
26886 + if (!au_br_writable(br->br_perm)) {
26889 + || (!wbr->wbr_whbase
26890 + && !wbr->wbr_plink
26891 + && !wbr->wbr_orph));
26892 + } else if (!au_br_wh_linkable(br->br_perm)) {
26893 + /* skip = (!br->br_whbase && !br->br_orph); */
26894 + skip = (!wbr || !wbr->wbr_whbase);
26895 + if (skip && wbr) {
26897 + skip = !!wbr->wbr_plink;
26899 + skip = !wbr->wbr_plink;
26902 + /* skip = (br->br_whbase && br->br_ohph); */
26903 + skip = (wbr && wbr->wbr_whbase);
26906 + skip = !!wbr->wbr_plink;
26908 + skip = !wbr->wbr_plink;
26912 + wbr_wh_read_unlock(wbr);
26914 + if (can_no_dreval) {
26915 + dentry = br->br_path.dentry;
26916 + spin_lock(&dentry->d_lock);
26917 + if (dentry->d_flags &
26918 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
26919 + can_no_dreval = 0;
26920 + spin_unlock(&dentry->d_lock);
26923 + if (au_br_fhsm(br->br_perm)) {
26925 + AuDebugOn(!br->br_fhsm);
26931 + hdir = au_hi(dir, bindex);
26932 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
26934 + wbr_wh_write_lock(wbr);
26935 + err = au_wh_init(br, sb);
26937 + wbr_wh_write_unlock(wbr);
26938 + au_hn_inode_unlock(hdir);
26940 + if (!err && do_free) {
26942 + br->br_wbr = NULL;
26946 + if (can_no_dreval)
26947 + au_fset_si(sbinfo, NO_DREVAL);
26949 + au_fclr_si(sbinfo, NO_DREVAL);
26952 + au_fset_si(sbinfo, FHSM);
26953 + for (bindex = bbot; bindex >= 0; bindex--) {
26954 + br = au_sbr(sb, bindex);
26955 + if (au_br_fhsm(br->br_perm)) {
26956 + au_fhsm_set_bottom(sb, bindex);
26961 + au_fclr_si(sbinfo, FHSM);
26962 + au_fhsm_set_bottom(sb, -1);
26968 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
26971 + unsigned int tmp;
26972 + aufs_bindex_t bindex, bbot;
26973 + struct au_opt *opt;
26974 + struct au_opt_xino *opt_xino, xino;
26975 + struct au_sbinfo *sbinfo;
26976 + struct au_branch *br;
26977 + struct inode *dir;
26979 + SiMustWriteLock(sb);
26984 + while (err >= 0 && opt->type != Opt_tail)
26985 + err = au_opt_simple(sb, opt++, opts);
26988 + else if (unlikely(err < 0))
26991 + /* disable xino and udba temporary */
26992 + sbinfo = au_sbi(sb);
26993 + tmp = sbinfo->si_mntflags;
26994 + au_opt_clr(sbinfo->si_mntflags, XINO);
26995 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
26998 + while (err >= 0 && opt->type != Opt_tail)
26999 + err = au_opt_br(sb, opt++, opts);
27002 + else if (unlikely(err < 0))
27005 + bbot = au_sbbot(sb);
27006 + if (unlikely(bbot < 0)) {
27008 + pr_err("no branches\n");
27012 + if (au_opt_test(tmp, XINO))
27013 + au_opt_set(sbinfo->si_mntflags, XINO);
27015 + while (!err && opt->type != Opt_tail)
27016 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27017 + if (unlikely(err))
27020 + err = au_opts_verify(sb, sb->s_flags, tmp);
27021 + if (unlikely(err))
27024 + /* restore xino */
27025 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27026 + xino.file = au_xino_def(sb);
27027 + err = PTR_ERR(xino.file);
27028 + if (IS_ERR(xino.file))
27031 + err = au_xino_set(sb, &xino, /*remount*/0);
27033 + if (unlikely(err))
27037 + /* restore udba */
27038 + tmp &= AuOptMask_UDBA;
27039 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27040 + sbinfo->si_mntflags |= tmp;
27041 + bbot = au_sbbot(sb);
27042 + for (bindex = 0; bindex <= bbot; bindex++) {
27043 + br = au_sbr(sb, bindex);
27044 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27045 + if (unlikely(err))
27046 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27048 + /* go on even if err */
27050 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27051 + dir = d_inode(sb->s_root);
27052 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27059 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27062 + unsigned char no_dreval;
27063 + struct inode *dir;
27064 + struct au_opt_xino *opt_xino;
27065 + struct au_opt *opt;
27066 + struct au_sbinfo *sbinfo;
27068 + SiMustWriteLock(sb);
27070 + err = au_dr_opt_flush(sb);
27071 + if (unlikely(err))
27073 + au_fset_opts(opts->flags, DR_FLUSHED);
27075 + dir = d_inode(sb->s_root);
27076 + sbinfo = au_sbi(sb);
27079 + while (err >= 0 && opt->type != Opt_tail) {
27080 + err = au_opt_simple(sb, opt, opts);
27082 + err = au_opt_br(sb, opt, opts);
27084 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27090 + /* go on even err */
27092 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27093 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27094 + if (unlikely(rerr && !err))
27097 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27098 + au_fset_opts(opts->flags, REFRESH_IDOP);
27100 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27101 + rerr = au_xib_trunc(sb);
27102 + if (unlikely(rerr && !err))
27106 + /* will be handled by the caller */
27107 + if (!au_ftest_opts(opts->flags, REFRESH)
27108 + && (opts->given_udba
27109 + || au_opt_test(sbinfo->si_mntflags, XINO)
27110 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27112 + au_fset_opts(opts->flags, REFRESH);
27114 + AuDbg("status 0x%x\n", opts->flags);
27120 +/* ---------------------------------------------------------------------- */
27122 +unsigned int au_opt_udba(struct super_block *sb)
27124 + return au_mntflags(sb) & AuOptMask_UDBA;
27126 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27127 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27128 +++ linux/fs/aufs/opts.h 2018-04-15 08:49:13.401150731 +0200
27131 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27133 + * This program, aufs is free software; you can redistribute it and/or modify
27134 + * it under the terms of the GNU General Public License as published by
27135 + * the Free Software Foundation; either version 2 of the License, or
27136 + * (at your option) any later version.
27138 + * This program is distributed in the hope that it will be useful,
27139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27141 + * GNU General Public License for more details.
27143 + * You should have received a copy of the GNU General Public License
27144 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27148 + * mount options/flags
27151 +#ifndef __AUFS_OPTS_H__
27152 +#define __AUFS_OPTS_H__
27156 +#include <linux/path.h>
27160 +/* ---------------------------------------------------------------------- */
27163 +#define AuOpt_XINO 1 /* external inode number bitmap
27164 + and translation table */
27165 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27166 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27167 +#define AuOpt_UDBA_REVAL (1 << 3)
27168 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27169 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27170 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27171 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27173 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27174 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27175 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27176 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27177 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27178 +#define AuOpt_DIO (1 << 14) /* direct io */
27179 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27181 +#ifndef CONFIG_AUFS_HNOTIFY
27182 +#undef AuOpt_UDBA_HNOTIFY
27183 +#define AuOpt_UDBA_HNOTIFY 0
27185 +#ifndef CONFIG_AUFS_DIRREN
27186 +#undef AuOpt_DIRREN
27187 +#define AuOpt_DIRREN 0
27189 +#ifndef CONFIG_AUFS_SHWH
27191 +#define AuOpt_SHWH 0
27194 +#define AuOpt_Def (AuOpt_XINO \
27195 + | AuOpt_UDBA_REVAL \
27197 + /* | AuOpt_DIRPERM1 */ \
27198 + | AuOpt_WARN_PERM)
27199 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27200 + | AuOpt_UDBA_REVAL \
27201 + | AuOpt_UDBA_HNOTIFY)
27203 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27204 +#define au_opt_set(flags, name) do { \
27205 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27206 + ((flags) |= AuOpt_##name); \
27208 +#define au_opt_set_udba(flags, name) do { \
27209 + (flags) &= ~AuOptMask_UDBA; \
27210 + ((flags) |= AuOpt_##name); \
27212 +#define au_opt_clr(flags, name) do { \
27213 + ((flags) &= ~AuOpt_##name); \
27216 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27218 +#ifdef CONFIG_PROC_FS
27221 + return mntflags & ~AuOpt_PLINK;
27225 +/* ---------------------------------------------------------------------- */
27227 +/* policies to select one among multiple writable branches */
27229 + AuWbrCreate_TDP, /* top down parent */
27230 + AuWbrCreate_RR, /* round robin */
27231 + AuWbrCreate_MFS, /* most free space */
27232 + AuWbrCreate_MFSV, /* mfs with seconds */
27233 + AuWbrCreate_MFSRR, /* mfs then rr */
27234 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27235 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27236 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27237 + AuWbrCreate_PMFS, /* parent and mfs */
27238 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27239 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27240 + AuWbrCreate_PMFSRRV, /* plus seconds */
27242 + AuWbrCreate_Def = AuWbrCreate_TDP
27246 + AuWbrCopyup_TDP, /* top down parent */
27247 + AuWbrCopyup_BUP, /* bottom up parent */
27248 + AuWbrCopyup_BU, /* bottom up */
27250 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27253 +/* ---------------------------------------------------------------------- */
27255 +struct au_opt_add {
27256 + aufs_bindex_t bindex;
27259 + struct path path;
27262 +struct au_opt_del {
27264 + struct path h_path;
27267 +struct au_opt_mod {
27270 + struct dentry *h_root;
27273 +struct au_opt_xino {
27275 + struct file *file;
27278 +struct au_opt_xino_itrunc {
27279 + aufs_bindex_t bindex;
27282 +struct au_opt_wbr_create {
27285 + unsigned long long mfsrr_watermark;
27291 + struct au_opt_xino xino;
27292 + struct au_opt_xino_itrunc xino_itrunc;
27293 + struct au_opt_add add;
27294 + struct au_opt_del del;
27295 + struct au_opt_mod mod;
27298 + unsigned int rdblk;
27299 + unsigned int rdhash;
27301 + struct au_opt_wbr_create wbr_create;
27303 + unsigned int fhsm_second;
27308 +#define AuOpts_REMOUNT 1
27309 +#define AuOpts_REFRESH (1 << 1)
27310 +#define AuOpts_TRUNC_XIB (1 << 2)
27311 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27312 +#define AuOpts_REFRESH_IDOP (1 << 4)
27313 +#define AuOpts_DR_FLUSHED (1 << 5)
27314 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27315 +#define au_fset_opts(flags, name) \
27316 + do { (flags) |= AuOpts_##name; } while (0)
27317 +#define au_fclr_opts(flags, name) \
27318 + do { (flags) &= ~AuOpts_##name; } while (0)
27320 +#ifndef CONFIG_AUFS_DIRREN
27321 +#undef AuOpts_DR_FLUSHED
27322 +#define AuOpts_DR_FLUSHED 0
27326 + struct au_opt *opt;
27329 + unsigned int given_udba;
27330 + unsigned int flags;
27331 + unsigned long sb_flags;
27334 +/* ---------------------------------------------------------------------- */
27337 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27338 +const char *au_optstr_udba(int udba);
27339 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27340 +const char *au_optstr_wbr_create(int wbr_create);
27342 +void au_opts_free(struct au_opts *opts);
27343 +struct super_block;
27344 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27345 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27346 + unsigned int pending);
27347 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27348 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27350 +unsigned int au_opt_udba(struct super_block *sb);
27352 +#endif /* __KERNEL__ */
27353 +#endif /* __AUFS_OPTS_H__ */
27354 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27355 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27356 +++ linux/fs/aufs/plink.c 2018-04-15 08:49:13.401150731 +0200
27359 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27361 + * This program, aufs is free software; you can redistribute it and/or modify
27362 + * it under the terms of the GNU General Public License as published by
27363 + * the Free Software Foundation; either version 2 of the License, or
27364 + * (at your option) any later version.
27366 + * This program is distributed in the hope that it will be useful,
27367 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27368 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27369 + * GNU General Public License for more details.
27371 + * You should have received a copy of the GNU General Public License
27372 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27382 + * the pseudo-link maintenance mode.
27383 + * during a user process maintains the pseudo-links,
27384 + * prohibit adding a new plink and branch manipulation.
27388 + * For entry functions which will handle plink, and i_mutex is already held
27390 + * They cannot wait and should return an error at once.
27391 + * Callers has to check the error.
27393 + * For entry functions which will handle plink, but i_mutex is not held
27395 + * They can wait the plink maintenance mode to finish.
27397 + * They behave like F_SETLK and F_SETLKW.
27398 + * If the caller never handle plink, then both flags are unnecessary.
27401 +int au_plink_maint(struct super_block *sb, int flags)
27405 + struct task_struct *parent, *prev;
27406 + struct au_sbinfo *sbi;
27408 + SiMustAnyLock(sb);
27411 + if (!au_opt_test(au_mntflags(sb), PLINK))
27414 + sbi = au_sbi(sb);
27415 + pid = sbi->si_plink_maint_pid;
27416 + if (!pid || pid == current->pid)
27419 + /* todo: it highly depends upon /sbin/mount.aufs */
27421 + parent = current;
27425 + parent = rcu_dereference(parent->real_parent);
27426 + if (parent == prev)
27428 + ppid = task_pid_vnr(parent);
27429 + if (pid == ppid) {
27430 + rcu_read_unlock();
27435 + rcu_read_unlock();
27437 + if (au_ftest_lock(flags, NOPLMW)) {
27438 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27439 + /* AuDebugOn(!lockdep_depth(current)); */
27440 + while (sbi->si_plink_maint_pid) {
27441 + si_read_unlock(sb);
27442 + /* gave up wake_up_bit() */
27443 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27445 + if (au_ftest_lock(flags, FLUSH))
27446 + au_nwt_flush(&sbi->si_nowait);
27447 + si_noflush_read_lock(sb);
27449 + } else if (au_ftest_lock(flags, NOPLM)) {
27450 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27458 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27460 + spin_lock(&sbinfo->si_plink_maint_lock);
27461 + sbinfo->si_plink_maint_pid = 0;
27462 + spin_unlock(&sbinfo->si_plink_maint_lock);
27463 + wake_up_all(&sbinfo->si_plink_wq);
27466 +int au_plink_maint_enter(struct super_block *sb)
27469 + struct au_sbinfo *sbinfo;
27472 + sbinfo = au_sbi(sb);
27473 + /* make sure i am the only one in this fs */
27474 + si_write_lock(sb, AuLock_FLUSH);
27475 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27476 + spin_lock(&sbinfo->si_plink_maint_lock);
27477 + if (!sbinfo->si_plink_maint_pid)
27478 + sbinfo->si_plink_maint_pid = current->pid;
27481 + spin_unlock(&sbinfo->si_plink_maint_lock);
27483 + si_write_unlock(sb);
27488 +/* ---------------------------------------------------------------------- */
27490 +#ifdef CONFIG_AUFS_DEBUG
27491 +void au_plink_list(struct super_block *sb)
27494 + struct au_sbinfo *sbinfo;
27495 + struct hlist_bl_head *hbl;
27496 + struct hlist_bl_node *pos;
27497 + struct au_icntnr *icntnr;
27499 + SiMustAnyLock(sb);
27501 + sbinfo = au_sbi(sb);
27502 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27503 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27505 + for (i = 0; i < AuPlink_NHASH; i++) {
27506 + hbl = sbinfo->si_plink + i;
27507 + hlist_bl_lock(hbl);
27508 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27509 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27510 + hlist_bl_unlock(hbl);
27515 +/* is the inode pseudo-linked? */
27516 +int au_plink_test(struct inode *inode)
27519 + struct au_sbinfo *sbinfo;
27520 + struct hlist_bl_head *hbl;
27521 + struct hlist_bl_node *pos;
27522 + struct au_icntnr *icntnr;
27524 + sbinfo = au_sbi(inode->i_sb);
27525 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27526 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27527 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27530 + i = au_plink_hash(inode->i_ino);
27531 + hbl = sbinfo->si_plink + i;
27532 + hlist_bl_lock(hbl);
27533 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27534 + if (&icntnr->vfs_inode == inode) {
27538 + hlist_bl_unlock(hbl);
27542 +/* ---------------------------------------------------------------------- */
27545 + * generate a name for plink.
27546 + * the file will be stored under AUFS_WH_PLINKDIR.
27548 +/* 20 is max digits length of ulong 64 */
27549 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27551 +static int plink_name(char *name, int len, struct inode *inode,
27552 + aufs_bindex_t bindex)
27555 + struct inode *h_inode;
27557 + h_inode = au_h_iptr(inode, bindex);
27558 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27562 +struct au_do_plink_lkup_args {
27563 + struct dentry **errp;
27564 + struct qstr *tgtname;
27565 + struct dentry *h_parent;
27566 + struct au_branch *br;
27569 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27570 + struct dentry *h_parent,
27571 + struct au_branch *br)
27573 + struct dentry *h_dentry;
27574 + struct inode *h_inode;
27576 + h_inode = d_inode(h_parent);
27577 + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27578 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27579 + inode_unlock_shared(h_inode);
27583 +static void au_call_do_plink_lkup(void *args)
27585 + struct au_do_plink_lkup_args *a = args;
27586 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27589 +/* lookup the plink-ed @inode under the branch at @bindex */
27590 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27592 + struct dentry *h_dentry, *h_parent;
27593 + struct au_branch *br;
27595 + char a[PLINK_NAME_LEN];
27596 + struct qstr tgtname = QSTR_INIT(a, 0);
27598 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27600 + br = au_sbr(inode->i_sb, bindex);
27601 + h_parent = br->br_wbr->wbr_plink;
27602 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27604 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27605 + struct au_do_plink_lkup_args args = {
27606 + .errp = &h_dentry,
27607 + .tgtname = &tgtname,
27608 + .h_parent = h_parent,
27612 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27613 + if (unlikely(wkq_err))
27614 + h_dentry = ERR_PTR(wkq_err);
27616 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27621 +/* create a pseudo-link */
27622 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27623 + struct dentry *h_dentry, struct au_branch *br)
27626 + struct path h_path = {
27627 + .mnt = au_br_mnt(br)
27629 + struct inode *h_dir, *delegated;
27631 + h_dir = d_inode(h_parent);
27632 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27634 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27635 + err = PTR_ERR(h_path.dentry);
27636 + if (IS_ERR(h_path.dentry))
27640 + /* wh.plink dir is not monitored */
27641 + /* todo: is it really safe? */
27642 + if (d_is_positive(h_path.dentry)
27643 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27644 + delegated = NULL;
27645 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27646 + if (unlikely(err == -EWOULDBLOCK)) {
27647 + pr_warn("cannot retry for NFSv4 delegation"
27648 + " for an internal unlink\n");
27651 + dput(h_path.dentry);
27652 + h_path.dentry = NULL;
27656 + if (!err && d_is_negative(h_path.dentry)) {
27657 + delegated = NULL;
27658 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27659 + if (unlikely(err == -EWOULDBLOCK)) {
27660 + pr_warn("cannot retry for NFSv4 delegation"
27661 + " for an internal link\n");
27665 + dput(h_path.dentry);
27668 + inode_unlock(h_dir);
27672 +struct do_whplink_args {
27674 + struct qstr *tgt;
27675 + struct dentry *h_parent;
27676 + struct dentry *h_dentry;
27677 + struct au_branch *br;
27680 +static void call_do_whplink(void *args)
27682 + struct do_whplink_args *a = args;
27683 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27686 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27687 + aufs_bindex_t bindex, struct au_branch *br)
27689 + int err, wkq_err;
27690 + struct au_wbr *wbr;
27691 + struct dentry *h_parent;
27692 + char a[PLINK_NAME_LEN];
27693 + struct qstr tgtname = QSTR_INIT(a, 0);
27695 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27696 + h_parent = wbr->wbr_plink;
27697 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27699 + /* always superio. */
27700 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27701 + struct do_whplink_args args = {
27704 + .h_parent = h_parent,
27705 + .h_dentry = h_dentry,
27708 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27709 + if (unlikely(wkq_err))
27712 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
27718 + * create a new pseudo-link for @h_dentry on @bindex.
27719 + * the linked inode is held in aufs @inode.
27721 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27722 + struct dentry *h_dentry)
27724 + struct super_block *sb;
27725 + struct au_sbinfo *sbinfo;
27726 + struct hlist_bl_head *hbl;
27727 + struct hlist_bl_node *pos;
27728 + struct au_icntnr *icntnr;
27729 + int found, err, cnt, i;
27731 + sb = inode->i_sb;
27732 + sbinfo = au_sbi(sb);
27733 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27734 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27736 + found = au_plink_test(inode);
27740 + i = au_plink_hash(inode->i_ino);
27741 + hbl = sbinfo->si_plink + i;
27744 + hlist_bl_lock(hbl);
27745 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
27746 + if (&icntnr->vfs_inode == inode) {
27752 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
27753 + hlist_bl_add_head(&icntnr->plink, hbl);
27755 + hlist_bl_unlock(hbl);
27757 + cnt = au_hbl_count(hbl);
27758 +#define msg "unexpectedly unblanced or too many pseudo-links"
27759 + if (cnt > AUFS_PLINK_WARN)
27760 + AuWarn1(msg ", %d\n", cnt);
27762 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
27763 + if (unlikely(err)) {
27764 + pr_warn("err %d, damaged pseudo link.\n", err);
27765 + au_hbl_del(&icntnr->plink, hbl);
27766 + iput(&icntnr->vfs_inode);
27769 + iput(&icntnr->vfs_inode);
27772 +/* free all plinks */
27773 +void au_plink_put(struct super_block *sb, int verbose)
27776 + struct au_sbinfo *sbinfo;
27777 + struct hlist_bl_head *hbl;
27778 + struct hlist_bl_node *pos, *tmp;
27779 + struct au_icntnr *icntnr;
27781 + SiMustWriteLock(sb);
27783 + sbinfo = au_sbi(sb);
27784 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27785 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27787 + /* no spin_lock since sbinfo is write-locked */
27789 + for (i = 0; i < AuPlink_NHASH; i++) {
27790 + hbl = sbinfo->si_plink + i;
27791 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
27792 + pr_warn("pseudo-link is not flushed");
27795 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
27796 + iput(&icntnr->vfs_inode);
27797 + INIT_HLIST_BL_HEAD(hbl);
27801 +void au_plink_clean(struct super_block *sb, int verbose)
27803 + struct dentry *root;
27805 + root = sb->s_root;
27806 + aufs_write_lock(root);
27807 + if (au_opt_test(au_mntflags(sb), PLINK))
27808 + au_plink_put(sb, verbose);
27809 + aufs_write_unlock(root);
27812 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
27815 + aufs_bindex_t btop, bbot, bindex;
27818 + btop = au_ibtop(inode);
27819 + bbot = au_ibbot(inode);
27821 + for (bindex = btop; bindex <= bbot; bindex++) {
27822 + if (!au_h_iptr(inode, bindex)
27823 + || au_ii_br_id(inode, bindex) != br_id)
27825 + au_set_h_iptr(inode, bindex, NULL, 0);
27830 + for (bindex = btop; bindex <= bbot; bindex++)
27831 + if (au_h_iptr(inode, bindex)) {
27841 +/* free the plinks on a branch specified by @br_id */
27842 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
27844 + struct au_sbinfo *sbinfo;
27845 + struct hlist_bl_head *hbl;
27846 + struct hlist_bl_node *pos, *tmp;
27847 + struct au_icntnr *icntnr;
27848 + struct inode *inode;
27851 + SiMustWriteLock(sb);
27853 + sbinfo = au_sbi(sb);
27854 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27855 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27857 + /* no bit_lock since sbinfo is write-locked */
27858 + for (i = 0; i < AuPlink_NHASH; i++) {
27859 + hbl = sbinfo->si_plink + i;
27860 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
27861 + inode = au_igrab(&icntnr->vfs_inode);
27862 + ii_write_lock_child(inode);
27863 + do_put = au_plink_do_half_refresh(inode, br_id);
27865 + hlist_bl_del(&icntnr->plink);
27868 + ii_write_unlock(inode);
27873 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
27874 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
27875 +++ linux/fs/aufs/poll.c 2018-04-15 08:49:13.401150731 +0200
27878 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27880 + * This program, aufs is free software; you can redistribute it and/or modify
27881 + * it under the terms of the GNU General Public License as published by
27882 + * the Free Software Foundation; either version 2 of the License, or
27883 + * (at your option) any later version.
27885 + * This program is distributed in the hope that it will be useful,
27886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27888 + * GNU General Public License for more details.
27890 + * You should have received a copy of the GNU General Public License
27891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27896 + * There is only one filesystem which implements ->poll operation, currently.
27901 +unsigned int aufs_poll(struct file *file, poll_table *wait)
27903 + unsigned int mask;
27905 + struct file *h_file;
27906 + struct super_block *sb;
27908 + /* We should pretend an error happened. */
27909 + mask = POLLERR /* | POLLIN | POLLOUT */;
27910 + sb = file->f_path.dentry->d_sb;
27911 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
27913 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
27914 + err = PTR_ERR(h_file);
27915 + if (IS_ERR(h_file))
27918 + /* it is not an error if h_file has no operation */
27919 + mask = DEFAULT_POLLMASK;
27920 + if (h_file->f_op->poll)
27921 + mask = h_file->f_op->poll(h_file, wait);
27922 + fput(h_file); /* instead of au_read_post() */
27925 + si_read_unlock(sb);
27926 + if (mask & POLLERR)
27927 + AuDbg("mask 0x%x\n", mask);
27930 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
27931 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
27932 +++ linux/fs/aufs/posix_acl.c 2018-04-15 08:49:13.401150731 +0200
27935 + * Copyright (C) 2014-2018 Junjiro R. Okajima
27937 + * This program, aufs is free software; you can redistribute it and/or modify
27938 + * it under the terms of the GNU General Public License as published by
27939 + * the Free Software Foundation; either version 2 of the License, or
27940 + * (at your option) any later version.
27942 + * This program is distributed in the hope that it will be useful,
27943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27945 + * GNU General Public License for more details.
27947 + * You should have received a copy of the GNU General Public License
27948 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27952 + * posix acl operations
27955 +#include <linux/fs.h>
27958 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
27960 + struct posix_acl *acl;
27962 + aufs_bindex_t bindex;
27963 + struct inode *h_inode;
27964 + struct super_block *sb;
27967 + sb = inode->i_sb;
27968 + si_read_lock(sb, AuLock_FLUSH);
27969 + ii_read_lock_child(inode);
27970 + if (!(sb->s_flags & MS_POSIXACL))
27973 + bindex = au_ibtop(inode);
27974 + h_inode = au_h_iptr(inode, bindex);
27975 + if (unlikely(!h_inode
27976 + || ((h_inode->i_mode & S_IFMT)
27977 + != (inode->i_mode & S_IFMT)))) {
27978 + err = au_busy_or_stale();
27979 + acl = ERR_PTR(err);
27983 + /* always topmost only */
27984 + acl = get_acl(h_inode, type);
27985 + if (!IS_ERR_OR_NULL(acl))
27986 + set_cached_acl(inode, type, acl);
27989 + ii_read_unlock(inode);
27990 + si_read_unlock(sb);
27992 + AuTraceErrPtr(acl);
27996 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28000 + struct dentry *dentry;
28001 + struct au_sxattr arg = {
28002 + .type = AU_ACL_SET,
28009 + IMustLock(inode);
28011 + if (inode->i_ino == AUFS_ROOT_INO)
28012 + dentry = dget(inode->i_sb->s_root);
28014 + dentry = d_find_alias(inode);
28016 + dentry = d_find_any_alias(inode);
28018 + pr_warn("cannot handle this inode, "
28019 + "please report to aufs-users ML\n");
28025 + ssz = au_sxattr(dentry, inode, &arg);
28030 + set_cached_acl(inode, type, acl);
28036 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28037 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28038 +++ linux/fs/aufs/procfs.c 2018-04-15 08:49:13.401150731 +0200
28041 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28043 + * This program, aufs is free software; you can redistribute it and/or modify
28044 + * it under the terms of the GNU General Public License as published by
28045 + * the Free Software Foundation; either version 2 of the License, or
28046 + * (at your option) any later version.
28048 + * This program is distributed in the hope that it will be useful,
28049 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28050 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28051 + * GNU General Public License for more details.
28053 + * You should have received a copy of the GNU General Public License
28054 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28058 + * procfs interfaces
28061 +#include <linux/proc_fs.h>
28064 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28066 + struct au_sbinfo *sbinfo;
28068 + sbinfo = file->private_data;
28070 + au_plink_maint_leave(sbinfo);
28071 + kobject_put(&sbinfo->si_kobj);
28077 +static void au_procfs_plm_write_clean(struct file *file)
28079 + struct au_sbinfo *sbinfo;
28081 + sbinfo = file->private_data;
28083 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28086 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28089 + struct super_block *sb;
28090 + struct au_sbinfo *sbinfo;
28091 + struct hlist_bl_node *pos;
28094 + if (unlikely(file->private_data))
28098 + /* don't use au_sbilist_lock() here */
28099 + hlist_bl_lock(&au_sbilist);
28100 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28101 + if (id == sysaufs_si_id(sbinfo)) {
28102 + kobject_get(&sbinfo->si_kobj);
28103 + sb = sbinfo->si_sb;
28106 + hlist_bl_unlock(&au_sbilist);
28109 + if (unlikely(!sb))
28112 + err = au_plink_maint_enter(sb);
28114 + /* keep kobject_get() */
28115 + file->private_data = sbinfo;
28117 + kobject_put(&sbinfo->si_kobj);
28123 + * Accept a valid "si=xxxx" only.
28124 + * Once it is accepted successfully, accept "clean" too.
28126 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28127 + size_t count, loff_t *ppos)
28130 + unsigned long id;
28131 + /* last newline is allowed */
28132 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28135 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28139 + if (unlikely(count > sizeof(buf)))
28142 + err = copy_from_user(buf, ubuf, count);
28143 + if (unlikely(err)) {
28150 + if (!strcmp("clean", buf)) {
28151 + au_procfs_plm_write_clean(file);
28152 + goto out_success;
28153 + } else if (unlikely(strncmp("si=", buf, 3)))
28156 + err = kstrtoul(buf + 3, 16, &id);
28157 + if (unlikely(err))
28160 + err = au_procfs_plm_write_si(file, id);
28161 + if (unlikely(err))
28165 + err = count; /* success */
28170 +static const struct file_operations au_procfs_plm_fop = {
28171 + .write = au_procfs_plm_write,
28172 + .release = au_procfs_plm_release,
28173 + .owner = THIS_MODULE
28176 +/* ---------------------------------------------------------------------- */
28178 +static struct proc_dir_entry *au_procfs_dir;
28180 +void au_procfs_fin(void)
28182 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28183 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28186 +int __init au_procfs_init(void)
28189 + struct proc_dir_entry *entry;
28192 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28193 + if (unlikely(!au_procfs_dir))
28196 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
28197 + au_procfs_dir, &au_procfs_plm_fop);
28198 + if (unlikely(!entry))
28202 + goto out; /* success */
28206 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28210 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28211 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28212 +++ linux/fs/aufs/rdu.c 2018-04-15 08:49:13.404484168 +0200
28215 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28217 + * This program, aufs is free software; you can redistribute it and/or modify
28218 + * it under the terms of the GNU General Public License as published by
28219 + * the Free Software Foundation; either version 2 of the License, or
28220 + * (at your option) any later version.
28222 + * This program is distributed in the hope that it will be useful,
28223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28225 + * GNU General Public License for more details.
28227 + * You should have received a copy of the GNU General Public License
28228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28232 + * readdir in userspace.
28235 +#include <linux/compat.h>
28236 +#include <linux/fs_stack.h>
28237 +#include <linux/security.h>
28240 +/* bits for struct aufs_rdu.flags */
28241 +#define AuRdu_CALLED 1
28242 +#define AuRdu_CONT (1 << 1)
28243 +#define AuRdu_FULL (1 << 2)
28244 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28245 +#define au_fset_rdu(flags, name) \
28246 + do { (flags) |= AuRdu_##name; } while (0)
28247 +#define au_fclr_rdu(flags, name) \
28248 + do { (flags) &= ~AuRdu_##name; } while (0)
28250 +struct au_rdu_arg {
28251 + struct dir_context ctx;
28252 + struct aufs_rdu *rdu;
28253 + union au_rdu_ent_ul ent;
28254 + unsigned long end;
28256 + struct super_block *sb;
28260 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28261 + loff_t offset, u64 h_ino, unsigned int d_type)
28264 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28265 + struct aufs_rdu *rdu = arg->rdu;
28266 + struct au_rdu_ent ent;
28270 + au_fset_rdu(rdu->cookie.flags, CALLED);
28271 + len = au_rdu_len(nlen);
28272 + if (arg->ent.ul + len < arg->end) {
28274 + ent.bindex = rdu->cookie.bindex;
28275 + ent.type = d_type;
28277 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28278 + ent.type = DT_UNKNOWN;
28280 + /* unnecessary to support mmap_sem since this is a dir */
28282 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28284 + if (copy_to_user(arg->ent.e->name, name, nlen))
28286 + /* the terminating NULL */
28287 + if (__put_user(0, arg->ent.e->name + nlen))
28290 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28291 + arg->ent.ul += len;
28295 + au_fset_rdu(rdu->cookie.flags, FULL);
28297 + rdu->tail = arg->ent;
28301 + /* AuTraceErr(err); */
28305 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28309 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28311 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28312 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28314 + if (unlikely(offset != cookie->h_pos))
28320 + au_fclr_rdu(cookie->flags, CALLED);
28322 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28326 + && au_ftest_rdu(cookie->flags, CALLED)
28327 + && !au_ftest_rdu(cookie->flags, FULL));
28328 + cookie->h_pos = h_file->f_pos;
28335 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28338 + aufs_bindex_t bbot;
28339 + struct au_rdu_arg arg = {
28341 + .actor = au_rdu_fill
28344 + struct dentry *dentry;
28345 + struct inode *inode;
28346 + struct file *h_file;
28347 + struct au_rdu_cookie *cookie = &rdu->cookie;
28349 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28350 + if (unlikely(err)) {
28356 + rdu->tail = rdu->ent;
28359 + arg.ent = rdu->ent;
28360 + arg.end = arg.ent.ul;
28361 + arg.end += rdu->sz;
28364 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28367 + err = security_file_permission(file, MAY_READ);
28369 + if (unlikely(err))
28372 + dentry = file->f_path.dentry;
28373 + inode = d_inode(dentry);
28374 + inode_lock_shared(inode);
28376 + arg.sb = inode->i_sb;
28377 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28378 + if (unlikely(err))
28380 + err = au_alive_dir(dentry);
28381 + if (unlikely(err))
28383 + /* todo: reval? */
28384 + fi_read_lock(file);
28387 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28388 + && cookie->generation != au_figen(file)))
28393 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28395 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28397 + bbot = au_fbtop(file);
28398 + if (cookie->bindex < bbot)
28399 + cookie->bindex = bbot;
28400 + bbot = au_fbbot_dir(file);
28401 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28402 + for (; !err && cookie->bindex <= bbot;
28403 + cookie->bindex++, cookie->h_pos = 0) {
28404 + h_file = au_hf_dir(file, cookie->bindex);
28408 + au_fclr_rdu(cookie->flags, FULL);
28409 + err = au_rdu_do(h_file, &arg);
28411 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28414 + AuDbg("rent %llu\n", rdu->rent);
28416 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28417 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28418 + au_fset_rdu(cookie->flags, CONT);
28419 + cookie->generation = au_figen(file);
28422 + ii_read_lock_child(inode);
28423 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28424 + ii_read_unlock(inode);
28427 + fi_read_unlock(file);
28429 + si_read_unlock(arg.sb);
28431 + inode_unlock_shared(inode);
28437 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28441 + unsigned long long nent;
28442 + union au_rdu_ent_ul *u;
28443 + struct au_rdu_ent ent;
28444 + struct super_block *sb;
28447 + nent = rdu->nent;
28449 + sb = file->f_path.dentry->d_sb;
28450 + si_read_lock(sb, AuLock_FLUSH);
28451 + while (nent-- > 0) {
28452 + /* unnecessary to support mmap_sem since this is a dir */
28453 + err = copy_from_user(&ent, u->e, sizeof(ent));
28455 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28456 + if (unlikely(err)) {
28462 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28464 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28466 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28468 + if (unlikely(err)) {
28473 + err = __put_user(ino, &u->e->ino);
28474 + if (unlikely(err)) {
28479 + u->ul += au_rdu_len(ent.nlen);
28481 + si_read_unlock(sb);
28486 +/* ---------------------------------------------------------------------- */
28488 +static int au_rdu_verify(struct aufs_rdu *rdu)
28490 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28491 + "%llu, b%d, 0x%x, g%u}\n",
28492 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28494 + rdu->rent, rdu->shwh, rdu->full,
28495 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28496 + rdu->cookie.generation);
28498 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28502 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28506 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28509 + struct aufs_rdu rdu;
28510 + void __user *p = (void __user *)arg;
28512 + err = copy_from_user(&rdu, p, sizeof(rdu));
28513 + if (unlikely(err)) {
28518 + err = au_rdu_verify(&rdu);
28519 + if (unlikely(err))
28523 + case AUFS_CTL_RDU:
28524 + err = au_rdu(file, &rdu);
28525 + if (unlikely(err))
28528 + e = copy_to_user(p, &rdu, sizeof(rdu));
28529 + if (unlikely(e)) {
28534 + case AUFS_CTL_RDU_INO:
28535 + err = au_rdu_ino(file, &rdu);
28539 + /* err = -ENOTTY; */
28548 +#ifdef CONFIG_COMPAT
28549 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28552 + struct aufs_rdu rdu;
28553 + void __user *p = compat_ptr(arg);
28555 + /* todo: get_user()? */
28556 + err = copy_from_user(&rdu, p, sizeof(rdu));
28557 + if (unlikely(err)) {
28562 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28563 + err = au_rdu_verify(&rdu);
28564 + if (unlikely(err))
28568 + case AUFS_CTL_RDU:
28569 + err = au_rdu(file, &rdu);
28570 + if (unlikely(err))
28573 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28574 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28575 + e = copy_to_user(p, &rdu, sizeof(rdu));
28576 + if (unlikely(e)) {
28581 + case AUFS_CTL_RDU_INO:
28582 + err = au_rdu_ino(file, &rdu);
28586 + /* err = -ENOTTY; */
28595 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28596 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28597 +++ linux/fs/aufs/rwsem.h 2018-04-15 08:49:13.404484168 +0200
28600 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28602 + * This program, aufs is free software; you can redistribute it and/or modify
28603 + * it under the terms of the GNU General Public License as published by
28604 + * the Free Software Foundation; either version 2 of the License, or
28605 + * (at your option) any later version.
28607 + * This program is distributed in the hope that it will be useful,
28608 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28609 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28610 + * GNU General Public License for more details.
28612 + * You should have received a copy of the GNU General Public License
28613 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28617 + * simple read-write semaphore wrappers
28620 +#ifndef __AUFS_RWSEM_H__
28621 +#define __AUFS_RWSEM_H__
28625 +#include "debug.h"
28628 + struct rw_semaphore rwsem;
28629 +#ifdef CONFIG_AUFS_DEBUG
28630 + /* just for debugging, not almighty counter */
28631 + atomic_t rcnt, wcnt;
28635 +#ifdef CONFIG_LOCKDEP
28636 +#define au_lockdep_set_name(rw) \
28637 + lockdep_set_class_and_name(&(rw)->rwsem, \
28638 + /*original key*/(rw)->rwsem.dep_map.key, \
28641 +#define au_lockdep_set_name(rw) do {} while (0)
28644 +#ifdef CONFIG_AUFS_DEBUG
28645 +#define AuDbgCntInit(rw) do { \
28646 + atomic_set(&(rw)->rcnt, 0); \
28647 + atomic_set(&(rw)->wcnt, 0); \
28648 + smp_mb(); /* atomic set */ \
28651 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
28652 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
28653 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
28654 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
28655 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
28656 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
28657 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
28659 +#define AuDbgCnt(rw, cnt) 0
28660 +#define AuDbgCntInit(rw) do {} while (0)
28661 +#define AuDbgRcntInc(rw) do {} while (0)
28662 +#define AuDbgRcntDec(rw) do {} while (0)
28663 +#define AuDbgWcntInc(rw) do {} while (0)
28664 +#define AuDbgWcntDec(rw) do {} while (0)
28665 +#endif /* CONFIG_AUFS_DEBUG */
28667 +/* to debug easier, do not make them inlined functions */
28668 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
28669 +/* rwsem_is_locked() is unusable */
28670 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
28671 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
28672 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
28673 + && AuDbgCnt(rw, wcnt) <= 0)
28674 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
28675 + || AuDbgCnt(rw, wcnt))
28677 +#define au_rw_init(rw) do { \
28678 + AuDbgCntInit(rw); \
28679 + init_rwsem(&(rw)->rwsem); \
28680 + au_lockdep_set_name(rw); \
28683 +#define au_rw_init_wlock(rw) do { \
28684 + au_rw_init(rw); \
28685 + down_write(&(rw)->rwsem); \
28686 + AuDbgWcntInc(rw); \
28689 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28690 + au_rw_init(rw); \
28691 + down_write_nested(&(rw)->rwsem, lsc); \
28692 + AuDbgWcntInc(rw); \
28695 +static inline void au_rw_read_lock(struct au_rwsem *rw)
28697 + down_read(&rw->rwsem);
28698 + AuDbgRcntInc(rw);
28701 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
28703 + down_read_nested(&rw->rwsem, lsc);
28704 + AuDbgRcntInc(rw);
28707 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
28709 + AuRwMustReadLock(rw);
28710 + AuDbgRcntDec(rw);
28711 + up_read(&rw->rwsem);
28714 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
28716 + AuRwMustWriteLock(rw);
28717 + AuDbgRcntInc(rw);
28718 + AuDbgWcntDec(rw);
28719 + downgrade_write(&rw->rwsem);
28722 +static inline void au_rw_write_lock(struct au_rwsem *rw)
28724 + down_write(&rw->rwsem);
28725 + AuDbgWcntInc(rw);
28728 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
28729 + unsigned int lsc)
28731 + down_write_nested(&rw->rwsem, lsc);
28732 + AuDbgWcntInc(rw);
28735 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
28737 + AuRwMustWriteLock(rw);
28738 + AuDbgWcntDec(rw);
28739 + up_write(&rw->rwsem);
28742 +/* why is not _nested version defined */
28743 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
28747 + ret = down_read_trylock(&rw->rwsem);
28749 + AuDbgRcntInc(rw);
28753 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
28757 + ret = down_write_trylock(&rw->rwsem);
28759 + AuDbgWcntInc(rw);
28763 +#undef AuDbgCntDec
28764 +#undef AuDbgRcntInc
28765 +#undef AuDbgRcntDec
28766 +#undef AuDbgWcntDec
28768 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
28769 +static inline void prefix##_read_lock(param) \
28770 +{ au_rw_read_lock(rwsem); } \
28771 +static inline void prefix##_write_lock(param) \
28772 +{ au_rw_write_lock(rwsem); } \
28773 +static inline int prefix##_read_trylock(param) \
28774 +{ return au_rw_read_trylock(rwsem); } \
28775 +static inline int prefix##_write_trylock(param) \
28776 +{ return au_rw_write_trylock(rwsem); }
28777 +/* why is not _nested version defined */
28778 +/* static inline void prefix##_read_trylock_nested(param, lsc)
28779 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
28780 +static inline void prefix##_write_trylock_nestd(param, lsc)
28781 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
28783 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
28784 +static inline void prefix##_read_unlock(param) \
28785 +{ au_rw_read_unlock(rwsem); } \
28786 +static inline void prefix##_write_unlock(param) \
28787 +{ au_rw_write_unlock(rwsem); } \
28788 +static inline void prefix##_downgrade_lock(param) \
28789 +{ au_rw_dgrade_lock(rwsem); }
28791 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
28792 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
28793 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
28795 +#endif /* __KERNEL__ */
28796 +#endif /* __AUFS_RWSEM_H__ */
28797 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28798 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28799 +++ linux/fs/aufs/sbinfo.c 2018-04-15 08:49:13.404484168 +0200
28802 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28804 + * This program, aufs is free software; you can redistribute it and/or modify
28805 + * it under the terms of the GNU General Public License as published by
28806 + * the Free Software Foundation; either version 2 of the License, or
28807 + * (at your option) any later version.
28809 + * This program is distributed in the hope that it will be useful,
28810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28812 + * GNU General Public License for more details.
28814 + * You should have received a copy of the GNU General Public License
28815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28819 + * superblock private data
28825 + * they are necessary regardless sysfs is disabled.
28827 +void au_si_free(struct kobject *kobj)
28830 + struct au_sbinfo *sbinfo;
28831 + char *locked __maybe_unused; /* debug only */
28833 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28834 + for (i = 0; i < AuPlink_NHASH; i++)
28835 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28836 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28838 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
28839 + percpu_counter_destroy(&sbinfo->si_ninodes);
28840 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
28841 + percpu_counter_destroy(&sbinfo->si_nfiles);
28843 + au_rw_write_lock(&sbinfo->si_rwsem);
28844 + au_br_free(sbinfo);
28845 + au_rw_write_unlock(&sbinfo->si_rwsem);
28847 + kfree(sbinfo->si_branch);
28848 + mutex_destroy(&sbinfo->si_xib_mtx);
28849 + AuRwDestroy(&sbinfo->si_rwsem);
28854 +int au_si_alloc(struct super_block *sb)
28857 + struct au_sbinfo *sbinfo;
28860 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
28861 + if (unlikely(!sbinfo))
28864 + /* will be reallocated separately */
28865 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
28866 + if (unlikely(!sbinfo->si_branch))
28869 + err = sysaufs_si_init(sbinfo);
28870 + if (unlikely(err))
28873 + au_nwt_init(&sbinfo->si_nowait);
28874 + au_rw_init_wlock(&sbinfo->si_rwsem);
28876 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
28877 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
28879 + sbinfo->si_bbot = -1;
28880 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
28882 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
28883 + sbinfo->si_wbr_create = AuWbrCreate_Def;
28884 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
28885 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
28887 + au_fhsm_init(sbinfo);
28889 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
28891 + sbinfo->si_xino_jiffy = jiffies;
28892 + sbinfo->si_xino_expire
28893 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
28894 + mutex_init(&sbinfo->si_xib_mtx);
28895 + sbinfo->si_xino_brid = -1;
28896 + /* leave si_xib_last_pindex and si_xib_next_bit */
28898 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
28900 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
28901 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
28902 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
28903 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
28905 + for (i = 0; i < AuPlink_NHASH; i++)
28906 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
28907 + init_waitqueue_head(&sbinfo->si_plink_wq);
28908 + spin_lock_init(&sbinfo->si_plink_maint_lock);
28910 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
28912 + /* with getattr by default */
28913 + sbinfo->si_iop_array = aufs_iop;
28915 + /* leave other members for sysaufs and si_mnt. */
28916 + sbinfo->si_sb = sb;
28917 + sb->s_fs_info = sbinfo;
28919 + return 0; /* success */
28922 + kfree(sbinfo->si_branch);
28929 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
28932 + struct au_branch **brp;
28934 + AuRwMustWriteLock(&sbinfo->si_rwsem);
28937 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
28938 + if (unlikely(!sz))
28939 + sz = sizeof(*brp);
28940 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
28943 + sbinfo->si_branch = brp;
28950 +/* ---------------------------------------------------------------------- */
28952 +unsigned int au_sigen_inc(struct super_block *sb)
28954 + unsigned int gen;
28955 + struct inode *inode;
28957 + SiMustWriteLock(sb);
28959 + gen = ++au_sbi(sb)->si_generation;
28960 + au_update_digen(sb->s_root);
28961 + inode = d_inode(sb->s_root);
28962 + au_update_iigen(inode, /*half*/0);
28963 + inode->i_version++;
28967 +aufs_bindex_t au_new_br_id(struct super_block *sb)
28969 + aufs_bindex_t br_id;
28971 + struct au_sbinfo *sbinfo;
28973 + SiMustWriteLock(sb);
28975 + sbinfo = au_sbi(sb);
28976 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
28977 + br_id = ++sbinfo->si_last_br_id;
28978 + AuDebugOn(br_id < 0);
28979 + if (br_id && au_br_index(sb, br_id) < 0)
28986 +/* ---------------------------------------------------------------------- */
28988 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
28989 +int si_read_lock(struct super_block *sb, int flags)
28994 + if (au_ftest_lock(flags, FLUSH))
28995 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28997 + si_noflush_read_lock(sb);
28998 + err = au_plink_maint(sb, flags);
28999 + if (unlikely(err))
29000 + si_read_unlock(sb);
29005 +int si_write_lock(struct super_block *sb, int flags)
29009 + if (au_ftest_lock(flags, FLUSH))
29010 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29012 + si_noflush_write_lock(sb);
29013 + err = au_plink_maint(sb, flags);
29014 + if (unlikely(err))
29015 + si_write_unlock(sb);
29020 +/* dentry and super_block lock. call at entry point */
29021 +int aufs_read_lock(struct dentry *dentry, int flags)
29024 + struct super_block *sb;
29026 + sb = dentry->d_sb;
29027 + err = si_read_lock(sb, flags);
29028 + if (unlikely(err))
29031 + if (au_ftest_lock(flags, DW))
29032 + di_write_lock_child(dentry);
29034 + di_read_lock_child(dentry, flags);
29036 + if (au_ftest_lock(flags, GEN)) {
29037 + err = au_digen_test(dentry, au_sigen(sb));
29038 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29039 + AuDebugOn(!err && au_dbrange_test(dentry));
29041 + err = au_dbrange_test(dentry);
29042 + if (unlikely(err))
29043 + aufs_read_unlock(dentry, flags);
29050 +void aufs_read_unlock(struct dentry *dentry, int flags)
29052 + if (au_ftest_lock(flags, DW))
29053 + di_write_unlock(dentry);
29055 + di_read_unlock(dentry, flags);
29056 + si_read_unlock(dentry->d_sb);
29059 +void aufs_write_lock(struct dentry *dentry)
29061 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29062 + di_write_lock_child(dentry);
29065 +void aufs_write_unlock(struct dentry *dentry)
29067 + di_write_unlock(dentry);
29068 + si_write_unlock(dentry->d_sb);
29071 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29074 + unsigned int sigen;
29075 + struct super_block *sb;
29078 + err = si_read_lock(sb, flags);
29079 + if (unlikely(err))
29082 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29084 + if (au_ftest_lock(flags, GEN)) {
29085 + sigen = au_sigen(sb);
29086 + err = au_digen_test(d1, sigen);
29087 + AuDebugOn(!err && au_dbrange_test(d1));
29089 + err = au_digen_test(d2, sigen);
29090 + AuDebugOn(!err && au_dbrange_test(d2));
29092 + if (unlikely(err))
29093 + aufs_read_and_write_unlock2(d1, d2);
29100 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29102 + di_write_unlock2(d1, d2);
29103 + si_read_unlock(d1->d_sb);
29105 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29106 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29107 +++ linux/fs/aufs/super.c 2018-04-15 08:49:13.404484168 +0200
29110 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29112 + * This program, aufs is free software; you can redistribute it and/or modify
29113 + * it under the terms of the GNU General Public License as published by
29114 + * the Free Software Foundation; either version 2 of the License, or
29115 + * (at your option) any later version.
29117 + * This program is distributed in the hope that it will be useful,
29118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29120 + * GNU General Public License for more details.
29122 + * You should have received a copy of the GNU General Public License
29123 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29127 + * mount and super_block operations
29130 +#include <linux/mm.h>
29131 +#include <linux/seq_file.h>
29132 +#include <linux/statfs.h>
29133 +#include <linux/vmalloc.h>
29137 + * super_operations
29139 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29141 + struct au_icntnr *c;
29143 + c = au_cache_alloc_icntnr();
29145 + au_icntnr_init(c);
29146 + c->vfs_inode.i_version = 1; /* sigen(sb); */
29147 + c->iinfo.ii_hinode = NULL;
29148 + return &c->vfs_inode;
29153 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29155 + struct inode *inode = container_of(head, struct inode, i_rcu);
29157 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29160 +static void aufs_destroy_inode(struct inode *inode)
29162 + if (!au_is_bad_inode(inode))
29163 + au_iinfo_fin(inode);
29164 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29167 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29169 + struct inode *inode;
29172 + inode = iget_locked(sb, ino);
29173 + if (unlikely(!inode)) {
29174 + inode = ERR_PTR(-ENOMEM);
29177 + if (!(inode->i_state & I_NEW))
29180 + err = au_xigen_new(inode);
29182 + err = au_iinfo_init(inode);
29184 + inode->i_version++;
29186 + iget_failed(inode);
29187 + inode = ERR_PTR(err);
29191 + /* never return NULL */
29192 + AuDebugOn(!inode);
29193 + AuTraceErrPtr(inode);
29197 +/* lock free root dinfo */
29198 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29201 + aufs_bindex_t bindex, bbot;
29202 + struct path path;
29203 + struct au_hdentry *hdp;
29204 + struct au_branch *br;
29205 + au_br_perm_str_t perm;
29208 + bbot = au_sbbot(sb);
29210 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29211 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29212 + br = au_sbr(sb, bindex);
29213 + path.mnt = au_br_mnt(br);
29214 + path.dentry = hdp->hd_dentry;
29215 + err = au_seq_path(seq, &path);
29217 + au_optstr_br_perm(&perm, br->br_perm);
29218 + seq_printf(seq, "=%s", perm.a);
29219 + if (bindex != bbot)
29220 + seq_putc(seq, ':');
29223 + if (unlikely(err || seq_has_overflowed(seq)))
29229 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29230 + const char *append)
29235 + while (*pat != ':')
29238 + strcpy(p, append);
29239 + AuDebugOn(strlen(fmt) >= len);
29242 +static void au_show_wbr_create(struct seq_file *m, int v,
29243 + struct au_sbinfo *sbinfo)
29247 + struct au_wbr_mfs *mfs;
29249 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29251 + seq_puts(m, ",create=");
29252 + pat = au_optstr_wbr_create(v);
29253 + mfs = &sbinfo->si_wbr_mfs;
29255 + case AuWbrCreate_TDP:
29256 + case AuWbrCreate_RR:
29257 + case AuWbrCreate_MFS:
29258 + case AuWbrCreate_PMFS:
29259 + seq_puts(m, pat);
29261 + case AuWbrCreate_MFSRR:
29262 + case AuWbrCreate_TDMFS:
29263 + case AuWbrCreate_PMFSRR:
29264 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29265 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29267 + case AuWbrCreate_MFSV:
29268 + case AuWbrCreate_PMFSV:
29269 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29270 + seq_printf(m, fmt,
29271 + jiffies_to_msecs(mfs->mfs_expire)
29274 + case AuWbrCreate_MFSRRV:
29275 + case AuWbrCreate_TDMFSV:
29276 + case AuWbrCreate_PMFSRRV:
29277 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29278 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29279 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29286 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29288 +#ifdef CONFIG_SYSFS
29292 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29293 + aufs_bindex_t bindex, brid;
29294 + struct qstr *name;
29296 + struct dentry *d, *h_root;
29298 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29301 + f = au_sbi(sb)->si_xib;
29305 + /* stop printing the default xino path on the first writable branch */
29307 + brid = au_xino_brid(sb);
29309 + bindex = au_br_index(sb, brid);
29310 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
29312 + d = f->f_path.dentry;
29313 + name = &d->d_name;
29314 + /* safe ->d_parent because the file is unlinked */
29315 + if (d->d_parent == h_root
29316 + && name->len == len
29317 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29320 + seq_puts(seq, ",xino=");
29321 + err = au_xino_path(seq, f);
29328 +/* seq_file will re-call me in case of too long string */
29329 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29332 + unsigned int mnt_flags, v;
29333 + struct super_block *sb;
29334 + struct au_sbinfo *sbinfo;
29336 +#define AuBool(name, str) do { \
29337 + v = au_opt_test(mnt_flags, name); \
29338 + if (v != au_opt_test(AuOpt_Def, name)) \
29339 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29342 +#define AuStr(name, str) do { \
29343 + v = mnt_flags & AuOptMask_##name; \
29344 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29345 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29348 +#define AuUInt(name, str, val) do { \
29349 + if (val != AUFS_##name##_DEF) \
29350 + seq_printf(m, "," #str "=%u", val); \
29353 + sb = dentry->d_sb;
29354 + if (sb->s_flags & MS_POSIXACL)
29355 + seq_puts(m, ",acl");
29357 + /* lock free root dinfo */
29358 + si_noflush_read_lock(sb);
29359 + sbinfo = au_sbi(sb);
29360 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29362 + mnt_flags = au_mntflags(sb);
29363 + if (au_opt_test(mnt_flags, XINO)) {
29364 + err = au_show_xino(m, sb);
29365 + if (unlikely(err))
29368 + seq_puts(m, ",noxino");
29370 + AuBool(TRUNC_XINO, trunc_xino);
29371 + AuStr(UDBA, udba);
29372 + AuBool(SHWH, shwh);
29373 + AuBool(PLINK, plink);
29374 + AuBool(DIO, dio);
29375 + AuBool(DIRPERM1, dirperm1);
29377 + v = sbinfo->si_wbr_create;
29378 + if (v != AuWbrCreate_Def)
29379 + au_show_wbr_create(m, v, sbinfo);
29381 + v = sbinfo->si_wbr_copyup;
29382 + if (v != AuWbrCopyup_Def)
29383 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29385 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29386 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29387 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29389 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29391 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29392 + AuUInt(RDCACHE, rdcache, v);
29394 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29395 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29397 + au_fhsm_show(m, sbinfo);
29399 + AuBool(DIRREN, dirren);
29400 + AuBool(SUM, sum);
29401 + /* AuBool(SUM_W, wsum); */
29402 + AuBool(WARN_PERM, warn_perm);
29403 + AuBool(VERBOSE, verbose);
29406 + /* be sure to print "br:" last */
29407 + if (!sysaufs_brs) {
29408 + seq_puts(m, ",br:");
29409 + au_show_brs(m, sb);
29411 + si_read_unlock(sb);
29419 +/* ---------------------------------------------------------------------- */
29421 +/* sum mode which returns the summation for statfs(2) */
29423 +static u64 au_add_till_max(u64 a, u64 b)
29431 + return ULLONG_MAX;
29434 +static u64 au_mul_till_max(u64 a, long mul)
29442 + return ULLONG_MAX;
29445 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29448 + long bsize, factor;
29449 + u64 blocks, bfree, bavail, files, ffree;
29450 + aufs_bindex_t bbot, bindex, i;
29451 + unsigned char shared;
29452 + struct path h_path;
29453 + struct super_block *h_sb;
29456 + bsize = LONG_MAX;
29462 + bbot = au_sbbot(sb);
29463 + for (bindex = 0; bindex <= bbot; bindex++) {
29464 + h_path.mnt = au_sbr_mnt(sb, bindex);
29465 + h_sb = h_path.mnt->mnt_sb;
29467 + for (i = 0; !shared && i < bindex; i++)
29468 + shared = (au_sbr_sb(sb, i) == h_sb);
29472 + /* sb->s_root for NFS is unreliable */
29473 + h_path.dentry = h_path.mnt->mnt_root;
29474 + err = vfs_statfs(&h_path, buf);
29475 + if (unlikely(err))
29478 + if (bsize > buf->f_bsize) {
29480 + * we will reduce bsize, so we have to expand blocks
29481 + * etc. to match them again
29483 + factor = (bsize / buf->f_bsize);
29484 + blocks = au_mul_till_max(blocks, factor);
29485 + bfree = au_mul_till_max(bfree, factor);
29486 + bavail = au_mul_till_max(bavail, factor);
29487 + bsize = buf->f_bsize;
29490 + factor = (buf->f_bsize / bsize);
29491 + blocks = au_add_till_max(blocks,
29492 + au_mul_till_max(buf->f_blocks, factor));
29493 + bfree = au_add_till_max(bfree,
29494 + au_mul_till_max(buf->f_bfree, factor));
29495 + bavail = au_add_till_max(bavail,
29496 + au_mul_till_max(buf->f_bavail, factor));
29497 + files = au_add_till_max(files, buf->f_files);
29498 + ffree = au_add_till_max(ffree, buf->f_ffree);
29501 + buf->f_bsize = bsize;
29502 + buf->f_blocks = blocks;
29503 + buf->f_bfree = bfree;
29504 + buf->f_bavail = bavail;
29505 + buf->f_files = files;
29506 + buf->f_ffree = ffree;
29507 + buf->f_frsize = 0;
29513 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29516 + struct path h_path;
29517 + struct super_block *sb;
29519 + /* lock free root dinfo */
29520 + sb = dentry->d_sb;
29521 + si_noflush_read_lock(sb);
29522 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29523 + /* sb->s_root for NFS is unreliable */
29524 + h_path.mnt = au_sbr_mnt(sb, 0);
29525 + h_path.dentry = h_path.mnt->mnt_root;
29526 + err = vfs_statfs(&h_path, buf);
29528 + err = au_statfs_sum(sb, buf);
29529 + si_read_unlock(sb);
29532 + buf->f_type = AUFS_SUPER_MAGIC;
29533 + buf->f_namelen = AUFS_MAX_NAMELEN;
29534 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29536 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29541 +/* ---------------------------------------------------------------------- */
29543 +static int aufs_sync_fs(struct super_block *sb, int wait)
29546 + aufs_bindex_t bbot, bindex;
29547 + struct au_branch *br;
29548 + struct super_block *h_sb;
29551 + si_noflush_read_lock(sb);
29552 + bbot = au_sbbot(sb);
29553 + for (bindex = 0; bindex <= bbot; bindex++) {
29554 + br = au_sbr(sb, bindex);
29555 + if (!au_br_writable(br->br_perm))
29558 + h_sb = au_sbr_sb(sb, bindex);
29559 + e = vfsub_sync_filesystem(h_sb, wait);
29560 + if (unlikely(e && !err))
29562 + /* go on even if an error happens */
29564 + si_read_unlock(sb);
29569 +/* ---------------------------------------------------------------------- */
29571 +/* final actions when unmounting a file system */
29572 +static void aufs_put_super(struct super_block *sb)
29574 + struct au_sbinfo *sbinfo;
29576 + sbinfo = au_sbi(sb);
29580 + dbgaufs_si_fin(sbinfo);
29581 + kobject_put(&sbinfo->si_kobj);
29584 +/* ---------------------------------------------------------------------- */
29586 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29587 + struct super_block *sb, void *arg)
29590 + unsigned long long n, sz;
29597 + if (*hint > ULLONG_MAX / sizeof(array)) {
29598 + array = ERR_PTR(-EMFILE);
29599 + pr_err("hint %llu\n", *hint);
29603 + sz = sizeof(array) * *hint;
29604 + array = kzalloc(sz, GFP_NOFS);
29605 + if (unlikely(!array))
29606 + array = vzalloc(sz);
29607 + if (unlikely(!array)) {
29608 + array = ERR_PTR(-ENOMEM);
29612 + n = cb(sb, array, *hint, arg);
29613 + AuDebugOn(n > *hint);
29620 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29621 + unsigned long long max __maybe_unused,
29624 + unsigned long long n;
29625 + struct inode **p, *inode;
29626 + struct list_head *head;
29631 + spin_lock(&sb->s_inode_list_lock);
29632 + list_for_each_entry(inode, head, i_sb_list) {
29633 + if (!au_is_bad_inode(inode)
29634 + && au_ii(inode)->ii_btop >= 0) {
29635 + spin_lock(&inode->i_lock);
29636 + if (atomic_read(&inode->i_count)) {
29640 + AuDebugOn(n > max);
29642 + spin_unlock(&inode->i_lock);
29645 + spin_unlock(&sb->s_inode_list_lock);
29650 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29652 + *max = au_ninodes(sb);
29653 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29656 +void au_iarray_free(struct inode **a, unsigned long long max)
29658 + unsigned long long ull;
29660 + for (ull = 0; ull < max; ull++)
29665 +/* ---------------------------------------------------------------------- */
29668 + * refresh dentry and inode at remount time.
29670 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29671 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29672 + struct dentry *parent)
29676 + di_write_lock_child(dentry);
29677 + di_read_lock_parent(parent, AuLock_IR);
29678 + err = au_refresh_dentry(dentry, parent);
29679 + if (!err && dir_flags)
29680 + au_hn_reset(d_inode(dentry), dir_flags);
29681 + di_read_unlock(parent, AuLock_IR);
29682 + di_write_unlock(dentry);
29687 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29688 + struct au_sbinfo *sbinfo,
29689 + const unsigned int dir_flags, unsigned int do_idop)
29692 + struct dentry *parent;
29695 + parent = dget_parent(dentry);
29696 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29697 + if (d_really_is_positive(dentry)) {
29698 + if (!d_is_dir(dentry))
29699 + err = au_do_refresh(dentry, /*dir_flags*/0,
29702 + err = au_do_refresh(dentry, dir_flags, parent);
29703 + if (unlikely(err))
29704 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29707 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29708 + AuDbgDentry(dentry);
29714 + au_refresh_dop(dentry, /*force_reval*/0);
29716 + au_refresh_dop(dentry, /*force_reval*/1);
29722 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29724 + int err, i, j, ndentry, e;
29725 + unsigned int sigen;
29726 + struct au_dcsub_pages dpages;
29727 + struct au_dpage *dpage;
29728 + struct dentry **dentries, *d;
29729 + struct au_sbinfo *sbinfo;
29730 + struct dentry *root = sb->s_root;
29731 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29734 + au_refresh_dop(root, /*force_reval*/0);
29736 + err = au_dpages_init(&dpages, GFP_NOFS);
29737 + if (unlikely(err))
29739 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29740 + if (unlikely(err))
29743 + sigen = au_sigen(sb);
29744 + sbinfo = au_sbi(sb);
29745 + for (i = 0; i < dpages.ndpage; i++) {
29746 + dpage = dpages.dpages + i;
29747 + dentries = dpage->dentries;
29748 + ndentry = dpage->ndentry;
29749 + for (j = 0; j < ndentry; j++) {
29751 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29753 + if (unlikely(e && !err))
29755 + /* go on even err */
29760 + au_dpages_free(&dpages);
29765 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29768 + unsigned int sigen;
29769 + unsigned long long max, ull;
29770 + struct inode *inode, **array;
29772 + array = au_iarray_alloc(sb, &max);
29773 + err = PTR_ERR(array);
29774 + if (IS_ERR(array))
29778 + sigen = au_sigen(sb);
29779 + for (ull = 0; ull < max; ull++) {
29780 + inode = array[ull];
29781 + if (unlikely(!inode))
29785 + ii_write_lock_child(inode);
29786 + if (au_iigen(inode, NULL) != sigen) {
29787 + e = au_refresh_hinode_self(inode);
29788 + if (unlikely(e)) {
29789 + au_refresh_iop(inode, /*force_getattr*/1);
29790 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29793 + /* go on even if err */
29796 + if (!e && do_idop)
29797 + au_refresh_iop(inode, /*force_getattr*/0);
29798 + ii_write_unlock(inode);
29801 + au_iarray_free(array, max);
29807 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29810 + unsigned int udba;
29811 + aufs_bindex_t bindex, bbot;
29812 + struct dentry *root;
29813 + struct inode *inode;
29814 + struct au_branch *br;
29815 + struct au_sbinfo *sbi;
29817 + au_sigen_inc(sb);
29818 + sbi = au_sbi(sb);
29819 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29821 + root = sb->s_root;
29822 + DiMustNoWaiters(root);
29823 + inode = d_inode(root);
29824 + IiMustNoWaiters(inode);
29826 + udba = au_opt_udba(sb);
29827 + bbot = au_sbbot(sb);
29828 + for (bindex = 0; bindex <= bbot; bindex++) {
29829 + br = au_sbr(sb, bindex);
29830 + err = au_hnotify_reset_br(udba, br, br->br_perm);
29831 + if (unlikely(err))
29832 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
29834 + /* go on even if err */
29836 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
29839 + if (au_ftest_si(sbi, NO_DREVAL)) {
29840 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
29841 + sb->s_d_op = &aufs_dop_noreval;
29842 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
29843 + sbi->si_iop_array = aufs_iop_nogetattr;
29845 + AuDebugOn(sb->s_d_op == &aufs_dop);
29846 + sb->s_d_op = &aufs_dop;
29847 + AuDebugOn(sbi->si_iop_array == aufs_iop);
29848 + sbi->si_iop_array = aufs_iop;
29850 + pr_info("reset to %pf and %pf\n",
29851 + sb->s_d_op, sbi->si_iop_array);
29854 + di_write_unlock(root);
29855 + err = au_refresh_d(sb, do_idop);
29856 + e = au_refresh_i(sb, do_idop);
29857 + if (unlikely(e && !err))
29859 + /* aufs_write_lock() calls ..._child() */
29860 + di_write_lock_child(root);
29862 + au_cpup_attr_all(inode, /*force*/1);
29864 + if (unlikely(err))
29865 + AuIOErr("refresh failed, ignored, %d\n", err);
29868 +/* stop extra interpretation of errno in mount(8), and strange error messages */
29869 +static int cvt_err(int err)
29883 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
29886 + unsigned int mntflags;
29887 + struct au_opts opts = {
29890 + struct dentry *root;
29891 + struct inode *inode;
29892 + struct au_sbinfo *sbinfo;
29895 + root = sb->s_root;
29896 + if (!data || !*data) {
29897 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29899 + di_write_lock_child(root);
29900 + err = au_opts_verify(sb, *flags, /*pending*/0);
29901 + aufs_write_unlock(root);
29907 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29908 + if (unlikely(!opts.opt))
29910 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
29911 + opts.flags = AuOpts_REMOUNT;
29912 + opts.sb_flags = *flags;
29914 + /* parse it before aufs lock */
29915 + err = au_opts_parse(sb, data, &opts);
29916 + if (unlikely(err))
29919 + sbinfo = au_sbi(sb);
29920 + inode = d_inode(root);
29921 + inode_lock(inode);
29922 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29923 + if (unlikely(err))
29925 + di_write_lock_child(root);
29927 + /* au_opts_remount() may return an error */
29928 + err = au_opts_remount(sb, &opts);
29929 + au_opts_free(&opts);
29931 + if (au_ftest_opts(opts.flags, REFRESH))
29932 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
29934 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
29935 + mntflags = au_mntflags(sb);
29936 + do_dx = !!au_opt_test(mntflags, DIO);
29937 + au_dy_arefresh(do_dx);
29940 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
29941 + aufs_write_unlock(root);
29944 + inode_unlock(inode);
29946 + free_page((unsigned long)opts.opt);
29948 + err = cvt_err(err);
29953 +static const struct super_operations aufs_sop = {
29954 + .alloc_inode = aufs_alloc_inode,
29955 + .destroy_inode = aufs_destroy_inode,
29956 + /* always deleting, no clearing */
29957 + .drop_inode = generic_delete_inode,
29958 + .show_options = aufs_show_options,
29959 + .statfs = aufs_statfs,
29960 + .put_super = aufs_put_super,
29961 + .sync_fs = aufs_sync_fs,
29962 + .remount_fs = aufs_remount_fs
29965 +/* ---------------------------------------------------------------------- */
29967 +static int alloc_root(struct super_block *sb)
29970 + struct inode *inode;
29971 + struct dentry *root;
29974 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
29975 + err = PTR_ERR(inode);
29976 + if (IS_ERR(inode))
29979 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
29980 + inode->i_fop = &aufs_dir_fop;
29981 + inode->i_mode = S_IFDIR;
29982 + set_nlink(inode, 2);
29983 + unlock_new_inode(inode);
29985 + root = d_make_root(inode);
29986 + if (unlikely(!root))
29988 + err = PTR_ERR(root);
29989 + if (IS_ERR(root))
29992 + err = au_di_init(root);
29994 + sb->s_root = root;
29995 + return 0; /* success */
30003 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30004 + int silent __maybe_unused)
30007 + struct au_opts opts = {
30010 + struct au_sbinfo *sbinfo;
30011 + struct dentry *root;
30012 + struct inode *inode;
30013 + char *arg = raw_data;
30015 + if (unlikely(!arg || !*arg)) {
30017 + pr_err("no arg\n");
30022 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30023 + if (unlikely(!opts.opt))
30025 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30026 + opts.sb_flags = sb->s_flags;
30028 + err = au_si_alloc(sb);
30029 + if (unlikely(err))
30031 + sbinfo = au_sbi(sb);
30033 + /* all timestamps always follow the ones on the branch */
30034 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
30035 + sb->s_op = &aufs_sop;
30036 + sb->s_d_op = &aufs_dop;
30037 + sb->s_magic = AUFS_SUPER_MAGIC;
30038 + sb->s_maxbytes = 0;
30039 + sb->s_stack_depth = 1;
30040 + au_export_init(sb);
30041 + au_xattr_init(sb);
30043 + err = alloc_root(sb);
30044 + if (unlikely(err)) {
30045 + si_write_unlock(sb);
30048 + root = sb->s_root;
30049 + inode = d_inode(root);
30052 + * actually we can parse options regardless aufs lock here.
30053 + * but at remount time, parsing must be done before aufs lock.
30054 + * so we follow the same rule.
30056 + ii_write_lock_parent(inode);
30057 + aufs_write_unlock(root);
30058 + err = au_opts_parse(sb, arg, &opts);
30059 + if (unlikely(err))
30062 + /* lock vfs_inode first, then aufs. */
30063 + inode_lock(inode);
30064 + aufs_write_lock(root);
30065 + err = au_opts_mount(sb, &opts);
30066 + au_opts_free(&opts);
30067 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30068 + sb->s_d_op = &aufs_dop_noreval;
30069 + pr_info("%pf\n", sb->s_d_op);
30070 + au_refresh_dop(root, /*force_reval*/0);
30071 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30072 + au_refresh_iop(inode, /*force_getattr*/0);
30074 + aufs_write_unlock(root);
30075 + inode_unlock(inode);
30077 + goto out_opts; /* success */
30081 + sb->s_root = NULL;
30083 + dbgaufs_si_fin(sbinfo);
30084 + kobject_put(&sbinfo->si_kobj);
30085 + sb->s_fs_info = NULL;
30087 + free_page((unsigned long)opts.opt);
30090 + err = cvt_err(err);
30095 +/* ---------------------------------------------------------------------- */
30097 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30098 + const char *dev_name __maybe_unused,
30101 + struct dentry *root;
30102 + struct super_block *sb;
30104 + /* all timestamps always follow the ones on the branch */
30105 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30106 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30107 + if (IS_ERR(root))
30111 + si_write_lock(sb, !AuLock_FLUSH);
30112 + sysaufs_brs_add(sb, 0);
30113 + si_write_unlock(sb);
30114 + au_sbilist_add(sb);
30120 +static void aufs_kill_sb(struct super_block *sb)
30122 + struct au_sbinfo *sbinfo;
30124 + sbinfo = au_sbi(sb);
30126 + au_sbilist_del(sb);
30127 + aufs_write_lock(sb->s_root);
30129 + if (sbinfo->si_wbr_create_ops->fin)
30130 + sbinfo->si_wbr_create_ops->fin(sb);
30131 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30132 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30133 + au_remount_refresh(sb, /*do_idop*/0);
30135 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30136 + au_plink_put(sb, /*verbose*/1);
30138 + au_dr_opt_flush(sb);
30139 + sbinfo->si_sb = NULL;
30140 + aufs_write_unlock(sb->s_root);
30141 + au_nwt_flush(&sbinfo->si_nowait);
30143 + kill_anon_super(sb);
30146 +struct file_system_type aufs_fs_type = {
30147 + .name = AUFS_FSTYPE,
30148 + /* a race between rename and others */
30149 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30150 + .mount = aufs_mount,
30151 + .kill_sb = aufs_kill_sb,
30152 + /* no need to __module_get() and module_put(). */
30153 + .owner = THIS_MODULE,
30155 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30156 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30157 +++ linux/fs/aufs/super.h 2018-04-15 08:49:13.404484168 +0200
30160 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30162 + * This program, aufs is free software; you can redistribute it and/or modify
30163 + * it under the terms of the GNU General Public License as published by
30164 + * the Free Software Foundation; either version 2 of the License, or
30165 + * (at your option) any later version.
30167 + * This program is distributed in the hope that it will be useful,
30168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30170 + * GNU General Public License for more details.
30172 + * You should have received a copy of the GNU General Public License
30173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30177 + * super_block operations
30180 +#ifndef __AUFS_SUPER_H__
30181 +#define __AUFS_SUPER_H__
30185 +#include <linux/fs.h>
30186 +#include <linux/kobject.h>
30188 +#include "rwsem.h"
30191 +/* policies to select one among multiple writable branches */
30192 +struct au_wbr_copyup_operations {
30193 + int (*copyup)(struct dentry *dentry);
30196 +#define AuWbr_DIR 1 /* target is a dir */
30197 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30199 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30200 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30201 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30203 +struct au_wbr_create_operations {
30204 + int (*create)(struct dentry *dentry, unsigned int flags);
30205 + int (*init)(struct super_block *sb);
30206 + int (*fin)(struct super_block *sb);
30209 +struct au_wbr_mfs {
30210 + struct mutex mfs_lock; /* protect this structure */
30211 + unsigned long mfs_jiffy;
30212 + unsigned long mfs_expire;
30213 + aufs_bindex_t mfs_bindex;
30215 + unsigned long long mfsrr_bytes;
30216 + unsigned long long mfsrr_watermark;
30219 +#define AuPlink_NHASH 100
30220 +static inline int au_plink_hash(ino_t ino)
30222 + return ino % AuPlink_NHASH;
30225 +/* File-based Hierarchical Storage Management */
30227 +#ifdef CONFIG_AUFS_FHSM
30228 + /* allow only one process who can receive the notification */
30229 + spinlock_t fhsm_spin;
30231 + wait_queue_head_t fhsm_wqh;
30232 + atomic_t fhsm_readable;
30234 + /* these are protected by si_rwsem */
30235 + unsigned long fhsm_expire;
30236 + aufs_bindex_t fhsm_bottom;
30241 +struct au_sbinfo {
30242 + /* nowait tasks in the system-wide workqueue */
30243 + struct au_nowait_tasks si_nowait;
30246 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
30247 + * rwsem for au_sbinfo is necessary.
30249 + struct au_rwsem si_rwsem;
30252 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30255 + struct percpu_counter si_ninodes, si_nfiles;
30257 + /* branch management */
30258 + unsigned int si_generation;
30260 + /* see AuSi_ flags */
30261 + unsigned char au_si_status;
30263 + aufs_bindex_t si_bbot;
30265 + /* dirty trick to keep br_id plus */
30266 + unsigned int si_last_br_id :
30267 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30268 + struct au_branch **si_branch;
30270 + /* policy to select a writable branch */
30271 + unsigned char si_wbr_copyup;
30272 + unsigned char si_wbr_create;
30273 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30274 + struct au_wbr_create_operations *si_wbr_create_ops;
30276 + /* round robin */
30277 + atomic_t si_wbr_rr_next;
30279 + /* most free space */
30280 + struct au_wbr_mfs si_wbr_mfs;
30282 + /* File-based Hierarchical Storage Management */
30283 + struct au_fhsm si_fhsm;
30285 + /* mount flags */
30286 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30287 + unsigned int si_mntflags;
30289 + /* external inode number (bitmap and translation table) */
30290 + vfs_readf_t si_xread;
30291 + vfs_writef_t si_xwrite;
30292 + struct file *si_xib;
30293 + struct mutex si_xib_mtx; /* protect xib members */
30294 + unsigned long *si_xib_buf;
30295 + unsigned long si_xib_last_pindex;
30296 + int si_xib_next_bit;
30297 + aufs_bindex_t si_xino_brid;
30298 + unsigned long si_xino_jiffy;
30299 + unsigned long si_xino_expire;
30300 + /* reserved for future use */
30301 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30303 +#ifdef CONFIG_AUFS_EXPORT
30304 + /* i_generation */
30305 + struct file *si_xigen;
30306 + atomic_t si_xigen_next;
30309 + /* dirty trick to suppoer atomic_open */
30310 + struct hlist_bl_head si_aopen;
30312 + /* vdir parameters */
30313 + unsigned long si_rdcache; /* max cache time in jiffies */
30314 + unsigned int si_rdblk; /* deblk size */
30315 + unsigned int si_rdhash; /* hash size */
30318 + * If the number of whiteouts are larger than si_dirwh, leave all of
30319 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30320 + * future fsck.aufs or kernel thread will remove them later.
30321 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30323 + unsigned int si_dirwh;
30325 + /* pseudo_link list */
30326 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30327 + wait_queue_head_t si_plink_wq;
30328 + spinlock_t si_plink_maint_lock;
30329 + pid_t si_plink_maint_pid;
30332 + struct hlist_bl_head si_files;
30334 + /* with/without getattr, brother of sb->s_d_op */
30335 + struct inode_operations *si_iop_array;
30338 + * sysfs and lifetime management.
30339 + * this is not a small structure and it may be a waste of memory in case
30340 + * of sysfs is disabled, particulary when many aufs-es are mounted.
30341 + * but using sysfs is majority.
30343 + struct kobject si_kobj;
30344 +#ifdef CONFIG_DEBUG_FS
30345 + struct dentry *si_dbgaufs;
30346 + struct dentry *si_dbgaufs_plink;
30347 + struct dentry *si_dbgaufs_xib;
30348 +#ifdef CONFIG_AUFS_EXPORT
30349 + struct dentry *si_dbgaufs_xigen;
30353 +#ifdef CONFIG_AUFS_SBILIST
30354 + struct hlist_bl_node si_list;
30357 + /* dirty, necessary for unmounting, sysfs and sysrq */
30358 + struct super_block *si_sb;
30361 +/* sbinfo status flags */
30363 + * set true when refresh_dirs() failed at remount time.
30364 + * then try refreshing dirs at access time again.
30365 + * if it is false, refreshing dirs at access time is unnecesary
30367 +#define AuSi_FAILED_REFRESH_DIR 1
30368 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30369 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30371 +#ifndef CONFIG_AUFS_FHSM
30373 +#define AuSi_FHSM 0
30376 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30377 + unsigned int flag)
30379 + AuRwMustAnyLock(&sbi->si_rwsem);
30380 + return sbi->au_si_status & flag;
30382 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30383 +#define au_fset_si(sbinfo, name) do { \
30384 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30385 + (sbinfo)->au_si_status |= AuSi_##name; \
30387 +#define au_fclr_si(sbinfo, name) do { \
30388 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30389 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30392 +/* ---------------------------------------------------------------------- */
30394 +/* policy to select one among writable branches */
30395 +#define AuWbrCopyup(sbinfo, ...) \
30396 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30397 +#define AuWbrCreate(sbinfo, ...) \
30398 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30400 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30401 +#define AuLock_DW 1 /* write-lock dentry */
30402 +#define AuLock_IR (1 << 1) /* read-lock inode */
30403 +#define AuLock_IW (1 << 2) /* write-lock inode */
30404 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30405 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30406 + /* except RENAME_EXCHANGE */
30407 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30408 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30409 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30410 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30411 +#define au_fset_lock(flags, name) \
30412 + do { (flags) |= AuLock_##name; } while (0)
30413 +#define au_fclr_lock(flags, name) \
30414 + do { (flags) &= ~AuLock_##name; } while (0)
30416 +/* ---------------------------------------------------------------------- */
30419 +extern struct file_system_type aufs_fs_type;
30420 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30421 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30422 + unsigned long long max, void *arg);
30423 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30424 + struct super_block *sb, void *arg);
30425 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30426 +void au_iarray_free(struct inode **a, unsigned long long max);
30429 +void au_si_free(struct kobject *kobj);
30430 +int au_si_alloc(struct super_block *sb);
30431 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30433 +unsigned int au_sigen_inc(struct super_block *sb);
30434 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30436 +int si_read_lock(struct super_block *sb, int flags);
30437 +int si_write_lock(struct super_block *sb, int flags);
30438 +int aufs_read_lock(struct dentry *dentry, int flags);
30439 +void aufs_read_unlock(struct dentry *dentry, int flags);
30440 +void aufs_write_lock(struct dentry *dentry);
30441 +void aufs_write_unlock(struct dentry *dentry);
30442 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30443 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30445 +/* wbr_policy.c */
30446 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30447 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30448 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30449 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30450 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30453 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30455 +#ifdef CONFIG_AUFS_FHSM
30458 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30462 + spin_lock(&fhsm->fhsm_spin);
30463 + pid = fhsm->fhsm_pid;
30464 + spin_unlock(&fhsm->fhsm_spin);
30469 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30470 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30471 +int au_fhsm_fd(struct super_block *sb, int oflags);
30472 +int au_fhsm_br_alloc(struct au_branch *br);
30473 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30474 +void au_fhsm_fin(struct super_block *sb);
30475 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30476 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30477 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30479 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30481 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30482 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30483 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30484 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30485 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30486 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30487 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30488 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30489 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30492 +/* ---------------------------------------------------------------------- */
30494 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30496 + return sb->s_fs_info;
30499 +/* ---------------------------------------------------------------------- */
30501 +#ifdef CONFIG_AUFS_EXPORT
30502 +int au_test_nfsd(void);
30503 +void au_export_init(struct super_block *sb);
30504 +void au_xigen_inc(struct inode *inode);
30505 +int au_xigen_new(struct inode *inode);
30506 +int au_xigen_set(struct super_block *sb, struct file *base);
30507 +void au_xigen_clr(struct super_block *sb);
30509 +static inline int au_busy_or_stale(void)
30511 + if (!au_test_nfsd())
30516 +AuStubInt0(au_test_nfsd, void)
30517 +AuStubVoid(au_export_init, struct super_block *sb)
30518 +AuStubVoid(au_xigen_inc, struct inode *inode)
30519 +AuStubInt0(au_xigen_new, struct inode *inode)
30520 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
30521 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30522 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30523 +#endif /* CONFIG_AUFS_EXPORT */
30525 +/* ---------------------------------------------------------------------- */
30527 +#ifdef CONFIG_AUFS_SBILIST
30529 +extern struct hlist_bl_head au_sbilist;
30531 +static inline void au_sbilist_init(void)
30533 + INIT_HLIST_BL_HEAD(&au_sbilist);
30536 +static inline void au_sbilist_add(struct super_block *sb)
30538 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30541 +static inline void au_sbilist_del(struct super_block *sb)
30543 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30546 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30547 +static inline void au_sbilist_lock(void)
30549 + hlist_bl_lock(&au_sbilist);
30552 +static inline void au_sbilist_unlock(void)
30554 + hlist_bl_unlock(&au_sbilist);
30556 +#define AuGFP_SBILIST GFP_ATOMIC
30558 +AuStubVoid(au_sbilist_lock, void)
30559 +AuStubVoid(au_sbilist_unlock, void)
30560 +#define AuGFP_SBILIST GFP_NOFS
30561 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30563 +AuStubVoid(au_sbilist_init, void)
30564 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30565 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30566 +AuStubVoid(au_sbilist_lock, void)
30567 +AuStubVoid(au_sbilist_unlock, void)
30568 +#define AuGFP_SBILIST GFP_NOFS
30571 +/* ---------------------------------------------------------------------- */
30573 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30576 + * This function is a dynamic '__init' function actually,
30577 + * so the tiny check for si_rwsem is unnecessary.
30579 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30580 +#ifdef CONFIG_DEBUG_FS
30581 + sbinfo->si_dbgaufs = NULL;
30582 + sbinfo->si_dbgaufs_plink = NULL;
30583 + sbinfo->si_dbgaufs_xib = NULL;
30584 +#ifdef CONFIG_AUFS_EXPORT
30585 + sbinfo->si_dbgaufs_xigen = NULL;
30590 +/* ---------------------------------------------------------------------- */
30592 +/* current->atomic_flags */
30593 +/* this value should never corrupt the ones defined in linux/sched.h */
30594 +#define PFA_AUFS 7
30596 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30597 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30598 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30600 +static inline int si_pid_test(struct super_block *sb)
30602 + return !!task_test_aufs(current);
30605 +static inline void si_pid_clr(struct super_block *sb)
30607 + AuDebugOn(!task_test_aufs(current));
30608 + task_clear_aufs(current);
30611 +static inline void si_pid_set(struct super_block *sb)
30613 + AuDebugOn(task_test_aufs(current));
30614 + task_set_aufs(current);
30617 +/* ---------------------------------------------------------------------- */
30619 +/* lock superblock. mainly for entry point functions */
30621 + * __si_read_lock, __si_write_lock,
30622 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
30624 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
30626 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30627 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30628 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30630 +static inline void si_noflush_read_lock(struct super_block *sb)
30632 + __si_read_lock(sb);
30636 +static inline int si_noflush_read_trylock(struct super_block *sb)
30640 + locked = __si_read_trylock(sb);
30646 +static inline void si_noflush_write_lock(struct super_block *sb)
30648 + __si_write_lock(sb);
30652 +static inline int si_noflush_write_trylock(struct super_block *sb)
30656 + locked = __si_write_trylock(sb);
30662 +#if 0 /* reserved */
30663 +static inline int si_read_trylock(struct super_block *sb, int flags)
30665 + if (au_ftest_lock(flags, FLUSH))
30666 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30667 + return si_noflush_read_trylock(sb);
30671 +static inline void si_read_unlock(struct super_block *sb)
30674 + __si_read_unlock(sb);
30677 +#if 0 /* reserved */
30678 +static inline int si_write_trylock(struct super_block *sb, int flags)
30680 + if (au_ftest_lock(flags, FLUSH))
30681 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30682 + return si_noflush_write_trylock(sb);
30686 +static inline void si_write_unlock(struct super_block *sb)
30689 + __si_write_unlock(sb);
30692 +#if 0 /* reserved */
30693 +static inline void si_downgrade_lock(struct super_block *sb)
30695 + __si_downgrade_lock(sb);
30699 +/* ---------------------------------------------------------------------- */
30701 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30703 + SiMustAnyLock(sb);
30704 + return au_sbi(sb)->si_bbot;
30707 +static inline unsigned int au_mntflags(struct super_block *sb)
30709 + SiMustAnyLock(sb);
30710 + return au_sbi(sb)->si_mntflags;
30713 +static inline unsigned int au_sigen(struct super_block *sb)
30715 + SiMustAnyLock(sb);
30716 + return au_sbi(sb)->si_generation;
30719 +static inline unsigned long long au_ninodes(struct super_block *sb)
30721 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
30727 +static inline void au_ninodes_inc(struct super_block *sb)
30729 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
30732 +static inline void au_ninodes_dec(struct super_block *sb)
30734 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
30737 +static inline unsigned long long au_nfiles(struct super_block *sb)
30739 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
30745 +static inline void au_nfiles_inc(struct super_block *sb)
30747 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
30750 +static inline void au_nfiles_dec(struct super_block *sb)
30752 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
30755 +static inline struct au_branch *au_sbr(struct super_block *sb,
30756 + aufs_bindex_t bindex)
30758 + SiMustAnyLock(sb);
30759 + return au_sbi(sb)->si_branch[0 + bindex];
30762 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
30764 + SiMustWriteLock(sb);
30765 + au_sbi(sb)->si_xino_brid = brid;
30768 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
30770 + SiMustAnyLock(sb);
30771 + return au_sbi(sb)->si_xino_brid;
30774 +#endif /* __KERNEL__ */
30775 +#endif /* __AUFS_SUPER_H__ */
30776 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30777 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30778 +++ linux/fs/aufs/sysaufs.c 2018-04-15 08:49:13.404484168 +0200
30781 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30783 + * This program, aufs is free software; you can redistribute it and/or modify
30784 + * it under the terms of the GNU General Public License as published by
30785 + * the Free Software Foundation; either version 2 of the License, or
30786 + * (at your option) any later version.
30788 + * This program is distributed in the hope that it will be useful,
30789 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30790 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30791 + * GNU General Public License for more details.
30793 + * You should have received a copy of the GNU General Public License
30794 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30798 + * sysfs interface and lifetime management
30799 + * they are necessary regardless sysfs is disabled.
30802 +#include <linux/random.h>
30805 +unsigned long sysaufs_si_mask;
30806 +struct kset *sysaufs_kset;
30808 +#define AuSiAttr(_name) { \
30809 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30810 + .show = sysaufs_si_##_name, \
30813 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30814 +struct attribute *sysaufs_si_attrs[] = {
30815 + &sysaufs_si_attr_xi_path.attr,
30819 +static const struct sysfs_ops au_sbi_ops = {
30820 + .show = sysaufs_si_show
30823 +static struct kobj_type au_sbi_ktype = {
30824 + .release = au_si_free,
30825 + .sysfs_ops = &au_sbi_ops,
30826 + .default_attrs = sysaufs_si_attrs
30829 +/* ---------------------------------------------------------------------- */
30831 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30835 + sbinfo->si_kobj.kset = sysaufs_kset;
30836 + /* cf. sysaufs_name() */
30837 + err = kobject_init_and_add
30838 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30839 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30841 + dbgaufs_si_null(sbinfo);
30843 + err = dbgaufs_si_init(sbinfo);
30844 + if (unlikely(err))
30845 + kobject_put(&sbinfo->si_kobj);
30850 +void sysaufs_fin(void)
30853 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30854 + kset_unregister(sysaufs_kset);
30857 +int __init sysaufs_init(void)
30862 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30863 + } while (!sysaufs_si_mask);
30866 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30867 + if (unlikely(!sysaufs_kset))
30869 + err = PTR_ERR(sysaufs_kset);
30870 + if (IS_ERR(sysaufs_kset))
30872 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30873 + if (unlikely(err)) {
30874 + kset_unregister(sysaufs_kset);
30878 + err = dbgaufs_init();
30879 + if (unlikely(err))
30884 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
30885 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
30886 +++ linux/fs/aufs/sysaufs.h 2018-04-15 08:49:13.404484168 +0200
30889 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30891 + * This program, aufs is free software; you can redistribute it and/or modify
30892 + * it under the terms of the GNU General Public License as published by
30893 + * the Free Software Foundation; either version 2 of the License, or
30894 + * (at your option) any later version.
30896 + * This program is distributed in the hope that it will be useful,
30897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30899 + * GNU General Public License for more details.
30901 + * You should have received a copy of the GNU General Public License
30902 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30906 + * sysfs interface and mount lifetime management
30909 +#ifndef __SYSAUFS_H__
30910 +#define __SYSAUFS_H__
30914 +#include <linux/sysfs.h>
30915 +#include "module.h"
30917 +struct super_block;
30920 +struct sysaufs_si_attr {
30921 + struct attribute attr;
30922 + int (*show)(struct seq_file *seq, struct super_block *sb);
30925 +/* ---------------------------------------------------------------------- */
30928 +extern unsigned long sysaufs_si_mask;
30929 +extern struct kset *sysaufs_kset;
30930 +extern struct attribute *sysaufs_si_attrs[];
30931 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
30932 +int __init sysaufs_init(void);
30933 +void sysaufs_fin(void);
30935 +/* ---------------------------------------------------------------------- */
30937 +/* some people doesn't like to show a pointer in kernel */
30938 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
30940 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
30943 +#define SysaufsSiNamePrefix "si_"
30944 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
30945 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
30947 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
30948 + sysaufs_si_id(sbinfo));
30952 +#ifdef CONFIG_SYSFS
30954 +extern struct attribute_group *sysaufs_attr_group;
30956 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
30957 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
30959 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
30960 +#ifdef CONFIG_COMPAT
30961 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
30964 +void sysaufs_br_init(struct au_branch *br);
30965 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
30966 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
30968 +#define sysaufs_brs_init() do {} while (0)
30971 +#define sysaufs_attr_group NULL
30973 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
30974 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
30975 + struct attribute *attr, char *buf)
30976 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
30977 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
30978 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
30980 +static inline void sysaufs_brs_init(void)
30985 +#endif /* CONFIG_SYSFS */
30987 +#endif /* __KERNEL__ */
30988 +#endif /* __SYSAUFS_H__ */
30989 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
30990 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
30991 +++ linux/fs/aufs/sysfs.c 2018-04-15 08:49:13.404484168 +0200
30994 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30996 + * This program, aufs is free software; you can redistribute it and/or modify
30997 + * it under the terms of the GNU General Public License as published by
30998 + * the Free Software Foundation; either version 2 of the License, or
30999 + * (at your option) any later version.
31001 + * This program is distributed in the hope that it will be useful,
31002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31004 + * GNU General Public License for more details.
31006 + * You should have received a copy of the GNU General Public License
31007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31011 + * sysfs interface
31014 +#include <linux/compat.h>
31015 +#include <linux/seq_file.h>
31018 +#ifdef CONFIG_AUFS_FS_MODULE
31019 +/* this entry violates the "one line per file" policy of sysfs */
31020 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31024 + static char *conf =
31025 +/* this file is generated at compiling */
31026 +#include "conf.str"
31029 + err = snprintf(buf, PAGE_SIZE, conf);
31030 + if (unlikely(err >= PAGE_SIZE))
31035 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31038 +static struct attribute *au_attr[] = {
31039 +#ifdef CONFIG_AUFS_FS_MODULE
31040 + &au_config_attr.attr,
31042 + NULL, /* need to NULL terminate the list of attributes */
31045 +static struct attribute_group sysaufs_attr_group_body = {
31049 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31051 +/* ---------------------------------------------------------------------- */
31053 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31057 + SiMustAnyLock(sb);
31060 + if (au_opt_test(au_mntflags(sb), XINO)) {
31061 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31062 + seq_putc(seq, '\n');
31068 + * the lifetime of branch is independent from the entry under sysfs.
31069 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31072 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31073 + aufs_bindex_t bindex, int idx)
31076 + struct path path;
31077 + struct dentry *root;
31078 + struct au_branch *br;
31079 + au_br_perm_str_t perm;
31081 + AuDbg("b%d\n", bindex);
31084 + root = sb->s_root;
31085 + di_read_lock_parent(root, !AuLock_IR);
31086 + br = au_sbr(sb, bindex);
31089 + case AuBrSysfs_BR:
31090 + path.mnt = au_br_mnt(br);
31091 + path.dentry = au_h_dptr(root, bindex);
31092 + err = au_seq_path(seq, &path);
31094 + au_optstr_br_perm(&perm, br->br_perm);
31095 + seq_printf(seq, "=%s\n", perm.a);
31098 + case AuBrSysfs_BRID:
31099 + seq_printf(seq, "%d\n", br->br_id);
31102 + di_read_unlock(root, !AuLock_IR);
31103 + if (unlikely(err || seq_has_overflowed(seq)))
31109 +/* ---------------------------------------------------------------------- */
31111 +static struct seq_file *au_seq(char *p, ssize_t len)
31113 + struct seq_file *seq;
31115 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31117 + /* mutex_init(&seq.lock); */
31120 + return seq; /* success */
31123 + seq = ERR_PTR(-ENOMEM);
31127 +#define SysaufsBr_PREFIX "br"
31128 +#define SysaufsBrid_PREFIX "brid"
31130 +/* todo: file size may exceed PAGE_SIZE */
31131 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31137 + aufs_bindex_t bbot;
31138 + struct au_sbinfo *sbinfo;
31139 + struct super_block *sb;
31140 + struct seq_file *seq;
31142 + struct attribute **cattr;
31144 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31145 + sb = sbinfo->si_sb;
31148 + * prevent a race condition between sysfs and aufs.
31149 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31150 + * prohibits maintaining the sysfs entries.
31151 + * hew we acquire read lock after sysfs_get_active_two().
31152 + * on the other hand, the remount process may maintain the sysfs/aufs
31153 + * entries after acquiring write lock.
31154 + * it can cause a deadlock.
31155 + * simply we gave up processing read here.
31158 + if (unlikely(!si_noflush_read_trylock(sb)))
31161 + seq = au_seq(buf, PAGE_SIZE);
31162 + err = PTR_ERR(seq);
31166 + name = (void *)attr->name;
31167 + cattr = sysaufs_si_attrs;
31169 + if (!strcmp(name, (*cattr)->name)) {
31170 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31177 + if (!strncmp(name, SysaufsBrid_PREFIX,
31178 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31179 + idx = AuBrSysfs_BRID;
31180 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31181 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31182 + sizeof(SysaufsBr_PREFIX) - 1)) {
31183 + idx = AuBrSysfs_BR;
31184 + name += sizeof(SysaufsBr_PREFIX) - 1;
31188 + err = kstrtol(name, 10, &l);
31190 + bbot = au_sbbot(sb);
31192 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31199 + err = seq->count;
31200 + /* sysfs limit */
31201 + if (unlikely(err == PAGE_SIZE))
31206 + si_read_unlock(sb);
31211 +/* ---------------------------------------------------------------------- */
31213 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31217 + aufs_bindex_t bindex, bbot;
31220 + struct seq_file *seq;
31221 + struct au_branch *br;
31223 + si_read_lock(sb, AuLock_FLUSH);
31224 + bbot = au_sbbot(sb);
31230 + buf = (void *)__get_free_page(GFP_NOFS);
31231 + if (unlikely(!buf))
31234 + seq = au_seq(buf, PAGE_SIZE);
31235 + err = PTR_ERR(seq);
31239 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31240 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31241 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31242 + if (unlikely(err))
31245 + br = au_sbr(sb, bindex);
31246 + brid = br->br_id;
31247 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31248 + err = __put_user(brid, &arg->id);
31249 + if (unlikely(err))
31252 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31253 + err = __put_user(br->br_perm, &arg->perm);
31254 + if (unlikely(err))
31257 + err = au_seq_path(seq, &br->br_path);
31258 + if (unlikely(err))
31260 + seq_putc(seq, '\0');
31261 + if (!seq_has_overflowed(seq)) {
31262 + err = copy_to_user(arg->path, seq->buf, seq->count);
31264 + if (unlikely(err))
31271 + if (unlikely(err))
31277 + free_page((unsigned long)buf);
31279 + si_read_unlock(sb);
31283 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31285 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31288 +#ifdef CONFIG_COMPAT
31289 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31291 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31295 +/* ---------------------------------------------------------------------- */
31297 +void sysaufs_br_init(struct au_branch *br)
31300 + struct au_brsysfs *br_sysfs;
31301 + struct attribute *attr;
31303 + br_sysfs = br->br_sysfs;
31304 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31305 + attr = &br_sysfs->attr;
31306 + sysfs_attr_init(attr);
31307 + attr->name = br_sysfs->name;
31308 + attr->mode = S_IRUGO;
31313 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31315 + struct au_branch *br;
31316 + struct kobject *kobj;
31317 + struct au_brsysfs *br_sysfs;
31319 + aufs_bindex_t bbot;
31321 + dbgaufs_brs_del(sb, bindex);
31323 + if (!sysaufs_brs)
31326 + kobj = &au_sbi(sb)->si_kobj;
31327 + bbot = au_sbbot(sb);
31328 + for (; bindex <= bbot; bindex++) {
31329 + br = au_sbr(sb, bindex);
31330 + br_sysfs = br->br_sysfs;
31331 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31332 + sysfs_remove_file(kobj, &br_sysfs->attr);
31338 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31341 + aufs_bindex_t bbot;
31342 + struct kobject *kobj;
31343 + struct au_branch *br;
31344 + struct au_brsysfs *br_sysfs;
31346 + dbgaufs_brs_add(sb, bindex);
31348 + if (!sysaufs_brs)
31351 + kobj = &au_sbi(sb)->si_kobj;
31352 + bbot = au_sbbot(sb);
31353 + for (; bindex <= bbot; bindex++) {
31354 + br = au_sbr(sb, bindex);
31355 + br_sysfs = br->br_sysfs;
31356 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31357 + SysaufsBr_PREFIX "%d", bindex);
31358 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31359 + SysaufsBrid_PREFIX "%d", bindex);
31360 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31361 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31362 + if (unlikely(err))
31363 + pr_warn("failed %s under sysfs(%d)\n",
31364 + br_sysfs->name, err);
31369 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31370 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31371 +++ linux/fs/aufs/sysrq.c 2018-04-15 08:49:13.404484168 +0200
31374 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31376 + * This program, aufs is free software; you can redistribute it and/or modify
31377 + * it under the terms of the GNU General Public License as published by
31378 + * the Free Software Foundation; either version 2 of the License, or
31379 + * (at your option) any later version.
31381 + * This program is distributed in the hope that it will be useful,
31382 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31383 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31384 + * GNU General Public License for more details.
31386 + * You should have received a copy of the GNU General Public License
31387 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31391 + * magic sysrq hanlder
31394 +/* #include <linux/sysrq.h> */
31395 +#include <linux/writeback.h>
31398 +/* ---------------------------------------------------------------------- */
31400 +static void sysrq_sb(struct super_block *sb)
31403 + struct au_sbinfo *sbinfo;
31404 + struct file *file;
31405 + struct hlist_bl_head *files;
31406 + struct hlist_bl_node *pos;
31407 + struct au_finfo *finfo;
31409 + plevel = au_plevel;
31410 + au_plevel = KERN_WARNING;
31412 + /* since we define pr_fmt, call printk directly */
31413 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31415 + sbinfo = au_sbi(sb);
31416 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31417 + pr("superblock\n");
31421 + pr("root dentry\n");
31422 + au_dpri_dentry(sb->s_root);
31423 + pr("root inode\n");
31424 + au_dpri_inode(d_inode(sb->s_root));
31429 + int err, i, j, ndentry;
31430 + struct au_dcsub_pages dpages;
31431 + struct au_dpage *dpage;
31433 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31434 + if (unlikely(err))
31436 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31438 + for (i = 0; i < dpages.ndpage; i++) {
31439 + dpage = dpages.dpages + i;
31440 + ndentry = dpage->ndentry;
31441 + for (j = 0; j < ndentry; j++)
31442 + au_dpri_dentry(dpage->dentries[j]);
31444 + au_dpages_free(&dpages);
31452 + pr("isolated inode\n");
31453 + spin_lock(&sb->s_inode_list_lock);
31454 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31455 + spin_lock(&i->i_lock);
31456 + if (1 || hlist_empty(&i->i_dentry))
31457 + au_dpri_inode(i);
31458 + spin_unlock(&i->i_lock);
31460 + spin_unlock(&sb->s_inode_list_lock);
31464 + files = &au_sbi(sb)->si_files;
31465 + hlist_bl_lock(files);
31466 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31469 + file = finfo->fi_file;
31470 + mode = file_inode(file)->i_mode;
31471 + if (!special_file(mode))
31472 + au_dpri_file(file);
31474 + hlist_bl_unlock(files);
31478 + au_plevel = plevel;
31481 +/* ---------------------------------------------------------------------- */
31483 +/* module parameter */
31484 +static char *aufs_sysrq_key = "a";
31485 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
31486 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31488 +static void au_sysrq(int key __maybe_unused)
31490 + struct au_sbinfo *sbinfo;
31491 + struct hlist_bl_node *pos;
31494 + au_sbilist_lock();
31495 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31496 + sysrq_sb(sbinfo->si_sb);
31497 + au_sbilist_unlock();
31501 +static struct sysrq_key_op au_sysrq_op = {
31502 + .handler = au_sysrq,
31503 + .help_msg = "Aufs",
31504 + .action_msg = "Aufs",
31505 + .enable_mask = SYSRQ_ENABLE_DUMP
31508 +/* ---------------------------------------------------------------------- */
31510 +int __init au_sysrq_init(void)
31516 + key = *aufs_sysrq_key;
31517 + if ('a' <= key && key <= 'z')
31518 + err = register_sysrq_key(key, &au_sysrq_op);
31519 + if (unlikely(err))
31520 + pr_err("err %d, sysrq=%c\n", err, key);
31524 +void au_sysrq_fin(void)
31528 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31529 + if (unlikely(err))
31530 + pr_err("err %d (ignored)\n", err);
31532 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31533 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31534 +++ linux/fs/aufs/vdir.c 2018-04-15 08:49:13.404484168 +0200
31537 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31539 + * This program, aufs is free software; you can redistribute it and/or modify
31540 + * it under the terms of the GNU General Public License as published by
31541 + * the Free Software Foundation; either version 2 of the License, or
31542 + * (at your option) any later version.
31544 + * This program is distributed in the hope that it will be useful,
31545 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31546 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31547 + * GNU General Public License for more details.
31549 + * You should have received a copy of the GNU General Public License
31550 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31554 + * virtual or vertical directory
31559 +static unsigned int calc_size(int nlen)
31561 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31564 +static int set_deblk_end(union au_vdir_deblk_p *p,
31565 + union au_vdir_deblk_p *deblk_end)
31567 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31568 + p->de->de_str.len = 0;
31572 + return -1; /* error */
31575 +/* returns true or false */
31576 +static int is_deblk_end(union au_vdir_deblk_p *p,
31577 + union au_vdir_deblk_p *deblk_end)
31579 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31580 + return !p->de->de_str.len;
31584 +static unsigned char *last_deblk(struct au_vdir *vdir)
31586 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31589 +/* ---------------------------------------------------------------------- */
31591 +/* estimate the appropriate size for name hash table */
31592 +unsigned int au_rdhash_est(loff_t sz)
31600 + if (sz < AUFS_RDHASH_DEF)
31601 + n = AUFS_RDHASH_DEF;
31602 + /* pr_info("n %u\n", n); */
31607 + * the allocated memory has to be freed by
31608 + * au_nhash_wh_free() or au_nhash_de_free().
31610 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31612 + struct hlist_head *head;
31616 + sz = sizeof(*nhash->nh_head) * num_hash;
31617 + head = kmalloc(sz, gfp);
31619 + nhash->nh_num = num_hash;
31620 + nhash->nh_head = head;
31621 + for (u = 0; u < num_hash; u++)
31622 + INIT_HLIST_HEAD(head++);
31623 + return 0; /* success */
31629 +static void nhash_count(struct hlist_head *head)
31633 + struct hlist_node *pos;
31636 + hlist_for_each(pos, head)
31638 + pr_info("%lu\n", n);
31642 +static void au_nhash_wh_do_free(struct hlist_head *head)
31644 + struct au_vdir_wh *pos;
31645 + struct hlist_node *node;
31647 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31651 +static void au_nhash_de_do_free(struct hlist_head *head)
31653 + struct au_vdir_dehstr *pos;
31654 + struct hlist_node *node;
31656 + hlist_for_each_entry_safe(pos, node, head, hash)
31657 + au_cache_free_vdir_dehstr(pos);
31660 +static void au_nhash_do_free(struct au_nhash *nhash,
31661 + void (*free)(struct hlist_head *head))
31664 + struct hlist_head *head;
31666 + n = nhash->nh_num;
31670 + head = nhash->nh_head;
31671 + while (n-- > 0) {
31672 + nhash_count(head);
31675 + kfree(nhash->nh_head);
31678 +void au_nhash_wh_free(struct au_nhash *whlist)
31680 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31683 +static void au_nhash_de_free(struct au_nhash *delist)
31685 + au_nhash_do_free(delist, au_nhash_de_do_free);
31688 +/* ---------------------------------------------------------------------- */
31690 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31694 + unsigned int u, n;
31695 + struct hlist_head *head;
31696 + struct au_vdir_wh *pos;
31699 + n = whlist->nh_num;
31700 + head = whlist->nh_head;
31701 + for (u = 0; u < n; u++, head++)
31702 + hlist_for_each_entry(pos, head, wh_hash)
31703 + if (pos->wh_bindex == btgt && ++num > limit)
31708 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31709 + unsigned char *name,
31710 + unsigned int len)
31713 + /* const unsigned int magic_bit = 12; */
31715 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31722 + /* v = hash_long(v, magic_bit); */
31723 + v %= nhash->nh_num;
31724 + return nhash->nh_head + v;
31727 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31730 + return str->len == nlen && !memcmp(str->name, name, nlen);
31733 +/* returns found or not */
31734 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31736 + struct hlist_head *head;
31737 + struct au_vdir_wh *pos;
31738 + struct au_vdir_destr *str;
31740 + head = au_name_hash(whlist, name, nlen);
31741 + hlist_for_each_entry(pos, head, wh_hash) {
31742 + str = &pos->wh_str;
31743 + AuDbg("%.*s\n", str->len, str->name);
31744 + if (au_nhash_test_name(str, name, nlen))
31750 +/* returns found(true) or not */
31751 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31753 + struct hlist_head *head;
31754 + struct au_vdir_dehstr *pos;
31755 + struct au_vdir_destr *str;
31757 + head = au_name_hash(delist, name, nlen);
31758 + hlist_for_each_entry(pos, head, hash) {
31760 + AuDbg("%.*s\n", str->len, str->name);
31761 + if (au_nhash_test_name(str, name, nlen))
31767 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31768 + unsigned char d_type)
31770 +#ifdef CONFIG_AUFS_SHWH
31771 + wh->wh_ino = ino;
31772 + wh->wh_type = d_type;
31776 +/* ---------------------------------------------------------------------- */
31778 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31779 + unsigned int d_type, aufs_bindex_t bindex,
31780 + unsigned char shwh)
31783 + struct au_vdir_destr *str;
31784 + struct au_vdir_wh *wh;
31786 + AuDbg("%.*s\n", nlen, name);
31787 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31790 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31791 + if (unlikely(!wh))
31795 + wh->wh_bindex = bindex;
31797 + au_shwh_init_wh(wh, ino, d_type);
31798 + str = &wh->wh_str;
31800 + memcpy(str->name, name, nlen);
31801 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31808 +static int append_deblk(struct au_vdir *vdir)
31811 + unsigned long ul;
31812 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31813 + union au_vdir_deblk_p p, deblk_end;
31814 + unsigned char **o;
31817 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31818 + GFP_NOFS, /*may_shrink*/0);
31819 + if (unlikely(!o))
31822 + vdir->vd_deblk = o;
31823 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31825 + ul = vdir->vd_nblk++;
31826 + vdir->vd_deblk[ul] = p.deblk;
31827 + vdir->vd_last.ul = ul;
31828 + vdir->vd_last.p.deblk = p.deblk;
31829 + deblk_end.deblk = p.deblk + deblk_sz;
31830 + err = set_deblk_end(&p, &deblk_end);
31837 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31838 + unsigned int d_type, struct au_nhash *delist)
31842 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31843 + union au_vdir_deblk_p p, *room, deblk_end;
31844 + struct au_vdir_dehstr *dehstr;
31846 + p.deblk = last_deblk(vdir);
31847 + deblk_end.deblk = p.deblk + deblk_sz;
31848 + room = &vdir->vd_last.p;
31849 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31850 + || !is_deblk_end(room, &deblk_end));
31852 + sz = calc_size(nlen);
31853 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31854 + err = append_deblk(vdir);
31855 + if (unlikely(err))
31858 + p.deblk = last_deblk(vdir);
31859 + deblk_end.deblk = p.deblk + deblk_sz;
31861 + AuDebugOn(room->deblk != p.deblk);
31865 + dehstr = au_cache_alloc_vdir_dehstr();
31866 + if (unlikely(!dehstr))
31869 + dehstr->str = &room->de->de_str;
31870 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31871 + room->de->de_ino = ino;
31872 + room->de->de_type = d_type;
31873 + room->de->de_str.len = nlen;
31874 + memcpy(room->de->de_str.name, name, nlen);
31877 + room->deblk += sz;
31878 + if (unlikely(set_deblk_end(room, &deblk_end)))
31879 + err = append_deblk(vdir);
31886 +/* ---------------------------------------------------------------------- */
31888 +void au_vdir_free(struct au_vdir *vdir)
31890 + unsigned char **deblk;
31892 + deblk = vdir->vd_deblk;
31893 + while (vdir->vd_nblk--)
31895 + kfree(vdir->vd_deblk);
31896 + au_cache_free_vdir(vdir);
31899 +static struct au_vdir *alloc_vdir(struct file *file)
31901 + struct au_vdir *vdir;
31902 + struct super_block *sb;
31905 + sb = file->f_path.dentry->d_sb;
31906 + SiMustAnyLock(sb);
31909 + vdir = au_cache_alloc_vdir();
31910 + if (unlikely(!vdir))
31913 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
31914 + if (unlikely(!vdir->vd_deblk))
31917 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
31918 + if (!vdir->vd_deblk_sz) {
31919 + /* estimate the appropriate size for deblk */
31920 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
31921 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
31923 + vdir->vd_nblk = 0;
31924 + vdir->vd_version = 0;
31925 + vdir->vd_jiffy = 0;
31926 + err = append_deblk(vdir);
31928 + return vdir; /* success */
31930 + kfree(vdir->vd_deblk);
31933 + au_cache_free_vdir(vdir);
31935 + vdir = ERR_PTR(err);
31939 +static int reinit_vdir(struct au_vdir *vdir)
31942 + union au_vdir_deblk_p p, deblk_end;
31944 + while (vdir->vd_nblk > 1) {
31945 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
31946 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
31949 + p.deblk = vdir->vd_deblk[0];
31950 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
31951 + err = set_deblk_end(&p, &deblk_end);
31952 + /* keep vd_dblk_sz */
31953 + vdir->vd_last.ul = 0;
31954 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
31955 + vdir->vd_version = 0;
31956 + vdir->vd_jiffy = 0;
31961 +/* ---------------------------------------------------------------------- */
31963 +#define AuFillVdir_CALLED 1
31964 +#define AuFillVdir_WHABLE (1 << 1)
31965 +#define AuFillVdir_SHWH (1 << 2)
31966 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
31967 +#define au_fset_fillvdir(flags, name) \
31968 + do { (flags) |= AuFillVdir_##name; } while (0)
31969 +#define au_fclr_fillvdir(flags, name) \
31970 + do { (flags) &= ~AuFillVdir_##name; } while (0)
31972 +#ifndef CONFIG_AUFS_SHWH
31973 +#undef AuFillVdir_SHWH
31974 +#define AuFillVdir_SHWH 0
31977 +struct fillvdir_arg {
31978 + struct dir_context ctx;
31979 + struct file *file;
31980 + struct au_vdir *vdir;
31981 + struct au_nhash delist;
31982 + struct au_nhash whlist;
31983 + aufs_bindex_t bindex;
31984 + unsigned int flags;
31988 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
31989 + loff_t offset __maybe_unused, u64 h_ino,
31990 + unsigned int d_type)
31992 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
31993 + char *name = (void *)__name;
31994 + struct super_block *sb;
31996 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
31999 + sb = arg->file->f_path.dentry->d_sb;
32000 + au_fset_fillvdir(arg->flags, CALLED);
32002 + if (nlen <= AUFS_WH_PFX_LEN
32003 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32004 + if (test_known(&arg->delist, name, nlen)
32005 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32006 + goto out; /* already exists or whiteouted */
32008 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32010 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32011 + d_type = DT_UNKNOWN;
32012 + arg->err = append_de(arg->vdir, name, nlen, ino,
32013 + d_type, &arg->delist);
32015 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32016 + name += AUFS_WH_PFX_LEN;
32017 + nlen -= AUFS_WH_PFX_LEN;
32018 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32019 + goto out; /* already whiteouted */
32022 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32025 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32026 + d_type = DT_UNKNOWN;
32027 + arg->err = au_nhash_append_wh
32028 + (&arg->whlist, name, nlen, ino, d_type,
32029 + arg->bindex, shwh);
32035 + arg->vdir->vd_jiffy = jiffies;
32037 + AuTraceErr(arg->err);
32041 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32042 + struct au_nhash *whlist, struct au_nhash *delist)
32044 +#ifdef CONFIG_AUFS_SHWH
32046 + unsigned int nh, u;
32047 + struct hlist_head *head;
32048 + struct au_vdir_wh *pos;
32049 + struct hlist_node *n;
32051 + struct au_vdir_destr *destr;
32053 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32056 + o = p = (void *)__get_free_page(GFP_NOFS);
32057 + if (unlikely(!p))
32061 + nh = whlist->nh_num;
32062 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32063 + p += AUFS_WH_PFX_LEN;
32064 + for (u = 0; u < nh; u++) {
32065 + head = whlist->nh_head + u;
32066 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32067 + destr = &pos->wh_str;
32068 + memcpy(p, destr->name, destr->len);
32069 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32070 + pos->wh_ino, pos->wh_type, delist);
32071 + if (unlikely(err))
32076 + free_page((unsigned long)o);
32086 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32089 + unsigned int rdhash;
32091 + aufs_bindex_t bbot, bindex, btop;
32092 + unsigned char shwh;
32093 + struct file *hf, *file;
32094 + struct super_block *sb;
32096 + file = arg->file;
32097 + sb = file->f_path.dentry->d_sb;
32098 + SiMustAnyLock(sb);
32100 + rdhash = au_sbi(sb)->si_rdhash;
32102 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32103 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32104 + if (unlikely(err))
32106 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32107 + if (unlikely(err))
32113 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32115 + au_fset_fillvdir(arg->flags, SHWH);
32117 + btop = au_fbtop(file);
32118 + bbot = au_fbbot_dir(file);
32119 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32120 + hf = au_hf_dir(file, bindex);
32124 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32126 + if (unlikely(offset))
32129 + arg->bindex = bindex;
32130 + au_fclr_fillvdir(arg->flags, WHABLE);
32132 + || (bindex != bbot
32133 + && au_br_whable(au_sbr_perm(sb, bindex))))
32134 + au_fset_fillvdir(arg->flags, WHABLE);
32137 + au_fclr_fillvdir(arg->flags, CALLED);
32139 + err = vfsub_iterate_dir(hf, &arg->ctx);
32142 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32145 + * dir_relax() may be good for concurrency, but aufs should not
32146 + * use it since it will cause a lockdep problem.
32150 + if (!err && shwh)
32151 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32153 + au_nhash_wh_free(&arg->whlist);
32156 + au_nhash_de_free(&arg->delist);
32161 +static int read_vdir(struct file *file, int may_read)
32164 + unsigned long expire;
32165 + unsigned char do_read;
32166 + struct fillvdir_arg arg = {
32168 + .actor = fillvdir
32171 + struct inode *inode;
32172 + struct au_vdir *vdir, *allocated;
32175 + inode = file_inode(file);
32176 + IMustLock(inode);
32177 + IiMustWriteLock(inode);
32178 + SiMustAnyLock(inode->i_sb);
32180 + allocated = NULL;
32182 + expire = au_sbi(inode->i_sb)->si_rdcache;
32183 + vdir = au_ivdir(inode);
32186 + vdir = alloc_vdir(file);
32187 + err = PTR_ERR(vdir);
32188 + if (IS_ERR(vdir))
32191 + allocated = vdir;
32192 + } else if (may_read
32193 + && (inode->i_version != vdir->vd_version
32194 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32196 + err = reinit_vdir(vdir);
32197 + if (unlikely(err))
32202 + return 0; /* success */
32206 + err = au_do_read_vdir(&arg);
32208 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32209 + vdir->vd_version = inode->i_version;
32210 + vdir->vd_last.ul = 0;
32211 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32213 + au_set_ivdir(inode, allocated);
32214 + } else if (allocated)
32215 + au_vdir_free(allocated);
32221 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32224 + unsigned long ul, n;
32225 + const unsigned int deblk_sz = src->vd_deblk_sz;
32227 + AuDebugOn(tgt->vd_nblk != 1);
32230 + if (tgt->vd_nblk < src->vd_nblk) {
32231 + unsigned char **p;
32233 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32234 + GFP_NOFS, /*may_shrink*/0);
32235 + if (unlikely(!p))
32237 + tgt->vd_deblk = p;
32240 + if (tgt->vd_deblk_sz != deblk_sz) {
32241 + unsigned char *p;
32243 + tgt->vd_deblk_sz = deblk_sz;
32244 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32245 + /*may_shrink*/1);
32246 + if (unlikely(!p))
32248 + tgt->vd_deblk[0] = p;
32250 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32251 + tgt->vd_version = src->vd_version;
32252 + tgt->vd_jiffy = src->vd_jiffy;
32254 + n = src->vd_nblk;
32255 + for (ul = 1; ul < n; ul++) {
32256 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32258 + if (unlikely(!tgt->vd_deblk[ul]))
32262 + tgt->vd_nblk = n;
32263 + tgt->vd_last.ul = tgt->vd_last.ul;
32264 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32265 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32266 + - src->vd_deblk[src->vd_last.ul];
32268 + return 0; /* success */
32271 + rerr = reinit_vdir(tgt);
32276 +int au_vdir_init(struct file *file)
32279 + struct inode *inode;
32280 + struct au_vdir *vdir_cache, *allocated;
32282 + /* test file->f_pos here instead of ctx->pos */
32283 + err = read_vdir(file, !file->f_pos);
32284 + if (unlikely(err))
32287 + allocated = NULL;
32288 + vdir_cache = au_fvdir_cache(file);
32289 + if (!vdir_cache) {
32290 + vdir_cache = alloc_vdir(file);
32291 + err = PTR_ERR(vdir_cache);
32292 + if (IS_ERR(vdir_cache))
32294 + allocated = vdir_cache;
32295 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32296 + /* test file->f_pos here instead of ctx->pos */
32297 + err = reinit_vdir(vdir_cache);
32298 + if (unlikely(err))
32301 + return 0; /* success */
32303 + inode = file_inode(file);
32304 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32306 + file->f_version = inode->i_version;
32308 + au_set_fvdir_cache(file, allocated);
32309 + } else if (allocated)
32310 + au_vdir_free(allocated);
32316 +static loff_t calc_offset(struct au_vdir *vdir)
32319 + union au_vdir_deblk_p p;
32321 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32322 + offset = vdir->vd_last.p.deblk - p.deblk;
32323 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32327 +/* returns true or false */
32328 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32331 + unsigned int deblk_sz;
32332 + unsigned long ul, n;
32334 + union au_vdir_deblk_p p, deblk_end;
32335 + struct au_vdir *vdir_cache;
32338 + vdir_cache = au_fvdir_cache(file);
32339 + offset = calc_offset(vdir_cache);
32340 + AuDbg("offset %lld\n", offset);
32341 + if (ctx->pos == offset)
32344 + vdir_cache->vd_last.ul = 0;
32345 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32350 + deblk_sz = vdir_cache->vd_deblk_sz;
32351 + ul = div64_u64(ctx->pos, deblk_sz);
32352 + AuDbg("ul %lu\n", ul);
32353 + if (ul >= vdir_cache->vd_nblk)
32356 + n = vdir_cache->vd_nblk;
32357 + for (; ul < n; ul++) {
32358 + p.deblk = vdir_cache->vd_deblk[ul];
32359 + deblk_end.deblk = p.deblk + deblk_sz;
32361 + offset *= deblk_sz;
32362 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32365 + l = calc_size(p.de->de_str.len);
32369 + if (!is_deblk_end(&p, &deblk_end)) {
32371 + vdir_cache->vd_last.ul = ul;
32372 + vdir_cache->vd_last.p = p;
32380 + AuDbg("valid %d\n", !valid);
32384 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32386 + unsigned int l, deblk_sz;
32387 + union au_vdir_deblk_p deblk_end;
32388 + struct au_vdir *vdir_cache;
32389 + struct au_vdir_de *de;
32391 + vdir_cache = au_fvdir_cache(file);
32392 + if (!seek_vdir(file, ctx))
32395 + deblk_sz = vdir_cache->vd_deblk_sz;
32397 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32398 + deblk_end.deblk += deblk_sz;
32399 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32400 + de = vdir_cache->vd_last.p.de;
32401 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32402 + de->de_str.len, de->de_str.name, ctx->pos,
32403 + (unsigned long)de->de_ino, de->de_type);
32404 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32405 + de->de_str.len, de->de_ino,
32407 + /* todo: ignore the error caused by udba? */
32408 + /* return err; */
32412 + l = calc_size(de->de_str.len);
32413 + vdir_cache->vd_last.p.deblk += l;
32416 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32417 + vdir_cache->vd_last.ul++;
32418 + vdir_cache->vd_last.p.deblk
32419 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32420 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32429 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32430 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32431 +++ linux/fs/aufs/vfsub.c 2018-04-15 08:49:13.404484168 +0200
32434 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32436 + * This program, aufs is free software; you can redistribute it and/or modify
32437 + * it under the terms of the GNU General Public License as published by
32438 + * the Free Software Foundation; either version 2 of the License, or
32439 + * (at your option) any later version.
32441 + * This program is distributed in the hope that it will be useful,
32442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32444 + * GNU General Public License for more details.
32446 + * You should have received a copy of the GNU General Public License
32447 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32451 + * sub-routines for VFS
32454 +#include <linux/mnt_namespace.h>
32455 +#include <linux/namei.h>
32456 +#include <linux/nsproxy.h>
32457 +#include <linux/security.h>
32458 +#include <linux/splice.h>
32461 +#ifdef CONFIG_AUFS_BR_FUSE
32462 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32464 + if (!au_test_fuse(h_sb) || !au_userns)
32467 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32471 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32476 + down_read(&h_sb->s_umount);
32477 + err = __sync_filesystem(h_sb, wait);
32478 + up_read(&h_sb->s_umount);
32484 +/* ---------------------------------------------------------------------- */
32486 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32490 + struct super_block *h_sb;
32492 + /* for remote fs, leave work for its getattr or d_revalidate */
32493 + /* for bad i_attr fs, handle them in aufs_getattr() */
32494 + /* still some fs may acquire i_mutex. we need to skip them */
32498 + h_sb = h_path->dentry->d_sb;
32499 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32501 + err = vfs_getattr(h_path, &st);
32506 +/* ---------------------------------------------------------------------- */
32508 +struct file *vfsub_dentry_open(struct path *path, int flags)
32510 + struct file *file;
32512 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32514 + if (!IS_ERR_OR_NULL(file)
32515 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32516 + i_readcount_inc(d_inode(path->dentry));
32521 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32523 + struct file *file;
32526 + file = filp_open(path,
32527 + oflags /* | __FMODE_NONOTIFY */,
32530 + if (IS_ERR(file))
32532 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32539 + * Ideally this function should call VFS:do_last() in order to keep all its
32540 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32541 + * structure such as nameidata. This is a second (or third) best approach.
32542 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32544 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32545 + struct vfsub_aopen_args *args, struct au_branch *br)
32548 + struct file *file = args->file;
32549 + /* copied from linux/fs/namei.c:atomic_open() */
32550 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32553 + AuDebugOn(!dir->i_op->atomic_open);
32555 + err = au_br_test_oflag(args->open_flag, br);
32556 + if (unlikely(err))
32559 + args->file->f_path.dentry = DENTRY_NOT_SET;
32560 + args->file->f_path.mnt = au_br_mnt(br);
32561 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32562 + args->create_mode, args->opened);
32564 + /* some filesystems don't set FILE_CREATED while succeeded? */
32565 + if (*args->opened & FILE_CREATED)
32566 + fsnotify_create(dir, dentry);
32572 + /* todo: call VFS:may_open() here */
32573 + err = open_check_o_direct(file);
32574 + /* todo: ima_file_check() too? */
32575 + if (!err && (args->open_flag & __FMODE_EXEC))
32576 + err = deny_write_access(file);
32577 + if (unlikely(err))
32578 + /* note that the file is created and still opened */
32583 + fsnotify_open(file);
32589 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32593 + err = kern_path(name, flags, path);
32594 + if (!err && d_is_positive(path->dentry))
32595 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32599 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32600 + struct dentry *parent, int len)
32602 + struct path path = {
32606 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32607 + if (IS_ERR(path.dentry))
32609 + if (d_is_positive(path.dentry))
32610 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32613 + AuTraceErrPtr(path.dentry);
32614 + return path.dentry;
32617 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32620 + struct path path = {
32624 + /* VFS checks it too, but by WARN_ON_ONCE() */
32625 + IMustLock(d_inode(parent));
32627 + path.dentry = lookup_one_len(name, parent, len);
32628 + if (IS_ERR(path.dentry))
32630 + if (d_is_positive(path.dentry))
32631 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32634 + AuTraceErrPtr(path.dentry);
32635 + return path.dentry;
32638 +void vfsub_call_lkup_one(void *args)
32640 + struct vfsub_lkup_one_args *a = args;
32641 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32644 +/* ---------------------------------------------------------------------- */
32646 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32647 + struct dentry *d2, struct au_hinode *hdir2)
32649 + struct dentry *d;
32652 + d = lock_rename(d1, d2);
32654 + au_hn_suspend(hdir1);
32655 + if (hdir1 != hdir2)
32656 + au_hn_suspend(hdir2);
32661 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32662 + struct dentry *d2, struct au_hinode *hdir2)
32664 + au_hn_resume(hdir1);
32665 + if (hdir1 != hdir2)
32666 + au_hn_resume(hdir2);
32668 + unlock_rename(d1, d2);
32672 +/* ---------------------------------------------------------------------- */
32674 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32677 + struct dentry *d;
32681 + d = path->dentry;
32682 + path->dentry = d->d_parent;
32683 + err = security_path_mknod(path, d, mode, 0);
32684 + path->dentry = d;
32685 + if (unlikely(err))
32689 + err = vfs_create(dir, path->dentry, mode, want_excl);
32692 + struct path tmp = *path;
32695 + vfsub_update_h_iattr(&tmp, &did);
32697 + tmp.dentry = path->dentry->d_parent;
32698 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32707 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32710 + struct dentry *d;
32714 + d = path->dentry;
32715 + path->dentry = d->d_parent;
32716 + err = security_path_symlink(path, d, symname);
32717 + path->dentry = d;
32718 + if (unlikely(err))
32722 + err = vfs_symlink(dir, path->dentry, symname);
32725 + struct path tmp = *path;
32728 + vfsub_update_h_iattr(&tmp, &did);
32730 + tmp.dentry = path->dentry->d_parent;
32731 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32740 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32743 + struct dentry *d;
32747 + d = path->dentry;
32748 + path->dentry = d->d_parent;
32749 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32750 + path->dentry = d;
32751 + if (unlikely(err))
32755 + err = vfs_mknod(dir, path->dentry, mode, dev);
32758 + struct path tmp = *path;
32761 + vfsub_update_h_iattr(&tmp, &did);
32763 + tmp.dentry = path->dentry->d_parent;
32764 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32773 +static int au_test_nlink(struct inode *inode)
32775 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32777 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32778 + || inode->i_nlink < link_max)
32783 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32784 + struct inode **delegated_inode)
32787 + struct dentry *d;
32791 + err = au_test_nlink(d_inode(src_dentry));
32792 + if (unlikely(err))
32795 + /* we don't call may_linkat() */
32796 + d = path->dentry;
32797 + path->dentry = d->d_parent;
32798 + err = security_path_link(src_dentry, path, d);
32799 + path->dentry = d;
32800 + if (unlikely(err))
32804 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32807 + struct path tmp = *path;
32810 + /* fuse has different memory inode for the same inumber */
32811 + vfsub_update_h_iattr(&tmp, &did);
32813 + tmp.dentry = path->dentry->d_parent;
32814 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32815 + tmp.dentry = src_dentry;
32816 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32825 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32826 + struct inode *dir, struct path *path,
32827 + struct inode **delegated_inode, unsigned int flags)
32830 + struct path tmp = {
32833 + struct dentry *d;
32836 + IMustLock(src_dir);
32838 + d = path->dentry;
32839 + path->dentry = d->d_parent;
32840 + tmp.dentry = src_dentry->d_parent;
32841 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32842 + path->dentry = d;
32843 + if (unlikely(err))
32847 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32848 + delegated_inode, flags);
32853 + tmp.dentry = d->d_parent;
32854 + vfsub_update_h_iattr(&tmp, &did);
32856 + tmp.dentry = src_dentry;
32857 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32858 + tmp.dentry = src_dentry->d_parent;
32859 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32868 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32871 + struct dentry *d;
32875 + d = path->dentry;
32876 + path->dentry = d->d_parent;
32877 + err = security_path_mkdir(path, d, mode);
32878 + path->dentry = d;
32879 + if (unlikely(err))
32883 + err = vfs_mkdir(dir, path->dentry, mode);
32886 + struct path tmp = *path;
32889 + vfsub_update_h_iattr(&tmp, &did);
32891 + tmp.dentry = path->dentry->d_parent;
32892 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32901 +int vfsub_rmdir(struct inode *dir, struct path *path)
32904 + struct dentry *d;
32908 + d = path->dentry;
32909 + path->dentry = d->d_parent;
32910 + err = security_path_rmdir(path, d);
32911 + path->dentry = d;
32912 + if (unlikely(err))
32916 + err = vfs_rmdir(dir, path->dentry);
32919 + struct path tmp = {
32920 + .dentry = path->dentry->d_parent,
32924 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
32931 +/* ---------------------------------------------------------------------- */
32933 +/* todo: support mmap_sem? */
32934 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
32940 + err = vfs_read(file, ubuf, count, ppos);
32943 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32947 +/* todo: kernel_read()? */
32948 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
32952 + mm_segment_t oldfs;
32959 + oldfs = get_fs();
32960 + set_fs(KERNEL_DS);
32961 + err = vfsub_read_u(file, buf.u, count, ppos);
32966 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
32972 + err = vfs_write(file, ubuf, count, ppos);
32975 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32979 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
32982 + mm_segment_t oldfs;
32985 + const char __user *u;
32989 + oldfs = get_fs();
32990 + set_fs(KERNEL_DS);
32991 + err = vfsub_write_u(file, buf.u, count, ppos);
32996 +int vfsub_flush(struct file *file, fl_owner_t id)
33001 + if (file->f_op->flush) {
33002 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33003 + err = file->f_op->flush(file, id);
33006 + err = file->f_op->flush(file, id);
33010 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33016 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33020 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
33023 + err = iterate_dir(file, ctx);
33026 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33031 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33032 + struct pipe_inode_info *pipe, size_t len,
33033 + unsigned int flags)
33038 + err = do_splice_to(in, ppos, pipe, len, flags);
33040 + file_accessed(in);
33042 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33046 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33047 + loff_t *ppos, size_t len, unsigned int flags)
33052 + err = do_splice_from(pipe, out, ppos, len, flags);
33055 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33059 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33063 + /* file can be NULL */
33065 + err = vfs_fsync(file, datasync);
33069 + AuDebugOn(!file);
33070 + path = &file->f_path;
33072 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33077 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33078 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33079 + struct file *h_file)
33082 + struct inode *h_inode;
33083 + struct super_block *h_sb;
33086 + err = vfsub_truncate(h_path, length);
33090 + h_inode = d_inode(h_path->dentry);
33091 + h_sb = h_inode->i_sb;
33093 + sb_start_write(h_sb);
33095 + err = locks_verify_truncate(h_inode, h_file, length);
33097 + err = security_path_truncate(h_path);
33100 + err = do_truncate(h_path->dentry, length, attr, h_file);
33104 + sb_end_write(h_sb);
33111 +/* ---------------------------------------------------------------------- */
33113 +struct au_vfsub_mkdir_args {
33115 + struct inode *dir;
33116 + struct path *path;
33120 +static void au_call_vfsub_mkdir(void *args)
33122 + struct au_vfsub_mkdir_args *a = args;
33123 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33126 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33128 + int err, do_sio, wkq_err;
33130 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33133 + err = vfsub_mkdir(dir, path, mode);
33136 + struct au_vfsub_mkdir_args args = {
33142 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33143 + if (unlikely(wkq_err))
33150 +struct au_vfsub_rmdir_args {
33152 + struct inode *dir;
33153 + struct path *path;
33156 +static void au_call_vfsub_rmdir(void *args)
33158 + struct au_vfsub_rmdir_args *a = args;
33159 + *a->errp = vfsub_rmdir(a->dir, a->path);
33162 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33164 + int err, do_sio, wkq_err;
33166 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33169 + err = vfsub_rmdir(dir, path);
33172 + struct au_vfsub_rmdir_args args = {
33177 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33178 + if (unlikely(wkq_err))
33185 +/* ---------------------------------------------------------------------- */
33187 +struct notify_change_args {
33189 + struct path *path;
33190 + struct iattr *ia;
33191 + struct inode **delegated_inode;
33194 +static void call_notify_change(void *args)
33196 + struct notify_change_args *a = args;
33197 + struct inode *h_inode;
33199 + h_inode = d_inode(a->path->dentry);
33200 + IMustLock(h_inode);
33202 + *a->errp = -EPERM;
33203 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33205 + *a->errp = notify_change(a->path->dentry, a->ia,
33206 + a->delegated_inode);
33209 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33211 + AuTraceErr(*a->errp);
33214 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33215 + struct inode **delegated_inode)
33218 + struct notify_change_args args = {
33222 + .delegated_inode = delegated_inode
33225 + call_notify_change(&args);
33230 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33231 + struct inode **delegated_inode)
33233 + int err, wkq_err;
33234 + struct notify_change_args args = {
33238 + .delegated_inode = delegated_inode
33241 + wkq_err = au_wkq_wait(call_notify_change, &args);
33242 + if (unlikely(wkq_err))
33248 +/* ---------------------------------------------------------------------- */
33250 +struct unlink_args {
33252 + struct inode *dir;
33253 + struct path *path;
33254 + struct inode **delegated_inode;
33257 +static void call_unlink(void *args)
33259 + struct unlink_args *a = args;
33260 + struct dentry *d = a->path->dentry;
33261 + struct inode *h_inode;
33262 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33263 + && au_dcount(d) == 1);
33265 + IMustLock(a->dir);
33267 + a->path->dentry = d->d_parent;
33268 + *a->errp = security_path_unlink(a->path, d);
33269 + a->path->dentry = d;
33270 + if (unlikely(*a->errp))
33273 + if (!stop_sillyrename)
33276 + if (d_is_positive(d)) {
33277 + h_inode = d_inode(d);
33282 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33285 + struct path tmp = {
33286 + .dentry = d->d_parent,
33287 + .mnt = a->path->mnt
33289 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33292 + if (!stop_sillyrename)
33297 + AuTraceErr(*a->errp);
33301 + * @dir: must be locked.
33302 + * @dentry: target dentry.
33304 +int vfsub_unlink(struct inode *dir, struct path *path,
33305 + struct inode **delegated_inode, int force)
33308 + struct unlink_args args = {
33312 + .delegated_inode = delegated_inode
33316 + call_unlink(&args);
33320 + wkq_err = au_wkq_wait(call_unlink, &args);
33321 + if (unlikely(wkq_err))
33327 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33328 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33329 +++ linux/fs/aufs/vfsub.h 2018-04-15 08:49:13.404484168 +0200
33332 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33334 + * This program, aufs is free software; you can redistribute it and/or modify
33335 + * it under the terms of the GNU General Public License as published by
33336 + * the Free Software Foundation; either version 2 of the License, or
33337 + * (at your option) any later version.
33339 + * This program is distributed in the hope that it will be useful,
33340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33342 + * GNU General Public License for more details.
33344 + * You should have received a copy of the GNU General Public License
33345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33349 + * sub-routines for VFS
33352 +#ifndef __AUFS_VFSUB_H__
33353 +#define __AUFS_VFSUB_H__
33357 +#include <linux/fs.h>
33358 +#include <linux/mount.h>
33359 +#include <linux/posix_acl.h>
33360 +#include <linux/xattr.h>
33361 +#include "debug.h"
33363 +/* copied from linux/fs/internal.h */
33364 +/* todo: BAD approach!! */
33365 +extern void __mnt_drop_write(struct vfsmount *);
33366 +extern int open_check_o_direct(struct file *f);
33368 +/* ---------------------------------------------------------------------- */
33370 +/* lock subclass for lower inode */
33371 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33372 +/* reduce? gave up. */
33374 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33375 + AuLsc_I_PARENT, /* lower inode, parent first */
33376 + AuLsc_I_PARENT2, /* copyup dirs */
33377 + AuLsc_I_PARENT3, /* copyup wh */
33383 +/* to debug easier, do not make them inlined functions */
33384 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33385 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33387 +/* why VFS doesn't define it? */
33389 +void vfsub_inode_lock_shared_nested(struct inode *inode, unsigned int sc)
33391 + down_read_nested(&inode->i_rwsem, sc);
33394 +/* ---------------------------------------------------------------------- */
33396 +static inline void vfsub_drop_nlink(struct inode *inode)
33398 + AuDebugOn(!inode->i_nlink);
33399 + drop_nlink(inode);
33402 +static inline void vfsub_dead_dir(struct inode *inode)
33404 + AuDebugOn(!S_ISDIR(inode->i_mode));
33405 + inode->i_flags |= S_DEAD;
33406 + clear_nlink(inode);
33409 +static inline int vfsub_native_ro(struct inode *inode)
33411 + return (inode->i_sb->s_flags & MS_RDONLY)
33412 + || IS_RDONLY(inode)
33413 + /* || IS_APPEND(inode) */
33414 + || IS_IMMUTABLE(inode);
33417 +#ifdef CONFIG_AUFS_BR_FUSE
33418 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33420 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33423 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33425 +/* ---------------------------------------------------------------------- */
33427 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33428 +struct file *vfsub_dentry_open(struct path *path, int flags);
33429 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33430 +struct vfsub_aopen_args {
33431 + struct file *file;
33432 + unsigned int open_flag;
33433 + umode_t create_mode;
33437 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33438 + struct vfsub_aopen_args *args, struct au_branch *br);
33439 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33441 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33442 + struct dentry *parent, int len);
33443 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33446 +struct vfsub_lkup_one_args {
33447 + struct dentry **errp;
33448 + struct qstr *name;
33449 + struct dentry *parent;
33452 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33453 + struct dentry *parent)
33455 + return vfsub_lookup_one_len(name->name, parent, name->len);
33458 +void vfsub_call_lkup_one(void *args);
33460 +/* ---------------------------------------------------------------------- */
33462 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33467 + err = mnt_want_write(mnt);
33472 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33475 + mnt_drop_write(mnt);
33479 +#if 0 /* reserved */
33480 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33483 + mnt_drop_write_file(file);
33488 +/* ---------------------------------------------------------------------- */
33491 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33492 + struct dentry *d2, struct au_hinode *hdir2);
33493 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33494 + struct dentry *d2, struct au_hinode *hdir2);
33496 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33498 +int vfsub_symlink(struct inode *dir, struct path *path,
33499 + const char *symname);
33500 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33501 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33502 + struct path *path, struct inode **delegated_inode);
33503 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33504 + struct inode *hdir, struct path *path,
33505 + struct inode **delegated_inode, unsigned int flags);
33506 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33507 +int vfsub_rmdir(struct inode *dir, struct path *path);
33509 +/* ---------------------------------------------------------------------- */
33511 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33513 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33515 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33517 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33519 +int vfsub_flush(struct file *file, fl_owner_t id);
33520 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33522 +static inline loff_t vfsub_f_size_read(struct file *file)
33524 + return i_size_read(file_inode(file));
33527 +static inline unsigned int vfsub_file_flags(struct file *file)
33529 + unsigned int flags;
33531 + spin_lock(&file->f_lock);
33532 + flags = file->f_flags;
33533 + spin_unlock(&file->f_lock);
33538 +static inline int vfsub_file_execed(struct file *file)
33540 + /* todo: direct access f_flags */
33541 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33544 +#if 0 /* reserved */
33545 +static inline void vfsub_file_accessed(struct file *h_file)
33547 + file_accessed(h_file);
33548 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33552 +#if 0 /* reserved */
33553 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33554 + struct dentry *h_dentry)
33556 + struct path h_path = {
33557 + .dentry = h_dentry,
33560 + touch_atime(&h_path);
33561 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33565 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
33568 + return update_time(h_inode, ts, flags);
33569 + /* no vfsub_update_h_iattr() since we don't have struct path */
33572 +#ifdef CONFIG_FS_POSIX_ACL
33573 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33577 + err = posix_acl_chmod(h_inode, h_mode);
33578 + if (err == -EOPNOTSUPP)
33583 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33586 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33587 + struct pipe_inode_info *pipe, size_t len,
33588 + unsigned int flags);
33589 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33590 + loff_t *ppos, size_t len, unsigned int flags);
33592 +static inline long vfsub_truncate(struct path *path, loff_t length)
33597 + err = vfs_truncate(path, length);
33602 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33603 + struct file *h_file);
33604 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33607 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33610 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33616 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33622 +/* copy_file_range(2) is a systemcall */
33623 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33624 + struct file *dst, loff_t dst_pos,
33625 + size_t len, unsigned int flags)
33630 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33636 +/* ---------------------------------------------------------------------- */
33638 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33643 + err = vfs_llseek(file, offset, origin);
33648 +/* ---------------------------------------------------------------------- */
33650 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33651 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33652 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33653 + struct inode **delegated_inode);
33654 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33655 + struct inode **delegated_inode);
33656 +int vfsub_unlink(struct inode *dir, struct path *path,
33657 + struct inode **delegated_inode, int force);
33659 +/* ---------------------------------------------------------------------- */
33661 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33662 + const void *value, size_t size, int flags)
33667 + err = vfs_setxattr(dentry, name, value, size, flags);
33673 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33678 + err = vfs_removexattr(dentry, name);
33684 +#endif /* __KERNEL__ */
33685 +#endif /* __AUFS_VFSUB_H__ */
33686 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33687 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33688 +++ linux/fs/aufs/wbr_policy.c 2018-04-15 08:49:13.404484168 +0200
33691 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33693 + * This program, aufs is free software; you can redistribute it and/or modify
33694 + * it under the terms of the GNU General Public License as published by
33695 + * the Free Software Foundation; either version 2 of the License, or
33696 + * (at your option) any later version.
33698 + * This program is distributed in the hope that it will be useful,
33699 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33700 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33701 + * GNU General Public License for more details.
33703 + * You should have received a copy of the GNU General Public License
33704 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33708 + * policies for selecting one among multiple writable branches
33711 +#include <linux/statfs.h>
33714 +/* subset of cpup_attr() */
33715 +static noinline_for_stack
33716 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33720 + struct inode *h_isrc;
33722 + h_isrc = d_inode(h_src);
33723 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33724 + ia.ia_mode = h_isrc->i_mode;
33725 + ia.ia_uid = h_isrc->i_uid;
33726 + ia.ia_gid = h_isrc->i_gid;
33727 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33728 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33729 + /* no delegation since it is just created */
33730 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33732 + /* is this nfs only? */
33733 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33734 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33735 + ia.ia_mode = h_isrc->i_mode;
33736 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33742 +#define AuCpdown_PARENT_OPQ 1
33743 +#define AuCpdown_WHED (1 << 1)
33744 +#define AuCpdown_MADE_DIR (1 << 2)
33745 +#define AuCpdown_DIROPQ (1 << 3)
33746 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33747 +#define au_fset_cpdown(flags, name) \
33748 + do { (flags) |= AuCpdown_##name; } while (0)
33749 +#define au_fclr_cpdown(flags, name) \
33750 + do { (flags) &= ~AuCpdown_##name; } while (0)
33752 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33753 + unsigned int *flags)
33756 + struct dentry *opq_dentry;
33758 + opq_dentry = au_diropq_create(dentry, bdst);
33759 + err = PTR_ERR(opq_dentry);
33760 + if (IS_ERR(opq_dentry))
33762 + dput(opq_dentry);
33763 + au_fset_cpdown(*flags, DIROPQ);
33769 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33770 + struct inode *dir, aufs_bindex_t bdst)
33773 + struct path h_path;
33774 + struct au_branch *br;
33776 + br = au_sbr(dentry->d_sb, bdst);
33777 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33778 + err = PTR_ERR(h_path.dentry);
33779 + if (IS_ERR(h_path.dentry))
33783 + if (d_is_positive(h_path.dentry)) {
33784 + h_path.mnt = au_br_mnt(br);
33785 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33788 + dput(h_path.dentry);
33794 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33795 + struct au_pin *pin,
33796 + struct dentry *h_parent, void *arg)
33799 + aufs_bindex_t bopq, btop;
33800 + struct path h_path;
33801 + struct dentry *parent;
33802 + struct inode *h_dir, *h_inode, *inode, *dir;
33803 + unsigned int *flags = arg;
33805 + btop = au_dbtop(dentry);
33806 + /* dentry is di-locked */
33807 + parent = dget_parent(dentry);
33808 + dir = d_inode(parent);
33809 + h_dir = d_inode(h_parent);
33810 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33811 + IMustLock(h_dir);
33813 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33814 + if (unlikely(err < 0))
33816 + h_path.dentry = au_h_dptr(dentry, bdst);
33817 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33818 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
33819 + S_IRWXU | S_IRUGO | S_IXUGO);
33820 + if (unlikely(err))
33822 + au_fset_cpdown(*flags, MADE_DIR);
33824 + bopq = au_dbdiropq(dentry);
33825 + au_fclr_cpdown(*flags, WHED);
33826 + au_fclr_cpdown(*flags, DIROPQ);
33827 + if (au_dbwh(dentry) == bdst)
33828 + au_fset_cpdown(*flags, WHED);
33829 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33830 + au_fset_cpdown(*flags, PARENT_OPQ);
33831 + h_inode = d_inode(h_path.dentry);
33832 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33833 + if (au_ftest_cpdown(*flags, WHED)) {
33834 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33835 + if (unlikely(err)) {
33836 + inode_unlock(h_inode);
33841 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33842 + inode_unlock(h_inode);
33843 + if (unlikely(err))
33846 + if (au_ftest_cpdown(*flags, WHED)) {
33847 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33848 + if (unlikely(err))
33852 + inode = d_inode(dentry);
33853 + if (au_ibbot(inode) < bdst)
33854 + au_set_ibbot(inode, bdst);
33855 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33856 + au_hi_flags(inode, /*isdir*/1));
33857 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33858 + goto out; /* success */
33862 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33863 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33864 + rerr = au_diropq_remove(dentry, bdst);
33865 + inode_unlock(h_inode);
33866 + if (unlikely(rerr)) {
33867 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33868 + dentry, bdst, rerr);
33874 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33875 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33876 + if (unlikely(rerr)) {
33877 + AuIOErr("failed removing %pd b%d (%d)\n",
33878 + dentry, bdst, rerr);
33883 + au_set_h_dptr(dentry, bdst, NULL);
33884 + if (au_dbbot(dentry) == bdst)
33885 + au_update_dbbot(dentry);
33891 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
33894 + unsigned int flags;
33897 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
33902 +/* ---------------------------------------------------------------------- */
33904 +/* policies for create */
33906 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
33908 + int err, i, j, ndentry;
33909 + aufs_bindex_t bopq;
33910 + struct au_dcsub_pages dpages;
33911 + struct au_dpage *dpage;
33912 + struct dentry **dentries, *parent, *d;
33914 + err = au_dpages_init(&dpages, GFP_NOFS);
33915 + if (unlikely(err))
33917 + parent = dget_parent(dentry);
33918 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
33919 + if (unlikely(err))
33923 + for (i = 0; i < dpages.ndpage; i++) {
33924 + dpage = dpages.dpages + i;
33925 + dentries = dpage->dentries;
33926 + ndentry = dpage->ndentry;
33927 + for (j = 0; j < ndentry; j++) {
33929 + di_read_lock_parent2(d, !AuLock_IR);
33930 + bopq = au_dbdiropq(d);
33931 + di_read_unlock(d, !AuLock_IR);
33932 + if (bopq >= 0 && bopq < err)
33939 + au_dpages_free(&dpages);
33944 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
33946 + for (; bindex >= 0; bindex--)
33947 + if (!au_br_rdonly(au_sbr(sb, bindex)))
33952 +/* top down parent */
33953 +static int au_wbr_create_tdp(struct dentry *dentry,
33954 + unsigned int flags __maybe_unused)
33957 + aufs_bindex_t btop, bindex;
33958 + struct super_block *sb;
33959 + struct dentry *parent, *h_parent;
33961 + sb = dentry->d_sb;
33962 + btop = au_dbtop(dentry);
33964 + if (!au_br_rdonly(au_sbr(sb, btop)))
33968 + parent = dget_parent(dentry);
33969 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
33970 + h_parent = au_h_dptr(parent, bindex);
33971 + if (!h_parent || d_is_negative(h_parent))
33974 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
33981 + /* bottom up here */
33982 + if (unlikely(err < 0)) {
33983 + err = au_wbr_bu(sb, btop - 1);
33985 + err = au_wbr_nonopq(dentry, err);
33989 + AuDbg("b%d\n", err);
33993 +/* ---------------------------------------------------------------------- */
33995 +/* an exception for the policy other than tdp */
33996 +static int au_wbr_create_exp(struct dentry *dentry)
33999 + aufs_bindex_t bwh, bdiropq;
34000 + struct dentry *parent;
34003 + bwh = au_dbwh(dentry);
34004 + parent = dget_parent(dentry);
34005 + bdiropq = au_dbdiropq(parent);
34007 + if (bdiropq >= 0)
34008 + err = min(bdiropq, bwh);
34011 + AuDbg("%d\n", err);
34012 + } else if (bdiropq >= 0) {
34014 + AuDbg("%d\n", err);
34019 + err = au_wbr_nonopq(dentry, err);
34021 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34024 + AuDbg("%d\n", err);
34028 +/* ---------------------------------------------------------------------- */
34031 +static int au_wbr_create_init_rr(struct super_block *sb)
34035 + err = au_wbr_bu(sb, au_sbbot(sb));
34036 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34039 + AuDbg("b%d\n", err);
34043 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34047 + aufs_bindex_t bindex, bbot;
34048 + struct super_block *sb;
34051 + err = au_wbr_create_exp(dentry);
34055 + sb = dentry->d_sb;
34056 + next = &au_sbi(sb)->si_wbr_rr_next;
34057 + bbot = au_sbbot(sb);
34059 + for (bindex = 0; bindex <= bbot; bindex++) {
34060 + if (!au_ftest_wbr(flags, DIR)) {
34061 + err = atomic_dec_return(next) + 1;
34062 + /* modulo for 0 is meaningless */
34063 + if (unlikely(!err))
34064 + err = atomic_dec_return(next) + 1;
34066 + err = atomic_read(next);
34067 + AuDbg("%d\n", err);
34070 + AuDbg("%d\n", err);
34071 + if (!au_br_rdonly(au_sbr(sb, err)))
34077 + err = au_wbr_nonopq(dentry, err);
34080 + AuDbg("%d\n", err);
34084 +/* ---------------------------------------------------------------------- */
34086 +/* most free space */
34087 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34089 + struct super_block *sb;
34090 + struct au_branch *br;
34091 + struct au_wbr_mfs *mfs;
34092 + struct dentry *h_parent;
34093 + aufs_bindex_t bindex, bbot;
34095 + unsigned long long b, bavail;
34096 + struct path h_path;
34097 + /* reduce the stack usage */
34098 + struct kstatfs *st;
34100 + st = kmalloc(sizeof(*st), GFP_NOFS);
34101 + if (unlikely(!st)) {
34102 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34107 + sb = dentry->d_sb;
34108 + mfs = &au_sbi(sb)->si_wbr_mfs;
34109 + MtxMustLock(&mfs->mfs_lock);
34110 + mfs->mfs_bindex = -EROFS;
34111 + mfs->mfsrr_bytes = 0;
34114 + bbot = au_sbbot(sb);
34116 + bindex = au_dbtop(parent);
34117 + bbot = au_dbtaildir(parent);
34120 + for (; bindex <= bbot; bindex++) {
34122 + h_parent = au_h_dptr(parent, bindex);
34123 + if (!h_parent || d_is_negative(h_parent))
34126 + br = au_sbr(sb, bindex);
34127 + if (au_br_rdonly(br))
34130 + /* sb->s_root for NFS is unreliable */
34131 + h_path.mnt = au_br_mnt(br);
34132 + h_path.dentry = h_path.mnt->mnt_root;
34133 + err = vfs_statfs(&h_path, st);
34134 + if (unlikely(err)) {
34135 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34139 + /* when the available size is equal, select the lower one */
34140 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34141 + || sizeof(b) < sizeof(st->f_bsize));
34142 + b = st->f_bavail * st->f_bsize;
34143 + br->br_wbr->wbr_bytes = b;
34144 + if (b >= bavail) {
34146 + mfs->mfs_bindex = bindex;
34147 + mfs->mfs_jiffy = jiffies;
34151 + mfs->mfsrr_bytes = bavail;
34152 + AuDbg("b%d\n", mfs->mfs_bindex);
34156 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34159 + struct dentry *parent;
34160 + struct super_block *sb;
34161 + struct au_wbr_mfs *mfs;
34163 + err = au_wbr_create_exp(dentry);
34167 + sb = dentry->d_sb;
34169 + if (au_ftest_wbr(flags, PARENT))
34170 + parent = dget_parent(dentry);
34171 + mfs = &au_sbi(sb)->si_wbr_mfs;
34172 + mutex_lock(&mfs->mfs_lock);
34173 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34174 + || mfs->mfs_bindex < 0
34175 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34176 + au_mfs(dentry, parent);
34177 + mutex_unlock(&mfs->mfs_lock);
34178 + err = mfs->mfs_bindex;
34182 + err = au_wbr_nonopq(dentry, err);
34185 + AuDbg("b%d\n", err);
34189 +static int au_wbr_create_init_mfs(struct super_block *sb)
34191 + struct au_wbr_mfs *mfs;
34193 + mfs = &au_sbi(sb)->si_wbr_mfs;
34194 + mutex_init(&mfs->mfs_lock);
34195 + mfs->mfs_jiffy = 0;
34196 + mfs->mfs_bindex = -EROFS;
34201 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34203 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34207 +/* ---------------------------------------------------------------------- */
34209 +/* top down regardless parent, and then mfs */
34210 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34211 + unsigned int flags __maybe_unused)
34214 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34215 + unsigned long long watermark;
34216 + struct super_block *sb;
34217 + struct au_wbr_mfs *mfs;
34218 + struct au_branch *br;
34219 + struct dentry *parent;
34221 + sb = dentry->d_sb;
34222 + mfs = &au_sbi(sb)->si_wbr_mfs;
34223 + mutex_lock(&mfs->mfs_lock);
34224 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34225 + || mfs->mfs_bindex < 0)
34226 + au_mfs(dentry, /*parent*/NULL);
34227 + watermark = mfs->mfsrr_watermark;
34228 + bmfs = mfs->mfs_bindex;
34229 + mutex_unlock(&mfs->mfs_lock);
34231 + /* another style of au_wbr_create_exp() */
34232 + bwh = au_dbwh(dentry);
34233 + parent = dget_parent(dentry);
34234 + btail = au_dbtaildir(parent);
34235 + if (bwh >= 0 && bwh < btail)
34238 + err = au_wbr_nonopq(dentry, btail);
34239 + if (unlikely(err < 0))
34243 + for (bindex = 0; bindex <= btail; bindex++) {
34244 + br = au_sbr(sb, bindex);
34245 + if (au_br_rdonly(br))
34247 + if (br->br_wbr->wbr_bytes > watermark) {
34258 + AuDbg("b%d\n", err);
34262 +/* ---------------------------------------------------------------------- */
34264 +/* most free space and then round robin */
34265 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34268 + struct au_wbr_mfs *mfs;
34270 + err = au_wbr_create_mfs(dentry, flags);
34272 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34273 + mutex_lock(&mfs->mfs_lock);
34274 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34275 + err = au_wbr_create_rr(dentry, flags);
34276 + mutex_unlock(&mfs->mfs_lock);
34279 + AuDbg("b%d\n", err);
34283 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34287 + au_wbr_create_init_mfs(sb); /* ignore */
34288 + err = au_wbr_create_init_rr(sb);
34293 +/* ---------------------------------------------------------------------- */
34295 +/* top down parent and most free space */
34296 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34299 + unsigned long long b;
34300 + aufs_bindex_t bindex, btop, bbot;
34301 + struct super_block *sb;
34302 + struct dentry *parent, *h_parent;
34303 + struct au_branch *br;
34305 + err = au_wbr_create_tdp(dentry, flags);
34306 + if (unlikely(err < 0))
34308 + parent = dget_parent(dentry);
34309 + btop = au_dbtop(parent);
34310 + bbot = au_dbtaildir(parent);
34311 + if (btop == bbot)
34312 + goto out_parent; /* success */
34314 + e2 = au_wbr_create_mfs(dentry, flags);
34316 + goto out_parent; /* success */
34318 + /* when the available size is equal, select upper one */
34319 + sb = dentry->d_sb;
34320 + br = au_sbr(sb, err);
34321 + b = br->br_wbr->wbr_bytes;
34322 + AuDbg("b%d, %llu\n", err, b);
34324 + for (bindex = btop; bindex <= bbot; bindex++) {
34325 + h_parent = au_h_dptr(parent, bindex);
34326 + if (!h_parent || d_is_negative(h_parent))
34329 + br = au_sbr(sb, bindex);
34330 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34331 + b = br->br_wbr->wbr_bytes;
34333 + AuDbg("b%d, %llu\n", err, b);
34338 + err = au_wbr_nonopq(dentry, err);
34343 + AuDbg("b%d\n", err);
34347 +/* ---------------------------------------------------------------------- */
34350 + * - top down parent
34351 + * - most free space with parent
34352 + * - most free space round-robin regardless parent
34354 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34357 + unsigned long long watermark;
34358 + struct super_block *sb;
34359 + struct au_branch *br;
34360 + struct au_wbr_mfs *mfs;
34362 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34363 + if (unlikely(err < 0))
34366 + sb = dentry->d_sb;
34367 + br = au_sbr(sb, err);
34368 + mfs = &au_sbi(sb)->si_wbr_mfs;
34369 + mutex_lock(&mfs->mfs_lock);
34370 + watermark = mfs->mfsrr_watermark;
34371 + mutex_unlock(&mfs->mfs_lock);
34372 + if (br->br_wbr->wbr_bytes < watermark)
34373 + /* regardless the parent dir */
34374 + err = au_wbr_create_mfsrr(dentry, flags);
34377 + AuDbg("b%d\n", err);
34381 +/* ---------------------------------------------------------------------- */
34383 +/* policies for copyup */
34385 +/* top down parent */
34386 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34388 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34391 +/* bottom up parent */
34392 +static int au_wbr_copyup_bup(struct dentry *dentry)
34395 + aufs_bindex_t bindex, btop;
34396 + struct dentry *parent, *h_parent;
34397 + struct super_block *sb;
34400 + sb = dentry->d_sb;
34401 + parent = dget_parent(dentry);
34402 + btop = au_dbtop(parent);
34403 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34404 + h_parent = au_h_dptr(parent, bindex);
34405 + if (!h_parent || d_is_negative(h_parent))
34408 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34415 + /* bottom up here */
34416 + if (unlikely(err < 0))
34417 + err = au_wbr_bu(sb, btop - 1);
34419 + AuDbg("b%d\n", err);
34424 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34428 + err = au_wbr_bu(dentry->d_sb, btop);
34429 + AuDbg("b%d\n", err);
34431 + err = au_wbr_nonopq(dentry, err);
34433 + AuDbg("b%d\n", err);
34437 +static int au_wbr_copyup_bu(struct dentry *dentry)
34440 + aufs_bindex_t btop;
34442 + btop = au_dbtop(dentry);
34443 + err = au_wbr_do_copyup_bu(dentry, btop);
34447 +/* ---------------------------------------------------------------------- */
34449 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34450 + [AuWbrCopyup_TDP] = {
34451 + .copyup = au_wbr_copyup_tdp
34453 + [AuWbrCopyup_BUP] = {
34454 + .copyup = au_wbr_copyup_bup
34456 + [AuWbrCopyup_BU] = {
34457 + .copyup = au_wbr_copyup_bu
34461 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34462 + [AuWbrCreate_TDP] = {
34463 + .create = au_wbr_create_tdp
34465 + [AuWbrCreate_RR] = {
34466 + .create = au_wbr_create_rr,
34467 + .init = au_wbr_create_init_rr
34469 + [AuWbrCreate_MFS] = {
34470 + .create = au_wbr_create_mfs,
34471 + .init = au_wbr_create_init_mfs,
34472 + .fin = au_wbr_create_fin_mfs
34474 + [AuWbrCreate_MFSV] = {
34475 + .create = au_wbr_create_mfs,
34476 + .init = au_wbr_create_init_mfs,
34477 + .fin = au_wbr_create_fin_mfs
34479 + [AuWbrCreate_MFSRR] = {
34480 + .create = au_wbr_create_mfsrr,
34481 + .init = au_wbr_create_init_mfsrr,
34482 + .fin = au_wbr_create_fin_mfs
34484 + [AuWbrCreate_MFSRRV] = {
34485 + .create = au_wbr_create_mfsrr,
34486 + .init = au_wbr_create_init_mfsrr,
34487 + .fin = au_wbr_create_fin_mfs
34489 + [AuWbrCreate_TDMFS] = {
34490 + .create = au_wbr_create_tdmfs,
34491 + .init = au_wbr_create_init_mfs,
34492 + .fin = au_wbr_create_fin_mfs
34494 + [AuWbrCreate_TDMFSV] = {
34495 + .create = au_wbr_create_tdmfs,
34496 + .init = au_wbr_create_init_mfs,
34497 + .fin = au_wbr_create_fin_mfs
34499 + [AuWbrCreate_PMFS] = {
34500 + .create = au_wbr_create_pmfs,
34501 + .init = au_wbr_create_init_mfs,
34502 + .fin = au_wbr_create_fin_mfs
34504 + [AuWbrCreate_PMFSV] = {
34505 + .create = au_wbr_create_pmfs,
34506 + .init = au_wbr_create_init_mfs,
34507 + .fin = au_wbr_create_fin_mfs
34509 + [AuWbrCreate_PMFSRR] = {
34510 + .create = au_wbr_create_pmfsrr,
34511 + .init = au_wbr_create_init_mfsrr,
34512 + .fin = au_wbr_create_fin_mfs
34514 + [AuWbrCreate_PMFSRRV] = {
34515 + .create = au_wbr_create_pmfsrr,
34516 + .init = au_wbr_create_init_mfsrr,
34517 + .fin = au_wbr_create_fin_mfs
34520 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34521 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34522 +++ linux/fs/aufs/whout.c 2018-04-15 08:49:13.404484168 +0200
34525 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34527 + * This program, aufs is free software; you can redistribute it and/or modify
34528 + * it under the terms of the GNU General Public License as published by
34529 + * the Free Software Foundation; either version 2 of the License, or
34530 + * (at your option) any later version.
34532 + * This program is distributed in the hope that it will be useful,
34533 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34534 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34535 + * GNU General Public License for more details.
34537 + * You should have received a copy of the GNU General Public License
34538 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34542 + * whiteout for logical deletion and opaque directory
34547 +#define WH_MASK S_IRUGO
34550 + * If a directory contains this file, then it is opaque. We start with the
34551 + * .wh. flag so that it is blocked by lookup.
34553 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34554 + sizeof(AUFS_WH_DIROPQ) - 1);
34557 + * generate whiteout name, which is NOT terminated by NULL.
34558 + * @name: original d_name.name
34559 + * @len: original d_name.len
34560 + * @wh: whiteout qstr
34561 + * returns zero when succeeds, otherwise error.
34562 + * succeeded value as wh->name should be freed by kfree().
34564 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34568 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34569 + return -ENAMETOOLONG;
34571 + wh->len = name->len + AUFS_WH_PFX_LEN;
34572 + p = kmalloc(wh->len, GFP_NOFS);
34575 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34576 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34583 +/* ---------------------------------------------------------------------- */
34586 + * test if the @wh_name exists under @h_parent.
34587 + * @try_sio specifies the necessary of super-io.
34589 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34592 + struct dentry *wh_dentry;
34595 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34597 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34598 + err = PTR_ERR(wh_dentry);
34599 + if (IS_ERR(wh_dentry)) {
34600 + if (err == -ENAMETOOLONG)
34606 + if (d_is_negative(wh_dentry))
34607 + goto out_wh; /* success */
34610 + if (d_is_reg(wh_dentry))
34611 + goto out_wh; /* success */
34614 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34615 + wh_dentry, d_inode(wh_dentry)->i_mode);
34624 + * test if the @h_dentry sets opaque or not.
34626 +int au_diropq_test(struct dentry *h_dentry)
34629 + struct inode *h_dir;
34631 + h_dir = d_inode(h_dentry);
34632 + err = au_wh_test(h_dentry, &diropq_name,
34633 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34638 + * returns a negative dentry whose name is unique and temporary.
34640 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34641 + struct qstr *prefix)
34643 + struct dentry *dentry;
34645 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34647 + /* strict atomic_t is unnecessary here */
34648 + static unsigned short cnt;
34651 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34654 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34655 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34656 + dentry = ERR_PTR(-ENAMETOOLONG);
34657 + if (unlikely(qs.len > NAME_MAX))
34659 + dentry = ERR_PTR(-ENOMEM);
34660 + name = kmalloc(qs.len + 1, GFP_NOFS);
34661 + if (unlikely(!name))
34665 + /* doubly whiteout-ed */
34666 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34667 + p = name + AUFS_WH_PFX_LEN * 2;
34668 + memcpy(p, prefix->name, prefix->len);
34669 + p += prefix->len;
34671 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34674 + for (i = 0; i < 3; i++) {
34675 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34676 + dentry = au_sio_lkup_one(&qs, h_parent);
34677 + if (IS_ERR(dentry) || d_is_negative(dentry))
34681 + /* pr_warn("could not get random name\n"); */
34682 + dentry = ERR_PTR(-EEXIST);
34683 + AuDbg("%.*s\n", AuLNPair(&qs));
34687 + if (name != defname)
34690 + AuTraceErrPtr(dentry);
34695 + * rename the @h_dentry on @br to the whiteouted temporary name.
34697 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34700 + struct path h_path = {
34701 + .mnt = au_br_mnt(br)
34703 + struct inode *h_dir, *delegated;
34704 + struct dentry *h_parent;
34706 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34707 + h_dir = d_inode(h_parent);
34708 + IMustLock(h_dir);
34710 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34711 + err = PTR_ERR(h_path.dentry);
34712 + if (IS_ERR(h_path.dentry))
34715 + /* under the same dir, no need to lock_rename() */
34716 + delegated = NULL;
34717 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34720 + if (unlikely(err == -EWOULDBLOCK)) {
34721 + pr_warn("cannot retry for NFSv4 delegation"
34722 + " for an internal rename\n");
34725 + dput(h_path.dentry);
34732 +/* ---------------------------------------------------------------------- */
34734 + * functions for removing a whiteout
34737 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34740 + struct inode *delegated;
34743 + * forces superio when the dir has a sticky bit.
34744 + * this may be a violation of unix fs semantics.
34746 + force = (h_dir->i_mode & S_ISVTX)
34747 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34748 + delegated = NULL;
34749 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34750 + if (unlikely(err == -EWOULDBLOCK)) {
34751 + pr_warn("cannot retry for NFSv4 delegation"
34752 + " for an internal unlink\n");
34758 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34759 + struct dentry *dentry)
34763 + err = do_unlink_wh(h_dir, h_path);
34764 + if (!err && dentry)
34765 + au_set_dbwh(dentry, -1);
34770 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34771 + struct au_branch *br)
34774 + struct path h_path = {
34775 + .mnt = au_br_mnt(br)
34779 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34780 + if (IS_ERR(h_path.dentry))
34781 + err = PTR_ERR(h_path.dentry);
34783 + if (d_is_reg(h_path.dentry))
34784 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34785 + dput(h_path.dentry);
34791 +/* ---------------------------------------------------------------------- */
34793 + * initialize/clean whiteout for a branch
34796 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34800 + struct inode *delegated;
34802 + if (d_is_negative(whpath->dentry))
34806 + err = vfsub_rmdir(h_dir, whpath);
34808 + delegated = NULL;
34809 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34810 + if (unlikely(err == -EWOULDBLOCK)) {
34811 + pr_warn("cannot retry for NFSv4 delegation"
34812 + " for an internal unlink\n");
34816 + if (unlikely(err))
34817 + pr_warn("failed removing %pd (%d), ignored.\n",
34818 + whpath->dentry, err);
34821 +static int test_linkable(struct dentry *h_root)
34823 + struct inode *h_dir = d_inode(h_root);
34825 + if (h_dir->i_op->link)
34828 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34829 + h_root, au_sbtype(h_root->d_sb));
34833 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34834 +static int au_whdir(struct inode *h_dir, struct path *path)
34839 + if (d_is_negative(path->dentry)) {
34840 + int mode = S_IRWXU;
34842 + if (au_test_nfs(path->dentry->d_sb))
34844 + err = vfsub_mkdir(h_dir, path, mode);
34845 + } else if (d_is_dir(path->dentry))
34848 + pr_err("unknown %pd exists\n", path->dentry);
34853 +struct au_wh_base {
34854 + const struct qstr *name;
34855 + struct dentry *dentry;
34858 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34859 + struct path *h_path)
34861 + h_path->dentry = base[AuBrWh_BASE].dentry;
34862 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34863 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34864 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34865 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34866 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34870 + * returns tri-state,
34871 + * minus: error, caller should print the message
34873 + * plus: error, caller should NOT print the message
34875 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34876 + int do_plink, struct au_wh_base base[],
34877 + struct path *h_path)
34880 + struct inode *h_dir;
34882 + h_dir = d_inode(h_root);
34883 + h_path->dentry = base[AuBrWh_BASE].dentry;
34884 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34885 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34887 + err = test_linkable(h_root);
34888 + if (unlikely(err)) {
34893 + err = au_whdir(h_dir, h_path);
34894 + if (unlikely(err))
34896 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34898 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34899 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34900 + err = au_whdir(h_dir, h_path);
34901 + if (unlikely(err))
34903 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34910 + * for the moment, aufs supports the branch filesystem which does not support
34911 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
34912 + * copyup failed. finally, such filesystem will not be used as the writable
34915 + * returns tri-state, see above.
34917 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
34918 + int do_plink, struct au_wh_base base[],
34919 + struct path *h_path)
34922 + struct inode *h_dir;
34924 + WbrWhMustWriteLock(wbr);
34926 + err = test_linkable(h_root);
34927 + if (unlikely(err)) {
34933 + * todo: should this create be done in /sbin/mount.aufs helper?
34936 + h_dir = d_inode(h_root);
34937 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
34938 + h_path->dentry = base[AuBrWh_BASE].dentry;
34939 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
34940 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
34943 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
34944 + if (unlikely(err))
34947 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34949 + err = au_whdir(h_dir, h_path);
34950 + if (unlikely(err))
34952 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34954 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34955 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
34957 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34958 + err = au_whdir(h_dir, h_path);
34959 + if (unlikely(err))
34961 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34968 + * initialize the whiteout base file/dir for @br.
34970 +int au_wh_init(struct au_branch *br, struct super_block *sb)
34973 + const unsigned char do_plink
34974 + = !!au_opt_test(au_mntflags(sb), PLINK);
34975 + struct inode *h_dir;
34976 + struct path path = br->br_path;
34977 + struct dentry *h_root = path.dentry;
34978 + struct au_wbr *wbr = br->br_wbr;
34979 + static const struct qstr base_name[] = {
34980 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
34981 + sizeof(AUFS_BASE_NAME) - 1),
34982 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
34983 + sizeof(AUFS_PLINKDIR_NAME) - 1),
34984 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
34985 + sizeof(AUFS_ORPHDIR_NAME) - 1)
34987 + struct au_wh_base base[] = {
34988 + [AuBrWh_BASE] = {
34989 + .name = base_name + AuBrWh_BASE,
34992 + [AuBrWh_PLINK] = {
34993 + .name = base_name + AuBrWh_PLINK,
34996 + [AuBrWh_ORPH] = {
34997 + .name = base_name + AuBrWh_ORPH,
35003 + WbrWhMustWriteLock(wbr);
35005 + for (i = 0; i < AuBrWh_Last; i++) {
35006 + /* doubly whiteouted */
35007 + struct dentry *d;
35009 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35010 + err = PTR_ERR(d);
35014 + base[i].dentry = d;
35016 + && wbr->wbr_wh[i]
35017 + && wbr->wbr_wh[i] != base[i].dentry);
35021 + for (i = 0; i < AuBrWh_Last; i++) {
35022 + dput(wbr->wbr_wh[i]);
35023 + wbr->wbr_wh[i] = NULL;
35027 + if (!au_br_writable(br->br_perm)) {
35028 + h_dir = d_inode(h_root);
35029 + au_wh_init_ro(h_dir, base, &path);
35030 + } else if (!au_br_wh_linkable(br->br_perm)) {
35031 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35037 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35043 + goto out; /* success */
35046 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35047 + err, h_root, au_sbtype(h_root->d_sb));
35049 + for (i = 0; i < AuBrWh_Last; i++)
35050 + dput(base[i].dentry);
35054 +/* ---------------------------------------------------------------------- */
35056 + * whiteouts are all hard-linked usually.
35057 + * when its link count reaches a ceiling, we create a new whiteout base
35058 + * asynchronously.
35061 +struct reinit_br_wh {
35062 + struct super_block *sb;
35063 + struct au_branch *br;
35066 +static void reinit_br_wh(void *arg)
35069 + aufs_bindex_t bindex;
35070 + struct path h_path;
35071 + struct reinit_br_wh *a = arg;
35072 + struct au_wbr *wbr;
35073 + struct inode *dir, *delegated;
35074 + struct dentry *h_root;
35075 + struct au_hinode *hdir;
35078 + wbr = a->br->br_wbr;
35079 + /* big aufs lock */
35080 + si_noflush_write_lock(a->sb);
35081 + if (!au_br_writable(a->br->br_perm))
35083 + bindex = au_br_index(a->sb, a->br->br_id);
35084 + if (unlikely(bindex < 0))
35087 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35088 + dir = d_inode(a->sb->s_root);
35089 + hdir = au_hi(dir, bindex);
35090 + h_root = au_h_dptr(a->sb->s_root, bindex);
35091 + AuDebugOn(h_root != au_br_dentry(a->br));
35093 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35094 + wbr_wh_write_lock(wbr);
35095 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35098 + h_path.dentry = wbr->wbr_whbase;
35099 + h_path.mnt = au_br_mnt(a->br);
35100 + delegated = NULL;
35101 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35103 + if (unlikely(err == -EWOULDBLOCK)) {
35104 + pr_warn("cannot retry for NFSv4 delegation"
35105 + " for an internal unlink\n");
35109 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35112 + dput(wbr->wbr_whbase);
35113 + wbr->wbr_whbase = NULL;
35115 + err = au_wh_init(a->br, a->sb);
35116 + wbr_wh_write_unlock(wbr);
35117 + au_hn_inode_unlock(hdir);
35118 + di_read_unlock(a->sb->s_root, AuLock_IR);
35120 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35124 + atomic_dec(&wbr->wbr_wh_running);
35125 + au_br_put(a->br);
35126 + si_write_unlock(a->sb);
35127 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35129 + if (unlikely(err))
35130 + AuIOErr("err %d\n", err);
35133 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35135 + int do_dec, wkq_err;
35136 + struct reinit_br_wh *arg;
35139 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35142 + /* ignore ENOMEM */
35143 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35146 + * dec(wh_running), kfree(arg) and dec(br_count)
35147 + * in reinit function
35152 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35153 + if (unlikely(wkq_err)) {
35154 + atomic_dec(&br->br_wbr->wbr_wh_running);
35163 + atomic_dec(&br->br_wbr->wbr_wh_running);
35166 +/* ---------------------------------------------------------------------- */
35169 + * create the whiteout @wh.
35171 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35172 + struct dentry *wh)
35175 + struct path h_path = {
35178 + struct au_branch *br;
35179 + struct au_wbr *wbr;
35180 + struct dentry *h_parent;
35181 + struct inode *h_dir, *delegated;
35183 + h_parent = wh->d_parent; /* dir inode is locked */
35184 + h_dir = d_inode(h_parent);
35185 + IMustLock(h_dir);
35187 + br = au_sbr(sb, bindex);
35188 + h_path.mnt = au_br_mnt(br);
35189 + wbr = br->br_wbr;
35190 + wbr_wh_read_lock(wbr);
35191 + if (wbr->wbr_whbase) {
35192 + delegated = NULL;
35193 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35194 + if (unlikely(err == -EWOULDBLOCK)) {
35195 + pr_warn("cannot retry for NFSv4 delegation"
35196 + " for an internal link\n");
35199 + if (!err || err != -EMLINK)
35202 + /* link count full. re-initialize br_whbase. */
35203 + kick_reinit_br_wh(sb, br);
35206 + /* return this error in this context */
35207 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35209 + au_fhsm_wrote(sb, bindex, /*force*/0);
35212 + wbr_wh_read_unlock(wbr);
35216 +/* ---------------------------------------------------------------------- */
35219 + * create or remove the diropq.
35221 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35222 + unsigned int flags)
35224 + struct dentry *opq_dentry, *h_dentry;
35225 + struct super_block *sb;
35226 + struct au_branch *br;
35229 + sb = dentry->d_sb;
35230 + br = au_sbr(sb, bindex);
35231 + h_dentry = au_h_dptr(dentry, bindex);
35232 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35233 + if (IS_ERR(opq_dentry))
35236 + if (au_ftest_diropq(flags, CREATE)) {
35237 + err = link_or_create_wh(sb, bindex, opq_dentry);
35239 + au_set_dbdiropq(dentry, bindex);
35240 + goto out; /* success */
35243 + struct path tmp = {
35244 + .dentry = opq_dentry,
35245 + .mnt = au_br_mnt(br)
35247 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35249 + au_set_dbdiropq(dentry, -1);
35251 + dput(opq_dentry);
35252 + opq_dentry = ERR_PTR(err);
35255 + return opq_dentry;
35258 +struct do_diropq_args {
35259 + struct dentry **errp;
35260 + struct dentry *dentry;
35261 + aufs_bindex_t bindex;
35262 + unsigned int flags;
35265 +static void call_do_diropq(void *args)
35267 + struct do_diropq_args *a = args;
35268 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35271 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35272 + unsigned int flags)
35274 + struct dentry *diropq, *h_dentry;
35276 + h_dentry = au_h_dptr(dentry, bindex);
35277 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35278 + diropq = do_diropq(dentry, bindex, flags);
35281 + struct do_diropq_args args = {
35283 + .dentry = dentry,
35284 + .bindex = bindex,
35288 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35289 + if (unlikely(wkq_err))
35290 + diropq = ERR_PTR(wkq_err);
35296 +/* ---------------------------------------------------------------------- */
35299 + * lookup whiteout dentry.
35300 + * @h_parent: lower parent dentry which must exist and be locked
35301 + * @base_name: name of dentry which will be whiteouted
35302 + * returns dentry for whiteout.
35304 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35305 + struct au_branch *br)
35308 + struct qstr wh_name;
35309 + struct dentry *wh_dentry;
35311 + err = au_wh_name_alloc(&wh_name, base_name);
35312 + wh_dentry = ERR_PTR(err);
35314 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35315 + kfree(wh_name.name);
35317 + return wh_dentry;
35321 + * link/create a whiteout for @dentry on @bindex.
35323 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35324 + struct dentry *h_parent)
35326 + struct dentry *wh_dentry;
35327 + struct super_block *sb;
35330 + sb = dentry->d_sb;
35331 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35332 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35333 + err = link_or_create_wh(sb, bindex, wh_dentry);
35335 + au_set_dbwh(dentry, bindex);
35336 + au_fhsm_wrote(sb, bindex, /*force*/0);
35339 + wh_dentry = ERR_PTR(err);
35343 + return wh_dentry;
35346 +/* ---------------------------------------------------------------------- */
35348 +/* Delete all whiteouts in this directory on branch bindex. */
35349 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35350 + aufs_bindex_t bindex, struct au_branch *br)
35353 + unsigned long ul, n;
35354 + struct qstr wh_name;
35356 + struct hlist_head *head;
35357 + struct au_vdir_wh *pos;
35358 + struct au_vdir_destr *str;
35361 + p = (void *)__get_free_page(GFP_NOFS);
35362 + wh_name.name = p;
35363 + if (unlikely(!wh_name.name))
35367 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35368 + p += AUFS_WH_PFX_LEN;
35369 + n = whlist->nh_num;
35370 + head = whlist->nh_head;
35371 + for (ul = 0; !err && ul < n; ul++, head++) {
35372 + hlist_for_each_entry(pos, head, wh_hash) {
35373 + if (pos->wh_bindex != bindex)
35376 + str = &pos->wh_str;
35377 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35378 + memcpy(p, str->name, str->len);
35379 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35380 + err = unlink_wh_name(h_dentry, &wh_name, br);
35385 + AuIOErr("whiteout name too long %.*s\n",
35386 + str->len, str->name);
35391 + free_page((unsigned long)wh_name.name);
35397 +struct del_wh_children_args {
35399 + struct dentry *h_dentry;
35400 + struct au_nhash *whlist;
35401 + aufs_bindex_t bindex;
35402 + struct au_branch *br;
35405 +static void call_del_wh_children(void *args)
35407 + struct del_wh_children_args *a = args;
35408 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35411 +/* ---------------------------------------------------------------------- */
35413 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35415 + struct au_whtmp_rmdir *whtmp;
35417 + unsigned int rdhash;
35419 + SiMustAnyLock(sb);
35421 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35422 + if (unlikely(!whtmp)) {
35423 + whtmp = ERR_PTR(-ENOMEM);
35427 + /* no estimation for dir size */
35428 + rdhash = au_sbi(sb)->si_rdhash;
35430 + rdhash = AUFS_RDHASH_DEF;
35431 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35432 + if (unlikely(err)) {
35434 + whtmp = ERR_PTR(err);
35441 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35444 + au_br_put(whtmp->br);
35445 + dput(whtmp->wh_dentry);
35446 + iput(whtmp->dir);
35447 + au_nhash_wh_free(&whtmp->whlist);
35452 + * rmdir the whiteouted temporary named dir @h_dentry.
35453 + * @whlist: whiteouted children.
35455 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35456 + struct dentry *wh_dentry, struct au_nhash *whlist)
35459 + unsigned int h_nlink;
35460 + struct path h_tmp;
35461 + struct inode *wh_inode, *h_dir;
35462 + struct au_branch *br;
35464 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35465 + IMustLock(h_dir);
35467 + br = au_sbr(dir->i_sb, bindex);
35468 + wh_inode = d_inode(wh_dentry);
35469 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35472 + * someone else might change some whiteouts while we were sleeping.
35473 + * it means this whlist may have an obsoleted entry.
35475 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35476 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35479 + struct del_wh_children_args args = {
35481 + .h_dentry = wh_dentry,
35482 + .whlist = whlist,
35483 + .bindex = bindex,
35487 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35488 + if (unlikely(wkq_err))
35491 + inode_unlock(wh_inode);
35494 + h_tmp.dentry = wh_dentry;
35495 + h_tmp.mnt = au_br_mnt(br);
35496 + h_nlink = h_dir->i_nlink;
35497 + err = vfsub_rmdir(h_dir, &h_tmp);
35498 + /* some fs doesn't change the parent nlink in some cases */
35499 + h_nlink -= h_dir->i_nlink;
35503 + if (au_ibtop(dir) == bindex) {
35504 + /* todo: dir->i_mutex is necessary */
35505 + au_cpup_attr_timesizes(dir);
35507 + vfsub_drop_nlink(dir);
35509 + return 0; /* success */
35512 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35516 +static void call_rmdir_whtmp(void *args)
35519 + aufs_bindex_t bindex;
35520 + struct au_whtmp_rmdir *a = args;
35521 + struct super_block *sb;
35522 + struct dentry *h_parent;
35523 + struct inode *h_dir;
35524 + struct au_hinode *hdir;
35526 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35527 + /* inode_lock(a->dir); */
35529 + sb = a->dir->i_sb;
35530 + si_read_lock(sb, !AuLock_FLUSH);
35531 + if (!au_br_writable(a->br->br_perm))
35533 + bindex = au_br_index(sb, a->br->br_id);
35534 + if (unlikely(bindex < 0))
35538 + ii_write_lock_parent(a->dir);
35539 + h_parent = dget_parent(a->wh_dentry);
35540 + h_dir = d_inode(h_parent);
35541 + hdir = au_hi(a->dir, bindex);
35542 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35543 + if (unlikely(err))
35545 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35546 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35549 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35550 + au_hn_inode_unlock(hdir);
35551 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35555 + ii_write_unlock(a->dir);
35557 + /* inode_unlock(a->dir); */
35558 + au_whtmp_rmdir_free(a);
35559 + si_read_unlock(sb);
35560 + au_nwt_done(&au_sbi(sb)->si_nowait);
35561 + if (unlikely(err))
35562 + AuIOErr("err %d\n", err);
35565 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35566 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35569 + struct super_block *sb;
35573 + /* all post-process will be done in do_rmdir_whtmp(). */
35575 + args->dir = au_igrab(dir);
35576 + args->br = au_sbr(sb, bindex);
35577 + au_br_get(args->br);
35578 + args->wh_dentry = dget(wh_dentry);
35579 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35580 + if (unlikely(wkq_err)) {
35581 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35582 + au_whtmp_rmdir_free(args);
35585 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35586 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35587 +++ linux/fs/aufs/whout.h 2018-04-15 08:49:13.404484168 +0200
35590 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35592 + * This program, aufs is free software; you can redistribute it and/or modify
35593 + * it under the terms of the GNU General Public License as published by
35594 + * the Free Software Foundation; either version 2 of the License, or
35595 + * (at your option) any later version.
35597 + * This program is distributed in the hope that it will be useful,
35598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35600 + * GNU General Public License for more details.
35602 + * You should have received a copy of the GNU General Public License
35603 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35607 + * whiteout for logical deletion and opaque directory
35610 +#ifndef __AUFS_WHOUT_H__
35611 +#define __AUFS_WHOUT_H__
35618 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35619 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35620 +int au_diropq_test(struct dentry *h_dentry);
35622 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35623 + struct qstr *prefix);
35624 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35625 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35626 + struct dentry *dentry);
35627 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35629 +/* diropq flags */
35630 +#define AuDiropq_CREATE 1
35631 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35632 +#define au_fset_diropq(flags, name) \
35633 + do { (flags) |= AuDiropq_##name; } while (0)
35634 +#define au_fclr_diropq(flags, name) \
35635 + do { (flags) &= ~AuDiropq_##name; } while (0)
35637 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35638 + unsigned int flags);
35639 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35640 + struct au_branch *br);
35641 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35642 + struct dentry *h_parent);
35644 +/* real rmdir for the whiteout-ed dir */
35645 +struct au_whtmp_rmdir {
35646 + struct inode *dir;
35647 + struct au_branch *br;
35648 + struct dentry *wh_dentry;
35649 + struct au_nhash whlist;
35652 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35653 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35654 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35655 + struct dentry *wh_dentry, struct au_nhash *whlist);
35656 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35657 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35659 +/* ---------------------------------------------------------------------- */
35661 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35662 + aufs_bindex_t bindex)
35664 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35667 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35669 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35672 +#endif /* __KERNEL__ */
35673 +#endif /* __AUFS_WHOUT_H__ */
35674 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35675 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35676 +++ linux/fs/aufs/wkq.c 2018-04-15 08:49:13.404484168 +0200
35679 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35681 + * This program, aufs is free software; you can redistribute it and/or modify
35682 + * it under the terms of the GNU General Public License as published by
35683 + * the Free Software Foundation; either version 2 of the License, or
35684 + * (at your option) any later version.
35686 + * This program is distributed in the hope that it will be useful,
35687 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35688 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35689 + * GNU General Public License for more details.
35691 + * You should have received a copy of the GNU General Public License
35692 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35696 + * workqueue for asynchronous/super-io operations
35697 + * todo: try new dredential scheme
35700 +#include <linux/module.h>
35703 +/* internal workqueue named AUFS_WKQ_NAME */
35705 +static struct workqueue_struct *au_wkq;
35707 +struct au_wkinfo {
35708 + struct work_struct wk;
35709 + struct kobject *kobj;
35711 + unsigned int flags; /* see wkq.h */
35713 + au_wkq_func_t func;
35716 + struct completion *comp;
35719 +/* ---------------------------------------------------------------------- */
35721 +static void wkq_func(struct work_struct *wk)
35723 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
35725 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
35726 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
35728 + wkinfo->func(wkinfo->args);
35729 + if (au_ftest_wkq(wkinfo->flags, WAIT))
35730 + complete(wkinfo->comp);
35732 + kobject_put(wkinfo->kobj);
35733 + module_put(THIS_MODULE); /* todo: ?? */
35739 + * Since struct completion is large, try allocating it dynamically.
35741 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
35742 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
35744 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35746 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
35748 + init_completion(*comp);
35749 + wkinfo->comp = *comp;
35755 +static void au_wkq_comp_free(struct completion *comp)
35763 +#define AuWkqCompDeclare(name) \
35764 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
35765 + struct completion *comp = &_ ## name
35767 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
35769 + wkinfo->comp = *comp;
35773 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
35777 +#endif /* 4KSTACKS */
35779 +static void au_wkq_run(struct au_wkinfo *wkinfo)
35781 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
35782 + if (au_wkq_test()) {
35783 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
35784 + " due to a dead dir by UDBA?\n");
35785 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
35788 + au_dbg_verify_kthread();
35790 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
35791 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
35792 + queue_work(au_wkq, &wkinfo->wk);
35794 + INIT_WORK(&wkinfo->wk, wkq_func);
35795 + schedule_work(&wkinfo->wk);
35800 + * Be careful. It is easy to make deadlock happen.
35801 + * processA: lock, wkq and wait
35802 + * processB: wkq and wait, lock in wkq
35805 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
35808 + AuWkqCompDeclare(comp);
35809 + struct au_wkinfo wkinfo = {
35815 + err = au_wkq_comp_alloc(&wkinfo, &comp);
35817 + au_wkq_run(&wkinfo);
35818 + /* no timeout, no interrupt */
35819 + wait_for_completion(wkinfo.comp);
35820 + au_wkq_comp_free(comp);
35823 + destroy_work_on_stack(&wkinfo.wk);
35828 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
35829 + * problem in a concurrent umounting.
35831 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
35832 + unsigned int flags)
35835 + struct au_wkinfo *wkinfo;
35837 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
35840 + * wkq_func() must free this wkinfo.
35841 + * it highly depends upon the implementation of workqueue.
35844 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
35846 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
35847 + wkinfo->flags = flags & ~AuWkq_WAIT;
35848 + wkinfo->func = func;
35849 + wkinfo->args = args;
35850 + wkinfo->comp = NULL;
35851 + kobject_get(wkinfo->kobj);
35852 + __module_get(THIS_MODULE); /* todo: ?? */
35854 + au_wkq_run(wkinfo);
35857 + au_nwt_done(&au_sbi(sb)->si_nowait);
35863 +/* ---------------------------------------------------------------------- */
35865 +void au_nwt_init(struct au_nowait_tasks *nwt)
35867 + atomic_set(&nwt->nw_len, 0);
35868 + /* smp_mb(); */ /* atomic_set */
35869 + init_waitqueue_head(&nwt->nw_wq);
35872 +void au_wkq_fin(void)
35874 + destroy_workqueue(au_wkq);
35877 +int __init au_wkq_init(void)
35882 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
35883 + if (IS_ERR(au_wkq))
35884 + err = PTR_ERR(au_wkq);
35885 + else if (!au_wkq)
35890 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
35891 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
35892 +++ linux/fs/aufs/wkq.h 2018-04-15 08:49:13.404484168 +0200
35895 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35897 + * This program, aufs is free software; you can redistribute it and/or modify
35898 + * it under the terms of the GNU General Public License as published by
35899 + * the Free Software Foundation; either version 2 of the License, or
35900 + * (at your option) any later version.
35902 + * This program is distributed in the hope that it will be useful,
35903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35905 + * GNU General Public License for more details.
35907 + * You should have received a copy of the GNU General Public License
35908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35912 + * workqueue for asynchronous/super-io operations
35913 + * todo: try new credentials management scheme
35916 +#ifndef __AUFS_WKQ_H__
35917 +#define __AUFS_WKQ_H__
35921 +#include <linux/wait.h>
35923 +struct super_block;
35925 +/* ---------------------------------------------------------------------- */
35928 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
35930 +struct au_nowait_tasks {
35932 + wait_queue_head_t nw_wq;
35935 +/* ---------------------------------------------------------------------- */
35937 +typedef void (*au_wkq_func_t)(void *args);
35940 +#define AuWkq_WAIT 1
35941 +#define AuWkq_NEST (1 << 1)
35942 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
35943 +#define au_fset_wkq(flags, name) \
35944 + do { (flags) |= AuWkq_##name; } while (0)
35945 +#define au_fclr_wkq(flags, name) \
35946 + do { (flags) &= ~AuWkq_##name; } while (0)
35948 +#ifndef CONFIG_AUFS_HNOTIFY
35950 +#define AuWkq_NEST 0
35954 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
35955 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
35956 + unsigned int flags);
35957 +void au_nwt_init(struct au_nowait_tasks *nwt);
35958 +int __init au_wkq_init(void);
35959 +void au_wkq_fin(void);
35961 +/* ---------------------------------------------------------------------- */
35963 +static inline int au_wkq_test(void)
35965 + return current->flags & PF_WQ_WORKER;
35968 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
35970 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
35973 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
35975 + if (atomic_dec_and_test(&nwt->nw_len))
35976 + wake_up_all(&nwt->nw_wq);
35979 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
35981 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
35985 +#endif /* __KERNEL__ */
35986 +#endif /* __AUFS_WKQ_H__ */
35987 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
35988 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
35989 +++ linux/fs/aufs/xattr.c 2018-04-15 08:49:13.404484168 +0200
35992 + * Copyright (C) 2014-2018 Junjiro R. Okajima
35994 + * This program, aufs is free software; you can redistribute it and/or modify
35995 + * it under the terms of the GNU General Public License as published by
35996 + * the Free Software Foundation; either version 2 of the License, or
35997 + * (at your option) any later version.
35999 + * This program is distributed in the hope that it will be useful,
36000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36002 + * GNU General Public License for more details.
36004 + * You should have received a copy of the GNU General Public License
36005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36009 + * handling xattr functions
36012 +#include <linux/fs.h>
36013 +#include <linux/posix_acl_xattr.h>
36014 +#include <linux/xattr.h>
36017 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36019 + if (!ignore_flags)
36027 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36032 +#define cmp(brattr, prefix) do { \
36033 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36034 + XATTR_##prefix##_PREFIX_LEN)) { \
36035 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36041 + cmp(SEC, SECURITY);
36042 + cmp(SYS, SYSTEM);
36043 + cmp(TR, TRUSTED);
36047 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36054 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36056 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36057 + char *name, char **buf, unsigned int ignore_flags,
36058 + unsigned int verbose)
36062 + struct inode *h_idst;
36064 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36066 + if (unlikely(err <= 0)) {
36067 + if (err == -ENODATA
36068 + || (err == -EOPNOTSUPP
36069 + && ((ignore_flags & au_xattr_out_of_list)
36070 + || (au_test_nfs_noacl(d_inode(h_src))
36071 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36073 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36076 + if (err && (verbose || au_debug_test()))
36077 + pr_err("%s, err %d\n", name, err);
36081 + /* unlock it temporary */
36082 + h_idst = d_inode(h_dst);
36083 + inode_unlock(h_idst);
36084 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36085 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36086 + if (unlikely(err)) {
36087 + if (verbose || au_debug_test())
36088 + pr_err("%s, err %d\n", name, err);
36089 + err = au_xattr_ignore(err, name, ignore_flags);
36096 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36097 + unsigned int verbose)
36099 + int err, unlocked, acl_access, acl_default;
36101 + struct inode *h_isrc, *h_idst;
36102 + char *value, *p, *o, *e;
36104 + /* try stopping to update the source inode while we are referencing */
36105 + /* there should not be the parent-child relationship between them */
36106 + h_isrc = d_inode(h_src);
36107 + h_idst = d_inode(h_dst);
36108 + inode_unlock(h_idst);
36109 + vfsub_inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36110 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36113 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36114 + ssz = vfs_listxattr(h_src, NULL, 0);
36116 + if (unlikely(err < 0)) {
36118 + if (err == -ENODATA
36119 + || err == -EOPNOTSUPP)
36120 + err = 0; /* ignore */
36129 + p = kmalloc(ssz, GFP_NOFS);
36131 + if (unlikely(!p))
36133 + err = vfs_listxattr(h_src, p, ssz);
36135 + inode_unlock_shared(h_isrc);
36137 + AuDbg("err %d, ssz %zd\n", err, ssz);
36138 + if (unlikely(err < 0))
36146 + while (!err && p < e) {
36147 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36148 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36149 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36150 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36152 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36154 + p += strlen(p) + 1;
36157 + ignore_flags |= au_xattr_out_of_list;
36158 + if (!err && !acl_access) {
36159 + err = au_do_cpup_xattr(h_dst, h_src,
36160 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36161 + ignore_flags, verbose);
36164 + if (!err && !acl_default) {
36165 + err = au_do_cpup_xattr(h_dst, h_src,
36166 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36167 + ignore_flags, verbose);
36177 + inode_unlock_shared(h_isrc);
36182 +/* ---------------------------------------------------------------------- */
36184 +static int au_smack_reentering(struct super_block *sb)
36186 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36188 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36189 + * i_op->getxattr(). ouch.
36191 + return si_pid_test(sb);
36202 +struct au_lgxattr {
36210 + const char *name;
36217 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36221 + struct path h_path;
36222 + struct super_block *sb;
36224 + sb = dentry->d_sb;
36225 + reenter = au_smack_reentering(sb);
36227 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36228 + if (unlikely(err))
36231 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36232 + if (unlikely(err))
36234 + if (unlikely(!h_path.dentry))
36235 + /* illegally overlapped or something */
36236 + goto out_di; /* pretending success */
36238 + /* always topmost entry only */
36239 + switch (arg->type) {
36240 + case AU_XATTR_LIST:
36241 + err = vfs_listxattr(h_path.dentry,
36242 + arg->u.list.list, arg->u.list.size);
36244 + case AU_XATTR_GET:
36245 + AuDebugOn(d_is_negative(h_path.dentry));
36246 + err = vfs_getxattr(h_path.dentry,
36247 + arg->u.get.name, arg->u.get.value,
36248 + arg->u.get.size);
36254 + di_read_unlock(dentry, AuLock_IR);
36257 + si_read_unlock(sb);
36263 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36265 + struct au_lgxattr arg = {
36266 + .type = AU_XATTR_LIST,
36273 + return au_lgxattr(dentry, &arg);
36276 +static ssize_t au_getxattr(struct dentry *dentry,
36277 + struct inode *inode __maybe_unused,
36278 + const char *name, void *value, size_t size)
36280 + struct au_lgxattr arg = {
36281 + .type = AU_XATTR_GET,
36289 + return au_lgxattr(dentry, &arg);
36292 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36293 + const char *name, const void *value, size_t size,
36296 + struct au_sxattr arg = {
36297 + .type = AU_XATTR_SET,
36306 + return au_sxattr(dentry, inode, &arg);
36309 +/* ---------------------------------------------------------------------- */
36311 +static int au_xattr_get(const struct xattr_handler *handler,
36312 + struct dentry *dentry, struct inode *inode,
36313 + const char *name, void *buffer, size_t size)
36315 + return au_getxattr(dentry, inode, name, buffer, size);
36318 +static int au_xattr_set(const struct xattr_handler *handler,
36319 + struct dentry *dentry, struct inode *inode,
36320 + const char *name, const void *value, size_t size,
36323 + return au_setxattr(dentry, inode, name, value, size, flags);
36326 +static const struct xattr_handler au_xattr_handler = {
36329 + .get = au_xattr_get,
36330 + .set = au_xattr_set
36333 +static const struct xattr_handler *au_xattr_handlers[] = {
36334 +#ifdef CONFIG_FS_POSIX_ACL
36335 + &posix_acl_access_xattr_handler,
36336 + &posix_acl_default_xattr_handler,
36338 + &au_xattr_handler, /* must be last */
36342 +void au_xattr_init(struct super_block *sb)
36344 + sb->s_xattr = au_xattr_handlers;
36346 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36347 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36348 +++ linux/fs/aufs/xino.c 2018-04-15 08:49:13.404484168 +0200
36351 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36353 + * This program, aufs is free software; you can redistribute it and/or modify
36354 + * it under the terms of the GNU General Public License as published by
36355 + * the Free Software Foundation; either version 2 of the License, or
36356 + * (at your option) any later version.
36358 + * This program is distributed in the hope that it will be useful,
36359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36361 + * GNU General Public License for more details.
36363 + * You should have received a copy of the GNU General Public License
36364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36368 + * external inode number translation table and bitmap
36371 +#include <linux/seq_file.h>
36372 +#include <linux/statfs.h>
36375 +/* todo: unnecessary to support mmap_sem since kernel-space? */
36376 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
36380 + mm_segment_t oldfs;
36387 + oldfs = get_fs();
36388 + set_fs(KERNEL_DS);
36390 + /* todo: signal_pending? */
36391 + err = func(file, buf.u, size, pos);
36392 + } while (err == -EAGAIN || err == -EINTR);
36395 +#if 0 /* reserved for future use */
36397 + fsnotify_access(file->f_path.dentry);
36403 +/* ---------------------------------------------------------------------- */
36405 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36406 + size_t size, loff_t *pos);
36408 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
36409 + size_t size, loff_t *pos)
36412 + mm_segment_t oldfs;
36415 + const char __user *u;
36418 + const int prevent_endless = 10;
36422 + oldfs = get_fs();
36423 + set_fs(KERNEL_DS);
36425 + err = func(file, buf.u, size, pos);
36426 + if (err == -EINTR
36427 + && !au_wkq_test()
36428 + && fatal_signal_pending(current)) {
36430 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
36431 + BUG_ON(err == -EINTR);
36432 + oldfs = get_fs();
36433 + set_fs(KERNEL_DS);
36435 + } while (i++ < prevent_endless
36436 + && (err == -EAGAIN || err == -EINTR));
36439 +#if 0 /* reserved for future use */
36441 + fsnotify_modify(file->f_path.dentry);
36447 +struct do_xino_fwrite_args {
36449 + vfs_writef_t func;
36450 + struct file *file;
36456 +static void call_do_xino_fwrite(void *args)
36458 + struct do_xino_fwrite_args *a = args;
36459 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
36462 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
36463 + size_t size, loff_t *pos)
36467 + struct do_xino_fwrite_args args = {
36477 + * it breaks RLIMIT_FSIZE and normal user's limit,
36478 + * users should care about quota and real 'filesystem full.'
36480 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
36481 + if (unlikely(wkq_err))
36487 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
36488 + size_t size, loff_t *pos)
36492 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
36494 + err = do_xino_fwrite(func, file, buf, size, pos);
36497 + err = xino_fwrite_wkq(func, file, buf, size, pos);
36502 +/* ---------------------------------------------------------------------- */
36505 + * create a new xinofile at the same place/path as @base_file.
36507 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
36509 + struct file *file;
36510 + struct dentry *base, *parent;
36511 + struct inode *dir, *delegated;
36512 + struct qstr *name;
36513 + struct path path;
36516 + base = base_file->f_path.dentry;
36517 + parent = base->d_parent; /* dir inode is locked */
36518 + dir = d_inode(parent);
36521 + file = ERR_PTR(-EINVAL);
36522 + name = &base->d_name;
36523 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36524 + if (IS_ERR(path.dentry)) {
36525 + file = (void *)path.dentry;
36526 + pr_err("%pd lookup err %ld\n",
36527 + base, PTR_ERR(path.dentry));
36531 + /* no need to mnt_want_write() since we call dentry_open() later */
36532 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
36533 + if (unlikely(err)) {
36534 + file = ERR_PTR(err);
36535 + pr_err("%pd create err %d\n", base, err);
36539 + path.mnt = base_file->f_path.mnt;
36540 + file = vfsub_dentry_open(&path,
36541 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36542 + /* | __FMODE_NONOTIFY */);
36543 + if (IS_ERR(file)) {
36544 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
36548 + delegated = NULL;
36549 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36550 + if (unlikely(err == -EWOULDBLOCK)) {
36551 + pr_warn("cannot retry for NFSv4 delegation"
36552 + " for an internal unlink\n");
36555 + if (unlikely(err)) {
36556 + pr_err("%pd unlink err %d\n", base, err);
36561 + /* no one can touch copy_src xino */
36562 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36563 + if (unlikely(err)) {
36564 + pr_err("%pd copy err %d\n", base, err);
36568 + goto out_dput; /* success */
36572 + file = ERR_PTR(err);
36574 + dput(path.dentry);
36579 +struct au_xino_lock_dir {
36580 + struct au_hinode *hdir;
36581 + struct dentry *parent;
36582 + struct inode *dir;
36585 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
36586 + struct au_xino_lock_dir *ldir)
36588 + aufs_bindex_t brid, bindex;
36590 + ldir->hdir = NULL;
36592 + brid = au_xino_brid(sb);
36594 + bindex = au_br_index(sb, brid);
36595 + if (bindex >= 0) {
36596 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36597 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36599 + ldir->parent = dget_parent(xino->f_path.dentry);
36600 + ldir->dir = d_inode(ldir->parent);
36601 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
36605 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36608 + au_hn_inode_unlock(ldir->hdir);
36610 + inode_unlock(ldir->dir);
36611 + dput(ldir->parent);
36615 +/* ---------------------------------------------------------------------- */
36617 +/* trucate xino files asynchronously */
36619 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
36622 + unsigned long jiffy;
36624 + aufs_bindex_t bi, bbot;
36625 + struct kstatfs *st;
36626 + struct au_branch *br;
36627 + struct file *new_xino, *file;
36628 + struct super_block *h_sb;
36629 + struct au_xino_lock_dir ldir;
36632 + st = kmalloc(sizeof(*st), GFP_NOFS);
36633 + if (unlikely(!st))
36637 + bbot = au_sbbot(sb);
36638 + if (unlikely(bindex < 0 || bbot < bindex))
36640 + br = au_sbr(sb, bindex);
36641 + file = br->br_xino.xi_file;
36645 + err = vfs_statfs(&file->f_path, st);
36646 + if (unlikely(err))
36647 + AuErr1("statfs err %d, ignored\n", err);
36649 + blocks = file_inode(file)->i_blocks;
36650 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36651 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
36653 + au_xino_lock_dir(sb, file, &ldir);
36654 + /* mnt_want_write() is unnecessary here */
36655 + new_xino = au_xino_create2(file, file);
36656 + au_xino_unlock_dir(&ldir);
36657 + err = PTR_ERR(new_xino);
36658 + if (IS_ERR(new_xino)) {
36659 + pr_err("err %d, ignored\n", err);
36664 + br->br_xino.xi_file = new_xino;
36666 + h_sb = au_br_sb(br);
36667 + for (bi = 0; bi <= bbot; bi++) {
36668 + if (unlikely(bi == bindex))
36670 + br = au_sbr(sb, bi);
36671 + if (au_br_sb(br) != h_sb)
36674 + fput(br->br_xino.xi_file);
36675 + br->br_xino.xi_file = new_xino;
36676 + get_file(new_xino);
36679 + err = vfs_statfs(&new_xino->f_path, st);
36681 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36682 + bindex, (u64)file_inode(new_xino)->i_blocks,
36683 + st->f_bfree, st->f_blocks);
36684 + if (file_inode(new_xino)->i_blocks < blocks)
36685 + au_sbi(sb)->si_xino_jiffy = jiffy;
36687 + AuErr1("statfs err %d, ignored\n", err);
36695 +struct xino_do_trunc_args {
36696 + struct super_block *sb;
36697 + struct au_branch *br;
36700 +static void xino_do_trunc(void *_args)
36702 + struct xino_do_trunc_args *args = _args;
36703 + struct super_block *sb;
36704 + struct au_branch *br;
36705 + struct inode *dir;
36707 + aufs_bindex_t bindex;
36711 + dir = d_inode(sb->s_root);
36714 + si_noflush_write_lock(sb);
36715 + ii_read_lock_parent(dir);
36716 + bindex = au_br_index(sb, br->br_id);
36717 + err = au_xino_trunc(sb, bindex);
36718 + ii_read_unlock(dir);
36719 + if (unlikely(err))
36720 + pr_warn("err b%d, (%d)\n", bindex, err);
36721 + atomic_dec(&br->br_xino_running);
36723 + si_write_unlock(sb);
36724 + au_nwt_done(&au_sbi(sb)->si_nowait);
36728 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
36731 + struct kstatfs st;
36732 + struct au_sbinfo *sbinfo;
36734 + /* todo: si_xino_expire and the ratio should be customizable */
36735 + sbinfo = au_sbi(sb);
36736 + if (time_before(jiffies,
36737 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
36740 + /* truncation border */
36741 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
36742 + if (unlikely(err)) {
36743 + AuErr1("statfs err %d, ignored\n", err);
36746 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
36752 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
36754 + struct xino_do_trunc_args *args;
36757 + if (!xino_trunc_test(sb, br))
36760 + if (atomic_inc_return(&br->br_xino_running) > 1)
36763 + /* lock and kfree() will be called in trunc_xino() */
36764 + args = kmalloc(sizeof(*args), GFP_NOFS);
36765 + if (unlikely(!args)) {
36766 + AuErr1("no memory\n");
36773 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
36775 + return; /* success */
36777 + pr_err("wkq %d\n", wkq_err);
36782 + atomic_dec(&br->br_xino_running);
36785 +/* ---------------------------------------------------------------------- */
36787 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
36788 + ino_t h_ino, ino_t ino)
36794 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
36795 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
36798 + pos *= sizeof(ino);
36799 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
36800 + if (sz == sizeof(ino))
36801 + return 0; /* success */
36803 + AuIOErr("write failed (%zd)\n", sz);
36808 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
36809 + * at the position of @h_ino.
36810 + * even if @ino is zero, it is written to the xinofile and means no entry.
36811 + * if the size of the xino file on a specific filesystem exceeds the watermark,
36812 + * try truncating it.
36814 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
36818 + unsigned int mnt_flags;
36819 + struct au_branch *br;
36821 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
36822 + || ((loff_t)-1) > 0);
36823 + SiMustAnyLock(sb);
36825 + mnt_flags = au_mntflags(sb);
36826 + if (!au_opt_test(mnt_flags, XINO))
36829 + br = au_sbr(sb, bindex);
36830 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
36833 + if (au_opt_test(mnt_flags, TRUNC_XINO)
36834 + && au_test_fs_trunc_xino(au_br_sb(br)))
36835 + xino_try_trunc(sb, br);
36836 + return 0; /* success */
36839 + AuIOErr("write failed (%d)\n", err);
36843 +/* ---------------------------------------------------------------------- */
36845 +/* aufs inode number bitmap */
36847 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
36848 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
36852 + AuDebugOn(bit < 0 || page_bits <= bit);
36853 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
36857 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
36859 + AuDebugOn(ino < AUFS_FIRST_INO);
36860 + ino -= AUFS_FIRST_INO;
36861 + *pindex = ino / page_bits;
36862 + *bit = ino % page_bits;
36865 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
36870 + struct au_sbinfo *sbinfo;
36871 + struct file *xib;
36872 + unsigned long *p;
36874 + sbinfo = au_sbi(sb);
36875 + MtxMustLock(&sbinfo->si_xib_mtx);
36876 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
36877 + || !au_opt_test(sbinfo->si_mntflags, XINO));
36879 + if (pindex == sbinfo->si_xib_last_pindex)
36882 + xib = sbinfo->si_xib;
36883 + p = sbinfo->si_xib_buf;
36884 + pos = sbinfo->si_xib_last_pindex;
36885 + pos *= PAGE_SIZE;
36886 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
36887 + if (unlikely(sz != PAGE_SIZE))
36891 + pos *= PAGE_SIZE;
36892 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
36893 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
36895 + memset(p, 0, PAGE_SIZE);
36896 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
36898 + if (sz == PAGE_SIZE) {
36899 + sbinfo->si_xib_last_pindex = pindex;
36900 + return 0; /* success */
36904 + AuIOErr1("write failed (%zd)\n", sz);
36911 +/* ---------------------------------------------------------------------- */
36913 +static void au_xib_clear_bit(struct inode *inode)
36916 + unsigned long pindex;
36917 + struct super_block *sb;
36918 + struct au_sbinfo *sbinfo;
36920 + AuDebugOn(inode->i_nlink);
36922 + sb = inode->i_sb;
36923 + xib_calc_bit(inode->i_ino, &pindex, &bit);
36924 + AuDebugOn(page_bits <= bit);
36925 + sbinfo = au_sbi(sb);
36926 + mutex_lock(&sbinfo->si_xib_mtx);
36927 + err = xib_pindex(sb, pindex);
36929 + clear_bit(bit, sbinfo->si_xib_buf);
36930 + sbinfo->si_xib_next_bit = bit;
36932 + mutex_unlock(&sbinfo->si_xib_mtx);
36935 +/* for s_op->delete_inode() */
36936 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
36939 + unsigned int mnt_flags;
36940 + aufs_bindex_t bindex, bbot, bi;
36941 + unsigned char try_trunc;
36942 + struct au_iinfo *iinfo;
36943 + struct super_block *sb;
36944 + struct au_hinode *hi;
36945 + struct inode *h_inode;
36946 + struct au_branch *br;
36947 + vfs_writef_t xwrite;
36949 + AuDebugOn(au_is_bad_inode(inode));
36951 + sb = inode->i_sb;
36952 + mnt_flags = au_mntflags(sb);
36953 + if (!au_opt_test(mnt_flags, XINO)
36954 + || inode->i_ino == AUFS_ROOT_INO)
36958 + au_xigen_inc(inode);
36959 + au_xib_clear_bit(inode);
36962 + iinfo = au_ii(inode);
36963 + bindex = iinfo->ii_btop;
36967 + xwrite = au_sbi(sb)->si_xwrite;
36968 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
36969 + hi = au_hinode(iinfo, bindex);
36970 + bbot = iinfo->ii_bbot;
36971 + for (; bindex <= bbot; bindex++, hi++) {
36972 + h_inode = hi->hi_inode;
36974 + || (!unlinked && h_inode->i_nlink))
36977 + /* inode may not be revalidated */
36978 + bi = au_br_index(sb, hi->hi_id);
36982 + br = au_sbr(sb, bi);
36983 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
36984 + h_inode->i_ino, /*ino*/0);
36985 + if (!err && try_trunc
36986 + && au_test_fs_trunc_xino(au_br_sb(br)))
36987 + xino_try_trunc(sb, br);
36991 +/* get an unused inode number from bitmap */
36992 +ino_t au_xino_new_ino(struct super_block *sb)
36995 + unsigned long *p, pindex, ul, pend;
36996 + struct au_sbinfo *sbinfo;
36997 + struct file *file;
36998 + int free_bit, err;
37000 + if (!au_opt_test(au_mntflags(sb), XINO))
37001 + return iunique(sb, AUFS_FIRST_INO);
37003 + sbinfo = au_sbi(sb);
37004 + mutex_lock(&sbinfo->si_xib_mtx);
37005 + p = sbinfo->si_xib_buf;
37006 + free_bit = sbinfo->si_xib_next_bit;
37007 + if (free_bit < page_bits && !test_bit(free_bit, p))
37008 + goto out; /* success */
37009 + free_bit = find_first_zero_bit(p, page_bits);
37010 + if (free_bit < page_bits)
37011 + goto out; /* success */
37013 + pindex = sbinfo->si_xib_last_pindex;
37014 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
37015 + err = xib_pindex(sb, ul);
37016 + if (unlikely(err))
37018 + free_bit = find_first_zero_bit(p, page_bits);
37019 + if (free_bit < page_bits)
37020 + goto out; /* success */
37023 + file = sbinfo->si_xib;
37024 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
37025 + for (ul = pindex + 1; ul <= pend; ul++) {
37026 + err = xib_pindex(sb, ul);
37027 + if (unlikely(err))
37029 + free_bit = find_first_zero_bit(p, page_bits);
37030 + if (free_bit < page_bits)
37031 + goto out; /* success */
37036 + set_bit(free_bit, p);
37037 + sbinfo->si_xib_next_bit = free_bit + 1;
37038 + pindex = sbinfo->si_xib_last_pindex;
37039 + mutex_unlock(&sbinfo->si_xib_mtx);
37040 + ino = xib_calc_ino(pindex, free_bit);
37041 + AuDbg("i%lu\n", (unsigned long)ino);
37044 + mutex_unlock(&sbinfo->si_xib_mtx);
37050 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37051 + * at the position of @h_ino.
37052 + * if @ino does not exist and @do_new is true, get new one.
37054 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37060 + struct file *file;
37061 + struct au_sbinfo *sbinfo;
37064 + if (!au_opt_test(au_mntflags(sb), XINO))
37065 + return 0; /* no xino */
37068 + sbinfo = au_sbi(sb);
37070 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
37071 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37074 + pos *= sizeof(*ino);
37076 + file = au_sbr(sb, bindex)->br_xino.xi_file;
37077 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
37078 + return 0; /* no ino */
37080 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
37081 + if (sz == sizeof(*ino))
37082 + return 0; /* success */
37085 + if (unlikely(sz >= 0)) {
37087 + AuIOErr("xino read error (%zd)\n", sz);
37093 +/* ---------------------------------------------------------------------- */
37095 +/* create and set a new xino file */
37097 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
37099 + struct file *file;
37100 + struct dentry *h_parent, *d;
37101 + struct inode *h_dir, *inode;
37105 + * at mount-time, and the xino file is the default path,
37106 + * hnotify is disabled so we have no notify events to ignore.
37107 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37109 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37110 + /* | __FMODE_NONOTIFY */,
37111 + S_IRUGO | S_IWUGO);
37112 + if (IS_ERR(file)) {
37114 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
37118 + /* keep file count */
37120 + inode = file_inode(file);
37121 + h_parent = dget_parent(file->f_path.dentry);
37122 + h_dir = d_inode(h_parent);
37123 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
37124 + /* mnt_want_write() is unnecessary here */
37125 + /* no delegation since it is just created */
37126 + if (inode->i_nlink)
37127 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37129 + inode_unlock(h_dir);
37131 + if (unlikely(err)) {
37133 + pr_err("unlink %s(%d)\n", fname, err);
37138 + d = file->f_path.dentry;
37139 + if (unlikely(sb == d->d_sb)) {
37141 + pr_err("%s must be outside\n", fname);
37144 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37146 + pr_err("xino doesn't support %s(%s)\n",
37147 + fname, au_sbtype(d->d_sb));
37150 + return file; /* success */
37154 + file = ERR_PTR(err);
37159 + * find another branch who is on the same filesystem of the specified
37160 + * branch{@btgt}. search until @bbot.
37162 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37163 + aufs_bindex_t bbot)
37165 + aufs_bindex_t bindex;
37166 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
37168 + for (bindex = 0; bindex < btgt; bindex++)
37169 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37171 + for (bindex++; bindex <= bbot; bindex++)
37172 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
37177 +/* ---------------------------------------------------------------------- */
37180 + * initialize the xinofile for the specified branch @br
37181 + * at the place/path where @base_file indicates.
37182 + * test whether another branch is on the same filesystem or not,
37183 + * if @do_test is true.
37185 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
37186 + struct file *base_file, int do_test)
37190 + aufs_bindex_t bbot, bindex;
37191 + struct au_branch *shared_br, *b;
37192 + struct file *file;
37193 + struct super_block *tgt_sb;
37195 + shared_br = NULL;
37196 + bbot = au_sbbot(sb);
37198 + tgt_sb = au_br_sb(br);
37199 + for (bindex = 0; bindex <= bbot; bindex++) {
37200 + b = au_sbr(sb, bindex);
37201 + if (tgt_sb == au_br_sb(b)) {
37208 + if (!shared_br || !shared_br->br_xino.xi_file) {
37209 + struct au_xino_lock_dir ldir;
37211 + au_xino_lock_dir(sb, base_file, &ldir);
37212 + /* mnt_want_write() is unnecessary here */
37213 + file = au_xino_create2(base_file, NULL);
37214 + au_xino_unlock_dir(&ldir);
37215 + err = PTR_ERR(file);
37216 + if (IS_ERR(file))
37218 + br->br_xino.xi_file = file;
37220 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
37221 + get_file(br->br_xino.xi_file);
37224 + ino = AUFS_ROOT_INO;
37225 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
37227 + if (unlikely(err)) {
37228 + fput(br->br_xino.xi_file);
37229 + br->br_xino.xi_file = NULL;
37236 +/* ---------------------------------------------------------------------- */
37238 +/* trucate a xino bitmap file */
37241 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37245 + unsigned long pindex;
37246 + loff_t pos, pend;
37247 + struct au_sbinfo *sbinfo;
37248 + vfs_readf_t func;
37250 + unsigned long *p;
37253 + sbinfo = au_sbi(sb);
37254 + MtxMustLock(&sbinfo->si_xib_mtx);
37255 + p = sbinfo->si_xib_buf;
37256 + func = sbinfo->si_xread;
37257 + pend = vfsub_f_size_read(file);
37259 + while (pos < pend) {
37260 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37262 + if (unlikely(sz <= 0))
37266 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37267 + if (unlikely(*ino < AUFS_FIRST_INO))
37270 + xib_calc_bit(*ino, &pindex, &bit);
37271 + AuDebugOn(page_bits <= bit);
37272 + err = xib_pindex(sb, pindex);
37284 +static int xib_restore(struct super_block *sb)
37287 + aufs_bindex_t bindex, bbot;
37291 + page = (void *)__get_free_page(GFP_NOFS);
37292 + if (unlikely(!page))
37296 + bbot = au_sbbot(sb);
37297 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37298 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
37299 + err = do_xib_restore
37300 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
37302 + AuDbg("b%d\n", bindex);
37303 + free_page((unsigned long)page);
37309 +int au_xib_trunc(struct super_block *sb)
37314 + struct au_xino_lock_dir ldir;
37315 + struct au_sbinfo *sbinfo;
37316 + unsigned long *p;
37317 + struct file *file;
37319 + SiMustWriteLock(sb);
37322 + sbinfo = au_sbi(sb);
37323 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37326 + file = sbinfo->si_xib;
37327 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37330 + au_xino_lock_dir(sb, file, &ldir);
37331 + /* mnt_want_write() is unnecessary here */
37332 + file = au_xino_create2(sbinfo->si_xib, NULL);
37333 + au_xino_unlock_dir(&ldir);
37334 + err = PTR_ERR(file);
37335 + if (IS_ERR(file))
37337 + fput(sbinfo->si_xib);
37338 + sbinfo->si_xib = file;
37340 + p = sbinfo->si_xib_buf;
37341 + memset(p, 0, PAGE_SIZE);
37343 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
37344 + if (unlikely(sz != PAGE_SIZE)) {
37346 + AuIOErr("err %d\n", err);
37352 + mutex_lock(&sbinfo->si_xib_mtx);
37353 + /* mnt_want_write() is unnecessary here */
37354 + err = xib_restore(sb);
37355 + mutex_unlock(&sbinfo->si_xib_mtx);
37361 +/* ---------------------------------------------------------------------- */
37364 + * xino mount option handlers
37368 +static void xino_clear_xib(struct super_block *sb)
37370 + struct au_sbinfo *sbinfo;
37372 + SiMustWriteLock(sb);
37374 + sbinfo = au_sbi(sb);
37375 + sbinfo->si_xread = NULL;
37376 + sbinfo->si_xwrite = NULL;
37377 + if (sbinfo->si_xib)
37378 + fput(sbinfo->si_xib);
37379 + sbinfo->si_xib = NULL;
37380 + if (sbinfo->si_xib_buf)
37381 + free_page((unsigned long)sbinfo->si_xib_buf);
37382 + sbinfo->si_xib_buf = NULL;
37385 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
37389 + struct au_sbinfo *sbinfo;
37390 + struct file *file;
37392 + SiMustWriteLock(sb);
37394 + sbinfo = au_sbi(sb);
37395 + file = au_xino_create2(base, sbinfo->si_xib);
37396 + err = PTR_ERR(file);
37397 + if (IS_ERR(file))
37399 + if (sbinfo->si_xib)
37400 + fput(sbinfo->si_xib);
37401 + sbinfo->si_xib = file;
37402 + sbinfo->si_xread = vfs_readf(file);
37403 + sbinfo->si_xwrite = vfs_writef(file);
37406 + if (!sbinfo->si_xib_buf)
37407 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
37408 + if (unlikely(!sbinfo->si_xib_buf))
37411 + sbinfo->si_xib_last_pindex = 0;
37412 + sbinfo->si_xib_next_bit = 0;
37413 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
37415 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
37416 + PAGE_SIZE, &pos);
37417 + if (unlikely(err != PAGE_SIZE))
37421 + goto out; /* success */
37424 + if (sbinfo->si_xib_buf)
37425 + free_page((unsigned long)sbinfo->si_xib_buf);
37426 + sbinfo->si_xib_buf = NULL;
37430 + fput(sbinfo->si_xib);
37431 + sbinfo->si_xib = NULL;
37432 + sbinfo->si_xread = NULL;
37433 + sbinfo->si_xwrite = NULL;
37438 +/* xino for each branch */
37439 +static void xino_clear_br(struct super_block *sb)
37441 + aufs_bindex_t bindex, bbot;
37442 + struct au_branch *br;
37444 + bbot = au_sbbot(sb);
37445 + for (bindex = 0; bindex <= bbot; bindex++) {
37446 + br = au_sbr(sb, bindex);
37447 + if (!br || !br->br_xino.xi_file)
37450 + fput(br->br_xino.xi_file);
37451 + br->br_xino.xi_file = NULL;
37455 +static int au_xino_set_br(struct super_block *sb, struct file *base)
37459 + aufs_bindex_t bindex, bbot, bshared;
37461 + struct file *old, *new;
37463 + struct au_branch *br;
37464 + struct inode *inode;
37465 + vfs_writef_t writef;
37467 + SiMustWriteLock(sb);
37470 + bbot = au_sbbot(sb);
37471 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
37472 + if (unlikely(!fpair))
37475 + inode = d_inode(sb->s_root);
37476 + ino = AUFS_ROOT_INO;
37477 + writef = au_sbi(sb)->si_xwrite;
37478 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37479 + bshared = is_sb_shared(sb, bindex, bindex - 1);
37480 + if (bshared >= 0) {
37481 + /* shared xino */
37482 + *p = fpair[bshared];
37483 + get_file(p->new);
37488 + br = au_sbr(sb, bindex);
37489 + p->old = br->br_xino.xi_file;
37490 + p->new = au_xino_create2(base, br->br_xino.xi_file);
37491 + err = PTR_ERR(p->new);
37492 + if (IS_ERR(p->new)) {
37498 + err = au_xino_do_write(writef, p->new,
37499 + au_h_iptr(inode, bindex)->i_ino, ino);
37500 + if (unlikely(err))
37504 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
37505 + br = au_sbr(sb, bindex);
37506 + if (br->br_xino.xi_file)
37507 + fput(br->br_xino.xi_file);
37508 + get_file(p->new);
37509 + br->br_xino.xi_file = p->new;
37513 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
37523 +void au_xino_clr(struct super_block *sb)
37525 + struct au_sbinfo *sbinfo;
37527 + au_xigen_clr(sb);
37528 + xino_clear_xib(sb);
37529 + xino_clear_br(sb);
37530 + sbinfo = au_sbi(sb);
37531 + /* lvalue, do not call au_mntflags() */
37532 + au_opt_clr(sbinfo->si_mntflags, XINO);
37535 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
37538 + struct dentry *parent, *cur_parent;
37539 + struct qstr *dname, *cur_name;
37540 + struct file *cur_xino;
37541 + struct inode *dir;
37542 + struct au_sbinfo *sbinfo;
37544 + SiMustWriteLock(sb);
37547 + sbinfo = au_sbi(sb);
37548 + parent = dget_parent(xino->file->f_path.dentry);
37551 + dname = &xino->file->f_path.dentry->d_name;
37552 + cur_xino = sbinfo->si_xib;
37554 + cur_parent = dget_parent(cur_xino->f_path.dentry);
37555 + cur_name = &cur_xino->f_path.dentry->d_name;
37556 + skip = (cur_parent == parent
37557 + && au_qstreq(dname, cur_name));
37558 + dput(cur_parent);
37564 + au_opt_set(sbinfo->si_mntflags, XINO);
37565 + dir = d_inode(parent);
37566 + inode_lock_nested(dir, AuLsc_I_PARENT);
37567 + /* mnt_want_write() is unnecessary here */
37568 + err = au_xino_set_xib(sb, xino->file);
37570 + err = au_xigen_set(sb, xino->file);
37572 + err = au_xino_set_br(sb, xino->file);
37573 + inode_unlock(dir);
37575 + goto out; /* success */
37578 + AuIOErr("failed creating xino(%d).\n", err);
37579 + au_xigen_clr(sb);
37580 + xino_clear_xib(sb);
37587 +/* ---------------------------------------------------------------------- */
37590 + * create a xinofile at the default place/path.
37592 +struct file *au_xino_def(struct super_block *sb)
37594 + struct file *file;
37596 + struct au_branch *br;
37597 + struct super_block *h_sb;
37598 + struct path path;
37599 + aufs_bindex_t bbot, bindex, bwr;
37602 + bbot = au_sbbot(sb);
37604 + for (bindex = 0; bindex <= bbot; bindex++) {
37605 + br = au_sbr(sb, bindex);
37606 + if (au_br_writable(br->br_perm)
37607 + && !au_test_fs_bad_xino(au_br_sb(br))) {
37614 + file = ERR_PTR(-ENOMEM);
37615 + page = (void *)__get_free_page(GFP_NOFS);
37616 + if (unlikely(!page))
37618 + path.mnt = au_br_mnt(br);
37619 + path.dentry = au_h_dptr(sb->s_root, bwr);
37620 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
37621 + file = (void *)p;
37622 + if (!IS_ERR(p)) {
37623 + strcat(p, "/" AUFS_XINO_FNAME);
37624 + AuDbg("%s\n", p);
37625 + file = au_xino_create(sb, p, /*silent*/0);
37626 + if (!IS_ERR(file))
37627 + au_xino_brid_set(sb, br->br_id);
37629 + free_page((unsigned long)page);
37631 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
37632 + if (IS_ERR(file))
37634 + h_sb = file->f_path.dentry->d_sb;
37635 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
37636 + pr_err("xino doesn't support %s(%s)\n",
37637 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
37639 + file = ERR_PTR(-EINVAL);
37641 + if (!IS_ERR(file))
37642 + au_xino_brid_set(sb, -1);
37649 +/* ---------------------------------------------------------------------- */
37651 +int au_xino_path(struct seq_file *seq, struct file *file)
37655 + err = au_seq_path(seq, &file->f_path);
37656 + if (unlikely(err))
37659 +#define Deleted "\\040(deleted)"
37660 + seq->count -= sizeof(Deleted) - 1;
37661 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
37662 + sizeof(Deleted) - 1));
37669 +/* ---------------------------------------------------------------------- */
37671 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
37672 + ino_t h_ino, int idx)
37674 + struct au_xino_file *xino;
37676 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
37677 + xino = &au_sbr(sb, bindex)->br_xino;
37678 + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx);
37680 + spin_lock(&xino->xi_nondir.spin);
37681 + AuDebugOn(xino->xi_nondir.array[idx] != h_ino);
37682 + xino->xi_nondir.array[idx] = 0;
37683 + spin_unlock(&xino->xi_nondir.spin);
37684 + wake_up_all(&xino->xi_nondir.wqh);
37687 +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino)
37689 + int found, total, i;
37692 + total = xino->xi_nondir.total;
37693 + for (i = 0; i < total; i++) {
37694 + if (xino->xi_nondir.array[i] != h_ino)
37703 +static int au_xinondir_expand(struct au_xino_file *xino)
37708 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
37711 + sz = xino->xi_nondir.total * sizeof(ino_t);
37712 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
37714 + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
37715 + /*may_shrink*/0);
37717 + xino->xi_nondir.array = p;
37718 + xino->xi_nondir.total <<= 1;
37719 + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total);
37727 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37730 + int err, found, empty;
37731 + struct au_xino_file *xino;
37735 + if (!au_opt_test(au_mntflags(sb), XINO))
37736 + goto out; /* no xino */
37738 + xino = &au_sbr(sb, bindex)->br_xino;
37741 + spin_lock(&xino->xi_nondir.spin);
37742 + found = au_xinondir_find(xino, h_ino);
37743 + if (found == -1) {
37744 + empty = au_xinondir_find(xino, /*h_ino*/0);
37745 + if (empty == -1) {
37746 + empty = xino->xi_nondir.total;
37747 + err = au_xinondir_expand(xino);
37748 + if (unlikely(err))
37751 + xino->xi_nondir.array[empty] = h_ino;
37754 + spin_unlock(&xino->xi_nondir.spin);
37755 + wait_event(xino->xi_nondir.wqh,
37756 + xino->xi_nondir.array[found] != h_ino);
37761 + spin_unlock(&xino->xi_nondir.spin);
37765 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
37766 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
37767 +++ linux/include/uapi/linux/aufs_type.h 2018-04-15 08:49:13.404484168 +0200
37770 + * Copyright (C) 2005-2018 Junjiro R. Okajima
37772 + * This program, aufs is free software; you can redistribute it and/or modify
37773 + * it under the terms of the GNU General Public License as published by
37774 + * the Free Software Foundation; either version 2 of the License, or
37775 + * (at your option) any later version.
37777 + * This program is distributed in the hope that it will be useful,
37778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37780 + * GNU General Public License for more details.
37782 + * You should have received a copy of the GNU General Public License
37783 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37786 +#ifndef __AUFS_TYPE_H__
37787 +#define __AUFS_TYPE_H__
37789 +#define AUFS_NAME "aufs"
37793 + * define it before including all other headers.
37794 + * sched.h may use pr_* macros before defining "current", so define the
37795 + * no-current version first, and re-define later.
37797 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
37798 +#include <linux/sched.h>
37800 +#define pr_fmt(fmt) \
37801 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
37802 + (int)sizeof(current->comm), current->comm, current->pid
37804 +#include <stdint.h>
37805 +#include <sys/types.h>
37806 +#endif /* __KERNEL__ */
37808 +#include <linux/limits.h>
37810 +#define AUFS_VERSION "4.9-20180409"
37812 +/* todo? move this to linux-2.6.19/include/magic.h */
37813 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
37815 +/* ---------------------------------------------------------------------- */
37817 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
37818 +typedef int8_t aufs_bindex_t;
37819 +#define AUFS_BRANCH_MAX 127
37821 +typedef int16_t aufs_bindex_t;
37822 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
37823 +#define AUFS_BRANCH_MAX 511
37824 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
37825 +#define AUFS_BRANCH_MAX 1023
37826 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
37827 +#define AUFS_BRANCH_MAX 32767
37832 +#ifndef AUFS_BRANCH_MAX
37833 +#error unknown CONFIG_AUFS_BRANCH_MAX value
37835 +#endif /* __KERNEL__ */
37837 +/* ---------------------------------------------------------------------- */
37839 +#define AUFS_FSTYPE AUFS_NAME
37841 +#define AUFS_ROOT_INO 2
37842 +#define AUFS_FIRST_INO 11
37844 +#define AUFS_WH_PFX ".wh."
37845 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
37846 +#define AUFS_WH_TMP_LEN 4
37847 +/* a limit for rmdir/rename a dir and copyup */
37848 +#define AUFS_MAX_NAMELEN (NAME_MAX \
37849 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
37851 + - AUFS_WH_TMP_LEN) /* hex */
37852 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
37853 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
37854 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
37855 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
37856 +#define AUFS_DIRWH_DEF 3
37857 +#define AUFS_RDCACHE_DEF 10 /* seconds */
37858 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
37859 +#define AUFS_RDBLK_DEF 512 /* bytes */
37860 +#define AUFS_RDHASH_DEF 32
37861 +#define AUFS_WKQ_NAME AUFS_NAME "d"
37862 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
37863 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
37864 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
37865 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
37867 +/* pseudo-link maintenace under /proc */
37868 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
37869 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
37870 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
37872 +/* dirren, renamed dir */
37873 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
37874 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
37875 +/* whiteouted doubly */
37876 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
37877 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
37879 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
37880 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
37882 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
37883 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
37884 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
37886 +/* doubly whiteouted */
37887 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
37888 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
37889 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
37891 +/* branch permissions and attributes */
37892 +#define AUFS_BRPERM_RW "rw"
37893 +#define AUFS_BRPERM_RO "ro"
37894 +#define AUFS_BRPERM_RR "rr"
37895 +#define AUFS_BRATTR_COO_REG "coo_reg"
37896 +#define AUFS_BRATTR_COO_ALL "coo_all"
37897 +#define AUFS_BRATTR_FHSM "fhsm"
37898 +#define AUFS_BRATTR_UNPIN "unpin"
37899 +#define AUFS_BRATTR_ICEX "icex"
37900 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
37901 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
37902 +#define AUFS_BRATTR_ICEX_TR "icextr"
37903 +#define AUFS_BRATTR_ICEX_USR "icexusr"
37904 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
37905 +#define AUFS_BRRATTR_WH "wh"
37906 +#define AUFS_BRWATTR_NLWH "nolwh"
37907 +#define AUFS_BRWATTR_MOO "moo"
37909 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
37910 +#define AuBrPerm_RO (1 << 1) /* readonly */
37911 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
37912 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
37914 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
37915 +#define AuBrAttr_COO_ALL (1 << 4)
37916 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
37918 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
37919 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
37920 + branch. meaningless since
37921 + linux-3.18-rc1 */
37923 +/* ignore error in copying XATTR */
37924 +#define AuBrAttr_ICEX_SEC (1 << 7)
37925 +#define AuBrAttr_ICEX_SYS (1 << 8)
37926 +#define AuBrAttr_ICEX_TR (1 << 9)
37927 +#define AuBrAttr_ICEX_USR (1 << 10)
37928 +#define AuBrAttr_ICEX_OTH (1 << 11)
37929 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
37930 + | AuBrAttr_ICEX_SYS \
37931 + | AuBrAttr_ICEX_TR \
37932 + | AuBrAttr_ICEX_USR \
37933 + | AuBrAttr_ICEX_OTH)
37935 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
37936 +#define AuBrRAttr_Mask AuBrRAttr_WH
37938 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
37939 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
37940 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
37942 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
37944 +/* #warning test userspace */
37946 +#ifndef CONFIG_AUFS_FHSM
37947 +#undef AuBrAttr_FHSM
37948 +#define AuBrAttr_FHSM 0
37950 +#ifndef CONFIG_AUFS_XATTR
37951 +#undef AuBrAttr_ICEX
37952 +#define AuBrAttr_ICEX 0
37953 +#undef AuBrAttr_ICEX_SEC
37954 +#define AuBrAttr_ICEX_SEC 0
37955 +#undef AuBrAttr_ICEX_SYS
37956 +#define AuBrAttr_ICEX_SYS 0
37957 +#undef AuBrAttr_ICEX_TR
37958 +#define AuBrAttr_ICEX_TR 0
37959 +#undef AuBrAttr_ICEX_USR
37960 +#define AuBrAttr_ICEX_USR 0
37961 +#undef AuBrAttr_ICEX_OTH
37962 +#define AuBrAttr_ICEX_OTH 0
37966 +/* the longest combination */
37967 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
37968 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
37969 + "+" AUFS_BRATTR_COO_REG \
37970 + "+" AUFS_BRATTR_FHSM \
37971 + "+" AUFS_BRATTR_UNPIN \
37972 + "+" AUFS_BRATTR_ICEX_SEC \
37973 + "+" AUFS_BRATTR_ICEX_SYS \
37974 + "+" AUFS_BRATTR_ICEX_USR \
37975 + "+" AUFS_BRATTR_ICEX_OTH \
37976 + "+" AUFS_BRWATTR_NLWH)
37979 + char a[AuBrPermStrSz];
37980 +} au_br_perm_str_t;
37982 +static inline int au_br_writable(int brperm)
37984 + return brperm & AuBrPerm_RW;
37987 +static inline int au_br_whable(int brperm)
37989 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
37992 +static inline int au_br_wh_linkable(int brperm)
37994 + return !(brperm & AuBrWAttr_NoLinkWH);
37997 +static inline int au_br_cmoo(int brperm)
37999 + return brperm & AuBrAttr_CMOO_Mask;
38002 +static inline int au_br_fhsm(int brperm)
38004 + return brperm & AuBrAttr_FHSM;
38007 +/* ---------------------------------------------------------------------- */
38011 + /* readdir in userspace */
38015 + AuCtl_WBR_FD, /* pathconf wrapper */
38016 + AuCtl_IBUSY, /* busy inode */
38017 + AuCtl_MVDOWN, /* move-down */
38018 + AuCtl_BR, /* info about branches */
38019 + AuCtl_FHSM_FD /* connection for fhsm */
38022 +/* borrowed from linux/include/linux/kernel.h */
38024 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38025 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38028 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38030 +#define __aligned(x) __attribute__((aligned(x)))
38035 +#define __packed __attribute__((packed))
38039 +struct au_rdu_cookie {
38044 + uint32_t generation;
38047 +struct au_rdu_ent {
38056 +static inline int au_rdu_len(int nlen)
38058 + /* include the terminating NULL */
38059 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38060 + sizeof(uint64_t));
38063 +union au_rdu_ent_ul {
38064 + struct au_rdu_ent __user *e;
38076 + uint64_t sz; /* AuCtl_RDU */
38077 + uint64_t nent; /* AuCtl_RDU_INO */
38079 + union au_rdu_ent_ul ent;
38080 + uint16_t verify[AufsCtlRduV_End];
38082 + /* input/output */
38086 + union au_rdu_ent_ul tail;
38087 + /* number of entries which were added in a single call */
38092 + struct au_rdu_cookie cookie;
38095 +/* ---------------------------------------------------------------------- */
38097 +/* dirren. the branch is identified by the filename who contains this */
38098 +struct au_drinfo {
38101 + uint8_t oldnamelen;
38102 + uint64_t _padding;
38104 + uint8_t oldname[0];
38107 +struct au_drinfo_fdata {
38109 + struct au_drinfo drinfo;
38112 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38114 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38116 +/* ---------------------------------------------------------------------- */
38118 +struct aufs_wbr_fd {
38123 +/* ---------------------------------------------------------------------- */
38125 +struct aufs_ibusy {
38126 + uint64_t ino, h_ino;
38130 +/* ---------------------------------------------------------------------- */
38132 +/* error code for move-down */
38133 +/* the actual message strings are implemented in aufs-util.git */
38135 + EAU_MVDOWN_OPAQUE = 1,
38136 + EAU_MVDOWN_WHITEOUT,
38137 + EAU_MVDOWN_UPPER,
38138 + EAU_MVDOWN_BOTTOM,
38139 + EAU_MVDOWN_NOUPPER,
38140 + EAU_MVDOWN_NOLOWERBR,
38144 +/* flags for move-down */
38145 +#define AUFS_MVDOWN_DMSG 1
38146 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38147 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38148 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38149 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38150 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38151 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38152 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38153 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38154 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38155 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38156 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38157 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38159 +/* index for move-down */
38161 + AUFS_MVDOWN_UPPER,
38162 + AUFS_MVDOWN_LOWER,
38163 + AUFS_MVDOWN_NARRAY
38167 + * additional info of move-down
38168 + * number of free blocks and inodes.
38169 + * subset of struct kstatfs, but smaller and always 64bit.
38171 +struct aufs_stfs {
38172 + uint64_t f_blocks;
38173 + uint64_t f_bavail;
38174 + uint64_t f_files;
38175 + uint64_t f_ffree;
38178 +struct aufs_stbr {
38179 + int16_t brid; /* optional input */
38180 + int16_t bindex; /* output */
38181 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38184 +struct aufs_mvdown {
38185 + uint32_t flags; /* input/output */
38186 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38187 + int8_t au_errno; /* output */
38190 +/* ---------------------------------------------------------------------- */
38192 +union aufs_brinfo {
38193 + /* PATH_MAX may differ between kernel-space and user-space */
38194 + char _spacer[4096];
38202 +/* ---------------------------------------------------------------------- */
38204 +#define AuCtlType 'A'
38205 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38206 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38207 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38208 + struct aufs_wbr_fd)
38209 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38210 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38211 + struct aufs_mvdown)
38212 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
38213 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
38215 +#endif /* __AUFS_TYPE_H__ */
38216 aufs4.9 loopback patch
38218 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38219 index 6ee9235..f64161f 100644
38220 --- a/drivers/block/loop.c
38221 +++ b/drivers/block/loop.c
38222 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
38225 struct switch_request {
38226 - struct file *file;
38227 + struct file *file, *virt_file;
38228 struct completion wait;
38231 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
38232 mapping = file->f_mapping;
38233 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
38234 lo->lo_backing_file = file;
38235 + lo->lo_backing_virt_file = p->virt_file;
38236 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
38237 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
38238 lo->old_gfp_mask = mapping_gfp_mask(mapping);
38239 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
38240 * First it needs to flush existing IO, it does this by sending a magic
38241 * BIO down the pipe. The completion of this BIO does the actual switch.
38243 -static int loop_switch(struct loop_device *lo, struct file *file)
38244 +static int loop_switch(struct loop_device *lo, struct file *file,
38245 + struct file *virt_file)
38247 struct switch_request w;
38250 + w.virt_file = virt_file;
38252 /* freeze queue and wait for completion of scheduled requests */
38253 blk_mq_freeze_queue(lo->lo_queue);
38254 @@ -619,7 +619,16 @@ static int loop_flush(struct loop_device
38255 /* loop not yet configured, no running thread, nothing to flush */
38256 if (lo->lo_state != Lo_bound)
38258 - return loop_switch(lo, NULL);
38259 + return loop_switch(lo, NULL, NULL);
38262 +static struct file *loop_real_file(struct file *file)
38264 + struct file *f = NULL;
38266 + if (file->f_path.dentry->d_sb->s_op->real_loop)
38267 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
38271 static void loop_reread_partitions(struct loop_device *lo,
38272 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38275 struct file *file, *old_file;
38276 + struct file *f, *virt_file = NULL, *old_virt_file;
38277 struct inode *inode;
38280 @@ -665,13 +678,20 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38284 + f = loop_real_file(file);
38286 + virt_file = file;
38291 error = loop_validate_file(file, bdev);
38295 inode = file->f_mapping->host;
38296 old_file = lo->lo_backing_file;
38297 + old_virt_file = lo->lo_backing_virt_file;
38301 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38304 /* and ... switch */
38305 - error = loop_switch(lo, file);
38306 + error = loop_switch(lo, file, virt_file);
38311 + if (old_virt_file)
38312 + fput(old_virt_file);
38313 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
38314 loop_reread_partitions(lo, bdev);
38324 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
38325 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38326 struct block_device *bdev, unsigned int arg)
38328 - struct file *file;
38329 + struct file *file, *f, *virt_file = NULL;
38330 struct inode *inode;
38331 struct address_space *mapping;
38332 unsigned lo_blocksize;
38333 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38337 + f = loop_real_file(file);
38339 + virt_file = file;
38345 if (lo->lo_state != Lo_unbound)
38346 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38347 lo->lo_device = bdev;
38348 lo->lo_flags = lo_flags;
38349 lo->lo_backing_file = file;
38350 + lo->lo_backing_virt_file = virt_file;
38351 lo->transfer = NULL;
38353 lo->lo_sizelimit = 0;
38354 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38361 /* This is safe: open() is still holding a reference. */
38362 module_put(THIS_MODULE);
38363 @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
38364 static int loop_clr_fd(struct loop_device *lo)
38366 struct file *filp = lo->lo_backing_file;
38367 + struct file *virt_filp = lo->lo_backing_virt_file;
38368 gfp_t gfp = lo->old_gfp_mask;
38369 struct block_device *bdev = lo->lo_device;
38371 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
38372 spin_lock_irq(&lo->lo_lock);
38373 lo->lo_state = Lo_rundown;
38374 lo->lo_backing_file = NULL;
38375 + lo->lo_backing_virt_file = NULL;
38376 spin_unlock_irq(&lo->lo_lock);
38378 loop_release_xfer(lo);
38379 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
38380 * bd_mutex which is usually taken before lo_ctl_mutex.
38388 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
38389 index fb2237c..c3888c5 100644
38390 --- a/drivers/block/loop.h
38391 +++ b/drivers/block/loop.h
38392 @@ -46,7 +46,7 @@ struct loop_device {
38393 int (*ioctl)(struct loop_device *, int cmd,
38394 unsigned long arg);
38396 - struct file * lo_backing_file;
38397 + struct file * lo_backing_file, *lo_backing_virt_file;
38398 struct block_device *lo_device;
38399 unsigned lo_blocksize;
38401 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
38402 index 22e93ee..4586e8d 100644
38403 --- a/fs/aufs/f_op.c
38404 +++ b/fs/aufs/f_op.c
38405 @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
38406 if (IS_ERR(h_file))
38409 - if (au_test_loopback_kthread()) {
38410 + if (0 && au_test_loopback_kthread()) {
38411 au_warn_loopback(h_file->f_path.dentry->d_sb);
38412 if (file->f_mapping != h_file->f_mapping) {
38413 file->f_mapping = h_file->f_mapping;
38414 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
38415 index c1dbe59..1fc4b49 100644
38416 --- a/fs/aufs/loop.c
38417 +++ b/fs/aufs/loop.c
38418 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
38419 symbol_put(loop_backing_file);
38420 kfree(au_warn_loopback_array);
38423 +/* ---------------------------------------------------------------------- */
38425 +/* support the loopback block device insude aufs */
38427 +struct file *aufs_real_loop(struct file *file)
38431 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
38432 + fi_read_lock(file);
38433 + f = au_hf_top(file);
38434 + fi_read_unlock(file);
38438 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
38439 index c08374e..5e05083 100644
38440 --- a/fs/aufs/loop.h
38441 +++ b/fs/aufs/loop.h
38442 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
38444 int au_loopback_init(void);
38445 void au_loopback_fin(void);
38447 +struct file *aufs_real_loop(struct file *file);
38449 +AuStub(struct file *, loop_backing_file, return NULL)
38451 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
38452 struct dentry *h_adding)
38453 AuStubInt0(au_test_loopback_kthread, void)
38454 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
38456 AuStubInt0(au_loopback_init, void)
38457 AuStubVoid(au_loopback_fin, void)
38459 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
38460 #endif /* BLK_DEV_LOOP */
38462 #endif /* __KERNEL__ */
38463 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
38464 index dd38e63..2486242 100644
38465 --- a/fs/aufs/super.c
38466 +++ b/fs/aufs/super.c
38467 @@ -838,7 +838,10 @@ static const struct super_operations aufs_sop = {
38468 .statfs = aufs_statfs,
38469 .put_super = aufs_put_super,
38470 .sync_fs = aufs_sync_fs,
38471 - .remount_fs = aufs_remount_fs
38472 + .remount_fs = aufs_remount_fs,
38473 +#ifdef CONFIG_AUFS_BDEV_LOOP
38474 + .real_loop = aufs_real_loop
38478 /* ---------------------------------------------------------------------- */
38479 diff --git a/include/linux/fs.h b/include/linux/fs.h
38480 index 42c7695..3e4f068 100644
38481 --- a/include/linux/fs.h
38482 +++ b/include/linux/fs.h
38483 @@ -1823,6 +1823,10 @@ struct super_operations {
38484 struct shrink_control *);
38485 long (*free_cached_objects)(struct super_block *,
38486 struct shrink_control *);
38487 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
38489 + struct file *(*real_loop)(struct file *);