1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index bc821a8..7ae814c 100644
8 @@ -251,6 +251,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/exofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index c9375fd..8af5671 100644
20 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9c125f7..4616bbf 100644
32 @@ -2519,6 +2519,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: linux-unionfs@vger.kernel.org
39 +L: aufs-users@lists.sourceforge.net (members only)
40 +W: http://aufs.sourceforge.net
41 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/filesystems/aufs/
44 +F: Documentation/ABI/testing/debugfs-aufs
45 +F: Documentation/ABI/testing/sysfs-aufs
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
51 W: http://miguelojeda.es/auxdisplay.htm
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index 55cf554..bc965e5 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -713,6 +713,24 @@ static inline int is_loop_device(struct file *file)
57 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index 2acfc69..ff338e2 100644
85 @@ -1234,7 +1234,7 @@ enum d_walk_ret {
87 * The @enter() and @finish() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *),
92 void (*finish)(void *))
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index d737ff0..7550799 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file * filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index 3b55391..e0c5255 100644
120 @@ -1663,7 +1663,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec *time, int flags)
125 +int update_time(struct inode *inode, struct timespec *time, int flags)
127 int (*update_time)(struct inode *, struct timespec *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 5f75969..61129ff 100644
133 @@ -846,6 +846,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/read_write.c b/fs/read_write.c
147 index c4eabbf..ddd6e67 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -489,6 +489,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS);
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS);
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index 005d09c..f617ab0 100644
183 @@ -837,8 +837,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
185 * Attempt to initiate a splice from pipe to file.
187 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
188 - loff_t *ppos, size_t len, unsigned int flags)
189 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
190 + loff_t *ppos, size_t len, unsigned int flags)
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
193 loff_t *, size_t, unsigned int);
194 @@ -854,9 +854,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
198 -static long do_splice_to(struct file *in, loff_t *ppos,
199 - struct pipe_inode_info *pipe, size_t len,
200 - unsigned int flags)
201 +long do_splice_to(struct file *in, loff_t *ppos,
202 + struct pipe_inode_info *pipe, size_t len,
203 + unsigned int flags)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index b54e054..2860782 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/file.h b/include/linux/file.h
221 index 279720d..76e38ea 100644
222 --- a/include/linux/file.h
223 +++ b/include/linux/file.h
224 @@ -20,6 +20,7 @@ struct dentry;
226 extern struct file *alloc_file(const struct path *, fmode_t mode,
227 const struct file_operations *fop);
228 +extern struct file *get_empty_filp(void);
230 static inline void fput_light(struct file *file, int fput_needed)
232 diff --git a/include/linux/fs.h b/include/linux/fs.h
233 index 760d8da..09a2542 100644
234 --- a/include/linux/fs.h
235 +++ b/include/linux/fs.h
236 @@ -1270,6 +1270,7 @@ extern void fasync_free(struct fasync_struct *);
237 /* can be called from interrupts */
238 extern void kill_fasync(struct fasync_struct **, int, int);
240 +extern int setfl(int fd, struct file * filp, unsigned long arg);
241 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
242 extern int f_setown(struct file *filp, unsigned long arg, int force);
243 extern void f_delown(struct file *filp);
244 @@ -1724,6 +1725,7 @@ struct file_operations {
245 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
246 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
247 int (*check_flags)(int);
248 + int (*setfl)(struct file *, unsigned long);
249 int (*flock) (struct file *, int, struct file_lock *);
250 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
251 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
252 @@ -1794,6 +1796,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
253 struct iovec *fast_pointer,
254 struct iovec **ret_pointer);
256 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
257 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
259 +vfs_readf_t vfs_readf(struct file *file);
260 +vfs_writef_t vfs_writef(struct file *file);
262 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
263 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
264 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
265 @@ -2199,6 +2207,7 @@ extern int current_umask(void);
266 extern void ihold(struct inode * inode);
267 extern void iput(struct inode *);
268 extern int generic_update_time(struct inode *, struct timespec *, int);
269 +extern int update_time(struct inode *, struct timespec *, int);
272 extern struct kobject *fs_kobj;
273 @@ -2485,6 +2494,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
277 +extern int __sync_filesystem(struct super_block *, int);
278 extern int sync_filesystem(struct super_block *);
279 extern const struct file_operations def_blk_fops;
280 extern const struct file_operations def_chr_fops;
281 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
282 index 6fc77d4..27e76f0 100644
283 --- a/include/linux/lockdep.h
284 +++ b/include/linux/lockdep.h
285 @@ -313,6 +313,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
286 return lock->key == key;
289 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
294 @@ -439,6 +441,7 @@ struct lockdep_map { };
296 #define lockdep_depth(tsk) (0)
298 +#define lockdep_is_held(lock) (1)
299 #define lockdep_is_held_type(l, r) (1)
301 #define lockdep_assert_held(l) do { (void)(l); } while (0)
302 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
303 index 3594208..24f5fd1 100644
304 --- a/include/linux/mnt_namespace.h
305 +++ b/include/linux/mnt_namespace.h
307 struct mnt_namespace;
309 struct user_namespace;
312 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
313 struct user_namespace *, struct fs_struct *);
314 extern void put_mnt_ns(struct mnt_namespace *ns);
316 +extern int is_current_mnt_ns(struct vfsmount *mnt);
318 extern const struct file_operations proc_mounts_operations;
319 extern const struct file_operations proc_mountinfo_operations;
320 extern const struct file_operations proc_mountstats_operations;
321 diff --git a/include/linux/splice.h b/include/linux/splice.h
322 index 74b4911..19789fb 100644
323 --- a/include/linux/splice.h
324 +++ b/include/linux/splice.h
325 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
327 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
328 extern const struct pipe_buf_operations default_pipe_buf_ops;
330 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
331 + loff_t *ppos, size_t len, unsigned int flags);
332 +extern long do_splice_to(struct file *in, loff_t *ppos,
333 + struct pipe_inode_info *pipe, size_t len,
334 + unsigned int flags);
336 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
337 index 0233863..06e0d7a 100644
338 --- a/kernel/locking/lockdep.c
339 +++ b/kernel/locking/lockdep.c
340 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
341 unsigned long nr_lock_classes;
342 static struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
344 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
345 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
347 if (!hlock->class_idx) {
349 @@ -151,6 +151,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
351 return lock_classes + hlock->class_idx - 1;
353 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
355 #ifdef CONFIG_LOCK_STAT
356 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
357 SPDX-License-Identifier: GPL-2.0
360 diff --git a/fs/proc/base.c b/fs/proc/base.c
361 index 1a76d75..77f698e 100644
364 @@ -2024,7 +2024,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
365 down_read(&mm->mmap_sem);
366 vma = find_exact_vma(mm, vm_start, vm_end);
367 if (vma && vma->vm_file) {
368 - *path = vma->vm_file->f_path;
369 + *path = vma_pr_or_file(vma)->f_path;
373 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
374 index 7563437..7c0dc0f 100644
375 --- a/fs/proc/nommu.c
376 +++ b/fs/proc/nommu.c
377 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
378 file = region->vm_file;
381 - struct inode *inode = file_inode(region->vm_file);
382 + struct inode *inode;
384 + file = vmr_pr_or_file(region);
385 + inode = file_inode(file);
386 dev = inode->i_sb->s_dev;
389 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
390 index c486ad4..76b71f8 100644
391 --- a/fs/proc/task_mmu.c
392 +++ b/fs/proc/task_mmu.c
393 @@ -305,7 +305,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
394 const char *name = NULL;
397 - struct inode *inode = file_inode(vma->vm_file);
398 + struct inode *inode;
400 + file = vma_pr_or_file(vma);
401 + inode = file_inode(file);
402 dev = inode->i_sb->s_dev;
404 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
405 @@ -1726,7 +1729,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
406 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
407 struct vm_area_struct *vma = v;
408 struct numa_maps *md = &numa_priv->md;
409 - struct file *file = vma->vm_file;
410 + struct file *file = vma_pr_or_file(vma);
411 struct mm_struct *mm = vma->vm_mm;
412 struct mm_walk walk = {
413 .hugetlb_entry = gather_hugetlb_stats,
414 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
415 index 5b62f57..dfb4a3b 100644
416 --- a/fs/proc/task_nommu.c
417 +++ b/fs/proc/task_nommu.c
418 @@ -156,7 +156,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
422 - struct inode *inode = file_inode(vma->vm_file);
423 + struct inode *inode;
425 + file = vma_pr_or_file(vma);
426 + inode = file_inode(file);
427 dev = inode->i_sb->s_dev;
429 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
430 diff --git a/include/linux/mm.h b/include/linux/mm.h
431 index 02a616e..01b3bb9 100644
432 --- a/include/linux/mm.h
433 +++ b/include/linux/mm.h
434 @@ -1380,6 +1380,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
435 unmap_mapping_range(mapping, holebegin, holelen, 0);
438 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
439 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
441 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
442 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
444 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
446 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
448 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
449 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
452 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
453 +extern void vmr_do_fput(struct vm_region *, const char[], int);
455 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
457 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
458 +#endif /* !CONFIG_MMU */
460 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
461 void *buf, int len, unsigned int gup_flags);
462 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
463 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
464 index 2161234..78aa367 100644
465 --- a/include/linux/mm_types.h
466 +++ b/include/linux/mm_types.h
467 @@ -251,6 +251,7 @@ struct vm_region {
468 unsigned long vm_top; /* region allocated to here */
469 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
470 struct file *vm_file; /* the backing file or NULL */
471 + struct file *vm_prfile; /* the virtual backing file or NULL */
473 int vm_usage; /* region usage count (access under nommu_region_sem) */
474 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
475 @@ -325,6 +326,7 @@ struct vm_area_struct {
476 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
478 struct file * vm_file; /* File we map to (can be NULL). */
479 + struct file *vm_prfile; /* shadow of vm_file */
480 void * vm_private_data; /* was vm_pte (shared mem) */
482 atomic_long_t swap_readahead_info;
483 diff --git a/kernel/fork.c b/kernel/fork.c
484 index a5d21c4..e965e09 100644
487 @@ -473,7 +473,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
488 struct inode *inode = file_inode(file);
489 struct address_space *mapping = file->f_mapping;
493 if (tmp->vm_flags & VM_DENYWRITE)
494 atomic_dec(&inode->i_writecount);
495 i_mmap_lock_write(mapping);
496 diff --git a/mm/Makefile b/mm/Makefile
497 index b4e54a9a..77892ae 100644
500 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
501 mm_init.o mmu_context.o percpu.o slab_common.o \
502 compaction.o vmacache.o \
503 interval_tree.o list_lru.o workingset.o \
505 + prfile.o debug.o $(mmu-y)
509 diff --git a/mm/filemap.c b/mm/filemap.c
510 index 0604cb0..45d2369 100644
513 @@ -2700,7 +2700,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf)
514 int ret = VM_FAULT_LOCKED;
516 sb_start_pagefault(inode->i_sb);
517 - file_update_time(vmf->vma->vm_file);
518 + vma_file_update_time(vmf->vma);
520 if (page->mapping != inode->i_mapping) {
522 diff --git a/mm/mmap.c b/mm/mmap.c
523 index fc41c05..e376869 100644
526 @@ -180,7 +180,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
527 if (vma->vm_ops && vma->vm_ops->close)
528 vma->vm_ops->close(vma);
530 - fput(vma->vm_file);
532 mpol_put(vma_policy(vma));
533 kmem_cache_free(vm_area_cachep, vma);
535 @@ -905,7 +905,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
538 uprobe_munmap(next, next->vm_start, next->vm_end);
543 anon_vma_merge(vma, next);
544 @@ -1820,8 +1820,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
552 /* Undo any partial mapping done by a device driver. */
553 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
554 @@ -2645,7 +2645,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
558 - get_file(new->vm_file);
561 if (new->vm_ops && new->vm_ops->open)
562 new->vm_ops->open(new);
563 @@ -2664,7 +2664,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
564 if (new->vm_ops && new->vm_ops->close)
565 new->vm_ops->close(new);
567 - fput(new->vm_file);
569 unlink_anon_vmas(new);
571 mpol_put(vma_policy(new));
572 @@ -2826,7 +2826,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 struct vm_area_struct *vma;
574 unsigned long populate = 0;
575 unsigned long ret = -EINVAL;
577 + struct file *file, *prfile;
579 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
580 current->comm, current->pid);
581 @@ -2901,10 +2901,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
585 - file = get_file(vma->vm_file);
587 + file = vma->vm_file;
588 + prfile = vma->vm_prfile;
589 ret = do_mmap_pgoff(vma->vm_file, start, size,
590 prot, flags, pgoff, &populate, NULL);
591 + if (!IS_ERR_VALUE(ret) && file && prfile) {
592 + struct vm_area_struct *new_vma;
594 + new_vma = find_vma(mm, ret);
595 + if (!new_vma->vm_prfile)
596 + new_vma->vm_prfile = prfile;
597 + if (new_vma != vma)
601 + * two fput()s instead of vma_fput(vma),
602 + * coz vma may not be available anymore.
608 up_write(&mm->mmap_sem);
610 @@ -3220,7 +3237,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
611 if (anon_vma_clone(new_vma, vma))
612 goto out_free_mempol;
613 if (new_vma->vm_file)
614 - get_file(new_vma->vm_file);
615 + vma_get_file(new_vma);
616 if (new_vma->vm_ops && new_vma->vm_ops->open)
617 new_vma->vm_ops->open(new_vma);
618 vma_link(mm, new_vma, prev, rb_link, rb_parent);
619 diff --git a/mm/nommu.c b/mm/nommu.c
620 index 1372373..6362dde 100644
623 @@ -629,7 +629,7 @@ static void __put_nommu_region(struct vm_region *region)
624 up_write(&nommu_region_sem);
627 - fput(region->vm_file);
630 /* IO memory and memory shared directly out of the pagecache
631 * from ramfs/tmpfs mustn't be released here */
632 @@ -767,7 +767,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
633 if (vma->vm_ops && vma->vm_ops->close)
634 vma->vm_ops->close(vma);
636 - fput(vma->vm_file);
638 put_nommu_region(vma->vm_region);
639 kmem_cache_free(vm_area_cachep, vma);
641 @@ -1289,7 +1289,7 @@ unsigned long do_mmap(struct file *file,
642 goto error_just_free;
645 - fput(region->vm_file);
647 kmem_cache_free(vm_region_jar, region);
650 @@ -1364,10 +1364,10 @@ unsigned long do_mmap(struct file *file,
651 up_write(&nommu_region_sem);
654 - fput(region->vm_file);
656 kmem_cache_free(vm_region_jar, region);
658 - fput(vma->vm_file);
660 kmem_cache_free(vm_area_cachep, vma);
663 diff --git a/mm/prfile.c b/mm/prfile.c
665 index 0000000..37e95e1
669 +/* SPDX-License-Identifier: GPL-2.0 */
671 + * Mainly for aufs which mmap(2) different file and wants to print different
672 + * path in /proc/PID/maps.
673 + * Call these functions via macros defined in linux/mm.h.
675 + * See Documentation/filesystems/aufs/design/06mmap.txt
677 + * Copyright (c) 2014-2018 Junjro R. Okajima
678 + * Copyright (c) 2014 Ian Campbell
681 +#include <linux/mm.h>
682 +#include <linux/file.h>
683 +#include <linux/fs.h>
685 +/* #define PRFILE_TRACE */
686 +static inline void prfile_trace(struct file *f, struct file *pr,
687 + const char func[], int line, const char func2[])
691 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
695 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
698 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
700 + prfile_trace(f, pr, func, line, __func__);
701 + file_update_time(f);
703 + file_update_time(pr);
706 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
709 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
711 + prfile_trace(f, pr, func, line, __func__);
712 + return (f && pr) ? pr : f;
715 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
717 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
719 + prfile_trace(f, pr, func, line, __func__);
725 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
727 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
736 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
739 + struct file *f = region->vm_file, *pr = region->vm_prfile;
741 + prfile_trace(f, pr, func, line, __func__);
742 + return (f && pr) ? pr : f;
745 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
747 + struct file *f = region->vm_file, *pr = region->vm_prfile;
749 + prfile_trace(f, pr, func, line, __func__);
754 +#endif /* !CONFIG_MMU */
755 SPDX-License-Identifier: GPL-2.0
756 aufs4.17 standalone patch
758 diff --git a/fs/dcache.c b/fs/dcache.c
759 index ff338e2..3e2bae8 100644
762 @@ -1342,6 +1342,7 @@ void d_walk(struct dentry *parent, void *data,
766 +EXPORT_SYMBOL_GPL(d_walk);
769 struct vfsmount *mnt;
770 @@ -2942,6 +2943,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
772 write_sequnlock(&rename_lock);
774 +EXPORT_SYMBOL_GPL(d_exchange);
777 * d_ancestor - search for an ancestor
778 diff --git a/fs/exec.c b/fs/exec.c
779 index 183059c..35adee4 100644
782 @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path)
783 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
784 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
786 +EXPORT_SYMBOL_GPL(path_noexec);
790 diff --git a/fs/fcntl.c b/fs/fcntl.c
791 index 7550799..d403576 100644
794 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
798 +EXPORT_SYMBOL_GPL(setfl);
800 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
802 diff --git a/fs/file_table.c b/fs/file_table.c
803 index 7ec0b3e..819ee07 100644
804 --- a/fs/file_table.c
805 +++ b/fs/file_table.c
806 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
808 return ERR_PTR(-ENFILE);
810 +EXPORT_SYMBOL_GPL(get_empty_filp);
813 * alloc_file - allocate and initialize a 'struct file'
814 @@ -257,6 +258,7 @@ void flush_delayed_fput(void)
818 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
820 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
822 @@ -299,6 +301,7 @@ void __fput_sync(struct file *file)
826 +EXPORT_SYMBOL_GPL(__fput_sync);
828 void put_filp(struct file *file)
830 @@ -307,6 +310,7 @@ void put_filp(struct file *file)
834 +EXPORT_SYMBOL_GPL(put_filp);
836 void __init files_init(void)
838 diff --git a/fs/inode.c b/fs/inode.c
839 index e0c5255..ff36056 100644
842 @@ -1672,6 +1672,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
844 return update_time(inode, time, flags);
846 +EXPORT_SYMBOL_GPL(update_time);
849 * touch_atime - update the access time
850 diff --git a/fs/namespace.c b/fs/namespace.c
851 index 61129ff..5d3e0382 100644
854 @@ -517,6 +517,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
855 mnt_dec_writers(real_mount(mnt));
858 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
861 * mnt_drop_write - give up write access to a mount
862 @@ -851,6 +852,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
864 return check_mnt(real_mount(mnt));
866 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
869 * vfsmount lock must be held for write
870 @@ -1893,6 +1895,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
874 +EXPORT_SYMBOL_GPL(iterate_mounts);
876 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
878 diff --git a/fs/notify/group.c b/fs/notify/group.c
879 index b7a4b6a..5a69d60 100644
880 --- a/fs/notify/group.c
881 +++ b/fs/notify/group.c
883 #include <linux/srcu.h>
884 #include <linux/rculist.h>
885 #include <linux/wait.h>
886 +#include <linux/module.h>
888 #include <linux/fsnotify_backend.h>
889 #include "fsnotify.h"
890 @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
892 refcount_inc(&group->refcnt);
894 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
897 * Drop a reference to a group. Free it if it's through.
898 @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
899 if (refcount_dec_and_test(&group->refcnt))
900 fsnotify_final_destroy_group(group);
902 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
905 * Create a new fsnotify_group and hold a reference for the group returned.
906 @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
910 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
912 int fsnotify_fasync(int fd, struct file *file, int on)
914 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
915 index e9191b4..1f8ccfa 100644
916 --- a/fs/notify/mark.c
917 +++ b/fs/notify/mark.c
918 @@ -108,6 +108,7 @@ void fsnotify_get_mark(struct fsnotify_mark *mark)
919 WARN_ON_ONCE(!refcount_read(&mark->refcnt));
920 refcount_inc(&mark->refcnt);
922 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
924 static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
926 @@ -392,6 +393,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
927 mutex_unlock(&group->mark_mutex);
928 fsnotify_free_mark(mark);
930 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
933 * Sorting function for lists of fsnotify marks.
934 @@ -606,6 +608,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
935 fsnotify_put_mark(mark);
938 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
940 int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
941 struct vfsmount *mnt, int allow_dups)
942 @@ -741,6 +744,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
943 fsnotify_get_group(group);
946 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
949 * Destroy all marks in destroy_list, waits for SRCU period to finish before
950 diff --git a/fs/open.c b/fs/open.c
951 index d0e955b..527bc1a 100644
954 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
955 inode_unlock(dentry->d_inode);
958 +EXPORT_SYMBOL_GPL(do_truncate);
960 long vfs_truncate(const struct path *path, loff_t length)
962 @@ -723,6 +724,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
964 return ksys_fchown(fd, user, group);
966 +EXPORT_SYMBOL_GPL(open_check_o_direct);
968 int open_check_o_direct(struct file *f)
970 diff --git a/fs/read_write.c b/fs/read_write.c
971 index ddd6e67..aabf92d 100644
972 --- a/fs/read_write.c
973 +++ b/fs/read_write.c
974 @@ -459,6 +459,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
978 +EXPORT_SYMBOL_GPL(vfs_read);
980 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
982 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
983 return new_sync_read;
984 return ERR_PTR(-ENOSYS);
986 +EXPORT_SYMBOL_GPL(vfs_readf);
988 vfs_writef_t vfs_writef(struct file *file)
990 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
991 return new_sync_write;
992 return ERR_PTR(-ENOSYS);
994 +EXPORT_SYMBOL_GPL(vfs_writef);
996 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
998 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
1002 +EXPORT_SYMBOL_GPL(vfs_write);
1004 static inline loff_t file_pos_read(struct file *file)
1006 diff --git a/fs/splice.c b/fs/splice.c
1007 index f617ab0..ec0ad02 100644
1010 @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
1012 return splice_write(pipe, out, ppos, len, flags);
1014 +EXPORT_SYMBOL_GPL(do_splice_from);
1017 * Attempt to initiate a splice from a file to a pipe.
1018 @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
1020 return splice_read(in, ppos, pipe, len, flags);
1022 +EXPORT_SYMBOL_GPL(do_splice_to);
1025 * splice_direct_to_actor - splices data directly between two non-pipes
1026 diff --git a/fs/sync.c b/fs/sync.c
1027 index 2860782..ffd7ea4 100644
1030 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
1031 sb->s_op->sync_fs(sb, wait);
1032 return __sync_blockdev(sb->s_bdev, wait);
1034 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1037 * Write out and wait upon all dirty data associated with this
1038 diff --git a/fs/xattr.c b/fs/xattr.c
1039 index 61cd28b..35570cd 100644
1042 @@ -297,6 +297,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1043 *xattr_value = value;
1046 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1049 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1050 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1051 index 06e0d7a..6af91bd 100644
1052 --- a/kernel/locking/lockdep.c
1053 +++ b/kernel/locking/lockdep.c
1054 @@ -151,6 +151,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1056 return lock_classes + hlock->class_idx - 1;
1058 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1059 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1061 #ifdef CONFIG_LOCK_STAT
1062 diff --git a/kernel/task_work.c b/kernel/task_work.c
1063 index 0fef395..83fb1ec 100644
1064 --- a/kernel/task_work.c
1065 +++ b/kernel/task_work.c
1066 @@ -116,3 +116,4 @@ void task_work_run(void)
1070 +EXPORT_SYMBOL_GPL(task_work_run);
1071 diff --git a/security/commoncap.c b/security/commoncap.c
1072 index 1ce701f..a0d106e 100644
1073 --- a/security/commoncap.c
1074 +++ b/security/commoncap.c
1075 @@ -1332,12 +1332,14 @@ int cap_mmap_addr(unsigned long addr)
1079 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
1081 int cap_mmap_file(struct file *file, unsigned long reqprot,
1082 unsigned long prot, unsigned long flags)
1086 +EXPORT_SYMBOL_GPL(cap_mmap_file);
1088 #ifdef CONFIG_SECURITY
1090 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1091 index c65b39b..e363d22 100644
1092 --- a/security/device_cgroup.c
1093 +++ b/security/device_cgroup.c
1095 #include <linux/device_cgroup.h>
1096 #include <linux/cgroup.h>
1097 #include <linux/ctype.h>
1098 +#include <linux/export.h>
1099 #include <linux/list.h>
1100 #include <linux/uaccess.h>
1101 #include <linux/seq_file.h>
1102 @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1106 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1107 diff --git a/security/security.c b/security/security.c
1108 index 7bc2fde..6bd0468 100644
1109 --- a/security/security.c
1110 +++ b/security/security.c
1111 @@ -537,6 +537,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1113 return call_int_hook(path_rmdir, 0, dir, dentry);
1115 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1117 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1119 @@ -553,6 +554,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1121 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1123 +EXPORT_SYMBOL_GPL(security_path_symlink);
1125 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1126 struct dentry *new_dentry)
1127 @@ -561,6 +563,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1129 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1131 +EXPORT_SYMBOL_GPL(security_path_link);
1133 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1134 const struct path *new_dir, struct dentry *new_dentry,
1135 @@ -588,6 +591,7 @@ int security_path_truncate(const struct path *path)
1137 return call_int_hook(path_truncate, 0, path);
1139 +EXPORT_SYMBOL_GPL(security_path_truncate);
1141 int security_path_chmod(const struct path *path, umode_t mode)
1143 @@ -595,6 +599,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1145 return call_int_hook(path_chmod, 0, path, mode);
1147 +EXPORT_SYMBOL_GPL(security_path_chmod);
1149 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1151 @@ -602,6 +607,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1153 return call_int_hook(path_chown, 0, path, uid, gid);
1155 +EXPORT_SYMBOL_GPL(security_path_chown);
1157 int security_path_chroot(const struct path *path)
1159 @@ -687,6 +693,7 @@ int security_inode_readlink(struct dentry *dentry)
1161 return call_int_hook(inode_readlink, 0, dentry);
1163 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1165 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1167 @@ -702,6 +709,7 @@ int security_inode_permission(struct inode *inode, int mask)
1169 return call_int_hook(inode_permission, 0, inode, mask);
1171 +EXPORT_SYMBOL_GPL(security_inode_permission);
1173 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1175 @@ -873,6 +881,7 @@ int security_file_permission(struct file *file, int mask)
1177 return fsnotify_perm(file, mask);
1179 +EXPORT_SYMBOL_GPL(security_file_permission);
1181 int security_file_alloc(struct file *file)
1183 @@ -932,6 +941,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1185 return ima_file_mmap(file, prot);
1187 +EXPORT_SYMBOL_GPL(security_mmap_file);
1189 int security_mmap_addr(unsigned long addr)
1191 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1192 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1193 +++ linux/Documentation/ABI/testing/debugfs-aufs 2018-07-19 09:46:13.053314374 +0200
1195 +What: /debug/aufs/si_<id>/
1197 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1199 + Under /debug/aufs, a directory named si_<id> is created
1200 + per aufs mount, where <id> is a unique id generated
1203 +What: /debug/aufs/si_<id>/plink
1205 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1207 + It has three lines and shows the information about the
1208 + pseudo-link. The first line is a single number
1209 + representing a number of buckets. The second line is a
1210 + number of pseudo-links per buckets (separated by a
1211 + blank). The last line is a single number representing a
1212 + total number of psedo-links.
1213 + When the aufs mount option 'noplink' is specified, it
1214 + will show "1\n0\n0\n".
1216 +What: /debug/aufs/si_<id>/xib
1218 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1220 + It shows the consumed blocks by xib (External Inode Number
1221 + Bitmap), its block size and file size.
1222 + When the aufs mount option 'noxino' is specified, it
1223 + will be empty. About XINO files, see the aufs manual.
1225 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1227 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1229 + It shows the consumed blocks by xino (External Inode Number
1230 + Translation Table), its link count, block size and file
1232 + Due to the file size limit, there may exist multiple
1233 + xino files per branch. In this case, "-N" is added to
1234 + the filename and it corresponds to the index of the
1235 + internal xino array. "-0" is omitted.
1236 + When the aufs mount option 'noxino' is specified, Those
1237 + entries won't exist. About XINO files, see the aufs
1240 +What: /debug/aufs/si_<id>/xigen
1242 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1244 + It shows the consumed blocks by xigen (External Inode
1245 + Generation Table), its block size and file size.
1246 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1248 + When the aufs mount option 'noxino' is specified, it
1249 + will be empty. About XINO files, see the aufs manual.
1250 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1251 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1252 +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-07-29 12:14:25.893041746 +0200
1254 +What: /sys/fs/aufs/si_<id>/
1256 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1258 + Under /sys/fs/aufs, a directory named si_<id> is created
1259 + per aufs mount, where <id> is a unique id generated
1262 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1264 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1266 + It shows the abolute path of a member directory (which
1267 + is called branch) in aufs, and its permission.
1269 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1271 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1273 + It shows the id of a member directory (which is called
1276 +What: /sys/fs/aufs/si_<id>/xi_path
1278 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1280 + It shows the abolute path of XINO (External Inode Number
1281 + Bitmap, Translation Table and Generation Table) file
1282 + even if it is the default path.
1283 + When the aufs mount option 'noxino' is specified, it
1284 + will be empty. About XINO files, see the aufs manual.
1285 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1286 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1287 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-04-15 08:49:13.394483860 +0200
1290 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1292 +# This program is free software; you can redistribute it and/or modify
1293 +# it under the terms of the GNU General Public License as published by
1294 +# the Free Software Foundation; either version 2 of the License, or
1295 +# (at your option) any later version.
1297 +# This program is distributed in the hope that it will be useful,
1298 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1299 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1300 +# GNU General Public License for more details.
1302 +# You should have received a copy of the GNU General Public License
1303 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1306 +----------------------------------------
1308 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1309 +1. abbrev. for "advanced multi-layered unification filesystem".
1310 +2. abbrev. for "another unionfs".
1311 +3. abbrev. for "auf das" in German which means "on the" in English.
1312 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1313 + But "Filesystem aufs Filesystem" is hard to understand.
1314 +4. abbrev. for "African Urban Fashion Show".
1316 +AUFS is a filesystem with features:
1317 +- multi layered stackable unification filesystem, the member directory
1318 + is called as a branch.
1319 +- branch permission and attribute, 'readonly', 'real-readonly',
1320 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1322 +- internal "file copy-on-write".
1323 +- logical deletion, whiteout.
1324 +- dynamic branch manipulation, adding, deleting and changing permission.
1325 +- allow bypassing aufs, user's direct branch access.
1326 +- external inode number translation table and bitmap which maintains the
1327 + persistent aufs inode number.
1328 +- seekable directory, including NFS readdir.
1329 +- file mapping, mmap and sharing pages.
1330 +- pseudo-link, hardlink over branches.
1331 +- loopback mounted filesystem as a branch.
1332 +- several policies to select one among multiple writable branches.
1333 +- revert a single systemcall when an error occurs in aufs.
1337 +Multi Layered Stackable Unification Filesystem
1338 +----------------------------------------------------------------------
1339 +Most people already knows what it is.
1340 +It is a filesystem which unifies several directories and provides a
1341 +merged single directory. When users access a file, the access will be
1342 +passed/re-directed/converted (sorry, I am not sure which English word is
1343 +correct) to the real file on the member filesystem. The member
1344 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1345 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1346 +readonly branch is handled by creating 'whiteout' on the upper writable
1349 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1350 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1351 +different approaches to implement the merged-view.
1352 +The former tries putting it into VFS, and the latter implements as a
1353 +separate filesystem.
1354 +(If I misunderstand about these implementations, please let me know and
1355 +I shall correct it. Because it is a long time ago when I read their
1356 +source files last time).
1358 +UnionMount's approach will be able to small, but may be hard to share
1359 +branches between several UnionMount since the whiteout in it is
1360 +implemented in the inode on branch filesystem and always
1361 +shared. According to Bharata's post, readdir does not seems to be
1363 +There are several missing features known in this implementations such as
1364 +- for users, the inode number may change silently. eg. copy-up.
1365 +- link(2) may break by copy-up.
1366 +- read(2) may get an obsoleted filedata (fstat(2) too).
1367 +- fcntl(F_SETLK) may be broken by copy-up.
1368 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1371 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1372 +merged into mainline. This is another implementation of UnionMount as a
1373 +separated filesystem. All the limitations and known problems which
1374 +UnionMount are equally inherited to "overlay" filesystem.
1376 +Unionfs has a longer history. When I started implementing a stackable
1377 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1378 +inode, dentry and file objects and they have an array pointing lower
1379 +same kind objects. After contributing many patches for Unionfs, I
1380 +re-started my project AUFS (Jun 2006).
1382 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1383 +implemented my own ideas, approaches and enhancements and it became
1384 +totally different one.
1386 +Comparing DM snapshot and fs based implementation
1387 +- the number of bytes to be copied between devices is much smaller.
1388 +- the type of filesystem must be one and only.
1389 +- the fs must be writable, no readonly fs, even for the lower original
1390 + device. so the compression fs will not be usable. but if we use
1391 + loopback mount, we may address this issue.
1393 + mount /cdrom/squashfs.img /sq
1394 + losetup /sq/ext2.img
1395 + losetup /somewhere/cow
1396 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1397 +- it will be difficult (or needs more operations) to extract the
1398 + difference between the original device and COW.
1399 +- DM snapshot-merge may help a lot when users try merging. in the
1400 + fs-layer union, users will use rsync(1).
1402 +You may want to read my old paper "Filesystems in LiveCD"
1403 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1406 +Several characters/aspects/persona of aufs
1407 +----------------------------------------------------------------------
1409 +Aufs has several characters, aspects or persona.
1410 +1. a filesystem, callee of VFS helper
1411 +2. sub-VFS, caller of VFS helper for branches
1412 +3. a virtual filesystem which maintains persistent inode number
1413 +4. reader/writer of files on branches such like an application
1415 +1. Callee of VFS Helper
1416 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1417 +unlink(2) from an application reaches sys_unlink() kernel function and
1418 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1419 +calls filesystem specific unlink operation. Actually aufs implements the
1420 +unlink operation but it behaves like a redirector.
1422 +2. Caller of VFS Helper for Branches
1423 +aufs_unlink() passes the unlink request to the branch filesystem as if
1424 +it were called from VFS. So the called unlink operation of the branch
1425 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1426 +every necessary pre/post operation for the branch filesystem.
1427 +- acquire the lock for the parent dir on a branch
1428 +- lookup in a branch
1429 +- revalidate dentry on a branch
1430 +- mnt_want_write() for a branch
1431 +- vfs_unlink() for a branch
1432 +- mnt_drop_write() for a branch
1433 +- release the lock on a branch
1435 +3. Persistent Inode Number
1436 +One of the most important issue for a filesystem is to maintain inode
1437 +numbers. This is particularly important to support exporting a
1438 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1439 +backend block device for its own. But some storage is necessary to
1440 +keep and maintain the inode numbers. It may be a large space and may not
1441 +suit to keep in memory. Aufs rents some space from its first writable
1442 +branch filesystem (by default) and creates file(s) on it. These files
1443 +are created by aufs internally and removed soon (currently) keeping
1445 +Note: Because these files are removed, they are totally gone after
1446 + unmounting aufs. It means the inode numbers are not persistent
1447 + across unmount or reboot. I have a plan to make them really
1448 + persistent which will be important for aufs on NFS server.
1450 +4. Read/Write Files Internally (copy-on-write)
1451 +Because a branch can be readonly, when you write a file on it, aufs will
1452 +"copy-up" it to the upper writable branch internally. And then write the
1453 +originally requested thing to the file. Generally kernel doesn't
1454 +open/read/write file actively. In aufs, even a single write may cause a
1455 +internal "file copy". This behaviour is very similar to cp(1) command.
1457 +Some people may think it is better to pass such work to user space
1458 +helper, instead of doing in kernel space. Actually I am still thinking
1459 +about it. But currently I have implemented it in kernel space.
1460 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1461 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1462 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-04-15 08:49:13.394483860 +0200
1465 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1467 +# This program is free software; you can redistribute it and/or modify
1468 +# it under the terms of the GNU General Public License as published by
1469 +# the Free Software Foundation; either version 2 of the License, or
1470 +# (at your option) any later version.
1472 +# This program is distributed in the hope that it will be useful,
1473 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1474 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1475 +# GNU General Public License for more details.
1477 +# You should have received a copy of the GNU General Public License
1478 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1480 +Basic Aufs Internal Structure
1482 +Superblock/Inode/Dentry/File Objects
1483 +----------------------------------------------------------------------
1484 +As like an ordinary filesystem, aufs has its own
1485 +superblock/inode/dentry/file objects. All these objects have a
1486 +dynamically allocated array and store the same kind of pointers to the
1487 +lower filesystem, branch.
1488 +For example, when you build a union with one readwrite branch and one
1489 +readonly, mounted /au, /rw and /ro respectively.
1491 +- /ro/fileA exists but /rw/fileA
1493 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1494 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1495 +- [0] = NULL (because /rw/fileA doesn't exist)
1498 +This style of an array is essentially same to the aufs
1499 +superblock/inode/dentry/file objects.
1501 +Because aufs supports manipulating branches, ie. add/delete/change
1502 +branches dynamically, these objects has its own generation. When
1503 +branches are changed, the generation in aufs superblock is
1504 +incremented. And a generation in other object are compared when it is
1505 +accessed. When a generation in other objects are obsoleted, aufs
1506 +refreshes the internal array.
1510 +----------------------------------------------------------------------
1511 +Additionally aufs superblock has some data for policies to select one
1512 +among multiple writable branches, XIB files, pseudo-links and kobject.
1513 +See below in detail.
1514 +About the policies which supports copy-down a directory, see
1515 +wbr_policy.txt too.
1518 +Branch and XINO(External Inode Number Translation Table)
1519 +----------------------------------------------------------------------
1520 +Every branch has its own xino (external inode number translation table)
1521 +file. The xino file is created and unlinked by aufs internally. When two
1522 +members of a union exist on the same filesystem, they share the single
1524 +The struct of a xino file is simple, just a sequence of aufs inode
1525 +numbers which is indexed by the lower inode number.
1526 +In the above sample, assume the inode number of /ro/fileA is i111 and
1527 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1528 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1530 +When the inode numbers are not contiguous, the xino file will be sparse
1531 +which has a hole in it and doesn't consume as much disk space as it
1532 +might appear. If your branch filesystem consumes disk space for such
1533 +holes, then you should specify 'xino=' option at mounting aufs.
1535 +Aufs has a mount option to free the disk blocks for such holes in XINO
1536 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1537 +meet a problem of disk shortage due to XINO files, then you should try
1538 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1539 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1540 +the holes in XINO files.
1542 +Also a writable branch has three kinds of "whiteout bases". All these
1543 +are existed when the branch is joined to aufs, and their names are
1544 +whiteout-ed doubly, so that users will never see their names in aufs
1546 +1. a regular file which will be hardlinked to all whiteouts.
1547 +2. a directory to store a pseudo-link.
1548 +3. a directory to store an "orphan"-ed file temporary.
1551 + When you remove a file on a readonly branch, aufs handles it as a
1552 + logical deletion and creates a whiteout on the upper writable branch
1553 + as a hardlink of this file in order not to consume inode on the
1556 + See below, Pseudo-link.
1558 + When "fileC" exists on the lower readonly branch only and it is
1559 + opened and removed with its parent dir, and then user writes
1560 + something into it, then aufs copies-up fileC to this
1561 + directory. Because there is no other dir to store fileC. After
1562 + creating a file under this dir, the file is unlinked.
1564 +Because aufs supports manipulating branches, ie. add/delete/change
1565 +dynamically, a branch has its own id. When the branch order changes,
1566 +aufs finds the new index by searching the branch id.
1570 +----------------------------------------------------------------------
1571 +Assume "fileA" exists on the lower readonly branch only and it is
1572 +hardlinked to "fileB" on the branch. When you write something to fileA,
1573 +aufs copies-up it to the upper writable branch. Additionally aufs
1574 +creates a hardlink under the Pseudo-link Directory of the writable
1575 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1576 +simple list. If fileB is read after unlinking fileA, aufs returns
1577 +filedata from the pseudo-link instead of the lower readonly
1578 +branch. Because the pseudo-link is based upon the inode, to keep the
1579 +inode number by xino (see above) is essentially necessary.
1581 +All the hardlinks under the Pseudo-link Directory of the writable branch
1582 +should be restored in a proper location later. Aufs provides a utility
1583 +to do this. The userspace helpers executed at remounting and unmounting
1585 +During this utility is running, it puts aufs into the pseudo-link
1586 +maintenance mode. In this mode, only the process which began the
1587 +maintenance mode (and its child processes) is allowed to operate in
1588 +aufs. Some other processes which are not related to the pseudo-link will
1589 +be allowed to run too, but the rest have to return an error or wait
1590 +until the maintenance mode ends. If a process already acquires an inode
1591 +mutex (in VFS), it has to return an error.
1594 +XIB(external inode number bitmap)
1595 +----------------------------------------------------------------------
1596 +Addition to the xino file per a branch, aufs has an external inode number
1597 +bitmap in a superblock object. It is also an internal file such like a
1599 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1601 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1603 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1604 +reduce the number of consumed disk blocks for these files.
1607 +Virtual or Vertical Dir, and Readdir in Userspace
1608 +----------------------------------------------------------------------
1609 +In order to support multiple layers (branches), aufs readdir operation
1610 +constructs a virtual dir block on memory. For readdir, aufs calls
1611 +vfs_readdir() internally for each dir on branches, merges their entries
1612 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1613 +object. So the file object has its entry list until it is closed. The
1614 +entry list will be updated when the file position is zero and becomes
1615 +obsoleted. This decision is made in aufs automatically.
1617 +The dynamically allocated memory block for the name of entries has a
1618 +unit of 512 bytes (by default) and stores the names contiguously (no
1619 +padding). Another block for each entry is handled by kmem_cache too.
1620 +During building dir blocks, aufs creates hash list and judging whether
1621 +the entry is whiteouted by its upper branch or already listed.
1622 +The merged result is cached in the corresponding inode object and
1623 +maintained by a customizable life-time option.
1625 +Some people may call it can be a security hole or invite DoS attack
1626 +since the opened and once readdir-ed dir (file object) holds its entry
1627 +list and becomes a pressure for system memory. But I'd say it is similar
1628 +to files under /proc or /sys. The virtual files in them also holds a
1629 +memory page (generally) while they are opened. When an idea to reduce
1630 +memory for them is introduced, it will be applied to aufs too.
1631 +For those who really hate this situation, I've developed readdir(3)
1632 +library which operates this merging in userspace. You just need to set
1633 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1634 +kernel space for readdir(3).
1638 +----------------------------------------------------------------------
1639 +Aufs sometimes requires privilege access to a branch. For instance,
1640 +in copy-up/down operation. When a user process is going to make changes
1641 +to a file which exists in the lower readonly branch only, and the mode
1642 +of one of ancestor directories may not be writable by a user
1643 +process. Here aufs copy-up the file with its ancestors and they may
1644 +require privilege to set its owner/group/mode/etc.
1645 +This is a typical case of a application character of aufs (see
1648 +Aufs uses workqueue synchronously for this case. It creates its own
1649 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1650 +passes the request to call mkdir or write (for example), and wait for
1651 +its completion. This approach solves a problem of a signal handler
1653 +If aufs didn't adopt the workqueue and changed the privilege of the
1654 +process, then the process may receive the unexpected SIGXFSZ or other
1657 +Also aufs uses the system global workqueue ("events" kernel thread) too
1658 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1659 +whiteout base and etc. This is unrelated to a privilege.
1660 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1661 +superblock at the beginning, at the same time waits for the completion
1662 +of all queued asynchronous tasks.
1666 +----------------------------------------------------------------------
1667 +The whiteout in aufs is very similar to Unionfs's. That is represented
1668 +by its filename. UnionMount takes an approach of a file mode, but I am
1669 +afraid several utilities (find(1) or something) will have to support it.
1671 +Basically the whiteout represents "logical deletion" which stops aufs to
1672 +lookup further, but also it represents "dir is opaque" which also stop
1675 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1676 +In order to make several functions in a single systemcall to be
1677 +revertible, aufs adopts an approach to rename a directory to a temporary
1678 +unique whiteouted name.
1679 +For example, in rename(2) dir where the target dir already existed, aufs
1680 +renames the target dir to a temporary unique whiteouted name before the
1681 +actual rename on a branch, and then handles other actions (make it opaque,
1682 +update the attributes, etc). If an error happens in these actions, aufs
1683 +simply renames the whiteouted name back and returns an error. If all are
1684 +succeeded, aufs registers a function to remove the whiteouted unique
1685 +temporary name completely and asynchronously to the system global
1690 +----------------------------------------------------------------------
1691 +It is a well-known feature or concept.
1692 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1693 +internally and makes change to the new file on the upper writable branch.
1694 +When the trigger systemcall does not update the timestamps of the parent
1695 +dir, aufs reverts it after copy-up.
1698 +Move-down (aufs3.9 and later)
1699 +----------------------------------------------------------------------
1700 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1701 +the lower readonly branch to the upper writable branch when a user
1702 +changes something about the file.
1703 +"Move-down" is an opposite action of copy-up. Basically this action is
1704 +ran manually instead of automatically and internally.
1705 +For desgin and implementation, aufs has to consider these issues.
1706 +- whiteout for the file may exist on the lower branch.
1707 +- ancestor directories may not exist on the lower branch.
1708 +- diropq for the ancestor directories may exist on the upper branch.
1709 +- free space on the lower branch will reduce.
1710 +- another access to the file may happen during moving-down, including
1711 + UDBA (see "Revalidate Dentry and UDBA").
1712 +- the file should not be hard-linked nor pseudo-linked. they should be
1713 + handled by auplink utility later.
1715 +Sometimes users want to move-down a file from the upper writable branch
1716 +to the lower readonly or writable branch. For instance,
1717 +- the free space of the upper writable branch is going to run out.
1718 +- create a new intermediate branch between the upper and lower branch.
1721 +For this purpose, use "aumvdown" command in aufs-util.git.
1722 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1723 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1724 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-04-15 08:49:13.394483860 +0200
1727 +# Copyright (C) 2015-2018 Junjiro R. Okajima
1729 +# This program is free software; you can redistribute it and/or modify
1730 +# it under the terms of the GNU General Public License as published by
1731 +# the Free Software Foundation; either version 2 of the License, or
1732 +# (at your option) any later version.
1734 +# This program is distributed in the hope that it will be useful,
1735 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1736 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1737 +# GNU General Public License for more details.
1739 +# You should have received a copy of the GNU General Public License
1740 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1742 +Support for a branch who has its ->atomic_open()
1743 +----------------------------------------------------------------------
1744 +The filesystems who implement its ->atomic_open() are not majority. For
1745 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1746 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1747 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1748 +sure whether all filesystems who have ->atomic_open() behave like this,
1749 +but NFSv4 surely returns the error.
1751 +In order to support ->atomic_open() for aufs, there are a few
1754 +A. Introduce aufs_atomic_open()
1755 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1757 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1758 + an aufs user Pip Cet's approach
1759 + - calls aufs_create(), VFS finish_open() and notify_change().
1760 + - pass fake-mode to finish_open(), and then correct the mode by
1762 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1763 + - no aufs_atomic_open().
1764 + - aufs_lookup() registers the TID to an aufs internal object.
1765 + - aufs_create() does nothing when the matching TID is registered, but
1766 + registers the mode.
1767 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1768 + TID is registered.
1769 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1771 + - no aufs_atomic_open().
1772 + - aufs_create() registers the TID to an internal object. this info
1773 + represents "this process created this file just now."
1774 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1775 + registered TID and re-try open() with superuser's credential.
1777 +Pros and cons for each approach.
1780 + - straightforward but highly depends upon VFS internal.
1781 + - the atomic behavaiour is kept.
1782 + - some of parameters such as nameidata are hard to reproduce for
1786 + - easy to implement.
1787 + - the atomic behavaiour is lost.
1789 + - the atomic behavaiour is kept.
1790 + - dirty and tricky.
1791 + - VFS checks whether the file is created correctly after calling
1792 + ->create(), which means this approach doesn't work.
1794 + - easy to implement.
1795 + - the atomic behavaiour is lost.
1796 + - to open a file with superuser's credential and give it to a user
1797 + process is a bad idea, since the file object keeps the credential
1798 + in it. It may affect LSM or something. This approach doesn't work
1801 +The approach A is ideal, but it hard to implement. So here is a
1802 +variation of A, which is to be implemented.
1804 +A-1. Introduce aufs_atomic_open()
1805 + - calls branch fs ->atomic_open() if exists. otherwise calls
1806 + vfs_create() and finish_open().
1807 + - the demerit is that the several checks after branch fs
1808 + ->atomic_open() are lost. in the ordinary case, the checks are
1809 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1810 + be implemented in aufs, but not all I am afraid.
1811 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1812 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1813 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-04-15 08:49:13.394483860 +0200
1816 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1818 +# This program is free software; you can redistribute it and/or modify
1819 +# it under the terms of the GNU General Public License as published by
1820 +# the Free Software Foundation; either version 2 of the License, or
1821 +# (at your option) any later version.
1823 +# This program is distributed in the hope that it will be useful,
1824 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1825 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1826 +# GNU General Public License for more details.
1828 +# You should have received a copy of the GNU General Public License
1829 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1832 +----------------------------------------------------------------------
1833 +Since aufs has a character of sub-VFS (see Introduction), it operates
1834 +lookup for branches as VFS does. It may be a heavy work. But almost all
1835 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1836 +directly connected to its parent. Digging down the directory hierarchy
1837 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1840 +When a branch is a remote filesystem, aufs basically relies upon its
1841 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1843 +For d_revalidate, aufs implements three levels of revalidate tests. See
1844 +"Revalidate Dentry and UDBA" in detail.
1847 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1848 +----------------------------------------------------------------------
1849 +Let's try case study.
1850 +- aufs has two branches, upper readwrite and lower readonly.
1852 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1853 +- user invoked "chmod a+rx /au/dirA"
1854 +- the internal copy-up is activated and "/rw/dirA" is created and its
1855 + permission bits are set to world readable.
1856 +- then "/au/dirA" becomes world readable?
1858 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1859 +or it may be a natively readonly filesystem. If aufs respects the lower
1860 +branch, it should not respond readdir request from other users. But user
1861 +allowed it by chmod. Should really aufs rejects showing the entries
1864 +To be honest, I don't have a good solution for this case. So aufs
1865 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1867 +When dirperm1 is specified, aufs checks only the highest one for the
1868 +directory permission, and shows the entries. Otherwise, as usual, checks
1869 +every dir existing on all branches and rejects the request.
1871 +As a side effect, dirperm1 option improves the performance of aufs
1872 +because the number of permission check is reduced when the number of
1876 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1877 +----------------------------------------------------------------------
1878 +Generally VFS helpers re-validate a dentry as a part of lookup.
1879 +0. digging down the directory hierarchy.
1880 +1. lock the parent dir by its i_mutex.
1881 +2. lookup the final (child) entry.
1883 +4. call the actual operation (create, unlink, etc.)
1884 +5. unlock the parent dir
1886 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1887 +called. Actually aufs implements it and checks the dentry on a branch is
1889 +But it is not enough. Because aufs has to release the lock for the
1890 +parent dir on a branch at the end of ->lookup() (step 2) and
1891 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1893 +If the file on a branch is changed directly, eg. bypassing aufs, after
1894 +aufs released the lock, then the subsequent operation may cause
1895 +something unpleasant result.
1897 +This situation is a result of VFS architecture, ->lookup() and
1898 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1899 +design from VFS's point of view. It is just not suitable for sub-VFS
1902 +Aufs supports such case by three level of revalidation which is
1903 +selectable by user.
1904 +1. Simple Revalidate
1905 + Addition to the native flow in VFS's, confirm the child-parent
1906 + relationship on the branch just after locking the parent dir on the
1907 + branch in the "actual operation" (step 4). When this validation
1908 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1909 + checks the validation of the dentry on branches.
1910 +2. Monitor Changes Internally by Inotify/Fsnotify
1911 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1912 + the dentry on the branch, and returns EBUSY if it finds different
1914 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1915 + during it is in cache. When the event is notified, aufs registers a
1916 + function to kernel 'events' thread by schedule_work(). And the
1917 + function sets some special status to the cached aufs dentry and inode
1918 + private data. If they are not cached, then aufs has nothing to
1919 + do. When the same file is accessed through aufs (step 0-3) later,
1920 + aufs will detect the status and refresh all necessary data.
1921 + In this mode, aufs has to ignore the event which is fired by aufs
1923 +3. No Extra Validation
1924 + This is the simplest test and doesn't add any additional revalidation
1925 + test, and skip the revalidation in step 4. It is useful and improves
1926 + aufs performance when system surely hide the aufs branches from user,
1927 + by over-mounting something (or another method).
1928 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1929 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1930 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-04-15 08:49:13.394483860 +0200
1933 +# Copyright (C) 2005-2018 Junjiro R. Okajima
1935 +# This program is free software; you can redistribute it and/or modify
1936 +# it under the terms of the GNU General Public License as published by
1937 +# the Free Software Foundation; either version 2 of the License, or
1938 +# (at your option) any later version.
1940 +# This program is distributed in the hope that it will be useful,
1941 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1942 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1943 +# GNU General Public License for more details.
1945 +# You should have received a copy of the GNU General Public License
1946 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1948 +Branch Manipulation
1950 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1951 +and changing its permission/attribute, there are a lot of works to do.
1955 +----------------------------------------------------------------------
1956 +o Confirm the adding dir exists outside of aufs, including loopback
1957 + mount, and its various attributes.
1958 +o Initialize the xino file and whiteout bases if necessary.
1961 +o Check the owner/group/mode of the directory
1962 + When the owner/group/mode of the adding directory differs from the
1963 + existing branch, aufs issues a warning because it may impose a
1965 + For example, when a upper writable branch has a world writable empty
1966 + top directory, a malicious user can create any files on the writable
1967 + branch directly, like copy-up and modify manually. If something like
1968 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1969 + writable branch, and the writable branch is world-writable, then a
1970 + malicious guy may create /etc/passwd on the writable branch directly
1971 + and the infected file will be valid in aufs.
1972 + I am afraid it can be a security issue, but aufs can do nothing except
1973 + producing a warning.
1977 +----------------------------------------------------------------------
1978 +o Confirm the deleting branch is not busy
1979 + To be general, there is one merit to adopt "remount" interface to
1980 + manipulate branches. It is to discard caches. At deleting a branch,
1981 + aufs checks the still cached (and connected) dentries and inodes. If
1982 + there are any, then they are all in-use. An inode without its
1983 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1985 + For the cached one, aufs checks whether the same named entry exists on
1987 + If the cached one is a directory, because aufs provides a merged view
1988 + to users, as long as one dir is left on any branch aufs can show the
1989 + dir to users. In this case, the branch can be removed from aufs.
1990 + Otherwise aufs rejects deleting the branch.
1992 + If any file on the deleting branch is opened by aufs, then aufs
1996 +Modify the Permission of a Branch
1997 +----------------------------------------------------------------------
1998 +o Re-initialize or remove the xino file and whiteout bases if necessary.
2001 +o rw --> ro: Confirm the modifying branch is not busy
2002 + Aufs rejects the request if any of these conditions are true.
2003 + - a file on the branch is mmap-ed.
2004 + - a regular file on the branch is opened for write and there is no
2005 + same named entry on the upper branch.
2006 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
2007 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
2008 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-04-15 08:49:13.394483860 +0200
2011 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2013 +# This program is free software; you can redistribute it and/or modify
2014 +# it under the terms of the GNU General Public License as published by
2015 +# the Free Software Foundation; either version 2 of the License, or
2016 +# (at your option) any later version.
2018 +# This program is distributed in the hope that it will be useful,
2019 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2020 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2021 +# GNU General Public License for more details.
2023 +# You should have received a copy of the GNU General Public License
2024 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2026 +Policies to Select One among Multiple Writable Branches
2027 +----------------------------------------------------------------------
2028 +When the number of writable branch is more than one, aufs has to decide
2029 +the target branch for file creation or copy-up. By default, the highest
2030 +writable branch which has the parent (or ancestor) dir of the target
2031 +file is chosen (top-down-parent policy).
2032 +By user's request, aufs implements some other policies to select the
2033 +writable branch, for file creation several policies, round-robin,
2034 +most-free-space, and other policies. For copy-up, top-down-parent,
2035 +bottom-up-parent, bottom-up and others.
2037 +As expected, the round-robin policy selects the branch in circular. When
2038 +you have two writable branches and creates 10 new files, 5 files will be
2039 +created for each branch. mkdir(2) systemcall is an exception. When you
2040 +create 10 new directories, all will be created on the same branch.
2041 +And the most-free-space policy selects the one which has most free
2042 +space among the writable branches. The amount of free space will be
2043 +checked by aufs internally, and users can specify its time interval.
2045 +The policies for copy-up is more simple,
2046 +top-down-parent is equivalent to the same named on in create policy,
2047 +bottom-up-parent selects the writable branch where the parent dir
2048 +exists and the nearest upper one from the copyup-source,
2049 +bottom-up selects the nearest upper writable branch from the
2050 +copyup-source, regardless the existence of the parent dir.
2052 +There are some rules or exceptions to apply these policies.
2053 +- If there is a readonly branch above the policy-selected branch and
2054 + the parent dir is marked as opaque (a variation of whiteout), or the
2055 + target (creating) file is whiteout-ed on the upper readonly branch,
2056 + then the result of the policy is ignored and the target file will be
2057 + created on the nearest upper writable branch than the readonly branch.
2058 +- If there is a writable branch above the policy-selected branch and
2059 + the parent dir is marked as opaque or the target file is whiteouted
2060 + on the branch, then the result of the policy is ignored and the target
2061 + file will be created on the highest one among the upper writable
2062 + branches who has diropq or whiteout. In case of whiteout, aufs removes
2064 +- link(2) and rename(2) systemcalls are exceptions in every policy.
2065 + They try selecting the branch where the source exists as possible
2066 + since copyup a large file will take long time. If it can't be,
2067 + ie. the branch where the source exists is readonly, then they will
2068 + follow the copyup policy.
2069 +- There is an exception for rename(2) when the target exists.
2070 + If the rename target exists, aufs compares the index of the branches
2071 + where the source and the target exists and selects the higher
2072 + one. If the selected branch is readonly, then aufs follows the
2074 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2075 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2076 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-04-15 08:49:13.394483860 +0200
2079 +// to view this graph, run dot(1) command in GRAPHVIZ.
2083 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2087 +aufs_rename -> whinfo [label="store/remove"];
2090 +inode_list [label="h_inum list in branch\ncache"];
2093 +whinode [label="h_inum list file"];
2096 +brmgmt [label="br_add/del/mod/umount"];
2098 +brmgmt -> inode_list [label="create/remove"];
2099 +brmgmt -> whinode [label="load/store"];
2101 +inode_list -> whinode [style=dashed,dir=both];
2103 +aufs_rename -> inode_list [label="add/del"];
2105 +aufs_lookup -> inode_list [label="search"];
2107 +aufs_lookup -> whinfo [label="load/remove"];
2109 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2110 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2111 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-04-15 08:49:13.394483860 +0200
2114 +# Copyright (C) 2017-2018 Junjiro R. Okajima
2116 +# This program is free software; you can redistribute it and/or modify
2117 +# it under the terms of the GNU General Public License as published by
2118 +# the Free Software Foundation; either version 2 of the License, or
2119 +# (at your option) any later version.
2121 +# This program is distributed in the hope that it will be useful,
2122 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2123 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2124 +# GNU General Public License for more details.
2126 +# You should have received a copy of the GNU General Public License
2127 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2129 +Special handling for renaming a directory (DIRREN)
2130 +----------------------------------------------------------------------
2131 +First, let's assume we have a simple usecase.
2135 +- /ro/dirA and /ro/dirA/file exist too
2136 +- there is no dirB on both branches
2137 +- a user issues rename("dirA", "dirB")
2139 +Now, what should aufs behave against this rename(2)?
2140 +There are a few possible cases.
2143 + since dirA exists on a readonly branch which cannot be renamed.
2145 + it is possible to copy-up dirA (only the dir itself), but the child
2146 + entries ("file" in this case) should not be. it must be a bad
2147 + approach to copy-up recursively.
2148 +C. returns a success.
2149 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2150 + is a violation of aufs' policy.
2151 +D. construct an extra information which indicates that /ro/dirA should
2152 + be handled as the name of dirB.
2153 + overlayfs has a similar feature called REDIRECT.
2155 +Until now, aufs implements the case B only which returns EXDEV, and
2156 +expects the userspace application behaves like mv(1) which tries
2157 +issueing rename(2) recursively.
2159 +A new aufs feature called DIRREN is introduced which implements the case
2160 +D. There are several "extra information" added.
2162 +1. detailed info per renamed directory
2163 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2164 +2. the inode-number list of directories on a branch
2165 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2167 +The filename of "detailed info per directory" represents the lower
2168 +branch, and its format is
2169 +- a type of the branch id
2171 + + uuid (not implemented yet)
2174 +- the inode-number of the branch root dir
2176 +And it contains these info in a single regular file.
2178 +- branch's inode-number of the logically renamed dir
2179 +- the name of the before-renamed dir
2181 +The "detailed info per directory" file is created in aufs rename(2), and
2182 +loaded in any lookup.
2183 +The info is considered in lookup for the matching case only. Here
2184 +"matching" means that the root of branch (in the info filename) is same
2185 +to the current looking-up branch. After looking-up the before-renamed
2186 +name, the inode-number is compared. And the matched dentry is used.
2188 +The "inode-number list of directories" is a regular file which contains
2189 +simply the inode-numbers on the branch. The file is created or updated
2190 +in removing the branch, and loaded in adding the branch. Its lifetime is
2191 +equal to the branch.
2192 +The list is refered in lookup, and when the current target inode is
2193 +found in the list, the aufs tries loading the "detailed info per
2194 +directory" and get the changed and valid name of the dir.
2196 +Theoretically these "extra informaiton" may be able to be put into XATTR
2197 +in the dir inode. But aufs doesn't choose this way because
2198 +1. XATTR may not be supported by the branch (or its configuration)
2199 +2. XATTR may have its size limit.
2200 +3. XATTR may be less easy to convert than a regular file, when the
2201 + format of the info is changed in the future.
2202 +At the same time, I agree that the regular file approach is much slower
2203 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2206 +This DIRREN feature is enabled by aufs configuration, and is activated
2207 +by a new mount option.
2209 +For the more complicated case, there is a work with UDBA option, which
2210 +is to dected the direct access to the branches (by-passing aufs) and to
2211 +maintain the cashes in aufs. Since a single cached aufs dentry may
2212 +contains two names, before- and after-rename, the name comparision in
2213 +UDBA handler may not work correctly. In this case, the behaviour will be
2214 +equivalen to udba=reval case.
2215 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2216 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2217 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-04-15 08:49:13.394483860 +0200
2220 +# Copyright (C) 2011-2018 Junjiro R. Okajima
2222 +# This program is free software; you can redistribute it and/or modify
2223 +# it under the terms of the GNU General Public License as published by
2224 +# the Free Software Foundation; either version 2 of the License, or
2225 +# (at your option) any later version.
2227 +# This program is distributed in the hope that it will be useful,
2228 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2229 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2230 +# GNU General Public License for more details.
2232 +# You should have received a copy of the GNU General Public License
2233 +# along with this program; if not, write to the Free Software
2234 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2237 +File-based Hierarchical Storage Management (FHSM)
2238 +----------------------------------------------------------------------
2239 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2240 +storage world. Aufs provides this feature as file-based with multiple
2241 +writable branches, based upon the principle of "Colder, the Lower".
2242 +Here the word "colder" means that the less used files, and "lower" means
2243 +that the position in the order of the stacked branches vertically.
2244 +These multiple writable branches are prioritized, ie. the topmost one
2245 +should be the fastest drive and be used heavily.
2247 +o Characters in aufs FHSM story
2248 +- aufs itself and a new branch attribute.
2249 +- a new ioctl interface to move-down and to establish a connection with
2250 + the daemon ("move-down" is a converse of "copy-up").
2251 +- userspace tool and daemon.
2253 +The userspace daemon establishes a connection with aufs and waits for
2254 +the notification. The notified information is very similar to struct
2255 +statfs containing the number of consumed blocks and inodes.
2256 +When the consumed blocks/inodes of a branch exceeds the user-specified
2257 +upper watermark, the daemon activates its move-down process until the
2258 +consumed blocks/inodes reaches the user-specified lower watermark.
2260 +The actual move-down is done by aufs based upon the request from
2261 +user-space since we need to maintain the inode number and the internal
2262 +pointer arrays in aufs.
2264 +Currently aufs FHSM handles the regular files only. Additionally they
2265 +must not be hard-linked nor pseudo-linked.
2268 +o Cowork of aufs and the user-space daemon
2269 + During the userspace daemon established the connection, aufs sends a
2270 + small notification to it whenever aufs writes something into the
2271 + writable branch. But it may cost high since aufs issues statfs(2)
2272 + internally. So user can specify a new option to cache the
2273 + info. Actually the notification is controlled by these factors.
2274 + + the specified cache time.
2275 + + classified as "force" by aufs internally.
2276 + Until the specified time expires, aufs doesn't send the info
2277 + except the forced cases. When aufs decide forcing, the info is always
2278 + notified to userspace.
2279 + For example, the number of free inodes is generally large enough and
2280 + the shortage of it happens rarely. So aufs doesn't force the
2281 + notification when creating a new file, directory and others. This is
2282 + the typical case which aufs doesn't force.
2283 + When aufs writes the actual filedata and the files consumes any of new
2284 + blocks, the aufs forces notifying.
2287 +o Interfaces in aufs
2288 +- New branch attribute.
2290 + Specifies that the branch is managed by FHSM feature. In other word,
2291 + participant in the FHSM.
2292 + When nofhsm is set to the branch, it will not be the source/target
2293 + branch of the move-down operation. This attribute is set
2294 + independently from coo and moo attributes, and if you want full
2295 + FHSM, you should specify them as well.
2296 +- New mount option.
2298 + Specifies a second to suppress many less important info to be
2301 + + AUFS_CTL_FHSM_FD
2302 + create a new file descriptor which userspace can read the notification
2303 + (a subset of struct statfs) from aufs.
2304 +- Module parameter 'brs'
2305 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2307 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2308 + When there are two or more branches with fhsm attributes,
2309 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2310 + terminates it. As a result of remounting and branch-manipulation, the
2311 + number of branches with fhsm attribute can be one. In this case,
2312 + /sbin/mount.aufs will terminate the user-space daemon.
2315 +Finally the operation is done as these steps in kernel-space.
2317 + + no one else is using the file.
2318 + + the file is not hard-linked.
2319 + + the file is not pseudo-linked.
2320 + + the file is a regular file.
2321 + + the parent dir is not opaqued.
2322 +- find the target writable branch.
2323 +- make sure the file is not whiteout-ed by the upper (than the target)
2325 +- make the parent dir on the target branch.
2326 +- mutex lock the inode on the branch.
2327 +- unlink the whiteout on the target branch (if exists).
2328 +- lookup and create the whiteout-ed temporary name on the target branch.
2329 +- copy the file as the whiteout-ed temporary name on the target branch.
2330 +- rename the whiteout-ed temporary name to the original name.
2331 +- unlink the file on the source branch.
2332 +- maintain the internal pointer array and the external inode number
2334 +- maintain the timestamps and other attributes of the parent dir and the
2337 +And of course, in every step, an error may happen. So the operation
2338 +should restore the original file state after an error happens.
2339 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2340 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2341 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-04-15 08:49:13.394483860 +0200
2344 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2346 +# This program is free software; you can redistribute it and/or modify
2347 +# it under the terms of the GNU General Public License as published by
2348 +# the Free Software Foundation; either version 2 of the License, or
2349 +# (at your option) any later version.
2351 +# This program is distributed in the hope that it will be useful,
2352 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2353 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2354 +# GNU General Public License for more details.
2356 +# You should have received a copy of the GNU General Public License
2357 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2359 +mmap(2) -- File Memory Mapping
2360 +----------------------------------------------------------------------
2361 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2362 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2364 +This approach is simple and good, but there is one problem.
2365 +Under /proc, several entries show the mmapped files by its path (with
2366 +device and inode number), and the printed path will be the path on the
2367 +branch fs's instead of virtual aufs's.
2368 +This is not a problem in most cases, but some utilities lsof(1) (and its
2369 +user) may expect the path on aufs.
2371 +To address this issue, aufs adds a new member called vm_prfile in struct
2372 +vm_area_struct (and struct vm_region). The original vm_file points to
2373 +the file on the branch fs in order to handle everything correctly as
2374 +usual. The new vm_prfile points to a virtual file in aufs, and the
2375 +show-functions in procfs refers to vm_prfile if it is set.
2376 +Also we need to maintain several other places where touching vm_file
2378 +- fork()/clone() copies vma and the reference count of vm_file is
2380 +- merging vma maintains the ref count too.
2382 +This is not a good approach. It just fakes the printed path. But it
2383 +leaves all behaviour around f_mapping unchanged. This is surely an
2385 +Actually aufs had adopted another complicated approach which calls
2386 +generic_file_mmap() and handles struct vm_operations_struct. In this
2387 +approach, aufs met a hard problem and I could not solve it without
2388 +switching the approach.
2390 +There may be one more another approach which is
2391 +- bind-mount the branch-root onto the aufs-root internally
2392 +- grab the new vfsmount (ie. struct mount)
2393 +- lazy-umount the branch-root internally
2394 +- in open(2) the aufs-file, open the branch-file with the hidden
2395 + vfsmount (instead of the original branch's vfsmount)
2396 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2397 + but it may be possible from userspace by the mount helper.
2399 +Adding the internal hidden vfsmount and using it in opening a file, the
2400 +file path under /proc will be printed correctly. This approach looks
2401 +smarter, but is not possible I am afraid.
2402 +- aufs-root may be bind-mount later. when it happens, another hidden
2403 + vfsmount will be required.
2404 +- it is hard to get the chance to bind-mount and lazy-umount
2405 + + in kernel-space, FS can have vfsmount in open(2) via
2406 + file->f_path, and aufs can know its vfsmount. But several locks are
2407 + already acquired, and if aufs tries to bind-mount and lazy-umount
2408 + here, then it may cause a deadlock.
2409 + + in user-space, bind-mount doesn't invoke the mount helper.
2410 +- since /proc shows dev and ino, aufs has to give vma these info. it
2411 + means a new member vm_prinode will be necessary. this is essentially
2412 + equivalent to vm_prfile described above.
2414 +I have to give up this "looks-smater" approach.
2415 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2416 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2417 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-04-15 08:49:13.394483860 +0200
2420 +# Copyright (C) 2014-2018 Junjiro R. Okajima
2422 +# This program is free software; you can redistribute it and/or modify
2423 +# it under the terms of the GNU General Public License as published by
2424 +# the Free Software Foundation; either version 2 of the License, or
2425 +# (at your option) any later version.
2427 +# This program is distributed in the hope that it will be useful,
2428 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2429 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2430 +# GNU General Public License for more details.
2432 +# You should have received a copy of the GNU General Public License
2433 +# along with this program; if not, write to the Free Software
2434 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2437 +Listing XATTR/EA and getting the value
2438 +----------------------------------------------------------------------
2439 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2440 +shows the values from the topmost existing file. This behaviour is good
2441 +for the non-dir entries since the bahaviour exactly matches the shown
2442 +information. But for the directories, aufs considers all the same named
2443 +entries on the lower branches. Which means, if one of the lower entry
2444 +rejects readdir call, then aufs returns an error even if the topmost
2445 +entry allows it. This behaviour is necessary to respect the branch fs's
2446 +security, but can make users confused since the user-visible standard
2447 +attributes don't match the behaviour.
2448 +To address this issue, aufs has a mount option called dirperm1 which
2449 +checks the permission for the topmost entry only, and ignores the lower
2450 +entry's permission.
2452 +A similar issue can happen around XATTR.
2453 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2454 +always set. Otherwise these very unpleasant situation would happen.
2455 +- listxattr(2) may return the duplicated entries.
2456 +- users may not be able to remove or reset the XATTR forever,
2459 +XATTR/EA support in the internal (copy,move)-(up,down)
2460 +----------------------------------------------------------------------
2461 +Generally the extended attributes of inode are categorized as these.
2462 +- "security" for LSM and capability.
2463 +- "system" for posix ACL, 'acl' mount option is required for the branch
2465 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2466 +- "user" for userspace, 'user_xattr' mount option is required for the
2467 + branch fs generally.
2469 +Moreover there are some other categories. Aufs handles these rather
2470 +unpopular categories as the ordinary ones, ie. there is no special
2471 +condition nor exception.
2473 +In copy-up, the support for XATTR on the dst branch may differ from the
2474 +src branch. In this case, the copy-up operation will get an error and
2475 +the original user operation which triggered the copy-up will fail. It
2476 +can happen that even all copy-up will fail.
2477 +When both of src and dst branches support XATTR and if an error occurs
2478 +during copying XATTR, then the copy-up should fail obviously. That is a
2479 +good reason and aufs should return an error to userspace. But when only
2480 +the src branch support that XATTR, aufs should not return an error.
2481 +For example, the src branch supports ACL but the dst branch doesn't
2482 +because the dst branch may natively un-support it or temporary
2483 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2484 +may NOT return an error even if the XATTR is not supported. It is
2485 +totally up to the branch fs.
2487 +Anyway when the aufs internal copy-up gets an error from the dst branch
2488 +fs, then aufs tries removing the just copied entry and returns the error
2489 +to the userspace. The worst case of this situation will be all copy-up
2492 +For the copy-up operation, there two basic approaches.
2493 +- copy the specified XATTR only (by category above), and return the
2494 + error unconditionally if it happens.
2495 +- copy all XATTR, and ignore the error on the specified category only.
2497 +In order to support XATTR and to implement the correct behaviour, aufs
2498 +chooses the latter approach and introduces some new branch attributes,
2499 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2500 +They correspond to the XATTR namespaces (see above). Additionally, to be
2501 +convenient, "icex" is also provided which means all "icex*" attributes
2502 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2504 +The meaning of these attributes is to ignore the error from setting
2505 +XATTR on that branch.
2506 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2507 +error from the dst branch according to the specified attributes.
2509 +Some XATTR may have its default value. The default value may come from
2510 +the parent dir or the environment. If the default value is set at the
2511 +file creating-time, it will be overwritten by copy-up.
2512 +Some contradiction may happen I am afraid.
2513 +Do we need another attribute to stop copying XATTR? I am unsure. For
2514 +now, aufs implements the branch attributes to ignore the error.
2515 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2516 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2517 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-04-15 08:49:13.394483860 +0200
2520 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2522 +# This program is free software; you can redistribute it and/or modify
2523 +# it under the terms of the GNU General Public License as published by
2524 +# the Free Software Foundation; either version 2 of the License, or
2525 +# (at your option) any later version.
2527 +# This program is distributed in the hope that it will be useful,
2528 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2529 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2530 +# GNU General Public License for more details.
2532 +# You should have received a copy of the GNU General Public License
2533 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2535 +Export Aufs via NFS
2536 +----------------------------------------------------------------------
2537 +Here is an approach.
2538 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2540 +- iget_locked(): initialize aufs inode generation for a new inode, and
2541 + store it in xigen file.
2542 +- destroy_inode(): increment aufs inode generation and store it in xigen
2543 + file. it is necessary even if it is not unlinked, because any data of
2544 + inode may be changed by UDBA.
2545 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2546 + build file handle by
2547 + + branch id (4 bytes)
2548 + + superblock generation (4 bytes)
2549 + + inode number (4 or 8 bytes)
2550 + + parent dir inode number (4 or 8 bytes)
2551 + + inode generation (4 bytes))
2552 + + return value of exportfs_encode_fh() for the parent on a branch (4
2554 + + file handle for a branch (by exportfs_encode_fh())
2556 + + find the index of a branch from its id in handle, and check it is
2557 + still exist in aufs.
2558 + + 1st level: get the inode number from handle and search it in cache.
2559 + + 2nd level: if not found in cache, get the parent inode number from
2560 + the handle and search it in cache. and then open the found parent
2561 + dir, find the matching inode number by vfs_readdir() and get its
2562 + name, and call lookup_one_len() for the target dentry.
2563 + + 3rd level: if the parent dir is not cached, call
2564 + exportfs_decode_fh() for a branch and get the parent on a branch,
2565 + build a pathname of it, convert it a pathname in aufs, call
2566 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2568 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2569 + for every branch, but not itself. to get this, (currently) aufs
2570 + searches in current->nsproxy->mnt_ns list. it may not be a good
2571 + idea, but I didn't get other approach.
2572 + + test the generation of the gotten inode.
2573 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2574 + convert it into ESTALE for NFSD.
2575 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2576 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2577 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2578 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2579 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-04-15 08:49:13.394483860 +0200
2582 +# Copyright (C) 2005-2018 Junjiro R. Okajima
2584 +# This program is free software; you can redistribute it and/or modify
2585 +# it under the terms of the GNU General Public License as published by
2586 +# the Free Software Foundation; either version 2 of the License, or
2587 +# (at your option) any later version.
2589 +# This program is distributed in the hope that it will be useful,
2590 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2591 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2592 +# GNU General Public License for more details.
2594 +# You should have received a copy of the GNU General Public License
2595 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2597 +Show Whiteout Mode (shwh)
2598 +----------------------------------------------------------------------
2599 +Generally aufs hides the name of whiteouts. But in some cases, to show
2600 +them is very useful for users. For instance, creating a new middle layer
2601 +(branch) by merging existing layers.
2603 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2604 +When you have three branches,
2605 +- Bottom: 'system', squashfs (underlying base system), read-only
2606 +- Middle: 'mods', squashfs, read-only
2607 +- Top: 'overlay', ram (tmpfs), read-write
2609 +The top layer is loaded at boot time and saved at shutdown, to preserve
2610 +the changes made to the system during the session.
2611 +When larger changes have been made, or smaller changes have accumulated,
2612 +the size of the saved top layer data grows. At this point, it would be
2613 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2614 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2615 +restoring save and load speed.
2617 +This merging is simplified by the use of another aufs mount, of just the
2618 +two overlay branches using the 'shwh' option.
2619 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2620 + aufs /livesys/merge_union
2622 +A merged view of these two branches is then available at
2623 +/livesys/merge_union, and the new feature is that the whiteouts are
2625 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2626 +writing to all branches. Also the default mode for all branches is 'ro'.
2627 +It is now possible to save the combined contents of the two overlay
2628 +branches to a new squashfs, e.g.:
2629 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2631 +This new squashfs archive can be stored on the boot device and the
2632 +initramfs will use it to replace the old one at the next boot.
2633 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2634 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2635 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-04-15 08:49:13.394483860 +0200
2638 +# Copyright (C) 2010-2018 Junjiro R. Okajima
2640 +# This program is free software; you can redistribute it and/or modify
2641 +# it under the terms of the GNU General Public License as published by
2642 +# the Free Software Foundation; either version 2 of the License, or
2643 +# (at your option) any later version.
2645 +# This program is distributed in the hope that it will be useful,
2646 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2647 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2648 +# GNU General Public License for more details.
2650 +# You should have received a copy of the GNU General Public License
2651 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2653 +Dynamically customizable FS operations
2654 +----------------------------------------------------------------------
2655 +Generally FS operations (struct inode_operations, struct
2656 +address_space_operations, struct file_operations, etc.) are defined as
2657 +"static const", but it never means that FS have only one set of
2658 +operation. Some FS have multiple sets of them. For instance, ext2 has
2659 +three sets, one for XIP, for NOBH, and for normal.
2660 +Since aufs overrides and redirects these operations, sometimes aufs has
2661 +to change its behaviour according to the branch FS type. More importantly
2662 +VFS acts differently if a function (member in the struct) is set or
2663 +not. It means aufs should have several sets of operations and select one
2664 +among them according to the branch FS definition.
2666 +In order to solve this problem and not to affect the behaviour of VFS,
2667 +aufs defines these operations dynamically. For instance, aufs defines
2668 +dummy direct_IO function for struct address_space_operations, but it may
2669 +not be set to the address_space_operations actually. When the branch FS
2670 +doesn't have it, aufs doesn't set it to its address_space_operations
2671 +while the function definition itself is still alive. So the behaviour
2672 +itself will not change, and it will return an error when direct_IO is
2675 +The lifetime of these dynamically generated operation object is
2676 +maintained by aufs branch object. When the branch is removed from aufs,
2677 +the reference counter of the object is decremented. When it reaches
2678 +zero, the dynamically generated operation object will be freed.
2680 +This approach is designed to support AIO (io_submit), Direct I/O and
2682 +Currently this approach is applied to address_space_operations for
2683 +regular files only.
2684 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2685 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2686 +++ linux/Documentation/filesystems/aufs/README 2018-06-15 11:15:15.400449109 +0200
2689 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2695 +----------------------------------------
2696 +In the early days, aufs was entirely re-designed and re-implemented
2697 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2698 +improvements and implementations, it becomes totally different from
2699 +Unionfs while keeping the basic features.
2700 +Recently, Unionfs Version 2.x series begin taking some of the same
2701 +approaches to aufs1's.
2702 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2703 +University and his team.
2705 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2706 +If you want older kernel version support, try aufs2-2.6.git or
2707 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2709 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2710 + According to Christoph Hellwig, linux rejects all union-type
2711 + filesystems but UnionMount.
2712 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2714 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2715 + UnionMount, and he pointed out an issue around a directory mutex
2716 + lock and aufs addressed it. But it is still unsure whether aufs will
2717 + be merged (or any other union solution).
2718 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2722 +----------------------------------------
2723 +- unite several directories into a single virtual filesystem. The member
2724 + directory is called as a branch.
2725 +- you can specify the permission flags to the branch, which are 'readonly',
2726 + 'readwrite' and 'whiteout-able.'
2727 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2728 + readonly branch are modifiable logically.
2729 +- dynamic branch manipulation, add, del.
2732 +Also there are many enhancements in aufs, such as:
2733 +- test only the highest one for the directory permission (dirperm1)
2734 +- copyup on open (coo=)
2735 +- 'move' policy for copy-up between two writable branches, after
2736 + checking free space.
2738 +- readdir(3) in userspace.
2739 +- keep inode number by external inode number table
2740 +- keep the timestamps of file/dir in internal copyup operation
2741 +- seekable directory, supporting NFS readdir.
2742 +- whiteout is hardlinked in order to reduce the consumption of inodes
2744 +- do not copyup, nor create a whiteout when it is unnecessary
2745 +- revert a single systemcall when an error occurs in aufs
2746 +- remount interface instead of ioctl
2747 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2748 +- loopback mounted filesystem as a branch
2749 +- kernel thread for removing the dir who has a plenty of whiteouts
2750 +- support copyup sparse file (a file which has a 'hole' in it)
2751 +- default permission flags for branches
2752 +- selectable permission flags for ro branch, whether whiteout can
2755 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2756 +- support multiple writable branches, some policies to select one
2757 + among multiple writable branches.
2758 +- a new semantics for link(2) and rename(2) to support multiple
2759 + writable branches.
2760 +- no glibc changes are required.
2761 +- pseudo hardlink (hardlink over branches)
2762 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2763 + including NFS or remote filesystem branch.
2764 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2767 +Currently these features are dropped temporary from aufs4.
2768 +See design/08plan.txt in detail.
2769 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2771 +- statistics of aufs thread (/sys/fs/aufs/stat)
2773 +Features or just an idea in the future (see also design/*.txt),
2774 +- reorder the branch index without del/re-add.
2775 +- permanent xino files for NFSD
2776 +- an option for refreshing the opened files after add/del branches
2777 +- light version, without branch manipulation. (unnecessary?)
2778 +- copyup in userspace
2779 +- inotify in userspace
2784 +----------------------------------------
2785 +There are three GIT trees for aufs4, aufs4-linux.git,
2786 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2788 +While the aufs-util is always necessary, you need either of aufs4-linux
2789 +or aufs4-standalone.
2791 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2792 +git://git.kernel.org/.../torvalds/linux.git.
2793 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2794 +build aufs4 as an external kernel module.
2795 +Several extra patches are not included in this tree. Only
2796 +aufs4-standalone tree contains them. They are described in the later
2797 +section "Configuration and Compilation."
2799 +On the other hand, the aufs4-standalone tree has only aufs source files
2800 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2801 +But you need to apply all aufs patches manually.
2803 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2804 +represents the linux kernel version, "linux-4.x". For instance,
2805 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2806 +"aufs4.x-rcN" branch.
2809 +$ git clone --reference /your/linux/git/tree \
2810 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2811 +- if you don't have linux GIT tree, then remove "--reference ..."
2812 +$ cd aufs4-linux.git
2813 +$ git checkout origin/aufs4.0
2815 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2816 +leave the patch-work to GIT.
2817 +$ cd /your/linux/git/tree
2818 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2820 +$ git checkout -b my4.0 v4.0
2821 +$ (add your local change...)
2822 +$ git pull aufs4 aufs4.0
2823 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2824 +- you may need to solve some conflicts between your_changes and
2825 + aufs4.0. in this case, git-rerere is recommended so that you can
2826 + solve the similar conflicts automatically when you upgrade to 4.1 or
2827 + later in the future.
2829 +o aufs4-standalone tree
2830 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2831 +$ cd aufs4-standalone.git
2832 +$ git checkout origin/aufs4.0
2835 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2836 +- note that the public aufs-util.git is on SourceForge instead of
2839 +$ git checkout origin/aufs4.0
2841 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2842 +The minor version number, 'x' in '4.x', of aufs may not always
2843 +follow the minor version number of the kernel.
2844 +Because changes in the kernel that cause the use of a new
2845 +minor version number do not always require changes to aufs-util.
2847 +Since aufs-util has its own minor version number, you may not be
2848 +able to find a GIT branch in aufs-util for your kernel's
2849 +exact minor version number.
2850 +In this case, you should git-checkout the branch for the
2851 +nearest lower number.
2853 +For (an unreleased) example:
2854 +If you are using "linux-4.10" and the "aufs4.10" branch
2855 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2856 +or something numerically smaller is the branch for your kernel.
2858 +Also you can view all branches by
2862 +3. Configuration and Compilation
2863 +----------------------------------------
2864 +Make sure you have git-checkout'ed the correct branch.
2866 +For aufs4-linux tree,
2867 +- enable CONFIG_AUFS_FS.
2868 +- set other aufs configurations if necessary.
2870 +For aufs4-standalone tree,
2871 +There are several ways to build.
2874 +- apply ./aufs4-kbuild.patch to your kernel source files.
2875 +- apply ./aufs4-base.patch too.
2876 +- apply ./aufs4-mmap.patch too.
2877 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2878 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2879 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2880 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2881 +- enable CONFIG_AUFS_FS, you can select either
2883 +- and build your kernel as usual.
2884 +- install the built kernel.
2885 + Note: Since linux-3.9, every filesystem module requires an alias
2886 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2887 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2888 +- install the header files too by "make headers_install" to the
2889 + directory where you specify. By default, it is $PWD/usr.
2890 + "make help" shows a brief note for headers_install.
2891 +- and reboot your system.
2894 +- module only (CONFIG_AUFS_FS=m).
2895 +- apply ./aufs4-base.patch to your kernel source files.
2896 +- apply ./aufs4-mmap.patch too.
2897 +- apply ./aufs4-standalone.patch too.
2898 +- build your kernel, don't forget "make headers_install", and reboot.
2899 +- edit ./config.mk and set other aufs configurations if necessary.
2900 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2901 + every aufs configurations.
2902 +- build the module by simple "make".
2903 + Note: Since linux-3.9, every filesystem module requires an alias
2904 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2905 + modules.aliases file.
2906 +- you can specify ${KDIR} make variable which points to your kernel
2908 +- install the files
2909 + + run "make install" to install the aufs module, or copy the built
2910 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2911 + + run "make install_headers" (instead of headers_install) to install
2912 + the modified aufs header file (you can specify DESTDIR which is
2913 + available in aufs standalone version's Makefile only), or copy
2914 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2915 + you like manually. By default, the target directory is $PWD/usr.
2916 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2917 + kernel source tree.
2919 +Note: The header file aufs_type.h is necessary to build aufs-util
2920 + as well as "make headers_install" in the kernel source tree.
2921 + headers_install is subject to be forgotten, but it is essentially
2922 + necessary, not only for building aufs-util.
2923 + You may not meet problems without headers_install in some older
2927 +- read README in aufs-util, build and install it
2928 +- note that your distribution may contain an obsoleted version of
2929 + aufs_type.h in /usr/include/linux or something. When you build aufs
2930 + utilities, make sure that your compiler refers the correct aufs header
2931 + file which is built by "make headers_install."
2932 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2933 + then run "make install_ulib" too. And refer to the aufs manual in
2936 +There several other patches in aufs4-standalone.git. They are all
2937 +optional. When you meet some problems, they will help you.
2938 +- aufs4-loopback.patch
2939 + Supports a nested loopback mount in a branch-fs. This patch is
2940 + unnecessary until aufs produces a message like "you may want to try
2941 + another patch for loopback file".
2943 + Modifies a system global kernel internal function get_next_ino() in
2944 + order to stop assigning 0 for an inode-number. Not directly related to
2945 + aufs, but recommended generally.
2947 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2948 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2949 + duplication of inode number, which is important for backup tools and
2950 + other utilities. When you find aufs XINO files for tmpfs branch
2951 + growing too much, try this patch.
2952 +- lockdep-debug.patch
2953 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2954 + also a caller of VFS functions for branch filesystems, subclassing of
2955 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2956 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2957 + need to apply this debug patch to expand several constant values.
2958 + If don't know what LOCKDEP, then you don't have apply this patch.
2962 +----------------------------------------
2963 +At first, make sure aufs-util are installed, and please read the aufs
2964 +manual, aufs.5 in aufs-util.git tree.
2968 +$ mkdir /tmp/rw /tmp/aufs
2969 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2971 +Here is another example. The result is equivalent.
2972 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2974 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2975 +# mount -o remount,append:${HOME} /tmp/aufs
2977 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2978 +you modify a file under /tmp/aufs, the one on your home directory is
2979 +not affected, instead the same named file will be newly created under
2980 +/tmp/rw. And all of your modification to a file will be applied to
2981 +the one under /tmp/rw. This is called the file based Copy on Write
2983 +Aufs mount options are described in aufs.5.
2984 +If you run chroot or something and make your aufs as a root directory,
2985 +then you need to customize the shutdown script. See the aufs manual in
2988 +Additionally, there are some sample usages of aufs which are a
2989 +diskless system with network booting, and LiveCD over NFS.
2990 +See sample dir in CVS tree on SourceForge.
2994 +----------------------------------------
2995 +When you have any problems or strange behaviour in aufs, please let me
2997 +- /proc/mounts (instead of the output of mount(8))
2998 +- /sys/module/aufs/*
2999 +- /sys/fs/aufs/* (if you have them)
3000 +- /debug/aufs/* (if you have them)
3001 +- linux kernel version
3002 + if your kernel is not plain, for example modified by distributor,
3003 + the url where i can download its source is necessary too.
3004 +- aufs version which was printed at loading the module or booting the
3005 + system, instead of the date you downloaded.
3006 +- configuration (define/undefine CONFIG_AUFS_xxx)
3007 +- kernel configuration or /proc/config.gz (if you have it)
3008 +- behaviour which you think to be incorrect
3009 +- actual operation, reproducible one is better
3010 +- mailto: aufs-users at lists.sourceforge.net
3012 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
3013 +and Feature Requests) on SourceForge. Please join and write to
3017 +6. Acknowledgements
3018 +----------------------------------------
3019 +Thanks to everyone who have tried and are using aufs, whoever
3020 +have reported a bug or any feedback.
3022 +Especially donators:
3023 +Tomas Matejicek(slax.org) made a donation (much more than once).
3024 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
3025 + scripts) is making "doubling" donations.
3026 + Unfortunately I cannot list all of the donators, but I really
3028 + It ends Aug 2010, but the ordinary donation URL is still available.
3029 + <http://sourceforge.net/donate/index.php?group_id=167503>
3030 +Dai Itasaka made a donation (2007/8).
3031 +Chuck Smith made a donation (2008/4, 10 and 12).
3032 +Henk Schoneveld made a donation (2008/9).
3033 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
3034 +Francois Dupoux made a donation (2008/11).
3035 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
3036 + aufs2 GIT tree (2009/2).
3037 +William Grant made a donation (2009/3).
3038 +Patrick Lane made a donation (2009/4).
3039 +The Mail Archive (mail-archive.com) made donations (2009/5).
3040 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
3041 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
3042 +Pavel Pronskiy made a donation (2011/2).
3043 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
3044 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
3045 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
3047 +Sam Liddicott made a donation (2011/9).
3048 +Era Scarecrow made a donation (2013/4).
3049 +Bor Ratajc made a donation (2013/4).
3050 +Alessandro Gorreta made a donation (2013/4).
3051 +POIRETTE Marc made a donation (2013/4).
3052 +Alessandro Gorreta made a donation (2013/4).
3053 +lauri kasvandik made a donation (2013/5).
3054 +"pemasu from Finland" made a donation (2013/7).
3055 +The Parted Magic Project made a donation (2013/9 and 11).
3056 +Pavel Barta made a donation (2013/10).
3057 +Nikolay Pertsev made a donation (2014/5).
3058 +James B made a donation (2014/7 and 2015/7).
3059 +Stefano Di Biase made a donation (2014/8).
3060 +Daniel Epellei made a donation (2015/1).
3061 +OmegaPhil made a donation (2016/1, 2018/4).
3062 +Tomasz Szewczyk made a donation (2016/4).
3063 +James Burry made a donation (2016/12).
3065 +Thank you very much.
3066 +Donations are always, including future donations, very important and
3067 +helpful for me to keep on developing aufs.
3071 +----------------------------------------
3072 +If you are an experienced user, no explanation is needed. Aufs is
3073 +just a linux filesystem.
3078 +# Local variables: ;
3081 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3082 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3083 +++ linux/fs/aufs/aufs.h 2018-07-19 09:46:13.053314374 +0200
3085 +/* SPDX-License-Identifier: GPL-2.0 */
3087 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3089 + * This program, aufs is free software; you can redistribute it and/or modify
3090 + * it under the terms of the GNU General Public License as published by
3091 + * the Free Software Foundation; either version 2 of the License, or
3092 + * (at your option) any later version.
3094 + * This program is distributed in the hope that it will be useful,
3095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3097 + * GNU General Public License for more details.
3099 + * You should have received a copy of the GNU General Public License
3100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3104 + * all header files
3112 +#define AuStub(type, name, body, ...) \
3113 + static inline type name(__VA_ARGS__) { body; }
3115 +#define AuStubVoid(name, ...) \
3116 + AuStub(void, name, , __VA_ARGS__)
3117 +#define AuStubInt0(name, ...) \
3118 + AuStub(int, name, return 0, __VA_ARGS__)
3122 +#include "branch.h"
3125 +#include "dbgaufs.h"
3126 +#include "dentry.h"
3128 +#include "dirren.h"
3131 +#include "fstype.h"
3135 +#include "module.h"
3139 +#include "sysaufs.h"
3144 +#endif /* __KERNEL__ */
3145 +#endif /* __AUFS_H__ */
3146 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3147 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3148 +++ linux/fs/aufs/branch.c 2018-07-19 09:46:13.053314374 +0200
3150 +/* SPDX-License-Identifier: GPL-2.0 */
3152 + * Copyright (C) 2005-2018 Junjiro R. Okajima
3154 + * This program, aufs is free software; you can redistribute it and/or modify
3155 + * it under the terms of the GNU General Public License as published by
3156 + * the Free Software Foundation; either version 2 of the License, or
3157 + * (at your option) any later version.
3159 + * This program is distributed in the hope that it will be useful,
3160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3162 + * GNU General Public License for more details.
3164 + * You should have received a copy of the GNU General Public License
3165 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3169 + * branch management
3172 +#include <linux/compat.h>
3173 +#include <linux/statfs.h>
3177 + * free a single branch
3179 +static void au_br_do_free(struct au_branch *br)
3182 + struct au_wbr *wbr;
3183 + struct au_dykey **key;
3185 + au_hnotify_fin_br(br);
3186 + /* always, regardless the mount option */
3187 + au_dr_hino_free(&br->br_dirren);
3190 + AuDebugOn(au_br_count(br));
3191 + au_br_count_fin(br);
3195 + for (i = 0; i < AuBrWh_Last; i++)
3196 + dput(wbr->wbr_wh[i]);
3197 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3198 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3201 + if (br->br_fhsm) {
3202 + au_br_fhsm_fin(br->br_fhsm);
3203 + kfree(br->br_fhsm);
3206 + key = br->br_dykey;
3207 + for (i = 0; i < AuBrDynOp; i++, key++)
3213 + /* recursive lock, s_umount of branch's */
3215 + path_put(&br->br_path);
3222 + * frees all branches
3224 +void au_br_free(struct au_sbinfo *sbinfo)
3226 + aufs_bindex_t bmax;
3227 + struct au_branch **br;
3229 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3231 + bmax = sbinfo->si_bbot + 1;
3232 + br = sbinfo->si_branch;
3234 + au_br_do_free(*br++);
3238 + * find the index of a branch which is specified by @br_id.
3240 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3242 + aufs_bindex_t bindex, bbot;
3244 + bbot = au_sbbot(sb);
3245 + for (bindex = 0; bindex <= bbot; bindex++)
3246 + if (au_sbr_id(sb, bindex) == br_id)
3251 +/* ---------------------------------------------------------------------- */
3257 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3258 + struct dentry *h_root)
3260 + if (unlikely(h_adding == h_root
3261 + || au_test_loopback_overlap(sb, h_adding)))
3263 + if (h_adding->d_sb != h_root->d_sb)
3265 + return au_test_subdir(h_adding, h_root)
3266 + || au_test_subdir(h_root, h_adding);
3270 + * returns a newly allocated branch. @new_nbranch is a number of branches
3271 + * after adding a branch.
3273 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3276 + struct au_branch *add_branch;
3277 + struct dentry *root;
3278 + struct inode *inode;
3282 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3283 + if (unlikely(!add_branch))
3285 + add_branch->br_xino = au_xino_alloc();
3286 + if (unlikely(!add_branch->br_xino))
3288 + err = au_hnotify_init_br(add_branch, perm);
3289 + if (unlikely(err))
3292 + if (au_br_writable(perm)) {
3293 + /* may be freed separately at changing the branch permission */
3294 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3296 + if (unlikely(!add_branch->br_wbr))
3300 + if (au_br_fhsm(perm)) {
3301 + err = au_fhsm_br_alloc(add_branch);
3302 + if (unlikely(err))
3306 + root = sb->s_root;
3307 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3309 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3311 + inode = d_inode(root);
3312 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3316 + return add_branch; /* success */
3319 + kfree(add_branch->br_wbr);
3321 + au_hnotify_fin_br(add_branch);
3323 + au_xino_put(add_branch);
3325 + kfree(add_branch);
3327 + return ERR_PTR(err);
3331 + * test if the branch permission is legal or not.
3333 +static int test_br(struct inode *inode, int brperm, char *path)
3337 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3342 + pr_err("write permission for readonly mount or inode, %s\n", path);
3350 + * 0: success, the caller will add it
3351 + * plus: success, it is already unified, the caller should ignore it
3354 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3357 + aufs_bindex_t bbot, bindex;
3358 + struct dentry *root, *h_dentry;
3359 + struct inode *inode, *h_inode;
3361 + root = sb->s_root;
3362 + bbot = au_sbbot(sb);
3363 + if (unlikely(bbot >= 0
3364 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3368 + pr_err("%s duplicated\n", add->pathname);
3373 + err = -ENOSPC; /* -E2BIG; */
3374 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3375 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3376 + pr_err("number of branches exceeded %s\n", add->pathname);
3381 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3382 + pr_err("bad index %d\n", add->bindex);
3386 + inode = d_inode(add->path.dentry);
3388 + if (unlikely(!inode->i_nlink)) {
3389 + pr_err("no existence %s\n", add->pathname);
3394 + if (unlikely(inode->i_sb == sb)) {
3395 + pr_err("%s must be outside\n", add->pathname);
3399 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3400 + pr_err("unsupported filesystem, %s (%s)\n",
3401 + add->pathname, au_sbtype(inode->i_sb));
3405 + if (unlikely(inode->i_sb->s_stack_depth)) {
3406 + pr_err("already stacked, %s (%s)\n",
3407 + add->pathname, au_sbtype(inode->i_sb));
3411 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3412 + if (unlikely(err))
3416 + return 0; /* success */
3419 + for (bindex = 0; bindex <= bbot; bindex++)
3420 + if (unlikely(test_overlap(sb, add->path.dentry,
3421 + au_h_dptr(root, bindex)))) {
3422 + pr_err("%s is overlapped\n", add->pathname);
3427 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3428 + h_dentry = au_h_dptr(root, 0);
3429 + h_inode = d_inode(h_dentry);
3430 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3431 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3432 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3433 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3435 + i_uid_read(inode), i_gid_read(inode),
3436 + (inode->i_mode & S_IALLUGO),
3437 + i_uid_read(h_inode), i_gid_read(h_inode),
3438 + (h_inode->i_mode & S_IALLUGO));
3446 + * initialize or clean the whiteouts for an adding branch
3448 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3451 + int err, old_perm;
3452 + aufs_bindex_t bindex;
3453 + struct inode *h_inode;
3454 + struct au_wbr *wbr;
3455 + struct au_hinode *hdir;
3456 + struct dentry *h_dentry;
3458 + err = vfsub_mnt_want_write(au_br_mnt(br));
3459 + if (unlikely(err))
3463 + old_perm = br->br_perm;
3464 + br->br_perm = new_perm;
3467 + bindex = au_br_index(sb, br->br_id);
3468 + if (0 <= bindex) {
3469 + hdir = au_hi(d_inode(sb->s_root), bindex);
3470 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3472 + h_dentry = au_br_dentry(br);
3473 + h_inode = d_inode(h_dentry);
3474 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3477 + err = au_wh_init(br, sb);
3479 + wbr_wh_write_lock(wbr);
3480 + err = au_wh_init(br, sb);
3481 + wbr_wh_write_unlock(wbr);
3484 + au_hn_inode_unlock(hdir);
3486 + inode_unlock(h_inode);
3487 + vfsub_mnt_drop_write(au_br_mnt(br));
3488 + br->br_perm = old_perm;
3490 + if (!err && wbr && !au_br_writable(new_perm)) {
3492 + br->br_wbr = NULL;
3499 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3503 + struct kstatfs kst;
3504 + struct au_wbr *wbr;
3507 + au_rw_init(&wbr->wbr_wh_rwsem);
3508 + atomic_set(&wbr->wbr_wh_running, 0);
3511 + * a limit for rmdir/rename a dir
3512 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3514 + err = vfs_statfs(&br->br_path, &kst);
3515 + if (unlikely(err))
3518 + if (kst.f_namelen >= NAME_MAX)
3519 + err = au_br_init_wh(sb, br, perm);
3521 + pr_err("%pd(%s), unsupported namelen %ld\n",
3523 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3529 +/* initialize a new branch */
3530 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3531 + struct au_opt_add *add)
3534 + struct au_branch *brbase;
3536 + struct inode *h_inode;
3539 + br->br_perm = add->perm;
3540 + br->br_path = add->path; /* set first, path_get() later */
3541 + spin_lock_init(&br->br_dykey_lock);
3542 + au_br_count_init(br);
3543 + br->br_id = au_new_br_id(sb);
3544 + AuDebugOn(br->br_id < 0);
3546 + /* always, regardless the given option */
3547 + err = au_dr_br_init(sb, br, &add->path);
3548 + if (unlikely(err))
3551 + if (au_br_writable(add->perm)) {
3552 + err = au_wbr_init(br, sb, add->perm);
3553 + if (unlikely(err))
3557 + if (au_opt_test(au_mntflags(sb), XINO)) {
3558 + brbase = au_sbr(sb, 0);
3559 + xf = au_xino_file(brbase);
3561 + h_inode = d_inode(add->path.dentry);
3562 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3563 + if (unlikely(err)) {
3564 + AuDebugOn(au_xino_file(br));
3569 + sysaufs_br_init(br);
3570 + path_get(&br->br_path);
3571 + goto out; /* success */
3574 + memset(&br->br_path, 0, sizeof(br->br_path));
3579 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3580 + struct au_branch *br, aufs_bindex_t bbot,
3581 + aufs_bindex_t amount)
3583 + struct au_branch **brp;
3585 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3587 + brp = sbinfo->si_branch + bindex;
3588 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3590 + sbinfo->si_bbot++;
3591 + if (unlikely(bbot < 0))
3592 + sbinfo->si_bbot = 0;
3595 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3596 + aufs_bindex_t bbot, aufs_bindex_t amount)
3598 + struct au_hdentry *hdp;
3600 + AuRwMustWriteLock(&dinfo->di_rwsem);
3602 + hdp = au_hdentry(dinfo, bindex);
3603 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3604 + au_h_dentry_init(hdp);
3606 + if (unlikely(bbot < 0))
3607 + dinfo->di_btop = 0;
3610 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3611 + aufs_bindex_t bbot, aufs_bindex_t amount)
3613 + struct au_hinode *hip;
3615 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3617 + hip = au_hinode(iinfo, bindex);
3618 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3619 + au_hinode_init(hip);
3621 + if (unlikely(bbot < 0))
3622 + iinfo->ii_btop = 0;
3625 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3626 + aufs_bindex_t bindex)
3628 + struct dentry *root, *h_dentry;
3629 + struct inode *root_inode, *h_inode;
3630 + aufs_bindex_t bbot, amount;
3632 + root = sb->s_root;
3633 + root_inode = d_inode(root);
3634 + bbot = au_sbbot(sb);
3635 + amount = bbot + 1 - bindex;
3636 + h_dentry = au_br_dentry(br);
3637 + au_sbilist_lock();
3638 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3639 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3640 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3641 + au_set_h_dptr(root, bindex, dget(h_dentry));
3642 + h_inode = d_inode(h_dentry);
3643 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3644 + au_sbilist_unlock();
3647 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3650 + aufs_bindex_t bbot, add_bindex;
3651 + struct dentry *root, *h_dentry;
3652 + struct inode *root_inode;
3653 + struct au_branch *add_branch;
3656 + root = sb->s_root;
3657 + root_inode = d_inode(root);
3658 + IMustLock(root_inode);
3659 + IiMustWriteLock(root_inode);
3660 + err = test_add(sb, add, remount);
3661 + if (unlikely(err < 0))
3665 + goto out; /* success */
3668 + bbot = au_sbbot(sb);
3669 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3670 + err = PTR_ERR(add_branch);
3671 + if (IS_ERR(add_branch))
3674 + err = au_br_init(add_branch, sb, add);
3675 + if (unlikely(err)) {
3676 + au_br_do_free(add_branch);
3680 + add_bindex = add->bindex;
3681 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3682 + au_br_do_add(sb, add_branch, add_bindex);
3683 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3684 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3686 + h_dentry = add->path.dentry;
3687 + if (!add_bindex) {
3688 + au_cpup_attr_all(root_inode, /*force*/1);
3689 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3691 + au_add_nlink(root_inode, d_inode(h_dentry));
3694 + * this test/set prevents aufs from handling unnecessary notify events
3695 + * of xino files, in case of re-adding a writable branch which was
3696 + * once detached from aufs.
3698 + if (au_xino_brid(sb) < 0
3699 + && au_br_writable(add_branch->br_perm)
3700 + && !au_test_fs_bad_xino(h_dentry->d_sb)) {
3701 + xf = au_xino_file(add_branch);
3702 + if (xf && xf->f_path.dentry->d_parent == h_dentry)
3703 + au_xino_brid_set(sb, add_branch->br_id);
3710 +/* ---------------------------------------------------------------------- */
3712 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3713 + unsigned long long max __maybe_unused,
3716 + unsigned long long n;
3717 + struct file **p, *f;
3718 + struct hlist_bl_head *files;
3719 + struct hlist_bl_node *pos;
3720 + struct au_finfo *finfo;
3724 + files = &au_sbi(sb)->si_files;
3725 + hlist_bl_lock(files);
3726 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3727 + f = finfo->fi_file;
3729 + && !special_file(file_inode(f)->i_mode)) {
3733 + AuDebugOn(n > max);
3736 + hlist_bl_unlock(files);
3741 +static struct file **au_farray_alloc(struct super_block *sb,
3742 + unsigned long long *max)
3744 + *max = au_nfiles(sb);
3745 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3748 +static void au_farray_free(struct file **a, unsigned long long max)
3750 + unsigned long long ull;
3752 + for (ull = 0; ull < max; ull++)
3758 +/* ---------------------------------------------------------------------- */
3764 +/* to show the line number, do not make it inlined function */
3765 +#define AuVerbose(do_info, fmt, ...) do { \
3767 + pr_info(fmt, ##__VA_ARGS__); \
3770 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3771 + aufs_bindex_t bbot)
3773 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3776 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3777 + aufs_bindex_t bbot)
3779 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3783 + * test if the branch is deletable or not.
3785 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3786 + unsigned int sigen, const unsigned int verbose)
3788 + int err, i, j, ndentry;
3789 + aufs_bindex_t btop, bbot;
3790 + struct au_dcsub_pages dpages;
3791 + struct au_dpage *dpage;
3794 + err = au_dpages_init(&dpages, GFP_NOFS);
3795 + if (unlikely(err))
3797 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3798 + if (unlikely(err))
3801 + for (i = 0; !err && i < dpages.ndpage; i++) {
3802 + dpage = dpages.dpages + i;
3803 + ndentry = dpage->ndentry;
3804 + for (j = 0; !err && j < ndentry; j++) {
3805 + d = dpage->dentries[j];
3806 + AuDebugOn(au_dcount(d) <= 0);
3807 + if (!au_digen_test(d, sigen)) {
3808 + di_read_lock_child(d, AuLock_IR);
3809 + if (unlikely(au_dbrange_test(d))) {
3810 + di_read_unlock(d, AuLock_IR);
3814 + di_write_lock_child(d);
3815 + if (unlikely(au_dbrange_test(d))) {
3816 + di_write_unlock(d);
3819 + err = au_reval_dpath(d, sigen);
3821 + di_downgrade_lock(d, AuLock_IR);
3823 + di_write_unlock(d);
3828 + /* AuDbgDentry(d); */
3829 + btop = au_dbtop(d);
3830 + bbot = au_dbbot(d);
3831 + if (btop <= bindex
3833 + && au_h_dptr(d, bindex)
3834 + && au_test_dbusy(d, btop, bbot)) {
3836 + AuVerbose(verbose, "busy %pd\n", d);
3839 + di_read_unlock(d, AuLock_IR);
3844 + au_dpages_free(&dpages);
3849 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3850 + unsigned int sigen, const unsigned int verbose)
3853 + unsigned long long max, ull;
3854 + struct inode *i, **array;
3855 + aufs_bindex_t btop, bbot;
3857 + array = au_iarray_alloc(sb, &max);
3858 + err = PTR_ERR(array);
3859 + if (IS_ERR(array))
3863 + AuDbg("b%d\n", bindex);
3864 + for (ull = 0; !err && ull < max; ull++) {
3868 + if (i->i_ino == AUFS_ROOT_INO)
3871 + /* AuDbgInode(i); */
3872 + if (au_iigen(i, NULL) == sigen)
3873 + ii_read_lock_child(i);
3875 + ii_write_lock_child(i);
3876 + err = au_refresh_hinode_self(i);
3879 + ii_downgrade_lock(i);
3881 + ii_write_unlock(i);
3886 + btop = au_ibtop(i);
3887 + bbot = au_ibbot(i);
3888 + if (btop <= bindex
3890 + && au_h_iptr(i, bindex)
3891 + && au_test_ibusy(i, btop, bbot)) {
3893 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3896 + ii_read_unlock(i);
3898 + au_iarray_free(array, max);
3904 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3905 + const unsigned int verbose)
3908 + unsigned int sigen;
3910 + sigen = au_sigen(root->d_sb);
3911 + DiMustNoWaiters(root);
3912 + IiMustNoWaiters(d_inode(root));
3913 + di_write_unlock(root);
3914 + err = test_dentry_busy(root, bindex, sigen, verbose);
3916 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3917 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3922 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3923 + struct file **to_free, int *idx)
3926 + unsigned char matched, root;
3927 + aufs_bindex_t bindex, bbot;
3928 + struct au_fidir *fidir;
3929 + struct au_hfile *hfile;
3932 + root = IS_ROOT(file->f_path.dentry);
3935 + to_free[*idx] = file;
3941 + fidir = au_fi(file)->fi_hdir;
3942 + AuDebugOn(!fidir);
3943 + bbot = au_fbbot_dir(file);
3944 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3945 + hfile = fidir->fd_hfile + bindex;
3946 + if (!hfile->hf_file)
3949 + if (hfile->hf_br->br_id == br_id) {
3961 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3962 + struct file **to_free, int opened)
3965 + unsigned long long ull, max;
3966 + aufs_bindex_t btop;
3967 + struct file *file, **array;
3968 + struct dentry *root;
3969 + struct au_hfile *hfile;
3971 + array = au_farray_alloc(sb, &max);
3972 + err = PTR_ERR(array);
3973 + if (IS_ERR(array))
3978 + root = sb->s_root;
3979 + di_write_unlock(root);
3980 + for (ull = 0; ull < max; ull++) {
3981 + file = array[ull];
3982 + if (unlikely(!file))
3985 + /* AuDbg("%pD\n", file); */
3986 + fi_read_lock(file);
3987 + btop = au_fbtop(file);
3988 + if (!d_is_dir(file->f_path.dentry)) {
3989 + hfile = &au_fi(file)->fi_htop;
3990 + if (hfile->hf_br->br_id == br_id)
3993 + err = test_dir_busy(file, br_id, to_free, &idx);
3994 + fi_read_unlock(file);
3995 + if (unlikely(err))
3998 + di_write_lock_child(root);
3999 + au_farray_free(array, max);
4000 + AuDebugOn(idx > opened);
4006 +static void br_del_file(struct file **to_free, unsigned long long opened,
4007 + aufs_bindex_t br_id)
4009 + unsigned long long ull;
4010 + aufs_bindex_t bindex, btop, bbot, bfound;
4011 + struct file *file;
4012 + struct au_fidir *fidir;
4013 + struct au_hfile *hfile;
4015 + for (ull = 0; ull < opened; ull++) {
4016 + file = to_free[ull];
4017 + if (unlikely(!file))
4020 + /* AuDbg("%pD\n", file); */
4021 + AuDebugOn(!d_is_dir(file->f_path.dentry));
4023 + fidir = au_fi(file)->fi_hdir;
4024 + AuDebugOn(!fidir);
4025 + fi_write_lock(file);
4026 + btop = au_fbtop(file);
4027 + bbot = au_fbbot_dir(file);
4028 + for (bindex = btop; bindex <= bbot; bindex++) {
4029 + hfile = fidir->fd_hfile + bindex;
4030 + if (!hfile->hf_file)
4033 + if (hfile->hf_br->br_id == br_id) {
4038 + AuDebugOn(bfound < 0);
4039 + au_set_h_fptr(file, bfound, NULL);
4040 + if (bfound == btop) {
4041 + for (btop++; btop <= bbot; btop++)
4042 + if (au_hf_dir(file, btop)) {
4043 + au_set_fbtop(file, btop);
4047 + fi_write_unlock(file);
4051 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
4052 + const aufs_bindex_t bindex,
4053 + const aufs_bindex_t bbot)
4055 + struct au_branch **brp, **p;
4057 + AuRwMustWriteLock(&sbinfo->si_rwsem);
4059 + brp = sbinfo->si_branch + bindex;
4060 + if (bindex < bbot)
4061 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4062 + sbinfo->si_branch[0 + bbot] = NULL;
4063 + sbinfo->si_bbot--;
4065 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4068 + sbinfo->si_branch = p;
4069 + /* harmless error */
4072 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4073 + const aufs_bindex_t bbot)
4075 + struct au_hdentry *hdp, *p;
4077 + AuRwMustWriteLock(&dinfo->di_rwsem);
4079 + hdp = au_hdentry(dinfo, bindex);
4080 + if (bindex < bbot)
4081 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4082 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4085 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4088 + dinfo->di_hdentry = p;
4089 + /* harmless error */
4092 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4093 + const aufs_bindex_t bbot)
4095 + struct au_hinode *hip, *p;
4097 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4099 + hip = au_hinode(iinfo, bindex);
4100 + if (bindex < bbot)
4101 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4102 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4105 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4108 + iinfo->ii_hinode = p;
4109 + /* harmless error */
4112 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4113 + struct au_branch *br)
4115 + aufs_bindex_t bbot;
4116 + struct au_sbinfo *sbinfo;
4117 + struct dentry *root, *h_root;
4118 + struct inode *inode, *h_inode;
4119 + struct au_hinode *hinode;
4121 + SiMustWriteLock(sb);
4123 + root = sb->s_root;
4124 + inode = d_inode(root);
4125 + sbinfo = au_sbi(sb);
4126 + bbot = sbinfo->si_bbot;
4128 + h_root = au_h_dptr(root, bindex);
4129 + hinode = au_hi(inode, bindex);
4130 + h_inode = au_igrab(hinode->hi_inode);
4133 + au_sbilist_lock();
4134 + au_br_do_del_brp(sbinfo, bindex, bbot);
4135 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4136 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4137 + au_sbilist_unlock();
4139 + /* ignore an error */
4140 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4144 + au_br_do_free(br);
4147 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4148 + unsigned long long max, void *arg)
4153 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4156 + unsigned long long opened;
4157 + unsigned int mnt_flags;
4158 + aufs_bindex_t bindex, bbot, br_id;
4159 + unsigned char do_wh, verbose;
4160 + struct au_branch *br;
4161 + struct au_wbr *wbr;
4162 + struct dentry *root;
4163 + struct file **to_free;
4168 + root = sb->s_root;
4169 + bindex = au_find_dbindex(root, del->h_path.dentry);
4172 + goto out; /* success */
4174 + pr_err("%s no such branch\n", del->pathname);
4177 + AuDbg("bindex b%d\n", bindex);
4180 + mnt_flags = au_mntflags(sb);
4181 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4182 + bbot = au_sbbot(sb);
4183 + if (unlikely(!bbot)) {
4184 + AuVerbose(verbose, "no more branches left\n");
4187 + br = au_sbr(sb, bindex);
4188 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4190 + br_id = br->br_id;
4191 + opened = au_br_count(br);
4192 + if (unlikely(opened)) {
4193 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4194 + err = PTR_ERR(to_free);
4195 + if (IS_ERR(to_free))
4198 + err = test_file_busy(sb, br_id, to_free, opened);
4199 + if (unlikely(err)) {
4200 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4206 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4208 + /* instead of WbrWhMustWriteLock(wbr) */
4209 + SiMustWriteLock(sb);
4210 + for (i = 0; i < AuBrWh_Last; i++) {
4211 + dput(wbr->wbr_wh[i]);
4212 + wbr->wbr_wh[i] = NULL;
4216 + err = test_children_busy(root, bindex, verbose);
4217 + if (unlikely(err)) {
4226 + * now we confirmed the branch is deletable.
4227 + * let's free the remaining opened dirs on the branch.
4229 + di_write_unlock(root);
4230 + br_del_file(to_free, opened, br_id);
4231 + di_write_lock_child(root);
4234 + sysaufs_brs_del(sb, bindex); /* remove successors */
4235 + dbgaufs_xino_del(br); /* remove one */
4236 + au_br_do_del(sb, bindex, br);
4237 + sysaufs_brs_add(sb, bindex); /* append successors */
4238 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4241 + au_cpup_attr_all(d_inode(root), /*force*/1);
4242 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4244 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4245 + if (au_opt_test(mnt_flags, PLINK))
4246 + au_plink_half_refresh(sb, br_id);
4248 + if (au_xino_brid(sb) == br_id)
4249 + au_xino_brid_set(sb, -1);
4250 + goto out; /* success */
4254 + rerr = au_br_init_wh(sb, br, br->br_perm);
4256 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4257 + del->pathname, rerr);
4260 + au_farray_free(to_free, opened);
4264 +/* ---------------------------------------------------------------------- */
4266 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4269 + aufs_bindex_t btop, bbot;
4270 + struct aufs_ibusy ibusy;
4271 + struct inode *inode, *h_inode;
4274 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4277 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4279 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4280 + if (unlikely(err)) {
4287 + si_read_lock(sb, AuLock_FLUSH);
4288 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4292 + ibusy.h_ino = 0; /* invalid */
4293 + inode = ilookup(sb, ibusy.ino);
4295 + || inode->i_ino == AUFS_ROOT_INO
4296 + || au_is_bad_inode(inode))
4299 + ii_read_lock_child(inode);
4300 + btop = au_ibtop(inode);
4301 + bbot = au_ibbot(inode);
4302 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4303 + h_inode = au_h_iptr(inode, ibusy.bindex);
4304 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4305 + ibusy.h_ino = h_inode->i_ino;
4307 + ii_read_unlock(inode);
4311 + si_read_unlock(sb);
4313 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4314 + if (unlikely(err)) {
4323 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4325 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4328 +#ifdef CONFIG_COMPAT
4329 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4331 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4335 +/* ---------------------------------------------------------------------- */
4338 + * change a branch permission
4341 +static void au_warn_ima(void)
4344 + /* since it doesn't support mark_files_ro() */
4345 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4349 +static int do_need_sigen_inc(int a, int b)
4351 + return au_br_whable(a) && !au_br_whable(b);
4354 +static int need_sigen_inc(int old, int new)
4356 + return do_need_sigen_inc(old, new)
4357 + || do_need_sigen_inc(new, old);
4360 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4363 + unsigned int mnt_flags;
4364 + unsigned long long ull, max;
4365 + aufs_bindex_t br_id;
4366 + unsigned char verbose, writer;
4367 + struct file *file, *hf, **array;
4368 + struct au_hfile *hfile;
4370 + mnt_flags = au_mntflags(sb);
4371 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4373 + array = au_farray_alloc(sb, &max);
4374 + err = PTR_ERR(array);
4375 + if (IS_ERR(array))
4379 + br_id = au_sbr_id(sb, bindex);
4380 + for (ull = 0; ull < max; ull++) {
4381 + file = array[ull];
4382 + if (unlikely(!file))
4385 + /* AuDbg("%pD\n", file); */
4386 + fi_read_lock(file);
4387 + if (unlikely(au_test_mmapped(file))) {
4389 + AuVerbose(verbose, "mmapped %pD\n", file);
4391 + FiMustNoWaiters(file);
4392 + fi_read_unlock(file);
4396 + hfile = &au_fi(file)->fi_htop;
4397 + hf = hfile->hf_file;
4398 + if (!d_is_reg(file->f_path.dentry)
4399 + || !(file->f_mode & FMODE_WRITE)
4400 + || hfile->hf_br->br_id != br_id
4401 + || !(hf->f_mode & FMODE_WRITE))
4402 + array[ull] = NULL;
4408 + FiMustNoWaiters(file);
4409 + fi_read_unlock(file);
4417 + for (ull = 0; ull < max; ull++) {
4418 + file = array[ull];
4422 + /* todo: already flushed? */
4424 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4425 + * approach which resets f_mode and calls mnt_drop_write() and
4426 + * file_release_write() for each file, because the branch
4427 + * attribute in aufs world is totally different from the native
4430 + /* fi_read_lock(file); */
4431 + hfile = &au_fi(file)->fi_htop;
4432 + hf = hfile->hf_file;
4433 + /* fi_read_unlock(file); */
4434 + spin_lock(&hf->f_lock);
4435 + writer = !!(hf->f_mode & FMODE_WRITER);
4436 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4437 + spin_unlock(&hf->f_lock);
4439 + put_write_access(file_inode(hf));
4440 + __mnt_drop_write(hf->f_path.mnt);
4445 + au_farray_free(array, max);
4451 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4455 + aufs_bindex_t bindex;
4456 + struct dentry *root;
4457 + struct au_branch *br;
4458 + struct au_br_fhsm *bf;
4460 + root = sb->s_root;
4461 + bindex = au_find_dbindex(root, mod->h_root);
4464 + return 0; /* success */
4466 + pr_err("%s no such branch\n", mod->path);
4469 + AuDbg("bindex b%d\n", bindex);
4471 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4472 + if (unlikely(err))
4475 + br = au_sbr(sb, bindex);
4476 + AuDebugOn(mod->h_root != au_br_dentry(br));
4477 + if (br->br_perm == mod->perm)
4478 + return 0; /* success */
4480 + /* pre-allocate for non-fhsm --> fhsm */
4482 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4483 + err = au_fhsm_br_alloc(br);
4484 + if (unlikely(err))
4487 + br->br_fhsm = NULL;
4490 + if (au_br_writable(br->br_perm)) {
4491 + /* remove whiteout base */
4492 + err = au_br_init_wh(sb, br, mod->perm);
4493 + if (unlikely(err))
4496 + if (!au_br_writable(mod->perm)) {
4497 + /* rw --> ro, file might be mmapped */
4498 + DiMustNoWaiters(root);
4499 + IiMustNoWaiters(d_inode(root));
4500 + di_write_unlock(root);
4501 + err = au_br_mod_files_ro(sb, bindex);
4502 + /* aufs_write_lock() calls ..._child() */
4503 + di_write_lock_child(root);
4505 + if (unlikely(err)) {
4507 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4510 + rerr = au_wbr_init(br, sb, br->br_perm);
4511 + if (unlikely(rerr)) {
4512 + AuIOErr("nested error %d (%d)\n",
4514 + br->br_perm = mod->perm;
4518 + } else if (au_br_writable(mod->perm)) {
4521 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4523 + err = au_wbr_init(br, sb, mod->perm);
4524 + if (unlikely(err)) {
4525 + kfree(br->br_wbr);
4526 + br->br_wbr = NULL;
4530 + if (unlikely(err))
4533 + if (au_br_fhsm(br->br_perm)) {
4534 + if (!au_br_fhsm(mod->perm)) {
4535 + /* fhsm --> non-fhsm */
4536 + au_br_fhsm_fin(br->br_fhsm);
4537 + kfree(br->br_fhsm);
4538 + br->br_fhsm = NULL;
4540 + } else if (au_br_fhsm(mod->perm))
4541 + /* non-fhsm --> fhsm */
4544 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4545 + br->br_perm = mod->perm;
4546 + goto out; /* success */
4555 +/* ---------------------------------------------------------------------- */
4557 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4560 + struct kstatfs kstfs;
4562 + err = vfs_statfs(&br->br_path, &kstfs);
4564 + stfs->f_blocks = kstfs.f_blocks;
4565 + stfs->f_bavail = kstfs.f_bavail;
4566 + stfs->f_files = kstfs.f_files;
4567 + stfs->f_ffree = kstfs.f_ffree;
4572 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4573 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4574 +++ linux/fs/aufs/branch.h 2018-07-19 09:46:13.053314374 +0200
4576 +/* SPDX-License-Identifier: GPL-2.0 */
4578 + * Copyright (C) 2005-2018 Junjiro R. Okajima
4580 + * This program, aufs is free software; you can redistribute it and/or modify
4581 + * it under the terms of the GNU General Public License as published by
4582 + * the Free Software Foundation; either version 2 of the License, or
4583 + * (at your option) any later version.
4585 + * This program is distributed in the hope that it will be useful,
4586 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4587 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4588 + * GNU General Public License for more details.
4590 + * You should have received a copy of the GNU General Public License
4591 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4595 + * branch filesystems and xino for them
4598 +#ifndef __AUFS_BRANCH_H__
4599 +#define __AUFS_BRANCH_H__
4603 +#include <linux/mount.h>
4604 +#include "dirren.h"
4609 +/* ---------------------------------------------------------------------- */
4613 + struct file *xi_file;
4618 + /* reserved for future use */
4619 + /* unsigned long *bitmap; */
4620 + wait_queue_head_t wqh;
4623 + atomic_t xi_truncating;
4625 + struct kref xi_kref;
4627 + /* todo: make xino files an array to support huge inode number */
4630 +/* File-based Hierarchical Storage Management */
4631 +struct au_br_fhsm {
4632 +#ifdef CONFIG_AUFS_FHSM
4633 + struct mutex bf_lock;
4634 + unsigned long bf_jiffy;
4635 + struct aufs_stfs bf_stfs;
4640 +/* members for writable branch only */
4641 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4643 + struct au_rwsem wbr_wh_rwsem;
4644 + struct dentry *wbr_wh[AuBrWh_Last];
4645 + atomic_t wbr_wh_running;
4646 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4647 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4648 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4651 + unsigned long long wbr_bytes;
4654 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4655 +#define AuBrDynOp (AuDyLast * 4)
4657 +#ifdef CONFIG_AUFS_HFSNOTIFY
4658 +/* support for asynchronous destruction */
4659 +struct au_br_hfsnotify {
4660 + struct fsnotify_group *hfsn_group;
4664 +/* sysfs entries */
4665 +struct au_brsysfs {
4667 + struct attribute attr;
4676 +/* protected by superblock rwsem */
4678 + struct au_xino *br_xino;
4680 + aufs_bindex_t br_id;
4683 + struct path br_path;
4684 + spinlock_t br_dykey_lock;
4685 + struct au_dykey *br_dykey[AuBrDynOp];
4686 + struct percpu_counter br_count;
4688 + struct au_wbr *br_wbr;
4689 + struct au_br_fhsm *br_fhsm;
4691 +#ifdef CONFIG_AUFS_HFSNOTIFY
4692 + struct au_br_hfsnotify *br_hfsn;
4695 +#ifdef CONFIG_SYSFS
4696 + /* entries under sysfs per mount-point */
4697 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4700 +#ifdef CONFIG_DEBUG_FS
4701 + struct dentry *br_dbgaufs; /* xino */
4704 + struct au_dr_br br_dirren;
4707 +/* ---------------------------------------------------------------------- */
4709 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4711 + return br->br_path.mnt;
4714 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4716 + return br->br_path.dentry;
4719 +static inline struct super_block *au_br_sb(struct au_branch *br)
4721 + return au_br_mnt(br)->mnt_sb;
4724 +static inline void au_br_get(struct au_branch *br)
4726 + percpu_counter_inc(&br->br_count);
4729 +static inline void au_br_put(struct au_branch *br)
4731 + percpu_counter_dec(&br->br_count);
4734 +static inline s64 au_br_count(struct au_branch *br)
4736 + return percpu_counter_sum(&br->br_count);
4739 +static inline void au_br_count_init(struct au_branch *br)
4741 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4744 +static inline void au_br_count_fin(struct au_branch *br)
4746 + percpu_counter_destroy(&br->br_count);
4749 +static inline int au_br_rdonly(struct au_branch *br)
4751 + return (sb_rdonly(au_br_sb(br))
4752 + || !au_br_writable(br->br_perm))
4756 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4758 +#ifdef CONFIG_AUFS_HNOTIFY
4759 + return !(brperm & AuBrPerm_RR);
4765 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4767 + int err, exec_flag;
4770 + exec_flag = oflag & __FMODE_EXEC;
4771 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4777 +static inline void au_xino_get(struct au_branch *br)
4779 + struct au_xino *xi;
4783 + kref_get(&xi->xi_kref);
4786 +static inline int au_xino_count(struct au_branch *br)
4789 + struct au_xino *xi;
4794 + v = kref_read(&xi->xi_kref);
4799 +static inline struct file *au_xino_file(struct au_branch *br)
4801 + struct au_xino *xi;
4804 + return xi ? xi->xi_file : NULL;
4807 +/* ---------------------------------------------------------------------- */
4811 +void au_br_free(struct au_sbinfo *sinfo);
4812 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4814 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4816 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4817 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4818 +#ifdef CONFIG_COMPAT
4819 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4822 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4825 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4828 +static const loff_t au_loff_max = LLONG_MAX;
4830 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent);
4831 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4832 + struct file *copy_src);
4834 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4836 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4838 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4840 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4841 + size_t size, loff_t *pos);
4843 +int au_xib_trunc(struct super_block *sb);
4844 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4846 +struct au_xino *au_xino_alloc(void);
4847 +int au_xino_put(struct au_branch *br);
4848 +void au_xino_file_set(struct au_branch *br, struct file *file);
4850 +struct au_opt_xino;
4851 +void au_xino_clr(struct super_block *sb);
4852 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4853 +struct file *au_xino_def(struct super_block *sb);
4854 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4855 + struct path *base);
4857 +ino_t au_xino_new_ino(struct super_block *sb);
4858 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4860 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4861 + ino_t h_ino, int idx);
4862 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4865 +int au_xino_path(struct seq_file *seq, struct file *file);
4867 +/* ---------------------------------------------------------------------- */
4869 +/* Superblock to branch */
4871 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4873 + return au_sbr(sb, bindex)->br_id;
4877 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4879 + return au_br_mnt(au_sbr(sb, bindex));
4883 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4885 + return au_br_sb(au_sbr(sb, bindex));
4888 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4890 + au_br_get(au_sbr(sb, bindex));
4893 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4895 + au_br_put(au_sbr(sb, bindex));
4898 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4900 + return au_sbr(sb, bindex)->br_perm;
4903 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4905 + return au_br_whable(au_sbr_perm(sb, bindex));
4908 +/* ---------------------------------------------------------------------- */
4910 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4911 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4912 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4913 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4915 +#define wbr_wh_read_trylock_nested(wbr) \
4916 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4917 +#define wbr_wh_write_trylock_nested(wbr) \
4918 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4921 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4922 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4923 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4925 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4926 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4927 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4929 +/* ---------------------------------------------------------------------- */
4931 +#ifdef CONFIG_AUFS_FHSM
4932 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4934 + mutex_init(&brfhsm->bf_lock);
4935 + brfhsm->bf_jiffy = 0;
4936 + brfhsm->bf_readable = 0;
4939 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4941 + mutex_destroy(&brfhsm->bf_lock);
4944 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4945 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4948 +#endif /* __KERNEL__ */
4949 +#endif /* __AUFS_BRANCH_H__ */
4950 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4951 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4952 +++ linux/fs/aufs/conf.mk 2018-06-04 09:08:09.181412645 +0200
4954 +# SPDX-License-Identifier: GPL-2.0
4956 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4960 +AuConfStr += ${1}=${${1}}
4964 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4966 + HNOTIFY HFSNOTIFY \
4978 +$(foreach i, ${AuConfAll}, \
4979 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4981 +AuConfName = ${obj}/conf.str
4982 +${AuConfName}.tmp: FORCE
4983 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4984 +${AuConfName}: ${AuConfName}.tmp
4985 + @diff -q $< $@ > /dev/null 2>&1 || { \
4986 + echo ' GEN ' $@; \
4990 +clean-files += ${AuConfName} ${AuConfName}.tmp
4991 +${obj}/sysfs.o: ${AuConfName}
4993 +-include ${srctree}/${src}/conf_priv.mk
4994 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4995 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4996 +++ linux/fs/aufs/cpup.c 2018-07-19 09:46:13.056647808 +0200
4998 +/* SPDX-License-Identifier: GPL-2.0 */
5000 + * Copyright (C) 2005-2018 Junjiro R. Okajima
5002 + * This program, aufs is free software; you can redistribute it and/or modify
5003 + * it under the terms of the GNU General Public License as published by
5004 + * the Free Software Foundation; either version 2 of the License, or
5005 + * (at your option) any later version.
5007 + * This program is distributed in the hope that it will be useful,
5008 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5009 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5010 + * GNU General Public License for more details.
5012 + * You should have received a copy of the GNU General Public License
5013 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5017 + * copy-up functions, see wbr_policy.c for copy-down
5020 +#include <linux/fs_stack.h>
5021 +#include <linux/mm.h>
5022 +#include <linux/task_work.h>
5025 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
5027 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
5028 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
5030 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
5032 + dst->i_flags |= iflags & ~mask;
5033 + if (au_test_fs_notime(dst->i_sb))
5034 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
5037 +void au_cpup_attr_timesizes(struct inode *inode)
5039 + struct inode *h_inode;
5041 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5042 + fsstack_copy_attr_times(inode, h_inode);
5043 + fsstack_copy_inode_size(inode, h_inode);
5046 +void au_cpup_attr_nlink(struct inode *inode, int force)
5048 + struct inode *h_inode;
5049 + struct super_block *sb;
5050 + aufs_bindex_t bindex, bbot;
5053 + bindex = au_ibtop(inode);
5054 + h_inode = au_h_iptr(inode, bindex);
5056 + && !S_ISDIR(h_inode->i_mode)
5057 + && au_opt_test(au_mntflags(sb), PLINK)
5058 + && au_plink_test(inode))
5062 + * 0 can happen in revalidating.
5063 + * h_inode->i_mutex may not be held here, but it is harmless since once
5064 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5066 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5067 + * the incorrect link count.
5069 + set_nlink(inode, h_inode->i_nlink);
5072 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5073 + * it may includes whplink directory.
5075 + if (S_ISDIR(h_inode->i_mode)) {
5076 + bbot = au_ibbot(inode);
5077 + for (bindex++; bindex <= bbot; bindex++) {
5078 + h_inode = au_h_iptr(inode, bindex);
5080 + au_add_nlink(inode, h_inode);
5085 +void au_cpup_attr_changeable(struct inode *inode)
5087 + struct inode *h_inode;
5089 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5090 + inode->i_mode = h_inode->i_mode;
5091 + inode->i_uid = h_inode->i_uid;
5092 + inode->i_gid = h_inode->i_gid;
5093 + au_cpup_attr_timesizes(inode);
5094 + au_cpup_attr_flags(inode, h_inode->i_flags);
5097 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5099 + struct au_iinfo *iinfo = au_ii(inode);
5101 + IiMustWriteLock(inode);
5103 + iinfo->ii_higen = h_inode->i_generation;
5104 + iinfo->ii_hsb1 = h_inode->i_sb;
5107 +void au_cpup_attr_all(struct inode *inode, int force)
5109 + struct inode *h_inode;
5111 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5112 + au_cpup_attr_changeable(inode);
5113 + if (inode->i_nlink > 0)
5114 + au_cpup_attr_nlink(inode, force);
5115 + inode->i_rdev = h_inode->i_rdev;
5116 + inode->i_blkbits = h_inode->i_blkbits;
5117 + au_cpup_igen(inode, h_inode);
5120 +/* ---------------------------------------------------------------------- */
5122 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5124 +/* keep the timestamps of the parent dir when cpup */
5125 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5126 + struct path *h_path)
5128 + struct inode *h_inode;
5130 + dt->dt_dentry = dentry;
5131 + dt->dt_h_path = *h_path;
5132 + h_inode = d_inode(h_path->dentry);
5133 + dt->dt_atime = h_inode->i_atime;
5134 + dt->dt_mtime = h_inode->i_mtime;
5138 +void au_dtime_revert(struct au_dtime *dt)
5140 + struct iattr attr;
5143 + attr.ia_atime = dt->dt_atime;
5144 + attr.ia_mtime = dt->dt_mtime;
5145 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5146 + | ATTR_ATIME | ATTR_ATIME_SET;
5148 + /* no delegation since this is a directory */
5149 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5150 + if (unlikely(err))
5151 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5154 +/* ---------------------------------------------------------------------- */
5156 +/* internal use only */
5157 +struct au_cpup_reg_attr {
5160 + unsigned int iflags; /* inode->i_flags */
5163 +static noinline_for_stack
5164 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5165 + struct au_cpup_reg_attr *h_src_attr)
5167 + int err, sbits, icex;
5168 + unsigned int mnt_flags;
5169 + unsigned char verbose;
5171 + struct path h_path;
5172 + struct inode *h_isrc, *h_idst;
5173 + struct kstat *h_st;
5174 + struct au_branch *br;
5176 + h_path.dentry = au_h_dptr(dst, bindex);
5177 + h_idst = d_inode(h_path.dentry);
5178 + br = au_sbr(dst->d_sb, bindex);
5179 + h_path.mnt = au_br_mnt(br);
5180 + h_isrc = d_inode(h_src);
5181 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5182 + | ATTR_ATIME | ATTR_MTIME
5183 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5184 + if (h_src_attr && h_src_attr->valid) {
5185 + h_st = &h_src_attr->st;
5186 + ia.ia_uid = h_st->uid;
5187 + ia.ia_gid = h_st->gid;
5188 + ia.ia_atime = h_st->atime;
5189 + ia.ia_mtime = h_st->mtime;
5190 + if (h_idst->i_mode != h_st->mode
5191 + && !S_ISLNK(h_idst->i_mode)) {
5192 + ia.ia_valid |= ATTR_MODE;
5193 + ia.ia_mode = h_st->mode;
5195 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5196 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5198 + ia.ia_uid = h_isrc->i_uid;
5199 + ia.ia_gid = h_isrc->i_gid;
5200 + ia.ia_atime = h_isrc->i_atime;
5201 + ia.ia_mtime = h_isrc->i_mtime;
5202 + if (h_idst->i_mode != h_isrc->i_mode
5203 + && !S_ISLNK(h_idst->i_mode)) {
5204 + ia.ia_valid |= ATTR_MODE;
5205 + ia.ia_mode = h_isrc->i_mode;
5207 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5208 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5210 + /* no delegation since it is just created */
5211 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5213 + /* is this nfs only? */
5214 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5215 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5216 + ia.ia_mode = h_isrc->i_mode;
5217 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5220 + icex = br->br_perm & AuBrAttr_ICEX;
5222 + mnt_flags = au_mntflags(dst->d_sb);
5223 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5224 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5230 +/* ---------------------------------------------------------------------- */
5232 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5233 + char *buf, unsigned long blksize)
5236 + size_t sz, rbytes, wbytes;
5237 + unsigned char all_zero;
5239 + struct inode *h_inode;
5240 + /* reduce stack usage */
5243 + zp = page_address(ZERO_PAGE(0));
5244 + if (unlikely(!zp))
5245 + return -ENOMEM; /* possible? */
5250 + AuDbg("len %lld\n", len);
5252 + if (len < blksize)
5256 + /* todo: signal_pending? */
5257 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5258 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5261 + if (unlikely(err < 0))
5265 + if (len >= rbytes && rbytes == blksize)
5266 + all_zero = !memcmp(buf, zp, rbytes);
5273 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5275 + /* todo: signal_pending? */
5276 + if (unlikely(err == -EAGAIN || err == -EINTR))
5278 + if (unlikely(err < 0))
5283 + if (unlikely(err < 0))
5289 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5291 + if (unlikely(res < 0))
5298 + /* the last block may be a hole */
5299 + if (!err && all_zero) {
5300 + AuLabel(last hole);
5303 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5304 + /* nfs requires this step to make last hole */
5305 + /* is this only nfs? */
5307 + /* todo: signal_pending? */
5308 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5309 + } while (err == -EAGAIN || err == -EINTR);
5316 + ia->ia_size = dst->f_pos;
5317 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5318 + ia->ia_file = dst;
5319 + h_inode = file_inode(dst);
5320 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5321 + /* no delegation since it is just created */
5322 + err = vfsub_notify_change(&dst->f_path, ia,
5323 + /*delegated*/NULL);
5324 + inode_unlock(h_inode);
5331 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5334 + unsigned long blksize;
5335 + unsigned char do_kfree;
5339 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
5340 + if (!blksize || PAGE_SIZE < blksize)
5341 + blksize = PAGE_SIZE;
5342 + AuDbg("blksize %lu\n", blksize);
5343 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5345 + buf = kmalloc(blksize, GFP_NOFS);
5347 + buf = (void *)__get_free_page(GFP_NOFS);
5348 + if (unlikely(!buf))
5351 + if (len > (1 << 22))
5352 + AuDbg("copying a large file %lld\n", (long long)len);
5356 + err = au_do_copy_file(dst, src, len, buf, blksize);
5360 + free_page((unsigned long)buf);
5366 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5369 + struct super_block *h_src_sb;
5370 + struct inode *h_src_inode;
5372 + h_src_inode = file_inode(src);
5373 + h_src_sb = h_src_inode->i_sb;
5375 + /* XFS acquires inode_lock */
5376 + if (!au_test_xfs(h_src_sb))
5377 + err = au_copy_file(dst, src, len);
5379 + inode_unlock_shared(h_src_inode);
5380 + err = au_copy_file(dst, src, len);
5381 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5387 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5390 + struct super_block *h_src_sb;
5391 + struct inode *h_src_inode;
5393 + h_src_inode = file_inode(src);
5394 + h_src_sb = h_src_inode->i_sb;
5395 + if (h_src_sb != file_inode(dst)->i_sb
5396 + || !dst->f_op->clone_file_range) {
5397 + err = au_do_copy(dst, src, len);
5401 + if (!au_test_nfs(h_src_sb)) {
5402 + inode_unlock_shared(h_src_inode);
5403 + err = vfsub_clone_file_range(src, dst, len);
5404 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5406 + err = vfsub_clone_file_range(src, dst, len);
5407 + /* older XFS has a condition in cloning */
5408 + if (unlikely(err != -EOPNOTSUPP))
5411 + /* the backend fs on NFS may not support cloning */
5412 + err = au_do_copy(dst, src, len);
5420 + * to support a sparse file which is opened with O_APPEND,
5421 + * we need to close the file.
5423 +static int au_cp_regular(struct au_cp_generic *cpg)
5426 + enum { SRC, DST };
5428 + aufs_bindex_t bindex;
5429 + unsigned int flags;
5430 + struct dentry *dentry;
5432 + struct file *file;
5436 + .bindex = cpg->bsrc,
5437 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5441 + .bindex = cpg->bdst,
5442 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5443 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5444 + .label = &&out_src
5447 + struct super_block *sb, *h_src_sb;
5448 + struct inode *h_src_inode;
5449 + struct task_struct *tsk = current;
5451 + /* bsrc branch can be ro/rw. */
5452 + sb = cpg->dentry->d_sb;
5454 + for (i = 0; i < 2; i++, f++) {
5455 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5456 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5457 + /*file*/NULL, f->force_wr);
5458 + err = PTR_ERR(f->file);
5459 + if (IS_ERR(f->file))
5463 + /* try stopping to update while we copyup */
5464 + h_src_inode = d_inode(file[SRC].dentry);
5465 + h_src_sb = h_src_inode->i_sb;
5466 + if (!au_test_nfs(h_src_sb))
5467 + IMustLock(h_src_inode);
5468 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5470 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5471 + if (tsk->flags & PF_KTHREAD)
5472 + __fput_sync(file[DST].file);
5474 + /* it happened actually */
5475 + fput(file[DST].file);
5478 + * we have to call both since we don't know which place the file
5482 + flush_delayed_fput();
5484 + au_sbr_put(sb, file[DST].bindex);
5487 + fput(file[SRC].file);
5488 + au_sbr_put(sb, file[SRC].bindex);
5493 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5494 + struct au_cpup_reg_attr *h_src_attr)
5498 + struct path h_path;
5499 + struct inode *h_src_inode, *h_dst_inode;
5502 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5503 + l = i_size_read(h_src_inode);
5504 + if (cpg->len == -1 || l < cpg->len)
5507 + /* try stopping to update while we are referencing */
5508 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5509 + au_pin_hdir_unlock(cpg->pin);
5511 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5512 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5513 + h_src_attr->iflags = h_src_inode->i_flags;
5514 + if (!au_test_nfs(h_src_inode->i_sb))
5515 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5517 + inode_unlock_shared(h_src_inode);
5518 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5519 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5521 + if (unlikely(err)) {
5522 + inode_unlock_shared(h_src_inode);
5525 + h_src_attr->valid = 1;
5526 + if (!au_test_nfs(h_src_inode->i_sb)) {
5527 + err = au_cp_regular(cpg);
5528 + inode_unlock_shared(h_src_inode);
5530 + inode_unlock_shared(h_src_inode);
5531 + err = au_cp_regular(cpg);
5533 + rerr = au_pin_hdir_relock(cpg->pin);
5537 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5538 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5539 + h_dst_inode = d_inode(h_path.dentry);
5540 + spin_lock(&h_dst_inode->i_lock);
5541 + h_dst_inode->i_state |= I_LINKABLE;
5542 + spin_unlock(&h_dst_inode->i_lock);
5549 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5550 + struct inode *h_dir)
5553 + mm_segment_t old_fs;
5560 + sym.k = (void *)__get_free_page(GFP_NOFS);
5561 + if (unlikely(!sym.k))
5564 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5565 + old_fs = get_fs();
5566 + set_fs(KERNEL_DS);
5567 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5572 + sym.k[symlen] = 0;
5573 + err = vfsub_symlink(h_dir, h_path, sym.k);
5575 + free_page((unsigned long)sym.k);
5582 + * regardless 'acl' option, reset all ACL.
5583 + * All ACL will be copied up later from the original entry on the lower branch.
5585 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5588 + struct dentry *h_dentry;
5589 + struct inode *h_inode;
5591 + h_dentry = h_path->dentry;
5592 + h_inode = d_inode(h_dentry);
5593 + /* forget_all_cached_acls(h_inode)); */
5594 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5596 + if (err == -EOPNOTSUPP)
5599 + err = vfsub_acl_chmod(h_inode, mode);
5605 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5606 + struct inode *h_dir, struct path *h_path)
5609 + struct inode *dir, *inode;
5611 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5613 + if (err == -EOPNOTSUPP)
5615 + if (unlikely(err))
5619 + * strange behaviour from the users view,
5620 + * particularry setattr case
5622 + dir = d_inode(dst_parent);
5623 + if (au_ibtop(dir) == cpg->bdst)
5624 + au_cpup_attr_nlink(dir, /*force*/1);
5625 + inode = d_inode(cpg->dentry);
5626 + au_cpup_attr_nlink(inode, /*force*/1);
5632 +static noinline_for_stack
5633 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5634 + struct au_cpup_reg_attr *h_src_attr)
5638 + unsigned int mnt_flags;
5639 + unsigned char isdir, isreg, force;
5640 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5641 + struct au_dtime dt;
5642 + struct path h_path;
5643 + struct dentry *h_src, *h_dst, *h_parent;
5644 + struct inode *h_inode, *h_dir;
5645 + struct super_block *sb;
5647 + /* bsrc branch can be ro/rw. */
5648 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5649 + h_inode = d_inode(h_src);
5650 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5652 + /* try stopping to be referenced while we are creating */
5653 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5654 + if (au_ftest_cpup(cpg->flags, RENAME))
5655 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5656 + AUFS_WH_PFX_LEN));
5657 + h_parent = h_dst->d_parent; /* dir inode is locked */
5658 + h_dir = d_inode(h_parent);
5660 + AuDebugOn(h_parent != h_dst->d_parent);
5662 + sb = cpg->dentry->d_sb;
5663 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5665 + h_path.dentry = h_parent;
5666 + au_dtime_store(&dt, dst_parent, &h_path);
5668 + h_path.dentry = h_dst;
5672 + mode = h_inode->i_mode;
5673 + switch (mode & S_IFMT) {
5676 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5677 + /*want_excl*/true);
5679 + err = au_do_cpup_regular(cpg, h_src_attr);
5683 + err = vfsub_mkdir(h_dir, &h_path, mode);
5685 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5688 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5692 + AuDebugOn(!capable(CAP_MKNOD));
5696 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5699 + AuIOErr("Unknown inode type 0%o\n", mode);
5703 + err = au_reset_acl(h_dir, &h_path, mode);
5705 + mnt_flags = au_mntflags(sb);
5706 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5708 + && au_opt_test(mnt_flags, XINO)
5709 + && (h_inode->i_nlink == 1
5710 + || (h_inode->i_state & I_LINKABLE))
5711 + /* todo: unnecessary? */
5712 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5713 + && cpg->bdst < cpg->bsrc
5714 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5715 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5716 + /* ignore this error */
5721 + force = !!cpg->len;
5722 + if (cpg->len == -1)
5723 + force = !!i_size_read(h_inode);
5725 + au_fhsm_wrote(sb, cpg->bdst, force);
5729 + au_dtime_revert(&dt);
5733 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5736 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5737 + struct inode *h_dir;
5738 + aufs_bindex_t bdst;
5740 + dentry = cpg->dentry;
5742 + h_dentry = au_h_dptr(dentry, bdst);
5743 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5745 + au_set_h_dptr(dentry, bdst, NULL);
5746 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5748 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5749 + au_set_h_dptr(dentry, bdst, h_dentry);
5752 + parent = dget_parent(dentry);
5753 + h_parent = au_h_dptr(parent, bdst);
5755 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5756 + if (IS_ERR(h_path->dentry))
5757 + err = PTR_ERR(h_path->dentry);
5759 + if (unlikely(err))
5762 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5763 + h_dir = d_inode(h_parent);
5765 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5766 + /* no delegation since it is just created */
5767 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5769 + dput(h_path->dentry);
5776 + * copyup the @dentry from @bsrc to @bdst.
5777 + * the caller must set the both of lower dentries.
5778 + * @len is for truncating when it is -1 copyup the entire file.
5779 + * in link/rename cases, @dst_parent may be different from the real one.
5780 + * basic->bsrc can be larger than basic->bdst.
5781 + * aufs doesn't touch the credential so
5782 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5784 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5787 + aufs_bindex_t old_ibtop;
5788 + unsigned char isdir, plink;
5789 + struct dentry *h_src, *h_dst, *h_parent;
5790 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5791 + struct super_block *sb;
5792 + struct au_branch *br;
5793 + /* to reuduce stack size */
5795 + struct au_dtime dt;
5796 + struct path h_path;
5797 + struct au_cpup_reg_attr h_src_attr;
5801 + a = kmalloc(sizeof(*a), GFP_NOFS);
5804 + a->h_src_attr.valid = 0;
5806 + sb = cpg->dentry->d_sb;
5807 + br = au_sbr(sb, cpg->bdst);
5808 + a->h_path.mnt = au_br_mnt(br);
5809 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5810 + h_parent = h_dst->d_parent; /* dir inode is locked */
5811 + h_dir = d_inode(h_parent);
5814 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5815 + inode = d_inode(cpg->dentry);
5818 + dst_parent = dget_parent(cpg->dentry);
5822 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5823 + dst_inode = au_h_iptr(inode, cpg->bdst);
5825 + if (unlikely(!plink)) {
5827 + AuIOErr("hi%lu(i%lu) exists on b%d "
5828 + "but plink is disabled\n",
5829 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5833 + if (dst_inode->i_nlink) {
5834 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5836 + h_src = au_plink_lkup(inode, cpg->bdst);
5837 + err = PTR_ERR(h_src);
5838 + if (IS_ERR(h_src))
5840 + if (unlikely(d_is_negative(h_src))) {
5842 + AuIOErr("i%lu exists on b%d "
5843 + "but not pseudo-linked\n",
5844 + inode->i_ino, cpg->bdst);
5850 + a->h_path.dentry = h_parent;
5851 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5854 + a->h_path.dentry = h_dst;
5856 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5857 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5858 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5860 + au_dtime_revert(&a->dt);
5861 + if (unlikely(err == -EWOULDBLOCK)) {
5862 + pr_warn("cannot retry for NFSv4 delegation"
5863 + " for an internal link\n");
5869 + /* todo: cpup_wh_file? */
5871 + au_update_ibrange(inode, /*do_put_zero*/1);
5874 + isdir = S_ISDIR(inode->i_mode);
5875 + old_ibtop = au_ibtop(inode);
5876 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5877 + if (unlikely(err))
5879 + dst_inode = d_inode(h_dst);
5880 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5881 + /* todo: necessary? */
5882 + /* au_pin_hdir_unlock(cpg->pin); */
5884 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5885 + if (unlikely(err)) {
5886 + /* todo: necessary? */
5887 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5888 + inode_unlock(dst_inode);
5892 + if (cpg->bdst < old_ibtop) {
5893 + if (S_ISREG(inode->i_mode)) {
5894 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5895 + if (unlikely(err)) {
5896 + /* ignore an error */
5897 + /* au_pin_hdir_relock(cpg->pin); */
5898 + inode_unlock(dst_inode);
5902 + au_set_ibtop(inode, cpg->bdst);
5904 + au_set_ibbot(inode, cpg->bdst);
5905 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5906 + au_hi_flags(inode, isdir));
5908 + /* todo: necessary? */
5909 + /* err = au_pin_hdir_relock(cpg->pin); */
5910 + inode_unlock(dst_inode);
5911 + if (unlikely(err))
5914 + src_inode = d_inode(h_src);
5916 + && (src_inode->i_nlink > 1
5917 + || src_inode->i_state & I_LINKABLE)
5919 + au_plink_append(inode, cpg->bdst, h_dst);
5921 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5922 + a->h_path.dentry = h_dst;
5923 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5926 + goto out_parent; /* success */
5930 + a->h_path.dentry = h_parent;
5931 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5932 + a->h_path.dentry = h_dst;
5934 + if (d_is_positive(h_dst)) {
5936 + /* no delegation since it is just created */
5937 + rerr = vfsub_unlink(h_dir, &a->h_path,
5938 + /*delegated*/NULL, /*force*/0);
5940 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5942 + au_dtime_revert(&a->dt);
5944 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5954 +#if 0 /* reserved */
5955 +struct au_cpup_single_args {
5957 + struct au_cp_generic *cpg;
5958 + struct dentry *dst_parent;
5961 +static void au_call_cpup_single(void *args)
5963 + struct au_cpup_single_args *a = args;
5965 + au_pin_hdir_acquire_nest(a->cpg->pin);
5966 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5967 + au_pin_hdir_release(a->cpg->pin);
5972 + * prevent SIGXFSZ in copy-up.
5973 + * testing CAP_MKNOD is for generic fs,
5974 + * but CAP_FSETID is for xfs only, currently.
5976 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5979 + struct super_block *sb;
5980 + struct inode *h_dir;
5983 + sb = au_pinned_parent(pin)->d_sb;
5984 + if (!au_wkq_test()
5985 + && (!au_sbi(sb)->si_plink_maint_pid
5986 + || au_plink_maint(sb, AuLock_NOPLM))) {
5987 + switch (mode & S_IFMT) {
5989 + /* no condition about RLIMIT_FSIZE and the file size */
5994 + do_sio = !capable(CAP_MKNOD);
5998 + do_sio = ((mode & (S_ISUID | S_ISGID))
5999 + && !capable(CAP_FSETID));
6000 + /* this workaround may be removed in the future */
6002 + h_dir = au_pinned_h_dir(pin);
6003 + do_sio = h_dir->i_mode & S_ISVTX;
6010 +#if 0 /* reserved */
6011 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
6014 + struct dentry *h_dentry;
6016 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
6017 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
6018 + err = au_cpup_single(cpg, dst_parent);
6020 + struct au_cpup_single_args args = {
6023 + .dst_parent = dst_parent
6025 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
6026 + if (unlikely(wkq_err))
6035 + * copyup the @dentry from the first active lower branch to @bdst,
6036 + * using au_cpup_single().
6038 +static int au_cpup_simple(struct au_cp_generic *cpg)
6041 + unsigned int flags_orig;
6042 + struct dentry *dentry;
6044 + AuDebugOn(cpg->bsrc < 0);
6046 + dentry = cpg->dentry;
6047 + DiMustWriteLock(dentry);
6049 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
6051 + flags_orig = cpg->flags;
6052 + au_fset_cpup(cpg->flags, RENAME);
6053 + err = au_cpup_single(cpg, NULL);
6054 + cpg->flags = flags_orig;
6056 + return 0; /* success */
6059 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6060 + au_set_dbtop(dentry, cpg->bsrc);
6066 +struct au_cpup_simple_args {
6068 + struct au_cp_generic *cpg;
6071 +static void au_call_cpup_simple(void *args)
6073 + struct au_cpup_simple_args *a = args;
6075 + au_pin_hdir_acquire_nest(a->cpg->pin);
6076 + *a->errp = au_cpup_simple(a->cpg);
6077 + au_pin_hdir_release(a->cpg->pin);
6080 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6083 + struct dentry *dentry, *parent;
6084 + struct file *h_file;
6085 + struct inode *h_dir;
6087 + dentry = cpg->dentry;
6089 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6090 + AuDebugOn(cpg->bsrc < 0);
6091 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6092 + err = PTR_ERR(h_file);
6093 + if (IS_ERR(h_file))
6097 + parent = dget_parent(dentry);
6098 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6099 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6100 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6101 + err = au_cpup_simple(cpg);
6103 + struct au_cpup_simple_args args = {
6107 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6108 + if (unlikely(wkq_err))
6114 + au_h_open_post(dentry, cpg->bsrc, h_file);
6120 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6122 + aufs_bindex_t bsrc, bbot;
6123 + struct dentry *dentry, *h_dentry;
6125 + if (cpg->bsrc < 0) {
6126 + dentry = cpg->dentry;
6127 + bbot = au_dbbot(dentry);
6128 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6129 + h_dentry = au_h_dptr(dentry, bsrc);
6131 + AuDebugOn(d_is_negative(h_dentry));
6135 + AuDebugOn(bsrc > bbot);
6138 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6139 + return au_do_sio_cpup_simple(cpg);
6142 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6144 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6145 + return au_do_sio_cpup_simple(cpg);
6148 +/* ---------------------------------------------------------------------- */
6151 + * copyup the deleted file for writing.
6153 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6154 + struct file *file)
6157 + unsigned int flags_orig;
6158 + aufs_bindex_t bsrc_orig;
6159 + struct au_dinfo *dinfo;
6161 + struct au_hdentry *hd;
6162 + struct dentry *h_dentry;
6165 + dinfo = au_di(cpg->dentry);
6166 + AuRwMustWriteLock(&dinfo->di_rwsem);
6168 + bsrc_orig = cpg->bsrc;
6169 + cpg->bsrc = dinfo->di_btop;
6170 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6171 + hdst.h_dentry = hdst.hd->hd_dentry;
6172 + hdst.hd->hd_dentry = wh_dentry;
6173 + dinfo->di_btop = cpg->bdst;
6175 + hsrc.h_dentry = NULL;
6177 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6178 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6179 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6181 + flags_orig = cpg->flags;
6182 + cpg->flags = !AuCpup_DTIME;
6183 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6184 + cpg->flags = flags_orig;
6187 + err = au_reopen_nondir(file);
6188 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6190 + hdst.hd->hd_dentry = hdst.h_dentry;
6191 + dinfo->di_btop = cpg->bsrc;
6192 + cpg->bsrc = bsrc_orig;
6197 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6200 + aufs_bindex_t bdst;
6201 + struct au_dtime dt;
6202 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6203 + struct au_branch *br;
6204 + struct path h_path;
6206 + dentry = cpg->dentry;
6208 + br = au_sbr(dentry->d_sb, bdst);
6209 + parent = dget_parent(dentry);
6210 + h_parent = au_h_dptr(parent, bdst);
6211 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6212 + err = PTR_ERR(wh_dentry);
6213 + if (IS_ERR(wh_dentry))
6216 + h_path.dentry = h_parent;
6217 + h_path.mnt = au_br_mnt(br);
6218 + au_dtime_store(&dt, parent, &h_path);
6219 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6220 + if (unlikely(err))
6224 + h_path.dentry = wh_dentry;
6225 + if (!d_is_dir(wh_dentry)) {
6226 + /* no delegation since it is just created */
6227 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6228 + /*delegated*/NULL, /*force*/0);
6230 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6231 + if (unlikely(err)) {
6232 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6236 + au_dtime_revert(&dt);
6237 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6246 +struct au_cpup_wh_args {
6248 + struct au_cp_generic *cpg;
6249 + struct file *file;
6252 +static void au_call_cpup_wh(void *args)
6254 + struct au_cpup_wh_args *a = args;
6256 + au_pin_hdir_acquire_nest(a->cpg->pin);
6257 + *a->errp = au_cpup_wh(a->cpg, a->file);
6258 + au_pin_hdir_release(a->cpg->pin);
6261 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6264 + aufs_bindex_t bdst;
6265 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6266 + struct inode *dir, *h_dir, *h_tmpdir;
6267 + struct au_wbr *wbr;
6268 + struct au_pin wh_pin, *pin_orig;
6270 + dentry = cpg->dentry;
6272 + parent = dget_parent(dentry);
6273 + dir = d_inode(parent);
6276 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6279 + if (!h_dir->i_nlink) {
6280 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6281 + h_orph = wbr->wbr_orph;
6283 + h_parent = dget(au_h_dptr(parent, bdst));
6284 + au_set_h_dptr(parent, bdst, dget(h_orph));
6285 + h_tmpdir = d_inode(h_orph);
6286 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6288 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6289 + /* todo: au_h_open_pre()? */
6291 + pin_orig = cpg->pin;
6292 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6293 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6294 + cpg->pin = &wh_pin;
6297 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6298 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6299 + err = au_cpup_wh(cpg, file);
6301 + struct au_cpup_wh_args args = {
6306 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6307 + if (unlikely(wkq_err))
6312 + inode_unlock(h_tmpdir);
6313 + /* todo: au_h_open_post()? */
6314 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6315 + au_set_h_dptr(parent, bdst, h_parent);
6316 + AuDebugOn(!pin_orig);
6317 + cpg->pin = pin_orig;
6325 +/* ---------------------------------------------------------------------- */
6328 + * generic routine for both of copy-up and copy-down.
6330 +/* cf. revalidate function in file.c */
6331 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6332 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6333 + struct au_pin *pin,
6334 + struct dentry *h_parent, void *arg),
6338 + struct au_pin pin;
6339 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6342 + parent = dget_parent(dentry);
6343 + if (IS_ROOT(parent))
6346 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6347 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6349 + /* do not use au_dpage */
6350 + real_parent = parent;
6353 + parent = dget_parent(dentry);
6354 + h_parent = au_h_dptr(parent, bdst);
6356 + goto out; /* success */
6358 + /* find top dir which is necessary to cpup */
6362 + parent = dget_parent(d);
6363 + di_read_lock_parent3(parent, !AuLock_IR);
6364 + h_parent = au_h_dptr(parent, bdst);
6365 + di_read_unlock(parent, !AuLock_IR);
6366 + } while (!h_parent);
6368 + if (d != real_parent)
6369 + di_write_lock_child3(d);
6371 + /* somebody else might create while we were sleeping */
6372 + h_dentry = au_h_dptr(d, bdst);
6373 + if (!h_dentry || d_is_negative(h_dentry)) {
6375 + au_update_dbtop(d);
6377 + au_pin_set_dentry(&pin, d);
6378 + err = au_do_pin(&pin);
6380 + err = cp(d, bdst, &pin, h_parent, arg);
6385 + if (d != real_parent)
6386 + di_write_unlock(d);
6387 + if (unlikely(err))
6396 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6397 + struct au_pin *pin,
6398 + struct dentry *h_parent __maybe_unused,
6399 + void *arg __maybe_unused)
6401 + struct au_cp_generic cpg = {
6407 + .flags = AuCpup_DTIME
6409 + return au_sio_cpup_simple(&cpg);
6412 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6414 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6417 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6420 + struct dentry *parent;
6421 + struct inode *dir;
6423 + parent = dget_parent(dentry);
6424 + dir = d_inode(parent);
6426 + if (au_h_iptr(dir, bdst))
6429 + di_read_unlock(parent, AuLock_IR);
6430 + di_write_lock_parent(parent);
6431 + /* someone else might change our inode while we were sleeping */
6432 + if (!au_h_iptr(dir, bdst))
6433 + err = au_cpup_dirs(dentry, bdst);
6434 + di_downgrade_lock(parent, AuLock_IR);
6440 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6441 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6442 +++ linux/fs/aufs/cpup.h 2018-07-19 09:46:13.056647808 +0200
6444 +/* SPDX-License-Identifier: GPL-2.0 */
6446 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6448 + * This program, aufs is free software; you can redistribute it and/or modify
6449 + * it under the terms of the GNU General Public License as published by
6450 + * the Free Software Foundation; either version 2 of the License, or
6451 + * (at your option) any later version.
6453 + * This program is distributed in the hope that it will be useful,
6454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6456 + * GNU General Public License for more details.
6458 + * You should have received a copy of the GNU General Public License
6459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6463 + * copy-up/down functions
6466 +#ifndef __AUFS_CPUP_H__
6467 +#define __AUFS_CPUP_H__
6471 +#include <linux/path.h>
6477 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6478 +void au_cpup_attr_timesizes(struct inode *inode);
6479 +void au_cpup_attr_nlink(struct inode *inode, int force);
6480 +void au_cpup_attr_changeable(struct inode *inode);
6481 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6482 +void au_cpup_attr_all(struct inode *inode, int force);
6484 +/* ---------------------------------------------------------------------- */
6486 +struct au_cp_generic {
6487 + struct dentry *dentry;
6488 + aufs_bindex_t bdst, bsrc;
6490 + struct au_pin *pin;
6491 + unsigned int flags;
6495 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6496 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6498 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6499 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6501 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6503 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6504 + the branch is marked as RO */
6506 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6507 +#undef AuCpup_HOPEN
6508 +#define AuCpup_HOPEN 0
6511 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6512 +#define au_fset_cpup(flags, name) \
6513 + do { (flags) |= AuCpup_##name; } while (0)
6514 +#define au_fclr_cpup(flags, name) \
6515 + do { (flags) &= ~AuCpup_##name; } while (0)
6517 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6518 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6519 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6520 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6522 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6523 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6524 + struct au_pin *pin,
6525 + struct dentry *h_parent, void *arg),
6527 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6528 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6530 +/* ---------------------------------------------------------------------- */
6532 +/* keep timestamps when copyup */
6534 + struct dentry *dt_dentry;
6535 + struct path dt_h_path;
6536 + struct timespec dt_atime, dt_mtime;
6538 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6539 + struct path *h_path);
6540 +void au_dtime_revert(struct au_dtime *dt);
6542 +#endif /* __KERNEL__ */
6543 +#endif /* __AUFS_CPUP_H__ */
6544 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6545 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6546 +++ linux/fs/aufs/dbgaufs.c 2018-07-19 09:46:13.056647808 +0200
6548 +/* SPDX-License-Identifier: GPL-2.0 */
6550 + * Copyright (C) 2005-2018 Junjiro R. Okajima
6552 + * This program, aufs is free software; you can redistribute it and/or modify
6553 + * it under the terms of the GNU General Public License as published by
6554 + * the Free Software Foundation; either version 2 of the License, or
6555 + * (at your option) any later version.
6557 + * This program is distributed in the hope that it will be useful,
6558 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6559 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6560 + * GNU General Public License for more details.
6562 + * You should have received a copy of the GNU General Public License
6563 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6567 + * debugfs interface
6570 +#include <linux/debugfs.h>
6573 +#ifndef CONFIG_SYSFS
6574 +#error DEBUG_FS depends upon SYSFS
6577 +static struct dentry *dbgaufs;
6578 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6580 +/* 20 is max digits length of ulong 64 */
6581 +struct dbgaufs_arg {
6587 + * common function for all XINO files
6589 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6590 + struct file *file)
6592 + kfree(file->private_data);
6596 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6601 + struct dbgaufs_arg *p;
6604 + p = kmalloc(sizeof(*p), GFP_NOFS);
6610 + file->private_data = p;
6614 + err = vfsub_getattr(&xf->f_path, &st);
6618 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6619 + cnt, st.blocks, st.blksize,
6620 + (long long)st.size);
6622 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6623 + st.blocks, st.blksize,
6624 + (long long)st.size);
6625 + AuDebugOn(p->n >= sizeof(p->a));
6627 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6636 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6637 + size_t count, loff_t *ppos)
6639 + struct dbgaufs_arg *p;
6641 + p = file->private_data;
6642 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6645 +/* ---------------------------------------------------------------------- */
6647 +struct dbgaufs_plink_arg {
6652 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6653 + struct file *file)
6655 + free_page((unsigned long)file->private_data);
6659 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6661 + int err, i, limit;
6662 + unsigned long n, sum;
6663 + struct dbgaufs_plink_arg *p;
6664 + struct au_sbinfo *sbinfo;
6665 + struct super_block *sb;
6666 + struct hlist_bl_head *hbl;
6669 + p = (void *)get_zeroed_page(GFP_NOFS);
6674 + sbinfo = inode->i_private;
6675 + sb = sbinfo->si_sb;
6676 + si_noflush_read_lock(sb);
6677 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6678 + limit = PAGE_SIZE - sizeof(p->n);
6680 + /* the number of buckets */
6681 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6686 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6688 + n = au_hbl_count(hbl);
6691 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6694 + if (unlikely(limit <= 0))
6697 + p->a[p->n - 1] = '\n';
6699 + /* the sum of plinks */
6700 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6703 + if (unlikely(limit <= 0))
6706 +#define str "1\n0\n0\n"
6707 + p->n = sizeof(str) - 1;
6708 + strcpy(p->a, str);
6711 + si_read_unlock(sb);
6714 + file->private_data = p;
6715 + goto out; /* success */
6718 + free_page((unsigned long)p);
6723 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6724 + size_t count, loff_t *ppos)
6726 + struct dbgaufs_plink_arg *p;
6728 + p = file->private_data;
6729 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6732 +static const struct file_operations dbgaufs_plink_fop = {
6733 + .owner = THIS_MODULE,
6734 + .open = dbgaufs_plink_open,
6735 + .release = dbgaufs_plink_release,
6736 + .read = dbgaufs_plink_read
6739 +/* ---------------------------------------------------------------------- */
6741 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6744 + struct au_sbinfo *sbinfo;
6745 + struct super_block *sb;
6747 + sbinfo = inode->i_private;
6748 + sb = sbinfo->si_sb;
6749 + si_noflush_read_lock(sb);
6750 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6751 + si_read_unlock(sb);
6755 +static const struct file_operations dbgaufs_xib_fop = {
6756 + .owner = THIS_MODULE,
6757 + .open = dbgaufs_xib_open,
6758 + .release = dbgaufs_xi_release,
6759 + .read = dbgaufs_xi_read
6762 +/* ---------------------------------------------------------------------- */
6764 +#define DbgaufsXi_PREFIX "xi"
6766 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6770 + struct au_sbinfo *sbinfo;
6771 + struct super_block *sb;
6773 + struct qstr *name;
6774 + struct au_branch *br;
6778 + name = &file->f_path.dentry->d_name;
6779 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6780 + || memcmp(name->name, DbgaufsXi_PREFIX,
6781 + sizeof(DbgaufsXi_PREFIX) - 1)))
6783 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6784 + if (unlikely(err))
6787 + sbinfo = inode->i_private;
6788 + sb = sbinfo->si_sb;
6789 + si_noflush_read_lock(sb);
6790 + if (l <= au_sbbot(sb)) {
6791 + br = au_sbr(sb, (aufs_bindex_t)l);
6792 + xf = au_xino_file(br);
6793 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6794 + au_xino_count(br));
6797 + si_read_unlock(sb);
6803 +static const struct file_operations dbgaufs_xino_fop = {
6804 + .owner = THIS_MODULE,
6805 + .open = dbgaufs_xino_open,
6806 + .release = dbgaufs_xi_release,
6807 + .read = dbgaufs_xi_read
6810 +void dbgaufs_xino_del(struct au_branch *br)
6812 + struct dentry *dbgaufs;
6814 + dbgaufs = br->br_dbgaufs;
6818 + br->br_dbgaufs = NULL;
6819 + /* debugfs acquires the parent i_mutex */
6821 + debugfs_remove(dbgaufs);
6825 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6827 + aufs_bindex_t bbot;
6828 + struct au_branch *br;
6830 + if (!au_sbi(sb)->si_dbgaufs)
6833 + bbot = au_sbbot(sb);
6834 + for (; bindex <= bbot; bindex++) {
6835 + br = au_sbr(sb, bindex);
6836 + dbgaufs_xino_del(br);
6840 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6841 + struct dentry *parent, struct au_sbinfo *sbinfo)
6843 + struct au_branch *br;
6845 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6847 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6848 + br = au_sbr(sb, bindex);
6849 + if (br->br_dbgaufs) {
6850 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6852 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6853 + /* debugfs acquires the parent i_mutex */
6855 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6859 + pr_warn("failed renaming %pd/%s, ignored.\n",
6864 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6865 + sbinfo, &dbgaufs_xino_fop);
6867 + if (unlikely(!br->br_dbgaufs))
6868 + pr_warn("failed creaiting %pd/%s, ignored.\n",
6873 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6875 + struct au_sbinfo *sbinfo;
6876 + struct dentry *parent;
6877 + aufs_bindex_t bbot;
6879 + if (!au_opt_test(au_mntflags(sb), XINO))
6882 + sbinfo = au_sbi(sb);
6883 + parent = sbinfo->si_dbgaufs;
6887 + bbot = au_sbbot(sb);
6889 + for (; bindex <= bbot; bindex++)
6890 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6892 + for (; bbot >= bindex; bbot--)
6893 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6896 +/* ---------------------------------------------------------------------- */
6898 +#ifdef CONFIG_AUFS_EXPORT
6899 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6902 + struct au_sbinfo *sbinfo;
6903 + struct super_block *sb;
6905 + sbinfo = inode->i_private;
6906 + sb = sbinfo->si_sb;
6907 + si_noflush_read_lock(sb);
6908 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6909 + si_read_unlock(sb);
6913 +static const struct file_operations dbgaufs_xigen_fop = {
6914 + .owner = THIS_MODULE,
6915 + .open = dbgaufs_xigen_open,
6916 + .release = dbgaufs_xi_release,
6917 + .read = dbgaufs_xi_read
6920 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6925 + * This function is a dynamic '__init' function actually,
6926 + * so the tiny check for si_rwsem is unnecessary.
6928 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6931 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6932 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6933 + &dbgaufs_xigen_fop);
6934 + if (sbinfo->si_dbgaufs_xigen)
6940 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6944 +#endif /* CONFIG_AUFS_EXPORT */
6946 +/* ---------------------------------------------------------------------- */
6948 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6951 + * This function is a dynamic '__fin' function actually,
6952 + * so the tiny check for si_rwsem is unnecessary.
6954 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6956 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6957 + sbinfo->si_dbgaufs = NULL;
6960 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6963 + char name[SysaufsSiNameLen];
6966 + * This function is a dynamic '__init' function actually,
6967 + * so the tiny check for si_rwsem is unnecessary.
6969 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6973 + AuErr1("/debug/aufs is uninitialized\n");
6978 + sysaufs_name(sbinfo, name);
6979 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6980 + if (unlikely(!sbinfo->si_dbgaufs))
6983 + /* regardless plink/noplink option */
6984 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6985 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6986 + &dbgaufs_plink_fop);
6987 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6990 + /* regardless xino/noxino option */
6991 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6992 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6993 + &dbgaufs_xib_fop);
6994 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6997 + err = dbgaufs_xigen_init(sbinfo);
6999 + goto out; /* success */
7002 + dbgaufs_si_fin(sbinfo);
7004 + if (unlikely(err))
7005 + pr_err("debugfs/aufs failed\n");
7009 +/* ---------------------------------------------------------------------- */
7011 +void dbgaufs_fin(void)
7013 + debugfs_remove(dbgaufs);
7016 +int __init dbgaufs_init(void)
7021 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7026 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7027 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7028 +++ linux/fs/aufs/dbgaufs.h 2018-07-19 09:46:13.056647808 +0200
7030 +/* SPDX-License-Identifier: GPL-2.0 */
7032 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7034 + * This program, aufs is free software; you can redistribute it and/or modify
7035 + * it under the terms of the GNU General Public License as published by
7036 + * the Free Software Foundation; either version 2 of the License, or
7037 + * (at your option) any later version.
7039 + * This program is distributed in the hope that it will be useful,
7040 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7041 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7042 + * GNU General Public License for more details.
7044 + * You should have received a copy of the GNU General Public License
7045 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7049 + * debugfs interface
7052 +#ifndef __DBGAUFS_H__
7053 +#define __DBGAUFS_H__
7057 +struct super_block;
7061 +#ifdef CONFIG_DEBUG_FS
7063 +void dbgaufs_xino_del(struct au_branch *br);
7064 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7065 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7066 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7067 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7068 +void dbgaufs_fin(void);
7069 +int __init dbgaufs_init(void);
7071 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7072 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7073 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7075 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7076 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7077 +AuStubVoid(dbgaufs_fin, void)
7078 +AuStubInt0(__init dbgaufs_init, void)
7079 +#endif /* CONFIG_DEBUG_FS */
7081 +#endif /* __KERNEL__ */
7082 +#endif /* __DBGAUFS_H__ */
7083 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7084 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7085 +++ linux/fs/aufs/dcsub.c 2018-07-19 09:46:13.056647808 +0200
7087 +/* SPDX-License-Identifier: GPL-2.0 */
7089 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7091 + * This program, aufs is free software; you can redistribute it and/or modify
7092 + * it under the terms of the GNU General Public License as published by
7093 + * the Free Software Foundation; either version 2 of the License, or
7094 + * (at your option) any later version.
7096 + * This program is distributed in the hope that it will be useful,
7097 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7099 + * GNU General Public License for more details.
7101 + * You should have received a copy of the GNU General Public License
7102 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7106 + * sub-routines for dentry cache
7111 +static void au_dpage_free(struct au_dpage *dpage)
7114 + struct dentry **p;
7116 + p = dpage->dentries;
7117 + for (i = 0; i < dpage->ndentry; i++)
7119 + free_page((unsigned long)dpage->dentries);
7122 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7128 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7129 + if (unlikely(!dpages->dpages))
7132 + p = (void *)__get_free_page(gfp);
7136 + dpages->dpages[0].ndentry = 0;
7137 + dpages->dpages[0].dentries = p;
7138 + dpages->ndpage = 1;
7139 + return 0; /* success */
7142 + kfree(dpages->dpages);
7147 +void au_dpages_free(struct au_dcsub_pages *dpages)
7150 + struct au_dpage *p;
7152 + p = dpages->dpages;
7153 + for (i = 0; i < dpages->ndpage; i++)
7154 + au_dpage_free(p++);
7155 + kfree(dpages->dpages);
7158 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7159 + struct dentry *dentry, gfp_t gfp)
7162 + struct au_dpage *dpage;
7165 + dpage = dpages->dpages + dpages->ndpage - 1;
7166 + sz = PAGE_SIZE / sizeof(dentry);
7167 + if (unlikely(dpage->ndentry >= sz)) {
7168 + AuLabel(new dpage);
7170 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7171 + p = au_kzrealloc(dpages->dpages, sz,
7172 + sz + sizeof(*dpages->dpages), gfp,
7177 + dpages->dpages = p;
7178 + dpage = dpages->dpages + dpages->ndpage;
7179 + p = (void *)__get_free_page(gfp);
7183 + dpage->ndentry = 0;
7184 + dpage->dentries = p;
7188 + AuDebugOn(au_dcount(dentry) <= 0);
7189 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7190 + return 0; /* success */
7196 +/* todo: BAD approach */
7197 +/* copied from linux/fs/dcache.c */
7205 +extern void d_walk(struct dentry *parent, void *data,
7206 + enum d_walk_ret (*enter)(void *, struct dentry *),
7207 + void (*finish)(void *));
7209 +struct ac_dpages_arg {
7211 + struct au_dcsub_pages *dpages;
7212 + struct super_block *sb;
7213 + au_dpages_test test;
7217 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7219 + enum d_walk_ret ret;
7220 + struct ac_dpages_arg *arg = _arg;
7222 + ret = D_WALK_CONTINUE;
7223 + if (dentry->d_sb == arg->sb
7224 + && !IS_ROOT(dentry)
7225 + && au_dcount(dentry) > 0
7227 + && (!arg->test || arg->test(dentry, arg->arg))) {
7228 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7229 + if (unlikely(arg->err))
7230 + ret = D_WALK_QUIT;
7236 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7237 + au_dpages_test test, void *arg)
7239 + struct ac_dpages_arg args = {
7247 + d_walk(root, &args, au_call_dpages_append, NULL);
7252 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7253 + int do_include, au_dpages_test test, void *arg)
7258 + write_seqlock(&rename_lock);
7259 + spin_lock(&dentry->d_lock);
7261 + && au_dcount(dentry) > 0
7262 + && (!test || test(dentry, arg)))
7263 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7264 + spin_unlock(&dentry->d_lock);
7265 + if (unlikely(err))
7269 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7272 + while (!IS_ROOT(dentry)) {
7273 + dentry = dentry->d_parent; /* rename_lock is locked */
7274 + spin_lock(&dentry->d_lock);
7275 + if (au_dcount(dentry) > 0
7276 + && (!test || test(dentry, arg)))
7277 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7278 + spin_unlock(&dentry->d_lock);
7279 + if (unlikely(err))
7284 + write_sequnlock(&rename_lock);
7288 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7290 + return au_di(dentry) && dentry->d_sb == arg;
7293 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7294 + struct dentry *dentry, int do_include)
7296 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7297 + au_dcsub_dpages_aufs, dentry->d_sb);
7300 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7302 + struct path path[2] = {
7311 + return path_is_under(path + 0, path + 1);
7313 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7314 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7315 +++ linux/fs/aufs/dcsub.h 2018-07-19 09:46:13.056647808 +0200
7317 +/* SPDX-License-Identifier: GPL-2.0 */
7319 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7321 + * This program, aufs is free software; you can redistribute it and/or modify
7322 + * it under the terms of the GNU General Public License as published by
7323 + * the Free Software Foundation; either version 2 of the License, or
7324 + * (at your option) any later version.
7326 + * This program is distributed in the hope that it will be useful,
7327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7329 + * GNU General Public License for more details.
7331 + * You should have received a copy of the GNU General Public License
7332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7336 + * sub-routines for dentry cache
7339 +#ifndef __AUFS_DCSUB_H__
7340 +#define __AUFS_DCSUB_H__
7344 +#include <linux/dcache.h>
7345 +#include <linux/fs.h>
7349 + struct dentry **dentries;
7352 +struct au_dcsub_pages {
7354 + struct au_dpage *dpages;
7357 +/* ---------------------------------------------------------------------- */
7360 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7361 +void au_dpages_free(struct au_dcsub_pages *dpages);
7362 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7363 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7364 + au_dpages_test test, void *arg);
7365 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7366 + int do_include, au_dpages_test test, void *arg);
7367 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7368 + struct dentry *dentry, int do_include);
7369 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7371 +/* ---------------------------------------------------------------------- */
7374 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7375 + * include/linux/dcache.h. Try them (in the future).
7378 +static inline int au_d_hashed_positive(struct dentry *d)
7381 + struct inode *inode = d_inode(d);
7384 + if (unlikely(d_unhashed(d)
7385 + || d_is_negative(d)
7386 + || !inode->i_nlink))
7391 +static inline int au_d_linkable(struct dentry *d)
7394 + struct inode *inode = d_inode(d);
7396 + err = au_d_hashed_positive(d);
7398 + && d_is_positive(d)
7399 + && (inode->i_state & I_LINKABLE))
7404 +static inline int au_d_alive(struct dentry *d)
7407 + struct inode *inode;
7411 + err = au_d_hashed_positive(d);
7413 + inode = d_inode(d);
7414 + if (unlikely(d_unlinked(d)
7415 + || d_is_negative(d)
7416 + || !inode->i_nlink))
7422 +static inline int au_alive_dir(struct dentry *d)
7426 + err = au_d_alive(d);
7427 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7432 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7434 + return a->len == b->len
7435 + && !memcmp(a->name, b->name, a->len);
7440 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7442 + * the type of d_lockref.count became int, but the inlined function d_count()
7443 + * still returns unsigned int.
7444 + * I don't know why. Maybe it is for every d_count() users?
7445 + * Anyway au_dcount() lives on.
7447 +static inline int au_dcount(struct dentry *d)
7449 + return (int)d_count(d);
7452 +#endif /* __KERNEL__ */
7453 +#endif /* __AUFS_DCSUB_H__ */
7454 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7455 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7456 +++ linux/fs/aufs/debug.c 2018-07-19 09:46:13.056647808 +0200
7458 +/* SPDX-License-Identifier: GPL-2.0 */
7460 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7462 + * This program, aufs is free software; you can redistribute it and/or modify
7463 + * it under the terms of the GNU General Public License as published by
7464 + * the Free Software Foundation; either version 2 of the License, or
7465 + * (at your option) any later version.
7467 + * This program is distributed in the hope that it will be useful,
7468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7470 + * GNU General Public License for more details.
7472 + * You should have received a copy of the GNU General Public License
7473 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7477 + * debug print functions
7482 +/* Returns 0, or -errno. arg is in kp->arg. */
7483 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7487 + err = kstrtoint(val, 0, &n);
7497 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7498 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7503 + return sprintf(buffer, "%d", atomic_read(a));
7506 +static struct kernel_param_ops param_ops_atomic_t = {
7507 + .set = param_atomic_t_set,
7508 + .get = param_atomic_t_get
7509 + /* void (*free)(void *arg) */
7512 +atomic_t aufs_debug = ATOMIC_INIT(0);
7513 +MODULE_PARM_DESC(debug, "debug print");
7514 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7516 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7517 +char *au_plevel = KERN_DEBUG;
7518 +#define dpri(fmt, ...) do { \
7520 + && strcmp(au_plevel, KERN_DEBUG)) \
7521 + || au_debug_test()) \
7522 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7525 +/* ---------------------------------------------------------------------- */
7527 +void au_dpri_whlist(struct au_nhash *whlist)
7529 + unsigned long ul, n;
7530 + struct hlist_head *head;
7531 + struct au_vdir_wh *pos;
7533 + n = whlist->nh_num;
7534 + head = whlist->nh_head;
7535 + for (ul = 0; ul < n; ul++) {
7536 + hlist_for_each_entry(pos, head, wh_hash)
7537 + dpri("b%d, %.*s, %d\n",
7539 + pos->wh_str.len, pos->wh_str.name,
7545 +void au_dpri_vdir(struct au_vdir *vdir)
7548 + union au_vdir_deblk_p p;
7551 + if (!vdir || IS_ERR(vdir)) {
7552 + dpri("err %ld\n", PTR_ERR(vdir));
7556 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7557 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7558 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7559 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7560 + p.deblk = vdir->vd_deblk[ul];
7562 + dpri("[%lu]: %p\n", ul, o);
7566 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7567 + struct dentry *wh)
7572 + if (!inode || IS_ERR(inode)) {
7573 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7577 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7578 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7579 + && sizeof(inode->i_blocks) != sizeof(u64));
7581 + n = (void *)wh->d_name.name;
7582 + l = wh->d_name.len;
7585 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7586 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7588 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7589 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7590 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7591 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7592 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7593 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7594 + inode->i_generation,
7595 + l ? ", wh " : "", l, n);
7599 +void au_dpri_inode(struct inode *inode)
7601 + struct au_iinfo *iinfo;
7602 + struct au_hinode *hi;
7603 + aufs_bindex_t bindex;
7606 + err = do_pri_inode(-1, inode, -1, NULL);
7607 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7610 + iinfo = au_ii(inode);
7611 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7612 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7613 + if (iinfo->ii_btop < 0)
7616 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7617 + hi = au_hinode(iinfo, bindex);
7619 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7623 +void au_dpri_dalias(struct inode *inode)
7627 + spin_lock(&inode->i_lock);
7628 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7629 + au_dpri_dentry(d);
7630 + spin_unlock(&inode->i_lock);
7633 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7635 + struct dentry *wh = NULL;
7637 + struct inode *inode;
7638 + struct au_iinfo *iinfo;
7639 + struct au_hinode *hi;
7641 + if (!dentry || IS_ERR(dentry)) {
7642 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7645 + /* do not call dget_parent() here */
7646 + /* note: access d_xxx without d_lock */
7647 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7648 + bindex, dentry, dentry,
7649 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7650 + au_dcount(dentry), dentry->d_flags,
7651 + d_unhashed(dentry) ? "un" : "");
7654 + if (d_is_positive(dentry))
7655 + inode = d_inode(dentry);
7657 + && au_test_aufs(dentry->d_sb)
7659 + && !au_is_bad_inode(inode)) {
7660 + iinfo = au_ii(inode);
7661 + hi = au_hinode(iinfo, bindex);
7663 + wh = hi->hi_whdentry;
7665 + do_pri_inode(bindex, inode, hn, wh);
7669 +void au_dpri_dentry(struct dentry *dentry)
7671 + struct au_dinfo *dinfo;
7672 + aufs_bindex_t bindex;
7675 + err = do_pri_dentry(-1, dentry);
7676 + if (err || !au_test_aufs(dentry->d_sb))
7679 + dinfo = au_di(dentry);
7682 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7683 + dinfo->di_btop, dinfo->di_bbot,
7684 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7685 + dinfo->di_tmpfile);
7686 + if (dinfo->di_btop < 0)
7688 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7689 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7692 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7696 + if (!file || IS_ERR(file)) {
7697 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7702 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7703 + && au_test_aufs(file->f_path.dentry->d_sb)
7705 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7706 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7707 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7708 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7709 + file->f_version, file->f_pos, a);
7710 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7711 + do_pri_dentry(bindex, file->f_path.dentry);
7715 +void au_dpri_file(struct file *file)
7717 + struct au_finfo *finfo;
7718 + struct au_fidir *fidir;
7719 + struct au_hfile *hfile;
7720 + aufs_bindex_t bindex;
7723 + err = do_pri_file(-1, file);
7725 + || IS_ERR_OR_NULL(file->f_path.dentry)
7726 + || !au_test_aufs(file->f_path.dentry->d_sb))
7729 + finfo = au_fi(file);
7732 + if (finfo->fi_btop < 0)
7734 + fidir = finfo->fi_hdir;
7736 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7738 + for (bindex = finfo->fi_btop;
7739 + bindex >= 0 && bindex <= fidir->fd_bbot;
7741 + hfile = fidir->fd_hfile + bindex;
7742 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7746 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7748 + struct vfsmount *mnt;
7749 + struct super_block *sb;
7751 + if (!br || IS_ERR(br))
7753 + mnt = au_br_mnt(br);
7754 + if (!mnt || IS_ERR(mnt))
7757 + if (!sb || IS_ERR(sb))
7760 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7761 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7763 + bindex, br->br_perm, br->br_id, au_br_count(br),
7764 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7765 + sb->s_flags, sb->s_count,
7766 + atomic_read(&sb->s_active), !!au_xino_file(br));
7770 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7774 +void au_dpri_sb(struct super_block *sb)
7776 + struct au_sbinfo *sbinfo;
7777 + aufs_bindex_t bindex;
7779 + /* to reuduce stack size */
7781 + struct vfsmount mnt;
7782 + struct au_branch fake;
7785 + /* this function can be called from magic sysrq */
7786 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7787 + if (unlikely(!a)) {
7788 + dpri("no memory\n");
7792 + a->mnt.mnt_sb = sb;
7793 + a->fake.br_path.mnt = &a->mnt;
7794 + au_br_count_init(&a->fake);
7795 + err = do_pri_br(-1, &a->fake);
7796 + au_br_count_fin(&a->fake);
7798 + dpri("dev 0x%x\n", sb->s_dev);
7799 + if (err || !au_test_aufs(sb))
7802 + sbinfo = au_sbi(sb);
7805 + dpri("nw %d, gen %u, kobj %d\n",
7806 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7807 + kref_read(&sbinfo->si_kobj.kref));
7808 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7809 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7812 +/* ---------------------------------------------------------------------- */
7814 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7816 + struct inode *h_inode, *inode = d_inode(dentry);
7817 + struct dentry *h_dentry;
7818 + aufs_bindex_t bindex, bbot, bi;
7820 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7823 + bbot = au_dbbot(dentry);
7824 + bi = au_ibbot(inode);
7827 + bindex = au_dbtop(dentry);
7828 + bi = au_ibtop(inode);
7832 + for (; bindex <= bbot; bindex++) {
7833 + h_dentry = au_h_dptr(dentry, bindex);
7836 + h_inode = au_h_iptr(inode, bindex);
7837 + if (unlikely(h_inode != d_inode(h_dentry))) {
7839 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7840 + AuDbgDentry(dentry);
7841 + AuDbgInode(inode);
7848 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7851 + struct au_dcsub_pages dpages;
7852 + struct au_dpage *dpage;
7853 + struct dentry **dentries;
7855 + err = au_dpages_init(&dpages, GFP_NOFS);
7857 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7859 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7860 + dpage = dpages.dpages + i;
7861 + dentries = dpage->dentries;
7862 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7863 + AuDebugOn(au_digen_test(dentries[j], sigen));
7865 + au_dpages_free(&dpages);
7868 +void au_dbg_verify_kthread(void)
7870 + if (au_wkq_test()) {
7873 + * It may be recursive, but udba=notify between two aufs mounts,
7874 + * where a single ro branch is shared, is not a problem.
7880 +/* ---------------------------------------------------------------------- */
7882 +int __init au_debug_init(void)
7884 + aufs_bindex_t bindex;
7885 + struct au_vdir_destr destr;
7888 + AuDebugOn(bindex >= 0);
7891 + AuDebugOn(destr.len < NAME_MAX);
7893 +#ifdef CONFIG_4KSTACKS
7894 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7899 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7900 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7901 +++ linux/fs/aufs/debug.h 2018-07-19 09:46:13.056647808 +0200
7903 +/* SPDX-License-Identifier: GPL-2.0 */
7905 + * Copyright (C) 2005-2018 Junjiro R. Okajima
7907 + * This program, aufs is free software; you can redistribute it and/or modify
7908 + * it under the terms of the GNU General Public License as published by
7909 + * the Free Software Foundation; either version 2 of the License, or
7910 + * (at your option) any later version.
7912 + * This program is distributed in the hope that it will be useful,
7913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7915 + * GNU General Public License for more details.
7917 + * You should have received a copy of the GNU General Public License
7918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7922 + * debug print functions
7925 +#ifndef __AUFS_DEBUG_H__
7926 +#define __AUFS_DEBUG_H__
7930 +#include <linux/atomic.h>
7931 +#include <linux/module.h>
7932 +#include <linux/kallsyms.h>
7933 +#include <linux/sysrq.h>
7935 +#ifdef CONFIG_AUFS_DEBUG
7936 +#define AuDebugOn(a) BUG_ON(a)
7938 +/* module parameter */
7939 +extern atomic_t aufs_debug;
7940 +static inline void au_debug_on(void)
7942 + atomic_inc(&aufs_debug);
7944 +static inline void au_debug_off(void)
7946 + atomic_dec_if_positive(&aufs_debug);
7949 +static inline int au_debug_test(void)
7951 + return atomic_read(&aufs_debug) > 0;
7954 +#define AuDebugOn(a) do {} while (0)
7955 +AuStubVoid(au_debug_on, void)
7956 +AuStubVoid(au_debug_off, void)
7957 +AuStubInt0(au_debug_test, void)
7958 +#endif /* CONFIG_AUFS_DEBUG */
7960 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7962 +/* ---------------------------------------------------------------------- */
7966 +#define AuDbg(fmt, ...) do { \
7967 + if (au_debug_test()) \
7968 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7970 +#define AuLabel(l) AuDbg(#l "\n")
7971 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7972 +#define AuWarn1(fmt, ...) do { \
7973 + static unsigned char _c; \
7975 + pr_warn(fmt, ##__VA_ARGS__); \
7978 +#define AuErr1(fmt, ...) do { \
7979 + static unsigned char _c; \
7981 + pr_err(fmt, ##__VA_ARGS__); \
7984 +#define AuIOErr1(fmt, ...) do { \
7985 + static unsigned char _c; \
7987 + AuIOErr(fmt, ##__VA_ARGS__); \
7990 +#define AuUnsupportMsg "This operation is not supported." \
7991 + " Please report this application to aufs-users ML."
7992 +#define AuUnsupport(fmt, ...) do { \
7993 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7997 +#define AuTraceErr(e) do { \
7998 + if (unlikely((e) < 0)) \
7999 + AuDbg("err %d\n", (int)(e)); \
8002 +#define AuTraceErrPtr(p) do { \
8004 + AuDbg("err %ld\n", PTR_ERR(p)); \
8007 +/* dirty macros for debug print, use with "%.*s" and caution */
8008 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8010 +/* ---------------------------------------------------------------------- */
8013 +#ifdef CONFIG_AUFS_DEBUG
8014 +extern struct mutex au_dbg_mtx;
8015 +extern char *au_plevel;
8017 +void au_dpri_whlist(struct au_nhash *whlist);
8019 +void au_dpri_vdir(struct au_vdir *vdir);
8021 +void au_dpri_inode(struct inode *inode);
8022 +void au_dpri_dalias(struct inode *inode);
8023 +void au_dpri_dentry(struct dentry *dentry);
8025 +void au_dpri_file(struct file *filp);
8026 +struct super_block;
8027 +void au_dpri_sb(struct super_block *sb);
8029 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8030 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8031 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8032 +void au_dbg_verify_kthread(void);
8034 +int __init au_debug_init(void);
8036 +#define AuDbgWhlist(w) do { \
8037 + mutex_lock(&au_dbg_mtx); \
8039 + au_dpri_whlist(w); \
8040 + mutex_unlock(&au_dbg_mtx); \
8043 +#define AuDbgVdir(v) do { \
8044 + mutex_lock(&au_dbg_mtx); \
8046 + au_dpri_vdir(v); \
8047 + mutex_unlock(&au_dbg_mtx); \
8050 +#define AuDbgInode(i) do { \
8051 + mutex_lock(&au_dbg_mtx); \
8053 + au_dpri_inode(i); \
8054 + mutex_unlock(&au_dbg_mtx); \
8057 +#define AuDbgDAlias(i) do { \
8058 + mutex_lock(&au_dbg_mtx); \
8060 + au_dpri_dalias(i); \
8061 + mutex_unlock(&au_dbg_mtx); \
8064 +#define AuDbgDentry(d) do { \
8065 + mutex_lock(&au_dbg_mtx); \
8067 + au_dpri_dentry(d); \
8068 + mutex_unlock(&au_dbg_mtx); \
8071 +#define AuDbgFile(f) do { \
8072 + mutex_lock(&au_dbg_mtx); \
8074 + au_dpri_file(f); \
8075 + mutex_unlock(&au_dbg_mtx); \
8078 +#define AuDbgSb(sb) do { \
8079 + mutex_lock(&au_dbg_mtx); \
8080 + AuDbg(#sb "\n"); \
8082 + mutex_unlock(&au_dbg_mtx); \
8085 +#define AuDbgSym(addr) do { \
8086 + char sym[KSYM_SYMBOL_LEN]; \
8087 + sprint_symbol(sym, (unsigned long)addr); \
8088 + AuDbg("%s\n", sym); \
8091 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8092 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8093 +AuStubVoid(au_dbg_verify_kthread, void)
8094 +AuStubInt0(__init au_debug_init, void)
8096 +#define AuDbgWhlist(w) do {} while (0)
8097 +#define AuDbgVdir(v) do {} while (0)
8098 +#define AuDbgInode(i) do {} while (0)
8099 +#define AuDbgDAlias(i) do {} while (0)
8100 +#define AuDbgDentry(d) do {} while (0)
8101 +#define AuDbgFile(f) do {} while (0)
8102 +#define AuDbgSb(sb) do {} while (0)
8103 +#define AuDbgSym(addr) do {} while (0)
8104 +#endif /* CONFIG_AUFS_DEBUG */
8106 +/* ---------------------------------------------------------------------- */
8108 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8109 +int __init au_sysrq_init(void);
8110 +void au_sysrq_fin(void);
8112 +#ifdef CONFIG_HW_CONSOLE
8113 +#define au_dbg_blocked() do { \
8115 + handle_sysrq('w'); \
8118 +AuStubVoid(au_dbg_blocked, void)
8122 +AuStubInt0(__init au_sysrq_init, void)
8123 +AuStubVoid(au_sysrq_fin, void)
8124 +AuStubVoid(au_dbg_blocked, void)
8125 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8127 +#endif /* __KERNEL__ */
8128 +#endif /* __AUFS_DEBUG_H__ */
8129 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8130 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8131 +++ linux/fs/aufs/dentry.c 2018-07-19 09:46:13.056647808 +0200
8133 +/* SPDX-License-Identifier: GPL-2.0 */
8135 + * Copyright (C) 2005-2018 Junjiro R. Okajima
8137 + * This program, aufs is free software; you can redistribute it and/or modify
8138 + * it under the terms of the GNU General Public License as published by
8139 + * the Free Software Foundation; either version 2 of the License, or
8140 + * (at your option) any later version.
8142 + * This program is distributed in the hope that it will be useful,
8143 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8144 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8145 + * GNU General Public License for more details.
8147 + * You should have received a copy of the GNU General Public License
8148 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8152 + * lookup and dentry operations
8155 +#include <linux/namei.h>
8159 + * returns positive/negative dentry, NULL or an error.
8160 + * NULL means whiteout-ed or not-found.
8162 +static struct dentry*
8163 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8164 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8166 + struct dentry *h_dentry;
8167 + struct inode *h_inode;
8168 + struct au_branch *br;
8169 + int wh_found, opq;
8170 + unsigned char wh_able;
8171 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8172 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8176 + br = au_sbr(dentry->d_sb, bindex);
8177 + wh_able = !!au_br_whable(br->br_perm);
8179 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8180 + h_dentry = ERR_PTR(wh_found);
8183 + if (unlikely(wh_found < 0))
8186 + /* We found a whiteout */
8187 + /* au_set_dbbot(dentry, bindex); */
8188 + au_set_dbwh(dentry, bindex);
8190 + return NULL; /* success */
8194 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8196 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8197 + if (IS_ERR(h_dentry)) {
8198 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8204 + h_inode = d_inode(h_dentry);
8205 + if (d_is_negative(h_dentry)) {
8208 + } else if (wh_found
8209 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8211 + else if (au_ftest_lkup(args->flags, DIRREN)
8213 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8214 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8215 + (unsigned long long)h_inode->i_ino);
8219 + if (au_dbbot(dentry) <= bindex)
8220 + au_set_dbbot(dentry, bindex);
8221 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8222 + au_set_dbtop(dentry, bindex);
8223 + au_set_h_dptr(dentry, bindex, h_dentry);
8225 + if (!d_is_dir(h_dentry)
8227 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8228 + goto out; /* success */
8230 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8231 + opq = au_diropq_test(h_dentry);
8232 + inode_unlock_shared(h_inode);
8234 + au_set_dbdiropq(dentry, bindex);
8235 + else if (unlikely(opq < 0)) {
8236 + au_set_h_dptr(dentry, bindex, NULL);
8237 + h_dentry = ERR_PTR(opq);
8248 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8250 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8251 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8257 + * returns the number of lower positive dentries,
8258 + * otherwise an error.
8259 + * can be called at unlinking with @type is zero.
8261 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8262 + unsigned int flags)
8264 + int npositive, err;
8265 + aufs_bindex_t bindex, btail, bdiropq;
8266 + unsigned char isdir, dirperm1, dirren;
8267 + struct au_do_lookup_args args = {
8269 + .name = &dentry->d_name
8271 + struct dentry *parent;
8272 + struct super_block *sb;
8274 + sb = dentry->d_sb;
8275 + err = au_test_shwh(sb, args.name);
8276 + if (unlikely(err))
8279 + err = au_wh_name_alloc(&args.whname, args.name);
8280 + if (unlikely(err))
8283 + isdir = !!d_is_dir(dentry);
8284 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8285 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8287 + au_fset_lkup(args.flags, DIRREN);
8290 + parent = dget_parent(dentry);
8291 + btail = au_dbtaildir(parent);
8292 + for (bindex = btop; bindex <= btail; bindex++) {
8293 + struct dentry *h_parent, *h_dentry;
8294 + struct inode *h_inode, *h_dir;
8295 + struct au_branch *br;
8297 + h_dentry = au_h_dptr(dentry, bindex);
8299 + if (d_is_positive(h_dentry))
8303 + h_parent = au_h_dptr(parent, bindex);
8304 + if (!h_parent || !d_is_dir(h_parent))
8308 + /* if the inum matches, then use the prepared name */
8309 + err = au_dr_lkup_name(&args, bindex);
8310 + if (unlikely(err))
8314 + h_dir = d_inode(h_parent);
8315 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8316 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8317 + inode_unlock_shared(h_dir);
8318 + err = PTR_ERR(h_dentry);
8319 + if (IS_ERR(h_dentry))
8322 + au_fclr_lkup(args.flags, ALLOW_NEG);
8324 + au_fset_lkup(args.flags, IGNORE_PERM);
8326 + if (au_dbwh(dentry) == bindex)
8330 + if (d_is_negative(h_dentry))
8332 + h_inode = d_inode(h_dentry);
8335 + args.type = h_inode->i_mode & S_IFMT;
8336 + if (args.type != S_IFDIR)
8339 + /* the type of lower may be different */
8340 + bdiropq = au_dbdiropq(dentry);
8341 + if (bdiropq >= 0 && bdiropq <= bindex)
8344 + br = au_sbr(sb, bindex);
8346 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8347 + /*add_ent*/NULL)) {
8348 + /* prepare next name to lookup */
8349 + err = au_dr_lkup(&args, dentry, bindex);
8350 + if (unlikely(err))
8356 + AuLabel(positive);
8357 + au_update_dbtop(dentry);
8360 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8361 + && au_dbtop(dentry) < 0)) {
8363 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8369 + kfree(args.whname.name);
8371 + au_dr_lkup_fin(&args);
8376 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8378 + struct dentry *dentry;
8381 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8382 + dentry = vfsub_lkup_one(name, parent);
8384 + struct vfsub_lkup_one_args args = {
8390 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8391 + if (unlikely(wkq_err))
8392 + dentry = ERR_PTR(wkq_err);
8399 + * lookup @dentry on @bindex which should be negative.
8401 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8404 + struct dentry *parent, *h_parent, *h_dentry;
8405 + struct au_branch *br;
8407 + parent = dget_parent(dentry);
8408 + h_parent = au_h_dptr(parent, bindex);
8409 + br = au_sbr(dentry->d_sb, bindex);
8411 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8413 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8414 + err = PTR_ERR(h_dentry);
8415 + if (IS_ERR(h_dentry))
8417 + if (unlikely(d_is_positive(h_dentry))) {
8419 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8425 + if (bindex < au_dbtop(dentry))
8426 + au_set_dbtop(dentry, bindex);
8427 + if (au_dbbot(dentry) < bindex)
8428 + au_set_dbbot(dentry, bindex);
8429 + au_set_h_dptr(dentry, bindex, h_dentry);
8436 +/* ---------------------------------------------------------------------- */
8438 +/* subset of struct inode */
8440 + unsigned long i_ino;
8441 + /* unsigned int i_nlink; */
8447 + blkcnt_t i_blocks;
8452 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8454 + ia->i_ino = h_inode->i_ino;
8455 + /* ia->i_nlink = h_inode->i_nlink; */
8456 + ia->i_uid = h_inode->i_uid;
8457 + ia->i_gid = h_inode->i_gid;
8458 + ia->i_version = inode_query_iversion(h_inode);
8460 + ia->i_size = h_inode->i_size;
8461 + ia->i_blocks = h_inode->i_blocks;
8463 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8466 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8468 + return ia->i_ino != h_inode->i_ino
8469 + /* || ia->i_nlink != h_inode->i_nlink */
8470 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8471 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8472 + || !inode_eq_iversion(h_inode, ia->i_version)
8474 + || ia->i_size != h_inode->i_size
8475 + || ia->i_blocks != h_inode->i_blocks
8477 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8480 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8481 + struct au_branch *br)
8484 + struct au_iattr ia;
8485 + struct inode *h_inode;
8486 + struct dentry *h_d;
8487 + struct super_block *h_sb;
8490 + memset(&ia, -1, sizeof(ia));
8491 + h_sb = h_dentry->d_sb;
8493 + if (d_is_positive(h_dentry)) {
8494 + h_inode = d_inode(h_dentry);
8495 + au_iattr_save(&ia, h_inode);
8496 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8497 + /* nfs d_revalidate may return 0 for negative dentry */
8498 + /* fuse d_revalidate always return 0 for negative dentry */
8501 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8502 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8503 + err = PTR_ERR(h_d);
8508 + if (unlikely(h_d != h_dentry
8509 + || d_inode(h_d) != h_inode
8510 + || (h_inode && au_iattr_test(&ia, h_inode))))
8511 + err = au_busy_or_stale();
8519 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8520 + struct dentry *h_parent, struct au_branch *br)
8525 + if (udba == AuOpt_UDBA_REVAL
8526 + && !au_test_fs_remote(h_dentry->d_sb)) {
8528 + err = (d_inode(h_dentry->d_parent) != h_dir);
8529 + } else if (udba != AuOpt_UDBA_NONE)
8530 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8535 +/* ---------------------------------------------------------------------- */
8537 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8540 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8541 + struct au_hdentry tmp, *p, *q;
8542 + struct au_dinfo *dinfo;
8543 + struct super_block *sb;
8545 + DiMustWriteLock(dentry);
8547 + sb = dentry->d_sb;
8548 + dinfo = au_di(dentry);
8549 + bbot = dinfo->di_bbot;
8550 + bwh = dinfo->di_bwh;
8551 + bdiropq = dinfo->di_bdiropq;
8552 + bindex = dinfo->di_btop;
8553 + p = au_hdentry(dinfo, bindex);
8554 + for (; bindex <= bbot; bindex++, p++) {
8555 + if (!p->hd_dentry)
8558 + new_bindex = au_br_index(sb, p->hd_id);
8559 + if (new_bindex == bindex)
8562 + if (dinfo->di_bwh == bindex)
8564 + if (dinfo->di_bdiropq == bindex)
8565 + bdiropq = new_bindex;
8566 + if (new_bindex < 0) {
8568 + p->hd_dentry = NULL;
8572 + /* swap two lower dentries, and loop again */
8573 + q = au_hdentry(dinfo, new_bindex);
8577 + if (tmp.hd_dentry) {
8583 + dinfo->di_bwh = -1;
8584 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8585 + dinfo->di_bwh = bwh;
8587 + dinfo->di_bdiropq = -1;
8589 + && bdiropq <= au_sbbot(sb)
8590 + && au_sbr_whable(sb, bdiropq))
8591 + dinfo->di_bdiropq = bdiropq;
8594 + dinfo->di_btop = -1;
8595 + dinfo->di_bbot = -1;
8596 + bbot = au_dbbot(parent);
8598 + p = au_hdentry(dinfo, bindex);
8599 + for (; bindex <= bbot; bindex++, p++)
8600 + if (p->hd_dentry) {
8601 + dinfo->di_btop = bindex;
8605 + if (dinfo->di_btop >= 0) {
8607 + p = au_hdentry(dinfo, bindex);
8608 + for (; bindex >= 0; bindex--, p--)
8609 + if (p->hd_dentry) {
8610 + dinfo->di_bbot = bindex;
8619 +static void au_do_hide(struct dentry *dentry)
8621 + struct inode *inode;
8623 + if (d_really_is_positive(dentry)) {
8624 + inode = d_inode(dentry);
8625 + if (!d_is_dir(dentry)) {
8626 + if (inode->i_nlink && !d_unhashed(dentry))
8627 + drop_nlink(inode);
8629 + clear_nlink(inode);
8630 + /* stop next lookup */
8631 + inode->i_flags |= S_DEAD;
8633 + smp_mb(); /* necessary? */
8638 +static int au_hide_children(struct dentry *parent)
8640 + int err, i, j, ndentry;
8641 + struct au_dcsub_pages dpages;
8642 + struct au_dpage *dpage;
8643 + struct dentry *dentry;
8645 + err = au_dpages_init(&dpages, GFP_NOFS);
8646 + if (unlikely(err))
8648 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8649 + if (unlikely(err))
8652 + /* in reverse order */
8653 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8654 + dpage = dpages.dpages + i;
8655 + ndentry = dpage->ndentry;
8656 + for (j = ndentry - 1; j >= 0; j--) {
8657 + dentry = dpage->dentries[j];
8658 + if (dentry != parent)
8659 + au_do_hide(dentry);
8664 + au_dpages_free(&dpages);
8669 +static void au_hide(struct dentry *dentry)
8673 + AuDbgDentry(dentry);
8674 + if (d_is_dir(dentry)) {
8675 + /* shrink_dcache_parent(dentry); */
8676 + err = au_hide_children(dentry);
8677 + if (unlikely(err))
8678 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8681 + au_do_hide(dentry);
8685 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8687 + * a dirty branch is added
8688 + * - on the top of layers
8689 + * - in the middle of layers
8690 + * - to the bottom of layers
8692 + * on the added branch there exists
8695 + * - a same named entry
8697 + * * negative --> positive
8698 + * * positive --> positive
8699 + * - type is unchanged
8700 + * - type is changed
8702 + * * negative --> negative
8703 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8706 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8707 + struct au_dinfo *tmp)
8710 + aufs_bindex_t bindex, bbot;
8712 + struct dentry *dentry;
8713 + struct inode *inode;
8715 + } orig_h, tmp_h = {
8718 + struct au_hdentry *hd;
8719 + struct inode *inode, *h_inode;
8720 + struct dentry *h_dentry;
8723 + AuDebugOn(dinfo->di_btop < 0);
8725 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8726 + orig_h.inode = NULL;
8727 + if (d_is_positive(orig_h.dentry)) {
8728 + orig_h.inode = d_inode(orig_h.dentry);
8729 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8731 + if (tmp->di_btop >= 0) {
8732 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8733 + if (d_is_positive(tmp_h.dentry)) {
8734 + tmp_h.inode = d_inode(tmp_h.dentry);
8735 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8740 + if (d_really_is_positive(dentry))
8741 + inode = d_inode(dentry);
8742 + if (!orig_h.inode) {
8743 + AuDbg("nagative originally\n");
8749 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8750 + AuDebugOn(dinfo->di_bdiropq != -1);
8752 + if (!tmp_h.inode) {
8753 + AuDbg("negative --> negative\n");
8754 + /* should have only one negative lower */
8755 + if (tmp->di_btop >= 0
8756 + && tmp->di_btop < dinfo->di_btop) {
8757 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8758 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8759 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8760 + au_di_cp(dinfo, tmp);
8761 + hd = au_hdentry(tmp, tmp->di_btop);
8762 + au_set_h_dptr(dentry, tmp->di_btop,
8763 + dget(hd->hd_dentry));
8765 + au_dbg_verify_dinode(dentry);
8767 + AuDbg("negative --> positive\n");
8769 + * similar to the behaviour of creating with bypassing
8771 + * unhash it in order to force an error in the
8772 + * succeeding create operation.
8773 + * we should not set S_DEAD here.
8776 + /* au_di_swap(tmp, dinfo); */
8777 + au_dbg_verify_dinode(dentry);
8780 + AuDbg("positive originally\n");
8781 + /* inode may be NULL */
8782 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8783 + if (!tmp_h.inode) {
8784 + AuDbg("positive --> negative\n");
8785 + /* or bypassing aufs */
8787 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8788 + dinfo->di_bwh = tmp->di_bwh;
8790 + err = au_refresh_hinode_self(inode);
8791 + au_dbg_verify_dinode(dentry);
8792 + } else if (orig_h.mode == tmp_h.mode) {
8793 + AuDbg("positive --> positive, same type\n");
8794 + if (!S_ISDIR(orig_h.mode)
8795 + && dinfo->di_btop > tmp->di_btop) {
8797 + * similar to the behaviour of removing and
8802 + err = au_refresh_hinode_self(inode);
8803 + au_dbg_verify_dinode(dentry);
8805 + /* fill empty slots */
8806 + if (dinfo->di_btop > tmp->di_btop)
8807 + dinfo->di_btop = tmp->di_btop;
8808 + if (dinfo->di_bbot < tmp->di_bbot)
8809 + dinfo->di_bbot = tmp->di_bbot;
8810 + dinfo->di_bwh = tmp->di_bwh;
8811 + dinfo->di_bdiropq = tmp->di_bdiropq;
8812 + bbot = dinfo->di_bbot;
8813 + bindex = tmp->di_btop;
8814 + hd = au_hdentry(tmp, bindex);
8815 + for (; bindex <= bbot; bindex++, hd++) {
8816 + if (au_h_dptr(dentry, bindex))
8818 + h_dentry = hd->hd_dentry;
8821 + AuDebugOn(d_is_negative(h_dentry));
8822 + h_inode = d_inode(h_dentry);
8823 + AuDebugOn(orig_h.mode
8824 + != (h_inode->i_mode
8826 + au_set_h_dptr(dentry, bindex,
8830 + err = au_refresh_hinode(inode, dentry);
8831 + au_dbg_verify_dinode(dentry);
8834 + AuDbg("positive --> positive, different type\n");
8835 + /* similar to the behaviour of removing and creating */
8838 + err = au_refresh_hinode_self(inode);
8839 + au_dbg_verify_dinode(dentry);
8847 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8849 + const struct dentry_operations *dop
8850 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8851 + static const unsigned int mask
8852 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8854 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8856 + if (dentry->d_op == dop)
8859 + AuDbg("%pd\n", dentry);
8860 + spin_lock(&dentry->d_lock);
8861 + if (dop == &aufs_dop)
8862 + dentry->d_flags |= mask;
8864 + dentry->d_flags &= ~mask;
8865 + dentry->d_op = dop;
8866 + spin_unlock(&dentry->d_lock);
8869 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8871 + int err, ebrange, nbr;
8872 + unsigned int sigen;
8873 + struct au_dinfo *dinfo, *tmp;
8874 + struct super_block *sb;
8875 + struct inode *inode;
8877 + DiMustWriteLock(dentry);
8878 + AuDebugOn(IS_ROOT(dentry));
8879 + AuDebugOn(d_really_is_negative(parent));
8881 + sb = dentry->d_sb;
8882 + sigen = au_sigen(sb);
8883 + err = au_digen_test(parent, sigen);
8884 + if (unlikely(err))
8887 + nbr = au_sbbot(sb) + 1;
8888 + dinfo = au_di(dentry);
8889 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8890 + if (unlikely(err))
8892 + ebrange = au_dbrange_test(dentry);
8894 + ebrange = au_do_refresh_hdentry(dentry, parent);
8896 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8897 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8898 + if (d_really_is_positive(dentry)) {
8899 + inode = d_inode(dentry);
8900 + err = au_refresh_hinode_self(inode);
8902 + au_dbg_verify_dinode(dentry);
8904 + goto out_dgen; /* success */
8908 + /* temporary dinfo */
8909 + AuDbgDentry(dentry);
8911 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8912 + if (unlikely(!tmp))
8914 + au_di_swap(tmp, dinfo);
8915 + /* returns the number of positive dentries */
8917 + * if current working dir is removed, it returns an error.
8918 + * but the dentry is legal.
8920 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8921 + AuDbgDentry(dentry);
8922 + au_di_swap(tmp, dinfo);
8923 + if (err == -ENOENT)
8926 + /* compare/refresh by dinfo */
8927 + AuDbgDentry(dentry);
8928 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8929 + au_dbg_verify_dinode(dentry);
8932 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8933 + au_rw_write_unlock(&tmp->di_rwsem);
8935 + if (unlikely(err))
8939 + au_update_digen(dentry);
8941 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8942 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8943 + AuDbgDentry(dentry);
8949 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8950 + struct dentry *dentry, aufs_bindex_t bindex)
8955 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8958 + AuDbg("b%d\n", bindex);
8960 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8961 + * due to whiteout and branch permission.
8963 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8964 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8965 + /* it may return tri-state */
8966 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8968 + if (unlikely(valid < 0))
8978 +/* todo: remove this */
8979 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8980 + unsigned int flags, int do_udba, int dirren)
8983 + umode_t mode, h_mode;
8984 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8985 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8986 + struct inode *h_inode, *h_cached_inode;
8987 + struct dentry *h_dentry;
8988 + struct qstr *name, *h_name;
8995 + unhashed = !!d_unhashed(dentry);
8996 + is_root = !!IS_ROOT(dentry);
8997 + name = &dentry->d_name;
8998 + tmpfile = au_di(dentry)->di_tmpfile;
9001 + * Theoretically, REVAL test should be unnecessary in case of
9003 + * But {fs,i}notify doesn't fire some necessary events,
9004 + * IN_ATTRIB for atime/nlink/pageio
9005 + * Let's do REVAL test too.
9007 + if (do_udba && inode) {
9008 + mode = (inode->i_mode & S_IFMT);
9009 + plus = (inode->i_nlink > 0);
9010 + ibs = au_ibtop(inode);
9011 + ibe = au_ibbot(inode);
9014 + btop = au_dbtop(dentry);
9016 + if (inode && S_ISDIR(inode->i_mode))
9017 + btail = au_dbtaildir(dentry);
9018 + for (bindex = btop; bindex <= btail; bindex++) {
9019 + h_dentry = au_h_dptr(dentry, bindex);
9023 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9024 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9025 + spin_lock(&h_dentry->d_lock);
9026 + h_name = &h_dentry->d_name;
9027 + if (unlikely(do_udba
9030 + && (unhashed != !!d_unhashed(h_dentry)
9031 + || (!tmpfile && !dirren
9032 + && !au_qstreq(name, h_name))
9035 + && !(flags & LOOKUP_OPEN)
9036 + && (h_dentry->d_flags
9037 + & DCACHE_NFSFS_RENAMED)))
9041 + h_unhashed = d_unhashed(h_dentry);
9042 + spin_unlock(&h_dentry->d_lock);
9043 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9044 + unhashed, h_unhashed, dentry, h_dentry);
9047 + spin_unlock(&h_dentry->d_lock);
9049 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9050 + if (unlikely(err))
9051 + /* do not goto err, to keep the errno */
9054 + /* todo: plink too? */
9059 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9063 + if (d_is_positive(h_dentry))
9064 + h_inode = d_inode(h_dentry);
9067 + h_cached_inode = h_inode;
9069 + h_mode = (h_inode->i_mode & S_IFMT);
9070 + h_plus = (h_inode->i_nlink > 0);
9072 + if (inode && ibs <= bindex && bindex <= ibe)
9073 + h_cached_inode = au_h_iptr(inode, bindex);
9076 + if (unlikely(plus != h_plus && !tmpfile))
9079 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9081 + && !IS_ROOT(h_dentry)
9082 + && unhashed != d_unhashed(h_dentry)))
9085 + if (unlikely(mode != h_mode
9086 + || h_cached_inode != h_inode))
9099 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9100 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9103 + struct dentry *parent;
9105 + if (!au_digen_test(dentry, sigen))
9108 + parent = dget_parent(dentry);
9109 + di_read_lock_parent(parent, AuLock_IR);
9110 + AuDebugOn(au_digen_test(parent, sigen));
9111 + au_dbg_verify_gen(parent, sigen);
9112 + err = au_refresh_dentry(dentry, parent);
9113 + di_read_unlock(parent, AuLock_IR);
9119 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9122 + struct dentry *d, *parent;
9124 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9125 + return simple_reval_dpath(dentry, sigen);
9127 + /* slow loop, keep it simple and stupid */
9128 + /* cf: au_cpup_dirs() */
9131 + while (au_digen_test(dentry, sigen)) {
9135 + parent = dget_parent(d);
9136 + if (!au_digen_test(parent, sigen))
9142 + di_write_lock_child2(d);
9144 + /* someone might update our dentry while we were sleeping */
9145 + if (au_digen_test(d, sigen)) {
9147 + * todo: consolidate with simple_reval_dpath(),
9148 + * do_refresh() and au_reval_for_attr().
9150 + di_read_lock_parent(parent, AuLock_IR);
9151 + err = au_refresh_dentry(d, parent);
9152 + di_read_unlock(parent, AuLock_IR);
9156 + di_write_unlock(d);
9158 + if (unlikely(err))
9166 + * if valid returns 1, otherwise 0.
9168 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9171 + unsigned int sigen;
9172 + unsigned char do_udba, dirren;
9173 + struct super_block *sb;
9174 + struct inode *inode;
9176 + /* todo: support rcu-walk? */
9177 + if (flags & LOOKUP_RCU)
9181 + if (unlikely(!au_di(dentry)))
9185 + sb = dentry->d_sb;
9188 + * i_mutex of parent dir may be held,
9189 + * but we should not return 'invalid' due to busy.
9191 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9192 + if (unlikely(err)) {
9198 + if (d_really_is_positive(dentry))
9199 + inode = d_inode(dentry);
9200 + if (unlikely(inode && au_is_bad_inode(inode))) {
9205 + if (unlikely(au_dbrange_test(dentry))) {
9211 + sigen = au_sigen(sb);
9212 + if (au_digen_test(dentry, sigen)) {
9213 + AuDebugOn(IS_ROOT(dentry));
9214 + err = au_reval_dpath(dentry, sigen);
9215 + if (unlikely(err)) {
9220 + di_downgrade_lock(dentry, AuLock_IR);
9223 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9225 + && !(inode->i_state && I_LINKABLE)
9226 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9231 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9232 + if (do_udba && inode) {
9233 + aufs_bindex_t btop = au_ibtop(inode);
9234 + struct inode *h_inode;
9237 + h_inode = au_h_iptr(inode, btop);
9238 + if (h_inode && au_test_higen(inode, h_inode)) {
9245 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9246 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9247 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9249 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9255 + di_downgrade_lock(dentry, AuLock_IR);
9257 + aufs_read_unlock(dentry, AuLock_IR);
9262 + AuDbg("%pd invalid, %d\n", dentry, valid);
9268 +static void aufs_d_release(struct dentry *dentry)
9270 + if (au_di(dentry)) {
9271 + au_di_fin(dentry);
9272 + au_hn_di_reinit(dentry);
9276 +const struct dentry_operations aufs_dop = {
9277 + .d_revalidate = aufs_d_revalidate,
9278 + .d_weak_revalidate = aufs_d_revalidate,
9279 + .d_release = aufs_d_release
9282 +/* aufs_dop without d_revalidate */
9283 +const struct dentry_operations aufs_dop_noreval = {
9284 + .d_release = aufs_d_release
9286 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9287 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9288 +++ linux/fs/aufs/dentry.h 2018-07-19 09:46:13.056647808 +0200
9290 +/* SPDX-License-Identifier: GPL-2.0 */
9292 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9294 + * This program, aufs is free software; you can redistribute it and/or modify
9295 + * it under the terms of the GNU General Public License as published by
9296 + * the Free Software Foundation; either version 2 of the License, or
9297 + * (at your option) any later version.
9299 + * This program is distributed in the hope that it will be useful,
9300 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9301 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9302 + * GNU General Public License for more details.
9304 + * You should have received a copy of the GNU General Public License
9305 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9309 + * lookup and dentry operations
9312 +#ifndef __AUFS_DENTRY_H__
9313 +#define __AUFS_DENTRY_H__
9317 +#include <linux/dcache.h>
9318 +#include "dirren.h"
9321 +struct au_hdentry {
9322 + struct dentry *hd_dentry;
9323 + aufs_bindex_t hd_id;
9327 + atomic_t di_generation;
9329 + struct au_rwsem di_rwsem;
9330 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9331 + unsigned char di_tmpfile; /* to allow the different name */
9332 + struct au_hdentry *di_hdentry;
9333 +} ____cacheline_aligned_in_smp;
9335 +/* ---------------------------------------------------------------------- */
9337 +/* flags for au_lkup_dentry() */
9338 +#define AuLkup_ALLOW_NEG 1
9339 +#define AuLkup_IGNORE_PERM (1 << 1)
9340 +#define AuLkup_DIRREN (1 << 2)
9341 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9342 +#define au_fset_lkup(flags, name) \
9343 + do { (flags) |= AuLkup_##name; } while (0)
9344 +#define au_fclr_lkup(flags, name) \
9345 + do { (flags) &= ~AuLkup_##name; } while (0)
9347 +#ifndef CONFIG_AUFS_DIRREN
9348 +#undef AuLkup_DIRREN
9349 +#define AuLkup_DIRREN 0
9352 +struct au_do_lookup_args {
9353 + unsigned int flags;
9355 + struct qstr whname, *name;
9356 + struct au_dr_lookup dirren;
9359 +/* ---------------------------------------------------------------------- */
9362 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9364 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9365 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9366 + struct dentry *h_parent, struct au_branch *br);
9368 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9369 + unsigned int flags);
9370 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9371 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9372 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9373 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9376 +void au_di_init_once(void *_di);
9377 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9378 +void au_di_free(struct au_dinfo *dinfo);
9379 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9380 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9381 +int au_di_init(struct dentry *dentry);
9382 +void au_di_fin(struct dentry *dentry);
9383 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9385 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9386 +void di_read_unlock(struct dentry *d, int flags);
9387 +void di_downgrade_lock(struct dentry *d, int flags);
9388 +void di_write_lock(struct dentry *d, unsigned int lsc);
9389 +void di_write_unlock(struct dentry *d);
9390 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9391 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9392 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9394 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9395 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9396 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9397 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9399 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9400 + struct dentry *h_dentry);
9401 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9402 +int au_dbrange_test(struct dentry *dentry);
9403 +void au_update_digen(struct dentry *dentry);
9404 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9405 +void au_update_dbtop(struct dentry *dentry);
9406 +void au_update_dbbot(struct dentry *dentry);
9407 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9409 +/* ---------------------------------------------------------------------- */
9411 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9413 + return dentry->d_fsdata;
9416 +/* ---------------------------------------------------------------------- */
9418 +/* lock subclass for dinfo */
9420 + AuLsc_DI_CHILD, /* child first */
9421 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9422 + AuLsc_DI_CHILD3, /* copyup dirs */
9426 + AuLsc_DI_TMP /* temp for replacing dinfo */
9430 + * di_read_lock_child, di_write_lock_child,
9431 + * di_read_lock_child2, di_write_lock_child2,
9432 + * di_read_lock_child3, di_write_lock_child3,
9433 + * di_read_lock_parent, di_write_lock_parent,
9434 + * di_read_lock_parent2, di_write_lock_parent2,
9435 + * di_read_lock_parent3, di_write_lock_parent3,
9437 +#define AuReadLockFunc(name, lsc) \
9438 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9439 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9441 +#define AuWriteLockFunc(name, lsc) \
9442 +static inline void di_write_lock_##name(struct dentry *d) \
9443 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9445 +#define AuRWLockFuncs(name, lsc) \
9446 + AuReadLockFunc(name, lsc) \
9447 + AuWriteLockFunc(name, lsc)
9449 +AuRWLockFuncs(child, CHILD);
9450 +AuRWLockFuncs(child2, CHILD2);
9451 +AuRWLockFuncs(child3, CHILD3);
9452 +AuRWLockFuncs(parent, PARENT);
9453 +AuRWLockFuncs(parent2, PARENT2);
9454 +AuRWLockFuncs(parent3, PARENT3);
9456 +#undef AuReadLockFunc
9457 +#undef AuWriteLockFunc
9458 +#undef AuRWLockFuncs
9460 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9461 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9462 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9464 +/* ---------------------------------------------------------------------- */
9466 +/* todo: memory barrier? */
9467 +static inline unsigned int au_digen(struct dentry *d)
9469 + return atomic_read(&au_di(d)->di_generation);
9472 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9474 + hdentry->hd_dentry = NULL;
9477 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9478 + aufs_bindex_t bindex)
9480 + return di->di_hdentry + bindex;
9483 +static inline void au_hdput(struct au_hdentry *hd)
9486 + dput(hd->hd_dentry);
9489 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9491 + DiMustAnyLock(dentry);
9492 + return au_di(dentry)->di_btop;
9495 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9497 + DiMustAnyLock(dentry);
9498 + return au_di(dentry)->di_bbot;
9501 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9503 + DiMustAnyLock(dentry);
9504 + return au_di(dentry)->di_bwh;
9507 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9509 + DiMustAnyLock(dentry);
9510 + return au_di(dentry)->di_bdiropq;
9513 +/* todo: hard/soft set? */
9514 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9516 + DiMustWriteLock(dentry);
9517 + au_di(dentry)->di_btop = bindex;
9520 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9522 + DiMustWriteLock(dentry);
9523 + au_di(dentry)->di_bbot = bindex;
9526 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9528 + DiMustWriteLock(dentry);
9529 + /* dbwh can be outside of btop - bbot range */
9530 + au_di(dentry)->di_bwh = bindex;
9533 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9535 + DiMustWriteLock(dentry);
9536 + au_di(dentry)->di_bdiropq = bindex;
9539 +/* ---------------------------------------------------------------------- */
9541 +#ifdef CONFIG_AUFS_HNOTIFY
9542 +static inline void au_digen_dec(struct dentry *d)
9544 + atomic_dec(&au_di(d)->di_generation);
9547 +static inline void au_hn_di_reinit(struct dentry *dentry)
9549 + dentry->d_fsdata = NULL;
9552 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9553 +#endif /* CONFIG_AUFS_HNOTIFY */
9555 +#endif /* __KERNEL__ */
9556 +#endif /* __AUFS_DENTRY_H__ */
9557 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9558 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9559 +++ linux/fs/aufs/dinfo.c 2018-07-19 09:46:13.056647808 +0200
9561 +/* SPDX-License-Identifier: GPL-2.0 */
9563 + * Copyright (C) 2005-2018 Junjiro R. Okajima
9565 + * This program, aufs is free software; you can redistribute it and/or modify
9566 + * it under the terms of the GNU General Public License as published by
9567 + * the Free Software Foundation; either version 2 of the License, or
9568 + * (at your option) any later version.
9570 + * This program is distributed in the hope that it will be useful,
9571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9573 + * GNU General Public License for more details.
9575 + * You should have received a copy of the GNU General Public License
9576 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9580 + * dentry private data
9585 +void au_di_init_once(void *_dinfo)
9587 + struct au_dinfo *dinfo = _dinfo;
9589 + au_rw_init(&dinfo->di_rwsem);
9592 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9594 + struct au_dinfo *dinfo;
9597 + dinfo = au_cache_alloc_dinfo();
9598 + if (unlikely(!dinfo))
9601 + nbr = au_sbbot(sb) + 1;
9604 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9605 + if (dinfo->di_hdentry) {
9606 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9607 + dinfo->di_btop = -1;
9608 + dinfo->di_bbot = -1;
9609 + dinfo->di_bwh = -1;
9610 + dinfo->di_bdiropq = -1;
9611 + dinfo->di_tmpfile = 0;
9612 + for (i = 0; i < nbr; i++)
9613 + dinfo->di_hdentry[i].hd_id = -1;
9617 + au_cache_free_dinfo(dinfo);
9624 +void au_di_free(struct au_dinfo *dinfo)
9626 + struct au_hdentry *p;
9627 + aufs_bindex_t bbot, bindex;
9629 + /* dentry may not be revalidated */
9630 + bindex = dinfo->di_btop;
9631 + if (bindex >= 0) {
9632 + bbot = dinfo->di_bbot;
9633 + p = au_hdentry(dinfo, bindex);
9634 + while (bindex++ <= bbot)
9637 + kfree(dinfo->di_hdentry);
9638 + au_cache_free_dinfo(dinfo);
9641 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9643 + struct au_hdentry *p;
9646 + AuRwMustWriteLock(&a->di_rwsem);
9647 + AuRwMustWriteLock(&b->di_rwsem);
9649 +#define DiSwap(v, name) \
9651 + v = a->di_##name; \
9652 + a->di_##name = b->di_##name; \
9653 + b->di_##name = v; \
9656 + DiSwap(p, hdentry);
9660 + DiSwap(bi, bdiropq);
9666 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9668 + AuRwMustWriteLock(&dst->di_rwsem);
9669 + AuRwMustWriteLock(&src->di_rwsem);
9671 + dst->di_btop = src->di_btop;
9672 + dst->di_bbot = src->di_bbot;
9673 + dst->di_bwh = src->di_bwh;
9674 + dst->di_bdiropq = src->di_bdiropq;
9678 +int au_di_init(struct dentry *dentry)
9681 + struct super_block *sb;
9682 + struct au_dinfo *dinfo;
9685 + sb = dentry->d_sb;
9686 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9688 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9689 + /* smp_mb(); */ /* atomic_set */
9690 + dentry->d_fsdata = dinfo;
9697 +void au_di_fin(struct dentry *dentry)
9699 + struct au_dinfo *dinfo;
9701 + dinfo = au_di(dentry);
9702 + AuRwDestroy(&dinfo->di_rwsem);
9703 + au_di_free(dinfo);
9706 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9709 + struct au_hdentry *hdp;
9711 + AuRwMustWriteLock(&dinfo->di_rwsem);
9714 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9716 + sz = sizeof(*hdp);
9717 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9720 + dinfo->di_hdentry = hdp;
9727 +/* ---------------------------------------------------------------------- */
9729 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9732 + case AuLsc_DI_CHILD:
9733 + ii_write_lock_child(inode);
9735 + case AuLsc_DI_CHILD2:
9736 + ii_write_lock_child2(inode);
9738 + case AuLsc_DI_CHILD3:
9739 + ii_write_lock_child3(inode);
9741 + case AuLsc_DI_PARENT:
9742 + ii_write_lock_parent(inode);
9744 + case AuLsc_DI_PARENT2:
9745 + ii_write_lock_parent2(inode);
9747 + case AuLsc_DI_PARENT3:
9748 + ii_write_lock_parent3(inode);
9755 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9758 + case AuLsc_DI_CHILD:
9759 + ii_read_lock_child(inode);
9761 + case AuLsc_DI_CHILD2:
9762 + ii_read_lock_child2(inode);
9764 + case AuLsc_DI_CHILD3:
9765 + ii_read_lock_child3(inode);
9767 + case AuLsc_DI_PARENT:
9768 + ii_read_lock_parent(inode);
9770 + case AuLsc_DI_PARENT2:
9771 + ii_read_lock_parent2(inode);
9773 + case AuLsc_DI_PARENT3:
9774 + ii_read_lock_parent3(inode);
9781 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9783 + struct inode *inode;
9785 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9786 + if (d_really_is_positive(d)) {
9787 + inode = d_inode(d);
9788 + if (au_ftest_lock(flags, IW))
9789 + do_ii_write_lock(inode, lsc);
9790 + else if (au_ftest_lock(flags, IR))
9791 + do_ii_read_lock(inode, lsc);
9795 +void di_read_unlock(struct dentry *d, int flags)
9797 + struct inode *inode;
9799 + if (d_really_is_positive(d)) {
9800 + inode = d_inode(d);
9801 + if (au_ftest_lock(flags, IW)) {
9802 + au_dbg_verify_dinode(d);
9803 + ii_write_unlock(inode);
9804 + } else if (au_ftest_lock(flags, IR)) {
9805 + au_dbg_verify_dinode(d);
9806 + ii_read_unlock(inode);
9809 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9812 +void di_downgrade_lock(struct dentry *d, int flags)
9814 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9815 + ii_downgrade_lock(d_inode(d));
9816 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9819 +void di_write_lock(struct dentry *d, unsigned int lsc)
9821 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9822 + if (d_really_is_positive(d))
9823 + do_ii_write_lock(d_inode(d), lsc);
9826 +void di_write_unlock(struct dentry *d)
9828 + au_dbg_verify_dinode(d);
9829 + if (d_really_is_positive(d))
9830 + ii_write_unlock(d_inode(d));
9831 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9834 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9836 + AuDebugOn(d1 == d2
9837 + || d_inode(d1) == d_inode(d2)
9838 + || d1->d_sb != d2->d_sb);
9840 + if ((isdir && au_test_subdir(d1, d2))
9842 + di_write_lock_child(d1);
9843 + di_write_lock_child2(d2);
9845 + di_write_lock_child(d2);
9846 + di_write_lock_child2(d1);
9850 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9852 + AuDebugOn(d1 == d2
9853 + || d_inode(d1) == d_inode(d2)
9854 + || d1->d_sb != d2->d_sb);
9856 + if ((isdir && au_test_subdir(d1, d2))
9858 + di_write_lock_parent(d1);
9859 + di_write_lock_parent2(d2);
9861 + di_write_lock_parent(d2);
9862 + di_write_lock_parent2(d1);
9866 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9868 + di_write_unlock(d1);
9869 + if (d_inode(d1) == d_inode(d2))
9870 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9872 + di_write_unlock(d2);
9875 +/* ---------------------------------------------------------------------- */
9877 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9881 + DiMustAnyLock(dentry);
9883 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9885 + AuDebugOn(bindex < 0);
9886 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9887 + AuDebugOn(d && au_dcount(d) <= 0);
9892 + * extended version of au_h_dptr().
9893 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9896 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9898 + struct dentry *h_dentry;
9899 + struct inode *inode, *h_inode;
9901 + AuDebugOn(d_really_is_negative(dentry));
9904 + if (au_dbtop(dentry) <= bindex
9905 + && bindex <= au_dbbot(dentry))
9906 + h_dentry = au_h_dptr(dentry, bindex);
9907 + if (h_dentry && !au_d_linkable(h_dentry)) {
9909 + goto out; /* success */
9912 + inode = d_inode(dentry);
9913 + AuDebugOn(bindex < au_ibtop(inode));
9914 + AuDebugOn(au_ibbot(inode) < bindex);
9915 + h_inode = au_h_iptr(inode, bindex);
9916 + h_dentry = d_find_alias(h_inode);
9918 + if (!IS_ERR(h_dentry)) {
9919 + if (!au_d_linkable(h_dentry))
9920 + goto out; /* success */
9926 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9927 + h_dentry = au_plink_lkup(inode, bindex);
9928 + AuDebugOn(!h_dentry);
9929 + if (!IS_ERR(h_dentry)) {
9930 + if (!au_d_hashed_positive(h_dentry))
9931 + goto out; /* success */
9938 + AuDbgDentry(h_dentry);
9942 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9944 + aufs_bindex_t bbot, bwh;
9946 + bbot = au_dbbot(dentry);
9948 + bwh = au_dbwh(dentry);
9951 + if (0 < bwh && bwh < bbot)
9957 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9959 + aufs_bindex_t bbot, bopq;
9961 + bbot = au_dbtail(dentry);
9963 + bopq = au_dbdiropq(dentry);
9964 + if (0 <= bopq && bopq < bbot)
9970 +/* ---------------------------------------------------------------------- */
9972 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9973 + struct dentry *h_dentry)
9975 + struct au_dinfo *dinfo;
9976 + struct au_hdentry *hd;
9977 + struct au_branch *br;
9979 + DiMustWriteLock(dentry);
9981 + dinfo = au_di(dentry);
9982 + hd = au_hdentry(dinfo, bindex);
9984 + hd->hd_dentry = h_dentry;
9986 + br = au_sbr(dentry->d_sb, bindex);
9987 + hd->hd_id = br->br_id;
9991 +int au_dbrange_test(struct dentry *dentry)
9994 + aufs_bindex_t btop, bbot;
9997 + btop = au_dbtop(dentry);
9998 + bbot = au_dbbot(dentry);
10000 + AuDebugOn(bbot < 0 && btop > bbot);
10003 + AuDebugOn(bbot >= 0);
10009 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10014 + if (unlikely(au_digen(dentry) != sigen
10015 + || au_iigen_test(d_inode(dentry), sigen)))
10021 +void au_update_digen(struct dentry *dentry)
10023 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10024 + /* smp_mb(); */ /* atomic_set */
10027 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10029 + struct au_dinfo *dinfo;
10030 + struct dentry *h_d;
10031 + struct au_hdentry *hdp;
10032 + aufs_bindex_t bindex, bbot;
10034 + DiMustWriteLock(dentry);
10036 + dinfo = au_di(dentry);
10037 + if (!dinfo || dinfo->di_btop < 0)
10040 + if (do_put_zero) {
10041 + bbot = dinfo->di_bbot;
10042 + bindex = dinfo->di_btop;
10043 + hdp = au_hdentry(dinfo, bindex);
10044 + for (; bindex <= bbot; bindex++, hdp++) {
10045 + h_d = hdp->hd_dentry;
10046 + if (h_d && d_is_negative(h_d))
10047 + au_set_h_dptr(dentry, bindex, NULL);
10051 + dinfo->di_btop = 0;
10052 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10053 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10054 + if (hdp->hd_dentry)
10056 + if (dinfo->di_btop > dinfo->di_bbot) {
10057 + dinfo->di_btop = -1;
10058 + dinfo->di_bbot = -1;
10062 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10063 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10064 + if (hdp->hd_dentry)
10066 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10069 +void au_update_dbtop(struct dentry *dentry)
10071 + aufs_bindex_t bindex, bbot;
10072 + struct dentry *h_dentry;
10074 + bbot = au_dbbot(dentry);
10075 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10076 + h_dentry = au_h_dptr(dentry, bindex);
10079 + if (d_is_positive(h_dentry)) {
10080 + au_set_dbtop(dentry, bindex);
10083 + au_set_h_dptr(dentry, bindex, NULL);
10087 +void au_update_dbbot(struct dentry *dentry)
10089 + aufs_bindex_t bindex, btop;
10090 + struct dentry *h_dentry;
10092 + btop = au_dbtop(dentry);
10093 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10094 + h_dentry = au_h_dptr(dentry, bindex);
10097 + if (d_is_positive(h_dentry)) {
10098 + au_set_dbbot(dentry, bindex);
10101 + au_set_h_dptr(dentry, bindex, NULL);
10105 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10107 + aufs_bindex_t bindex, bbot;
10109 + bbot = au_dbbot(dentry);
10110 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10111 + if (au_h_dptr(dentry, bindex) == h_dentry)
10115 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10116 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10117 +++ linux/fs/aufs/dir.c 2018-07-19 09:46:13.056647808 +0200
10119 +/* SPDX-License-Identifier: GPL-2.0 */
10121 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10123 + * This program, aufs is free software; you can redistribute it and/or modify
10124 + * it under the terms of the GNU General Public License as published by
10125 + * the Free Software Foundation; either version 2 of the License, or
10126 + * (at your option) any later version.
10128 + * This program is distributed in the hope that it will be useful,
10129 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10130 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10131 + * GNU General Public License for more details.
10133 + * You should have received a copy of the GNU General Public License
10134 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10138 + * directory operations
10141 +#include <linux/fs_stack.h>
10144 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10146 + unsigned int nlink;
10148 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10150 + nlink = dir->i_nlink;
10151 + nlink += h_dir->i_nlink - 2;
10152 + if (h_dir->i_nlink < 2)
10154 + smp_mb(); /* for i_nlink */
10155 + /* 0 can happen in revaliding */
10156 + set_nlink(dir, nlink);
10159 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10161 + unsigned int nlink;
10163 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10165 + nlink = dir->i_nlink;
10166 + nlink -= h_dir->i_nlink - 2;
10167 + if (h_dir->i_nlink < 2)
10169 + smp_mb(); /* for i_nlink */
10170 + /* nlink == 0 means the branch-fs is broken */
10171 + set_nlink(dir, nlink);
10174 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10177 + aufs_bindex_t bindex, bbot;
10178 + struct file *h_file;
10179 + struct dentry *h_dentry;
10183 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10185 + bbot = au_fbbot_dir(file);
10186 + for (bindex = au_fbtop(file);
10187 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10189 + h_file = au_hf_dir(file, bindex);
10190 + if (h_file && file_inode(h_file))
10191 + sz += vfsub_f_size_read(h_file);
10194 + AuDebugOn(!dentry);
10195 + AuDebugOn(!d_is_dir(dentry));
10197 + bbot = au_dbtaildir(dentry);
10198 + for (bindex = au_dbtop(dentry);
10199 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10201 + h_dentry = au_h_dptr(dentry, bindex);
10202 + if (h_dentry && d_is_positive(h_dentry))
10203 + sz += i_size_read(d_inode(h_dentry));
10206 + if (sz < KMALLOC_MAX_SIZE)
10207 + sz = roundup_pow_of_two(sz);
10208 + if (sz > KMALLOC_MAX_SIZE)
10209 + sz = KMALLOC_MAX_SIZE;
10210 + else if (sz < NAME_MAX) {
10211 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10212 + sz = AUFS_RDBLK_DEF;
10217 +struct au_dir_ts_arg {
10218 + struct dentry *dentry;
10219 + aufs_bindex_t brid;
10222 +static void au_do_dir_ts(void *arg)
10224 + struct au_dir_ts_arg *a = arg;
10225 + struct au_dtime dt;
10226 + struct path h_path;
10227 + struct inode *dir, *h_dir;
10228 + struct super_block *sb;
10229 + struct au_branch *br;
10230 + struct au_hinode *hdir;
10232 + aufs_bindex_t btop, bindex;
10234 + sb = a->dentry->d_sb;
10235 + if (d_really_is_negative(a->dentry))
10237 + /* no dir->i_mutex lock */
10238 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10240 + dir = d_inode(a->dentry);
10241 + btop = au_ibtop(dir);
10242 + bindex = au_br_index(sb, a->brid);
10243 + if (bindex < btop)
10246 + br = au_sbr(sb, bindex);
10247 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10248 + if (!h_path.dentry)
10250 + h_path.mnt = au_br_mnt(br);
10251 + au_dtime_store(&dt, a->dentry, &h_path);
10253 + br = au_sbr(sb, btop);
10254 + if (!au_br_writable(br->br_perm))
10256 + h_path.dentry = au_h_dptr(a->dentry, btop);
10257 + h_path.mnt = au_br_mnt(br);
10258 + err = vfsub_mnt_want_write(h_path.mnt);
10261 + hdir = au_hi(dir, btop);
10262 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10263 + h_dir = au_h_iptr(dir, btop);
10264 + if (h_dir->i_nlink
10265 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10266 + dt.dt_h_path = h_path;
10267 + au_dtime_revert(&dt);
10269 + au_hn_inode_unlock(hdir);
10270 + vfsub_mnt_drop_write(h_path.mnt);
10271 + au_cpup_attr_timesizes(dir);
10274 + aufs_read_unlock(a->dentry, AuLock_DW);
10277 + au_nwt_done(&au_sbi(sb)->si_nowait);
10281 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10283 + int perm, wkq_err;
10284 + aufs_bindex_t btop;
10285 + struct au_dir_ts_arg *arg;
10286 + struct dentry *dentry;
10287 + struct super_block *sb;
10291 + dentry = d_find_any_alias(dir);
10292 + AuDebugOn(!dentry);
10293 + sb = dentry->d_sb;
10294 + btop = au_ibtop(dir);
10295 + if (btop == bindex) {
10296 + au_cpup_attr_timesizes(dir);
10300 + perm = au_sbr_perm(sb, btop);
10301 + if (!au_br_writable(perm))
10304 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10308 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10309 + arg->brid = au_sbr_id(sb, bindex);
10310 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10311 + if (unlikely(wkq_err)) {
10312 + pr_err("wkq %d\n", wkq_err);
10321 +/* ---------------------------------------------------------------------- */
10323 +static int reopen_dir(struct file *file)
10326 + unsigned int flags;
10327 + aufs_bindex_t bindex, btail, btop;
10328 + struct dentry *dentry, *h_dentry;
10329 + struct file *h_file;
10331 + /* open all lower dirs */
10332 + dentry = file->f_path.dentry;
10333 + btop = au_dbtop(dentry);
10334 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10335 + au_set_h_fptr(file, bindex, NULL);
10336 + au_set_fbtop(file, btop);
10338 + btail = au_dbtaildir(dentry);
10339 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10340 + au_set_h_fptr(file, bindex, NULL);
10341 + au_set_fbbot_dir(file, btail);
10343 + flags = vfsub_file_flags(file);
10344 + for (bindex = btop; bindex <= btail; bindex++) {
10345 + h_dentry = au_h_dptr(dentry, bindex);
10348 + h_file = au_hf_dir(file, bindex);
10352 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10353 + err = PTR_ERR(h_file);
10354 + if (IS_ERR(h_file))
10355 + goto out; /* close all? */
10356 + au_set_h_fptr(file, bindex, h_file);
10358 + au_update_figen(file);
10359 + /* todo: necessary? */
10360 + /* file->f_ra = h_file->f_ra; */
10367 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10370 + aufs_bindex_t bindex, btail;
10371 + struct dentry *dentry, *h_dentry;
10372 + struct vfsmount *mnt;
10374 + FiMustWriteLock(file);
10375 + AuDebugOn(h_file);
10378 + mnt = file->f_path.mnt;
10379 + dentry = file->f_path.dentry;
10380 + file->f_version = inode_query_iversion(d_inode(dentry));
10381 + bindex = au_dbtop(dentry);
10382 + au_set_fbtop(file, bindex);
10383 + btail = au_dbtaildir(dentry);
10384 + au_set_fbbot_dir(file, btail);
10385 + for (; !err && bindex <= btail; bindex++) {
10386 + h_dentry = au_h_dptr(dentry, bindex);
10390 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10391 + if (unlikely(err))
10393 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10394 + if (IS_ERR(h_file)) {
10395 + err = PTR_ERR(h_file);
10398 + au_set_h_fptr(file, bindex, h_file);
10400 + au_update_figen(file);
10401 + /* todo: necessary? */
10402 + /* file->f_ra = h_file->f_ra; */
10404 + return 0; /* success */
10407 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10408 + au_set_h_fptr(file, bindex, NULL);
10409 + au_set_fbtop(file, -1);
10410 + au_set_fbbot_dir(file, -1);
10415 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10416 + struct file *file)
10419 + struct super_block *sb;
10420 + struct au_fidir *fidir;
10423 + sb = file->f_path.dentry->d_sb;
10424 + si_read_lock(sb, AuLock_FLUSH);
10425 + fidir = au_fidir_alloc(sb);
10427 + struct au_do_open_args args = {
10428 + .open = do_open_dir,
10431 + err = au_do_open(file, &args);
10432 + if (unlikely(err))
10435 + si_read_unlock(sb);
10439 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10440 + struct file *file)
10442 + struct au_vdir *vdir_cache;
10443 + struct au_finfo *finfo;
10444 + struct au_fidir *fidir;
10445 + struct au_hfile *hf;
10446 + aufs_bindex_t bindex, bbot;
10448 + finfo = au_fi(file);
10449 + fidir = finfo->fi_hdir;
10451 + au_hbl_del(&finfo->fi_hlist,
10452 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10453 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10455 + au_vdir_free(vdir_cache);
10457 + bindex = finfo->fi_btop;
10458 + if (bindex >= 0) {
10459 + hf = fidir->fd_hfile + bindex;
10461 + * calls fput() instead of filp_close(),
10462 + * since no dnotify or lock for the lower file.
10464 + bbot = fidir->fd_bbot;
10465 + for (; bindex <= bbot; bindex++, hf++)
10467 + au_hfput(hf, /*execed*/0);
10470 + finfo->fi_hdir = NULL;
10472 + au_finfo_fin(file);
10476 +/* ---------------------------------------------------------------------- */
10478 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10481 + aufs_bindex_t bindex, bbot;
10482 + struct file *h_file;
10485 + bbot = au_fbbot_dir(file);
10486 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10487 + h_file = au_hf_dir(file, bindex);
10489 + err = vfsub_flush(h_file, id);
10494 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10496 + return au_do_flush(file, id, au_do_flush_dir);
10499 +/* ---------------------------------------------------------------------- */
10501 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10504 + aufs_bindex_t bbot, bindex;
10505 + struct inode *inode;
10506 + struct super_block *sb;
10509 + sb = dentry->d_sb;
10510 + inode = d_inode(dentry);
10511 + IMustLock(inode);
10512 + bbot = au_dbbot(dentry);
10513 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10514 + struct path h_path;
10516 + if (au_test_ro(sb, bindex, inode))
10518 + h_path.dentry = au_h_dptr(dentry, bindex);
10519 + if (!h_path.dentry)
10522 + h_path.mnt = au_sbr_mnt(sb, bindex);
10523 + err = vfsub_fsync(NULL, &h_path, datasync);
10529 +static int au_do_fsync_dir(struct file *file, int datasync)
10532 + aufs_bindex_t bbot, bindex;
10533 + struct file *h_file;
10534 + struct super_block *sb;
10535 + struct inode *inode;
10537 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10538 + if (unlikely(err))
10541 + inode = file_inode(file);
10542 + sb = inode->i_sb;
10543 + bbot = au_fbbot_dir(file);
10544 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10545 + h_file = au_hf_dir(file, bindex);
10546 + if (!h_file || au_test_ro(sb, bindex, inode))
10549 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10557 + * @file may be NULL
10559 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10563 + struct dentry *dentry;
10564 + struct inode *inode;
10565 + struct super_block *sb;
10568 + dentry = file->f_path.dentry;
10569 + inode = d_inode(dentry);
10570 + inode_lock(inode);
10571 + sb = dentry->d_sb;
10572 + si_noflush_read_lock(sb);
10574 + err = au_do_fsync_dir(file, datasync);
10576 + di_write_lock_child(dentry);
10577 + err = au_do_fsync_dir_no_file(dentry, datasync);
10579 + au_cpup_attr_timesizes(inode);
10580 + di_write_unlock(dentry);
10582 + fi_write_unlock(file);
10584 + si_read_unlock(sb);
10585 + inode_unlock(inode);
10589 +/* ---------------------------------------------------------------------- */
10591 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10594 + struct dentry *dentry;
10595 + struct inode *inode, *h_inode;
10596 + struct super_block *sb;
10598 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10600 + dentry = file->f_path.dentry;
10601 + inode = d_inode(dentry);
10602 + IMustLock(inode);
10604 + sb = dentry->d_sb;
10605 + si_read_lock(sb, AuLock_FLUSH);
10606 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10607 + if (unlikely(err))
10609 + err = au_alive_dir(dentry);
10611 + err = au_vdir_init(file);
10612 + di_downgrade_lock(dentry, AuLock_IR);
10613 + if (unlikely(err))
10616 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10617 + if (!au_test_nfsd()) {
10618 + err = au_vdir_fill_de(file, ctx);
10619 + fsstack_copy_attr_atime(inode, h_inode);
10622 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10623 + * encode_fh() and others.
10625 + atomic_inc(&h_inode->i_count);
10626 + di_read_unlock(dentry, AuLock_IR);
10627 + si_read_unlock(sb);
10628 + err = au_vdir_fill_de(file, ctx);
10629 + fsstack_copy_attr_atime(inode, h_inode);
10630 + fi_write_unlock(file);
10638 + di_read_unlock(dentry, AuLock_IR);
10639 + fi_write_unlock(file);
10641 + si_read_unlock(sb);
10645 +/* ---------------------------------------------------------------------- */
10647 +#define AuTestEmpty_WHONLY 1
10648 +#define AuTestEmpty_CALLED (1 << 1)
10649 +#define AuTestEmpty_SHWH (1 << 2)
10650 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10651 +#define au_fset_testempty(flags, name) \
10652 + do { (flags) |= AuTestEmpty_##name; } while (0)
10653 +#define au_fclr_testempty(flags, name) \
10654 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10656 +#ifndef CONFIG_AUFS_SHWH
10657 +#undef AuTestEmpty_SHWH
10658 +#define AuTestEmpty_SHWH 0
10661 +struct test_empty_arg {
10662 + struct dir_context ctx;
10663 + struct au_nhash *whlist;
10664 + unsigned int flags;
10666 + aufs_bindex_t bindex;
10669 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10670 + int namelen, loff_t offset __maybe_unused, u64 ino,
10671 + unsigned int d_type)
10673 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10675 + char *name = (void *)__name;
10678 + au_fset_testempty(arg->flags, CALLED);
10680 + if (name[0] == '.'
10681 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10682 + goto out; /* success */
10684 + if (namelen <= AUFS_WH_PFX_LEN
10685 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10686 + if (au_ftest_testempty(arg->flags, WHONLY)
10687 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10688 + arg->err = -ENOTEMPTY;
10692 + name += AUFS_WH_PFX_LEN;
10693 + namelen -= AUFS_WH_PFX_LEN;
10694 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10695 + arg->err = au_nhash_append_wh
10696 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10697 + au_ftest_testempty(arg->flags, SHWH));
10701 + AuTraceErr(arg->err);
10705 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10708 + struct file *h_file;
10710 + h_file = au_h_open(dentry, arg->bindex,
10711 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10712 + /*file*/NULL, /*force_wr*/0);
10713 + err = PTR_ERR(h_file);
10714 + if (IS_ERR(h_file))
10718 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10719 + && !file_inode(h_file)->i_nlink)
10724 + au_fclr_testempty(arg->flags, CALLED);
10726 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10729 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10733 + au_sbr_put(dentry->d_sb, arg->bindex);
10738 +struct do_test_empty_args {
10740 + struct dentry *dentry;
10741 + struct test_empty_arg *arg;
10744 +static void call_do_test_empty(void *args)
10746 + struct do_test_empty_args *a = args;
10747 + *a->errp = do_test_empty(a->dentry, a->arg);
10750 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10752 + int err, wkq_err;
10753 + struct dentry *h_dentry;
10754 + struct inode *h_inode;
10756 + h_dentry = au_h_dptr(dentry, arg->bindex);
10757 + h_inode = d_inode(h_dentry);
10758 + /* todo: i_mode changes anytime? */
10759 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10760 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10761 + inode_unlock_shared(h_inode);
10763 + err = do_test_empty(dentry, arg);
10765 + struct do_test_empty_args args = {
10767 + .dentry = dentry,
10770 + unsigned int flags = arg->flags;
10772 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10773 + if (unlikely(wkq_err))
10775 + arg->flags = flags;
10781 +int au_test_empty_lower(struct dentry *dentry)
10784 + unsigned int rdhash;
10785 + aufs_bindex_t bindex, btop, btail;
10786 + struct au_nhash whlist;
10787 + struct test_empty_arg arg = {
10789 + .actor = test_empty_cb
10792 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10794 + SiMustAnyLock(dentry->d_sb);
10796 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10798 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10799 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10800 + if (unlikely(err))
10804 + arg.whlist = &whlist;
10805 + btop = au_dbtop(dentry);
10806 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10807 + au_fset_testempty(arg.flags, SHWH);
10808 + test_empty = do_test_empty;
10809 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10810 + test_empty = sio_test_empty;
10811 + arg.bindex = btop;
10812 + err = test_empty(dentry, &arg);
10813 + if (unlikely(err))
10816 + au_fset_testempty(arg.flags, WHONLY);
10817 + btail = au_dbtaildir(dentry);
10818 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10819 + struct dentry *h_dentry;
10821 + h_dentry = au_h_dptr(dentry, bindex);
10822 + if (h_dentry && d_is_positive(h_dentry)) {
10823 + arg.bindex = bindex;
10824 + err = test_empty(dentry, &arg);
10829 + au_nhash_wh_free(&whlist);
10834 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10837 + struct test_empty_arg arg = {
10839 + .actor = test_empty_cb
10842 + aufs_bindex_t bindex, btail;
10845 + arg.whlist = whlist;
10846 + arg.flags = AuTestEmpty_WHONLY;
10847 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10848 + au_fset_testempty(arg.flags, SHWH);
10849 + btail = au_dbtaildir(dentry);
10850 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10851 + struct dentry *h_dentry;
10853 + h_dentry = au_h_dptr(dentry, bindex);
10854 + if (h_dentry && d_is_positive(h_dentry)) {
10855 + arg.bindex = bindex;
10856 + err = sio_test_empty(dentry, &arg);
10863 +/* ---------------------------------------------------------------------- */
10865 +const struct file_operations aufs_dir_fop = {
10866 + .owner = THIS_MODULE,
10867 + .llseek = default_llseek,
10868 + .read = generic_read_dir,
10869 + .iterate_shared = aufs_iterate_shared,
10870 + .unlocked_ioctl = aufs_ioctl_dir,
10871 +#ifdef CONFIG_COMPAT
10872 + .compat_ioctl = aufs_compat_ioctl_dir,
10874 + .open = aufs_open_dir,
10875 + .release = aufs_release_dir,
10876 + .flush = aufs_flush_dir,
10877 + .fsync = aufs_fsync_dir
10879 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10880 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10881 +++ linux/fs/aufs/dir.h 2018-07-19 09:46:13.056647808 +0200
10883 +/* SPDX-License-Identifier: GPL-2.0 */
10885 + * Copyright (C) 2005-2018 Junjiro R. Okajima
10887 + * This program, aufs is free software; you can redistribute it and/or modify
10888 + * it under the terms of the GNU General Public License as published by
10889 + * the Free Software Foundation; either version 2 of the License, or
10890 + * (at your option) any later version.
10892 + * This program is distributed in the hope that it will be useful,
10893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10895 + * GNU General Public License for more details.
10897 + * You should have received a copy of the GNU General Public License
10898 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10902 + * directory operations
10905 +#ifndef __AUFS_DIR_H__
10906 +#define __AUFS_DIR_H__
10910 +#include <linux/fs.h>
10912 +/* ---------------------------------------------------------------------- */
10914 +/* need to be faster and smaller */
10917 + unsigned int nh_num;
10918 + struct hlist_head *nh_head;
10921 +struct au_vdir_destr {
10922 + unsigned char len;
10923 + unsigned char name[0];
10926 +struct au_vdir_dehstr {
10927 + struct hlist_node hash;
10928 + struct au_vdir_destr *str;
10929 +} ____cacheline_aligned_in_smp;
10931 +struct au_vdir_de {
10933 + unsigned char de_type;
10934 + /* caution: packed */
10935 + struct au_vdir_destr de_str;
10938 +struct au_vdir_wh {
10939 + struct hlist_node wh_hash;
10940 +#ifdef CONFIG_AUFS_SHWH
10942 + aufs_bindex_t wh_bindex;
10943 + unsigned char wh_type;
10945 + aufs_bindex_t wh_bindex;
10947 + /* caution: packed */
10948 + struct au_vdir_destr wh_str;
10951 +union au_vdir_deblk_p {
10952 + unsigned char *deblk;
10953 + struct au_vdir_de *de;
10957 + unsigned char **vd_deblk;
10958 + unsigned long vd_nblk;
10960 + unsigned long ul;
10961 + union au_vdir_deblk_p p;
10965 + unsigned int vd_deblk_sz;
10966 + unsigned long vd_jiffy;
10967 +} ____cacheline_aligned_in_smp;
10969 +/* ---------------------------------------------------------------------- */
10972 +extern const struct file_operations aufs_dir_fop;
10973 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10974 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10975 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10976 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10977 +int au_test_empty_lower(struct dentry *dentry);
10978 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10981 +unsigned int au_rdhash_est(loff_t sz);
10982 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10983 +void au_nhash_wh_free(struct au_nhash *whlist);
10984 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10986 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10987 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10988 + unsigned int d_type, aufs_bindex_t bindex,
10989 + unsigned char shwh);
10990 +void au_vdir_free(struct au_vdir *vdir);
10991 +int au_vdir_init(struct file *file);
10992 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10995 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10997 +#ifdef CONFIG_AUFS_RDU
10999 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
11000 +#ifdef CONFIG_COMPAT
11001 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
11002 + unsigned long arg);
11005 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11006 + unsigned int cmd, unsigned long arg)
11007 +#ifdef CONFIG_COMPAT
11008 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11009 + unsigned int cmd, unsigned long arg)
11013 +#endif /* __KERNEL__ */
11014 +#endif /* __AUFS_DIR_H__ */
11015 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11016 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11017 +++ linux/fs/aufs/dirren.c 2018-07-19 09:46:13.056647808 +0200
11019 +/* SPDX-License-Identifier: GPL-2.0 */
11021 + * Copyright (C) 2017-2018 Junjiro R. Okajima
11023 + * This program, aufs is free software; you can redistribute it and/or modify
11024 + * it under the terms of the GNU General Public License as published by
11025 + * the Free Software Foundation; either version 2 of the License, or
11026 + * (at your option) any later version.
11028 + * This program is distributed in the hope that it will be useful,
11029 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11030 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11031 + * GNU General Public License for more details.
11033 + * You should have received a copy of the GNU General Public License
11034 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11038 + * special handling in renaming a directoy
11039 + * in order to support looking-up the before-renamed name on the lower readonly
11043 +#include <linux/byteorder/generic.h>
11046 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11050 + idx = au_dr_ihash(ent->dr_h_ino);
11051 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11054 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11057 + struct hlist_bl_head *hbl;
11060 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11061 + hbl = dr->dr_h_ino + i;
11062 + hlist_bl_lock(hbl);
11063 + ret &= hlist_bl_empty(hbl);
11064 + hlist_bl_unlock(hbl);
11070 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11072 + struct au_dr_hino *found, *ent;
11073 + struct hlist_bl_head *hbl;
11074 + struct hlist_bl_node *pos;
11078 + idx = au_dr_ihash(ino);
11079 + hbl = dr->dr_h_ino + idx;
11080 + hlist_bl_lock(hbl);
11081 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11082 + if (ent->dr_h_ino == ino) {
11086 + hlist_bl_unlock(hbl);
11091 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11092 + struct au_dr_hino *add_ent)
11095 + struct hlist_bl_head *hbl;
11096 + struct hlist_bl_node *pos;
11097 + struct au_dr_hino *ent;
11100 + idx = au_dr_ihash(ino);
11101 + hbl = dr->dr_h_ino + idx;
11104 + struct hlist_bl_node *tmp;
11106 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11107 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11110 + hlist_bl_lock(hbl);
11111 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11112 + if (ent->dr_h_ino == ino) {
11116 + if (!found && add_ent)
11117 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11118 + hlist_bl_unlock(hbl);
11120 + if (!found && add_ent)
11121 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11126 +void au_dr_hino_free(struct au_dr_br *dr)
11129 + struct hlist_bl_head *hbl;
11130 + struct hlist_bl_node *pos, *tmp;
11131 + struct au_dr_hino *ent;
11133 + /* SiMustWriteLock(sb); */
11135 + for (i = 0; i < AuDirren_NHASH; i++) {
11136 + hbl = dr->dr_h_ino + i;
11137 + /* no spinlock since sbinfo must be write-locked */
11138 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11140 + INIT_HLIST_BL_HEAD(hbl);
11144 +/* returns the number of inodes or an error */
11145 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11146 + struct file *hinofile)
11150 + loff_t pos, oldsize;
11152 + struct inode *hinoinode;
11153 + struct hlist_bl_head *hbl;
11154 + struct hlist_bl_node *n1, *n2;
11155 + struct au_dr_hino *ent;
11157 + SiMustWriteLock(sb);
11158 + AuDebugOn(!au_br_writable(br->br_perm));
11160 + hinoinode = file_inode(hinofile);
11161 + oldsize = i_size_read(hinoinode);
11165 + hbl = br->br_dirren.dr_h_ino;
11166 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11167 + /* no bit-lock since sbinfo must be write-locked */
11168 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11169 + AuDbg("hi%llu, %pD2\n",
11170 + (unsigned long long)ent->dr_h_ino, hinofile);
11171 + u64 = cpu_to_be64(ent->dr_h_ino);
11172 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11173 + if (ssz == sizeof(u64))
11176 + /* write error */
11177 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11184 + /* regardless the error */
11185 + if (pos < oldsize) {
11186 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11194 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11201 + struct au_dr_hino *ent;
11202 + struct inode *hinoinode;
11203 + struct hlist_bl_head *hbl;
11207 + hbl = dr->dr_h_ino;
11208 + hinoinode = file_inode(hinofile);
11209 + sz = i_size_read(hinoinode);
11210 + AuDebugOn(sz % sizeof(u64));
11211 + n = sz / sizeof(u64);
11213 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11214 + if (unlikely(ssz != sizeof(u64))) {
11215 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11222 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11228 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11229 + AuDbg("hi%llu, %pD2\n",
11230 + (unsigned long long)ent->dr_h_ino, hinofile);
11231 + hidx = au_dr_ihash(ent->dr_h_ino);
11232 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11234 + goto out; /* success */
11237 + au_dr_hino_free(dr);
11244 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11245 + * @path is a switch to distinguish load and store.
11247 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11248 + struct au_branch *br, const struct path *path)
11251 + unsigned char load, suspend;
11252 + struct file *hinofile;
11253 + struct au_hinode *hdir;
11254 + struct inode *dir, *delegated;
11255 + struct path hinopath;
11256 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11257 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11259 + AuDebugOn(bindex < 0 && !br);
11260 + AuDebugOn(bindex >= 0 && br);
11265 + br = au_sbr(sb, bindex);
11268 + path = &br->br_path;
11269 + AuDebugOn(!au_br_writable(br->br_perm));
11270 + if (unlikely(!au_br_writable(br->br_perm)))
11276 + dir = d_inode(sb->s_root);
11277 + hdir = au_hinode(au_ii(dir), bindex);
11278 + dir = hdir->hi_inode;
11279 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11281 + dir = d_inode(path->dentry);
11282 + inode_lock_nested(dir, AuLsc_I_CHILD);
11284 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11285 + err = PTR_ERR(hinopath.dentry);
11286 + if (IS_ERR(hinopath.dentry))
11290 + flags = O_RDONLY;
11292 + if (d_is_negative(hinopath.dentry))
11293 + goto out_dput; /* success */
11295 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11296 + if (d_is_positive(hinopath.dentry)) {
11297 + delegated = NULL;
11298 + err = vfsub_unlink(dir, &hinopath, &delegated,
11301 + if (unlikely(err))
11302 + pr_err("ignored err %d, %pd2\n",
11303 + err, hinopath.dentry);
11304 + if (unlikely(err == -EWOULDBLOCK))
11309 + } else if (!d_is_positive(hinopath.dentry)) {
11310 + err = vfsub_create(dir, &hinopath, 0600,
11311 + /*want_excl*/false);
11313 + if (unlikely(err))
11316 + flags = O_WRONLY;
11318 + hinopath.mnt = path->mnt;
11319 + hinofile = vfsub_dentry_open(&hinopath, flags);
11321 + au_hn_inode_unlock(hdir);
11323 + inode_unlock(dir);
11324 + dput(hinopath.dentry);
11325 + AuTraceErrPtr(hinofile);
11326 + if (IS_ERR(hinofile)) {
11327 + err = PTR_ERR(hinofile);
11332 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11334 + err = au_dr_hino_store(sb, br, hinofile);
11339 + dput(hinopath.dentry);
11342 + au_hn_inode_unlock(hdir);
11344 + inode_unlock(dir);
11350 +/* ---------------------------------------------------------------------- */
11352 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11355 + struct kstatfs kstfs;
11357 + struct dentry *dentry;
11358 + struct super_block *sb;
11360 + err = vfs_statfs((void *)path, &kstfs);
11362 + if (unlikely(err))
11365 + /* todo: support for UUID */
11367 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11368 + brid->type = AuBrid_FSID;
11369 + brid->fsid = kstfs.f_fsid;
11371 + dentry = path->dentry;
11372 + sb = dentry->d_sb;
11375 + brid->type = AuBrid_DEV;
11384 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11385 + const struct path *path)
11388 + struct au_dr_br *dr;
11389 + struct hlist_bl_head *hbl;
11391 + dr = &br->br_dirren;
11392 + hbl = dr->dr_h_ino;
11393 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11394 + INIT_HLIST_BL_HEAD(hbl);
11396 + err = au_dr_brid_init(&dr->dr_brid, path);
11397 + if (unlikely(err))
11400 + if (au_opt_test(au_mntflags(sb), DIRREN))
11401 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11408 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11413 + if (au_br_writable(br->br_perm))
11414 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11416 + au_dr_hino_free(&br->br_dirren);
11421 +/* ---------------------------------------------------------------------- */
11423 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11424 + char *buf, size_t sz)
11427 + unsigned int major, minor;
11431 + err = snprintf(p, sz, "%d_", brid->type);
11432 + AuDebugOn(err > sz);
11435 + switch (brid->type) {
11436 + case AuBrid_Unset:
11438 + case AuBrid_UUID:
11439 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11441 + case AuBrid_FSID:
11442 + err = snprintf(p, sz, "%08x-%08x",
11443 + brid->fsid.val[0], brid->fsid.val[1]);
11446 + major = MAJOR(brid->dev);
11447 + minor = MINOR(brid->dev);
11448 + if (major <= 0xff && minor <= 0xff)
11449 + err = snprintf(p, sz, "%02x%02x", major, minor);
11451 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11454 + AuDebugOn(err > sz);
11457 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11458 + AuDebugOn(err > sz);
11465 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11468 + struct dentry *br_dentry;
11469 + struct inode *br_inode;
11471 + br_dentry = au_br_dentry(br);
11472 + br_inode = d_inode(br_dentry);
11473 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11474 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11475 + AuDebugOn(rlen > len);
11480 +/* ---------------------------------------------------------------------- */
11483 + * from the given @h_dentry, construct drinfo at @*fdata.
11484 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11487 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11488 + struct dentry *h_dentry,
11489 + unsigned char *allocated)
11492 + struct au_drinfo_fdata *f, *p;
11493 + struct au_drinfo *drinfo;
11494 + struct inode *h_inode;
11495 + struct qstr *qname;
11499 + h_inode = d_inode(h_dentry);
11500 + qname = &h_dentry->d_name;
11501 + drinfo = &f->drinfo;
11502 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11503 + drinfo->oldnamelen = qname->len;
11504 + if (*allocated < sizeof(*f) + qname->len) {
11505 + v = roundup_pow_of_two(*allocated + qname->len);
11506 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11507 + if (unlikely(!p)) {
11515 + drinfo = &f->drinfo;
11517 + memcpy(drinfo->oldname, qname->name, qname->len);
11518 + AuDbg("i%llu, %.*s\n",
11519 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11520 + drinfo->oldname);
11527 +/* callers have to free the return value */
11528 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11530 + struct au_drinfo *ret, *drinfo;
11531 + struct au_drinfo_fdata fdata;
11536 + ret = ERR_PTR(-EIO);
11538 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11539 + if (unlikely(ssz != sizeof(fdata))) {
11540 + AuIOErr("ssz %zd, %u, %pD2\n",
11541 + ssz, (unsigned int)sizeof(fdata), file);
11545 + fdata.magic = ntohl((__force __be32)fdata.magic);
11546 + switch (fdata.magic) {
11547 + case AUFS_DRINFO_MAGIC_V1:
11550 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11551 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11555 + drinfo = &fdata.drinfo;
11556 + len = drinfo->oldnamelen;
11558 + AuIOErr("broken drinfo %pD2\n", file);
11563 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11564 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11565 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11566 + (unsigned long long)drinfo->ino,
11567 + (unsigned long long)h_ino, file);
11568 + goto out; /* success */
11571 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11572 + if (unlikely(!ret)) {
11573 + ret = ERR_PTR(-ENOMEM);
11574 + AuTraceErrPtr(ret);
11579 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11580 + if (unlikely(ssz != len)) {
11582 + ret = ERR_PTR(-EIO);
11583 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11587 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11593 +/* ---------------------------------------------------------------------- */
11595 +/* in order to be revertible */
11596 +struct au_drinfo_rev_elm {
11598 + struct dentry *info_dentry;
11599 + struct au_drinfo *info_last;
11602 +struct au_drinfo_rev {
11603 + unsigned char already;
11604 + aufs_bindex_t nelm;
11605 + struct au_drinfo_rev_elm elm[0];
11608 +/* todo: isn't it too large? */
11609 +struct au_drinfo_store {
11610 + struct path h_ppath;
11611 + struct dentry *h_dentry;
11612 + struct au_drinfo_fdata *fdata;
11613 + char *infoname; /* inside of whname, just after PFX */
11614 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11615 + aufs_bindex_t btgt, btail;
11616 + unsigned char no_sio,
11617 + allocated, /* current size of *fdata */
11618 + infonamelen, /* room size for p */
11619 + whnamelen, /* length of the genarated name */
11620 + renameback; /* renamed back */
11623 +/* on rename(2) error, the caller should revert it using @elm */
11624 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11625 + struct au_drinfo_rev_elm *elm)
11630 + struct path infopath = {
11631 + .mnt = w->h_ppath.mnt
11633 + struct inode *h_dir, *h_inode, *delegated;
11634 + struct file *infofile;
11635 + struct qstr *qname;
11638 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11640 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11642 + AuTraceErrPtr(infopath.dentry);
11643 + if (IS_ERR(infopath.dentry)) {
11644 + err = PTR_ERR(infopath.dentry);
11649 + h_dir = d_inode(w->h_ppath.dentry);
11650 + if (elm && d_is_negative(infopath.dentry)) {
11651 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11653 + if (unlikely(err))
11655 + elm->created = 1;
11656 + elm->info_dentry = dget(infopath.dentry);
11659 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11660 + AuTraceErrPtr(infofile);
11661 + if (IS_ERR(infofile)) {
11662 + err = PTR_ERR(infofile);
11666 + h_inode = d_inode(infopath.dentry);
11667 + if (elm && i_size_read(h_inode)) {
11668 + h_inode = d_inode(w->h_dentry);
11669 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11670 + AuTraceErrPtr(elm->info_last);
11671 + if (IS_ERR(elm->info_last)) {
11672 + err = PTR_ERR(elm->info_last);
11673 + elm->info_last = NULL;
11674 + AuDebugOn(elm->info_dentry);
11679 + if (elm && w->renameback) {
11680 + delegated = NULL;
11681 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11683 + if (unlikely(err == -EWOULDBLOCK))
11689 + qname = &w->h_dentry->d_name;
11690 + len = sizeof(*w->fdata) + qname->len;
11692 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11693 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11694 + if (ssz == len) {
11695 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11696 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11697 + goto out_fput; /* success */
11702 + /* the caller should revert it using @elm */
11708 + dput(infopath.dentry);
11714 +struct au_call_drinfo_do_store_args {
11716 + struct au_drinfo_store *w;
11717 + struct au_drinfo_rev_elm *elm;
11720 +static void au_call_drinfo_do_store(void *args)
11722 + struct au_call_drinfo_do_store_args *a = args;
11724 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11727 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11728 + struct au_drinfo_rev_elm *elm)
11730 + int err, wkq_err;
11733 + err = au_drinfo_do_store(w, elm);
11735 + struct au_call_drinfo_do_store_args a = {
11740 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11741 + if (unlikely(wkq_err))
11749 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11750 + aufs_bindex_t btgt)
11754 + memset(w, 0, sizeof(*w));
11755 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11756 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11757 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11758 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11760 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11763 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11764 + if (unlikely(!w->fdata)) {
11768 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11775 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11780 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11781 + struct au_drinfo_store *w)
11783 + struct au_drinfo_rev_elm *elm;
11784 + struct inode *h_dir, *delegated;
11786 + struct path infopath = {
11787 + .mnt = w->h_ppath.mnt
11790 + h_dir = d_inode(w->h_ppath.dentry);
11791 + IMustLock(h_dir);
11795 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11796 + AuDebugOn(elm->created && elm->info_last);
11797 + if (elm->created) {
11799 + delegated = NULL;
11800 + infopath.dentry = elm->info_dentry;
11801 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11804 + if (unlikely(err == -EWOULDBLOCK))
11806 + dput(elm->info_dentry);
11807 + } else if (elm->info_last) {
11809 + w->fdata->drinfo = *elm->info_last;
11810 + memcpy(w->fdata->drinfo.oldname,
11811 + elm->info_last->oldname,
11812 + elm->info_last->oldnamelen);
11813 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11814 + kfree(elm->info_last);
11816 + if (unlikely(err))
11817 + AuIOErr("%d, %s\n", err, w->whname);
11818 + /* go on even if err */
11822 +/* caller has to call au_dr_rename_fin() later */
11823 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11824 + struct qstr *dst_name, void *_rev)
11826 + int err, sz, nelm;
11827 + aufs_bindex_t bindex, btail;
11828 + struct au_drinfo_store work;
11829 + struct au_drinfo_rev *rev, **p;
11830 + struct au_drinfo_rev_elm *elm;
11831 + struct super_block *sb;
11832 + struct au_branch *br;
11833 + struct au_hinode *hdir;
11835 + err = au_drinfo_store_work_init(&work, btgt);
11837 + if (unlikely(err))
11841 + btail = au_dbtaildir(dentry);
11842 + nelm = btail - btgt;
11843 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11844 + rev = kcalloc(1, sz, GFP_NOFS);
11845 + if (unlikely(!rev)) {
11849 + rev->nelm = nelm;
11855 + sb = dentry->d_sb;
11856 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11857 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11858 + hdir = au_hi(d_inode(dentry), btgt);
11859 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11860 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11861 + work.h_dentry = au_h_dptr(dentry, bindex);
11862 + if (!work.h_dentry)
11865 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11866 + &work.allocated);
11868 + if (unlikely(err))
11871 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11872 + br = au_sbr(sb, bindex);
11873 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11874 + work.whnamelen += au_drinfo_name(br, work.infoname,
11875 + work.infonamelen);
11876 + AuDbg("whname %.*s, i%llu, %.*s\n",
11877 + work.whnamelen, work.whname,
11878 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11879 + work.fdata->drinfo.oldnamelen,
11880 + work.fdata->drinfo.oldname);
11882 + err = au_drinfo_store_sio(&work, elm);
11884 + if (unlikely(err))
11887 + if (unlikely(err)) {
11888 + /* revert all drinfo */
11889 + au_drinfo_store_rev(rev, &work);
11893 + au_hn_inode_unlock(hdir);
11896 + au_drinfo_store_work_fin(&work);
11901 +/* ---------------------------------------------------------------------- */
11903 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11904 + struct qstr *dst_name, void *_rev)
11906 + int err, already;
11908 + struct super_block *sb;
11909 + struct au_branch *br;
11910 + struct au_dr_br *dr;
11911 + struct dentry *h_dentry;
11912 + struct inode *h_inode;
11913 + struct au_dr_hino *ent;
11914 + struct au_drinfo_rev *rev, **p;
11916 + AuDbg("bindex %d\n", bindex);
11919 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11920 + if (unlikely(!ent))
11924 + br = au_sbr(sb, bindex);
11925 + dr = &br->br_dirren;
11926 + h_dentry = au_h_dptr(src, bindex);
11927 + h_inode = d_inode(h_dentry);
11928 + ino = h_inode->i_ino;
11929 + ent->dr_h_ino = ino;
11930 + already = au_dr_hino_test_add(dr, ino, ent);
11931 + AuDbg("b%d, hi%llu, already %d\n",
11932 + bindex, (unsigned long long)ino, already);
11934 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11939 + rev->already = already;
11940 + goto out; /* success */
11945 + au_dr_hino_del(dr, ent);
11953 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11955 + struct au_drinfo_rev *rev;
11956 + struct au_drinfo_rev_elm *elm;
11961 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11962 + dput(elm->info_dentry);
11963 + kfree(elm->info_last);
11968 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11971 + struct au_drinfo_store work;
11972 + struct au_drinfo_rev *rev = _rev;
11973 + struct super_block *sb;
11974 + struct au_branch *br;
11975 + struct inode *h_inode;
11976 + struct au_dr_br *dr;
11977 + struct au_dr_hino *ent;
11979 + err = au_drinfo_store_work_init(&work, btgt);
11980 + if (unlikely(err))
11984 + br = au_sbr(sb, btgt);
11985 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11986 + work.h_ppath.mnt = au_br_mnt(br);
11987 + au_drinfo_store_rev(rev, &work);
11988 + au_drinfo_store_work_fin(&work);
11989 + if (rev->already)
11992 + dr = &br->br_dirren;
11993 + h_inode = d_inode(work.h_ppath.dentry);
11994 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11996 + au_dr_hino_del(dr, ent);
12001 + if (unlikely(err))
12002 + pr_err("failed to remove dirren info\n");
12005 +/* ---------------------------------------------------------------------- */
12007 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12008 + char *whname, int whnamelen,
12009 + struct dentry **info_dentry)
12011 + struct au_drinfo *drinfo;
12013 + struct inode *h_dir;
12014 + struct path infopath;
12017 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12019 + *info_dentry = NULL;
12022 + h_dir = d_inode(h_ppath->dentry);
12023 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12024 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12026 + if (IS_ERR(infopath.dentry)) {
12027 + drinfo = (void *)infopath.dentry;
12031 + if (d_is_negative(infopath.dentry))
12032 + goto out_dput; /* success */
12034 + infopath.mnt = h_ppath->mnt;
12035 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12036 + inode_unlock_shared(h_dir);
12039 + drinfo = (void *)f;
12043 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12044 + if (IS_ERR_OR_NULL(drinfo))
12047 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12048 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12053 + dput(infopath.dentry);
12056 + inode_unlock_shared(h_dir);
12057 + AuTraceErrPtr(drinfo);
12061 +struct au_drinfo_do_load_args {
12062 + struct au_drinfo **drinfop;
12063 + struct path *h_ppath;
12066 + struct dentry **info_dentry;
12069 +static void au_call_drinfo_do_load(void *args)
12071 + struct au_drinfo_do_load_args *a = args;
12073 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12077 +struct au_drinfo_load {
12078 + struct path h_ppath;
12079 + struct qstr *qname;
12080 + unsigned char no_sio;
12082 + aufs_bindex_t ninfo;
12083 + struct au_drinfo **drinfo;
12086 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12087 + struct au_branch *br)
12089 + int err, wkq_err, whnamelen, e;
12090 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12091 + = AUFS_WH_DR_INFO_PFX;
12092 + struct au_drinfo *drinfo;
12093 + struct qstr oldname;
12094 + struct inode *h_dir, *delegated;
12095 + struct dentry *info_dentry;
12096 + struct path infopath;
12098 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12099 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12100 + sizeof(whname) - whnamelen);
12102 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12105 + struct au_drinfo_do_load_args args = {
12106 + .drinfop = &drinfo,
12107 + .h_ppath = &w->h_ppath,
12108 + .whname = whname,
12109 + .whnamelen = whnamelen,
12110 + .info_dentry = &info_dentry
12112 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12113 + if (unlikely(wkq_err))
12114 + drinfo = ERR_PTR(wkq_err);
12116 + err = PTR_ERR(drinfo);
12117 + if (IS_ERR_OR_NULL(drinfo))
12121 + oldname.len = drinfo->oldnamelen;
12122 + oldname.name = drinfo->oldname;
12123 + if (au_qstreq(w->qname, &oldname)) {
12124 + /* the name is renamed back */
12128 + infopath.dentry = info_dentry;
12129 + infopath.mnt = w->h_ppath.mnt;
12130 + h_dir = d_inode(w->h_ppath.dentry);
12131 + delegated = NULL;
12132 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12133 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12134 + inode_unlock(h_dir);
12136 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12137 + if (unlikely(e == -EWOULDBLOCK))
12140 + kfree(w->drinfo[bindex]);
12141 + w->drinfo[bindex] = drinfo;
12142 + dput(info_dentry);
12149 +/* ---------------------------------------------------------------------- */
12151 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12153 + struct au_drinfo **p = drinfo;
12156 + kfree(*drinfo++);
12160 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12161 + aufs_bindex_t btgt)
12164 + struct au_drinfo_load w;
12165 + aufs_bindex_t bindex, bbot;
12166 + struct au_branch *br;
12167 + struct inode *h_dir;
12168 + struct au_dr_hino *ent;
12169 + struct super_block *sb;
12171 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12172 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12173 + AuLNPair(&lkup->whname), btgt);
12175 + sb = dentry->d_sb;
12176 + bbot = au_sbbot(sb);
12177 + w.ninfo = bbot + 1;
12178 + if (!lkup->dirren.drinfo) {
12179 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12180 + sizeof(*lkup->dirren.drinfo),
12182 + if (unlikely(!lkup->dirren.drinfo)) {
12186 + lkup->dirren.ninfo = w.ninfo;
12188 + w.drinfo = lkup->dirren.drinfo;
12189 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12190 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12191 + AuDebugOn(!w.h_ppath.dentry);
12192 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12193 + w.qname = &dentry->d_name;
12196 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12197 + br = au_sbr(sb, bindex);
12198 + err = au_drinfo_load(&w, bindex, br);
12199 + if (unlikely(err))
12201 + if (w.drinfo[bindex])
12205 + br = au_sbr(sb, btgt);
12206 + h_dir = d_inode(w.h_ppath.dentry);
12207 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12209 + au_dr_hino_del(&br->br_dirren, ent);
12212 + goto out; /* success */
12215 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12216 + lkup->dirren.ninfo = 0;
12217 + lkup->dirren.drinfo = NULL;
12223 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12225 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12228 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12231 + struct au_drinfo *drinfo;
12234 + if (!lkup->dirren.drinfo)
12236 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12237 + drinfo = lkup->dirren.drinfo[btgt + 1];
12241 + kfree(lkup->whname.name);
12242 + lkup->whname.name = NULL;
12243 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12244 + lkup->dirren.dr_name.name = drinfo->oldname;
12245 + lkup->name = &lkup->dirren.dr_name;
12246 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12248 + AuDbg("name %.*s, whname %.*s, b%d\n",
12249 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12257 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12261 + struct au_drinfo *drinfo;
12264 + if (!lkup->dirren.drinfo)
12266 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12267 + drinfo = lkup->dirren.drinfo[bindex + 1];
12271 + match = (drinfo->ino == h_ino);
12272 + AuDbg("match %d\n", match);
12278 +/* ---------------------------------------------------------------------- */
12280 +int au_dr_opt_set(struct super_block *sb)
12283 + aufs_bindex_t bindex, bbot;
12284 + struct au_branch *br;
12287 + bbot = au_sbbot(sb);
12288 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12289 + br = au_sbr(sb, bindex);
12290 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12296 +int au_dr_opt_flush(struct super_block *sb)
12299 + aufs_bindex_t bindex, bbot;
12300 + struct au_branch *br;
12303 + bbot = au_sbbot(sb);
12304 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12305 + br = au_sbr(sb, bindex);
12306 + if (au_br_writable(br->br_perm))
12307 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12313 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12316 + aufs_bindex_t bindex, bbot;
12317 + struct au_branch *br;
12321 + err = au_dr_opt_flush(sb);
12322 + if (unlikely(err))
12326 + bbot = au_sbbot(sb);
12327 + for (bindex = 0; bindex <= bbot; bindex++) {
12328 + br = au_sbr(sb, bindex);
12329 + au_dr_hino_free(&br->br_dirren);
12335 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12336 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12337 +++ linux/fs/aufs/dirren.h 2018-07-19 09:46:13.056647808 +0200
12339 +/* SPDX-License-Identifier: GPL-2.0 */
12341 + * Copyright (C) 2017-2018 Junjiro R. Okajima
12343 + * This program, aufs is free software; you can redistribute it and/or modify
12344 + * it under the terms of the GNU General Public License as published by
12345 + * the Free Software Foundation; either version 2 of the License, or
12346 + * (at your option) any later version.
12348 + * This program is distributed in the hope that it will be useful,
12349 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12350 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12351 + * GNU General Public License for more details.
12353 + * You should have received a copy of the GNU General Public License
12354 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12358 + * renamed dir info
12361 +#ifndef __AUFS_DIRREN_H__
12362 +#define __AUFS_DIRREN_H__
12366 +#include <linux/dcache.h>
12367 +#include <linux/statfs.h>
12368 +#include <linux/uuid.h>
12371 +#define AuDirren_NHASH 100
12373 +#ifdef CONFIG_AUFS_DIRREN
12374 +enum au_brid_type {
12381 +struct au_dr_brid {
12382 + enum au_brid_type type;
12384 + uuid_t uuid; /* unimplemented yet */
12390 +/* 20 is the max digits length of ulong 64 */
12391 +/* brid-type "_" uuid "_" inum */
12392 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12393 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12395 +struct au_dr_hino {
12396 + struct hlist_bl_node dr_hnode;
12401 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12402 + struct au_dr_brid dr_brid;
12405 +struct au_dr_lookup {
12406 + /* dr_name is pointed by struct au_do_lookup_args.name */
12407 + struct qstr dr_name; /* subset of dr_info */
12408 + aufs_bindex_t ninfo;
12409 + struct au_drinfo **drinfo;
12412 +struct au_dr_hino;
12414 +struct au_dr_br { };
12415 +struct au_dr_lookup { };
12418 +/* ---------------------------------------------------------------------- */
12421 +struct au_do_lookup_args;
12423 +#ifdef CONFIG_AUFS_DIRREN
12424 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12425 + struct au_dr_hino *add_ent);
12426 +void au_dr_hino_free(struct au_dr_br *dr);
12427 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12428 + const struct path *path);
12429 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12430 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12431 + struct qstr *dst_name, void *_rev);
12432 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12433 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12434 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12435 + aufs_bindex_t bindex);
12436 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12437 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12439 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12440 +int au_dr_opt_set(struct super_block *sb);
12441 +int au_dr_opt_flush(struct super_block *sb);
12442 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12444 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12445 + struct au_dr_hino *add_ent);
12446 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12447 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12448 + const struct path *path);
12449 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12450 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12451 + struct qstr *dst_name, void *_rev);
12452 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12453 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12455 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12456 + aufs_bindex_t bindex);
12457 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12458 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12459 + aufs_bindex_t bindex, ino_t h_ino);
12460 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12461 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12462 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12463 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12466 +/* ---------------------------------------------------------------------- */
12468 +#ifdef CONFIG_AUFS_DIRREN
12469 +static inline int au_dr_ihash(ino_t h_ino)
12471 + return h_ino % AuDirren_NHASH;
12474 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12477 +#endif /* __KERNEL__ */
12478 +#endif /* __AUFS_DIRREN_H__ */
12479 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12480 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12481 +++ linux/fs/aufs/dynop.c 2018-07-19 09:46:13.056647808 +0200
12483 +/* SPDX-License-Identifier: GPL-2.0 */
12485 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12487 + * This program, aufs is free software; you can redistribute it and/or modify
12488 + * it under the terms of the GNU General Public License as published by
12489 + * the Free Software Foundation; either version 2 of the License, or
12490 + * (at your option) any later version.
12492 + * This program is distributed in the hope that it will be useful,
12493 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12494 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12495 + * GNU General Public License for more details.
12497 + * You should have received a copy of the GNU General Public License
12498 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12502 + * dynamically customizable operations for regular files
12507 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12510 + * How large will these lists be?
12511 + * Usually just a few elements, 20-30 at most for each, I guess.
12513 +static struct hlist_bl_head dynop[AuDyLast];
12515 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12516 + const void *h_op)
12518 + struct au_dykey *key, *tmp;
12519 + struct hlist_bl_node *pos;
12522 + hlist_bl_lock(hbl);
12523 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12524 + if (tmp->dk_op.dy_hop == h_op) {
12526 + kref_get(&key->dk_kref);
12529 + hlist_bl_unlock(hbl);
12534 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12536 + struct au_dykey **k, *found;
12537 + const void *h_op = key->dk_op.dy_hop;
12541 + k = br->br_dykey;
12542 + for (i = 0; i < AuBrDynOp; i++)
12544 + if (k[i]->dk_op.dy_hop == h_op) {
12551 + spin_lock(&br->br_dykey_lock);
12552 + for (; i < AuBrDynOp; i++)
12554 + if (k[i]->dk_op.dy_hop == h_op) {
12562 + spin_unlock(&br->br_dykey_lock);
12563 + BUG_ON(i == AuBrDynOp); /* expand the array */
12569 +/* kref_get() if @key is already added */
12570 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12572 + struct au_dykey *tmp, *found;
12573 + struct hlist_bl_node *pos;
12574 + const void *h_op = key->dk_op.dy_hop;
12577 + hlist_bl_lock(hbl);
12578 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12579 + if (tmp->dk_op.dy_hop == h_op) {
12580 + kref_get(&tmp->dk_kref);
12585 + hlist_bl_add_head(&key->dk_hnode, hbl);
12586 + hlist_bl_unlock(hbl);
12593 +static void dy_free_rcu(struct rcu_head *rcu)
12595 + struct au_dykey *key;
12597 + key = container_of(rcu, struct au_dykey, dk_rcu);
12602 +static void dy_free(struct kref *kref)
12604 + struct au_dykey *key;
12605 + struct hlist_bl_head *hbl;
12607 + key = container_of(kref, struct au_dykey, dk_kref);
12608 + hbl = dynop + key->dk_op.dy_type;
12609 + au_hbl_del(&key->dk_hnode, hbl);
12610 + call_rcu(&key->dk_rcu, dy_free_rcu);
12613 +void au_dy_put(struct au_dykey *key)
12615 + kref_put(&key->dk_kref, dy_free);
12618 +/* ---------------------------------------------------------------------- */
12620 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12622 +#ifdef CONFIG_AUFS_DEBUG
12623 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12624 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12626 +#define DyDbgDeclare(cnt) do {} while (0)
12627 +#define DyDbgInc(cnt) do {} while (0)
12630 +#define DySet(func, dst, src, h_op, h_sb) do { \
12632 + if (h_op->func) { \
12634 + dst.func = src.func; \
12636 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12640 +#define DySetForce(func, dst, src) do { \
12641 + AuDebugOn(!src.func); \
12643 + dst.func = src.func; \
12646 +#define DySetAop(func) \
12647 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12648 +#define DySetAopForce(func) \
12649 + DySetForce(func, dyaop->da_op, aufs_aop)
12651 +static void dy_aop(struct au_dykey *key, const void *h_op,
12652 + struct super_block *h_sb __maybe_unused)
12654 + struct au_dyaop *dyaop = (void *)key;
12655 + const struct address_space_operations *h_aop = h_op;
12656 + DyDbgDeclare(cnt);
12658 + AuDbg("%s\n", au_sbtype(h_sb));
12660 + DySetAop(writepage);
12661 + DySetAopForce(readpage); /* force */
12662 + DySetAop(writepages);
12663 + DySetAop(set_page_dirty);
12664 + DySetAop(readpages);
12665 + DySetAop(write_begin);
12666 + DySetAop(write_end);
12668 + DySetAop(invalidatepage);
12669 + DySetAop(releasepage);
12670 + DySetAop(freepage);
12671 + /* this one will be changed according to an aufs mount option */
12672 + DySetAop(direct_IO);
12673 + DySetAop(migratepage);
12674 + DySetAop(isolate_page);
12675 + DySetAop(putback_page);
12676 + DySetAop(launder_page);
12677 + DySetAop(is_partially_uptodate);
12678 + DySetAop(is_dirty_writeback);
12679 + DySetAop(error_remove_page);
12680 + DySetAop(swap_activate);
12681 + DySetAop(swap_deactivate);
12683 + DyDbgSize(cnt, *h_aop);
12686 +/* ---------------------------------------------------------------------- */
12688 +static void dy_bug(struct kref *kref)
12693 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12695 + struct au_dykey *key, *old;
12696 + struct hlist_bl_head *hbl;
12699 + void (*set)(struct au_dykey *key, const void *h_op,
12700 + struct super_block *h_sb __maybe_unused);
12702 + static const struct op a[] = {
12704 + .sz = sizeof(struct au_dyaop),
12708 + const struct op *p;
12710 + hbl = dynop + op->dy_type;
12711 + key = dy_gfind_get(hbl, op->dy_hop);
12713 + goto out_add; /* success */
12715 + p = a + op->dy_type;
12716 + key = kzalloc(p->sz, GFP_NOFS);
12717 + if (unlikely(!key)) {
12718 + key = ERR_PTR(-ENOMEM);
12722 + key->dk_op.dy_hop = op->dy_hop;
12723 + kref_init(&key->dk_kref);
12724 + p->set(key, op->dy_hop, au_br_sb(br));
12725 + old = dy_gadd(hbl, key);
12732 + old = dy_bradd(br, key);
12734 + /* its ref-count should never be zero here */
12735 + kref_put(&key->dk_kref, dy_bug);
12740 +/* ---------------------------------------------------------------------- */
12742 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
12743 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12744 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12745 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12746 + * See the aufs manual in detail.
12748 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12751 + dyaop->da_op.direct_IO = NULL;
12753 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12756 +static struct au_dyaop *dy_aget(struct au_branch *br,
12757 + const struct address_space_operations *h_aop,
12760 + struct au_dyaop *dyaop;
12761 + struct au_dynop op;
12763 + op.dy_type = AuDy_AOP;
12764 + op.dy_haop = h_aop;
12765 + dyaop = (void *)dy_get(&op, br);
12766 + if (IS_ERR(dyaop))
12768 + dy_adx(dyaop, do_dx);
12774 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12775 + struct inode *h_inode)
12778 + struct super_block *sb;
12779 + struct au_branch *br;
12780 + struct au_dyaop *dyaop;
12782 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12783 + IiMustWriteLock(inode);
12785 + sb = inode->i_sb;
12786 + br = au_sbr(sb, bindex);
12787 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12788 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12789 + err = PTR_ERR(dyaop);
12790 + if (IS_ERR(dyaop))
12791 + /* unnecessary to call dy_fput() */
12795 + inode->i_mapping->a_ops = &dyaop->da_op;
12802 + * Is it safe to replace a_ops during the inode/file is in operation?
12803 + * Yes, I hope so.
12805 +int au_dy_irefresh(struct inode *inode)
12808 + aufs_bindex_t btop;
12809 + struct inode *h_inode;
12812 + if (S_ISREG(inode->i_mode)) {
12813 + btop = au_ibtop(inode);
12814 + h_inode = au_h_iptr(inode, btop);
12815 + err = au_dy_iaop(inode, btop, h_inode);
12820 +void au_dy_arefresh(int do_dx)
12822 + struct hlist_bl_head *hbl;
12823 + struct hlist_bl_node *pos;
12824 + struct au_dykey *key;
12826 + hbl = dynop + AuDy_AOP;
12827 + hlist_bl_lock(hbl);
12828 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12829 + dy_adx((void *)key, do_dx);
12830 + hlist_bl_unlock(hbl);
12833 +/* ---------------------------------------------------------------------- */
12835 +void __init au_dy_init(void)
12839 + /* make sure that 'struct au_dykey *' can be any type */
12840 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12842 + for (i = 0; i < AuDyLast; i++)
12843 + INIT_HLIST_BL_HEAD(dynop + i);
12846 +void au_dy_fin(void)
12850 + for (i = 0; i < AuDyLast; i++)
12851 + WARN_ON(!hlist_bl_empty(dynop + i));
12853 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12854 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12855 +++ linux/fs/aufs/dynop.h 2018-07-19 09:46:13.056647808 +0200
12857 +/* SPDX-License-Identifier: GPL-2.0 */
12859 + * Copyright (C) 2010-2018 Junjiro R. Okajima
12861 + * This program, aufs is free software; you can redistribute it and/or modify
12862 + * it under the terms of the GNU General Public License as published by
12863 + * the Free Software Foundation; either version 2 of the License, or
12864 + * (at your option) any later version.
12866 + * This program is distributed in the hope that it will be useful,
12867 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12869 + * GNU General Public License for more details.
12871 + * You should have received a copy of the GNU General Public License
12872 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12876 + * dynamically customizable operations (for regular files only)
12879 +#ifndef __AUFS_DYNOP_H__
12880 +#define __AUFS_DYNOP_H__
12884 +#include <linux/fs.h>
12885 +#include <linux/kref.h>
12887 +enum {AuDy_AOP, AuDyLast};
12892 + const void *dy_hop;
12893 + const struct address_space_operations *dy_haop;
12899 + struct hlist_bl_node dk_hnode;
12900 + struct rcu_head dk_rcu;
12902 + struct au_dynop dk_op;
12905 + * during I am in the branch local array, kref is gotten. when the
12906 + * branch is removed, kref is put.
12908 + struct kref dk_kref;
12911 +/* stop unioning since their sizes are very different from each other */
12913 + struct au_dykey da_key;
12914 + struct address_space_operations da_op; /* not const */
12917 +/* ---------------------------------------------------------------------- */
12921 +void au_dy_put(struct au_dykey *key);
12922 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12923 + struct inode *h_inode);
12924 +int au_dy_irefresh(struct inode *inode);
12925 +void au_dy_arefresh(int do_dio);
12927 +void __init au_dy_init(void);
12928 +void au_dy_fin(void);
12930 +#endif /* __KERNEL__ */
12931 +#endif /* __AUFS_DYNOP_H__ */
12932 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12933 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12934 +++ linux/fs/aufs/export.c 2018-07-19 09:46:13.056647808 +0200
12936 +/* SPDX-License-Identifier: GPL-2.0 */
12938 + * Copyright (C) 2005-2018 Junjiro R. Okajima
12940 + * This program, aufs is free software; you can redistribute it and/or modify
12941 + * it under the terms of the GNU General Public License as published by
12942 + * the Free Software Foundation; either version 2 of the License, or
12943 + * (at your option) any later version.
12945 + * This program is distributed in the hope that it will be useful,
12946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12948 + * GNU General Public License for more details.
12950 + * You should have received a copy of the GNU General Public License
12951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12958 +#include <linux/exportfs.h>
12959 +#include <linux/fs_struct.h>
12960 +#include <linux/namei.h>
12961 +#include <linux/nsproxy.h>
12962 +#include <linux/random.h>
12963 +#include <linux/writeback.h>
12967 +#ifdef CONFIG_AUFS_INO_T_64
12975 +static ino_t decode_ino(__u32 *a)
12979 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12981 +#ifdef CONFIG_AUFS_INO_T_64
12987 +static void encode_ino(__u32 *a, ino_t ino)
12993 +#ifdef CONFIG_AUFS_INO_T_64
12998 +/* NFS file handle */
13002 +#ifdef CONFIG_AUFS_INO_T_64
13003 + /* support 64bit inode number */
13016 + Fh_ino = Fh_ino1,
13017 + Fh_dir_ino = Fh_dir_ino1
13020 +static int au_test_anon(struct dentry *dentry)
13022 + /* note: read d_flags without d_lock */
13023 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13026 +int au_test_nfsd(void)
13029 + struct task_struct *tsk = current;
13030 + char comm[sizeof(tsk->comm)];
13033 + if (tsk->flags & PF_KTHREAD) {
13034 + get_task_comm(comm, tsk);
13035 + ret = !strcmp(comm, "nfsd");
13041 +/* ---------------------------------------------------------------------- */
13042 +/* inode generation external table */
13044 +void au_xigen_inc(struct inode *inode)
13049 + struct super_block *sb;
13050 + struct au_sbinfo *sbinfo;
13052 + sb = inode->i_sb;
13053 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13055 + sbinfo = au_sbi(sb);
13056 + pos = inode->i_ino;
13057 + pos *= sizeof(igen);
13058 + igen = inode->i_generation + 1;
13059 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13060 + sizeof(igen), &pos);
13061 + if (sz == sizeof(igen))
13062 + return; /* success */
13064 + if (unlikely(sz >= 0))
13065 + AuIOErr("xigen error (%zd)\n", sz);
13068 +int au_xigen_new(struct inode *inode)
13073 + struct super_block *sb;
13074 + struct au_sbinfo *sbinfo;
13075 + struct file *file;
13078 + /* todo: dirty, at mount time */
13079 + if (inode->i_ino == AUFS_ROOT_INO)
13081 + sb = inode->i_sb;
13082 + SiMustAnyLock(sb);
13083 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13087 + pos = inode->i_ino;
13088 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13089 + AuIOErr1("too large i%lld\n", pos);
13092 + pos *= sizeof(inode->i_generation);
13095 + sbinfo = au_sbi(sb);
13096 + file = sbinfo->si_xigen;
13099 + if (vfsub_f_size_read(file)
13100 + < pos + sizeof(inode->i_generation)) {
13101 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13102 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13103 + sizeof(inode->i_generation), &pos);
13105 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13106 + sizeof(inode->i_generation), &pos);
13107 + if (sz == sizeof(inode->i_generation))
13108 + goto out; /* success */
13111 + if (unlikely(sz >= 0)) {
13113 + AuIOErr("xigen error (%zd)\n", sz);
13120 +int au_xigen_set(struct super_block *sb, struct path *path)
13123 + struct au_sbinfo *sbinfo;
13124 + struct file *file;
13126 + SiMustWriteLock(sb);
13128 + sbinfo = au_sbi(sb);
13129 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13130 + err = PTR_ERR(file);
13131 + if (IS_ERR(file))
13134 + if (sbinfo->si_xigen)
13135 + fput(sbinfo->si_xigen);
13136 + sbinfo->si_xigen = file;
13143 +void au_xigen_clr(struct super_block *sb)
13145 + struct au_sbinfo *sbinfo;
13147 + SiMustWriteLock(sb);
13149 + sbinfo = au_sbi(sb);
13150 + if (sbinfo->si_xigen) {
13151 + fput(sbinfo->si_xigen);
13152 + sbinfo->si_xigen = NULL;
13156 +/* ---------------------------------------------------------------------- */
13158 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13161 + struct dentry *dentry, *d;
13162 + struct inode *inode;
13163 + unsigned int sigen;
13166 + inode = ilookup(sb, ino);
13170 + dentry = ERR_PTR(-ESTALE);
13171 + sigen = au_sigen(sb);
13172 + if (unlikely(au_is_bad_inode(inode)
13173 + || IS_DEADDIR(inode)
13174 + || sigen != au_iigen(inode, NULL)))
13178 + if (!dir_ino || S_ISDIR(inode->i_mode))
13179 + dentry = d_find_alias(inode);
13181 + spin_lock(&inode->i_lock);
13182 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13183 + spin_lock(&d->d_lock);
13184 + if (!au_test_anon(d)
13185 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13186 + dentry = dget_dlock(d);
13187 + spin_unlock(&d->d_lock);
13190 + spin_unlock(&d->d_lock);
13192 + spin_unlock(&inode->i_lock);
13194 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13195 + /* need to refresh */
13203 + AuTraceErrPtr(dentry);
13207 +/* ---------------------------------------------------------------------- */
13209 +/* todo: dirty? */
13210 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13212 +struct au_compare_mnt_args {
13214 + struct super_block *sb;
13217 + struct vfsmount *mnt;
13220 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13222 + struct au_compare_mnt_args *a = arg;
13224 + if (mnt->mnt_sb != a->sb)
13226 + a->mnt = mntget(mnt);
13230 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13233 + struct path root;
13234 + struct au_compare_mnt_args args = {
13238 + get_fs_root(current->fs, &root);
13240 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13241 + rcu_read_unlock();
13244 + AuDebugOn(!args.mnt);
13248 +struct au_nfsd_si_lock {
13249 + unsigned int sigen;
13250 + aufs_bindex_t bindex, br_id;
13251 + unsigned char force_lock;
13254 +static int si_nfsd_read_lock(struct super_block *sb,
13255 + struct au_nfsd_si_lock *nsi_lock)
13258 + aufs_bindex_t bindex;
13260 + si_read_lock(sb, AuLock_FLUSH);
13262 + /* branch id may be wrapped around */
13264 + bindex = au_br_index(sb, nsi_lock->br_id);
13265 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13266 + goto out; /* success */
13270 + if (!nsi_lock->force_lock)
13271 + si_read_unlock(sb);
13274 + nsi_lock->bindex = bindex;
13278 +struct find_name_by_ino {
13279 + struct dir_context ctx;
13280 + int called, found;
13287 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13288 + loff_t offset, u64 ino, unsigned int d_type)
13290 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13294 + if (a->ino != ino)
13297 + memcpy(a->name, name, namelen);
13298 + a->namelen = namelen;
13303 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13304 + struct au_nfsd_si_lock *nsi_lock)
13306 + struct dentry *dentry, *parent;
13307 + struct file *file;
13308 + struct inode *dir;
13309 + struct find_name_by_ino arg = {
13311 + .actor = find_name_by_ino
13316 + parent = path->dentry;
13318 + si_read_unlock(parent->d_sb);
13319 + file = vfsub_dentry_open(path, au_dir_roflags);
13320 + dentry = (void *)file;
13321 + if (IS_ERR(file))
13324 + dentry = ERR_PTR(-ENOMEM);
13325 + arg.name = (void *)__get_free_page(GFP_NOFS);
13326 + if (unlikely(!arg.name))
13333 + err = vfsub_iterate_dir(file, &arg.ctx);
13334 + } while (!err && !arg.found && arg.called);
13335 + dentry = ERR_PTR(err);
13336 + if (unlikely(err))
13338 + /* instead of ENOENT */
13339 + dentry = ERR_PTR(-ESTALE);
13343 + /* do not call vfsub_lkup_one() */
13344 + dir = d_inode(parent);
13345 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13346 + AuTraceErrPtr(dentry);
13347 + if (IS_ERR(dentry))
13349 + AuDebugOn(au_test_anon(dentry));
13350 + if (unlikely(d_really_is_negative(dentry))) {
13352 + dentry = ERR_PTR(-ENOENT);
13356 + free_page((unsigned long)arg.name);
13360 + if (unlikely(nsi_lock
13361 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13362 + if (!IS_ERR(dentry)) {
13364 + dentry = ERR_PTR(-ESTALE);
13366 + AuTraceErrPtr(dentry);
13370 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13372 + struct au_nfsd_si_lock *nsi_lock)
13374 + struct dentry *dentry;
13375 + struct path path;
13377 + if (dir_ino != AUFS_ROOT_INO) {
13378 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13379 + dentry = path.dentry;
13380 + if (!path.dentry || IS_ERR(path.dentry))
13382 + AuDebugOn(au_test_anon(path.dentry));
13384 + path.dentry = dget(sb->s_root);
13386 + path.mnt = au_mnt_get(sb);
13387 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13391 + AuTraceErrPtr(dentry);
13395 +/* ---------------------------------------------------------------------- */
13397 +static int h_acceptable(void *expv, struct dentry *dentry)
13402 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13403 + char *buf, int len, struct super_block *sb)
13407 + struct path path;
13409 + p = d_path(h_rootpath, buf, len);
13414 + path.mnt = h_rootpath->mnt;
13415 + path.dentry = h_parent;
13416 + p = d_path(&path, buf, len);
13422 + path.mnt = au_mnt_get(sb);
13423 + path.dentry = sb->s_root;
13424 + p = d_path(&path, buf, len - strlen(p));
13425 + mntput(path.mnt);
13429 + p[strlen(p)] = '/';
13432 + AuTraceErrPtr(p);
13437 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13438 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13440 + struct dentry *dentry, *h_parent, *root;
13441 + struct super_block *h_sb;
13442 + char *pathname, *p;
13443 + struct vfsmount *h_mnt;
13444 + struct au_branch *br;
13446 + struct path path;
13448 + br = au_sbr(sb, nsi_lock->bindex);
13449 + h_mnt = au_br_mnt(br);
13450 + h_sb = h_mnt->mnt_sb;
13451 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13453 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13454 + fh_len - Fh_tail, fh[Fh_h_type],
13455 + h_acceptable, /*context*/NULL);
13457 + dentry = h_parent;
13458 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13459 + AuWarn1("%s decode_fh failed, %ld\n",
13460 + au_sbtype(h_sb), PTR_ERR(h_parent));
13464 + if (unlikely(au_test_anon(h_parent))) {
13465 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13466 + au_sbtype(h_sb));
13467 + goto out_h_parent;
13470 + dentry = ERR_PTR(-ENOMEM);
13471 + pathname = (void *)__get_free_page(GFP_NOFS);
13472 + if (unlikely(!pathname))
13473 + goto out_h_parent;
13475 + root = sb->s_root;
13476 + path.mnt = h_mnt;
13477 + di_read_lock_parent(root, !AuLock_IR);
13478 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13479 + di_read_unlock(root, !AuLock_IR);
13480 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13481 + dentry = (void *)p;
13483 + goto out_pathname;
13485 + si_read_unlock(sb);
13486 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13487 + dentry = ERR_PTR(err);
13488 + if (unlikely(err))
13491 + dentry = ERR_PTR(-ENOENT);
13492 + AuDebugOn(au_test_anon(path.dentry));
13493 + if (unlikely(d_really_is_negative(path.dentry)))
13496 + if (ino != d_inode(path.dentry)->i_ino)
13497 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13499 + dentry = dget(path.dentry);
13504 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13505 + if (!IS_ERR(dentry)) {
13507 + dentry = ERR_PTR(-ESTALE);
13510 + free_page((unsigned long)pathname);
13514 + AuTraceErrPtr(dentry);
13518 +/* ---------------------------------------------------------------------- */
13520 +static struct dentry *
13521 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13524 + struct dentry *dentry;
13525 + __u32 *fh = fid->raw;
13526 + struct au_branch *br;
13527 + ino_t ino, dir_ino;
13528 + struct au_nfsd_si_lock nsi_lock = {
13532 + dentry = ERR_PTR(-ESTALE);
13533 + /* it should never happen, but the file handle is unreliable */
13534 + if (unlikely(fh_len < Fh_tail))
13536 + nsi_lock.sigen = fh[Fh_sigen];
13537 + nsi_lock.br_id = fh[Fh_br_id];
13539 + /* branch id may be wrapped around */
13541 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13543 + nsi_lock.force_lock = 1;
13545 + /* is this inode still cached? */
13546 + ino = decode_ino(fh + Fh_ino);
13547 + /* it should never happen */
13548 + if (unlikely(ino == AUFS_ROOT_INO))
13551 + dir_ino = decode_ino(fh + Fh_dir_ino);
13552 + dentry = decode_by_ino(sb, ino, dir_ino);
13553 + if (IS_ERR(dentry))
13558 + /* is the parent dir cached? */
13559 + br = au_sbr(sb, nsi_lock.bindex);
13561 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13562 + if (IS_ERR(dentry))
13567 + /* lookup path */
13568 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13569 + if (IS_ERR(dentry))
13571 + if (unlikely(!dentry))
13572 + /* todo?: make it ESTALE */
13576 + if (!au_digen_test(dentry, au_sigen(sb))
13577 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13578 + goto out_unlock; /* success */
13581 + dentry = ERR_PTR(-ESTALE);
13585 + si_read_unlock(sb);
13587 + AuTraceErrPtr(dentry);
13591 +#if 0 /* reserved for future use */
13592 +/* support subtreecheck option */
13593 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13594 + int fh_len, int fh_type)
13596 + struct dentry *parent;
13597 + __u32 *fh = fid->raw;
13600 + dir_ino = decode_ino(fh + Fh_dir_ino);
13601 + parent = decode_by_ino(sb, dir_ino, 0);
13602 + if (IS_ERR(parent))
13605 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13606 + dir_ino, fh, fh_len);
13609 + AuTraceErrPtr(parent);
13614 +/* ---------------------------------------------------------------------- */
13616 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13617 + struct inode *dir)
13620 + aufs_bindex_t bindex;
13621 + struct super_block *sb, *h_sb;
13622 + struct dentry *dentry, *parent, *h_parent;
13623 + struct inode *h_dir;
13624 + struct au_branch *br;
13627 + if (unlikely(*max_len <= Fh_tail)) {
13628 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13632 + err = FILEID_ROOT;
13633 + if (inode->i_ino == AUFS_ROOT_INO) {
13634 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13639 + sb = inode->i_sb;
13640 + err = si_read_lock(sb, AuLock_FLUSH);
13641 + if (unlikely(err))
13644 +#ifdef CONFIG_AUFS_DEBUG
13645 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13646 + AuWarn1("NFS-exporting requires xino\n");
13650 + ii_read_lock_child(inode);
13651 + bindex = au_ibtop(inode);
13653 + dentry = d_find_any_alias(inode);
13654 + if (unlikely(!dentry))
13656 + AuDebugOn(au_test_anon(dentry));
13657 + parent = dget_parent(dentry);
13659 + if (unlikely(!parent))
13661 + if (d_really_is_positive(parent))
13662 + dir = d_inode(parent);
13665 + ii_read_lock_parent(dir);
13666 + h_dir = au_h_iptr(dir, bindex);
13667 + ii_read_unlock(dir);
13668 + if (unlikely(!h_dir))
13670 + h_parent = d_find_any_alias(h_dir);
13671 + if (unlikely(!h_parent))
13672 + goto out_hparent;
13675 + br = au_sbr(sb, bindex);
13676 + h_sb = au_br_sb(br);
13677 + if (unlikely(!h_sb->s_export_op)) {
13678 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13679 + goto out_hparent;
13682 + fh[Fh_br_id] = br->br_id;
13683 + fh[Fh_sigen] = au_sigen(sb);
13684 + encode_ino(fh + Fh_ino, inode->i_ino);
13685 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13686 + fh[Fh_igen] = inode->i_generation;
13688 + *max_len -= Fh_tail;
13689 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13691 + /*connectable or subtreecheck*/0);
13692 + err = fh[Fh_h_type];
13693 + *max_len += Fh_tail;
13694 + /* todo: macros? */
13695 + if (err != FILEID_INVALID)
13698 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13705 + ii_read_unlock(inode);
13706 + si_read_unlock(sb);
13708 + if (unlikely(err < 0))
13709 + err = FILEID_INVALID;
13713 +/* ---------------------------------------------------------------------- */
13715 +static int aufs_commit_metadata(struct inode *inode)
13718 + aufs_bindex_t bindex;
13719 + struct super_block *sb;
13720 + struct inode *h_inode;
13721 + int (*f)(struct inode *inode);
13723 + sb = inode->i_sb;
13724 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13725 + ii_write_lock_child(inode);
13726 + bindex = au_ibtop(inode);
13727 + AuDebugOn(bindex < 0);
13728 + h_inode = au_h_iptr(inode, bindex);
13730 + f = h_inode->i_sb->s_export_op->commit_metadata;
13732 + err = f(h_inode);
13734 + struct writeback_control wbc = {
13735 + .sync_mode = WB_SYNC_ALL,
13736 + .nr_to_write = 0 /* metadata only */
13739 + err = sync_inode(h_inode, &wbc);
13742 + au_cpup_attr_timesizes(inode);
13743 + ii_write_unlock(inode);
13744 + si_read_unlock(sb);
13748 +/* ---------------------------------------------------------------------- */
13750 +static struct export_operations aufs_export_op = {
13751 + .fh_to_dentry = aufs_fh_to_dentry,
13752 + /* .fh_to_parent = aufs_fh_to_parent, */
13753 + .encode_fh = aufs_encode_fh,
13754 + .commit_metadata = aufs_commit_metadata
13757 +void au_export_init(struct super_block *sb)
13759 + struct au_sbinfo *sbinfo;
13762 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13763 + && IS_MODULE(CONFIG_EXPORTFS),
13764 + AUFS_NAME ": unsupported configuration "
13765 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13767 + sb->s_export_op = &aufs_export_op;
13768 + sbinfo = au_sbi(sb);
13769 + sbinfo->si_xigen = NULL;
13770 + get_random_bytes(&u, sizeof(u));
13771 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13772 + atomic_set(&sbinfo->si_xigen_next, u);
13774 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13775 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13776 +++ linux/fs/aufs/fhsm.c 2018-07-19 09:46:13.056647808 +0200
13778 +/* SPDX-License-Identifier: GPL-2.0 */
13780 + * Copyright (C) 2011-2018 Junjiro R. Okajima
13782 + * This program, aufs is free software; you can redistribute it and/or modify
13783 + * it under the terms of the GNU General Public License as published by
13784 + * the Free Software Foundation; either version 2 of the License, or
13785 + * (at your option) any later version.
13787 + * This program is distributed in the hope that it will be useful,
13788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13790 + * GNU General Public License for more details.
13792 + * You should have received a copy of the GNU General Public License
13793 + * along with this program; if not, write to the Free Software
13794 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13798 + * File-based Hierarchy Storage Management
13801 +#include <linux/anon_inodes.h>
13802 +#include <linux/poll.h>
13803 +#include <linux/seq_file.h>
13804 +#include <linux/statfs.h>
13807 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13809 + struct au_sbinfo *sbinfo;
13810 + struct au_fhsm *fhsm;
13812 + SiMustAnyLock(sb);
13814 + sbinfo = au_sbi(sb);
13815 + fhsm = &sbinfo->si_fhsm;
13816 + AuDebugOn(!fhsm);
13817 + return fhsm->fhsm_bottom;
13820 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13822 + struct au_sbinfo *sbinfo;
13823 + struct au_fhsm *fhsm;
13825 + SiMustWriteLock(sb);
13827 + sbinfo = au_sbi(sb);
13828 + fhsm = &sbinfo->si_fhsm;
13829 + AuDebugOn(!fhsm);
13830 + fhsm->fhsm_bottom = bindex;
13833 +/* ---------------------------------------------------------------------- */
13835 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13837 + struct au_br_fhsm *bf;
13839 + bf = br->br_fhsm;
13840 + MtxMustLock(&bf->bf_lock);
13842 + return !bf->bf_readable
13843 + || time_after(jiffies,
13844 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13847 +/* ---------------------------------------------------------------------- */
13849 +static void au_fhsm_notify(struct super_block *sb, int val)
13851 + struct au_sbinfo *sbinfo;
13852 + struct au_fhsm *fhsm;
13854 + SiMustAnyLock(sb);
13856 + sbinfo = au_sbi(sb);
13857 + fhsm = &sbinfo->si_fhsm;
13858 + if (au_fhsm_pid(fhsm)
13859 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13860 + atomic_set(&fhsm->fhsm_readable, val);
13862 + wake_up(&fhsm->fhsm_wqh);
13866 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13867 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13870 + struct au_branch *br;
13871 + struct au_br_fhsm *bf;
13873 + br = au_sbr(sb, bindex);
13874 + AuDebugOn(au_br_rdonly(br));
13875 + bf = br->br_fhsm;
13879 + mutex_lock(&bf->bf_lock);
13881 + MtxMustLock(&bf->bf_lock);
13883 + /* sb->s_root for NFS is unreliable */
13884 + err = au_br_stfs(br, &bf->bf_stfs);
13885 + if (unlikely(err)) {
13886 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13890 + bf->bf_jiffy = jiffies;
13891 + bf->bf_readable = 1;
13893 + au_fhsm_notify(sb, /*val*/1);
13895 + *rstfs = bf->bf_stfs;
13899 + mutex_unlock(&bf->bf_lock);
13900 + au_fhsm_notify(sb, /*val*/1);
13905 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13908 + struct au_sbinfo *sbinfo;
13909 + struct au_fhsm *fhsm;
13910 + struct au_branch *br;
13911 + struct au_br_fhsm *bf;
13913 + AuDbg("b%d, force %d\n", bindex, force);
13914 + SiMustAnyLock(sb);
13916 + sbinfo = au_sbi(sb);
13917 + fhsm = &sbinfo->si_fhsm;
13918 + if (!au_ftest_si(sbinfo, FHSM)
13919 + || fhsm->fhsm_bottom == bindex)
13922 + br = au_sbr(sb, bindex);
13923 + bf = br->br_fhsm;
13925 + mutex_lock(&bf->bf_lock);
13927 + || au_fhsm_pid(fhsm)
13928 + || au_fhsm_test_jiffy(sbinfo, br))
13929 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13931 + mutex_unlock(&bf->bf_lock);
13934 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13936 + aufs_bindex_t bindex, bbot;
13937 + struct au_branch *br;
13939 + /* exclude the bottom */
13940 + bbot = au_fhsm_bottom(sb);
13941 + for (bindex = 0; bindex < bbot; bindex++) {
13942 + br = au_sbr(sb, bindex);
13943 + if (au_br_fhsm(br->br_perm))
13944 + au_fhsm_wrote(sb, bindex, force);
13948 +/* ---------------------------------------------------------------------- */
13950 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13953 + struct au_sbinfo *sbinfo;
13954 + struct au_fhsm *fhsm;
13957 + sbinfo = file->private_data;
13958 + fhsm = &sbinfo->si_fhsm;
13959 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13960 + if (atomic_read(&fhsm->fhsm_readable))
13961 + mask = EPOLLIN /* | EPOLLRDNORM */;
13964 + AuDbg("mask 0x%x\n", mask);
13968 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13969 + struct aufs_stfs *stfs, __s16 brid)
13973 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13975 + err = __put_user(brid, &stbr->brid);
13976 + if (unlikely(err))
13982 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13983 + struct aufs_stbr __user *stbr, size_t count)
13987 + aufs_bindex_t bindex, bbot;
13988 + struct au_branch *br;
13989 + struct au_br_fhsm *bf;
13991 + /* except the bottom branch */
13994 + bbot = au_fhsm_bottom(sb);
13995 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13996 + br = au_sbr(sb, bindex);
13997 + if (!au_br_fhsm(br->br_perm))
14000 + bf = br->br_fhsm;
14001 + mutex_lock(&bf->bf_lock);
14002 + if (bf->bf_readable) {
14004 + if (count >= sizeof(*stbr))
14005 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14008 + bf->bf_readable = 0;
14009 + count -= sizeof(*stbr);
14013 + mutex_unlock(&bf->bf_lock);
14016 + err = sizeof(*stbr) * nstbr;
14021 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14026 + aufs_bindex_t nfhsm, bindex, bbot;
14027 + struct au_sbinfo *sbinfo;
14028 + struct au_fhsm *fhsm;
14029 + struct au_branch *br;
14030 + struct super_block *sb;
14033 + sbinfo = file->private_data;
14034 + fhsm = &sbinfo->si_fhsm;
14036 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14037 + if (!atomic_read(&fhsm->fhsm_readable)) {
14038 + if (vfsub_file_flags(file) & O_NONBLOCK)
14041 + err = wait_event_interruptible_locked_irq
14043 + atomic_read(&fhsm->fhsm_readable));
14045 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14046 + if (unlikely(err))
14049 + /* sb may already be dead */
14050 + au_rw_read_lock(&sbinfo->si_rwsem);
14051 + readable = atomic_read(&fhsm->fhsm_readable);
14052 + if (readable > 0) {
14053 + sb = sbinfo->si_sb;
14055 + /* exclude the bottom branch */
14057 + bbot = au_fhsm_bottom(sb);
14058 + for (bindex = 0; bindex < bbot; bindex++) {
14059 + br = au_sbr(sb, bindex);
14060 + if (au_br_fhsm(br->br_perm))
14064 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14065 + atomic_set(&fhsm->fhsm_readable, 0);
14066 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14070 + au_rw_read_unlock(&sbinfo->si_rwsem);
14078 +static int au_fhsm_release(struct inode *inode, struct file *file)
14080 + struct au_sbinfo *sbinfo;
14081 + struct au_fhsm *fhsm;
14083 + /* sb may already be dead */
14084 + sbinfo = file->private_data;
14085 + fhsm = &sbinfo->si_fhsm;
14086 + spin_lock(&fhsm->fhsm_spin);
14087 + fhsm->fhsm_pid = 0;
14088 + spin_unlock(&fhsm->fhsm_spin);
14089 + kobject_put(&sbinfo->si_kobj);
14094 +static const struct file_operations au_fhsm_fops = {
14095 + .owner = THIS_MODULE,
14096 + .llseek = noop_llseek,
14097 + .read = au_fhsm_read,
14098 + .poll = au_fhsm_poll,
14099 + .release = au_fhsm_release
14102 +int au_fhsm_fd(struct super_block *sb, int oflags)
14105 + struct au_sbinfo *sbinfo;
14106 + struct au_fhsm *fhsm;
14109 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14113 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14117 + sbinfo = au_sbi(sb);
14118 + fhsm = &sbinfo->si_fhsm;
14119 + spin_lock(&fhsm->fhsm_spin);
14120 + if (!fhsm->fhsm_pid)
14121 + fhsm->fhsm_pid = current->pid;
14124 + spin_unlock(&fhsm->fhsm_spin);
14125 + if (unlikely(err))
14128 + oflags |= O_RDONLY;
14129 + /* oflags |= FMODE_NONOTIFY; */
14130 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14132 + if (unlikely(fd < 0))
14135 + /* succeed reglardless 'fhsm' status */
14136 + kobject_get(&sbinfo->si_kobj);
14137 + si_noflush_read_lock(sb);
14138 + if (au_ftest_si(sbinfo, FHSM))
14139 + au_fhsm_wrote_all(sb, /*force*/0);
14140 + si_read_unlock(sb);
14141 + goto out; /* success */
14144 + spin_lock(&fhsm->fhsm_spin);
14145 + fhsm->fhsm_pid = 0;
14146 + spin_unlock(&fhsm->fhsm_spin);
14152 +/* ---------------------------------------------------------------------- */
14154 +int au_fhsm_br_alloc(struct au_branch *br)
14159 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14161 + au_br_fhsm_init(br->br_fhsm);
14168 +/* ---------------------------------------------------------------------- */
14170 +void au_fhsm_fin(struct super_block *sb)
14172 + au_fhsm_notify(sb, /*val*/-1);
14175 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14177 + struct au_fhsm *fhsm;
14179 + fhsm = &sbinfo->si_fhsm;
14180 + spin_lock_init(&fhsm->fhsm_spin);
14181 + init_waitqueue_head(&fhsm->fhsm_wqh);
14182 + atomic_set(&fhsm->fhsm_readable, 0);
14183 + fhsm->fhsm_expire
14184 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14185 + fhsm->fhsm_bottom = -1;
14188 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14190 + sbinfo->si_fhsm.fhsm_expire
14191 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14194 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14198 + if (!au_ftest_si(sbinfo, FHSM))
14201 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14202 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14203 + seq_printf(seq, ",fhsm_sec=%u", u);
14205 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14206 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14207 +++ linux/fs/aufs/file.c 2018-07-19 09:46:13.056647808 +0200
14209 +/* SPDX-License-Identifier: GPL-2.0 */
14211 + * Copyright (C) 2005-2018 Junjiro R. Okajima
14213 + * This program, aufs is free software; you can redistribute it and/or modify
14214 + * it under the terms of the GNU General Public License as published by
14215 + * the Free Software Foundation; either version 2 of the License, or
14216 + * (at your option) any later version.
14218 + * This program is distributed in the hope that it will be useful,
14219 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14221 + * GNU General Public License for more details.
14223 + * You should have received a copy of the GNU General Public License
14224 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14228 + * handling file/dir, and address_space operation
14231 +#ifdef CONFIG_AUFS_DEBUG
14232 +#include <linux/migrate.h>
14234 +#include <linux/pagemap.h>
14237 +/* drop flags for writing */
14238 +unsigned int au_file_roflags(unsigned int flags)
14240 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14241 + flags |= O_RDONLY | O_NOATIME;
14245 +/* common functions to regular file and dir */
14246 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14247 + struct file *file, int force_wr)
14249 + struct file *h_file;
14250 + struct dentry *h_dentry;
14251 + struct inode *h_inode;
14252 + struct super_block *sb;
14253 + struct au_branch *br;
14254 + struct path h_path;
14257 + /* a race condition can happen between open and unlink/rmdir */
14258 + h_file = ERR_PTR(-ENOENT);
14259 + h_dentry = au_h_dptr(dentry, bindex);
14260 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14262 + h_inode = d_inode(h_dentry);
14263 + spin_lock(&h_dentry->d_lock);
14264 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14265 + /* || !d_inode(dentry)->i_nlink */
14267 + spin_unlock(&h_dentry->d_lock);
14268 + if (unlikely(err))
14271 + sb = dentry->d_sb;
14272 + br = au_sbr(sb, bindex);
14273 + err = au_br_test_oflag(flags, br);
14274 + h_file = ERR_PTR(err);
14275 + if (unlikely(err))
14278 + /* drop flags for writing */
14279 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14280 + if (force_wr && !(flags & O_WRONLY))
14282 + flags = au_file_roflags(flags);
14284 + h_file = ERR_PTR(-EROFS);
14285 + flags = au_file_roflags(flags);
14286 + if (unlikely(vfsub_native_ro(h_inode)
14287 + || IS_APPEND(h_inode)))
14289 + flags &= ~O_ACCMODE;
14290 + flags |= O_WRONLY;
14293 + flags &= ~O_CREAT;
14295 + h_path.dentry = h_dentry;
14296 + h_path.mnt = au_br_mnt(br);
14297 + h_file = vfsub_dentry_open(&h_path, flags);
14298 + if (IS_ERR(h_file))
14301 + if (flags & __FMODE_EXEC) {
14302 + err = deny_write_access(h_file);
14303 + if (unlikely(err)) {
14305 + h_file = ERR_PTR(err);
14309 + fsnotify_open(h_file);
14310 + goto out; /* success */
14318 +static int au_cmoo(struct dentry *dentry)
14320 + int err, cmoo, matched;
14321 + unsigned int udba;
14322 + struct path h_path;
14323 + struct au_pin pin;
14324 + struct au_cp_generic cpg = {
14325 + .dentry = dentry,
14330 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14332 + struct inode *delegated;
14333 + struct super_block *sb;
14334 + struct au_sbinfo *sbinfo;
14335 + struct au_fhsm *fhsm;
14337 + struct au_branch *br;
14338 + struct dentry *parent;
14339 + struct au_hinode *hdir;
14341 + DiMustWriteLock(dentry);
14342 + IiMustWriteLock(d_inode(dentry));
14345 + if (IS_ROOT(dentry))
14347 + cpg.bsrc = au_dbtop(dentry);
14351 + sb = dentry->d_sb;
14352 + sbinfo = au_sbi(sb);
14353 + fhsm = &sbinfo->si_fhsm;
14354 + pid = au_fhsm_pid(fhsm);
14357 + && (current->pid == pid
14358 + || rcu_dereference(current->real_parent)->pid == pid));
14359 + rcu_read_unlock();
14363 + br = au_sbr(sb, cpg.bsrc);
14364 + cmoo = au_br_cmoo(br->br_perm);
14367 + if (!d_is_reg(dentry))
14368 + cmoo &= AuBrAttr_COO_ALL;
14372 + parent = dget_parent(dentry);
14373 + di_write_lock_parent(parent);
14374 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14376 + if (unlikely(err < 0)) {
14377 + err = 0; /* there is no upper writable branch */
14380 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14382 + /* do not respect the coo attrib for the target branch */
14383 + err = au_cpup_dirs(dentry, cpg.bdst);
14384 + if (unlikely(err))
14387 + di_downgrade_lock(parent, AuLock_IR);
14388 + udba = au_opt_udba(sb);
14389 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14390 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14391 + if (unlikely(err))
14394 + err = au_sio_cpup_simple(&cpg);
14396 + if (unlikely(err))
14398 + if (!(cmoo & AuBrWAttr_MOO))
14399 + goto out_parent; /* success */
14401 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14402 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14403 + if (unlikely(err))
14406 + h_path.mnt = au_br_mnt(br);
14407 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14408 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14409 + delegated = NULL;
14410 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14412 + /* todo: keep h_dentry or not? */
14413 + if (unlikely(err == -EWOULDBLOCK)) {
14414 + pr_warn("cannot retry for NFSv4 delegation"
14415 + " for an internal unlink\n");
14418 + if (unlikely(err)) {
14419 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14423 + goto out_parent; /* success */
14426 + di_downgrade_lock(parent, AuLock_IR);
14428 + di_read_unlock(parent, AuLock_IR);
14435 +int au_do_open(struct file *file, struct au_do_open_args *args)
14437 + int err, aopen = args->aopen;
14438 + struct dentry *dentry;
14439 + struct au_finfo *finfo;
14442 + err = au_finfo_init(file, args->fidir);
14445 + err = au_finfo_init(file, args->fidir);
14448 + if (unlikely(err))
14451 + dentry = file->f_path.dentry;
14452 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14453 + di_write_lock_child(dentry);
14454 + err = au_cmoo(dentry);
14455 + di_downgrade_lock(dentry, AuLock_IR);
14458 + err = args->open(file, vfsub_file_flags(file), NULL);
14461 + err = args->open(file, vfsub_file_flags(file), NULL);
14465 + di_read_unlock(dentry, AuLock_IR);
14467 + finfo = au_fi(file);
14469 + finfo->fi_file = file;
14470 + au_hbl_add(&finfo->fi_hlist,
14471 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14474 + fi_write_unlock(file);
14477 + fi_write_unlock(file);
14480 + if (unlikely(err)) {
14481 + finfo->fi_hdir = NULL;
14482 + au_finfo_fin(file);
14490 +int au_reopen_nondir(struct file *file)
14493 + aufs_bindex_t btop;
14494 + struct dentry *dentry;
14495 + struct file *h_file, *h_file_tmp;
14497 + dentry = file->f_path.dentry;
14498 + btop = au_dbtop(dentry);
14499 + h_file_tmp = NULL;
14500 + if (au_fbtop(file) == btop) {
14501 + h_file = au_hf_top(file);
14502 + if (file->f_mode == h_file->f_mode)
14503 + return 0; /* success */
14504 + h_file_tmp = h_file;
14505 + get_file(h_file_tmp);
14506 + au_set_h_fptr(file, btop, NULL);
14508 + AuDebugOn(au_fi(file)->fi_hdir);
14511 + * file exists on both of rw and ro
14512 + * open --> dbtop and fbtop are both 0
14513 + * prepend a branch as rw, "rw" become ro
14515 + * delete the top branch, "rw" becomes rw again
14516 + * --> dbtop is 1, fbtop is still 0
14517 + * write --> fbtop is 0 but dbtop is 1
14519 + /* AuDebugOn(au_fbtop(file) < btop); */
14521 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14522 + file, /*force_wr*/0);
14523 + err = PTR_ERR(h_file);
14524 + if (IS_ERR(h_file)) {
14525 + if (h_file_tmp) {
14526 + au_sbr_get(dentry->d_sb, btop);
14527 + au_set_h_fptr(file, btop, h_file_tmp);
14528 + h_file_tmp = NULL;
14530 + goto out; /* todo: close all? */
14534 + au_set_fbtop(file, btop);
14535 + au_set_h_fptr(file, btop, h_file);
14536 + au_update_figen(file);
14537 + /* todo: necessary? */
14538 + /* file->f_ra = h_file->f_ra; */
14542 + fput(h_file_tmp);
14546 +/* ---------------------------------------------------------------------- */
14548 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14549 + struct dentry *hi_wh)
14552 + aufs_bindex_t btop;
14553 + struct au_dinfo *dinfo;
14554 + struct dentry *h_dentry;
14555 + struct au_hdentry *hdp;
14557 + dinfo = au_di(file->f_path.dentry);
14558 + AuRwMustWriteLock(&dinfo->di_rwsem);
14560 + btop = dinfo->di_btop;
14561 + dinfo->di_btop = btgt;
14562 + hdp = au_hdentry(dinfo, btgt);
14563 + h_dentry = hdp->hd_dentry;
14564 + hdp->hd_dentry = hi_wh;
14565 + err = au_reopen_nondir(file);
14566 + hdp->hd_dentry = h_dentry;
14567 + dinfo->di_btop = btop;
14572 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14573 + aufs_bindex_t bcpup, struct au_pin *pin)
14576 + struct inode *inode, *h_inode;
14577 + struct dentry *h_dentry, *hi_wh;
14578 + struct au_cp_generic cpg = {
14579 + .dentry = file->f_path.dentry,
14586 + au_update_dbtop(cpg.dentry);
14587 + inode = d_inode(cpg.dentry);
14589 + if (au_dbtop(cpg.dentry) <= bcpup
14590 + && au_dbbot(cpg.dentry) >= bcpup) {
14591 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14592 + if (h_dentry && d_is_positive(h_dentry))
14593 + h_inode = d_inode(h_dentry);
14595 + hi_wh = au_hi_wh(inode, bcpup);
14596 + if (!hi_wh && !h_inode)
14597 + err = au_sio_cpup_wh(&cpg, file);
14599 + /* already copied-up after unlink */
14600 + err = au_reopen_wh(file, bcpup, hi_wh);
14603 + && (inode->i_nlink > 1
14604 + || (inode->i_state & I_LINKABLE))
14605 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14606 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14612 + * prepare the @file for writing.
14614 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14617 + aufs_bindex_t dbtop;
14618 + struct dentry *parent;
14619 + struct inode *inode;
14620 + struct super_block *sb;
14621 + struct file *h_file;
14622 + struct au_cp_generic cpg = {
14623 + .dentry = file->f_path.dentry,
14628 + .flags = AuCpup_DTIME
14631 + sb = cpg.dentry->d_sb;
14632 + inode = d_inode(cpg.dentry);
14633 + cpg.bsrc = au_fbtop(file);
14634 + err = au_test_ro(sb, cpg.bsrc, inode);
14635 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14636 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14641 + /* need to cpup or reopen */
14642 + parent = dget_parent(cpg.dentry);
14643 + di_write_lock_parent(parent);
14644 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14646 + if (unlikely(err < 0))
14650 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14651 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14652 + if (unlikely(err))
14656 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14657 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14658 + if (unlikely(err))
14661 + dbtop = au_dbtop(cpg.dentry);
14662 + if (dbtop <= cpg.bdst)
14663 + cpg.bsrc = cpg.bdst;
14665 + if (dbtop <= cpg.bdst /* just reopen */
14666 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14668 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14669 + if (IS_ERR(h_file))
14670 + err = PTR_ERR(h_file);
14672 + di_downgrade_lock(parent, AuLock_IR);
14673 + if (dbtop > cpg.bdst)
14674 + err = au_sio_cpup_simple(&cpg);
14676 + err = au_reopen_nondir(file);
14677 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14679 + } else { /* copyup as wh and reopen */
14681 + * since writable hfsplus branch is not supported,
14682 + * h_open_pre/post() are unnecessary.
14684 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14685 + di_downgrade_lock(parent, AuLock_IR);
14689 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14690 + goto out_dput; /* success */
14696 + di_downgrade_lock(parent, AuLock_IR);
14698 + di_read_unlock(parent, AuLock_IR);
14705 +/* ---------------------------------------------------------------------- */
14707 +int au_do_flush(struct file *file, fl_owner_t id,
14708 + int (*flush)(struct file *file, fl_owner_t id))
14711 + struct super_block *sb;
14712 + struct inode *inode;
14714 + inode = file_inode(file);
14715 + sb = inode->i_sb;
14716 + si_noflush_read_lock(sb);
14717 + fi_read_lock(file);
14718 + ii_read_lock_child(inode);
14720 + err = flush(file, id);
14721 + au_cpup_attr_timesizes(inode);
14723 + ii_read_unlock(inode);
14724 + fi_read_unlock(file);
14725 + si_read_unlock(sb);
14729 +/* ---------------------------------------------------------------------- */
14731 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14734 + struct au_pin pin;
14735 + struct au_finfo *finfo;
14736 + struct dentry *parent, *hi_wh;
14737 + struct inode *inode;
14738 + struct super_block *sb;
14739 + struct au_cp_generic cpg = {
14740 + .dentry = file->f_path.dentry,
14745 + .flags = AuCpup_DTIME
14748 + FiMustWriteLock(file);
14751 + finfo = au_fi(file);
14752 + sb = cpg.dentry->d_sb;
14753 + inode = d_inode(cpg.dentry);
14754 + cpg.bdst = au_ibtop(inode);
14755 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14758 + parent = dget_parent(cpg.dentry);
14759 + if (au_test_ro(sb, cpg.bdst, inode)) {
14760 + di_read_lock_parent(parent, !AuLock_IR);
14761 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14763 + di_read_unlock(parent, !AuLock_IR);
14764 + if (unlikely(err < 0))
14769 + di_read_lock_parent(parent, AuLock_IR);
14770 + hi_wh = au_hi_wh(inode, cpg.bdst);
14771 + if (!S_ISDIR(inode->i_mode)
14772 + && au_opt_test(au_mntflags(sb), PLINK)
14773 + && au_plink_test(inode)
14774 + && !d_unhashed(cpg.dentry)
14775 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14776 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14777 + if (unlikely(err))
14780 + /* always superio. */
14781 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14782 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14784 + err = au_sio_cpup_simple(&cpg);
14787 + } else if (hi_wh) {
14788 + /* already copied-up after unlink */
14789 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14790 + *need_reopen = 0;
14794 + di_read_unlock(parent, AuLock_IR);
14801 +static void au_do_refresh_dir(struct file *file)
14803 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14804 + struct au_hfile *p, tmp, *q;
14805 + struct au_finfo *finfo;
14806 + struct super_block *sb;
14807 + struct au_fidir *fidir;
14809 + FiMustWriteLock(file);
14811 + sb = file->f_path.dentry->d_sb;
14812 + finfo = au_fi(file);
14813 + fidir = finfo->fi_hdir;
14814 + AuDebugOn(!fidir);
14815 + p = fidir->fd_hfile + finfo->fi_btop;
14816 + brid = p->hf_br->br_id;
14817 + bbot = fidir->fd_bbot;
14818 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14822 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14823 + if (new_bindex == bindex)
14825 + if (new_bindex < 0) {
14826 + au_set_h_fptr(file, bindex, NULL);
14830 + /* swap two lower inode, and loop again */
14831 + q = fidir->fd_hfile + new_bindex;
14835 + if (tmp.hf_file) {
14841 + p = fidir->fd_hfile;
14842 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14843 + bbot = au_sbbot(sb);
14844 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14845 + finfo->fi_btop++, p++)
14846 + if (p->hf_file) {
14847 + if (file_inode(p->hf_file))
14849 + au_hfput(p, /*execed*/0);
14852 + bbot = au_br_index(sb, brid);
14853 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14854 + finfo->fi_btop++, p++)
14856 + au_hfput(p, /*execed*/0);
14857 + bbot = au_sbbot(sb);
14860 + p = fidir->fd_hfile + bbot;
14861 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14862 + fidir->fd_bbot--, p--)
14863 + if (p->hf_file) {
14864 + if (file_inode(p->hf_file))
14866 + au_hfput(p, /*execed*/0);
14868 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14872 + * after branch manipulating, refresh the file.
14874 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14876 + int err, need_reopen, nbr;
14877 + aufs_bindex_t bbot, bindex;
14878 + struct dentry *dentry;
14879 + struct super_block *sb;
14880 + struct au_finfo *finfo;
14881 + struct au_hfile *hfile;
14883 + dentry = file->f_path.dentry;
14884 + sb = dentry->d_sb;
14885 + nbr = au_sbbot(sb) + 1;
14886 + finfo = au_fi(file);
14887 + if (!finfo->fi_hdir) {
14888 + hfile = &finfo->fi_htop;
14889 + AuDebugOn(!hfile->hf_file);
14890 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14891 + AuDebugOn(bindex < 0);
14892 + if (bindex != finfo->fi_btop)
14893 + au_set_fbtop(file, bindex);
14895 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14896 + if (unlikely(err))
14898 + au_do_refresh_dir(file);
14903 + if (!au_test_mmapped(file))
14904 + err = au_file_refresh_by_inode(file, &need_reopen);
14905 + if (finfo->fi_hdir)
14906 + /* harmless if err */
14907 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14908 + if (!err && need_reopen && !d_unlinked(dentry))
14909 + err = reopen(file);
14911 + au_update_figen(file);
14912 + goto out; /* success */
14915 + /* error, close all lower files */
14916 + if (finfo->fi_hdir) {
14917 + bbot = au_fbbot_dir(file);
14918 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14919 + au_set_h_fptr(file, bindex, NULL);
14926 +/* common function to regular file and dir */
14927 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14928 + int wlock, unsigned int fi_lsc)
14931 + unsigned int sigen, figen;
14932 + aufs_bindex_t btop;
14933 + unsigned char pseudo_link;
14934 + struct dentry *dentry;
14935 + struct inode *inode;
14938 + dentry = file->f_path.dentry;
14939 + inode = d_inode(dentry);
14940 + sigen = au_sigen(dentry->d_sb);
14941 + fi_write_lock_nested(file, fi_lsc);
14942 + figen = au_figen(file);
14944 + di_write_lock_child(dentry);
14946 + di_write_lock_child2(dentry);
14947 + btop = au_dbtop(dentry);
14948 + pseudo_link = (btop != au_ibtop(inode));
14949 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14951 + di_downgrade_lock(dentry, AuLock_IR);
14952 + fi_downgrade_lock(file);
14954 + goto out; /* success */
14957 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14958 + if (au_digen_test(dentry, sigen)) {
14959 + err = au_reval_dpath(dentry, sigen);
14960 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14964 + err = refresh_file(file, reopen);
14967 + di_downgrade_lock(dentry, AuLock_IR);
14968 + fi_downgrade_lock(file);
14971 + di_write_unlock(dentry);
14972 + fi_write_unlock(file);
14979 +/* ---------------------------------------------------------------------- */
14981 +/* cf. aufs_nopage() */
14982 +/* for madvise(2) */
14983 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14985 + unlock_page(page);
14989 +/* it will never be called, but necessary to support O_DIRECT */
14990 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14991 +{ BUG(); return 0; }
14993 +/* they will never be called. */
14994 +#ifdef CONFIG_AUFS_DEBUG
14995 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14996 + loff_t pos, unsigned len, unsigned flags,
14997 + struct page **pagep, void **fsdata)
14998 +{ AuUnsupport(); return 0; }
14999 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15000 + loff_t pos, unsigned len, unsigned copied,
15001 + struct page *page, void *fsdata)
15002 +{ AuUnsupport(); return 0; }
15003 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15004 +{ AuUnsupport(); return 0; }
15006 +static int aufs_set_page_dirty(struct page *page)
15007 +{ AuUnsupport(); return 0; }
15008 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15009 + unsigned int length)
15010 +{ AuUnsupport(); }
15011 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15012 +{ AuUnsupport(); return 0; }
15013 +#if 0 /* called by memory compaction regardless file */
15014 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15015 + struct page *page, enum migrate_mode mode)
15016 +{ AuUnsupport(); return 0; }
15018 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15019 +{ AuUnsupport(); return true; }
15020 +static void aufs_putback_page(struct page *page)
15021 +{ AuUnsupport(); }
15022 +static int aufs_launder_page(struct page *page)
15023 +{ AuUnsupport(); return 0; }
15024 +static int aufs_is_partially_uptodate(struct page *page,
15025 + unsigned long from,
15026 + unsigned long count)
15027 +{ AuUnsupport(); return 0; }
15028 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15030 +{ AuUnsupport(); }
15031 +static int aufs_error_remove_page(struct address_space *mapping,
15032 + struct page *page)
15033 +{ AuUnsupport(); return 0; }
15034 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15036 +{ AuUnsupport(); return 0; }
15037 +static void aufs_swap_deactivate(struct file *file)
15038 +{ AuUnsupport(); }
15039 +#endif /* CONFIG_AUFS_DEBUG */
15041 +const struct address_space_operations aufs_aop = {
15042 + .readpage = aufs_readpage,
15043 + .direct_IO = aufs_direct_IO,
15044 +#ifdef CONFIG_AUFS_DEBUG
15045 + .writepage = aufs_writepage,
15046 + /* no writepages, because of writepage */
15047 + .set_page_dirty = aufs_set_page_dirty,
15048 + /* no readpages, because of readpage */
15049 + .write_begin = aufs_write_begin,
15050 + .write_end = aufs_write_end,
15051 + /* no bmap, no block device */
15052 + .invalidatepage = aufs_invalidatepage,
15053 + .releasepage = aufs_releasepage,
15054 + /* is fallback_migrate_page ok? */
15055 + /* .migratepage = aufs_migratepage, */
15056 + .isolate_page = aufs_isolate_page,
15057 + .putback_page = aufs_putback_page,
15058 + .launder_page = aufs_launder_page,
15059 + .is_partially_uptodate = aufs_is_partially_uptodate,
15060 + .is_dirty_writeback = aufs_is_dirty_writeback,
15061 + .error_remove_page = aufs_error_remove_page,
15062 + .swap_activate = aufs_swap_activate,
15063 + .swap_deactivate = aufs_swap_deactivate
15064 +#endif /* CONFIG_AUFS_DEBUG */
15066 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15067 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15068 +++ linux/fs/aufs/file.h 2018-07-19 09:46:13.059981241 +0200
15070 +/* SPDX-License-Identifier: GPL-2.0 */
15072 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15074 + * This program, aufs is free software; you can redistribute it and/or modify
15075 + * it under the terms of the GNU General Public License as published by
15076 + * the Free Software Foundation; either version 2 of the License, or
15077 + * (at your option) any later version.
15079 + * This program is distributed in the hope that it will be useful,
15080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15082 + * GNU General Public License for more details.
15084 + * You should have received a copy of the GNU General Public License
15085 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15089 + * file operations
15092 +#ifndef __AUFS_FILE_H__
15093 +#define __AUFS_FILE_H__
15097 +#include <linux/file.h>
15098 +#include <linux/fs.h>
15099 +#include <linux/mm_types.h>
15100 +#include <linux/poll.h>
15101 +#include "rwsem.h"
15105 + struct file *hf_file;
15106 + struct au_branch *hf_br;
15111 + aufs_bindex_t fd_bbot;
15112 + aufs_bindex_t fd_nent;
15113 + struct au_vdir *fd_vdir_cache;
15114 + struct au_hfile fd_hfile[];
15117 +static inline int au_fidir_sz(int nent)
15119 + AuDebugOn(nent < 0);
15120 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15124 + atomic_t fi_generation;
15126 + struct au_rwsem fi_rwsem;
15127 + aufs_bindex_t fi_btop;
15129 + /* do not union them */
15130 + struct { /* for non-dir */
15131 + struct au_hfile fi_htop;
15132 + atomic_t fi_mmapped;
15134 + struct au_fidir *fi_hdir; /* for dir only */
15136 + struct hlist_bl_node fi_hlist;
15137 + struct file *fi_file; /* very ugly */
15138 +} ____cacheline_aligned_in_smp;
15140 +/* ---------------------------------------------------------------------- */
15143 +extern const struct address_space_operations aufs_aop;
15144 +unsigned int au_file_roflags(unsigned int flags);
15145 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15146 + struct file *file, int force_wr);
15147 +struct au_do_open_args {
15149 + int (*open)(struct file *file, int flags,
15150 + struct file *h_file);
15151 + struct au_fidir *fidir;
15152 + struct file *h_file;
15154 +int au_do_open(struct file *file, struct au_do_open_args *args);
15155 +int au_reopen_nondir(struct file *file);
15157 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15158 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15159 + int wlock, unsigned int fi_lsc);
15160 +int au_do_flush(struct file *file, fl_owner_t id,
15161 + int (*flush)(struct file *file, fl_owner_t id));
15164 +#ifdef CONFIG_AUFS_POLL
15165 +__poll_t aufs_poll(struct file *file, poll_table *wait);
15168 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15170 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15172 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15173 + struct file *h_file);
15175 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15176 + aufs_bindex_t bindex, int force_wr)
15177 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15178 + struct file *h_file);
15182 +extern const struct file_operations aufs_file_fop;
15183 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15184 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15185 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15188 +void au_hfput(struct au_hfile *hf, int execed);
15189 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15190 + struct file *h_file);
15192 +void au_update_figen(struct file *file);
15193 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15194 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15196 +void au_fi_init_once(void *_fi);
15197 +void au_finfo_fin(struct file *file);
15198 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15201 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15202 +#ifdef CONFIG_COMPAT
15203 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15204 + unsigned long arg);
15205 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15206 + unsigned long arg);
15209 +/* ---------------------------------------------------------------------- */
15211 +static inline struct au_finfo *au_fi(struct file *file)
15213 + return file->private_data;
15216 +/* ---------------------------------------------------------------------- */
15218 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15219 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15220 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15221 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15223 +#define fi_read_trylock_nested(f) \
15224 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15225 +#define fi_write_trylock_nested(f) \
15226 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15229 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15230 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15231 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15233 +/* lock subclass for finfo */
15239 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15241 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15244 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15246 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15250 + * fi_read_lock_1, fi_write_lock_1,
15251 + * fi_read_lock_2, fi_write_lock_2
15253 +#define AuReadLockFunc(name) \
15254 +static inline void fi_read_lock_##name(struct file *f) \
15255 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15257 +#define AuWriteLockFunc(name) \
15258 +static inline void fi_write_lock_##name(struct file *f) \
15259 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15261 +#define AuRWLockFuncs(name) \
15262 + AuReadLockFunc(name) \
15263 + AuWriteLockFunc(name)
15268 +#undef AuReadLockFunc
15269 +#undef AuWriteLockFunc
15270 +#undef AuRWLockFuncs
15272 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15273 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15274 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15276 +/* ---------------------------------------------------------------------- */
15278 +/* todo: hard/soft set? */
15279 +static inline aufs_bindex_t au_fbtop(struct file *file)
15281 + FiMustAnyLock(file);
15282 + return au_fi(file)->fi_btop;
15285 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15287 + FiMustAnyLock(file);
15288 + AuDebugOn(!au_fi(file)->fi_hdir);
15289 + return au_fi(file)->fi_hdir->fd_bbot;
15292 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15294 + FiMustAnyLock(file);
15295 + AuDebugOn(!au_fi(file)->fi_hdir);
15296 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15299 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15301 + FiMustWriteLock(file);
15302 + au_fi(file)->fi_btop = bindex;
15305 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15307 + FiMustWriteLock(file);
15308 + AuDebugOn(!au_fi(file)->fi_hdir);
15309 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15312 +static inline void au_set_fvdir_cache(struct file *file,
15313 + struct au_vdir *vdir_cache)
15315 + FiMustWriteLock(file);
15316 + AuDebugOn(!au_fi(file)->fi_hdir);
15317 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15320 +static inline struct file *au_hf_top(struct file *file)
15322 + FiMustAnyLock(file);
15323 + AuDebugOn(au_fi(file)->fi_hdir);
15324 + return au_fi(file)->fi_htop.hf_file;
15327 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15329 + FiMustAnyLock(file);
15330 + AuDebugOn(!au_fi(file)->fi_hdir);
15331 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15334 +/* todo: memory barrier? */
15335 +static inline unsigned int au_figen(struct file *f)
15337 + return atomic_read(&au_fi(f)->fi_generation);
15340 +static inline void au_set_mmapped(struct file *f)
15342 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15344 + pr_warn("fi_mmapped wrapped around\n");
15345 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15349 +static inline void au_unset_mmapped(struct file *f)
15351 + atomic_dec(&au_fi(f)->fi_mmapped);
15354 +static inline int au_test_mmapped(struct file *f)
15356 + return atomic_read(&au_fi(f)->fi_mmapped);
15359 +/* customize vma->vm_file */
15361 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15362 + struct file *file)
15366 + f = vma->vm_file;
15368 + vma->vm_file = file;
15373 +#define AuDbgVmRegion(file, vma) do {} while (0)
15375 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15376 + struct file *file)
15378 + au_do_vm_file_reset(vma, file);
15381 +#define AuDbgVmRegion(file, vma) \
15382 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15384 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15385 + struct file *file)
15389 + au_do_vm_file_reset(vma, file);
15390 + f = vma->vm_region->vm_file;
15392 + vma->vm_region->vm_file = file;
15395 +#endif /* CONFIG_MMU */
15397 +/* handle vma->vm_prfile */
15398 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15399 + struct file *file)
15402 + vma->vm_prfile = file;
15403 +#ifndef CONFIG_MMU
15405 + vma->vm_region->vm_prfile = file;
15409 +#endif /* __KERNEL__ */
15410 +#endif /* __AUFS_FILE_H__ */
15411 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15412 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15413 +++ linux/fs/aufs/finfo.c 2018-07-19 09:46:13.059981241 +0200
15415 +/* SPDX-License-Identifier: GPL-2.0 */
15417 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15419 + * This program, aufs is free software; you can redistribute it and/or modify
15420 + * it under the terms of the GNU General Public License as published by
15421 + * the Free Software Foundation; either version 2 of the License, or
15422 + * (at your option) any later version.
15424 + * This program is distributed in the hope that it will be useful,
15425 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15426 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15427 + * GNU General Public License for more details.
15429 + * You should have received a copy of the GNU General Public License
15430 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15434 + * file private data
15439 +void au_hfput(struct au_hfile *hf, int execed)
15442 + allow_write_access(hf->hf_file);
15443 + fput(hf->hf_file);
15444 + hf->hf_file = NULL;
15445 + au_br_put(hf->hf_br);
15446 + hf->hf_br = NULL;
15449 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15451 + struct au_finfo *finfo = au_fi(file);
15452 + struct au_hfile *hf;
15453 + struct au_fidir *fidir;
15455 + fidir = finfo->fi_hdir;
15457 + AuDebugOn(finfo->fi_btop != bindex);
15458 + hf = &finfo->fi_htop;
15460 + hf = fidir->fd_hfile + bindex;
15462 + if (hf && hf->hf_file)
15463 + au_hfput(hf, vfsub_file_execed(file));
15465 + FiMustWriteLock(file);
15466 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15467 + hf->hf_file = val;
15468 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15472 +void au_update_figen(struct file *file)
15474 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15475 + /* smp_mb(); */ /* atomic_set */
15478 +/* ---------------------------------------------------------------------- */
15480 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15482 + struct au_fidir *fidir;
15485 + nbr = au_sbbot(sb) + 1;
15487 + nbr = 2; /* initial allocate for 2 branches */
15488 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15490 + fidir->fd_bbot = -1;
15491 + fidir->fd_nent = nbr;
15497 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15500 + struct au_fidir *fidir, *p;
15502 + AuRwMustWriteLock(&finfo->fi_rwsem);
15503 + fidir = finfo->fi_hdir;
15504 + AuDebugOn(!fidir);
15507 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15508 + GFP_NOFS, may_shrink);
15510 + p->fd_nent = nbr;
15511 + finfo->fi_hdir = p;
15518 +/* ---------------------------------------------------------------------- */
15520 +void au_finfo_fin(struct file *file)
15522 + struct au_finfo *finfo;
15524 + au_nfiles_dec(file->f_path.dentry->d_sb);
15526 + finfo = au_fi(file);
15527 + AuDebugOn(finfo->fi_hdir);
15528 + AuRwDestroy(&finfo->fi_rwsem);
15529 + au_cache_free_finfo(finfo);
15532 +void au_fi_init_once(void *_finfo)
15534 + struct au_finfo *finfo = _finfo;
15536 + au_rw_init(&finfo->fi_rwsem);
15539 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15542 + struct au_finfo *finfo;
15543 + struct dentry *dentry;
15546 + dentry = file->f_path.dentry;
15547 + finfo = au_cache_alloc_finfo();
15548 + if (unlikely(!finfo))
15552 + au_nfiles_inc(dentry->d_sb);
15553 + au_rw_write_lock(&finfo->fi_rwsem);
15554 + finfo->fi_btop = -1;
15555 + finfo->fi_hdir = fidir;
15556 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15557 + /* smp_mb(); */ /* atomic_set */
15559 + file->private_data = finfo;
15564 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15565 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15566 +++ linux/fs/aufs/f_op.c 2018-07-19 09:46:13.056647808 +0200
15568 +/* SPDX-License-Identifier: GPL-2.0 */
15570 + * Copyright (C) 2005-2018 Junjiro R. Okajima
15572 + * This program, aufs is free software; you can redistribute it and/or modify
15573 + * it under the terms of the GNU General Public License as published by
15574 + * the Free Software Foundation; either version 2 of the License, or
15575 + * (at your option) any later version.
15577 + * This program is distributed in the hope that it will be useful,
15578 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15579 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15580 + * GNU General Public License for more details.
15582 + * You should have received a copy of the GNU General Public License
15583 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15587 + * file and vm operations
15590 +#include <linux/aio.h>
15591 +#include <linux/fs_stack.h>
15592 +#include <linux/mman.h>
15593 +#include <linux/security.h>
15596 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15599 + aufs_bindex_t bindex;
15600 + struct dentry *dentry, *h_dentry;
15601 + struct au_finfo *finfo;
15602 + struct inode *h_inode;
15604 + FiMustWriteLock(file);
15607 + dentry = file->f_path.dentry;
15608 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15609 + finfo = au_fi(file);
15610 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15611 + atomic_set(&finfo->fi_mmapped, 0);
15612 + bindex = au_dbtop(dentry);
15614 + h_dentry = au_h_dptr(dentry, bindex);
15615 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15616 + if (unlikely(err))
15618 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15620 + h_dentry = h_file->f_path.dentry;
15621 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15622 + if (unlikely(err))
15624 + get_file(h_file);
15626 + if (IS_ERR(h_file))
15627 + err = PTR_ERR(h_file);
15629 + if ((flags & __O_TMPFILE)
15630 + && !(flags & O_EXCL)) {
15631 + h_inode = file_inode(h_file);
15632 + spin_lock(&h_inode->i_lock);
15633 + h_inode->i_state |= I_LINKABLE;
15634 + spin_unlock(&h_inode->i_lock);
15636 + au_set_fbtop(file, bindex);
15637 + au_set_h_fptr(file, bindex, h_file);
15638 + au_update_figen(file);
15639 + /* todo: necessary? */
15640 + /* file->f_ra = h_file->f_ra; */
15647 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15648 + struct file *file)
15651 + struct super_block *sb;
15652 + struct au_do_open_args args = {
15653 + .open = au_do_open_nondir
15656 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15657 + file, vfsub_file_flags(file), file->f_mode);
15659 + sb = file->f_path.dentry->d_sb;
15660 + si_read_lock(sb, AuLock_FLUSH);
15661 + err = au_do_open(file, &args);
15662 + si_read_unlock(sb);
15666 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15668 + struct au_finfo *finfo;
15669 + aufs_bindex_t bindex;
15671 + finfo = au_fi(file);
15672 + au_hbl_del(&finfo->fi_hlist,
15673 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15674 + bindex = finfo->fi_btop;
15676 + au_set_h_fptr(file, bindex, NULL);
15678 + au_finfo_fin(file);
15682 +/* ---------------------------------------------------------------------- */
15684 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15687 + struct file *h_file;
15690 + h_file = au_hf_top(file);
15692 + err = vfsub_flush(h_file, id);
15696 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15698 + return au_do_flush(file, id, au_do_flush_nondir);
15701 +/* ---------------------------------------------------------------------- */
15703 + * read and write functions acquire [fdi]_rwsem once, but release before
15704 + * mmap_sem. This is because to stop a race condition between mmap(2).
15705 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
15706 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15707 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15710 +/* Callers should call au_read_post() or fput() in the end */
15711 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15713 + struct file *h_file;
15716 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15718 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15719 + h_file = au_hf_top(file);
15720 + get_file(h_file);
15722 + fi_read_unlock(file);
15724 + h_file = ERR_PTR(err);
15729 +static void au_read_post(struct inode *inode, struct file *h_file)
15731 + /* update without lock, I don't think it a problem */
15732 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15736 +struct au_write_pre {
15738 + unsigned int lsc;
15742 + aufs_bindex_t btop;
15746 + * return with iinfo is write-locked
15747 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15750 +static struct file *au_write_pre(struct file *file, int do_ready,
15751 + struct au_write_pre *wpre)
15753 + struct file *h_file;
15754 + struct dentry *dentry;
15756 + unsigned int lsc;
15757 + struct au_pin pin;
15762 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15763 + h_file = ERR_PTR(err);
15764 + if (unlikely(err))
15767 + dentry = file->f_path.dentry;
15769 + err = au_ready_to_write(file, -1, &pin);
15770 + if (unlikely(err)) {
15771 + h_file = ERR_PTR(err);
15772 + di_write_unlock(dentry);
15777 + di_downgrade_lock(dentry, /*flags*/0);
15779 + wpre->btop = au_fbtop(file);
15780 + h_file = au_hf_top(file);
15781 + get_file(h_file);
15783 + wpre->blks = file_inode(h_file)->i_blocks;
15786 + di_read_unlock(dentry, /*flags*/0);
15789 + fi_write_unlock(file);
15794 +static void au_write_post(struct inode *inode, struct file *h_file,
15795 + struct au_write_pre *wpre, ssize_t written)
15797 + struct inode *h_inode;
15799 + au_cpup_attr_timesizes(inode);
15800 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15801 + h_inode = file_inode(h_file);
15802 + inode->i_mode = h_inode->i_mode;
15803 + ii_write_unlock(inode);
15804 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15806 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15807 + /*force*/h_inode->i_blocks > wpre->blks);
15811 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15815 + struct inode *inode;
15816 + struct file *h_file;
15817 + struct super_block *sb;
15819 + inode = file_inode(file);
15820 + sb = inode->i_sb;
15821 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15823 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15824 + err = PTR_ERR(h_file);
15825 + if (IS_ERR(h_file))
15828 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15829 + err = vfsub_read_u(h_file, buf, count, ppos);
15830 + /* todo: necessary? */
15831 + /* file->f_ra = h_file->f_ra; */
15832 + au_read_post(inode, h_file);
15835 + si_read_unlock(sb);
15840 + * todo: very ugly
15841 + * it locks both of i_mutex and si_rwsem for read in safe.
15842 + * if the plink maintenance mode continues forever (that is the problem),
15843 + * may loop forever.
15845 +static void au_mtx_and_read_lock(struct inode *inode)
15848 + struct super_block *sb = inode->i_sb;
15851 + inode_lock(inode);
15852 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15855 + inode_unlock(inode);
15856 + si_read_lock(sb, AuLock_NOPLMW);
15857 + si_read_unlock(sb);
15861 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15862 + size_t count, loff_t *ppos)
15865 + struct au_write_pre wpre;
15866 + struct inode *inode;
15867 + struct file *h_file;
15868 + char __user *buf = (char __user *)ubuf;
15870 + inode = file_inode(file);
15871 + au_mtx_and_read_lock(inode);
15874 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15875 + err = PTR_ERR(h_file);
15876 + if (IS_ERR(h_file))
15879 + err = vfsub_write_u(h_file, buf, count, ppos);
15880 + au_write_post(inode, h_file, &wpre, err);
15883 + si_read_unlock(inode->i_sb);
15884 + inode_unlock(inode);
15888 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15889 + struct iov_iter *iov_iter)
15892 + struct file *file;
15893 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15895 + err = security_file_permission(h_file, rw);
15896 + if (unlikely(err))
15901 + if (rw == MAY_READ)
15902 + iter = h_file->f_op->read_iter;
15903 + else if (rw == MAY_WRITE)
15904 + iter = h_file->f_op->write_iter;
15906 + file = kio->ki_filp;
15907 + kio->ki_filp = h_file;
15910 + err = iter(kio, iov_iter);
15913 + /* currently there is no such fs */
15915 + kio->ki_filp = file;
15921 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15924 + struct file *file, *h_file;
15925 + struct inode *inode;
15926 + struct super_block *sb;
15928 + file = kio->ki_filp;
15929 + inode = file_inode(file);
15930 + sb = inode->i_sb;
15931 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15933 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15934 + err = PTR_ERR(h_file);
15935 + if (IS_ERR(h_file))
15938 + if (au_test_loopback_kthread()) {
15939 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15940 + if (file->f_mapping != h_file->f_mapping) {
15941 + file->f_mapping = h_file->f_mapping;
15942 + smp_mb(); /* unnecessary? */
15945 + fi_read_unlock(file);
15947 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15948 + /* todo: necessary? */
15949 + /* file->f_ra = h_file->f_ra; */
15950 + au_read_post(inode, h_file);
15953 + si_read_unlock(sb);
15957 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15960 + struct au_write_pre wpre;
15961 + struct inode *inode;
15962 + struct file *file, *h_file;
15964 + file = kio->ki_filp;
15965 + inode = file_inode(file);
15966 + au_mtx_and_read_lock(inode);
15969 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15970 + err = PTR_ERR(h_file);
15971 + if (IS_ERR(h_file))
15974 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15975 + au_write_post(inode, h_file, &wpre, err);
15978 + si_read_unlock(inode->i_sb);
15979 + inode_unlock(inode);
15983 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15984 + struct pipe_inode_info *pipe, size_t len,
15985 + unsigned int flags)
15988 + struct file *h_file;
15989 + struct inode *inode;
15990 + struct super_block *sb;
15992 + inode = file_inode(file);
15993 + sb = inode->i_sb;
15994 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15996 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15997 + err = PTR_ERR(h_file);
15998 + if (IS_ERR(h_file))
16001 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16002 + /* todo: necessasry? */
16003 + /* file->f_ra = h_file->f_ra; */
16004 + au_read_post(inode, h_file);
16007 + si_read_unlock(sb);
16012 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16013 + size_t len, unsigned int flags)
16016 + struct au_write_pre wpre;
16017 + struct inode *inode;
16018 + struct file *h_file;
16020 + inode = file_inode(file);
16021 + au_mtx_and_read_lock(inode);
16024 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16025 + err = PTR_ERR(h_file);
16026 + if (IS_ERR(h_file))
16029 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16030 + au_write_post(inode, h_file, &wpre, err);
16033 + si_read_unlock(inode->i_sb);
16034 + inode_unlock(inode);
16038 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16042 + struct au_write_pre wpre;
16043 + struct inode *inode;
16044 + struct file *h_file;
16046 + inode = file_inode(file);
16047 + au_mtx_and_read_lock(inode);
16050 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16051 + err = PTR_ERR(h_file);
16052 + if (IS_ERR(h_file))
16056 + err = vfs_fallocate(h_file, mode, offset, len);
16058 + au_write_post(inode, h_file, &wpre, /*written*/1);
16061 + si_read_unlock(inode->i_sb);
16062 + inode_unlock(inode);
16066 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16067 + struct file *dst, loff_t dst_pos,
16068 + size_t len, unsigned int flags)
16071 + struct au_write_pre wpre;
16072 + enum { SRC, DST };
16074 + struct inode *inode;
16075 + struct file *h_file;
16076 + struct super_block *h_sb;
16078 +#define a_src a[SRC]
16079 +#define a_dst a[DST]
16082 + a_src.inode = file_inode(src);
16083 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16085 + a_dst.inode = file_inode(dst);
16086 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16089 + au_mtx_and_read_lock(a_dst.inode);
16091 + * in order to match the order in di_write_lock2_{child,parent}(),
16092 + * use f_path.dentry for this comparision.
16094 + if (src->f_path.dentry < dst->f_path.dentry) {
16095 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16096 + err = PTR_ERR(a_src.h_file);
16097 + if (IS_ERR(a_src.h_file))
16100 + wpre.lsc = AuLsc_FI_2;
16101 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16102 + err = PTR_ERR(a_dst.h_file);
16103 + if (IS_ERR(a_dst.h_file)) {
16104 + au_read_post(a_src.inode, a_src.h_file);
16108 + wpre.lsc = AuLsc_FI_1;
16109 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16110 + err = PTR_ERR(a_dst.h_file);
16111 + if (IS_ERR(a_dst.h_file))
16114 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16115 + err = PTR_ERR(a_src.h_file);
16116 + if (IS_ERR(a_src.h_file)) {
16117 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16124 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16125 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16126 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16132 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16133 + dst_pos, len, flags);
16136 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16137 + fi_read_unlock(src);
16138 + au_read_post(a_src.inode, a_src.h_file);
16140 + si_read_unlock(a_dst.inode->i_sb);
16141 + inode_unlock(a_dst.inode);
16148 +/* ---------------------------------------------------------------------- */
16151 + * The locking order around current->mmap_sem.
16152 + * - in most and regular cases
16153 + * file I/O syscall -- aufs_read() or something
16154 + * -- si_rwsem for read -- mmap_sem
16155 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16157 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16158 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
16159 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
16160 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16161 + * It means that when aufs acquires si_rwsem for write, the process should never
16162 + * acquire mmap_sem.
16164 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16165 + * problem either since any directory is not able to be mmap-ed.
16166 + * The similar scenario is applied to aufs_readlink() too.
16169 +#if 0 /* stop calling security_file_mmap() */
16170 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16171 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16173 +static unsigned long au_arch_prot_conv(unsigned long flags)
16175 + /* currently ppc64 only */
16176 +#ifdef CONFIG_PPC64
16177 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16178 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16179 + return AuConv_VM_PROT(flags, SAO);
16181 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16186 +static unsigned long au_prot_conv(unsigned long flags)
16188 + return AuConv_VM_PROT(flags, READ)
16189 + | AuConv_VM_PROT(flags, WRITE)
16190 + | AuConv_VM_PROT(flags, EXEC)
16191 + | au_arch_prot_conv(flags);
16194 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16195 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16197 +static unsigned long au_flag_conv(unsigned long flags)
16199 + return AuConv_VM_MAP(flags, GROWSDOWN)
16200 + | AuConv_VM_MAP(flags, DENYWRITE)
16201 + | AuConv_VM_MAP(flags, LOCKED);
16205 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16208 + const unsigned char wlock
16209 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16210 + struct super_block *sb;
16211 + struct file *h_file;
16212 + struct inode *inode;
16214 + AuDbgVmRegion(file, vma);
16216 + inode = file_inode(file);
16217 + sb = inode->i_sb;
16219 + si_read_lock(sb, AuLock_NOPLMW);
16221 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16223 + err = PTR_ERR(h_file);
16224 + if (IS_ERR(h_file))
16228 + au_set_mmapped(file);
16229 + au_vm_file_reset(vma, h_file);
16231 + * we cannot call security_mmap_file() here since it may acquire
16232 + * mmap_sem or i_mutex.
16234 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16235 + * au_flag_conv(vma->vm_flags));
16238 + err = call_mmap(h_file, vma);
16240 + au_vm_prfile_set(vma, file);
16241 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16242 + goto out_fput; /* success */
16244 + au_unset_mmapped(file);
16245 + au_vm_file_reset(vma, file);
16249 + ii_write_unlock(inode);
16254 + si_read_unlock(sb);
16260 +/* ---------------------------------------------------------------------- */
16262 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16266 + struct au_write_pre wpre;
16267 + struct inode *inode;
16268 + struct file *h_file;
16270 + err = 0; /* -EBADF; */ /* posix? */
16271 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16274 + inode = file_inode(file);
16275 + au_mtx_and_read_lock(inode);
16278 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16279 + err = PTR_ERR(h_file);
16280 + if (IS_ERR(h_file))
16283 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16284 + au_write_post(inode, h_file, &wpre, /*written*/0);
16287 + si_read_unlock(inode->i_sb);
16288 + inode_unlock(inode);
16293 +static int aufs_fasync(int fd, struct file *file, int flag)
16296 + struct file *h_file;
16297 + struct super_block *sb;
16299 + sb = file->f_path.dentry->d_sb;
16300 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16302 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16303 + err = PTR_ERR(h_file);
16304 + if (IS_ERR(h_file))
16307 + if (h_file->f_op->fasync)
16308 + err = h_file->f_op->fasync(fd, h_file, flag);
16309 + fput(h_file); /* instead of au_read_post() */
16312 + si_read_unlock(sb);
16316 +static int aufs_setfl(struct file *file, unsigned long arg)
16319 + struct file *h_file;
16320 + struct super_block *sb;
16322 + sb = file->f_path.dentry->d_sb;
16323 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16325 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16326 + err = PTR_ERR(h_file);
16327 + if (IS_ERR(h_file))
16330 + /* stop calling h_file->fasync */
16331 + arg |= vfsub_file_flags(file) & FASYNC;
16332 + err = setfl(/*unused fd*/-1, h_file, arg);
16333 + fput(h_file); /* instead of au_read_post() */
16336 + si_read_unlock(sb);
16340 +/* ---------------------------------------------------------------------- */
16342 +/* no one supports this operation, currently */
16344 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16345 + size_t len, loff_t *pos, int more)
16350 +/* ---------------------------------------------------------------------- */
16352 +const struct file_operations aufs_file_fop = {
16353 + .owner = THIS_MODULE,
16355 + .llseek = default_llseek,
16357 + .read = aufs_read,
16358 + .write = aufs_write,
16359 + .read_iter = aufs_read_iter,
16360 + .write_iter = aufs_write_iter,
16362 +#ifdef CONFIG_AUFS_POLL
16363 + .poll = aufs_poll,
16365 + .unlocked_ioctl = aufs_ioctl_nondir,
16366 +#ifdef CONFIG_COMPAT
16367 + .compat_ioctl = aufs_compat_ioctl_nondir,
16369 + .mmap = aufs_mmap,
16370 + .open = aufs_open_nondir,
16371 + .flush = aufs_flush_nondir,
16372 + .release = aufs_release_nondir,
16373 + .fsync = aufs_fsync_nondir,
16374 + .fasync = aufs_fasync,
16375 + /* .sendpage = aufs_sendpage, */
16376 + .setfl = aufs_setfl,
16377 + .splice_write = aufs_splice_write,
16378 + .splice_read = aufs_splice_read,
16380 + .aio_splice_write = aufs_aio_splice_write,
16381 + .aio_splice_read = aufs_aio_splice_read,
16383 + .fallocate = aufs_fallocate,
16384 + .copy_file_range = aufs_copy_file_range
16386 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16387 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16388 +++ linux/fs/aufs/fstype.h 2018-07-19 09:46:13.059981241 +0200
16390 +/* SPDX-License-Identifier: GPL-2.0 */
16392 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16394 + * This program, aufs is free software; you can redistribute it and/or modify
16395 + * it under the terms of the GNU General Public License as published by
16396 + * the Free Software Foundation; either version 2 of the License, or
16397 + * (at your option) any later version.
16399 + * This program is distributed in the hope that it will be useful,
16400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16402 + * GNU General Public License for more details.
16404 + * You should have received a copy of the GNU General Public License
16405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16409 + * judging filesystem type
16412 +#ifndef __AUFS_FSTYPE_H__
16413 +#define __AUFS_FSTYPE_H__
16417 +#include <linux/fs.h>
16418 +#include <linux/magic.h>
16419 +#include <linux/nfs_fs.h>
16420 +#include <linux/romfs_fs.h>
16422 +static inline int au_test_aufs(struct super_block *sb)
16424 + return sb->s_magic == AUFS_SUPER_MAGIC;
16427 +static inline const char *au_sbtype(struct super_block *sb)
16429 + return sb->s_type->name;
16432 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16434 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16435 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16441 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16443 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16444 + return sb->s_magic == ROMFS_MAGIC;
16450 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16452 +#if IS_ENABLED(CONFIG_CRAMFS)
16453 + return sb->s_magic == CRAMFS_MAGIC;
16458 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16460 +#if IS_ENABLED(CONFIG_NFS_FS)
16461 + return sb->s_magic == NFS_SUPER_MAGIC;
16467 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16469 +#if IS_ENABLED(CONFIG_FUSE_FS)
16470 + return sb->s_magic == FUSE_SUPER_MAGIC;
16476 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16478 +#if IS_ENABLED(CONFIG_XFS_FS)
16479 + return sb->s_magic == XFS_SB_MAGIC;
16485 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16487 +#ifdef CONFIG_TMPFS
16488 + return sb->s_magic == TMPFS_MAGIC;
16494 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16496 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16497 + return !strcmp(au_sbtype(sb), "ecryptfs");
16503 +static inline int au_test_ramfs(struct super_block *sb)
16505 + return sb->s_magic == RAMFS_MAGIC;
16508 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16510 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16511 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16517 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16519 +#ifdef CONFIG_PROC_FS
16520 + return sb->s_magic == PROC_SUPER_MAGIC;
16526 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16528 +#ifdef CONFIG_SYSFS
16529 + return sb->s_magic == SYSFS_MAGIC;
16535 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16537 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16538 + return sb->s_magic == CONFIGFS_MAGIC;
16544 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16546 +#if IS_ENABLED(CONFIG_MINIX_FS)
16547 + return sb->s_magic == MINIX3_SUPER_MAGIC
16548 + || sb->s_magic == MINIX2_SUPER_MAGIC
16549 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16550 + || sb->s_magic == MINIX_SUPER_MAGIC
16551 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16557 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16559 +#if IS_ENABLED(CONFIG_FAT_FS)
16560 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16566 +static inline int au_test_msdos(struct super_block *sb)
16568 + return au_test_fat(sb);
16571 +static inline int au_test_vfat(struct super_block *sb)
16573 + return au_test_fat(sb);
16576 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16578 +#ifdef CONFIG_SECURITYFS
16579 + return sb->s_magic == SECURITYFS_MAGIC;
16585 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16587 +#if IS_ENABLED(CONFIG_SQUASHFS)
16588 + return sb->s_magic == SQUASHFS_MAGIC;
16594 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16596 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16597 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16603 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16605 +#if IS_ENABLED(CONFIG_XENFS)
16606 + return sb->s_magic == XENFS_SUPER_MAGIC;
16612 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16614 +#ifdef CONFIG_DEBUG_FS
16615 + return sb->s_magic == DEBUGFS_MAGIC;
16621 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16623 +#if IS_ENABLED(CONFIG_NILFS)
16624 + return sb->s_magic == NILFS_SUPER_MAGIC;
16630 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16632 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16633 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16639 +/* ---------------------------------------------------------------------- */
16641 + * they can't be an aufs branch.
16643 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16646 +#ifndef CONFIG_AUFS_BR_RAMFS
16647 + au_test_ramfs(sb) ||
16649 + au_test_procfs(sb)
16650 + || au_test_sysfs(sb)
16651 + || au_test_configfs(sb)
16652 + || au_test_debugfs(sb)
16653 + || au_test_securityfs(sb)
16654 + || au_test_xenfs(sb)
16655 + || au_test_ecryptfs(sb)
16656 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16657 + || au_test_aufs(sb); /* will be supported in next version */
16660 +static inline int au_test_fs_remote(struct super_block *sb)
16662 + return !au_test_tmpfs(sb)
16663 +#ifdef CONFIG_AUFS_BR_RAMFS
16664 + && !au_test_ramfs(sb)
16666 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16669 +/* ---------------------------------------------------------------------- */
16672 + * Note: these functions (below) are created after reading ->getattr() in all
16673 + * filesystems under linux/fs. it means we have to do so in every update...
16677 + * some filesystems require getattr to refresh the inode attributes before
16679 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16680 + * and leave the work for d_revalidate()
16682 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16684 + return au_test_nfs(sb)
16685 + || au_test_fuse(sb)
16686 + /* || au_test_btrfs(sb) */ /* untested */
16691 + * filesystems which don't maintain i_size or i_blocks.
16693 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16695 + return au_test_xfs(sb)
16696 + || au_test_btrfs(sb)
16697 + || au_test_ubifs(sb)
16698 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16699 + /* || au_test_minix(sb) */ /* untested */
16704 + * filesystems which don't store the correct value in some of their inode
16707 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16709 + return au_test_fs_bad_iattr_size(sb)
16710 + || au_test_fat(sb)
16711 + || au_test_msdos(sb)
16712 + || au_test_vfat(sb);
16715 +/* they don't check i_nlink in link(2) */
16716 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16718 + return au_test_tmpfs(sb)
16719 +#ifdef CONFIG_AUFS_BR_RAMFS
16720 + || au_test_ramfs(sb)
16722 + || au_test_ubifs(sb)
16723 + || au_test_hfsplus(sb);
16727 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16729 +static inline int au_test_fs_notime(struct super_block *sb)
16731 + return au_test_nfs(sb)
16732 + || au_test_fuse(sb)
16733 + || au_test_ubifs(sb)
16737 +/* temporary support for i#1 in cramfs */
16738 +static inline int au_test_fs_unique_ino(struct inode *inode)
16740 + if (au_test_cramfs(inode->i_sb))
16741 + return inode->i_ino != 1;
16745 +/* ---------------------------------------------------------------------- */
16748 + * the filesystem where the xino files placed must support i/o after unlink and
16749 + * maintain i_size and i_blocks.
16751 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16753 + return au_test_fs_remote(sb)
16754 + || au_test_fs_bad_iattr_size(sb)
16755 + /* don't want unnecessary work for xino */
16756 + || au_test_aufs(sb)
16757 + || au_test_ecryptfs(sb)
16758 + || au_test_nilfs(sb);
16761 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16763 + return au_test_tmpfs(sb)
16764 + || au_test_ramfs(sb);
16768 + * test if the @sb is real-readonly.
16770 +static inline int au_test_fs_rr(struct super_block *sb)
16772 + return au_test_squashfs(sb)
16773 + || au_test_iso9660(sb)
16774 + || au_test_cramfs(sb)
16775 + || au_test_romfs(sb);
16779 + * test if the @inode is nfs with 'noacl' option
16780 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16782 +static inline int au_test_nfs_noacl(struct inode *inode)
16784 + return au_test_nfs(inode->i_sb)
16785 + /* && IS_POSIXACL(inode) */
16786 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16789 +#endif /* __KERNEL__ */
16790 +#endif /* __AUFS_FSTYPE_H__ */
16791 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16792 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16793 +++ linux/fs/aufs/hbl.h 2018-07-19 09:46:13.059981241 +0200
16795 +/* SPDX-License-Identifier: GPL-2.0 */
16797 + * Copyright (C) 2017-2018 Junjiro R. Okajima
16799 + * This program, aufs is free software; you can redistribute it and/or modify
16800 + * it under the terms of the GNU General Public License as published by
16801 + * the Free Software Foundation; either version 2 of the License, or
16802 + * (at your option) any later version.
16804 + * This program is distributed in the hope that it will be useful,
16805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16807 + * GNU General Public License for more details.
16809 + * You should have received a copy of the GNU General Public License
16810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16814 + * helpers for hlist_bl.h
16817 +#ifndef __AUFS_HBL_H__
16818 +#define __AUFS_HBL_H__
16822 +#include <linux/list_bl.h>
16824 +static inline void au_hbl_add(struct hlist_bl_node *node,
16825 + struct hlist_bl_head *hbl)
16827 + hlist_bl_lock(hbl);
16828 + hlist_bl_add_head(node, hbl);
16829 + hlist_bl_unlock(hbl);
16832 +static inline void au_hbl_del(struct hlist_bl_node *node,
16833 + struct hlist_bl_head *hbl)
16835 + hlist_bl_lock(hbl);
16836 + hlist_bl_del(node);
16837 + hlist_bl_unlock(hbl);
16840 +#define au_hbl_for_each(pos, head) \
16841 + for (pos = hlist_bl_first(head); \
16845 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16847 + unsigned long cnt;
16848 + struct hlist_bl_node *pos;
16851 + hlist_bl_lock(hbl);
16852 + au_hbl_for_each(pos, hbl)
16854 + hlist_bl_unlock(hbl);
16858 +#endif /* __KERNEL__ */
16859 +#endif /* __AUFS_HBL_H__ */
16860 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16861 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16862 +++ linux/fs/aufs/hfsnotify.c 2018-07-19 09:46:13.059981241 +0200
16864 +/* SPDX-License-Identifier: GPL-2.0 */
16866 + * Copyright (C) 2005-2018 Junjiro R. Okajima
16868 + * This program, aufs is free software; you can redistribute it and/or modify
16869 + * it under the terms of the GNU General Public License as published by
16870 + * the Free Software Foundation; either version 2 of the License, or
16871 + * (at your option) any later version.
16873 + * This program is distributed in the hope that it will be useful,
16874 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16875 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16876 + * GNU General Public License for more details.
16878 + * You should have received a copy of the GNU General Public License
16879 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16883 + * fsnotify for the lower directories
16888 +/* FS_IN_IGNORED is unnecessary */
16889 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16890 + | FS_CREATE | FS_EVENT_ON_CHILD);
16891 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16892 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16894 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16896 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16898 + /* AuDbg("here\n"); */
16899 + au_cache_free_hnotify(hn);
16900 + smp_mb__before_atomic(); /* for atomic64_dec */
16901 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16902 + wake_up(&au_hfsn_wq);
16905 +static int au_hfsn_alloc(struct au_hinode *hinode)
16908 + struct au_hnotify *hn;
16909 + struct super_block *sb;
16910 + struct au_branch *br;
16911 + struct fsnotify_mark *mark;
16912 + aufs_bindex_t bindex;
16914 + hn = hinode->hi_notify;
16915 + sb = hn->hn_aufs_inode->i_sb;
16916 + bindex = au_br_index(sb, hinode->hi_id);
16917 + br = au_sbr(sb, bindex);
16918 + AuDebugOn(!br->br_hfsn);
16920 + mark = &hn->hn_mark;
16921 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16922 + mark->mask = AuHfsnMask;
16924 + * by udba rename or rmdir, aufs assign a new inode to the known
16925 + * h_inode, so specify 1 to allow dups.
16928 + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL,
16929 + /*allow_dups*/1);
16935 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16937 + struct fsnotify_mark *mark;
16938 + unsigned long long ull;
16939 + struct fsnotify_group *group;
16941 + ull = atomic64_inc_return(&au_hfsn_ifree);
16944 + mark = &hn->hn_mark;
16945 + spin_lock(&mark->lock);
16946 + group = mark->group;
16947 + fsnotify_get_group(group);
16948 + spin_unlock(&mark->lock);
16950 + fsnotify_destroy_mark(mark, group);
16951 + fsnotify_put_mark(mark);
16952 + fsnotify_put_group(group);
16955 + /* free hn by myself */
16959 +/* ---------------------------------------------------------------------- */
16961 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16963 + struct fsnotify_mark *mark;
16965 + mark = &hinode->hi_notify->hn_mark;
16966 + spin_lock(&mark->lock);
16968 + AuDebugOn(mark->mask & AuHfsnMask);
16969 + mark->mask |= AuHfsnMask;
16971 + AuDebugOn(!(mark->mask & AuHfsnMask));
16972 + mark->mask &= ~AuHfsnMask;
16974 + spin_unlock(&mark->lock);
16975 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16978 +/* ---------------------------------------------------------------------- */
16980 +/* #define AuDbgHnotify */
16981 +#ifdef AuDbgHnotify
16982 +static char *au_hfsn_name(u32 mask)
16984 +#ifdef CONFIG_AUFS_DEBUG
16985 +#define test_ret(flag) \
16987 + if (mask & flag) \
16990 + test_ret(FS_ACCESS);
16991 + test_ret(FS_MODIFY);
16992 + test_ret(FS_ATTRIB);
16993 + test_ret(FS_CLOSE_WRITE);
16994 + test_ret(FS_CLOSE_NOWRITE);
16995 + test_ret(FS_OPEN);
16996 + test_ret(FS_MOVED_FROM);
16997 + test_ret(FS_MOVED_TO);
16998 + test_ret(FS_CREATE);
16999 + test_ret(FS_DELETE);
17000 + test_ret(FS_DELETE_SELF);
17001 + test_ret(FS_MOVE_SELF);
17002 + test_ret(FS_UNMOUNT);
17003 + test_ret(FS_Q_OVERFLOW);
17004 + test_ret(FS_IN_IGNORED);
17005 + test_ret(FS_ISDIR);
17006 + test_ret(FS_IN_ONESHOT);
17007 + test_ret(FS_EVENT_ON_CHILD);
17016 +/* ---------------------------------------------------------------------- */
17018 +static void au_hfsn_free_group(struct fsnotify_group *group)
17020 + struct au_br_hfsnotify *hfsn = group->private;
17022 + /* AuDbg("here\n"); */
17026 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17027 + struct inode *inode,
17028 + struct fsnotify_mark *inode_mark,
17029 + struct fsnotify_mark *vfsmount_mark,
17030 + u32 mask, const void *data, int data_type,
17031 + const unsigned char *file_name, u32 cookie,
17032 + struct fsnotify_iter_info *iter_info)
17035 + struct au_hnotify *hnotify;
17036 + struct inode *h_dir, *h_inode;
17037 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17039 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17042 + /* if FS_UNMOUNT happens, there must be another bug */
17043 + AuDebugOn(mask & FS_UNMOUNT);
17044 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17049 +#ifdef AuDbgHnotify
17051 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17052 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17053 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17054 + h_dir->i_ino, mask, au_hfsn_name(mask),
17055 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17056 + /* WARN_ON(1); */
17061 + AuDebugOn(!inode_mark);
17062 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17063 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17069 +static struct fsnotify_ops au_hfsn_ops = {
17070 + .handle_event = au_hfsn_handle_event,
17071 + .free_group_priv = au_hfsn_free_group,
17072 + .free_mark = au_hfsn_free_mark
17075 +/* ---------------------------------------------------------------------- */
17077 +static void au_hfsn_fin_br(struct au_branch *br)
17079 + struct au_br_hfsnotify *hfsn;
17081 + hfsn = br->br_hfsn;
17084 + fsnotify_put_group(hfsn->hfsn_group);
17089 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17092 + struct fsnotify_group *group;
17093 + struct au_br_hfsnotify *hfsn;
17096 + br->br_hfsn = NULL;
17097 + if (!au_br_hnotifyable(perm))
17101 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17102 + if (unlikely(!hfsn))
17106 + group = fsnotify_alloc_group(&au_hfsn_ops);
17107 + if (IS_ERR(group)) {
17108 + err = PTR_ERR(group);
17109 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17113 + group->private = hfsn;
17114 + hfsn->hfsn_group = group;
17115 + br->br_hfsn = hfsn;
17116 + goto out; /* success */
17124 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17129 + if (!br->br_hfsn)
17130 + err = au_hfsn_init_br(br, perm);
17135 +/* ---------------------------------------------------------------------- */
17137 +static void au_hfsn_fin(void)
17139 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17140 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17143 +const struct au_hnotify_op au_hnotify_op = {
17144 + .ctl = au_hfsn_ctl,
17145 + .alloc = au_hfsn_alloc,
17146 + .free = au_hfsn_free,
17148 + .fin = au_hfsn_fin,
17150 + .reset_br = au_hfsn_reset_br,
17151 + .fin_br = au_hfsn_fin_br,
17152 + .init_br = au_hfsn_init_br
17154 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17155 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17156 +++ linux/fs/aufs/hfsplus.c 2018-07-19 09:46:13.059981241 +0200
17158 +/* SPDX-License-Identifier: GPL-2.0 */
17160 + * Copyright (C) 2010-2018 Junjiro R. Okajima
17162 + * This program, aufs is free software; you can redistribute it and/or modify
17163 + * it under the terms of the GNU General Public License as published by
17164 + * the Free Software Foundation; either version 2 of the License, or
17165 + * (at your option) any later version.
17167 + * This program is distributed in the hope that it will be useful,
17168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17170 + * GNU General Public License for more details.
17172 + * You should have received a copy of the GNU General Public License
17173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17177 + * special support for filesystems which aqucires an inode mutex
17178 + * at final closing a file, eg, hfsplus.
17180 + * This trick is very simple and stupid, just to open the file before really
17181 + * neceeary open to tell hfsplus that this is not the final closing.
17182 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17183 + * and au_h_open_post() after releasing it.
17188 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17191 + struct file *h_file;
17192 + struct dentry *h_dentry;
17194 + h_dentry = au_h_dptr(dentry, bindex);
17195 + AuDebugOn(!h_dentry);
17196 + AuDebugOn(d_is_negative(h_dentry));
17199 + if (au_test_hfsplus(h_dentry->d_sb)
17200 + && d_is_reg(h_dentry))
17201 + h_file = au_h_open(dentry, bindex,
17202 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17203 + /*file*/NULL, force_wr);
17207 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17208 + struct file *h_file)
17212 + au_sbr_put(dentry->d_sb, bindex);
17215 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17216 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17217 +++ linux/fs/aufs/hnotify.c 2018-07-19 09:46:13.059981241 +0200
17219 +/* SPDX-License-Identifier: GPL-2.0 */
17221 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17223 + * This program, aufs is free software; you can redistribute it and/or modify
17224 + * it under the terms of the GNU General Public License as published by
17225 + * the Free Software Foundation; either version 2 of the License, or
17226 + * (at your option) any later version.
17228 + * This program is distributed in the hope that it will be useful,
17229 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17230 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17231 + * GNU General Public License for more details.
17233 + * You should have received a copy of the GNU General Public License
17234 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17238 + * abstraction to notify the direct changes on lower directories
17243 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17246 + struct au_hnotify *hn;
17249 + hn = au_cache_alloc_hnotify();
17251 + hn->hn_aufs_inode = inode;
17252 + hinode->hi_notify = hn;
17253 + err = au_hnotify_op.alloc(hinode);
17255 + if (unlikely(err)) {
17256 + hinode->hi_notify = NULL;
17257 + au_cache_free_hnotify(hn);
17259 + * The upper dir was removed by udba, but the same named
17260 + * dir left. In this case, aufs assignes a new inode
17261 + * number and set the monitor again.
17262 + * For the lower dir, the old monitnor is still left.
17264 + if (err == -EEXIST)
17273 +void au_hn_free(struct au_hinode *hinode)
17275 + struct au_hnotify *hn;
17277 + hn = hinode->hi_notify;
17279 + hinode->hi_notify = NULL;
17280 + if (au_hnotify_op.free(hinode, hn))
17281 + au_cache_free_hnotify(hn);
17285 +/* ---------------------------------------------------------------------- */
17287 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17289 + if (hinode->hi_notify)
17290 + au_hnotify_op.ctl(hinode, do_set);
17293 +void au_hn_reset(struct inode *inode, unsigned int flags)
17295 + aufs_bindex_t bindex, bbot;
17296 + struct inode *hi;
17297 + struct dentry *iwhdentry;
17299 + bbot = au_ibbot(inode);
17300 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17301 + hi = au_h_iptr(inode, bindex);
17305 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17306 + iwhdentry = au_hi_wh(inode, bindex);
17310 + au_set_h_iptr(inode, bindex, NULL, 0);
17311 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17312 + flags & ~AuHi_XINO);
17315 + /* inode_unlock(hi); */
17319 +/* ---------------------------------------------------------------------- */
17321 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17324 + aufs_bindex_t bindex, bbot, bfound, btop;
17325 + struct inode *h_i;
17328 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17329 + pr_warn("branch root dir was changed\n");
17334 + bbot = au_ibbot(inode);
17335 + btop = au_ibtop(inode);
17336 +#if 0 /* reserved for future use */
17337 + if (bindex == bbot) {
17338 + /* keep this ino in rename case */
17342 + for (bindex = btop; bindex <= bbot; bindex++)
17343 + if (au_h_iptr(inode, bindex) == h_inode) {
17350 + for (bindex = btop; bindex <= bbot; bindex++) {
17351 + h_i = au_h_iptr(inode, bindex);
17355 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17356 + /* ignore this error */
17357 + /* bad action? */
17360 + /* children inode number will be broken */
17367 +static int hn_gen_tree(struct dentry *dentry)
17369 + int err, i, j, ndentry;
17370 + struct au_dcsub_pages dpages;
17371 + struct au_dpage *dpage;
17372 + struct dentry **dentries;
17374 + err = au_dpages_init(&dpages, GFP_NOFS);
17375 + if (unlikely(err))
17377 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17378 + if (unlikely(err))
17381 + for (i = 0; i < dpages.ndpage; i++) {
17382 + dpage = dpages.dpages + i;
17383 + dentries = dpage->dentries;
17384 + ndentry = dpage->ndentry;
17385 + for (j = 0; j < ndentry; j++) {
17386 + struct dentry *d;
17393 + if (d_really_is_positive(d))
17394 + /* todo: reset children xino?
17395 + cached children only? */
17396 + au_iigen_dec(d_inode(d));
17401 + au_dpages_free(&dpages);
17404 + /* discard children */
17405 + dentry_unhash(dentry);
17413 + * return 0 if processed.
17415 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17416 + const unsigned int isdir)
17419 + struct dentry *d;
17420 + struct qstr *dname;
17423 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17424 + pr_warn("branch root dir was changed\n");
17430 + AuDebugOn(!name);
17431 + au_iigen_dec(inode);
17432 + spin_lock(&inode->i_lock);
17433 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17434 + spin_lock(&d->d_lock);
17435 + dname = &d->d_name;
17436 + if (dname->len != nlen
17437 + && memcmp(dname->name, name, nlen)) {
17438 + spin_unlock(&d->d_lock);
17443 + spin_unlock(&d->d_lock);
17446 + spin_unlock(&inode->i_lock);
17448 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17449 + d = d_find_any_alias(inode);
17451 + au_iigen_dec(inode);
17455 + spin_lock(&d->d_lock);
17456 + dname = &d->d_name;
17457 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17458 + spin_unlock(&d->d_lock);
17459 + err = hn_gen_tree(d);
17460 + spin_lock(&d->d_lock);
17462 + spin_unlock(&d->d_lock);
17471 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17475 + if (IS_ROOT(dentry)) {
17476 + pr_warn("branch root dir was changed\n");
17482 + au_digen_dec(dentry);
17483 + if (d_really_is_positive(dentry))
17484 + au_iigen_dec(d_inode(dentry));
17486 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17487 + if (d_really_is_positive(dentry))
17488 + err = hn_gen_tree(dentry);
17495 +/* ---------------------------------------------------------------------- */
17497 +/* hnotify job flags */
17498 +#define AuHnJob_XINO0 1
17499 +#define AuHnJob_GEN (1 << 1)
17500 +#define AuHnJob_DIRENT (1 << 2)
17501 +#define AuHnJob_ISDIR (1 << 3)
17502 +#define AuHnJob_TRYXINO0 (1 << 4)
17503 +#define AuHnJob_MNTPNT (1 << 5)
17504 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17505 +#define au_fset_hnjob(flags, name) \
17506 + do { (flags) |= AuHnJob_##name; } while (0)
17507 +#define au_fclr_hnjob(flags, name) \
17508 + do { (flags) &= ~AuHnJob_##name; } while (0)
17516 +struct au_hnotify_args {
17517 + struct inode *h_dir, *dir, *h_child_inode;
17519 + unsigned int flags[AuHnLast];
17520 + unsigned int h_child_nlen;
17521 + char h_child_name[];
17524 +struct hn_job_args {
17525 + unsigned int flags;
17526 + struct inode *inode, *h_inode, *dir, *h_dir;
17527 + struct dentry *dentry;
17532 +static int hn_job(struct hn_job_args *a)
17534 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17538 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17539 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17541 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17544 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17545 + if (!a->h_inode->i_nlink
17546 + && !(a->h_inode->i_state & I_LINKABLE))
17547 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17548 + inode_unlock_shared(a->h_inode);
17551 + /* make the generation obsolete */
17552 + if (au_ftest_hnjob(a->flags, GEN)) {
17555 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17557 + if (e && a->dentry)
17558 + hn_gen_by_name(a->dentry, isdir);
17559 + /* ignore this error */
17562 + /* make dir entries obsolete */
17563 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17564 + struct au_vdir *vdir;
17566 + vdir = au_ivdir(a->inode);
17568 + vdir->vd_jiffy = 0;
17569 + /* IMustLock(a->inode); */
17570 + /* inode_inc_iversion(a->inode); */
17573 + /* can do nothing but warn */
17574 + if (au_ftest_hnjob(a->flags, MNTPNT)
17576 + && d_mountpoint(a->dentry))
17577 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17582 +/* ---------------------------------------------------------------------- */
17584 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17585 + struct inode *dir)
17587 + struct dentry *dentry, *d, *parent;
17588 + struct qstr *dname;
17590 + parent = d_find_any_alias(dir);
17595 + spin_lock(&parent->d_lock);
17596 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17597 + /* AuDbg("%pd\n", d); */
17598 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17599 + dname = &d->d_name;
17600 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17601 + goto cont_unlock;
17605 + goto cont_unlock;
17606 + if (au_dcount(d) > 0) {
17607 + dentry = dget_dlock(d);
17608 + spin_unlock(&d->d_lock);
17613 + spin_unlock(&d->d_lock);
17615 + spin_unlock(&parent->d_lock);
17619 + di_write_lock_child(dentry);
17624 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17625 + aufs_bindex_t bindex, ino_t h_ino)
17627 + struct inode *inode;
17632 + err = au_xino_read(sb, bindex, h_ino, &ino);
17634 + inode = ilookup(sb, ino);
17638 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17639 + pr_warn("wrong root branch\n");
17645 + ii_write_lock_child(inode);
17651 +static void au_hn_bh(void *_args)
17653 + struct au_hnotify_args *a = _args;
17654 + struct super_block *sb;
17655 + aufs_bindex_t bindex, bbot, bfound;
17656 + unsigned char xino, try_iput;
17658 + struct inode *inode;
17660 + struct hn_job_args args;
17661 + struct dentry *dentry;
17662 + struct au_sbinfo *sbinfo;
17664 + AuDebugOn(!_args);
17665 + AuDebugOn(!a->h_dir);
17666 + AuDebugOn(!a->dir);
17667 + AuDebugOn(!a->mask);
17668 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17669 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17670 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17675 + * do not lock a->dir->i_mutex here
17676 + * because of d_revalidate() may cause a deadlock.
17678 + sb = a->dir->i_sb;
17680 + sbinfo = au_sbi(sb);
17681 + AuDebugOn(!sbinfo);
17682 + si_write_lock(sb, AuLock_NOPLMW);
17684 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17685 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17686 + case FS_MOVED_FROM:
17687 + case FS_MOVED_TO:
17688 + AuWarn1("DIRREN with UDBA may not work correctly "
17689 + "for the direct rename(2)\n");
17692 + ii_read_lock_parent(a->dir);
17694 + bbot = au_ibbot(a->dir);
17695 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17696 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17700 + ii_read_unlock(a->dir);
17701 + if (unlikely(bfound < 0))
17704 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17706 + if (a->h_child_inode)
17707 + h_ino = a->h_child_inode->i_ino;
17709 + if (a->h_child_nlen
17710 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17711 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17712 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17715 + if (dentry && d_really_is_positive(dentry))
17716 + inode = d_inode(dentry);
17717 + if (xino && !inode && h_ino
17718 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17719 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17720 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17721 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17725 + args.flags = a->flags[AuHn_CHILD];
17726 + args.dentry = dentry;
17727 + args.inode = inode;
17728 + args.h_inode = a->h_child_inode;
17729 + args.dir = a->dir;
17730 + args.h_dir = a->h_dir;
17731 + args.h_name = a->h_child_name;
17732 + args.h_nlen = a->h_child_nlen;
17733 + err = hn_job(&args);
17735 + if (au_di(dentry))
17736 + di_write_unlock(dentry);
17739 + if (inode && try_iput) {
17740 + ii_write_unlock(inode);
17744 + ii_write_lock_parent(a->dir);
17745 + args.flags = a->flags[AuHn_PARENT];
17746 + args.dentry = NULL;
17747 + args.inode = a->dir;
17748 + args.h_inode = a->h_dir;
17750 + args.h_dir = NULL;
17751 + args.h_name = NULL;
17753 + err = hn_job(&args);
17754 + ii_write_unlock(a->dir);
17757 + iput(a->h_child_inode);
17760 + si_write_unlock(sb);
17761 + au_nwt_done(&sbinfo->si_nowait);
17765 +/* ---------------------------------------------------------------------- */
17767 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17768 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17771 + unsigned int flags[AuHnLast], f;
17772 + unsigned char isdir, isroot, wh;
17773 + struct inode *dir;
17774 + struct au_hnotify_args *args;
17775 + char *p, *h_child_name;
17778 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17779 + dir = igrab(hnotify->hn_aufs_inode);
17783 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17785 + h_child_name = (void *)h_child_qstr->name;
17786 + len = h_child_qstr->len;
17787 + if (h_child_name) {
17788 + if (len > AUFS_WH_PFX_LEN
17789 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17790 + h_child_name += AUFS_WH_PFX_LEN;
17791 + len -= AUFS_WH_PFX_LEN;
17797 + if (h_child_inode)
17798 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17799 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17800 + flags[AuHn_CHILD] = 0;
17802 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17803 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17804 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17805 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17806 + case FS_MOVED_FROM:
17807 + case FS_MOVED_TO:
17808 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17809 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17812 + AuDebugOn(!h_child_name);
17817 + * aufs never be able to get this child inode.
17818 + * revalidation should be in d_revalidate()
17819 + * by checking i_nlink, i_generation or d_unhashed().
17821 + AuDebugOn(!h_child_name);
17822 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17823 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17831 + h_child_inode = NULL;
17834 + /* iput() and kfree() will be called in au_hnotify() */
17835 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17836 + if (unlikely(!args)) {
17837 + AuErr1("no memory\n");
17841 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17842 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17843 + args->mask = mask;
17845 + args->h_dir = igrab(h_dir);
17846 + if (h_child_inode)
17847 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17848 + args->h_child_inode = h_child_inode;
17849 + args->h_child_nlen = len;
17851 + p = (void *)args;
17852 + p += sizeof(*args);
17853 + memcpy(p, h_child_name, len);
17857 + /* NFS fires the event for silly-renamed one from kworker */
17859 + if (!dir->i_nlink
17860 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17862 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17863 + if (unlikely(err)) {
17864 + pr_err("wkq %d\n", err);
17865 + iput(args->h_child_inode);
17866 + iput(args->h_dir);
17875 +/* ---------------------------------------------------------------------- */
17877 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17881 + AuDebugOn(!(udba & AuOptMask_UDBA));
17884 + if (au_hnotify_op.reset_br)
17885 + err = au_hnotify_op.reset_br(udba, br, perm);
17890 +int au_hnotify_init_br(struct au_branch *br, int perm)
17895 + if (au_hnotify_op.init_br)
17896 + err = au_hnotify_op.init_br(br, perm);
17901 +void au_hnotify_fin_br(struct au_branch *br)
17903 + if (au_hnotify_op.fin_br)
17904 + au_hnotify_op.fin_br(br);
17907 +static void au_hn_destroy_cache(void)
17909 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17910 + au_cache[AuCache_HNOTIFY] = NULL;
17913 +int __init au_hnotify_init(void)
17918 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17919 + if (au_cache[AuCache_HNOTIFY]) {
17921 + if (au_hnotify_op.init)
17922 + err = au_hnotify_op.init();
17923 + if (unlikely(err))
17924 + au_hn_destroy_cache();
17930 +void au_hnotify_fin(void)
17932 + if (au_hnotify_op.fin)
17933 + au_hnotify_op.fin();
17935 + /* cf. au_cache_fin() */
17936 + if (au_cache[AuCache_HNOTIFY])
17937 + au_hn_destroy_cache();
17939 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17940 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17941 +++ linux/fs/aufs/iinfo.c 2018-07-19 09:46:13.059981241 +0200
17943 +/* SPDX-License-Identifier: GPL-2.0 */
17945 + * Copyright (C) 2005-2018 Junjiro R. Okajima
17947 + * This program, aufs is free software; you can redistribute it and/or modify
17948 + * it under the terms of the GNU General Public License as published by
17949 + * the Free Software Foundation; either version 2 of the License, or
17950 + * (at your option) any later version.
17952 + * This program is distributed in the hope that it will be useful,
17953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17955 + * GNU General Public License for more details.
17957 + * You should have received a copy of the GNU General Public License
17958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17962 + * inode private data
17967 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17969 + struct inode *h_inode;
17970 + struct au_hinode *hinode;
17972 + IiMustAnyLock(inode);
17974 + hinode = au_hinode(au_ii(inode), bindex);
17975 + h_inode = hinode->hi_inode;
17976 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17980 +/* todo: hard/soft set? */
17981 +void au_hiput(struct au_hinode *hinode)
17983 + au_hn_free(hinode);
17984 + dput(hinode->hi_whdentry);
17985 + iput(hinode->hi_inode);
17988 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17990 + unsigned int flags;
17991 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17994 + if (au_opt_test(mnt_flags, XINO))
17995 + au_fset_hi(flags, XINO);
17996 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17997 + au_fset_hi(flags, HNOTIFY);
18001 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18002 + struct inode *h_inode, unsigned int flags)
18004 + struct au_hinode *hinode;
18005 + struct inode *hi;
18006 + struct au_iinfo *iinfo = au_ii(inode);
18008 + IiMustWriteLock(inode);
18010 + hinode = au_hinode(iinfo, bindex);
18011 + hi = hinode->hi_inode;
18012 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18015 + au_hiput(hinode);
18016 + hinode->hi_inode = h_inode;
18019 + struct super_block *sb = inode->i_sb;
18020 + struct au_branch *br;
18022 + AuDebugOn(inode->i_mode
18023 + && (h_inode->i_mode & S_IFMT)
18024 + != (inode->i_mode & S_IFMT));
18025 + if (bindex == iinfo->ii_btop)
18026 + au_cpup_igen(inode, h_inode);
18027 + br = au_sbr(sb, bindex);
18028 + hinode->hi_id = br->br_id;
18029 + if (au_ftest_hi(flags, XINO)) {
18030 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18032 + if (unlikely(err))
18033 + AuIOErr1("failed au_xino_write() %d\n", err);
18036 + if (au_ftest_hi(flags, HNOTIFY)
18037 + && au_br_hnotifyable(br->br_perm)) {
18038 + err = au_hn_alloc(hinode, inode);
18039 + if (unlikely(err))
18040 + AuIOErr1("au_hn_alloc() %d\n", err);
18045 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18046 + struct dentry *h_wh)
18048 + struct au_hinode *hinode;
18050 + IiMustWriteLock(inode);
18052 + hinode = au_hinode(au_ii(inode), bindex);
18053 + AuDebugOn(hinode->hi_whdentry);
18054 + hinode->hi_whdentry = h_wh;
18057 +void au_update_iigen(struct inode *inode, int half)
18059 + struct au_iinfo *iinfo;
18060 + struct au_iigen *iigen;
18061 + unsigned int sigen;
18063 + sigen = au_sigen(inode->i_sb);
18064 + iinfo = au_ii(inode);
18065 + iigen = &iinfo->ii_generation;
18066 + spin_lock(&iigen->ig_spin);
18067 + iigen->ig_generation = sigen;
18069 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18071 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18072 + spin_unlock(&iigen->ig_spin);
18075 +/* it may be called at remount time, too */
18076 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18078 + struct au_iinfo *iinfo;
18079 + aufs_bindex_t bindex, bbot;
18081 + AuDebugOn(au_is_bad_inode(inode));
18082 + IiMustWriteLock(inode);
18084 + iinfo = au_ii(inode);
18085 + if (do_put_zero && iinfo->ii_btop >= 0) {
18086 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18088 + struct inode *h_i;
18090 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18093 + && !(h_i->i_state & I_LINKABLE))
18094 + au_set_h_iptr(inode, bindex, NULL, 0);
18098 + iinfo->ii_btop = -1;
18099 + iinfo->ii_bbot = -1;
18100 + bbot = au_sbbot(inode->i_sb);
18101 + for (bindex = 0; bindex <= bbot; bindex++)
18102 + if (au_hinode(iinfo, bindex)->hi_inode) {
18103 + iinfo->ii_btop = bindex;
18106 + if (iinfo->ii_btop >= 0)
18107 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18108 + if (au_hinode(iinfo, bindex)->hi_inode) {
18109 + iinfo->ii_bbot = bindex;
18112 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18115 +/* ---------------------------------------------------------------------- */
18117 +void au_icntnr_init_once(void *_c)
18119 + struct au_icntnr *c = _c;
18120 + struct au_iinfo *iinfo = &c->iinfo;
18122 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18123 + au_rw_init(&iinfo->ii_rwsem);
18124 + inode_init_once(&c->vfs_inode);
18127 +void au_hinode_init(struct au_hinode *hinode)
18129 + hinode->hi_inode = NULL;
18130 + hinode->hi_id = -1;
18131 + au_hn_init(hinode);
18132 + hinode->hi_whdentry = NULL;
18135 +int au_iinfo_init(struct inode *inode)
18137 + struct au_iinfo *iinfo;
18138 + struct super_block *sb;
18139 + struct au_hinode *hi;
18142 + sb = inode->i_sb;
18143 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18144 + nbr = au_sbbot(sb) + 1;
18145 + if (unlikely(nbr <= 0))
18147 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18149 + au_ninodes_inc(sb);
18151 + iinfo->ii_hinode = hi;
18152 + for (i = 0; i < nbr; i++, hi++)
18153 + au_hinode_init(hi);
18155 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18156 + iinfo->ii_btop = -1;
18157 + iinfo->ii_bbot = -1;
18158 + iinfo->ii_vdir = NULL;
18164 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18167 + struct au_hinode *hip;
18169 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18172 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18175 + iinfo->ii_hinode = hip;
18176 + i = iinfo->ii_bbot + 1;
18178 + for (; i < nbr; i++, hip++)
18179 + au_hinode_init(hip);
18186 +void au_iinfo_fin(struct inode *inode)
18188 + struct au_iinfo *iinfo;
18189 + struct au_hinode *hi;
18190 + struct super_block *sb;
18191 + aufs_bindex_t bindex, bbot;
18192 + const unsigned char unlinked = !inode->i_nlink;
18194 + AuDebugOn(au_is_bad_inode(inode));
18196 + sb = inode->i_sb;
18197 + au_ninodes_dec(sb);
18198 + if (si_pid_test(sb))
18199 + au_xino_delete_inode(inode, unlinked);
18202 + * it is safe to hide the dependency between sbinfo and
18206 + si_noflush_read_lock(sb);
18207 + au_xino_delete_inode(inode, unlinked);
18208 + si_read_unlock(sb);
18212 + iinfo = au_ii(inode);
18213 + if (iinfo->ii_vdir)
18214 + au_vdir_free(iinfo->ii_vdir);
18216 + bindex = iinfo->ii_btop;
18217 + if (bindex >= 0) {
18218 + hi = au_hinode(iinfo, bindex);
18219 + bbot = iinfo->ii_bbot;
18220 + while (bindex++ <= bbot) {
18221 + if (hi->hi_inode)
18226 + kfree(iinfo->ii_hinode);
18227 + AuRwDestroy(&iinfo->ii_rwsem);
18229 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18230 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18231 +++ linux/fs/aufs/inode.c 2018-07-19 09:46:13.059981241 +0200
18233 +/* SPDX-License-Identifier: GPL-2.0 */
18235 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18237 + * This program, aufs is free software; you can redistribute it and/or modify
18238 + * it under the terms of the GNU General Public License as published by
18239 + * the Free Software Foundation; either version 2 of the License, or
18240 + * (at your option) any later version.
18242 + * This program is distributed in the hope that it will be useful,
18243 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18244 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18245 + * GNU General Public License for more details.
18247 + * You should have received a copy of the GNU General Public License
18248 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18252 + * inode functions
18257 +struct inode *au_igrab(struct inode *inode)
18260 + AuDebugOn(!atomic_read(&inode->i_count));
18266 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18268 + au_cpup_attr_all(inode, /*force*/0);
18269 + au_update_iigen(inode, /*half*/1);
18271 + inode_inc_iversion(inode);
18274 +static int au_ii_refresh(struct inode *inode, int *update)
18278 + aufs_bindex_t bindex, new_bindex;
18279 + struct super_block *sb;
18280 + struct au_iinfo *iinfo;
18281 + struct au_hinode *p, *q, tmp;
18283 + AuDebugOn(au_is_bad_inode(inode));
18284 + IiMustWriteLock(inode);
18287 + sb = inode->i_sb;
18288 + nbr = au_sbbot(sb) + 1;
18289 + type = inode->i_mode & S_IFMT;
18290 + iinfo = au_ii(inode);
18291 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18292 + if (unlikely(err))
18295 + AuDebugOn(iinfo->ii_btop < 0);
18296 + p = au_hinode(iinfo, iinfo->ii_btop);
18297 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18299 + if (!p->hi_inode)
18302 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18303 + new_bindex = au_br_index(sb, p->hi_id);
18304 + if (new_bindex == bindex)
18307 + if (new_bindex < 0) {
18310 + p->hi_inode = NULL;
18314 + if (new_bindex < iinfo->ii_btop)
18315 + iinfo->ii_btop = new_bindex;
18316 + if (iinfo->ii_bbot < new_bindex)
18317 + iinfo->ii_bbot = new_bindex;
18318 + /* swap two lower inode, and loop again */
18319 + q = au_hinode(iinfo, new_bindex);
18323 + if (tmp.hi_inode) {
18328 + au_update_ibrange(inode, /*do_put_zero*/0);
18329 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18330 + e = au_dy_irefresh(inode);
18331 + if (unlikely(e && !err))
18339 +void au_refresh_iop(struct inode *inode, int force_getattr)
18342 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18343 + const struct inode_operations *iop
18344 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18346 + if (inode->i_op == iop)
18349 + switch (inode->i_mode & S_IFMT) {
18351 + type = AuIop_DIR;
18354 + type = AuIop_SYMLINK;
18357 + type = AuIop_OTHER;
18361 + inode->i_op = iop + type;
18362 + /* unnecessary smp_wmb() */
18365 +int au_refresh_hinode_self(struct inode *inode)
18369 + err = au_ii_refresh(inode, &update);
18371 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18377 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18379 + int err, e, update;
18380 + unsigned int flags;
18382 + aufs_bindex_t bindex, bbot;
18383 + unsigned char isdir;
18384 + struct au_hinode *p;
18385 + struct au_iinfo *iinfo;
18387 + err = au_ii_refresh(inode, &update);
18388 + if (unlikely(err))
18392 + iinfo = au_ii(inode);
18393 + p = au_hinode(iinfo, iinfo->ii_btop);
18394 + mode = (inode->i_mode & S_IFMT);
18395 + isdir = S_ISDIR(mode);
18396 + flags = au_hi_flags(inode, isdir);
18397 + bbot = au_dbbot(dentry);
18398 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18399 + struct inode *h_i, *h_inode;
18400 + struct dentry *h_d;
18402 + h_d = au_h_dptr(dentry, bindex);
18403 + if (!h_d || d_is_negative(h_d))
18406 + h_inode = d_inode(h_d);
18407 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18408 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18409 + h_i = au_h_iptr(inode, bindex);
18411 + if (h_i == h_inode)
18417 + if (bindex < iinfo->ii_btop)
18418 + iinfo->ii_btop = bindex;
18419 + if (iinfo->ii_bbot < bindex)
18420 + iinfo->ii_bbot = bindex;
18421 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18424 + au_update_ibrange(inode, /*do_put_zero*/0);
18425 + e = au_dy_irefresh(inode);
18426 + if (unlikely(e && !err))
18429 + au_refresh_hinode_attr(inode, update && isdir);
18436 +static int set_inode(struct inode *inode, struct dentry *dentry)
18439 + unsigned int flags;
18441 + aufs_bindex_t bindex, btop, btail;
18442 + unsigned char isdir;
18443 + struct dentry *h_dentry;
18444 + struct inode *h_inode;
18445 + struct au_iinfo *iinfo;
18446 + struct inode_operations *iop;
18448 + IiMustWriteLock(inode);
18452 + iop = au_sbi(inode->i_sb)->si_iop_array;
18453 + btop = au_dbtop(dentry);
18454 + h_dentry = au_h_dptr(dentry, btop);
18455 + h_inode = d_inode(h_dentry);
18456 + mode = h_inode->i_mode;
18457 + switch (mode & S_IFMT) {
18459 + btail = au_dbtail(dentry);
18460 + inode->i_op = iop + AuIop_OTHER;
18461 + inode->i_fop = &aufs_file_fop;
18462 + err = au_dy_iaop(inode, btop, h_inode);
18463 + if (unlikely(err))
18468 + btail = au_dbtaildir(dentry);
18469 + inode->i_op = iop + AuIop_DIR;
18470 + inode->i_fop = &aufs_dir_fop;
18473 + btail = au_dbtail(dentry);
18474 + inode->i_op = iop + AuIop_SYMLINK;
18480 + btail = au_dbtail(dentry);
18481 + inode->i_op = iop + AuIop_OTHER;
18482 + init_special_inode(inode, mode, h_inode->i_rdev);
18485 + AuIOErr("Unknown file type 0%o\n", mode);
18490 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18491 + flags = au_hi_flags(inode, isdir);
18492 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18493 + && au_ftest_hi(flags, HNOTIFY)
18494 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18495 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18496 + au_fclr_hi(flags, HNOTIFY);
18497 + iinfo = au_ii(inode);
18498 + iinfo->ii_btop = btop;
18499 + iinfo->ii_bbot = btail;
18500 + for (bindex = btop; bindex <= btail; bindex++) {
18501 + h_dentry = au_h_dptr(dentry, bindex);
18503 + au_set_h_iptr(inode, bindex,
18504 + au_igrab(d_inode(h_dentry)), flags);
18506 + au_cpup_attr_all(inode, /*force*/1);
18508 + * to force calling aufs_get_acl() every time,
18509 + * do not call cache_no_acl() for aufs inode.
18517 + * successful returns with iinfo write_locked
18519 + * zero: success, matched
18520 + * plus: no error, but unmatched
18522 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18525 + unsigned int gen, igflags;
18526 + aufs_bindex_t bindex, bbot;
18527 + struct inode *h_inode, *h_dinode;
18528 + struct dentry *h_dentry;
18531 + * before this function, if aufs got any iinfo lock, it must be only
18532 + * one, the parent dir.
18533 + * it can happen by UDBA and the obsoleted inode number.
18536 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18540 + ii_write_lock_new_child(inode);
18541 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18542 + h_dinode = d_inode(h_dentry);
18543 + bbot = au_ibbot(inode);
18544 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18545 + h_inode = au_h_iptr(inode, bindex);
18546 + if (!h_inode || h_inode != h_dinode)
18550 + gen = au_iigen(inode, &igflags);
18551 + if (gen == au_digen(dentry)
18552 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18555 + /* fully refresh inode using dentry */
18556 + err = au_refresh_hinode(inode, dentry);
18558 + au_update_iigen(inode, /*half*/0);
18562 + if (unlikely(err))
18563 + ii_write_unlock(inode);
18568 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18569 + unsigned int d_type, ino_t *ino)
18572 + const int isnondir = d_type != DT_DIR;
18574 + /* prevent hardlinked inode number from race condition */
18576 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18577 + if (unlikely(err))
18581 + err = au_xino_read(sb, bindex, h_ino, ino);
18582 + if (unlikely(err))
18583 + goto out_xinondir;
18587 + *ino = au_xino_new_ino(sb);
18588 + if (unlikely(!*ino))
18589 + goto out_xinondir;
18590 + err = au_xino_write(sb, bindex, h_ino, *ino);
18591 + if (unlikely(err))
18592 + goto out_xinondir;
18596 + if (isnondir && idx >= 0)
18597 + au_xinondir_leave(sb, bindex, h_ino, idx);
18602 +/* successful returns with iinfo write_locked */
18603 +/* todo: return with unlocked? */
18604 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18606 + struct inode *inode, *h_inode;
18607 + struct dentry *h_dentry;
18608 + struct super_block *sb;
18609 + ino_t h_ino, ino;
18610 + int err, idx, hlinked;
18611 + aufs_bindex_t btop;
18613 + sb = dentry->d_sb;
18614 + btop = au_dbtop(dentry);
18615 + h_dentry = au_h_dptr(dentry, btop);
18616 + h_inode = d_inode(h_dentry);
18617 + h_ino = h_inode->i_ino;
18618 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18622 + * stop 'race'-ing between hardlinks under different
18626 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18627 + inode = ERR_PTR(err);
18628 + if (unlikely(err))
18632 + err = au_xino_read(sb, btop, h_ino, &ino);
18633 + inode = ERR_PTR(err);
18634 + if (unlikely(err))
18635 + goto out_xinondir;
18638 + ino = au_xino_new_ino(sb);
18639 + if (unlikely(!ino)) {
18640 + inode = ERR_PTR(-EIO);
18641 + goto out_xinondir;
18645 + AuDbg("i%lu\n", (unsigned long)ino);
18646 + inode = au_iget_locked(sb, ino);
18647 + err = PTR_ERR(inode);
18648 + if (IS_ERR(inode))
18649 + goto out_xinondir;
18651 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18652 + if (inode->i_state & I_NEW) {
18653 + ii_write_lock_new_child(inode);
18654 + err = set_inode(inode, dentry);
18656 + unlock_new_inode(inode);
18657 + goto out_xinondir; /* success */
18661 + * iget_failed() calls iput(), but we need to call
18662 + * ii_write_unlock() after iget_failed(). so dirty hack for
18665 + atomic_inc(&inode->i_count);
18666 + iget_failed(inode);
18667 + ii_write_unlock(inode);
18668 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18669 + /* ignore this error */
18671 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18673 + * horrible race condition between lookup, readdir and copyup
18674 + * (or something).
18676 + if (hlinked && idx >= 0)
18677 + au_xinondir_leave(sb, btop, h_ino, idx);
18678 + err = reval_inode(inode, dentry);
18679 + if (unlikely(err < 0)) {
18684 + goto out; /* success */
18685 + else if (hlinked && idx >= 0) {
18686 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18687 + if (unlikely(err)) {
18689 + inode = ERR_PTR(err);
18695 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18696 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18697 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18698 + btop, au_sbtype(h_dentry->d_sb), dentry,
18699 + (unsigned long)h_ino, (unsigned long)ino);
18701 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18704 + if (hlinked && idx >= 0)
18705 + au_xinondir_leave(sb, btop, h_ino, idx);
18711 + inode = ERR_PTR(err);
18713 + if (hlinked && idx >= 0)
18714 + au_xinondir_leave(sb, btop, h_ino, idx);
18719 +/* ---------------------------------------------------------------------- */
18721 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18722 + struct inode *inode)
18725 + struct inode *hi;
18727 + err = au_br_rdonly(au_sbr(sb, bindex));
18729 + /* pseudo-link after flushed may happen out of bounds */
18732 + && au_ibtop(inode) <= bindex
18733 + && bindex <= au_ibbot(inode)) {
18735 + * permission check is unnecessary since vfsub routine
18736 + * will be called later
18738 + hi = au_h_iptr(inode, bindex);
18740 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18746 +int au_test_h_perm(struct inode *h_inode, int mask)
18748 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18750 + return inode_permission(h_inode, mask);
18753 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18755 + if (au_test_nfs(h_inode->i_sb)
18756 + && (mask & MAY_WRITE)
18757 + && S_ISDIR(h_inode->i_mode))
18758 + mask |= MAY_READ; /* force permission check */
18759 + return au_test_h_perm(h_inode, mask);
18761 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18762 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18763 +++ linux/fs/aufs/inode.h 2018-07-19 09:46:13.059981241 +0200
18765 +/* SPDX-License-Identifier: GPL-2.0 */
18767 + * Copyright (C) 2005-2018 Junjiro R. Okajima
18769 + * This program, aufs is free software; you can redistribute it and/or modify
18770 + * it under the terms of the GNU General Public License as published by
18771 + * the Free Software Foundation; either version 2 of the License, or
18772 + * (at your option) any later version.
18774 + * This program is distributed in the hope that it will be useful,
18775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18777 + * GNU General Public License for more details.
18779 + * You should have received a copy of the GNU General Public License
18780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18784 + * inode operations
18787 +#ifndef __AUFS_INODE_H__
18788 +#define __AUFS_INODE_H__
18792 +#include <linux/fsnotify.h>
18793 +#include "rwsem.h"
18797 +struct au_hnotify {
18798 +#ifdef CONFIG_AUFS_HNOTIFY
18799 +#ifdef CONFIG_AUFS_HFSNOTIFY
18800 + /* never use fsnotify_add_vfsmount_mark() */
18801 + struct fsnotify_mark hn_mark;
18803 + struct inode *hn_aufs_inode; /* no get/put */
18805 +} ____cacheline_aligned_in_smp;
18807 +struct au_hinode {
18808 + struct inode *hi_inode;
18809 + aufs_bindex_t hi_id;
18810 +#ifdef CONFIG_AUFS_HNOTIFY
18811 + struct au_hnotify *hi_notify;
18814 + /* reference to the copied-up whiteout with get/put */
18815 + struct dentry *hi_whdentry;
18819 +#define AuIG_HALF_REFRESHED 1
18820 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18821 +#define au_ig_fset(flags, name) \
18822 + do { (flags) |= AuIG_##name; } while (0)
18823 +#define au_ig_fclr(flags, name) \
18824 + do { (flags) &= ~AuIG_##name; } while (0)
18827 + spinlock_t ig_spin;
18828 + __u32 ig_generation, ig_flags;
18833 + struct au_iigen ii_generation;
18834 + struct super_block *ii_hsb1; /* no get/put */
18836 + struct au_rwsem ii_rwsem;
18837 + aufs_bindex_t ii_btop, ii_bbot;
18839 + struct au_hinode *ii_hinode;
18840 + struct au_vdir *ii_vdir;
18843 +struct au_icntnr {
18844 + struct au_iinfo iinfo;
18845 + struct inode vfs_inode;
18846 + struct hlist_bl_node plink;
18847 +} ____cacheline_aligned_in_smp;
18849 +/* au_pin flags */
18850 +#define AuPin_DI_LOCKED 1
18851 +#define AuPin_MNT_WRITE (1 << 1)
18852 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18853 +#define au_fset_pin(flags, name) \
18854 + do { (flags) |= AuPin_##name; } while (0)
18855 +#define au_fclr_pin(flags, name) \
18856 + do { (flags) &= ~AuPin_##name; } while (0)
18860 + struct dentry *dentry;
18861 + unsigned int udba;
18862 + unsigned char lsc_di, lsc_hi, flags;
18863 + aufs_bindex_t bindex;
18866 + struct dentry *parent;
18867 + struct au_hinode *hdir;
18868 + struct vfsmount *h_mnt;
18870 + /* temporary unlock/relock for copyup */
18871 + struct dentry *h_dentry, *h_parent;
18872 + struct au_branch *br;
18873 + struct task_struct *task;
18876 +void au_pin_hdir_unlock(struct au_pin *p);
18877 +int au_pin_hdir_lock(struct au_pin *p);
18878 +int au_pin_hdir_relock(struct au_pin *p);
18879 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18880 +void au_pin_hdir_release(struct au_pin *p);
18882 +/* ---------------------------------------------------------------------- */
18884 +static inline struct au_iinfo *au_ii(struct inode *inode)
18886 + BUG_ON(is_bad_inode(inode));
18887 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18890 +/* ---------------------------------------------------------------------- */
18893 +struct inode *au_igrab(struct inode *inode);
18894 +void au_refresh_iop(struct inode *inode, int force_getattr);
18895 +int au_refresh_hinode_self(struct inode *inode);
18896 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18897 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18898 + unsigned int d_type, ino_t *ino);
18899 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18900 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18901 + struct inode *inode);
18902 +int au_test_h_perm(struct inode *h_inode, int mask);
18903 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18905 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18906 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18908 +#ifdef CONFIG_AUFS_SHWH
18909 + return au_ino(sb, bindex, h_ino, d_type, ino);
18922 +extern struct inode_operations aufs_iop[AuIop_Last],
18923 + aufs_iop_nogetattr[AuIop_Last];
18925 +/* au_wr_dir flags */
18926 +#define AuWrDir_ADD_ENTRY 1
18927 +#define AuWrDir_ISDIR (1 << 1)
18928 +#define AuWrDir_TMPFILE (1 << 2)
18929 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18930 +#define au_fset_wrdir(flags, name) \
18931 + do { (flags) |= AuWrDir_##name; } while (0)
18932 +#define au_fclr_wrdir(flags, name) \
18933 + do { (flags) &= ~AuWrDir_##name; } while (0)
18935 +struct au_wr_dir_args {
18936 + aufs_bindex_t force_btgt;
18937 + unsigned char flags;
18939 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18940 + struct au_wr_dir_args *args);
18942 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18943 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18944 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18945 + unsigned int udba, unsigned char flags);
18946 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18947 + unsigned int udba, unsigned char flags) __must_check;
18948 +int au_do_pin(struct au_pin *pin) __must_check;
18949 +void au_unpin(struct au_pin *pin);
18950 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18952 +#define AuIcpup_DID_CPUP 1
18953 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18954 +#define au_fset_icpup(flags, name) \
18955 + do { (flags) |= AuIcpup_##name; } while (0)
18956 +#define au_fclr_icpup(flags, name) \
18957 + do { (flags) &= ~AuIcpup_##name; } while (0)
18959 +struct au_icpup_args {
18960 + unsigned char flags;
18961 + unsigned char pin_flags;
18962 + aufs_bindex_t btgt;
18963 + unsigned int udba;
18964 + struct au_pin pin;
18965 + struct path h_path;
18966 + struct inode *h_inode;
18969 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18970 + struct au_icpup_args *a);
18972 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18976 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18977 + struct dentry *h_parent, int isdir);
18978 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18980 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18981 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18983 +struct vfsub_aopen_args;
18984 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18985 + struct vfsub_aopen_args *args);
18986 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18987 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18988 + struct dentry *dentry);
18989 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18992 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18993 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18994 + struct dentry *h_parent, int isdir);
18995 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18996 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18999 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19000 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19001 + struct inode *dir, struct dentry *dentry,
19002 + unsigned int flags);
19005 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19006 +void au_hiput(struct au_hinode *hinode);
19007 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19008 + struct dentry *h_wh);
19009 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19011 +/* hinode flags */
19012 +#define AuHi_XINO 1
19013 +#define AuHi_HNOTIFY (1 << 1)
19014 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19015 +#define au_fset_hi(flags, name) \
19016 + do { (flags) |= AuHi_##name; } while (0)
19017 +#define au_fclr_hi(flags, name) \
19018 + do { (flags) &= ~AuHi_##name; } while (0)
19020 +#ifndef CONFIG_AUFS_HNOTIFY
19021 +#undef AuHi_HNOTIFY
19022 +#define AuHi_HNOTIFY 0
19025 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19026 + struct inode *h_inode, unsigned int flags);
19028 +void au_update_iigen(struct inode *inode, int half);
19029 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19031 +void au_icntnr_init_once(void *_c);
19032 +void au_hinode_init(struct au_hinode *hinode);
19033 +int au_iinfo_init(struct inode *inode);
19034 +void au_iinfo_fin(struct inode *inode);
19035 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19037 +#ifdef CONFIG_PROC_FS
19039 +int au_plink_maint(struct super_block *sb, int flags);
19041 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19042 +int au_plink_maint_enter(struct super_block *sb);
19043 +#ifdef CONFIG_AUFS_DEBUG
19044 +void au_plink_list(struct super_block *sb);
19046 +AuStubVoid(au_plink_list, struct super_block *sb)
19048 +int au_plink_test(struct inode *inode);
19049 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19050 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19051 + struct dentry *h_dentry);
19052 +void au_plink_put(struct super_block *sb, int verbose);
19053 +void au_plink_clean(struct super_block *sb, int verbose);
19054 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19056 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19057 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19058 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19059 +AuStubVoid(au_plink_list, struct super_block *sb);
19060 +AuStubInt0(au_plink_test, struct inode *inode);
19061 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19062 + struct inode *inode, aufs_bindex_t bindex);
19063 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19064 + struct dentry *h_dentry);
19065 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19066 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19067 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19068 +#endif /* CONFIG_PROC_FS */
19070 +#ifdef CONFIG_AUFS_XATTR
19072 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19073 + unsigned int verbose);
19074 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19075 +void au_xattr_init(struct super_block *sb);
19077 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19078 + int ignore_flags, unsigned int verbose);
19079 +AuStubVoid(au_xattr_init, struct super_block *sb);
19082 +#ifdef CONFIG_FS_POSIX_ACL
19083 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19084 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19087 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19093 +struct au_sxattr {
19097 + const char *name;
19098 + const void *value;
19103 + struct posix_acl *acl;
19108 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19109 + struct au_sxattr *arg);
19112 +/* ---------------------------------------------------------------------- */
19114 +/* lock subclass for iinfo */
19116 + AuLsc_II_CHILD, /* child first */
19117 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19118 + AuLsc_II_CHILD3, /* copyup dirs */
19119 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19120 + AuLsc_II_PARENT2,
19121 + AuLsc_II_PARENT3, /* copyup dirs */
19122 + AuLsc_II_NEW_CHILD
19126 + * ii_read_lock_child, ii_write_lock_child,
19127 + * ii_read_lock_child2, ii_write_lock_child2,
19128 + * ii_read_lock_child3, ii_write_lock_child3,
19129 + * ii_read_lock_parent, ii_write_lock_parent,
19130 + * ii_read_lock_parent2, ii_write_lock_parent2,
19131 + * ii_read_lock_parent3, ii_write_lock_parent3,
19132 + * ii_read_lock_new_child, ii_write_lock_new_child,
19134 +#define AuReadLockFunc(name, lsc) \
19135 +static inline void ii_read_lock_##name(struct inode *i) \
19137 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19140 +#define AuWriteLockFunc(name, lsc) \
19141 +static inline void ii_write_lock_##name(struct inode *i) \
19143 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19146 +#define AuRWLockFuncs(name, lsc) \
19147 + AuReadLockFunc(name, lsc) \
19148 + AuWriteLockFunc(name, lsc)
19150 +AuRWLockFuncs(child, CHILD);
19151 +AuRWLockFuncs(child2, CHILD2);
19152 +AuRWLockFuncs(child3, CHILD3);
19153 +AuRWLockFuncs(parent, PARENT);
19154 +AuRWLockFuncs(parent2, PARENT2);
19155 +AuRWLockFuncs(parent3, PARENT3);
19156 +AuRWLockFuncs(new_child, NEW_CHILD);
19158 +#undef AuReadLockFunc
19159 +#undef AuWriteLockFunc
19160 +#undef AuRWLockFuncs
19162 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19163 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19164 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19166 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19167 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19168 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19170 +/* ---------------------------------------------------------------------- */
19172 +static inline void au_icntnr_init(struct au_icntnr *c)
19174 +#ifdef CONFIG_AUFS_DEBUG
19175 + c->vfs_inode.i_mode = 0;
19179 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19181 + unsigned int gen;
19182 + struct au_iinfo *iinfo;
19183 + struct au_iigen *iigen;
19185 + iinfo = au_ii(inode);
19186 + iigen = &iinfo->ii_generation;
19187 + spin_lock(&iigen->ig_spin);
19189 + *igflags = iigen->ig_flags;
19190 + gen = iigen->ig_generation;
19191 + spin_unlock(&iigen->ig_spin);
19196 +/* tiny test for inode number */
19197 +/* tmpfs generation is too rough */
19198 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19200 + struct au_iinfo *iinfo;
19202 + iinfo = au_ii(inode);
19203 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19204 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19205 + && iinfo->ii_higen == h_inode->i_generation);
19208 +static inline void au_iigen_dec(struct inode *inode)
19210 + struct au_iinfo *iinfo;
19211 + struct au_iigen *iigen;
19213 + iinfo = au_ii(inode);
19214 + iigen = &iinfo->ii_generation;
19215 + spin_lock(&iigen->ig_spin);
19216 + iigen->ig_generation--;
19217 + spin_unlock(&iigen->ig_spin);
19220 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19225 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19231 +/* ---------------------------------------------------------------------- */
19233 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19234 + aufs_bindex_t bindex)
19236 + return iinfo->ii_hinode + bindex;
19239 +static inline int au_is_bad_inode(struct inode *inode)
19241 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19244 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19245 + aufs_bindex_t bindex)
19247 + IiMustAnyLock(inode);
19248 + return au_hinode(au_ii(inode), bindex)->hi_id;
19251 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19253 + IiMustAnyLock(inode);
19254 + return au_ii(inode)->ii_btop;
19257 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19259 + IiMustAnyLock(inode);
19260 + return au_ii(inode)->ii_bbot;
19263 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19265 + IiMustAnyLock(inode);
19266 + return au_ii(inode)->ii_vdir;
19269 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19271 + IiMustAnyLock(inode);
19272 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19275 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19277 + IiMustWriteLock(inode);
19278 + au_ii(inode)->ii_btop = bindex;
19281 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19283 + IiMustWriteLock(inode);
19284 + au_ii(inode)->ii_bbot = bindex;
19287 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19289 + IiMustWriteLock(inode);
19290 + au_ii(inode)->ii_vdir = vdir;
19293 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19295 + IiMustAnyLock(inode);
19296 + return au_hinode(au_ii(inode), bindex);
19299 +/* ---------------------------------------------------------------------- */
19301 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19304 + return pin->parent;
19308 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19310 + if (pin && pin->hdir)
19311 + return pin->hdir->hi_inode;
19315 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19318 + return pin->hdir;
19322 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19325 + pin->dentry = dentry;
19328 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19329 + unsigned char lflag)
19333 + au_fset_pin(pin->flags, DI_LOCKED);
19335 + au_fclr_pin(pin->flags, DI_LOCKED);
19339 +#if 0 /* reserved */
19340 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19343 + dput(pin->parent);
19344 + pin->parent = dget(parent);
19349 +/* ---------------------------------------------------------------------- */
19352 +#ifdef CONFIG_AUFS_HNOTIFY
19353 +struct au_hnotify_op {
19354 + void (*ctl)(struct au_hinode *hinode, int do_set);
19355 + int (*alloc)(struct au_hinode *hinode);
19358 + * if it returns true, the the caller should free hinode->hi_notify,
19359 + * otherwise ->free() frees it.
19361 + int (*free)(struct au_hinode *hinode,
19362 + struct au_hnotify *hn) __must_check;
19364 + void (*fin)(void);
19365 + int (*init)(void);
19367 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19368 + void (*fin_br)(struct au_branch *br);
19369 + int (*init_br)(struct au_branch *br, int perm);
19373 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19374 +void au_hn_free(struct au_hinode *hinode);
19375 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19376 +void au_hn_reset(struct inode *inode, unsigned int flags);
19377 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19378 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19379 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19380 +int au_hnotify_init_br(struct au_branch *br, int perm);
19381 +void au_hnotify_fin_br(struct au_branch *br);
19382 +int __init au_hnotify_init(void);
19383 +void au_hnotify_fin(void);
19386 +extern const struct au_hnotify_op au_hnotify_op;
19389 +void au_hn_init(struct au_hinode *hinode)
19391 + hinode->hi_notify = NULL;
19394 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19396 + return hinode->hi_notify;
19400 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19401 + struct au_hinode *hinode __maybe_unused,
19402 + struct inode *inode __maybe_unused)
19403 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19404 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19405 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19406 + int do_set __maybe_unused)
19407 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19408 + unsigned int flags __maybe_unused)
19409 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19410 + struct au_branch *br __maybe_unused,
19411 + int perm __maybe_unused)
19412 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19413 + int perm __maybe_unused)
19414 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19415 +AuStubInt0(__init au_hnotify_init, void)
19416 +AuStubVoid(au_hnotify_fin, void)
19417 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19418 +#endif /* CONFIG_AUFS_HNOTIFY */
19420 +static inline void au_hn_suspend(struct au_hinode *hdir)
19422 + au_hn_ctl(hdir, /*do_set*/0);
19425 +static inline void au_hn_resume(struct au_hinode *hdir)
19427 + au_hn_ctl(hdir, /*do_set*/1);
19430 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19432 + inode_lock(hdir->hi_inode);
19433 + au_hn_suspend(hdir);
19436 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19437 + unsigned int sc __maybe_unused)
19439 + inode_lock_nested(hdir->hi_inode, sc);
19440 + au_hn_suspend(hdir);
19443 +#if 0 /* unused */
19444 +#include "vfsub.h"
19445 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19448 + inode_lock_shared_nested(hdir->hi_inode, sc);
19449 + au_hn_suspend(hdir);
19453 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19455 + au_hn_resume(hdir);
19456 + inode_unlock(hdir->hi_inode);
19459 +#endif /* __KERNEL__ */
19460 +#endif /* __AUFS_INODE_H__ */
19461 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19462 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19463 +++ linux/fs/aufs/ioctl.c 2018-07-19 09:46:13.059981241 +0200
19465 +/* SPDX-License-Identifier: GPL-2.0 */
19467 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19469 + * This program, aufs is free software; you can redistribute it and/or modify
19470 + * it under the terms of the GNU General Public License as published by
19471 + * the Free Software Foundation; either version 2 of the License, or
19472 + * (at your option) any later version.
19474 + * This program is distributed in the hope that it will be useful,
19475 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19476 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19477 + * GNU General Public License for more details.
19479 + * You should have received a copy of the GNU General Public License
19480 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19485 + * plink-management and readdir in userspace.
19486 + * assist the pathconf(3) wrapper library.
19488 + * File-based Hierarchical Storage Management.
19491 +#include <linux/compat.h>
19492 +#include <linux/file.h>
19495 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19498 + aufs_bindex_t wbi, bindex, bbot;
19499 + struct file *h_file;
19500 + struct super_block *sb;
19501 + struct dentry *root;
19502 + struct au_branch *br;
19503 + struct aufs_wbr_fd wbrfd = {
19504 + .oflags = au_dir_roflags,
19507 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19508 + | O_NOATIME | O_CLOEXEC;
19510 + AuDebugOn(wbrfd.oflags & ~valid);
19513 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19514 + if (unlikely(err)) {
19520 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19521 + wbrfd.oflags |= au_dir_roflags;
19522 + AuDbg("0%o\n", wbrfd.oflags);
19523 + if (unlikely(wbrfd.oflags & ~valid))
19527 + fd = get_unused_fd_flags(0);
19529 + if (unlikely(fd < 0))
19532 + h_file = ERR_PTR(-EINVAL);
19535 + sb = path->dentry->d_sb;
19536 + root = sb->s_root;
19537 + aufs_read_lock(root, AuLock_IR);
19538 + bbot = au_sbbot(sb);
19539 + if (wbrfd.brid >= 0) {
19540 + wbi = au_br_index(sb, wbrfd.brid);
19541 + if (unlikely(wbi < 0 || wbi > bbot))
19545 + h_file = ERR_PTR(-ENOENT);
19546 + br = au_sbr(sb, wbi);
19547 + if (!au_br_writable(br->br_perm)) {
19551 + bindex = wbi + 1;
19553 + for (; bindex <= bbot; bindex++) {
19554 + br = au_sbr(sb, bindex);
19555 + if (au_br_writable(br->br_perm)) {
19557 + br = au_sbr(sb, wbi);
19562 + AuDbg("wbi %d\n", wbi);
19564 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19568 + aufs_read_unlock(root, AuLock_IR);
19569 + err = PTR_ERR(h_file);
19570 + if (IS_ERR(h_file))
19573 + au_br_put(br); /* cf. au_h_open() */
19574 + fd_install(fd, h_file);
19576 + goto out; /* success */
19579 + put_unused_fd(fd);
19585 +/* ---------------------------------------------------------------------- */
19587 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19590 + struct dentry *dentry;
19593 + case AUFS_CTL_RDU:
19594 + case AUFS_CTL_RDU_INO:
19595 + err = au_rdu_ioctl(file, cmd, arg);
19598 + case AUFS_CTL_WBR_FD:
19599 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19602 + case AUFS_CTL_IBUSY:
19603 + err = au_ibusy_ioctl(file, arg);
19606 + case AUFS_CTL_BRINFO:
19607 + err = au_brinfo_ioctl(file, arg);
19610 + case AUFS_CTL_FHSM_FD:
19611 + dentry = file->f_path.dentry;
19612 + if (IS_ROOT(dentry))
19613 + err = au_fhsm_fd(dentry->d_sb, arg);
19619 + /* do not call the lower */
19620 + AuDbg("0x%x\n", cmd);
19628 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19633 + case AUFS_CTL_MVDOWN:
19634 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19637 + case AUFS_CTL_WBR_FD:
19638 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19642 + /* do not call the lower */
19643 + AuDbg("0x%x\n", cmd);
19651 +#ifdef CONFIG_COMPAT
19652 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19653 + unsigned long arg)
19658 + case AUFS_CTL_RDU:
19659 + case AUFS_CTL_RDU_INO:
19660 + err = au_rdu_compat_ioctl(file, cmd, arg);
19663 + case AUFS_CTL_IBUSY:
19664 + err = au_ibusy_compat_ioctl(file, arg);
19667 + case AUFS_CTL_BRINFO:
19668 + err = au_brinfo_compat_ioctl(file, arg);
19672 + err = aufs_ioctl_dir(file, cmd, arg);
19679 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19680 + unsigned long arg)
19682 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19685 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19686 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19687 +++ linux/fs/aufs/i_op_add.c 2018-07-19 09:46:13.059981241 +0200
19689 +/* SPDX-License-Identifier: GPL-2.0 */
19691 + * Copyright (C) 2005-2018 Junjiro R. Okajima
19693 + * This program, aufs is free software; you can redistribute it and/or modify
19694 + * it under the terms of the GNU General Public License as published by
19695 + * the Free Software Foundation; either version 2 of the License, or
19696 + * (at your option) any later version.
19698 + * This program is distributed in the hope that it will be useful,
19699 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19700 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19701 + * GNU General Public License for more details.
19703 + * You should have received a copy of the GNU General Public License
19704 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19708 + * inode operations (add entry)
19714 + * final procedure of adding a new entry, except link(2).
19715 + * remove whiteout, instantiate, copyup the parent dir's times and size
19716 + * and update version.
19717 + * if it failed, re-create the removed whiteout.
19719 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19720 + struct dentry *wh_dentry, struct dentry *dentry)
19723 + aufs_bindex_t bwh;
19724 + struct path h_path;
19725 + struct super_block *sb;
19726 + struct inode *inode, *h_dir;
19727 + struct dentry *wh;
19732 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19733 + IMustLock(h_dir);
19734 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19735 + bwh = au_dbwh(dentry);
19736 + h_path.dentry = wh_dentry;
19737 + h_path.mnt = au_sbr_mnt(sb, bindex);
19738 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19740 + if (unlikely(err))
19744 + inode = au_new_inode(dentry, /*must_new*/1);
19745 + if (!IS_ERR(inode)) {
19746 + d_instantiate(dentry, inode);
19747 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19749 + au_dir_ts(dir, bindex);
19750 + inode_inc_iversion(dir);
19751 + au_fhsm_wrote(sb, bindex, /*force*/0);
19752 + return 0; /* success */
19755 + err = PTR_ERR(inode);
19760 + /* dir inode is locked */
19761 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19762 + rerr = PTR_ERR(wh);
19763 + if (IS_ERR(wh)) {
19764 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19765 + dentry, err, rerr);
19774 +static int au_d_may_add(struct dentry *dentry)
19779 + if (unlikely(d_unhashed(dentry)))
19781 + if (unlikely(d_really_is_positive(dentry)))
19787 + * simple tests for the adding inode operations.
19788 + * following the checks in vfs, plus the parent-child relationship.
19790 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19791 + struct dentry *h_parent, int isdir)
19795 + struct dentry *h_dentry;
19796 + struct inode *h_inode;
19798 + err = -ENAMETOOLONG;
19799 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19802 + h_dentry = au_h_dptr(dentry, bindex);
19803 + if (d_really_is_negative(dentry)) {
19805 + if (unlikely(d_is_positive(h_dentry)))
19808 + /* rename(2) case */
19810 + if (unlikely(d_is_negative(h_dentry)))
19812 + h_inode = d_inode(h_dentry);
19813 + if (unlikely(!h_inode->i_nlink))
19816 + h_mode = h_inode->i_mode;
19819 + if (unlikely(S_ISDIR(h_mode)))
19821 + } else if (unlikely(!S_ISDIR(h_mode))) {
19828 + /* expected parent dir is locked */
19829 + if (unlikely(h_parent != h_dentry->d_parent))
19838 + * initial procedure of adding a new entry.
19839 + * prepare writable branch and the parent dir, lock it,
19840 + * and lookup whiteout for the new entry.
19842 +static struct dentry*
19843 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19844 + struct dentry *src_dentry, struct au_pin *pin,
19845 + struct au_wr_dir_args *wr_dir_args)
19847 + struct dentry *wh_dentry, *h_parent;
19848 + struct super_block *sb;
19849 + struct au_branch *br;
19851 + unsigned int udba;
19852 + aufs_bindex_t bcpup;
19854 + AuDbg("%pd\n", dentry);
19856 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19858 + wh_dentry = ERR_PTR(err);
19859 + if (unlikely(err < 0))
19862 + sb = dentry->d_sb;
19863 + udba = au_opt_udba(sb);
19864 + err = au_pin(pin, dentry, bcpup, udba,
19865 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19866 + wh_dentry = ERR_PTR(err);
19867 + if (unlikely(err))
19870 + h_parent = au_pinned_h_parent(pin);
19871 + if (udba != AuOpt_UDBA_NONE
19872 + && au_dbtop(dentry) == bcpup)
19873 + err = au_may_add(dentry, bcpup, h_parent,
19874 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19875 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19876 + err = -ENAMETOOLONG;
19877 + wh_dentry = ERR_PTR(err);
19878 + if (unlikely(err))
19881 + br = au_sbr(sb, bcpup);
19883 + struct path tmp = {
19884 + .dentry = h_parent,
19885 + .mnt = au_br_mnt(br)
19887 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19890 + wh_dentry = NULL;
19891 + if (bcpup != au_dbwh(dentry))
19892 + goto out; /* success */
19895 + * ENAMETOOLONG here means that if we allowed create such name, then it
19896 + * would not be able to removed in the future. So we don't allow such
19897 + * name here and we don't handle ENAMETOOLONG differently here.
19899 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19902 + if (IS_ERR(wh_dentry))
19905 + return wh_dentry;
19908 +/* ---------------------------------------------------------------------- */
19910 +enum { Mknod, Symlink, Creat };
19911 +struct simple_arg {
19918 + struct vfsub_aopen_args *aopen;
19921 + const char *symname;
19930 +static int add_simple(struct inode *dir, struct dentry *dentry,
19931 + struct simple_arg *arg)
19934 + aufs_bindex_t btop;
19935 + unsigned char created;
19936 + const unsigned char try_aopen
19937 + = (arg->type == Creat && arg->u.c.try_aopen);
19938 + struct dentry *wh_dentry, *parent;
19939 + struct inode *h_dir;
19940 + struct super_block *sb;
19941 + struct au_branch *br;
19942 + /* to reuduce stack size */
19944 + struct au_dtime dt;
19945 + struct au_pin pin;
19946 + struct path h_path;
19947 + struct au_wr_dir_args wr_dir_args;
19950 + AuDbg("%pd\n", dentry);
19954 + a = kmalloc(sizeof(*a), GFP_NOFS);
19955 + if (unlikely(!a))
19957 + a->wr_dir_args.force_btgt = -1;
19958 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19960 + parent = dentry->d_parent; /* dir inode is locked */
19961 + if (!try_aopen) {
19962 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19963 + if (unlikely(err))
19966 + err = au_d_may_add(dentry);
19967 + if (unlikely(err))
19970 + di_write_lock_parent(parent);
19971 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19972 + &a->pin, &a->wr_dir_args);
19973 + err = PTR_ERR(wh_dentry);
19974 + if (IS_ERR(wh_dentry))
19977 + btop = au_dbtop(dentry);
19978 + sb = dentry->d_sb;
19979 + br = au_sbr(sb, btop);
19980 + a->h_path.dentry = au_h_dptr(dentry, btop);
19981 + a->h_path.mnt = au_br_mnt(br);
19982 + h_dir = au_pinned_h_dir(&a->pin);
19983 + switch (arg->type) {
19986 + if (!try_aopen || !h_dir->i_op->atomic_open)
19987 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19988 + arg->u.c.want_excl);
19990 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
19991 + arg->u.c.aopen, br);
19994 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19997 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20005 + err = epilog(dir, btop, wh_dentry, dentry);
20008 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
20009 + /* no delegation since it is just created */
20010 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20013 + AuIOErr("%pd revert failure(%d, %d)\n",
20014 + dentry, err, rerr);
20017 + au_dtime_revert(&a->dt);
20020 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
20021 + *arg->u.c.aopen->opened |= FILE_CREATED;
20023 + au_unpin(&a->pin);
20028 + di_write_unlock(parent);
20030 + if (unlikely(err)) {
20031 + au_update_dbtop(dentry);
20035 + aufs_read_unlock(dentry, AuLock_DW);
20042 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20045 + struct simple_arg arg = {
20052 + return add_simple(dir, dentry, &arg);
20055 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20057 + struct simple_arg arg = {
20059 + .u.s.symname = symname
20061 + return add_simple(dir, dentry, &arg);
20064 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20067 + struct simple_arg arg = {
20071 + .want_excl = want_excl
20074 + return add_simple(dir, dentry, &arg);
20077 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20078 + struct vfsub_aopen_args *aopen_args)
20080 + struct simple_arg arg = {
20083 + .mode = aopen_args->create_mode,
20084 + .want_excl = aopen_args->open_flag & O_EXCL,
20085 + .try_aopen = true,
20086 + .aopen = aopen_args
20089 + return add_simple(dir, dentry, &arg);
20092 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20095 + aufs_bindex_t bindex;
20096 + struct super_block *sb;
20097 + struct dentry *parent, *h_parent, *h_dentry;
20098 + struct inode *h_dir, *inode;
20099 + struct vfsmount *h_mnt;
20100 + struct au_wr_dir_args wr_dir_args = {
20101 + .force_btgt = -1,
20102 + .flags = AuWrDir_TMPFILE
20105 + /* copy-up may happen */
20109 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20110 + if (unlikely(err))
20113 + err = au_di_init(dentry);
20114 + if (unlikely(err))
20118 + parent = d_find_any_alias(dir);
20119 + AuDebugOn(!parent);
20120 + di_write_lock_parent(parent);
20121 + if (unlikely(d_inode(parent) != dir))
20124 + err = au_digen_test(parent, au_sigen(sb));
20125 + if (unlikely(err))
20128 + bindex = au_dbtop(parent);
20129 + au_set_dbtop(dentry, bindex);
20130 + au_set_dbbot(dentry, bindex);
20131 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20133 + if (unlikely(err < 0))
20136 + err = -EOPNOTSUPP;
20137 + h_dir = au_h_iptr(dir, bindex);
20138 + if (unlikely(!h_dir->i_op->tmpfile))
20141 + h_mnt = au_sbr_mnt(sb, bindex);
20142 + err = vfsub_mnt_want_write(h_mnt);
20143 + if (unlikely(err))
20146 + h_parent = au_h_dptr(parent, bindex);
20147 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20148 + if (IS_ERR(h_dentry)) {
20149 + err = PTR_ERR(h_dentry);
20153 + au_set_dbtop(dentry, bindex);
20154 + au_set_dbbot(dentry, bindex);
20155 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20156 + inode = au_new_inode(dentry, /*must_new*/1);
20157 + if (IS_ERR(inode)) {
20158 + err = PTR_ERR(inode);
20159 + au_set_h_dptr(dentry, bindex, NULL);
20160 + au_set_dbtop(dentry, -1);
20161 + au_set_dbbot(dentry, -1);
20163 + if (!inode->i_nlink)
20164 + set_nlink(inode, 1);
20165 + d_tmpfile(dentry, inode);
20166 + au_di(dentry)->di_tmpfile = 1;
20168 + /* update without i_mutex */
20169 + if (au_ibtop(dir) == au_dbtop(dentry))
20170 + au_cpup_attr_timesizes(dir);
20175 + vfsub_mnt_drop_write(h_mnt);
20177 + di_write_unlock(parent);
20179 + di_write_unlock(dentry);
20180 + if (unlikely(err)) {
20181 + au_di_fin(dentry);
20182 + dentry->d_fsdata = NULL;
20185 + si_read_unlock(sb);
20187 + inode_unlock(dir);
20191 +/* ---------------------------------------------------------------------- */
20193 +struct au_link_args {
20194 + aufs_bindex_t bdst, bsrc;
20195 + struct au_pin pin;
20196 + struct path h_path;
20197 + struct dentry *src_parent, *parent;
20200 +static int au_cpup_before_link(struct dentry *src_dentry,
20201 + struct au_link_args *a)
20204 + struct dentry *h_src_dentry;
20205 + struct au_cp_generic cpg = {
20206 + .dentry = src_dentry,
20211 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20214 + di_read_lock_parent(a->src_parent, AuLock_IR);
20215 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20216 + if (unlikely(err))
20219 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20220 + err = au_pin(&a->pin, src_dentry, a->bdst,
20221 + au_opt_udba(src_dentry->d_sb),
20222 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20223 + if (unlikely(err))
20226 + err = au_sio_cpup_simple(&cpg);
20227 + au_unpin(&a->pin);
20230 + di_read_unlock(a->src_parent, AuLock_IR);
20234 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20235 + struct au_link_args *a)
20238 + unsigned char plink;
20239 + aufs_bindex_t bbot;
20240 + struct dentry *h_src_dentry;
20241 + struct inode *h_inode, *inode, *delegated;
20242 + struct super_block *sb;
20243 + struct file *h_file;
20247 + sb = src_dentry->d_sb;
20248 + inode = d_inode(src_dentry);
20249 + if (au_ibtop(inode) <= a->bdst)
20250 + h_inode = au_h_iptr(inode, a->bdst);
20251 + if (!h_inode || !h_inode->i_nlink) {
20252 + /* copyup src_dentry as the name of dentry. */
20253 + bbot = au_dbbot(dentry);
20254 + if (bbot < a->bsrc)
20255 + au_set_dbbot(dentry, a->bsrc);
20256 + au_set_h_dptr(dentry, a->bsrc,
20257 + dget(au_h_dptr(src_dentry, a->bsrc)));
20258 + dget(a->h_path.dentry);
20259 + au_set_h_dptr(dentry, a->bdst, NULL);
20260 + AuDbg("temporary d_inode...\n");
20261 + spin_lock(&dentry->d_lock);
20262 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20263 + spin_unlock(&dentry->d_lock);
20264 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20265 + if (IS_ERR(h_file))
20266 + err = PTR_ERR(h_file);
20268 + struct au_cp_generic cpg = {
20269 + .dentry = dentry,
20274 + .flags = AuCpup_KEEPLINO
20276 + err = au_sio_cpup_simple(&cpg);
20277 + au_h_open_post(dentry, a->bsrc, h_file);
20279 + dput(a->h_path.dentry);
20280 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20282 + au_set_h_dptr(dentry, a->bdst,
20283 + a->h_path.dentry);
20285 + spin_lock(&dentry->d_lock);
20286 + dentry->d_inode = NULL; /* restore */
20287 + spin_unlock(&dentry->d_lock);
20288 + AuDbg("temporary d_inode...done\n");
20289 + au_set_h_dptr(dentry, a->bsrc, NULL);
20290 + au_set_dbbot(dentry, bbot);
20292 + /* the inode of src_dentry already exists on a.bdst branch */
20293 + h_src_dentry = d_find_alias(h_inode);
20294 + if (!h_src_dentry && au_plink_test(inode)) {
20296 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20297 + err = PTR_ERR(h_src_dentry);
20298 + if (IS_ERR(h_src_dentry))
20301 + if (unlikely(d_is_negative(h_src_dentry))) {
20302 + dput(h_src_dentry);
20303 + h_src_dentry = NULL;
20307 + if (h_src_dentry) {
20308 + delegated = NULL;
20309 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20310 + &a->h_path, &delegated);
20311 + if (unlikely(err == -EWOULDBLOCK)) {
20312 + pr_warn("cannot retry for NFSv4 delegation"
20313 + " for an internal link\n");
20316 + dput(h_src_dentry);
20318 + AuIOErr("no dentry found for hi%lu on b%d\n",
20319 + h_inode->i_ino, a->bdst);
20324 + if (!err && !plink)
20325 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20332 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20333 + struct dentry *dentry)
20336 + struct au_dtime dt;
20337 + struct au_link_args *a;
20338 + struct dentry *wh_dentry, *h_src_dentry;
20339 + struct inode *inode, *delegated;
20340 + struct super_block *sb;
20341 + struct au_wr_dir_args wr_dir_args = {
20342 + /* .force_btgt = -1, */
20343 + .flags = AuWrDir_ADD_ENTRY
20347 + inode = d_inode(src_dentry);
20348 + IMustLock(inode);
20351 + a = kzalloc(sizeof(*a), GFP_NOFS);
20352 + if (unlikely(!a))
20355 + a->parent = dentry->d_parent; /* dir inode is locked */
20356 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20357 + AuLock_NOPLM | AuLock_GEN);
20358 + if (unlikely(err))
20360 + err = au_d_linkable(src_dentry);
20361 + if (unlikely(err))
20363 + err = au_d_may_add(dentry);
20364 + if (unlikely(err))
20367 + a->src_parent = dget_parent(src_dentry);
20368 + wr_dir_args.force_btgt = au_ibtop(inode);
20370 + di_write_lock_parent(a->parent);
20371 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20372 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20374 + err = PTR_ERR(wh_dentry);
20375 + if (IS_ERR(wh_dentry))
20379 + sb = dentry->d_sb;
20380 + a->bdst = au_dbtop(dentry);
20381 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20382 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20383 + a->bsrc = au_ibtop(inode);
20384 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20385 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20386 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20387 + if (!h_src_dentry) {
20388 + a->bsrc = au_dbtop(src_dentry);
20389 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20390 + AuDebugOn(!h_src_dentry);
20391 + } else if (IS_ERR(h_src_dentry)) {
20392 + err = PTR_ERR(h_src_dentry);
20397 + * aufs doesn't touch the credential so
20398 + * security_dentry_create_files_as() is unnecrssary.
20400 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20401 + if (a->bdst < a->bsrc
20402 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20403 + err = au_cpup_or_link(src_dentry, dentry, a);
20405 + delegated = NULL;
20406 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20407 + &a->h_path, &delegated);
20408 + if (unlikely(err == -EWOULDBLOCK)) {
20409 + pr_warn("cannot retry for NFSv4 delegation"
20410 + " for an internal link\n");
20414 + dput(h_src_dentry);
20417 + * copyup src_dentry to the branch we process,
20418 + * and then link(2) to it.
20420 + dput(h_src_dentry);
20421 + if (a->bdst < a->bsrc
20422 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20423 + au_unpin(&a->pin);
20424 + di_write_unlock(a->parent);
20425 + err = au_cpup_before_link(src_dentry, a);
20426 + di_write_lock_parent(a->parent);
20428 + err = au_pin(&a->pin, dentry, a->bdst,
20430 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20431 + if (unlikely(err))
20435 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20437 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20438 + delegated = NULL;
20439 + err = vfsub_link(h_src_dentry,
20440 + au_pinned_h_dir(&a->pin),
20441 + &a->h_path, &delegated);
20442 + if (unlikely(err == -EWOULDBLOCK)) {
20443 + pr_warn("cannot retry"
20444 + " for NFSv4 delegation"
20445 + " for an internal link\n");
20451 + if (unlikely(err))
20455 + a->h_path.dentry = wh_dentry;
20456 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20458 + if (unlikely(err))
20462 + au_dir_ts(dir, a->bdst);
20463 + inode_inc_iversion(dir);
20464 + inc_nlink(inode);
20465 + inode->i_ctime = dir->i_ctime;
20466 + d_instantiate(dentry, au_igrab(inode));
20467 + if (d_unhashed(a->h_path.dentry))
20468 + /* some filesystem calls d_drop() */
20470 + /* some filesystems consume an inode even hardlink */
20471 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20472 + goto out_unpin; /* success */
20475 + /* no delegation since it is just created */
20476 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20477 + /*delegated*/NULL, /*force*/0);
20478 + if (unlikely(rerr)) {
20479 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20482 + au_dtime_revert(&dt);
20484 + au_unpin(&a->pin);
20488 + di_write_unlock(a->parent);
20489 + dput(a->src_parent);
20491 + if (unlikely(err)) {
20492 + au_update_dbtop(dentry);
20495 + aufs_read_and_write_unlock2(dentry, src_dentry);
20503 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20506 + aufs_bindex_t bindex;
20507 + unsigned char diropq;
20508 + struct path h_path;
20509 + struct dentry *wh_dentry, *parent, *opq_dentry;
20510 + struct inode *h_inode;
20511 + struct super_block *sb;
20513 + struct au_pin pin;
20514 + struct au_dtime dt;
20515 + } *a; /* reduce the stack usage */
20516 + struct au_wr_dir_args wr_dir_args = {
20517 + .force_btgt = -1,
20518 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20524 + a = kmalloc(sizeof(*a), GFP_NOFS);
20525 + if (unlikely(!a))
20528 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20529 + if (unlikely(err))
20531 + err = au_d_may_add(dentry);
20532 + if (unlikely(err))
20535 + parent = dentry->d_parent; /* dir inode is locked */
20536 + di_write_lock_parent(parent);
20537 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20538 + &a->pin, &wr_dir_args);
20539 + err = PTR_ERR(wh_dentry);
20540 + if (IS_ERR(wh_dentry))
20543 + sb = dentry->d_sb;
20544 + bindex = au_dbtop(dentry);
20545 + h_path.dentry = au_h_dptr(dentry, bindex);
20546 + h_path.mnt = au_sbr_mnt(sb, bindex);
20547 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20548 + if (unlikely(err))
20551 + /* make the dir opaque */
20553 + h_inode = d_inode(h_path.dentry);
20555 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20556 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20557 + opq_dentry = au_diropq_create(dentry, bindex);
20558 + inode_unlock(h_inode);
20559 + err = PTR_ERR(opq_dentry);
20560 + if (IS_ERR(opq_dentry))
20562 + dput(opq_dentry);
20566 + err = epilog(dir, bindex, wh_dentry, dentry);
20569 + goto out_unpin; /* success */
20574 + AuLabel(revert opq);
20575 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20576 + rerr = au_diropq_remove(dentry, bindex);
20577 + inode_unlock(h_inode);
20579 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20580 + dentry, err, rerr);
20586 + AuLabel(revert dir);
20587 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20589 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20590 + dentry, err, rerr);
20593 + au_dtime_revert(&a->dt);
20595 + au_unpin(&a->pin);
20598 + di_write_unlock(parent);
20600 + if (unlikely(err)) {
20601 + au_update_dbtop(dentry);
20604 + aufs_read_unlock(dentry, AuLock_DW);
20610 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20611 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20612 +++ linux/fs/aufs/i_op.c 2018-07-19 09:46:13.059981241 +0200
20614 +/* SPDX-License-Identifier: GPL-2.0 */
20616 + * Copyright (C) 2005-2018 Junjiro R. Okajima
20618 + * This program, aufs is free software; you can redistribute it and/or modify
20619 + * it under the terms of the GNU General Public License as published by
20620 + * the Free Software Foundation; either version 2 of the License, or
20621 + * (at your option) any later version.
20623 + * This program is distributed in the hope that it will be useful,
20624 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20625 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20626 + * GNU General Public License for more details.
20628 + * You should have received a copy of the GNU General Public License
20629 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20633 + * inode operations (except add/del/rename)
20636 +#include <linux/device_cgroup.h>
20637 +#include <linux/fs_stack.h>
20638 +#include <linux/namei.h>
20639 +#include <linux/security.h>
20642 +static int h_permission(struct inode *h_inode, int mask,
20643 + struct path *h_path, int brperm)
20646 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20649 + if (write_mask && IS_IMMUTABLE(h_inode))
20653 + if (((mask & MAY_EXEC)
20654 + && S_ISREG(h_inode->i_mode)
20655 + && (path_noexec(h_path)
20656 + || !(h_inode->i_mode & S_IXUGO))))
20660 + * - skip the lower fs test in the case of write to ro branch.
20661 + * - nfs dir permission write check is optimized, but a policy for
20662 + * link/rename requires a real check.
20663 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20664 + * in this case, generic_permission() returns -EOPNOTSUPP.
20666 + if ((write_mask && !au_br_writable(brperm))
20667 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20668 + && write_mask && !(mask & MAY_READ))
20669 + || !h_inode->i_op->permission) {
20670 + /* AuLabel(generic_permission); */
20671 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20672 + err = generic_permission(h_inode, mask);
20673 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20674 + err = h_inode->i_op->permission(h_inode, mask);
20677 + /* AuLabel(h_inode->permission); */
20678 + err = h_inode->i_op->permission(h_inode, mask);
20683 + err = devcgroup_inode_permission(h_inode, mask);
20685 + err = security_inode_permission(h_inode, mask);
20689 + /* todo: do we need to call ima_path_check()? */
20690 + struct path h_path = {
20694 + err = ima_path_check(&h_path,
20695 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20696 + IMA_COUNT_LEAVE);
20704 +static int aufs_permission(struct inode *inode, int mask)
20707 + aufs_bindex_t bindex, bbot;
20708 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20709 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20710 + struct inode *h_inode;
20711 + struct super_block *sb;
20712 + struct au_branch *br;
20714 + /* todo: support rcu-walk? */
20715 + if (mask & MAY_NOT_BLOCK)
20718 + sb = inode->i_sb;
20719 + si_read_lock(sb, AuLock_FLUSH);
20720 + ii_read_lock_child(inode);
20722 + err = au_iigen_test(inode, au_sigen(sb));
20723 + if (unlikely(err))
20729 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20730 + err = au_busy_or_stale();
20731 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20732 + if (unlikely(!h_inode
20733 + || (h_inode->i_mode & S_IFMT)
20734 + != (inode->i_mode & S_IFMT)))
20738 + bindex = au_ibtop(inode);
20739 + br = au_sbr(sb, bindex);
20740 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20743 + && !special_file(h_inode->i_mode)) {
20744 + /* test whether the upper writable branch exists */
20746 + for (; bindex >= 0; bindex--)
20747 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20755 + /* non-write to dir */
20757 + bbot = au_ibbot(inode);
20758 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20759 + h_inode = au_h_iptr(inode, bindex);
20761 + err = au_busy_or_stale();
20762 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20765 + br = au_sbr(sb, bindex);
20766 + err = h_permission(h_inode, mask, &br->br_path,
20772 + ii_read_unlock(inode);
20773 + si_read_unlock(sb);
20777 +/* ---------------------------------------------------------------------- */
20779 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20780 + unsigned int flags)
20782 + struct dentry *ret, *parent;
20783 + struct inode *inode;
20784 + struct super_block *sb;
20785 + int err, npositive;
20789 + /* todo: support rcu-walk? */
20790 + ret = ERR_PTR(-ECHILD);
20791 + if (flags & LOOKUP_RCU)
20794 + ret = ERR_PTR(-ENAMETOOLONG);
20795 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20799 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20800 + ret = ERR_PTR(err);
20801 + if (unlikely(err))
20804 + err = au_di_init(dentry);
20805 + ret = ERR_PTR(err);
20806 + if (unlikely(err))
20810 + npositive = 0; /* suppress a warning */
20811 + parent = dentry->d_parent; /* dir inode is locked */
20812 + di_read_lock_parent(parent, AuLock_IR);
20813 + err = au_alive_dir(parent);
20815 + err = au_digen_test(parent, au_sigen(sb));
20817 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20818 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20819 + AuLkup_ALLOW_NEG);
20822 + di_read_unlock(parent, AuLock_IR);
20823 + ret = ERR_PTR(err);
20824 + if (unlikely(err < 0))
20828 + inode = au_new_inode(dentry, /*must_new*/0);
20829 + if (IS_ERR(inode)) {
20830 + ret = (void *)inode;
20837 + atomic_inc(&inode->i_count);
20838 + ret = d_splice_alias(inode, dentry);
20840 + if (unlikely(d_need_lookup(dentry))) {
20841 + spin_lock(&dentry->d_lock);
20842 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20843 + spin_unlock(&dentry->d_lock);
20847 + if (!IS_ERR(ret)) {
20849 + if (ret && ret != dentry)
20850 + ii_write_unlock(inode);
20852 + ii_write_unlock(inode);
20859 + di_write_unlock(dentry);
20861 + si_read_unlock(sb);
20866 +/* ---------------------------------------------------------------------- */
20868 +struct aopen_node {
20869 + struct hlist_bl_node hblist;
20870 + struct file *file, *h_file;
20873 +static int au_do_aopen(struct inode *inode, struct file *file)
20875 + struct hlist_bl_head *aopen;
20876 + struct hlist_bl_node *pos;
20877 + struct aopen_node *node;
20878 + struct au_do_open_args args = {
20880 + .open = au_do_open_nondir
20883 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20884 + hlist_bl_lock(aopen);
20885 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20886 + if (node->file == file) {
20887 + args.h_file = node->h_file;
20890 + hlist_bl_unlock(aopen);
20891 + /* AuDebugOn(!args.h_file); */
20893 + return au_do_open(file, &args);
20896 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20897 + struct file *file, unsigned int open_flag,
20898 + umode_t create_mode, int *opened)
20900 + int err, unlocked, h_opened = *opened;
20901 + unsigned int lkup_flags;
20902 + struct dentry *parent, *d;
20903 + struct hlist_bl_head *aopen;
20904 + struct vfsub_aopen_args args = {
20905 + .open_flag = open_flag,
20906 + .create_mode = create_mode,
20907 + .opened = &h_opened
20909 + struct aopen_node aopen_node = {
20914 + AuDbg("open_flag 0%o\n", open_flag);
20915 + AuDbgDentry(dentry);
20918 + if (!au_di(dentry)) {
20919 + lkup_flags = LOOKUP_OPEN;
20920 + if (open_flag & O_CREAT)
20921 + lkup_flags |= LOOKUP_CREATE;
20922 + d = aufs_lookup(dir, dentry, lkup_flags);
20924 + err = PTR_ERR(d);
20929 + * obsoleted dentry found.
20930 + * another error will be returned later.
20936 + AuDbgDentry(dentry);
20939 + if (d_is_positive(dentry)
20940 + || d_unhashed(dentry)
20941 + || d_unlinked(dentry)
20942 + || !(open_flag & O_CREAT))
20943 + goto out_no_open;
20946 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20947 + if (unlikely(err))
20950 + parent = dentry->d_parent; /* dir is locked */
20951 + di_write_lock_parent(parent);
20952 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20953 + if (unlikely(err))
20956 + AuDbgDentry(dentry);
20957 + if (d_is_positive(dentry))
20960 + args.file = get_empty_filp();
20961 + err = PTR_ERR(args.file);
20962 + if (IS_ERR(args.file))
20965 + args.file->f_flags = file->f_flags;
20966 + err = au_aopen_or_create(dir, dentry, &args);
20968 + AuDbgFile(args.file);
20969 + if (unlikely(err < 0)) {
20970 + if (h_opened & FILE_OPENED)
20973 + put_filp(args.file);
20976 + di_write_unlock(parent);
20977 + di_write_unlock(dentry);
20980 + /* some filesystems don't set FILE_CREATED while succeeded? */
20981 + *opened |= FILE_CREATED;
20982 + if (h_opened & FILE_OPENED)
20983 + aopen_node.h_file = args.file;
20985 + put_filp(args.file);
20986 + args.file = NULL;
20988 + aopen = &au_sbi(dir->i_sb)->si_aopen;
20989 + au_hbl_add(&aopen_node.hblist, aopen);
20990 + err = finish_open(file, dentry, au_do_aopen, opened);
20991 + au_hbl_del(&aopen_node.hblist, aopen);
20994 + if (aopen_node.h_file)
20995 + fput(aopen_node.h_file);
20999 + si_read_unlock(dentry->d_sb);
21001 + di_write_unlock(parent);
21002 + aufs_read_unlock(dentry, AuLock_DW);
21004 + AuDbgDentry(dentry);
21005 + if (unlikely(err < 0))
21008 + if (err >= 0 && !(*opened & FILE_CREATED)) {
21009 + AuLabel(out_no_open);
21011 + err = finish_no_open(file, dentry);
21014 + AuDbg("%pd%s%s\n", dentry,
21015 + (*opened & FILE_CREATED) ? " created" : "",
21016 + (*opened & FILE_OPENED) ? " opened" : "");
21022 +/* ---------------------------------------------------------------------- */
21024 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21025 + const unsigned char add_entry, aufs_bindex_t bcpup,
21026 + aufs_bindex_t btop)
21029 + struct dentry *h_parent;
21030 + struct inode *h_dir;
21033 + IMustLock(d_inode(parent));
21035 + di_write_lock_parent(parent);
21038 + if (!au_h_dptr(parent, bcpup)) {
21039 + if (btop > bcpup)
21040 + err = au_cpup_dirs(dentry, bcpup);
21041 + else if (btop < bcpup)
21042 + err = au_cpdown_dirs(dentry, bcpup);
21046 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21047 + h_parent = au_h_dptr(parent, bcpup);
21048 + h_dir = d_inode(h_parent);
21049 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21050 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21051 + /* todo: no unlock here */
21052 + inode_unlock_shared(h_dir);
21054 + AuDbg("bcpup %d\n", bcpup);
21056 + if (d_really_is_negative(dentry))
21057 + au_set_h_dptr(dentry, btop, NULL);
21058 + au_update_dbrange(dentry, /*do_put_zero*/0);
21063 + di_write_unlock(parent);
21065 + err = bcpup; /* success */
21072 + * decide the branch and the parent dir where we will create a new entry.
21073 + * returns new bindex or an error.
21074 + * copyup the parent dir if needed.
21076 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21077 + struct au_wr_dir_args *args)
21080 + unsigned int flags;
21081 + aufs_bindex_t bcpup, btop, src_btop;
21082 + const unsigned char add_entry
21083 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21084 + | au_ftest_wrdir(args->flags, TMPFILE);
21085 + struct super_block *sb;
21086 + struct dentry *parent;
21087 + struct au_sbinfo *sbinfo;
21089 + sb = dentry->d_sb;
21090 + sbinfo = au_sbi(sb);
21091 + parent = dget_parent(dentry);
21092 + btop = au_dbtop(dentry);
21094 + if (args->force_btgt < 0) {
21095 + if (src_dentry) {
21096 + src_btop = au_dbtop(src_dentry);
21097 + if (src_btop < btop)
21098 + bcpup = src_btop;
21099 + } else if (add_entry) {
21101 + if (au_ftest_wrdir(args->flags, ISDIR))
21102 + au_fset_wbr(flags, DIR);
21103 + err = AuWbrCreate(sbinfo, dentry, flags);
21107 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21109 + err = AuWbrCopyup(sbinfo, dentry);
21111 + if (!IS_ROOT(dentry)) {
21112 + di_read_lock_parent(parent, !AuLock_IR);
21113 + err = AuWbrCopyup(sbinfo, dentry);
21114 + di_read_unlock(parent, !AuLock_IR);
21116 + err = AuWbrCopyup(sbinfo, dentry);
21119 + if (unlikely(err < 0))
21123 + bcpup = args->force_btgt;
21124 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21127 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21129 + if (bcpup == btop)
21130 + goto out; /* success */
21132 + /* copyup the new parent into the branch we process */
21133 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21135 + if (d_really_is_negative(dentry)) {
21136 + au_set_h_dptr(dentry, btop, NULL);
21137 + au_set_dbtop(dentry, bcpup);
21138 + au_set_dbbot(dentry, bcpup);
21140 + AuDebugOn(add_entry
21141 + && !au_ftest_wrdir(args->flags, TMPFILE)
21142 + && !au_h_dptr(dentry, bcpup));
21150 +/* ---------------------------------------------------------------------- */
21152 +void au_pin_hdir_unlock(struct au_pin *p)
21155 + au_hn_inode_unlock(p->hdir);
21158 +int au_pin_hdir_lock(struct au_pin *p)
21166 + /* even if an error happens later, keep this lock */
21167 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21170 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21175 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21176 + p->h_parent, p->br);
21182 +int au_pin_hdir_relock(struct au_pin *p)
21185 + struct inode *h_i;
21186 + struct dentry *h_d[] = {
21191 + err = au_pin_hdir_lock(p);
21192 + if (unlikely(err))
21195 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21198 + if (d_is_positive(h_d[i])) {
21199 + h_i = d_inode(h_d[i]);
21200 + err = !h_i->i_nlink;
21208 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21210 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21211 + p->hdir->hi_inode->i_rwsem.owner = task;
21215 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21218 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21219 + p->lsc_hi, 0, NULL, _RET_IP_);
21220 + au_pin_hdir_set_owner(p, current);
21224 +void au_pin_hdir_release(struct au_pin *p)
21227 + au_pin_hdir_set_owner(p, p->task);
21228 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21232 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21234 + if (pin && pin->parent)
21235 + return au_h_dptr(pin->parent, pin->bindex);
21239 +void au_unpin(struct au_pin *p)
21242 + au_pin_hdir_unlock(p);
21243 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21244 + vfsub_mnt_drop_write(p->h_mnt);
21248 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21249 + di_read_unlock(p->parent, AuLock_IR);
21250 + iput(p->hdir->hi_inode);
21252 + p->parent = NULL;
21255 + /* do not clear p->task */
21258 +int au_do_pin(struct au_pin *p)
21261 + struct super_block *sb;
21262 + struct inode *h_dir;
21265 + sb = p->dentry->d_sb;
21266 + p->br = au_sbr(sb, p->bindex);
21267 + if (IS_ROOT(p->dentry)) {
21268 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21269 + p->h_mnt = au_br_mnt(p->br);
21270 + err = vfsub_mnt_want_write(p->h_mnt);
21271 + if (unlikely(err)) {
21272 + au_fclr_pin(p->flags, MNT_WRITE);
21279 + p->h_dentry = NULL;
21280 + if (p->bindex <= au_dbbot(p->dentry))
21281 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21283 + p->parent = dget_parent(p->dentry);
21284 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21285 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21288 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21289 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21291 + h_dir = p->hdir->hi_inode;
21295 + * if DI_LOCKED is not set, then p->parent may be different
21296 + * and h_parent can be NULL.
21298 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21300 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21301 + di_read_unlock(p->parent, AuLock_IR);
21303 + p->parent = NULL;
21307 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21308 + p->h_mnt = au_br_mnt(p->br);
21309 + err = vfsub_mnt_want_write(p->h_mnt);
21310 + if (unlikely(err)) {
21311 + au_fclr_pin(p->flags, MNT_WRITE);
21312 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21313 + di_read_unlock(p->parent, AuLock_IR);
21315 + p->parent = NULL;
21321 + err = au_pin_hdir_lock(p);
21323 + goto out; /* success */
21328 + pr_err("err %d\n", err);
21329 + err = au_busy_or_stale();
21334 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21335 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21336 + unsigned int udba, unsigned char flags)
21338 + p->dentry = dentry;
21340 + p->lsc_di = lsc_di;
21341 + p->lsc_hi = lsc_hi;
21342 + p->flags = flags;
21343 + p->bindex = bindex;
21345 + p->parent = NULL;
21349 + p->h_dentry = NULL;
21350 + p->h_parent = NULL;
21352 + p->task = current;
21355 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21356 + unsigned int udba, unsigned char flags)
21358 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21360 + return au_do_pin(pin);
21363 +/* ---------------------------------------------------------------------- */
21366 + * ->setattr() and ->getattr() are called in various cases.
21367 + * chmod, stat: dentry is revalidated.
21368 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21370 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21372 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21373 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21376 + struct dentry *parent;
21379 + if (au_digen_test(dentry, sigen)) {
21380 + parent = dget_parent(dentry);
21381 + di_read_lock_parent(parent, AuLock_IR);
21382 + err = au_refresh_dentry(dentry, parent);
21383 + di_read_unlock(parent, AuLock_IR);
21391 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21392 + struct au_icpup_args *a)
21396 + aufs_bindex_t btop, ibtop;
21397 + struct dentry *hi_wh, *parent;
21398 + struct inode *inode;
21399 + struct au_wr_dir_args wr_dir_args = {
21400 + .force_btgt = -1,
21404 + if (d_is_dir(dentry))
21405 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21406 + /* plink or hi_wh() case */
21407 + btop = au_dbtop(dentry);
21408 + inode = d_inode(dentry);
21409 + ibtop = au_ibtop(inode);
21410 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21411 + wr_dir_args.force_btgt = ibtop;
21412 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21413 + if (unlikely(err < 0))
21417 + au_fset_icpup(a->flags, DID_CPUP);
21420 + a->pin_flags = AuPin_MNT_WRITE;
21422 + if (!IS_ROOT(dentry)) {
21423 + au_fset_pin(a->pin_flags, DI_LOCKED);
21424 + parent = dget_parent(dentry);
21425 + di_write_lock_parent(parent);
21428 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21429 + if (unlikely(err))
21433 + a->h_path.dentry = au_h_dptr(dentry, btop);
21434 + a->h_inode = d_inode(a->h_path.dentry);
21435 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21436 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21437 + if (ia->ia_size < i_size_read(a->h_inode))
21438 + sz = ia->ia_size;
21439 + inode_unlock_shared(a->h_inode);
21443 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21444 + hi_wh = au_hi_wh(inode, a->btgt);
21446 + struct au_cp_generic cpg = {
21447 + .dentry = dentry,
21453 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21454 + if (unlikely(err))
21456 + hi_wh = au_hi_wh(inode, a->btgt);
21457 + /* todo: revalidate hi_wh? */
21462 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21463 + di_downgrade_lock(parent, AuLock_IR);
21467 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21468 + goto out; /* success */
21470 + if (!d_unhashed(dentry)) {
21471 + struct au_cp_generic cpg = {
21472 + .dentry = dentry,
21477 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21479 + err = au_sio_cpup_simple(&cpg);
21481 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21482 + } else if (!hi_wh)
21483 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21485 + a->h_path.dentry = hi_wh; /* do not dget here */
21488 + a->h_inode = d_inode(a->h_path.dentry);
21490 + goto out; /* success */
21491 + au_unpin(&a->pin);
21494 + di_write_unlock(parent);
21499 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21503 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21506 + struct inode *inode, *delegated;
21507 + struct super_block *sb;
21508 + struct file *file;
21509 + struct au_icpup_args *a;
21511 + inode = d_inode(dentry);
21512 + IMustLock(inode);
21514 + err = setattr_prepare(dentry, ia);
21515 + if (unlikely(err))
21519 + a = kzalloc(sizeof(*a), GFP_NOFS);
21520 + if (unlikely(!a))
21523 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21524 + ia->ia_valid &= ~ATTR_MODE;
21527 + sb = dentry->d_sb;
21528 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21529 + if (unlikely(err))
21532 + if (ia->ia_valid & ATTR_FILE) {
21533 + /* currently ftruncate(2) only */
21534 + AuDebugOn(!d_is_reg(dentry));
21535 + file = ia->ia_file;
21536 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21538 + if (unlikely(err))
21540 + ia->ia_file = au_hf_top(file);
21541 + a->udba = AuOpt_UDBA_NONE;
21543 + /* fchmod() doesn't pass ia_file */
21544 + a->udba = au_opt_udba(sb);
21545 + di_write_lock_child(dentry);
21546 + /* no d_unlinked(), to set UDBA_NONE for root */
21547 + if (d_unhashed(dentry))
21548 + a->udba = AuOpt_UDBA_NONE;
21549 + if (a->udba != AuOpt_UDBA_NONE) {
21550 + AuDebugOn(IS_ROOT(dentry));
21551 + err = au_reval_for_attr(dentry, au_sigen(sb));
21552 + if (unlikely(err))
21557 + err = au_pin_and_icpup(dentry, ia, a);
21558 + if (unlikely(err < 0))
21560 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21561 + ia->ia_file = NULL;
21562 + ia->ia_valid &= ~ATTR_FILE;
21565 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21566 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21567 + == (ATTR_MODE | ATTR_CTIME)) {
21568 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21569 + if (unlikely(err))
21571 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21572 + && (ia->ia_valid & ATTR_CTIME)) {
21573 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21574 + if (unlikely(err))
21578 + if (ia->ia_valid & ATTR_SIZE) {
21581 + if (ia->ia_size < i_size_read(inode))
21583 + truncate_setsize(inode, ia->ia_size);
21586 + if (ia->ia_valid & ATTR_FILE)
21588 + inode_unlock(a->h_inode);
21589 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21590 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21592 + delegated = NULL;
21594 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21596 + err = break_deleg_wait(&delegated);
21604 + * regardless aufs 'acl' option setting.
21605 + * why don't all acl-aware fs call this func from their ->setattr()?
21607 + if (!err && (ia->ia_valid & ATTR_MODE))
21608 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21610 + au_cpup_attr_changeable(inode);
21613 + inode_unlock(a->h_inode);
21614 + au_unpin(&a->pin);
21615 + if (unlikely(err))
21616 + au_update_dbtop(dentry);
21618 + di_write_unlock(dentry);
21620 + fi_write_unlock(file);
21621 + ia->ia_file = file;
21622 + ia->ia_valid |= ATTR_FILE;
21625 + si_read_unlock(sb);
21633 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21634 +static int au_h_path_to_set_attr(struct dentry *dentry,
21635 + struct au_icpup_args *a, struct path *h_path)
21638 + struct super_block *sb;
21640 + sb = dentry->d_sb;
21641 + a->udba = au_opt_udba(sb);
21642 + /* no d_unlinked(), to set UDBA_NONE for root */
21643 + if (d_unhashed(dentry))
21644 + a->udba = AuOpt_UDBA_NONE;
21645 + if (a->udba != AuOpt_UDBA_NONE) {
21646 + AuDebugOn(IS_ROOT(dentry));
21647 + err = au_reval_for_attr(dentry, au_sigen(sb));
21648 + if (unlikely(err))
21651 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21652 + if (unlikely(err < 0))
21655 + h_path->dentry = a->h_path.dentry;
21656 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21662 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21663 + struct au_sxattr *arg)
21666 + struct path h_path;
21667 + struct super_block *sb;
21668 + struct au_icpup_args *a;
21669 + struct inode *h_inode;
21671 + IMustLock(inode);
21674 + a = kzalloc(sizeof(*a), GFP_NOFS);
21675 + if (unlikely(!a))
21678 + sb = dentry->d_sb;
21679 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21680 + if (unlikely(err))
21683 + h_path.dentry = NULL; /* silence gcc */
21684 + di_write_lock_child(dentry);
21685 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21686 + if (unlikely(err))
21689 + inode_unlock(a->h_inode);
21690 + switch (arg->type) {
21691 + case AU_XATTR_SET:
21692 + AuDebugOn(d_is_negative(h_path.dentry));
21693 + err = vfsub_setxattr(h_path.dentry,
21694 + arg->u.set.name, arg->u.set.value,
21695 + arg->u.set.size, arg->u.set.flags);
21698 + err = -EOPNOTSUPP;
21699 + h_inode = d_inode(h_path.dentry);
21700 + if (h_inode->i_op->set_acl)
21701 + /* this will call posix_acl_update_mode */
21702 + err = h_inode->i_op->set_acl(h_inode,
21703 + arg->u.acl_set.acl,
21704 + arg->u.acl_set.type);
21708 + au_cpup_attr_timesizes(inode);
21710 + au_unpin(&a->pin);
21711 + if (unlikely(err))
21712 + au_update_dbtop(dentry);
21715 + di_write_unlock(dentry);
21716 + si_read_unlock(sb);
21725 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21726 + unsigned int nlink)
21730 + inode->i_mode = st->mode;
21731 + /* don't i_[ug]id_write() here */
21732 + inode->i_uid = st->uid;
21733 + inode->i_gid = st->gid;
21734 + inode->i_atime = st->atime;
21735 + inode->i_mtime = st->mtime;
21736 + inode->i_ctime = st->ctime;
21738 + au_cpup_attr_nlink(inode, /*force*/0);
21739 + if (S_ISDIR(inode->i_mode)) {
21740 + n = inode->i_nlink;
21743 + smp_mb(); /* for i_nlink */
21744 + /* 0 can happen */
21745 + set_nlink(inode, n);
21748 + spin_lock(&inode->i_lock);
21749 + inode->i_blocks = st->blocks;
21750 + i_size_write(inode, st->size);
21751 + spin_unlock(&inode->i_lock);
21755 + * common routine for aufs_getattr() and au_getxattr().
21756 + * returns zero or negative (an error).
21757 + * @dentry will be read-locked in success.
21759 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21763 + unsigned int mnt_flags, sigen;
21764 + unsigned char udba_none;
21765 + aufs_bindex_t bindex;
21766 + struct super_block *sb, *h_sb;
21767 + struct inode *inode;
21769 + h_path->mnt = NULL;
21770 + h_path->dentry = NULL;
21773 + sb = dentry->d_sb;
21774 + mnt_flags = au_mntflags(sb);
21775 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21777 + if (unlikely(locked))
21778 + goto body; /* skip locking dinfo */
21780 + /* support fstat(2) */
21781 + if (!d_unlinked(dentry) && !udba_none) {
21782 + sigen = au_sigen(sb);
21783 + err = au_digen_test(dentry, sigen);
21785 + di_read_lock_child(dentry, AuLock_IR);
21786 + err = au_dbrange_test(dentry);
21787 + if (unlikely(err)) {
21788 + di_read_unlock(dentry, AuLock_IR);
21792 + AuDebugOn(IS_ROOT(dentry));
21793 + di_write_lock_child(dentry);
21794 + err = au_dbrange_test(dentry);
21796 + err = au_reval_for_attr(dentry, sigen);
21798 + di_downgrade_lock(dentry, AuLock_IR);
21800 + di_write_unlock(dentry);
21805 + di_read_lock_child(dentry, AuLock_IR);
21808 + inode = d_inode(dentry);
21809 + bindex = au_ibtop(inode);
21810 + h_path->mnt = au_sbr_mnt(sb, bindex);
21811 + h_sb = h_path->mnt->mnt_sb;
21813 + && !au_test_fs_bad_iattr(h_sb)
21815 + goto out; /* success */
21817 + if (au_dbtop(dentry) == bindex)
21818 + h_path->dentry = au_h_dptr(dentry, bindex);
21819 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21820 + h_path->dentry = au_plink_lkup(inode, bindex);
21821 + if (IS_ERR(h_path->dentry))
21822 + /* pretending success */
21823 + h_path->dentry = NULL;
21825 + dput(h_path->dentry);
21832 +static int aufs_getattr(const struct path *path, struct kstat *st,
21833 + u32 request, unsigned int query)
21836 + unsigned char positive;
21837 + struct path h_path;
21838 + struct dentry *dentry;
21839 + struct inode *inode;
21840 + struct super_block *sb;
21842 + dentry = path->dentry;
21843 + inode = d_inode(dentry);
21844 + sb = dentry->d_sb;
21845 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21846 + if (unlikely(err))
21848 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21849 + if (unlikely(err))
21851 + if (unlikely(!h_path.dentry))
21852 + /* illegally overlapped or something */
21853 + goto out_fill; /* pretending success */
21855 + positive = d_is_positive(h_path.dentry);
21857 + /* no vfsub version */
21858 + err = vfs_getattr(&h_path, st, request, query);
21861 + au_refresh_iattr(inode, st,
21862 + d_inode(h_path.dentry)->i_nlink);
21863 + goto out_fill; /* success */
21869 + generic_fillattr(inode, st);
21871 + di_read_unlock(dentry, AuLock_IR);
21873 + si_read_unlock(sb);
21879 +/* ---------------------------------------------------------------------- */
21881 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21882 + struct delayed_call *done)
21885 + struct dentry *h_dentry;
21886 + struct inode *h_inode;
21888 + aufs_bindex_t bindex;
21890 + ret = NULL; /* suppress a warning */
21895 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21896 + if (unlikely(err))
21899 + err = au_d_hashed_positive(dentry);
21900 + if (unlikely(err))
21904 + inode = d_inode(dentry);
21905 + bindex = au_ibtop(inode);
21906 + h_inode = au_h_iptr(inode, bindex);
21907 + if (unlikely(!h_inode->i_op->get_link))
21912 + if (au_dbtop(dentry) <= bindex) {
21913 + h_dentry = au_h_dptr(dentry, bindex);
21918 + h_dentry = d_find_any_alias(h_inode);
21919 + if (IS_ERR(h_dentry)) {
21920 + err = PTR_ERR(h_dentry);
21924 + if (unlikely(!h_dentry))
21928 + AuDbg("%ps\n", h_inode->i_op->get_link);
21929 + AuDbgDentry(h_dentry);
21930 + ret = vfs_get_link(h_dentry, done);
21933 + err = PTR_ERR(ret);
21936 + aufs_read_unlock(dentry, AuLock_IR);
21938 + if (unlikely(err))
21939 + ret = ERR_PTR(err);
21940 + AuTraceErrPtr(ret);
21944 +/* ---------------------------------------------------------------------- */
21946 +static int au_is_special(struct inode *inode)
21948 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21951 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
21954 + aufs_bindex_t bindex;
21955 + struct super_block *sb;
21956 + struct inode *h_inode;
21957 + struct vfsmount *h_mnt;
21959 + sb = inode->i_sb;
21960 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21961 + "unexpected s_flags 0x%lx", sb->s_flags);
21963 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21965 + si_read_lock(sb, AuLock_FLUSH);
21966 + ii_write_lock_child(inode);
21969 + bindex = au_ibtop(inode);
21970 + h_inode = au_h_iptr(inode, bindex);
21971 + if (!au_test_ro(sb, bindex, inode)) {
21972 + h_mnt = au_sbr_mnt(sb, bindex);
21973 + err = vfsub_mnt_want_write(h_mnt);
21975 + err = vfsub_update_time(h_inode, ts, flags);
21976 + vfsub_mnt_drop_write(h_mnt);
21978 + } else if (au_is_special(h_inode)) {
21980 + * Never copy-up here.
21981 + * These special files may already be opened and used for
21982 + * communicating. If we copied it up, then the communication
21983 + * would be corrupted.
21985 + AuWarn1("timestamps for i%lu are ignored "
21986 + "since it is on readonly branch (hi%lu).\n",
21987 + inode->i_ino, h_inode->i_ino);
21988 + } else if (flags & ~S_ATIME) {
21990 + AuIOErr1("unexpected flags 0x%x\n", flags);
21995 + au_cpup_attr_timesizes(inode);
21996 + ii_write_unlock(inode);
21997 + si_read_unlock(sb);
22000 + if (!err && (flags & S_VERSION))
22001 + inode_inc_iversion(inode);
22006 +/* ---------------------------------------------------------------------- */
22008 +/* no getattr version will be set by module.c:aufs_init() */
22009 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22011 + [AuIop_SYMLINK] = {
22012 + .permission = aufs_permission,
22013 +#ifdef CONFIG_FS_POSIX_ACL
22014 + .get_acl = aufs_get_acl,
22015 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22018 + .setattr = aufs_setattr,
22019 + .getattr = aufs_getattr,
22021 +#ifdef CONFIG_AUFS_XATTR
22022 + .listxattr = aufs_listxattr,
22025 + .get_link = aufs_get_link,
22027 + /* .update_time = aufs_update_time */
22030 + .create = aufs_create,
22031 + .lookup = aufs_lookup,
22032 + .link = aufs_link,
22033 + .unlink = aufs_unlink,
22034 + .symlink = aufs_symlink,
22035 + .mkdir = aufs_mkdir,
22036 + .rmdir = aufs_rmdir,
22037 + .mknod = aufs_mknod,
22038 + .rename = aufs_rename,
22040 + .permission = aufs_permission,
22041 +#ifdef CONFIG_FS_POSIX_ACL
22042 + .get_acl = aufs_get_acl,
22043 + .set_acl = aufs_set_acl,
22046 + .setattr = aufs_setattr,
22047 + .getattr = aufs_getattr,
22049 +#ifdef CONFIG_AUFS_XATTR
22050 + .listxattr = aufs_listxattr,
22053 + .update_time = aufs_update_time,
22054 + .atomic_open = aufs_atomic_open,
22055 + .tmpfile = aufs_tmpfile
22057 + [AuIop_OTHER] = {
22058 + .permission = aufs_permission,
22059 +#ifdef CONFIG_FS_POSIX_ACL
22060 + .get_acl = aufs_get_acl,
22061 + .set_acl = aufs_set_acl,
22064 + .setattr = aufs_setattr,
22065 + .getattr = aufs_getattr,
22067 +#ifdef CONFIG_AUFS_XATTR
22068 + .listxattr = aufs_listxattr,
22071 + .update_time = aufs_update_time
22074 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22075 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22076 +++ linux/fs/aufs/i_op_del.c 2018-07-19 09:46:13.059981241 +0200
22078 +/* SPDX-License-Identifier: GPL-2.0 */
22080 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22082 + * This program, aufs is free software; you can redistribute it and/or modify
22083 + * it under the terms of the GNU General Public License as published by
22084 + * the Free Software Foundation; either version 2 of the License, or
22085 + * (at your option) any later version.
22087 + * This program is distributed in the hope that it will be useful,
22088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22090 + * GNU General Public License for more details.
22092 + * You should have received a copy of the GNU General Public License
22093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22097 + * inode operations (del entry)
22103 + * decide if a new whiteout for @dentry is necessary or not.
22104 + * when it is necessary, prepare the parent dir for the upper branch whose
22105 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22106 + * be done by caller.
22108 + * 0: wh is unnecessary
22109 + * plus: wh is necessary
22112 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22114 + int need_wh, err;
22115 + aufs_bindex_t btop;
22116 + struct super_block *sb;
22118 + sb = dentry->d_sb;
22119 + btop = au_dbtop(dentry);
22120 + if (*bcpup < 0) {
22122 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22123 + err = AuWbrCopyup(au_sbi(sb), dentry);
22125 + if (unlikely(err < 0))
22129 + AuDebugOn(btop < *bcpup
22130 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22131 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22133 + if (*bcpup != btop) {
22134 + err = au_cpup_dirs(dentry, *bcpup);
22135 + if (unlikely(err))
22139 + struct au_dinfo *dinfo, *tmp;
22141 + need_wh = -ENOMEM;
22142 + dinfo = au_di(dentry);
22143 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22145 + au_di_cp(tmp, dinfo);
22146 + au_di_swap(tmp, dinfo);
22147 + /* returns the number of positive dentries */
22148 + need_wh = au_lkup_dentry(dentry, btop + 1,
22149 + /* AuLkup_IGNORE_PERM */ 0);
22150 + au_di_swap(tmp, dinfo);
22151 + au_rw_write_unlock(&tmp->di_rwsem);
22155 + AuDbg("need_wh %d\n", need_wh);
22163 + * simple tests for the del-entry operations.
22164 + * following the checks in vfs, plus the parent-child relationship.
22166 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22167 + struct dentry *h_parent, int isdir)
22171 + struct dentry *h_dentry, *h_latest;
22172 + struct inode *h_inode;
22174 + h_dentry = au_h_dptr(dentry, bindex);
22175 + if (d_really_is_positive(dentry)) {
22177 + if (unlikely(d_is_negative(h_dentry)))
22179 + h_inode = d_inode(h_dentry);
22180 + if (unlikely(!h_inode->i_nlink))
22183 + h_mode = h_inode->i_mode;
22186 + if (unlikely(S_ISDIR(h_mode)))
22188 + } else if (unlikely(!S_ISDIR(h_mode))) {
22193 + /* rename(2) case */
22195 + if (unlikely(d_is_positive(h_dentry)))
22200 + /* expected parent dir is locked */
22201 + if (unlikely(h_parent != h_dentry->d_parent))
22206 + * rmdir a dir may break the consistency on some filesystem.
22207 + * let's try heavy test.
22210 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22211 + && au_test_h_perm(d_inode(h_parent),
22212 + MAY_EXEC | MAY_WRITE)))
22215 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22217 + if (IS_ERR(h_latest))
22219 + if (h_latest == h_dentry)
22228 + * decide the branch where we operate for @dentry. the branch index will be set
22229 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
22230 + * dir for reverting.
22231 + * when a new whiteout is necessary, create it.
22233 +static struct dentry*
22234 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22235 + struct au_dtime *dt, struct au_pin *pin)
22237 + struct dentry *wh_dentry;
22238 + struct super_block *sb;
22239 + struct path h_path;
22240 + int err, need_wh;
22241 + unsigned int udba;
22242 + aufs_bindex_t bcpup;
22244 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22245 + wh_dentry = ERR_PTR(need_wh);
22246 + if (unlikely(need_wh < 0))
22249 + sb = dentry->d_sb;
22250 + udba = au_opt_udba(sb);
22252 + err = au_pin(pin, dentry, bcpup, udba,
22253 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22254 + wh_dentry = ERR_PTR(err);
22255 + if (unlikely(err))
22258 + h_path.dentry = au_pinned_h_parent(pin);
22259 + if (udba != AuOpt_UDBA_NONE
22260 + && au_dbtop(dentry) == bcpup) {
22261 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22262 + wh_dentry = ERR_PTR(err);
22263 + if (unlikely(err))
22267 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22268 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22269 + wh_dentry = NULL;
22271 + goto out; /* success, no need to create whiteout */
22273 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22274 + if (IS_ERR(wh_dentry))
22277 + /* returns with the parent is locked and wh_dentry is dget-ed */
22278 + goto out; /* success */
22283 + return wh_dentry;
22287 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22288 + * in order to be revertible and save time for removing many child whiteouts
22290 + * returns 1 when there are too many child whiteout and caller should remove
22291 + * them asynchronously. returns 0 when the number of children is enough small to
22292 + * remove now or the branch fs is a remote fs.
22293 + * otherwise return an error.
22295 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22296 + struct au_nhash *whlist, struct inode *dir)
22298 + int rmdir_later, err, dirwh;
22299 + struct dentry *h_dentry;
22300 + struct super_block *sb;
22301 + struct inode *inode;
22303 + sb = dentry->d_sb;
22304 + SiMustAnyLock(sb);
22305 + h_dentry = au_h_dptr(dentry, bindex);
22306 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22307 + if (unlikely(err))
22310 + /* stop monitoring */
22311 + inode = d_inode(dentry);
22312 + au_hn_free(au_hi(inode, bindex));
22314 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22315 + dirwh = au_sbi(sb)->si_dirwh;
22316 + rmdir_later = (dirwh <= 1);
22317 + if (!rmdir_later)
22318 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22321 + return rmdir_later;
22324 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22325 + if (unlikely(err)) {
22326 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22327 + h_dentry, bindex, err);
22337 + * final procedure for deleting a entry.
22338 + * maintain dentry and iattr.
22340 +static void epilog(struct inode *dir, struct dentry *dentry,
22341 + aufs_bindex_t bindex)
22343 + struct inode *inode;
22345 + inode = d_inode(dentry);
22347 + inode->i_ctime = dir->i_ctime;
22349 + au_dir_ts(dir, bindex);
22350 + inode_inc_iversion(dir);
22354 + * when an error happened, remove the created whiteout and revert everything.
22356 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22357 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22358 + struct dentry *dentry, struct au_dtime *dt)
22361 + struct path h_path = {
22362 + .dentry = wh_dentry,
22363 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22366 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22368 + au_set_dbwh(dentry, bwh);
22369 + au_dtime_revert(dt);
22373 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22377 +/* ---------------------------------------------------------------------- */
22379 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22382 + aufs_bindex_t bwh, bindex, btop;
22383 + struct inode *inode, *h_dir, *delegated;
22384 + struct dentry *parent, *wh_dentry;
22385 + /* to reuduce stack size */
22387 + struct au_dtime dt;
22388 + struct au_pin pin;
22389 + struct path h_path;
22395 + a = kmalloc(sizeof(*a), GFP_NOFS);
22396 + if (unlikely(!a))
22399 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22400 + if (unlikely(err))
22402 + err = au_d_hashed_positive(dentry);
22403 + if (unlikely(err))
22405 + inode = d_inode(dentry);
22406 + IMustLock(inode);
22408 + if (unlikely(d_is_dir(dentry)))
22409 + goto out_unlock; /* possible? */
22411 + btop = au_dbtop(dentry);
22412 + bwh = au_dbwh(dentry);
22414 + parent = dentry->d_parent; /* dir inode is locked */
22415 + di_write_lock_parent(parent);
22416 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22418 + err = PTR_ERR(wh_dentry);
22419 + if (IS_ERR(wh_dentry))
22422 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22423 + a->h_path.dentry = au_h_dptr(dentry, btop);
22424 + dget(a->h_path.dentry);
22425 + if (bindex == btop) {
22426 + h_dir = au_pinned_h_dir(&a->pin);
22427 + delegated = NULL;
22428 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22429 + if (unlikely(err == -EWOULDBLOCK)) {
22430 + pr_warn("cannot retry for NFSv4 delegation"
22431 + " for an internal unlink\n");
22435 + /* dir inode is locked */
22436 + h_dir = d_inode(wh_dentry->d_parent);
22437 + IMustLock(h_dir);
22442 + vfsub_drop_nlink(inode);
22443 + epilog(dir, dentry, bindex);
22445 + /* update target timestamps */
22446 + if (bindex == btop) {
22447 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22449 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22451 + /* todo: this timestamp may be reverted later */
22452 + inode->i_ctime = h_dir->i_ctime;
22453 + goto out_unpin; /* success */
22460 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22467 + au_unpin(&a->pin);
22469 + dput(a->h_path.dentry);
22471 + di_write_unlock(parent);
22473 + aufs_read_unlock(dentry, AuLock_DW);
22480 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22482 + int err, rmdir_later;
22483 + aufs_bindex_t bwh, bindex, btop;
22484 + struct inode *inode;
22485 + struct dentry *parent, *wh_dentry, *h_dentry;
22486 + struct au_whtmp_rmdir *args;
22487 + /* to reuduce stack size */
22489 + struct au_dtime dt;
22490 + struct au_pin pin;
22496 + a = kmalloc(sizeof(*a), GFP_NOFS);
22497 + if (unlikely(!a))
22500 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22501 + if (unlikely(err))
22503 + err = au_alive_dir(dentry);
22504 + if (unlikely(err))
22506 + inode = d_inode(dentry);
22507 + IMustLock(inode);
22509 + if (unlikely(!d_is_dir(dentry)))
22510 + goto out_unlock; /* possible? */
22513 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22514 + if (unlikely(!args))
22517 + parent = dentry->d_parent; /* dir inode is locked */
22518 + di_write_lock_parent(parent);
22519 + err = au_test_empty(dentry, &args->whlist);
22520 + if (unlikely(err))
22523 + btop = au_dbtop(dentry);
22524 + bwh = au_dbwh(dentry);
22526 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22528 + err = PTR_ERR(wh_dentry);
22529 + if (IS_ERR(wh_dentry))
22532 + h_dentry = au_h_dptr(dentry, btop);
22535 + if (bindex == btop) {
22536 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22538 + rmdir_later = err;
22542 + /* stop monitoring */
22543 + au_hn_free(au_hi(inode, btop));
22545 + /* dir inode is locked */
22546 + IMustLock(d_inode(wh_dentry->d_parent));
22551 + vfsub_dead_dir(inode);
22552 + au_set_dbdiropq(dentry, -1);
22553 + epilog(dir, dentry, bindex);
22555 + if (rmdir_later) {
22556 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22560 + goto out_unpin; /* success */
22568 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22575 + au_unpin(&a->pin);
22579 + di_write_unlock(parent);
22581 + au_whtmp_rmdir_free(args);
22583 + aufs_read_unlock(dentry, AuLock_DW);
22590 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22591 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22592 +++ linux/fs/aufs/i_op_ren.c 2018-07-19 09:46:13.059981241 +0200
22594 +/* SPDX-License-Identifier: GPL-2.0 */
22596 + * Copyright (C) 2005-2018 Junjiro R. Okajima
22598 + * This program, aufs is free software; you can redistribute it and/or modify
22599 + * it under the terms of the GNU General Public License as published by
22600 + * the Free Software Foundation; either version 2 of the License, or
22601 + * (at your option) any later version.
22603 + * This program is distributed in the hope that it will be useful,
22604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22606 + * GNU General Public License for more details.
22608 + * You should have received a copy of the GNU General Public License
22609 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22613 + * inode operation (rename entry)
22614 + * todo: this is crazy monster
22619 +enum { AuSRC, AuDST, AuSrcDst };
22620 +enum { AuPARENT, AuCHILD, AuParentChild };
22622 +#define AuRen_ISDIR_SRC 1
22623 +#define AuRen_ISDIR_DST (1 << 1)
22624 +#define AuRen_ISSAMEDIR (1 << 2)
22625 +#define AuRen_WHSRC (1 << 3)
22626 +#define AuRen_WHDST (1 << 4)
22627 +#define AuRen_MNT_WRITE (1 << 5)
22628 +#define AuRen_DT_DSTDIR (1 << 6)
22629 +#define AuRen_DIROPQ_SRC (1 << 7)
22630 +#define AuRen_DIROPQ_DST (1 << 8)
22631 +#define AuRen_DIRREN (1 << 9)
22632 +#define AuRen_DROPPED_SRC (1 << 10)
22633 +#define AuRen_DROPPED_DST (1 << 11)
22634 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22635 +#define au_fset_ren(flags, name) \
22636 + do { (flags) |= AuRen_##name; } while (0)
22637 +#define au_fclr_ren(flags, name) \
22638 + do { (flags) &= ~AuRen_##name; } while (0)
22640 +#ifndef CONFIG_AUFS_DIRREN
22641 +#undef AuRen_DIRREN
22642 +#define AuRen_DIRREN 0
22645 +struct au_ren_args {
22647 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22649 + struct inode *dir, *inode;
22650 + struct au_hinode *hdir, *hinode;
22651 + struct au_dtime dt[AuParentChild];
22652 + aufs_bindex_t btop, bdiropq;
22655 +#define src_dentry sd[AuSRC].dentry
22656 +#define src_dir sd[AuSRC].dir
22657 +#define src_inode sd[AuSRC].inode
22658 +#define src_h_dentry sd[AuSRC].h_dentry
22659 +#define src_parent sd[AuSRC].parent
22660 +#define src_h_parent sd[AuSRC].h_parent
22661 +#define src_wh_dentry sd[AuSRC].wh_dentry
22662 +#define src_hdir sd[AuSRC].hdir
22663 +#define src_hinode sd[AuSRC].hinode
22664 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22665 +#define src_dt sd[AuSRC].dt
22666 +#define src_btop sd[AuSRC].btop
22667 +#define src_bdiropq sd[AuSRC].bdiropq
22669 +#define dst_dentry sd[AuDST].dentry
22670 +#define dst_dir sd[AuDST].dir
22671 +#define dst_inode sd[AuDST].inode
22672 +#define dst_h_dentry sd[AuDST].h_dentry
22673 +#define dst_parent sd[AuDST].parent
22674 +#define dst_h_parent sd[AuDST].h_parent
22675 +#define dst_wh_dentry sd[AuDST].wh_dentry
22676 +#define dst_hdir sd[AuDST].hdir
22677 +#define dst_hinode sd[AuDST].hinode
22678 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22679 +#define dst_dt sd[AuDST].dt
22680 +#define dst_btop sd[AuDST].btop
22681 +#define dst_bdiropq sd[AuDST].bdiropq
22683 + struct dentry *h_trap;
22684 + struct au_branch *br;
22685 + struct path h_path;
22686 + struct au_nhash whlist;
22687 + aufs_bindex_t btgt, src_bwh;
22690 + unsigned short auren_flags;
22691 + unsigned char flags; /* syscall parameter */
22692 + unsigned char exchange;
22695 + struct au_whtmp_rmdir *thargs;
22696 + struct dentry *h_dst;
22697 + struct au_hinode *h_root;
22700 +/* ---------------------------------------------------------------------- */
22703 + * functions for reverting.
22704 + * when an error happened in a single rename systemcall, we should revert
22705 + * everything as if nothing happened.
22706 + * we don't need to revert the copied-up/down the parent dir since they are
22710 +#define RevertFailure(fmt, ...) do { \
22711 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22712 + ##__VA_ARGS__, err, rerr); \
22716 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22719 + struct dentry *d;
22720 +#define src_or_dst(member) a->sd[idx].member
22722 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22723 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22724 + rerr = au_diropq_remove(d, a->btgt);
22725 + au_hn_inode_unlock(src_or_dst(hinode));
22726 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22728 + RevertFailure("remove diropq %pd", d);
22730 +#undef src_or_dst_
22733 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22735 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22736 + au_ren_do_rev_diropq(err, a, AuSRC);
22737 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22738 + au_ren_do_rev_diropq(err, a, AuDST);
22741 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22744 + struct inode *delegated;
22746 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22747 + a->src_h_parent);
22748 + rerr = PTR_ERR(a->h_path.dentry);
22749 + if (IS_ERR(a->h_path.dentry)) {
22750 + RevertFailure("lkup one %pd", a->src_dentry);
22754 + delegated = NULL;
22755 + rerr = vfsub_rename(a->dst_h_dir,
22756 + au_h_dptr(a->src_dentry, a->btgt),
22757 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22758 + if (unlikely(rerr == -EWOULDBLOCK)) {
22759 + pr_warn("cannot retry for NFSv4 delegation"
22760 + " for an internal rename\n");
22763 + d_drop(a->h_path.dentry);
22764 + dput(a->h_path.dentry);
22765 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22767 + RevertFailure("rename %pd", a->src_dentry);
22770 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22773 + struct inode *delegated;
22775 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22776 + a->dst_h_parent);
22777 + rerr = PTR_ERR(a->h_path.dentry);
22778 + if (IS_ERR(a->h_path.dentry)) {
22779 + RevertFailure("lkup one %pd", a->dst_dentry);
22782 + if (d_is_positive(a->h_path.dentry)) {
22783 + d_drop(a->h_path.dentry);
22784 + dput(a->h_path.dentry);
22788 + delegated = NULL;
22789 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22790 + &delegated, a->flags);
22791 + if (unlikely(rerr == -EWOULDBLOCK)) {
22792 + pr_warn("cannot retry for NFSv4 delegation"
22793 + " for an internal rename\n");
22796 + d_drop(a->h_path.dentry);
22797 + dput(a->h_path.dentry);
22799 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22801 + RevertFailure("rename %pd", a->h_dst);
22804 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22808 + a->h_path.dentry = a->src_wh_dentry;
22809 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22810 + au_set_dbwh(a->src_dentry, a->src_bwh);
22812 + RevertFailure("unlink %pd", a->src_wh_dentry);
22814 +#undef RevertFailure
22816 +/* ---------------------------------------------------------------------- */
22819 + * when we have to copyup the renaming entry, do it with the rename-target name
22820 + * in order to minimize the cost (the later actual rename is unnecessary).
22821 + * otherwise rename it on the target branch.
22823 +static int au_ren_or_cpup(struct au_ren_args *a)
22826 + struct dentry *d;
22827 + struct inode *delegated;
22829 + d = a->src_dentry;
22830 + if (au_dbtop(d) == a->btgt) {
22831 + a->h_path.dentry = a->dst_h_dentry;
22832 + AuDebugOn(au_dbtop(d) != a->btgt);
22833 + delegated = NULL;
22834 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22835 + a->dst_h_dir, &a->h_path, &delegated,
22837 + if (unlikely(err == -EWOULDBLOCK)) {
22838 + pr_warn("cannot retry for NFSv4 delegation"
22839 + " for an internal rename\n");
22845 + if (!err && a->h_dst)
22846 + /* it will be set to dinfo later */
22852 +/* cf. aufs_rmdir() */
22853 +static int au_ren_del_whtmp(struct au_ren_args *a)
22856 + struct inode *dir;
22858 + dir = a->dst_dir;
22859 + SiMustAnyLock(dir->i_sb);
22860 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22861 + au_sbi(dir->i_sb)->si_dirwh)
22862 + || au_test_fs_remote(a->h_dst->d_sb)) {
22863 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22864 + if (unlikely(err))
22865 + pr_warn("failed removing whtmp dir %pd (%d), "
22866 + "ignored.\n", a->h_dst, err);
22868 + au_nhash_wh_free(&a->thargs->whlist);
22869 + a->thargs->whlist = a->whlist;
22870 + a->whlist.nh_num = 0;
22871 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22873 + a->thargs = NULL;
22879 +/* make it 'opaque' dir. */
22880 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22883 + struct dentry *d, *diropq;
22884 +#define src_or_dst(member) a->sd[idx].member
22887 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22888 + src_or_dst(bdiropq) = au_dbdiropq(d);
22889 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22890 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22891 + diropq = au_diropq_create(d, a->btgt);
22892 + au_hn_inode_unlock(src_or_dst(hinode));
22893 + if (IS_ERR(diropq))
22894 + err = PTR_ERR(diropq);
22898 +#undef src_or_dst_
22902 +static int au_ren_diropq(struct au_ren_args *a)
22905 + unsigned char always;
22906 + struct dentry *d;
22909 + d = a->dst_dentry; /* already renamed on the branch */
22910 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22911 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22912 + && !au_ftest_ren(a->auren_flags, DIRREN)
22913 + && a->btgt != au_dbdiropq(a->src_dentry)
22914 + && (a->dst_wh_dentry
22915 + || a->btgt <= au_dbdiropq(d)
22916 + /* hide the lower to keep xino */
22917 + /* the lowers may not be a dir, but we hide them anyway */
22918 + || a->btgt < au_dbbot(d)
22921 + err = au_ren_do_diropq(a, AuSRC);
22922 + if (unlikely(err))
22924 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22926 + if (!a->exchange)
22927 + goto out; /* success */
22929 + d = a->src_dentry; /* already renamed on the branch */
22930 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22931 + && a->btgt != au_dbdiropq(a->dst_dentry)
22932 + && (a->btgt < au_dbdiropq(d)
22933 + || a->btgt < au_dbbot(d)
22935 + AuDbgDentry(a->src_dentry);
22936 + AuDbgDentry(a->dst_dentry);
22937 + err = au_ren_do_diropq(a, AuDST);
22938 + if (unlikely(err))
22939 + goto out_rev_src;
22940 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22942 + goto out; /* success */
22945 + AuDbg("err %d, reverting src\n", err);
22946 + au_ren_rev_diropq(err, a);
22951 +static int do_rename(struct au_ren_args *a)
22954 + struct dentry *d, *h_d;
22956 + if (!a->exchange) {
22957 + /* prepare workqueue args for asynchronous rmdir */
22958 + h_d = a->dst_h_dentry;
22959 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22960 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22961 + && d_is_positive(h_d)) {
22963 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22965 + if (unlikely(!a->thargs))
22967 + a->h_dst = dget(h_d);
22970 + /* create whiteout for src_dentry */
22971 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22972 + a->src_bwh = au_dbwh(a->src_dentry);
22973 + AuDebugOn(a->src_bwh >= 0);
22974 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22975 + a->src_h_parent);
22976 + err = PTR_ERR(a->src_wh_dentry);
22977 + if (IS_ERR(a->src_wh_dentry))
22981 + /* lookup whiteout for dentry */
22982 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22983 + h_d = au_wh_lkup(a->dst_h_parent,
22984 + &a->dst_dentry->d_name, a->br);
22985 + err = PTR_ERR(h_d);
22988 + if (d_is_negative(h_d))
22991 + a->dst_wh_dentry = h_d;
22994 + /* rename dentry to tmpwh */
22996 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22997 + if (unlikely(err))
23000 + d = a->dst_dentry;
23001 + au_set_h_dptr(d, a->btgt, NULL);
23002 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23003 + if (unlikely(err))
23005 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23009 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23011 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23012 + && d_is_positive(a->dst_h_dentry)
23013 + && a->src_btop != a->btgt);
23016 + /* rename by vfs_rename or cpup */
23017 + err = au_ren_or_cpup(a);
23018 + if (unlikely(err))
23019 + /* leave the copied-up one */
23022 + /* make dir opaque */
23023 + err = au_ren_diropq(a);
23024 + if (unlikely(err))
23027 + /* update target timestamps */
23028 + if (a->exchange) {
23029 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23030 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23031 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23032 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23034 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23035 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23036 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23037 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23039 + if (!a->exchange) {
23040 + /* remove whiteout for dentry */
23041 + if (a->dst_wh_dentry) {
23042 + a->h_path.dentry = a->dst_wh_dentry;
23043 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23045 + if (unlikely(err))
23049 + /* remove whtmp */
23051 + au_ren_del_whtmp(a); /* ignore this error */
23053 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23056 + goto out_success;
23059 + au_ren_rev_diropq(err, a);
23061 + au_ren_rev_rename(err, a);
23065 + au_ren_rev_whtmp(err, a);
23067 + dput(a->dst_wh_dentry);
23068 + a->dst_wh_dentry = NULL;
23070 + if (a->src_wh_dentry)
23071 + au_ren_rev_whsrc(err, a);
23073 + dput(a->src_wh_dentry);
23074 + dput(a->dst_wh_dentry);
23078 + au_whtmp_rmdir_free(a->thargs);
23079 + a->thargs = NULL;
23085 +/* ---------------------------------------------------------------------- */
23088 + * test if @dentry dir can be rename destination or not.
23089 + * success means, it is a logically empty dir.
23091 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23093 + return au_test_empty(dentry, whlist);
23097 + * test if @a->src_dentry dir can be rename source or not.
23098 + * if it can, return 0.
23100 + * - it is a logically empty dir.
23101 + * - or, it exists on writable branch and has no children including whiteouts
23102 + * on the lower branch unless DIRREN is on.
23104 +static int may_rename_srcdir(struct au_ren_args *a)
23107 + unsigned int rdhash;
23108 + aufs_bindex_t btop, btgt;
23109 + struct dentry *dentry;
23110 + struct super_block *sb;
23111 + struct au_sbinfo *sbinfo;
23113 + dentry = a->src_dentry;
23114 + sb = dentry->d_sb;
23115 + sbinfo = au_sbi(sb);
23116 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23117 + au_fset_ren(a->auren_flags, DIRREN);
23120 + btop = au_dbtop(dentry);
23121 + if (btop != btgt) {
23122 + struct au_nhash whlist;
23124 + SiMustAnyLock(sb);
23125 + rdhash = sbinfo->si_rdhash;
23127 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23129 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23130 + if (unlikely(err))
23132 + err = au_test_empty(dentry, &whlist);
23133 + au_nhash_wh_free(&whlist);
23137 + if (btop == au_dbtaildir(dentry))
23138 + return 0; /* success */
23140 + err = au_test_empty_lower(dentry);
23143 + if (err == -ENOTEMPTY) {
23144 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23147 + AuWarn1("renaming dir who has child(ren) on multiple "
23148 + "branches, is not supported\n");
23155 +/* side effect: sets whlist and h_dentry */
23156 +static int au_ren_may_dir(struct au_ren_args *a)
23159 + unsigned int rdhash;
23160 + struct dentry *d;
23162 + d = a->dst_dentry;
23163 + SiMustAnyLock(d->d_sb);
23166 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23167 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23169 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23170 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23171 + if (unlikely(err))
23174 + if (!a->exchange) {
23175 + au_set_dbtop(d, a->dst_btop);
23176 + err = may_rename_dstdir(d, &a->whlist);
23177 + au_set_dbtop(d, a->btgt);
23179 + err = may_rename_srcdir(a);
23181 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23182 + if (unlikely(err))
23185 + d = a->src_dentry;
23186 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23187 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23188 + err = may_rename_srcdir(a);
23189 + if (unlikely(err)) {
23190 + au_nhash_wh_free(&a->whlist);
23191 + a->whlist.nh_num = 0;
23198 +/* ---------------------------------------------------------------------- */
23201 + * simple tests for rename.
23202 + * following the checks in vfs, plus the parent-child relationship.
23204 +static int au_may_ren(struct au_ren_args *a)
23207 + struct inode *h_inode;
23209 + if (a->src_btop == a->btgt) {
23210 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23211 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23212 + if (unlikely(err))
23215 + if (unlikely(a->src_h_dentry == a->h_trap))
23220 + if (a->dst_btop != a->btgt)
23223 + err = -ENOTEMPTY;
23224 + if (unlikely(a->dst_h_dentry == a->h_trap))
23228 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23229 + if (d_really_is_negative(a->dst_dentry)) {
23230 + if (d_is_negative(a->dst_h_dentry))
23231 + err = au_may_add(a->dst_dentry, a->btgt,
23232 + a->dst_h_parent, isdir);
23234 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23236 + h_inode = d_inode(a->dst_h_dentry);
23237 + if (h_inode->i_nlink)
23238 + err = au_may_del(a->dst_dentry, a->btgt,
23239 + a->dst_h_parent, isdir);
23243 + if (unlikely(err == -ENOENT || err == -EEXIST))
23249 +/* ---------------------------------------------------------------------- */
23254 + * - src_dir and dir by lock_rename()
23255 + * - inode if exitsts
23258 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23260 + * + di_write_lock2_child()
23261 + * + di_write_lock_child()
23262 + * + ii_write_lock_child()
23263 + * + di_write_lock_child2()
23264 + * + ii_write_lock_child2()
23265 + * + src_parent and parent
23266 + * + di_write_lock_parent()
23267 + * + ii_write_lock_parent()
23268 + * + di_write_lock_parent2()
23269 + * + ii_write_lock_parent2()
23270 + * + lower src_dir and dir by vfsub_lock_rename()
23271 + * + verify the every relationships between child and parent. if any
23272 + * of them failed, unlock all and return -EBUSY.
23274 +static void au_ren_unlock(struct au_ren_args *a)
23276 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23277 + a->dst_h_parent, a->dst_hdir);
23278 + if (au_ftest_ren(a->auren_flags, DIRREN)
23280 + au_hn_inode_unlock(a->h_root);
23281 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23282 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23285 +static int au_ren_lock(struct au_ren_args *a)
23288 + unsigned int udba;
23291 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23292 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23293 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23294 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23296 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23297 + if (unlikely(err))
23299 + au_fset_ren(a->auren_flags, MNT_WRITE);
23300 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23301 + struct dentry *root;
23302 + struct inode *dir;
23305 + * sbinfo is already locked, so this ii_read_lock is
23306 + * unnecessary. but our debugging feature checks it.
23308 + root = a->src_inode->i_sb->s_root;
23309 + if (root != a->src_parent && root != a->dst_parent) {
23310 + dir = d_inode(root);
23311 + ii_read_lock_parent3(dir);
23312 + a->h_root = au_hi(dir, a->btgt);
23313 + ii_read_unlock(dir);
23314 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23317 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23318 + a->dst_h_parent, a->dst_hdir);
23319 + udba = au_opt_udba(a->src_dentry->d_sb);
23320 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23321 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23322 + err = au_busy_or_stale();
23323 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23324 + err = au_h_verify(a->src_h_dentry, udba,
23325 + d_inode(a->src_h_parent), a->src_h_parent,
23327 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23328 + err = au_h_verify(a->dst_h_dentry, udba,
23329 + d_inode(a->dst_h_parent), a->dst_h_parent,
23332 + goto out; /* success */
23334 + err = au_busy_or_stale();
23335 + au_ren_unlock(a);
23341 +/* ---------------------------------------------------------------------- */
23343 +static void au_ren_refresh_dir(struct au_ren_args *a)
23345 + struct inode *dir;
23347 + dir = a->dst_dir;
23348 + inode_inc_iversion(dir);
23349 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23350 + /* is this updating defined in POSIX? */
23351 + au_cpup_attr_timesizes(a->src_inode);
23352 + au_cpup_attr_nlink(dir, /*force*/1);
23354 + au_dir_ts(dir, a->btgt);
23356 + if (a->exchange) {
23357 + dir = a->src_dir;
23358 + inode_inc_iversion(dir);
23359 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23360 + /* is this updating defined in POSIX? */
23361 + au_cpup_attr_timesizes(a->dst_inode);
23362 + au_cpup_attr_nlink(dir, /*force*/1);
23364 + au_dir_ts(dir, a->btgt);
23367 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23370 + dir = a->src_dir;
23371 + inode_inc_iversion(dir);
23372 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23373 + au_cpup_attr_nlink(dir, /*force*/1);
23374 + au_dir_ts(dir, a->btgt);
23377 +static void au_ren_refresh(struct au_ren_args *a)
23379 + aufs_bindex_t bbot, bindex;
23380 + struct dentry *d, *h_d;
23381 + struct inode *i, *h_i;
23382 + struct super_block *sb;
23384 + d = a->dst_dentry;
23387 + /* already dget-ed by au_ren_or_cpup() */
23388 + au_set_h_dptr(d, a->btgt, a->h_dst);
23390 + i = a->dst_inode;
23392 + if (!a->exchange) {
23393 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23394 + vfsub_drop_nlink(i);
23396 + vfsub_dead_dir(i);
23397 + au_cpup_attr_timesizes(i);
23399 + au_update_dbrange(d, /*do_put_zero*/1);
23401 + au_cpup_attr_nlink(i, /*force*/1);
23404 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23405 + au_set_h_dptr(d, bindex, NULL);
23406 + bbot = au_dbbot(d);
23407 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23408 + au_set_h_dptr(d, bindex, NULL);
23409 + au_update_dbrange(d, /*do_put_zero*/0);
23413 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23414 + d_drop(a->src_dentry);
23415 + if (au_ftest_ren(a->auren_flags, DIRREN))
23416 + au_set_dbwh(a->src_dentry, -1);
23420 + d = a->src_dentry;
23421 + au_set_dbwh(d, -1);
23422 + bbot = au_dbbot(d);
23423 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23424 + h_d = au_h_dptr(d, bindex);
23426 + au_set_h_dptr(d, bindex, NULL);
23428 + au_set_dbbot(d, a->btgt);
23431 + i = a->src_inode;
23432 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23433 + return; /* success */
23435 + bbot = au_ibbot(i);
23436 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23437 + h_i = au_h_iptr(i, bindex);
23439 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23440 + /* ignore this error */
23441 + au_set_h_iptr(i, bindex, NULL, 0);
23444 + au_set_ibbot(i, a->btgt);
23447 +/* ---------------------------------------------------------------------- */
23449 +/* mainly for link(2) and rename(2) */
23450 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23452 + aufs_bindex_t bdiropq, bwh;
23453 + struct dentry *parent;
23454 + struct au_branch *br;
23456 + parent = dentry->d_parent;
23457 + IMustLock(d_inode(parent)); /* dir is locked */
23459 + bdiropq = au_dbdiropq(parent);
23460 + bwh = au_dbwh(dentry);
23461 + br = au_sbr(dentry->d_sb, btgt);
23462 + if (au_br_rdonly(br)
23463 + || (0 <= bdiropq && bdiropq < btgt)
23464 + || (0 <= bwh && bwh < btgt))
23467 + AuDbg("btgt %d\n", btgt);
23471 +/* sets src_btop, dst_btop and btgt */
23472 +static int au_ren_wbr(struct au_ren_args *a)
23475 + struct au_wr_dir_args wr_dir_args = {
23476 + /* .force_btgt = -1, */
23477 + .flags = AuWrDir_ADD_ENTRY
23480 + a->src_btop = au_dbtop(a->src_dentry);
23481 + a->dst_btop = au_dbtop(a->dst_dentry);
23482 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23483 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23484 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23485 + wr_dir_args.force_btgt = a->src_btop;
23486 + if (a->dst_inode && a->dst_btop < a->src_btop)
23487 + wr_dir_args.force_btgt = a->dst_btop;
23488 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23489 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23492 + au_update_dbtop(a->dst_dentry);
23497 +static void au_ren_dt(struct au_ren_args *a)
23499 + a->h_path.dentry = a->src_h_parent;
23500 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23501 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23502 + a->h_path.dentry = a->dst_h_parent;
23503 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23506 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23507 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23511 + a->h_path.dentry = a->src_h_dentry;
23512 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23513 + if (d_is_positive(a->dst_h_dentry)) {
23514 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23515 + a->h_path.dentry = a->dst_h_dentry;
23516 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23520 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23522 + struct dentry *h_d;
23523 + struct inode *h_inode;
23525 + au_dtime_revert(a->src_dt + AuPARENT);
23526 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23527 + au_dtime_revert(a->dst_dt + AuPARENT);
23529 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23530 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23531 + h_inode = d_inode(h_d);
23532 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23533 + au_dtime_revert(a->src_dt + AuCHILD);
23534 + inode_unlock(h_inode);
23536 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23537 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23538 + h_inode = d_inode(h_d);
23539 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23540 + au_dtime_revert(a->dst_dt + AuCHILD);
23541 + inode_unlock(h_inode);
23546 +/* ---------------------------------------------------------------------- */
23548 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23549 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23550 + unsigned int _flags)
23552 + int err, lock_flags;
23554 + /* reduce stack space */
23555 + struct au_ren_args *a;
23556 + struct au_pin pin;
23558 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23559 + IMustLock(_src_dir);
23560 + IMustLock(_dst_dir);
23563 + if (unlikely(_flags & RENAME_WHITEOUT))
23567 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23568 + a = kzalloc(sizeof(*a), GFP_NOFS);
23569 + if (unlikely(!a))
23572 + a->flags = _flags;
23573 + a->exchange = _flags & RENAME_EXCHANGE;
23574 + a->src_dir = _src_dir;
23575 + a->src_dentry = _src_dentry;
23576 + a->src_inode = NULL;
23577 + if (d_really_is_positive(a->src_dentry))
23578 + a->src_inode = d_inode(a->src_dentry);
23579 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23580 + a->dst_dir = _dst_dir;
23581 + a->dst_dentry = _dst_dentry;
23582 + a->dst_inode = NULL;
23583 + if (d_really_is_positive(a->dst_dentry))
23584 + a->dst_inode = d_inode(a->dst_dentry);
23585 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23586 + if (a->dst_inode) {
23588 + * if EXCHANGE && src is non-dir && dst is dir,
23589 + * dst is not locked.
23591 + /* IMustLock(a->dst_inode); */
23592 + au_igrab(a->dst_inode);
23596 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23597 + if (d_is_dir(a->src_dentry)) {
23598 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23599 + if (unlikely(!a->exchange
23600 + && d_really_is_positive(a->dst_dentry)
23601 + && !d_is_dir(a->dst_dentry)))
23603 + lock_flags |= AuLock_DIRS;
23605 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23606 + au_fset_ren(a->auren_flags, ISDIR_DST);
23607 + if (unlikely(!a->exchange
23608 + && d_really_is_positive(a->src_dentry)
23609 + && !d_is_dir(a->src_dentry)))
23611 + lock_flags |= AuLock_DIRS;
23613 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23615 + if (unlikely(err))
23618 + err = au_d_hashed_positive(a->src_dentry);
23619 + if (unlikely(err))
23622 + if (a->dst_inode) {
23624 + * If it is a dir, VFS unhash it before this
23625 + * function. It means we cannot rely upon d_unhashed().
23627 + if (unlikely(!a->dst_inode->i_nlink))
23629 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23630 + err = au_d_hashed_positive(a->dst_dentry);
23631 + if (unlikely(err && !a->exchange))
23633 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23635 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23639 + * is it possible?
23640 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23641 + * there may exist a problem somewhere else.
23644 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23647 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23648 + di_write_lock_parent(a->dst_parent);
23650 + /* which branch we process */
23651 + err = au_ren_wbr(a);
23652 + if (unlikely(err < 0))
23654 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23655 + a->h_path.mnt = au_br_mnt(a->br);
23657 + /* are they available to be renamed */
23658 + err = au_ren_may_dir(a);
23659 + if (unlikely(err))
23660 + goto out_children;
23662 + /* prepare the writable parent dir on the same branch */
23663 + if (a->dst_btop == a->btgt) {
23664 + au_fset_ren(a->auren_flags, WHDST);
23666 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23667 + if (unlikely(err))
23668 + goto out_children;
23672 + if (!a->exchange) {
23673 + if (a->src_dir != a->dst_dir) {
23675 + * this temporary unlock is safe,
23676 + * because both dir->i_mutex are locked.
23678 + di_write_unlock(a->dst_parent);
23679 + di_write_lock_parent(a->src_parent);
23680 + err = au_wr_dir_need_wh(a->src_dentry,
23681 + au_ftest_ren(a->auren_flags,
23684 + di_write_unlock(a->src_parent);
23685 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23687 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23689 + err = au_wr_dir_need_wh(a->src_dentry,
23690 + au_ftest_ren(a->auren_flags,
23694 + if (unlikely(err < 0))
23695 + goto out_children;
23697 + au_fset_ren(a->auren_flags, WHSRC);
23700 + if (a->src_btop != a->btgt) {
23701 + err = au_pin(&pin, a->src_dentry, a->btgt,
23702 + au_opt_udba(a->src_dentry->d_sb),
23703 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23705 + struct au_cp_generic cpg = {
23706 + .dentry = a->src_dentry,
23708 + .bsrc = a->src_btop,
23711 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23713 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23714 + err = au_sio_cpup_simple(&cpg);
23717 + if (unlikely(err))
23718 + goto out_children;
23719 + a->src_btop = a->btgt;
23720 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23721 + if (!a->exchange)
23722 + au_fset_ren(a->auren_flags, WHSRC);
23726 + if (a->exchange && a->dst_inode
23727 + && a->dst_btop != a->btgt) {
23728 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23729 + au_opt_udba(a->dst_dentry->d_sb),
23730 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23732 + struct au_cp_generic cpg = {
23733 + .dentry = a->dst_dentry,
23735 + .bsrc = a->dst_btop,
23738 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23740 + err = au_sio_cpup_simple(&cpg);
23743 + if (unlikely(err))
23744 + goto out_children;
23745 + a->dst_btop = a->btgt;
23746 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23749 + /* lock them all */
23750 + err = au_ren_lock(a);
23751 + if (unlikely(err))
23752 + /* leave the copied-up one */
23753 + goto out_children;
23755 + if (!a->exchange) {
23756 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23757 + err = au_may_ren(a);
23758 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23759 + err = -ENAMETOOLONG;
23760 + if (unlikely(err))
23764 + /* store timestamps to be revertible */
23767 + /* store dirren info */
23768 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23769 + err = au_dr_rename(a->src_dentry, a->btgt,
23770 + &a->dst_dentry->d_name, &rev);
23772 + if (unlikely(err))
23777 + err = do_rename(a);
23778 + if (unlikely(err))
23781 + if (au_ftest_ren(a->auren_flags, DIRREN))
23782 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23784 + /* update dir attributes */
23785 + au_ren_refresh_dir(a);
23787 + /* dput/iput all lower dentries */
23788 + au_ren_refresh(a);
23790 + goto out_hdir; /* success */
23793 + if (au_ftest_ren(a->auren_flags, DIRREN))
23794 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23796 + au_ren_rev_dt(err, a);
23798 + au_ren_unlock(a);
23800 + au_nhash_wh_free(&a->whlist);
23801 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23802 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23803 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23804 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23808 + if (d_unhashed(a->src_dentry))
23809 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23810 + if (d_unhashed(a->dst_dentry))
23811 + au_fset_ren(a->auren_flags, DROPPED_DST);
23812 + if (!a->exchange)
23813 + d_move(a->src_dentry, a->dst_dentry);
23815 + d_exchange(a->src_dentry, a->dst_dentry);
23816 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23817 + d_drop(a->dst_dentry);
23819 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23820 + d_drop(a->src_dentry);
23822 + au_update_dbtop(a->dst_dentry);
23823 + if (!a->dst_inode)
23824 + d_drop(a->dst_dentry);
23826 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23827 + di_write_unlock(a->dst_parent);
23829 + di_write_unlock2(a->src_parent, a->dst_parent);
23831 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23833 + iput(a->dst_inode);
23835 + au_whtmp_rmdir_free(a->thargs);
23841 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23842 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23843 +++ linux/fs/aufs/Kconfig 2018-06-04 09:08:09.181412645 +0200
23845 +# SPDX-License-Identifier: GPL-2.0
23847 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23849 + Aufs is a stackable unification filesystem such as Unionfs,
23850 + which unifies several directories and provides a merged single
23852 + In the early days, aufs was entirely re-designed and
23853 + re-implemented Unionfs Version 1.x series. Introducing many
23854 + original ideas, approaches and improvements, it becomes totally
23855 + different from Unionfs while keeping the basic features.
23859 + prompt "Maximum number of branches"
23860 + default AUFS_BRANCH_MAX_127
23862 + Specifies the maximum number of branches (or member directories)
23863 + in a single aufs. The larger value consumes more system
23864 + resources and has a minor impact to performance.
23865 +config AUFS_BRANCH_MAX_127
23868 + Specifies the maximum number of branches (or member directories)
23869 + in a single aufs. The larger value consumes more system
23870 + resources and has a minor impact to performance.
23871 +config AUFS_BRANCH_MAX_511
23874 + Specifies the maximum number of branches (or member directories)
23875 + in a single aufs. The larger value consumes more system
23876 + resources and has a minor impact to performance.
23877 +config AUFS_BRANCH_MAX_1023
23880 + Specifies the maximum number of branches (or member directories)
23881 + in a single aufs. The larger value consumes more system
23882 + resources and has a minor impact to performance.
23883 +config AUFS_BRANCH_MAX_32767
23886 + Specifies the maximum number of branches (or member directories)
23887 + in a single aufs. The larger value consumes more system
23888 + resources and has a minor impact to performance.
23891 +config AUFS_SBILIST
23893 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23896 + Automatic configuration for internal use.
23897 + When aufs supports Magic SysRq or /proc, enabled automatically.
23899 +config AUFS_HNOTIFY
23900 + bool "Detect direct branch access (bypassing aufs)"
23902 + If you want to modify files on branches directly, eg. bypassing aufs,
23903 + and want aufs to detect the changes of them fully, then enable this
23904 + option and use 'udba=notify' mount option.
23905 + Currently there is only one available configuration, "fsnotify".
23906 + It will have a negative impact to the performance.
23907 + See detail in aufs.5.
23910 + prompt "method" if AUFS_HNOTIFY
23911 + default AUFS_HFSNOTIFY
23912 +config AUFS_HFSNOTIFY
23917 +config AUFS_EXPORT
23918 + bool "NFS-exportable aufs"
23919 + depends on EXPORTFS
23921 + If you want to export your mounted aufs via NFS, then enable this
23922 + option. There are several requirements for this configuration.
23923 + See detail in aufs.5.
23925 +config AUFS_INO_T_64
23927 + depends on AUFS_EXPORT
23928 + depends on 64BIT && !(ALPHA || S390)
23931 + Automatic configuration for internal use.
23932 + /* typedef unsigned long/int __kernel_ino_t */
23933 + /* alpha and s390x are int */
23936 + bool "support for XATTR/EA (including Security Labels)"
23938 + If your branch fs supports XATTR/EA and you want to make them
23939 + available in aufs too, then enable this opsion and specify the
23940 + branch attributes for EA.
23941 + See detail in aufs.5.
23944 + bool "File-based Hierarchical Storage Management"
23946 + Hierarchical Storage Management (or HSM) is a well-known feature
23947 + in the storage world. Aufs provides this feature as file-based.
23948 + with multiple branches.
23949 + These multiple branches are prioritized, ie. the topmost one
23950 + should be the fastest drive and be used heavily.
23953 + bool "Readdir in userspace"
23955 + Aufs has two methods to provide a merged view for a directory,
23956 + by a user-space library and by kernel-space natively. The latter
23957 + is always enabled but sometimes large and slow.
23958 + If you enable this option, install the library in aufs2-util
23959 + package, and set some environment variables for your readdir(3),
23960 + then the work will be handled in user-space which generally
23961 + shows better performance in most cases.
23962 + See detail in aufs.5.
23964 +config AUFS_DIRREN
23965 + bool "Workaround for rename(2)-ing a directory"
23967 + By default, aufs returns EXDEV error in renameing a dir who has
23968 + his child on the lower branch, since it is a bad idea to issue
23969 + rename(2) internally for every lower branch. But user may not
23970 + accept this behaviour. So here is a workaround to allow such
23971 + rename(2) and store some extra infromation on the writable
23972 + branch. Obviously this costs high (and I don't like it).
23973 + To use this feature, you need to enable this configuration AND
23974 + to specify the mount option `dirren.'
23975 + See details in aufs.5 and the design documents.
23978 + bool "Show whiteouts"
23980 + If you want to make the whiteouts in aufs visible, then enable
23981 + this option and specify 'shwh' mount option. Although it may
23982 + sounds like philosophy or something, but in technically it
23983 + simply shows the name of whiteout with keeping its behaviour.
23985 +config AUFS_BR_RAMFS
23986 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23988 + If you want to use ramfs as an aufs branch fs, then enable this
23989 + option. Generally tmpfs is recommended.
23990 + Aufs prohibited them to be a branch fs by default, because
23991 + initramfs becomes unusable after switch_root or something
23992 + generally. If you sets initramfs as an aufs branch and boot your
23993 + system by switch_root, you will meet a problem easily since the
23994 + files in initramfs may be inaccessible.
23995 + Unless you are going to use ramfs as an aufs branch fs without
23996 + switch_root or something, leave it N.
23998 +config AUFS_BR_FUSE
23999 + bool "Fuse fs as an aufs branch"
24000 + depends on FUSE_FS
24003 + If you want to use fuse-based userspace filesystem as an aufs
24004 + branch fs, then enable this option.
24005 + It implements the internal poll(2) operation which is
24006 + implemented by fuse only (curretnly).
24011 + Automatic configuration for internal use.
24013 +config AUFS_BR_HFSPLUS
24014 + bool "Hfsplus as an aufs branch"
24015 + depends on HFSPLUS_FS
24018 + If you want to use hfsplus fs as an aufs branch fs, then enable
24019 + this option. This option introduces a small overhead at
24020 + copying-up a file on hfsplus.
24022 +config AUFS_BDEV_LOOP
24024 + depends on BLK_DEV_LOOP
24027 + Automatic configuration for internal use.
24028 + Convert =[ym] into =y.
24031 + bool "Debug aufs"
24033 + Enable this to compile aufs internal debug code.
24034 + It will have a negative impact to the performance.
24036 +config AUFS_MAGIC_SYSRQ
24038 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24041 + Automatic configuration for internal use.
24042 + When aufs supports Magic SysRq, enabled automatically.
24044 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24045 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24046 +++ linux/fs/aufs/loop.c 2018-07-19 09:46:13.059981241 +0200
24048 +/* SPDX-License-Identifier: GPL-2.0 */
24050 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24052 + * This program, aufs is free software; you can redistribute it and/or modify
24053 + * it under the terms of the GNU General Public License as published by
24054 + * the Free Software Foundation; either version 2 of the License, or
24055 + * (at your option) any later version.
24057 + * This program is distributed in the hope that it will be useful,
24058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24060 + * GNU General Public License for more details.
24062 + * You should have received a copy of the GNU General Public License
24063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24067 + * support for loopback block device as a branch
24072 +/* added into drivers/block/loop.c */
24073 +static struct file *(*backing_file_func)(struct super_block *sb);
24076 + * test if two lower dentries have overlapping branches.
24078 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24080 + struct super_block *h_sb;
24081 + struct file *backing_file;
24083 + if (unlikely(!backing_file_func)) {
24084 + /* don't load "loop" module here */
24085 + backing_file_func = symbol_get(loop_backing_file);
24086 + if (unlikely(!backing_file_func))
24087 + /* "loop" module is not loaded */
24091 + h_sb = h_adding->d_sb;
24092 + backing_file = backing_file_func(h_sb);
24093 + if (!backing_file)
24096 + h_adding = backing_file->f_path.dentry;
24098 + * h_adding can be local NFS.
24099 + * in this case aufs cannot detect the loop.
24101 + if (unlikely(h_adding->d_sb == sb))
24103 + return !!au_test_subdir(h_adding, sb->s_root);
24106 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24107 +int au_test_loopback_kthread(void)
24110 + struct task_struct *tsk = current;
24111 + char c, comm[sizeof(tsk->comm)];
24114 + if (tsk->flags & PF_KTHREAD) {
24115 + get_task_comm(comm, tsk);
24117 + ret = ('0' <= c && c <= '9'
24118 + && !strncmp(comm, "loop", 4));
24124 +/* ---------------------------------------------------------------------- */
24126 +#define au_warn_loopback_step 16
24127 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24128 +static unsigned long *au_warn_loopback_array;
24130 +void au_warn_loopback(struct super_block *h_sb)
24132 + int i, new_nelem;
24133 + unsigned long *a, magic;
24134 + static DEFINE_SPINLOCK(spin);
24136 + magic = h_sb->s_magic;
24137 + spin_lock(&spin);
24138 + a = au_warn_loopback_array;
24139 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24140 + if (a[i] == magic) {
24141 + spin_unlock(&spin);
24145 + /* h_sb is new to us, print it */
24146 + if (i < au_warn_loopback_nelem) {
24151 + /* expand the array */
24152 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24153 + a = au_kzrealloc(au_warn_loopback_array,
24154 + au_warn_loopback_nelem * sizeof(unsigned long),
24155 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24156 + /*may_shrink*/0);
24158 + au_warn_loopback_nelem = new_nelem;
24159 + au_warn_loopback_array = a;
24164 + spin_unlock(&spin);
24165 + AuWarn1("realloc failed, ignored\n");
24169 + spin_unlock(&spin);
24170 + pr_warn("you may want to try another patch for loopback file "
24171 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24174 +int au_loopback_init(void)
24177 + struct super_block *sb __maybe_unused;
24179 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
24182 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24183 + sizeof(unsigned long), GFP_NOFS);
24184 + if (unlikely(!au_warn_loopback_array))
24190 +void au_loopback_fin(void)
24192 + if (backing_file_func)
24193 + symbol_put(loop_backing_file);
24194 + kfree(au_warn_loopback_array);
24196 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24197 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24198 +++ linux/fs/aufs/loop.h 2018-07-19 09:46:13.059981241 +0200
24200 +/* SPDX-License-Identifier: GPL-2.0 */
24202 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24204 + * This program, aufs is free software; you can redistribute it and/or modify
24205 + * it under the terms of the GNU General Public License as published by
24206 + * the Free Software Foundation; either version 2 of the License, or
24207 + * (at your option) any later version.
24209 + * This program is distributed in the hope that it will be useful,
24210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24212 + * GNU General Public License for more details.
24214 + * You should have received a copy of the GNU General Public License
24215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24219 + * support for loopback mount as a branch
24222 +#ifndef __AUFS_LOOP_H__
24223 +#define __AUFS_LOOP_H__
24228 +struct super_block;
24230 +#ifdef CONFIG_AUFS_BDEV_LOOP
24231 +/* drivers/block/loop.c */
24232 +struct file *loop_backing_file(struct super_block *sb);
24235 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24236 +int au_test_loopback_kthread(void);
24237 +void au_warn_loopback(struct super_block *h_sb);
24239 +int au_loopback_init(void);
24240 +void au_loopback_fin(void);
24242 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24243 + struct dentry *h_adding)
24244 +AuStubInt0(au_test_loopback_kthread, void)
24245 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24247 +AuStubInt0(au_loopback_init, void)
24248 +AuStubVoid(au_loopback_fin, void)
24249 +#endif /* BLK_DEV_LOOP */
24251 +#endif /* __KERNEL__ */
24252 +#endif /* __AUFS_LOOP_H__ */
24253 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24254 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24255 +++ linux/fs/aufs/magic.mk 2018-06-04 09:08:09.188079511 +0200
24257 +# SPDX-License-Identifier: GPL-2.0
24259 +# defined in ${srctree}/fs/fuse/inode.c
24261 +ifdef CONFIG_FUSE_FS
24262 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24265 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24267 +ifdef CONFIG_XFS_FS
24268 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24271 +# defined in ${srctree}/fs/configfs/mount.c
24273 +ifdef CONFIG_CONFIGFS_FS
24274 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24277 +# defined in ${srctree}/fs/ubifs/ubifs.h
24279 +ifdef CONFIG_UBIFS_FS
24280 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24283 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24285 +ifdef CONFIG_HFSPLUS_FS
24286 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24288 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24289 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24290 +++ linux/fs/aufs/Makefile 2018-06-04 09:08:09.181412645 +0200
24292 +# SPDX-License-Identifier: GPL-2.0
24294 +include ${src}/magic.mk
24295 +ifeq (${CONFIG_AUFS_FS},m)
24296 +include ${src}/conf.mk
24298 +-include ${src}/priv_def.mk
24300 +# cf. include/linux/kernel.h
24302 +ccflags-y += -DDEBUG
24303 +# sparse requires the full pathname
24305 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24307 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24310 +obj-$(CONFIG_AUFS_FS) += aufs.o
24311 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24312 + wkq.o vfsub.o dcsub.o \
24313 + cpup.o whout.o wbr_policy.o \
24314 + dinfo.o dentry.o \
24316 + finfo.o file.o f_op.o \
24318 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24322 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24323 +aufs-$(CONFIG_SYSFS) += sysfs.o
24324 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24325 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24326 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24327 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24328 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24329 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24330 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24331 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24332 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24333 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24334 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24335 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24336 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24337 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24338 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24339 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24340 +++ linux/fs/aufs/module.c 2018-07-19 09:46:13.059981241 +0200
24342 +/* SPDX-License-Identifier: GPL-2.0 */
24344 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24346 + * This program, aufs is free software; you can redistribute it and/or modify
24347 + * it under the terms of the GNU General Public License as published by
24348 + * the Free Software Foundation; either version 2 of the License, or
24349 + * (at your option) any later version.
24351 + * This program is distributed in the hope that it will be useful,
24352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24354 + * GNU General Public License for more details.
24356 + * You should have received a copy of the GNU General Public License
24357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24361 + * module global variables and operations
24364 +#include <linux/module.h>
24365 +#include <linux/seq_file.h>
24368 +/* shrinkable realloc */
24369 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24377 +#if 0 /* unused */
24384 + AuDebugOn(!new_sz);
24387 + diff = au_kmidx_sub(sz, new_sz);
24393 + /* expand or SLOB */
24394 + p = krealloc(p, new_sz, gfp);
24395 + else if (new_sz < sz && may_shrink) {
24399 + q = kmalloc(new_sz, gfp);
24402 + memcpy(q, p, new_sz);
24414 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24417 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24418 + if (p && new_sz > nused)
24419 + memset(p + nused, 0, new_sz - nused);
24423 +/* ---------------------------------------------------------------------- */
24427 +struct kmem_cache *au_cache[AuCache_Last];
24429 +static void au_cache_fin(void)
24434 + * Make sure all delayed rcu free inodes are flushed before we
24439 + /* excluding AuCache_HNOTIFY */
24440 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24441 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24442 + kmem_cache_destroy(au_cache[i]);
24443 + au_cache[i] = NULL;
24447 +static int __init au_cache_init(void)
24449 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24450 + if (au_cache[AuCache_DINFO])
24451 + /* SLAB_DESTROY_BY_RCU */
24452 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24453 + au_icntnr_init_once);
24454 + if (au_cache[AuCache_ICNTNR])
24455 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24456 + au_fi_init_once);
24457 + if (au_cache[AuCache_FINFO])
24458 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24459 + if (au_cache[AuCache_VDIR])
24460 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24461 + if (au_cache[AuCache_DEHSTR])
24468 +/* ---------------------------------------------------------------------- */
24470 +int au_dir_roflags;
24472 +#ifdef CONFIG_AUFS_SBILIST
24474 + * iterate_supers_type() doesn't protect us from
24475 + * remounting (branch management)
24477 +struct hlist_bl_head au_sbilist;
24481 + * functions for module interface.
24483 +MODULE_LICENSE("GPL");
24484 +/* MODULE_LICENSE("GPL v2"); */
24485 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24486 +MODULE_DESCRIPTION(AUFS_NAME
24487 + " -- Advanced multi layered unification filesystem");
24488 +MODULE_VERSION(AUFS_VERSION);
24489 +MODULE_ALIAS_FS(AUFS_NAME);
24491 +/* this module parameter has no meaning when SYSFS is disabled */
24492 +int sysaufs_brs = 1;
24493 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24494 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
24496 +/* this module parameter has no meaning when USER_NS is disabled */
24498 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24499 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
24501 +/* ---------------------------------------------------------------------- */
24503 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24505 +int au_seq_path(struct seq_file *seq, struct path *path)
24509 + err = seq_path(seq, path, au_esc_chars);
24518 +/* ---------------------------------------------------------------------- */
24520 +static int __init aufs_init(void)
24525 + p = au_esc_chars;
24526 + for (i = 1; i <= ' '; i++)
24532 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24534 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24535 + for (i = 0; i < AuIop_Last; i++)
24536 + aufs_iop_nogetattr[i].getattr = NULL;
24538 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24540 + au_sbilist_init();
24541 + sysaufs_brs_init();
24544 + err = sysaufs_init();
24545 + if (unlikely(err))
24547 + err = dbgaufs_init();
24548 + if (unlikely(err))
24549 + goto out_sysaufs;
24550 + err = au_procfs_init();
24551 + if (unlikely(err))
24552 + goto out_dbgaufs;
24553 + err = au_wkq_init();
24554 + if (unlikely(err))
24556 + err = au_loopback_init();
24557 + if (unlikely(err))
24559 + err = au_hnotify_init();
24560 + if (unlikely(err))
24561 + goto out_loopback;
24562 + err = au_sysrq_init();
24563 + if (unlikely(err))
24565 + err = au_cache_init();
24566 + if (unlikely(err))
24569 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24570 + err = register_filesystem(&aufs_fs_type);
24571 + if (unlikely(err))
24574 + /* since we define pr_fmt, call printk directly */
24575 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24576 + goto out; /* success */
24583 + au_hnotify_fin();
24585 + au_loopback_fin();
24599 +static void __exit aufs_exit(void)
24601 + unregister_filesystem(&aufs_fs_type);
24604 + au_hnotify_fin();
24605 + au_loopback_fin();
24613 +module_init(aufs_init);
24614 +module_exit(aufs_exit);
24615 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24616 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24617 +++ linux/fs/aufs/module.h 2018-07-19 09:46:13.059981241 +0200
24619 +/* SPDX-License-Identifier: GPL-2.0 */
24621 + * Copyright (C) 2005-2018 Junjiro R. Okajima
24623 + * This program, aufs is free software; you can redistribute it and/or modify
24624 + * it under the terms of the GNU General Public License as published by
24625 + * the Free Software Foundation; either version 2 of the License, or
24626 + * (at your option) any later version.
24628 + * This program is distributed in the hope that it will be useful,
24629 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24630 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24631 + * GNU General Public License for more details.
24633 + * You should have received a copy of the GNU General Public License
24634 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24638 + * module initialization and module-global
24641 +#ifndef __AUFS_MODULE_H__
24642 +#define __AUFS_MODULE_H__
24646 +#include <linux/slab.h>
24651 +/* module parameters */
24652 +extern int sysaufs_brs;
24653 +extern bool au_userns;
24655 +/* ---------------------------------------------------------------------- */
24657 +extern int au_dir_roflags;
24659 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24660 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24663 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24665 +#ifndef CONFIG_SLOB
24666 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24668 + return -1; /* SLOB is untested */
24672 +int au_seq_path(struct seq_file *seq, struct path *path);
24674 +#ifdef CONFIG_PROC_FS
24676 +int __init au_procfs_init(void);
24677 +void au_procfs_fin(void);
24679 +AuStubInt0(au_procfs_init, void);
24680 +AuStubVoid(au_procfs_fin, void);
24683 +/* ---------------------------------------------------------------------- */
24692 + AuCache_HNOTIFY, /* must be last */
24696 +extern struct kmem_cache *au_cache[AuCache_Last];
24698 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24699 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24700 +#define AuCacheCtor(type, ctor) \
24701 + kmem_cache_create(#type, sizeof(struct type), \
24702 + __alignof__(struct type), AuCacheFlags, ctor)
24704 +#define AuCacheFuncs(name, index) \
24705 +static inline struct au_##name *au_cache_alloc_##name(void) \
24706 +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24707 +static inline void au_cache_free_##name(struct au_##name *p) \
24708 +{ kmem_cache_free(au_cache[AuCache_##index], p); }
24710 +AuCacheFuncs(dinfo, DINFO);
24711 +AuCacheFuncs(icntnr, ICNTNR);
24712 +AuCacheFuncs(finfo, FINFO);
24713 +AuCacheFuncs(vdir, VDIR);
24714 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24715 +#ifdef CONFIG_AUFS_HNOTIFY
24716 +AuCacheFuncs(hnotify, HNOTIFY);
24719 +#endif /* __KERNEL__ */
24720 +#endif /* __AUFS_MODULE_H__ */
24721 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24722 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24723 +++ linux/fs/aufs/mvdown.c 2018-07-19 09:46:13.059981241 +0200
24725 +/* SPDX-License-Identifier: GPL-2.0 */
24727 + * Copyright (C) 2011-2018 Junjiro R. Okajima
24729 + * This program, aufs is free software; you can redistribute it and/or modify
24730 + * it under the terms of the GNU General Public License as published by
24731 + * the Free Software Foundation; either version 2 of the License, or
24732 + * (at your option) any later version.
24734 + * This program is distributed in the hope that it will be useful,
24735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24737 + * GNU General Public License for more details.
24739 + * You should have received a copy of the GNU General Public License
24740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24744 + * move-down, opposite of copy-up
24749 +struct au_mvd_args {
24751 + struct super_block *h_sb;
24752 + struct dentry *h_parent;
24753 + struct au_hinode *hdir;
24754 + struct inode *h_dir, *h_inode;
24755 + struct au_pin pin;
24756 + } info[AUFS_MVDOWN_NARRAY];
24758 + struct aufs_mvdown mvdown;
24759 + struct dentry *dentry, *parent;
24760 + struct inode *inode, *dir;
24761 + struct super_block *sb;
24762 + aufs_bindex_t bopq, bwh, bfound;
24763 + unsigned char rename_lock;
24766 +#define mvd_errno mvdown.au_errno
24767 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24768 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24769 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24770 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24772 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24773 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24774 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24775 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24776 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24777 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24779 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24780 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24781 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24782 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24783 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24784 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24786 +#define AU_MVD_PR(flag, ...) do { \
24788 + pr_err(__VA_ARGS__); \
24791 +static int find_lower_writable(struct au_mvd_args *a)
24793 + struct super_block *sb;
24794 + aufs_bindex_t bindex, bbot;
24795 + struct au_branch *br;
24798 + bindex = a->mvd_bsrc;
24799 + bbot = au_sbbot(sb);
24800 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24801 + for (bindex++; bindex <= bbot; bindex++) {
24802 + br = au_sbr(sb, bindex);
24803 + if (au_br_fhsm(br->br_perm)
24804 + && !sb_rdonly(au_br_sb(br)))
24807 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24808 + for (bindex++; bindex <= bbot; bindex++) {
24809 + br = au_sbr(sb, bindex);
24810 + if (!au_br_rdonly(br))
24814 + for (bindex++; bindex <= bbot; bindex++) {
24815 + br = au_sbr(sb, bindex);
24816 + if (!sb_rdonly(au_br_sb(br))) {
24817 + if (au_br_rdonly(br))
24819 + |= AUFS_MVDOWN_ROLOWER_R;
24827 +/* make the parent dir on bdst */
24828 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24833 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24834 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24835 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24836 + a->mvd_h_dst_parent = NULL;
24837 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24838 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24839 + if (!a->mvd_h_dst_parent) {
24840 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24841 + if (unlikely(err)) {
24842 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24845 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24853 +/* lock them all */
24854 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24857 + struct dentry *h_trap;
24859 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24860 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24861 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24862 + au_opt_udba(a->sb),
24863 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24865 + if (unlikely(err)) {
24866 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24870 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24871 + a->rename_lock = 0;
24872 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24873 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24874 + au_opt_udba(a->sb),
24875 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24876 + err = au_do_pin(&a->mvd_pin_src);
24878 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24879 + if (unlikely(err)) {
24880 + AU_MVD_PR(dmsg, "pin_src failed\n");
24883 + goto out; /* success */
24886 + a->rename_lock = 1;
24887 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24888 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24889 + au_opt_udba(a->sb),
24890 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24892 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24893 + if (unlikely(err)) {
24894 + AU_MVD_PR(dmsg, "pin_src failed\n");
24895 + au_pin_hdir_lock(&a->mvd_pin_dst);
24898 + au_pin_hdir_unlock(&a->mvd_pin_src);
24899 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24900 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24902 + err = (h_trap != a->mvd_h_src_parent);
24904 + err = (h_trap != a->mvd_h_dst_parent);
24906 + BUG_ON(err); /* it should never happen */
24907 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24910 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24911 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24912 + au_pin_hdir_lock(&a->mvd_pin_src);
24913 + au_unpin(&a->mvd_pin_src);
24914 + au_pin_hdir_lock(&a->mvd_pin_dst);
24917 + goto out; /* success */
24920 + au_unpin(&a->mvd_pin_dst);
24926 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
24928 + if (!a->rename_lock)
24929 + au_unpin(&a->mvd_pin_src);
24931 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24932 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24933 + au_pin_hdir_lock(&a->mvd_pin_src);
24934 + au_unpin(&a->mvd_pin_src);
24935 + au_pin_hdir_lock(&a->mvd_pin_dst);
24937 + au_unpin(&a->mvd_pin_dst);
24940 +/* copy-down the file */
24941 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
24944 + struct au_cp_generic cpg = {
24945 + .dentry = a->dentry,
24946 + .bdst = a->mvd_bdst,
24947 + .bsrc = a->mvd_bsrc,
24949 + .pin = &a->mvd_pin_dst,
24950 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24953 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
24954 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
24955 + au_fset_cpup(cpg.flags, OVERWRITE);
24956 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
24957 + au_fset_cpup(cpg.flags, RWDST);
24958 + err = au_sio_cpdown_simple(&cpg);
24959 + if (unlikely(err))
24960 + AU_MVD_PR(dmsg, "cpdown failed\n");
24967 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
24970 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
24973 + struct path h_path;
24974 + struct au_branch *br;
24975 + struct inode *delegated;
24977 + br = au_sbr(a->sb, a->mvd_bdst);
24978 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
24979 + err = PTR_ERR(h_path.dentry);
24980 + if (IS_ERR(h_path.dentry)) {
24981 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
24986 + if (d_is_positive(h_path.dentry)) {
24987 + h_path.mnt = au_br_mnt(br);
24988 + delegated = NULL;
24989 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
24990 + &delegated, /*force*/0);
24991 + if (unlikely(err == -EWOULDBLOCK)) {
24992 + pr_warn("cannot retry for NFSv4 delegation"
24993 + " for an internal unlink\n");
24996 + if (unlikely(err))
24997 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
24999 + dput(h_path.dentry);
25007 + * unlink the topmost h_dentry
25009 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25012 + struct path h_path;
25013 + struct inode *delegated;
25015 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25016 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25017 + delegated = NULL;
25018 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25019 + if (unlikely(err == -EWOULDBLOCK)) {
25020 + pr_warn("cannot retry for NFSv4 delegation"
25021 + " for an internal unlink\n");
25024 + if (unlikely(err))
25025 + AU_MVD_PR(dmsg, "unlink failed\n");
25031 +/* Since mvdown succeeded, we ignore an error of this function */
25032 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25035 + struct au_branch *br;
25037 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25038 + br = au_sbr(a->sb, a->mvd_bsrc);
25039 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25041 + br = au_sbr(a->sb, a->mvd_bdst);
25042 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25043 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25046 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25048 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25052 + * copy-down the file and unlink the bsrc file.
25053 + * - unlink the bdst whout if exist
25054 + * - copy-down the file (with whtmp name and rename)
25055 + * - unlink the bsrc file
25057 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25061 + err = au_do_mkdir(dmsg, a);
25063 + err = au_do_lock(dmsg, a);
25064 + if (unlikely(err))
25068 + * do not revert the activities we made on bdst since they should be
25069 + * harmless in aufs.
25072 + err = au_do_cpdown(dmsg, a);
25074 + err = au_do_unlink_wh(dmsg, a);
25075 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25076 + err = au_do_unlink(dmsg, a);
25077 + if (unlikely(err))
25080 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25081 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25082 + if (find_lower_writable(a) < 0)
25083 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25085 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25086 + au_do_stfs(dmsg, a);
25088 + /* maintain internal array */
25089 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25090 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25091 + au_set_dbtop(a->dentry, a->mvd_bdst);
25092 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25093 + au_set_ibtop(a->inode, a->mvd_bdst);
25095 + /* hide the lower */
25096 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25097 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25098 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25099 + au_set_ibbot(a->inode, a->mvd_bsrc);
25101 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25102 + au_set_dbbot(a->dentry, a->mvd_bdst);
25103 + if (au_ibbot(a->inode) < a->mvd_bdst)
25104 + au_set_ibbot(a->inode, a->mvd_bdst);
25107 + au_do_unlock(dmsg, a);
25113 +/* ---------------------------------------------------------------------- */
25115 +/* make sure the file is idle */
25116 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25118 + int err, plinked;
25121 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25122 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25123 + && au_dcount(a->dentry) == 1
25124 + && atomic_read(&a->inode->i_count) == 1
25125 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25126 + && (!plinked || !au_plink_test(a->inode))
25127 + && a->inode->i_nlink == 1)
25132 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25133 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25134 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25135 + a->mvd_h_src_inode->i_nlink,
25136 + plinked, plinked ? au_plink_test(a->inode) : 0);
25143 +/* make sure the parent dir is fine */
25144 +static int au_mvd_args_parent(const unsigned char dmsg,
25145 + struct au_mvd_args *a)
25148 + aufs_bindex_t bindex;
25151 + if (unlikely(au_alive_dir(a->parent))) {
25153 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25157 + a->bopq = au_dbdiropq(a->parent);
25158 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25159 + AuDbg("b%d\n", bindex);
25160 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25161 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25163 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25164 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25165 + a->bopq, a->mvd_bdst);
25173 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25174 + struct au_mvd_args *a)
25177 + struct au_dinfo *dinfo, *tmp;
25179 + /* lookup the next lower positive entry */
25181 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25182 + if (unlikely(!tmp))
25187 + dinfo = au_di(a->dentry);
25188 + au_di_cp(tmp, dinfo);
25189 + au_di_swap(tmp, dinfo);
25191 + /* returns the number of positive dentries */
25192 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25193 + /* AuLkup_IGNORE_PERM */ 0);
25195 + a->bwh = au_dbwh(a->dentry);
25196 + else if (err > 0)
25197 + a->bfound = au_dbtop(a->dentry);
25199 + au_di_swap(tmp, dinfo);
25200 + au_rw_write_unlock(&tmp->di_rwsem);
25202 + if (unlikely(err < 0))
25203 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25206 + * here, we have these cases.
25208 + * no positive dentry under bsrc. there are more sub-cases.
25210 + * there no whiteout, we can safely move-down.
25213 + * bsrc < bwh && bwh < bdst
25214 + * there is a whiteout on RO branch. cannot proceed.
25216 + * there is a whiteout on the RW target branch. it should
25219 + * there is a whiteout somewhere unrelated branch.
25220 + * -1 < bfound && bfound <= bsrc
25223 + * found, but it is on RO branch between bsrc and bdst. cannot
25226 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25229 + * found, after we create the file on bdst, it will be hidden.
25232 + AuDebugOn(a->bfound == -1
25234 + && a->bwh <= a->mvd_bsrc);
25235 + AuDebugOn(-1 < a->bfound
25236 + && a->bfound <= a->mvd_bsrc);
25239 + if (a->bfound == -1
25240 + && a->mvd_bsrc < a->bwh
25242 + && a->bwh < a->mvd_bdst) {
25243 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25244 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25245 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25247 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25248 + a->mvd_errno = EAU_MVDOWN_UPPER;
25249 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25250 + a->mvd_bdst, a->bfound);
25254 + err = 0; /* success */
25261 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25266 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25267 + && a->bfound == a->mvd_bdst)
25273 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25276 + struct au_branch *br;
25279 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25283 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25284 + a->mvd_bsrc = au_ibtop(a->inode);
25286 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25287 + if (unlikely(a->mvd_bsrc < 0
25288 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25289 + || au_dbbot(a->dentry) < a->mvd_bsrc
25290 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25291 + || (a->mvd_bsrc < au_ibtop(a->inode)
25292 + || au_ibbot(a->inode) < a->mvd_bsrc
25293 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25294 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25295 + AU_MVD_PR(dmsg, "no upper\n");
25299 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25300 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25301 + AU_MVD_PR(dmsg, "on the bottom\n");
25304 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25305 + br = au_sbr(a->sb, a->mvd_bsrc);
25306 + err = au_br_rdonly(br);
25307 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25308 + if (unlikely(err))
25310 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25311 + || IS_APPEND(a->mvd_h_src_inode))) {
25313 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25319 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25320 + a->mvd_bdst = find_lower_writable(a);
25321 + if (unlikely(a->mvd_bdst < 0)) {
25322 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25323 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25327 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25328 + if (unlikely(a->mvd_bdst < 0
25329 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25330 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25331 + AU_MVD_PR(dmsg, "no lower brid\n");
25336 + err = au_mvd_args_busy(dmsg, a);
25338 + err = au_mvd_args_parent(dmsg, a);
25340 + err = au_mvd_args_intermediate(dmsg, a);
25342 + err = au_mvd_args_exist(dmsg, a);
25344 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25351 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25354 + unsigned char dmsg;
25355 + struct au_mvd_args *args;
25356 + struct inode *inode;
25358 + inode = d_inode(dentry);
25360 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25364 + args = kmalloc(sizeof(*args), GFP_NOFS);
25365 + if (unlikely(!args))
25368 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25370 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25371 + if (unlikely(err)) {
25376 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25377 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25378 + args->mvdown.au_errno = 0;
25379 + args->dentry = dentry;
25380 + args->inode = inode;
25381 + args->sb = dentry->d_sb;
25384 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25385 + args->parent = dget_parent(dentry);
25386 + args->dir = d_inode(args->parent);
25387 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25388 + dput(args->parent);
25389 + if (unlikely(args->parent != dentry->d_parent)) {
25390 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25394 + inode_lock_nested(inode, I_MUTEX_CHILD);
25395 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25396 + if (unlikely(err))
25399 + di_write_lock_parent(args->parent);
25400 + err = au_mvd_args(dmsg, args);
25401 + if (unlikely(err))
25404 + err = au_do_mvdown(dmsg, args);
25405 + if (unlikely(err))
25408 + au_cpup_attr_timesizes(args->dir);
25409 + au_cpup_attr_timesizes(inode);
25410 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25411 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25412 + /* au_digen_dec(dentry); */
25415 + di_write_unlock(args->parent);
25416 + aufs_read_unlock(dentry, AuLock_DW);
25418 + inode_unlock(inode);
25420 + inode_unlock(args->dir);
25422 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25430 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25431 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25432 +++ linux/fs/aufs/opts.c 2018-07-19 09:46:13.059981241 +0200
25434 +/* SPDX-License-Identifier: GPL-2.0 */
25436 + * Copyright (C) 2005-2018 Junjiro R. Okajima
25438 + * This program, aufs is free software; you can redistribute it and/or modify
25439 + * it under the terms of the GNU General Public License as published by
25440 + * the Free Software Foundation; either version 2 of the License, or
25441 + * (at your option) any later version.
25443 + * This program is distributed in the hope that it will be useful,
25444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25446 + * GNU General Public License for more details.
25448 + * You should have received a copy of the GNU General Public License
25449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25453 + * mount options/flags
25456 +#include <linux/namei.h>
25457 +#include <linux/types.h> /* a distribution requires */
25458 +#include <linux/parser.h>
25461 +/* ---------------------------------------------------------------------- */
25465 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25466 + Opt_idel, Opt_imod,
25467 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25468 + Opt_rdblk_def, Opt_rdhash_def,
25469 + Opt_xino, Opt_noxino,
25470 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25471 + Opt_trunc_xino_path, Opt_itrunc_xino,
25472 + Opt_trunc_xib, Opt_notrunc_xib,
25473 + Opt_shwh, Opt_noshwh,
25474 + Opt_plink, Opt_noplink, Opt_list_plink,
25476 + Opt_dio, Opt_nodio,
25477 + Opt_diropq_a, Opt_diropq_w,
25478 + Opt_warn_perm, Opt_nowarn_perm,
25479 + Opt_wbr_copyup, Opt_wbr_create,
25481 + Opt_verbose, Opt_noverbose,
25482 + Opt_sum, Opt_nosum, Opt_wsum,
25483 + Opt_dirperm1, Opt_nodirperm1,
25484 + Opt_dirren, Opt_nodirren,
25485 + Opt_acl, Opt_noacl,
25486 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25489 +static match_table_t options = {
25490 + {Opt_br, "br=%s"},
25491 + {Opt_br, "br:%s"},
25493 + {Opt_add, "add=%d:%s"},
25494 + {Opt_add, "add:%d:%s"},
25495 + {Opt_add, "ins=%d:%s"},
25496 + {Opt_add, "ins:%d:%s"},
25497 + {Opt_append, "append=%s"},
25498 + {Opt_append, "append:%s"},
25499 + {Opt_prepend, "prepend=%s"},
25500 + {Opt_prepend, "prepend:%s"},
25502 + {Opt_del, "del=%s"},
25503 + {Opt_del, "del:%s"},
25504 + /* {Opt_idel, "idel:%d"}, */
25505 + {Opt_mod, "mod=%s"},
25506 + {Opt_mod, "mod:%s"},
25507 + /* {Opt_imod, "imod:%d:%s"}, */
25509 + {Opt_dirwh, "dirwh=%d"},
25511 + {Opt_xino, "xino=%s"},
25512 + {Opt_noxino, "noxino"},
25513 + {Opt_trunc_xino, "trunc_xino"},
25514 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25515 + {Opt_notrunc_xino, "notrunc_xino"},
25516 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25517 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25518 + /* {Opt_zxino, "zxino=%s"}, */
25519 + {Opt_trunc_xib, "trunc_xib"},
25520 + {Opt_notrunc_xib, "notrunc_xib"},
25522 +#ifdef CONFIG_PROC_FS
25523 + {Opt_plink, "plink"},
25525 + {Opt_ignore_silent, "plink"},
25528 + {Opt_noplink, "noplink"},
25530 +#ifdef CONFIG_AUFS_DEBUG
25531 + {Opt_list_plink, "list_plink"},
25534 + {Opt_udba, "udba=%s"},
25536 + {Opt_dio, "dio"},
25537 + {Opt_nodio, "nodio"},
25539 +#ifdef CONFIG_AUFS_DIRREN
25540 + {Opt_dirren, "dirren"},
25541 + {Opt_nodirren, "nodirren"},
25543 + {Opt_ignore, "dirren"},
25544 + {Opt_ignore_silent, "nodirren"},
25547 +#ifdef CONFIG_AUFS_FHSM
25548 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25550 + {Opt_ignore, "fhsm_sec=%d"},
25553 + {Opt_diropq_a, "diropq=always"},
25554 + {Opt_diropq_a, "diropq=a"},
25555 + {Opt_diropq_w, "diropq=whiteouted"},
25556 + {Opt_diropq_w, "diropq=w"},
25558 + {Opt_warn_perm, "warn_perm"},
25559 + {Opt_nowarn_perm, "nowarn_perm"},
25561 + /* keep them temporary */
25562 + {Opt_ignore_silent, "nodlgt"},
25563 + {Opt_ignore, "clean_plink"},
25565 +#ifdef CONFIG_AUFS_SHWH
25566 + {Opt_shwh, "shwh"},
25568 + {Opt_noshwh, "noshwh"},
25570 + {Opt_dirperm1, "dirperm1"},
25571 + {Opt_nodirperm1, "nodirperm1"},
25573 + {Opt_verbose, "verbose"},
25574 + {Opt_verbose, "v"},
25575 + {Opt_noverbose, "noverbose"},
25576 + {Opt_noverbose, "quiet"},
25577 + {Opt_noverbose, "q"},
25578 + {Opt_noverbose, "silent"},
25580 + {Opt_sum, "sum"},
25581 + {Opt_nosum, "nosum"},
25582 + {Opt_wsum, "wsum"},
25584 + {Opt_rdcache, "rdcache=%d"},
25585 + {Opt_rdblk, "rdblk=%d"},
25586 + {Opt_rdblk_def, "rdblk=def"},
25587 + {Opt_rdhash, "rdhash=%d"},
25588 + {Opt_rdhash_def, "rdhash=def"},
25590 + {Opt_wbr_create, "create=%s"},
25591 + {Opt_wbr_create, "create_policy=%s"},
25592 + {Opt_wbr_copyup, "cpup=%s"},
25593 + {Opt_wbr_copyup, "copyup=%s"},
25594 + {Opt_wbr_copyup, "copyup_policy=%s"},
25596 + /* generic VFS flag */
25597 +#ifdef CONFIG_FS_POSIX_ACL
25598 + {Opt_acl, "acl"},
25599 + {Opt_noacl, "noacl"},
25601 + {Opt_ignore, "acl"},
25602 + {Opt_ignore_silent, "noacl"},
25605 + /* internal use for the scripts */
25606 + {Opt_ignore_silent, "si=%s"},
25608 + {Opt_br, "dirs=%s"},
25609 + {Opt_ignore, "debug=%d"},
25610 + {Opt_ignore, "delete=whiteout"},
25611 + {Opt_ignore, "delete=all"},
25612 + {Opt_ignore, "imap=%s"},
25614 + /* temporary workaround, due to old mount(8)? */
25615 + {Opt_ignore_silent, "relatime"},
25620 +/* ---------------------------------------------------------------------- */
25622 +static const char *au_parser_pattern(int val, match_table_t tbl)
25624 + struct match_token *p;
25627 + while (p->pattern) {
25628 + if (p->token == val)
25629 + return p->pattern;
25636 +static const char *au_optstr(int *val, match_table_t tbl)
25638 + struct match_token *p;
25645 + while (p->pattern) {
25647 + && (v & p->token) == p->token) {
25648 + *val &= ~p->token;
25649 + return p->pattern;
25658 +/* ---------------------------------------------------------------------- */
25660 +static match_table_t brperm = {
25661 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25662 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25663 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25667 +static match_table_t brattr = {
25669 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25670 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25671 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25672 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25673 +#ifdef CONFIG_AUFS_FHSM
25674 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25676 +#ifdef CONFIG_AUFS_XATTR
25677 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25678 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25679 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25680 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25681 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25682 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25685 + /* ro/rr branch */
25686 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25689 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25690 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25695 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25702 + p = strchr(str, '+');
25705 + v = match_token(str, table, args);
25707 + if (v & AuBrAttr_CMOO_Mask)
25708 + attr &= ~AuBrAttr_CMOO_Mask;
25713 + pr_warn("ignored branch attribute %s\n", str);
25723 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25731 + p = au_optstr(&perm, brattr);
25734 + memcpy(q, p, sz + 1);
25740 + p = au_optstr(&perm, brattr);
25744 + memcpy(q, p, sz + 1);
25750 + return q - str->a;
25753 +static int noinline_for_stack br_perm_val(char *perm)
25755 + int val, bad, sz;
25757 + substring_t args[MAX_OPT_ARGS];
25758 + au_br_perm_str_t attr;
25760 + p = strchr(perm, '+');
25763 + val = match_token(perm, brperm, args);
25767 + pr_warn("ignored branch permission %s\n", perm);
25768 + val = AuBrPerm_RO;
25774 + val |= br_attr_val(p + 1, brattr, args);
25777 + switch (val & AuBrPerm_Mask) {
25778 + case AuBrPerm_RO:
25779 + case AuBrPerm_RR:
25780 + bad = val & AuBrWAttr_Mask;
25781 + val &= ~AuBrWAttr_Mask;
25783 + case AuBrPerm_RW:
25784 + bad = val & AuBrRAttr_Mask;
25785 + val &= ~AuBrRAttr_Mask;
25790 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25791 + * does not treat it as an error, just warning.
25792 + * this is a tiny guard for the user operation.
25794 + if (val & AuBrAttr_UNPIN) {
25795 + bad |= AuBrAttr_UNPIN;
25796 + val &= ~AuBrAttr_UNPIN;
25799 + if (unlikely(bad)) {
25800 + sz = au_do_optstr_br_attr(&attr, bad);
25802 + pr_warn("ignored branch attribute %s\n", attr.a);
25809 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25811 + au_br_perm_str_t attr;
25817 + p = au_optstr(&perm, brperm);
25818 + AuDebugOn(!p || !*p);
25820 + memcpy(q, p, sz + 1);
25823 + sz = au_do_optstr_br_attr(&attr, perm);
25826 + memcpy(q, attr.a, sz + 1);
25829 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25832 +/* ---------------------------------------------------------------------- */
25834 +static match_table_t udbalevel = {
25835 + {AuOpt_UDBA_REVAL, "reval"},
25836 + {AuOpt_UDBA_NONE, "none"},
25837 +#ifdef CONFIG_AUFS_HNOTIFY
25838 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25839 +#ifdef CONFIG_AUFS_HFSNOTIFY
25840 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25846 +static int noinline_for_stack udba_val(char *str)
25848 + substring_t args[MAX_OPT_ARGS];
25850 + return match_token(str, udbalevel, args);
25853 +const char *au_optstr_udba(int udba)
25855 + return au_parser_pattern(udba, udbalevel);
25858 +/* ---------------------------------------------------------------------- */
25860 +static match_table_t au_wbr_create_policy = {
25861 + {AuWbrCreate_TDP, "tdp"},
25862 + {AuWbrCreate_TDP, "top-down-parent"},
25863 + {AuWbrCreate_RR, "rr"},
25864 + {AuWbrCreate_RR, "round-robin"},
25865 + {AuWbrCreate_MFS, "mfs"},
25866 + {AuWbrCreate_MFS, "most-free-space"},
25867 + {AuWbrCreate_MFSV, "mfs:%d"},
25868 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25870 + /* top-down regardless the parent, and then mfs */
25871 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25872 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25874 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25875 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25876 + {AuWbrCreate_PMFS, "pmfs"},
25877 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25878 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25879 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25884 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25885 + struct au_opt_wbr_create *create)
25888 + unsigned long long ull;
25891 + if (!match_u64(arg, &ull))
25892 + create->mfsrr_watermark = ull;
25894 + pr_err("bad integer in %s\n", str);
25901 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25902 + struct au_opt_wbr_create *create)
25907 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25908 + create->mfs_second = n;
25910 + pr_err("bad integer in %s\n", str);
25917 +static int noinline_for_stack
25918 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
25921 + substring_t args[MAX_OPT_ARGS];
25923 + err = match_token(str, au_wbr_create_policy, args);
25924 + create->wbr_create = err;
25926 + case AuWbrCreate_MFSRRV:
25927 + case AuWbrCreate_TDMFSV:
25928 + case AuWbrCreate_PMFSRRV:
25929 + e = au_wbr_mfs_wmark(&args[0], str, create);
25931 + e = au_wbr_mfs_sec(&args[1], str, create);
25935 + case AuWbrCreate_MFSRR:
25936 + case AuWbrCreate_TDMFS:
25937 + case AuWbrCreate_PMFSRR:
25938 + e = au_wbr_mfs_wmark(&args[0], str, create);
25939 + if (unlikely(e)) {
25944 + case AuWbrCreate_MFS:
25945 + case AuWbrCreate_PMFS:
25946 + create->mfs_second = AUFS_MFS_DEF_SEC;
25948 + case AuWbrCreate_MFSV:
25949 + case AuWbrCreate_PMFSV:
25950 + e = au_wbr_mfs_sec(&args[0], str, create);
25959 +const char *au_optstr_wbr_create(int wbr_create)
25961 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
25964 +static match_table_t au_wbr_copyup_policy = {
25965 + {AuWbrCopyup_TDP, "tdp"},
25966 + {AuWbrCopyup_TDP, "top-down-parent"},
25967 + {AuWbrCopyup_BUP, "bup"},
25968 + {AuWbrCopyup_BUP, "bottom-up-parent"},
25969 + {AuWbrCopyup_BU, "bu"},
25970 + {AuWbrCopyup_BU, "bottom-up"},
25974 +static int noinline_for_stack au_wbr_copyup_val(char *str)
25976 + substring_t args[MAX_OPT_ARGS];
25978 + return match_token(str, au_wbr_copyup_policy, args);
25981 +const char *au_optstr_wbr_copyup(int wbr_copyup)
25983 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
25986 +/* ---------------------------------------------------------------------- */
25988 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
25990 +static void dump_opts(struct au_opts *opts)
25992 +#ifdef CONFIG_AUFS_DEBUG
25993 + /* reduce stack space */
25995 + struct au_opt_add *add;
25996 + struct au_opt_del *del;
25997 + struct au_opt_mod *mod;
25998 + struct au_opt_xino *xino;
25999 + struct au_opt_xino_itrunc *xino_itrunc;
26000 + struct au_opt_wbr_create *create;
26002 + struct au_opt *opt;
26005 + while (opt->type != Opt_tail) {
26006 + switch (opt->type) {
26008 + u.add = &opt->add;
26009 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26010 + u.add->bindex, u.add->pathname, u.add->perm,
26011 + u.add->path.dentry);
26015 + u.del = &opt->del;
26016 + AuDbg("del {%s, %p}\n",
26017 + u.del->pathname, u.del->h_path.dentry);
26021 + u.mod = &opt->mod;
26022 + AuDbg("mod {%s, 0x%x, %p}\n",
26023 + u.mod->path, u.mod->perm, u.mod->h_root);
26026 + u.add = &opt->add;
26027 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26028 + u.add->bindex, u.add->pathname, u.add->perm,
26029 + u.add->path.dentry);
26031 + case Opt_prepend:
26032 + u.add = &opt->add;
26033 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26034 + u.add->bindex, u.add->pathname, u.add->perm,
26035 + u.add->path.dentry);
26038 + AuDbg("dirwh %d\n", opt->dirwh);
26040 + case Opt_rdcache:
26041 + AuDbg("rdcache %d\n", opt->rdcache);
26044 + AuDbg("rdblk %u\n", opt->rdblk);
26046 + case Opt_rdblk_def:
26047 + AuDbg("rdblk_def\n");
26050 + AuDbg("rdhash %u\n", opt->rdhash);
26052 + case Opt_rdhash_def:
26053 + AuDbg("rdhash_def\n");
26056 + u.xino = &opt->xino;
26057 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26059 + case Opt_trunc_xino:
26060 + AuLabel(trunc_xino);
26062 + case Opt_notrunc_xino:
26063 + AuLabel(notrunc_xino);
26065 + case Opt_trunc_xino_path:
26066 + case Opt_itrunc_xino:
26067 + u.xino_itrunc = &opt->xino_itrunc;
26068 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26073 + case Opt_trunc_xib:
26074 + AuLabel(trunc_xib);
26076 + case Opt_notrunc_xib:
26077 + AuLabel(notrunc_xib);
26085 + case Opt_dirperm1:
26086 + AuLabel(dirperm1);
26088 + case Opt_nodirperm1:
26089 + AuLabel(nodirperm1);
26094 + case Opt_noplink:
26095 + AuLabel(noplink);
26097 + case Opt_list_plink:
26098 + AuLabel(list_plink);
26101 + AuDbg("udba %d, %s\n",
26102 + opt->udba, au_optstr_udba(opt->udba));
26110 + case Opt_diropq_a:
26111 + AuLabel(diropq_a);
26113 + case Opt_diropq_w:
26114 + AuLabel(diropq_w);
26116 + case Opt_warn_perm:
26117 + AuLabel(warn_perm);
26119 + case Opt_nowarn_perm:
26120 + AuLabel(nowarn_perm);
26122 + case Opt_verbose:
26123 + AuLabel(verbose);
26125 + case Opt_noverbose:
26126 + AuLabel(noverbose);
26137 + case Opt_wbr_create:
26138 + u.create = &opt->wbr_create;
26139 + AuDbg("create %d, %s\n", u.create->wbr_create,
26140 + au_optstr_wbr_create(u.create->wbr_create));
26141 + switch (u.create->wbr_create) {
26142 + case AuWbrCreate_MFSV:
26143 + case AuWbrCreate_PMFSV:
26144 + AuDbg("%d sec\n", u.create->mfs_second);
26146 + case AuWbrCreate_MFSRR:
26147 + case AuWbrCreate_TDMFS:
26148 + AuDbg("%llu watermark\n",
26149 + u.create->mfsrr_watermark);
26151 + case AuWbrCreate_MFSRRV:
26152 + case AuWbrCreate_TDMFSV:
26153 + case AuWbrCreate_PMFSRRV:
26154 + AuDbg("%llu watermark, %d sec\n",
26155 + u.create->mfsrr_watermark,
26156 + u.create->mfs_second);
26160 + case Opt_wbr_copyup:
26161 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26162 + au_optstr_wbr_copyup(opt->wbr_copyup));
26164 + case Opt_fhsm_sec:
26165 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26170 + case Opt_nodirren:
26171 + AuLabel(nodirren);
26187 +void au_opts_free(struct au_opts *opts)
26189 + struct au_opt *opt;
26192 + while (opt->type != Opt_tail) {
26193 + switch (opt->type) {
26196 + case Opt_prepend:
26197 + path_put(&opt->add.path);
26201 + path_put(&opt->del.h_path);
26205 + dput(opt->mod.h_root);
26208 + fput(opt->xino.file);
26215 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26216 + aufs_bindex_t bindex)
26219 + struct au_opt_add *add = &opt->add;
26222 + add->bindex = bindex;
26223 + add->perm = AuBrPerm_RO;
26224 + add->pathname = opt_str;
26225 + p = strchr(opt_str, '=');
26229 + add->perm = br_perm_val(p);
26232 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26235 + add->perm = AuBrPerm_RO;
26236 + if (au_test_fs_rr(add->path.dentry->d_sb))
26237 + add->perm = AuBrPerm_RR;
26238 + else if (!bindex && !(sb_flags & SB_RDONLY))
26239 + add->perm = AuBrPerm_RW;
26241 + opt->type = Opt_add;
26244 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26251 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26255 + del->pathname = args[0].from;
26256 + AuDbg("del path %s\n", del->pathname);
26258 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26259 + if (unlikely(err))
26260 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26265 +#if 0 /* reserved for future use */
26266 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26267 + struct au_opt_del *del, substring_t args[])
26270 + struct dentry *root;
26273 + root = sb->s_root;
26274 + aufs_read_lock(root, AuLock_FLUSH);
26275 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26276 + pr_err("out of bounds, %d\n", bindex);
26281 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26282 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26285 + aufs_read_unlock(root, !AuLock_IR);
26290 +static int noinline_for_stack
26291 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26294 + struct path path;
26298 + mod->path = args[0].from;
26299 + p = strchr(mod->path, '=');
26300 + if (unlikely(!p)) {
26301 + pr_err("no permssion %s\n", args[0].from);
26306 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26307 + if (unlikely(err)) {
26308 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26312 + mod->perm = br_perm_val(p);
26313 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26314 + mod->h_root = dget(path.dentry);
26321 +#if 0 /* reserved for future use */
26322 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26323 + struct au_opt_mod *mod, substring_t args[])
26326 + struct dentry *root;
26329 + root = sb->s_root;
26330 + aufs_read_lock(root, AuLock_FLUSH);
26331 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26332 + pr_err("out of bounds, %d\n", bindex);
26337 + mod->perm = br_perm_val(args[1].from);
26338 + AuDbg("mod path %s, perm 0x%x, %s\n",
26339 + mod->path, mod->perm, args[1].from);
26340 + mod->h_root = dget(au_h_dptr(root, bindex));
26343 + aufs_read_unlock(root, !AuLock_IR);
26348 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26349 + substring_t args[])
26352 + struct file *file;
26354 + file = au_xino_create(sb, args[0].from, /*silent*/0);
26355 + err = PTR_ERR(file);
26356 + if (IS_ERR(file))
26360 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26362 + pr_err("%s must be outside\n", args[0].from);
26367 + xino->file = file;
26368 + xino->path = args[0].from;
26374 +static int noinline_for_stack
26375 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26376 + struct au_opt_xino_itrunc *xino_itrunc,
26377 + substring_t args[])
26380 + aufs_bindex_t bbot, bindex;
26381 + struct path path;
26382 + struct dentry *root;
26384 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26385 + if (unlikely(err)) {
26386 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26390 + xino_itrunc->bindex = -1;
26391 + root = sb->s_root;
26392 + aufs_read_lock(root, AuLock_FLUSH);
26393 + bbot = au_sbbot(sb);
26394 + for (bindex = 0; bindex <= bbot; bindex++) {
26395 + if (au_h_dptr(root, bindex) == path.dentry) {
26396 + xino_itrunc->bindex = bindex;
26400 + aufs_read_unlock(root, !AuLock_IR);
26403 + if (unlikely(xino_itrunc->bindex < 0)) {
26404 + pr_err("no such branch %s\n", args[0].from);
26412 +/* called without aufs lock */
26413 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26415 + int err, n, token;
26416 + aufs_bindex_t bindex;
26417 + unsigned char skipped;
26418 + struct dentry *root;
26419 + struct au_opt *opt, *opt_tail;
26421 + /* reduce the stack space */
26423 + struct au_opt_xino_itrunc *xino_itrunc;
26424 + struct au_opt_wbr_create *create;
26427 + substring_t args[MAX_OPT_ARGS];
26431 + a = kmalloc(sizeof(*a), GFP_NOFS);
26432 + if (unlikely(!a))
26435 + root = sb->s_root;
26439 + opt_tail = opt + opts->max_opt - 1;
26440 + opt->type = Opt_tail;
26441 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26444 + token = match_token(opt_str, options, a->args);
26448 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26450 + err = opt_add(opt, opt_str, opts->sb_flags,
26452 + if (unlikely(!err && ++opt > opt_tail)) {
26456 + opt->type = Opt_tail;
26461 + if (unlikely(match_int(&a->args[0], &n))) {
26462 + pr_err("bad integer in %s\n", opt_str);
26466 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26469 + opt->type = token;
26472 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26473 + /*dummy bindex*/1);
26475 + opt->type = token;
26477 + case Opt_prepend:
26478 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26481 + opt->type = token;
26484 + err = au_opts_parse_del(&opt->del, a->args);
26486 + opt->type = token;
26488 +#if 0 /* reserved for future use */
26490 + del->pathname = "(indexed)";
26491 + if (unlikely(match_int(&args[0], &n))) {
26492 + pr_err("bad integer in %s\n", opt_str);
26495 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26497 + opt->type = token;
26501 + err = au_opts_parse_mod(&opt->mod, a->args);
26503 + opt->type = token;
26505 +#ifdef IMOD /* reserved for future use */
26507 + u.mod->path = "(indexed)";
26508 + if (unlikely(match_int(&a->args[0], &n))) {
26509 + pr_err("bad integer in %s\n", opt_str);
26512 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26514 + opt->type = token;
26518 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26520 + opt->type = token;
26523 + case Opt_trunc_xino_path:
26524 + err = au_opts_parse_xino_itrunc_path
26525 + (sb, &opt->xino_itrunc, a->args);
26527 + opt->type = token;
26530 + case Opt_itrunc_xino:
26531 + u.xino_itrunc = &opt->xino_itrunc;
26532 + if (unlikely(match_int(&a->args[0], &n))) {
26533 + pr_err("bad integer in %s\n", opt_str);
26536 + u.xino_itrunc->bindex = n;
26537 + aufs_read_lock(root, AuLock_FLUSH);
26538 + if (n < 0 || au_sbbot(sb) < n) {
26539 + pr_err("out of bounds, %d\n", n);
26540 + aufs_read_unlock(root, !AuLock_IR);
26543 + aufs_read_unlock(root, !AuLock_IR);
26545 + opt->type = token;
26549 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26552 + opt->type = token;
26555 + case Opt_rdcache:
26556 + if (unlikely(match_int(&a->args[0], &n))) {
26557 + pr_err("bad integer in %s\n", opt_str);
26560 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26561 + pr_err("rdcache must be smaller than %d\n",
26562 + AUFS_RDCACHE_MAX);
26565 + opt->rdcache = n;
26567 + opt->type = token;
26570 + if (unlikely(match_int(&a->args[0], &n)
26572 + || n > KMALLOC_MAX_SIZE)) {
26573 + pr_err("bad integer in %s\n", opt_str);
26576 + if (unlikely(n && n < NAME_MAX)) {
26577 + pr_err("rdblk must be larger than %d\n",
26583 + opt->type = token;
26586 + if (unlikely(match_int(&a->args[0], &n)
26588 + || n * sizeof(struct hlist_head)
26589 + > KMALLOC_MAX_SIZE)) {
26590 + pr_err("bad integer in %s\n", opt_str);
26595 + opt->type = token;
26598 + case Opt_trunc_xino:
26599 + case Opt_notrunc_xino:
26601 + case Opt_trunc_xib:
26602 + case Opt_notrunc_xib:
26605 + case Opt_dirperm1:
26606 + case Opt_nodirperm1:
26608 + case Opt_noplink:
26609 + case Opt_list_plink:
26612 + case Opt_diropq_a:
26613 + case Opt_diropq_w:
26614 + case Opt_warn_perm:
26615 + case Opt_nowarn_perm:
26616 + case Opt_verbose:
26617 + case Opt_noverbose:
26621 + case Opt_rdblk_def:
26622 + case Opt_rdhash_def:
26624 + case Opt_nodirren:
26628 + opt->type = token;
26632 + opt->udba = udba_val(a->args[0].from);
26633 + if (opt->udba >= 0) {
26635 + opt->type = token;
26637 + pr_err("wrong value, %s\n", opt_str);
26640 + case Opt_wbr_create:
26641 + u.create = &opt->wbr_create;
26642 + u.create->wbr_create
26643 + = au_wbr_create_val(a->args[0].from, u.create);
26644 + if (u.create->wbr_create >= 0) {
26646 + opt->type = token;
26648 + pr_err("wrong value, %s\n", opt_str);
26650 + case Opt_wbr_copyup:
26651 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26652 + if (opt->wbr_copyup >= 0) {
26654 + opt->type = token;
26656 + pr_err("wrong value, %s\n", opt_str);
26659 + case Opt_fhsm_sec:
26660 + if (unlikely(match_int(&a->args[0], &n)
26662 + pr_err("bad integer in %s\n", opt_str);
26665 + if (sysaufs_brs) {
26666 + opt->fhsm_second = n;
26667 + opt->type = token;
26669 + pr_warn("ignored %s\n", opt_str);
26674 + pr_warn("ignored %s\n", opt_str);
26676 + case Opt_ignore_silent:
26681 + pr_err("unknown option %s\n", opt_str);
26685 + if (!err && !skipped) {
26686 + if (unlikely(++opt > opt_tail)) {
26689 + opt->type = Opt_tail;
26692 + opt->type = Opt_tail;
26698 + if (unlikely(err))
26699 + au_opts_free(opts);
26705 +static int au_opt_wbr_create(struct super_block *sb,
26706 + struct au_opt_wbr_create *create)
26709 + struct au_sbinfo *sbinfo;
26711 + SiMustWriteLock(sb);
26713 + err = 1; /* handled */
26714 + sbinfo = au_sbi(sb);
26715 + if (sbinfo->si_wbr_create_ops->fin) {
26716 + err = sbinfo->si_wbr_create_ops->fin(sb);
26721 + sbinfo->si_wbr_create = create->wbr_create;
26722 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26723 + switch (create->wbr_create) {
26724 + case AuWbrCreate_MFSRRV:
26725 + case AuWbrCreate_MFSRR:
26726 + case AuWbrCreate_TDMFS:
26727 + case AuWbrCreate_TDMFSV:
26728 + case AuWbrCreate_PMFSRR:
26729 + case AuWbrCreate_PMFSRRV:
26730 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26732 + case AuWbrCreate_MFS:
26733 + case AuWbrCreate_MFSV:
26734 + case AuWbrCreate_PMFS:
26735 + case AuWbrCreate_PMFSV:
26736 + sbinfo->si_wbr_mfs.mfs_expire
26737 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26741 + if (sbinfo->si_wbr_create_ops->init)
26742 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26749 + * plus: processed without an error
26750 + * zero: unprocessed
26752 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26753 + struct au_opts *opts)
26756 + struct au_sbinfo *sbinfo;
26758 + SiMustWriteLock(sb);
26760 + err = 1; /* handled */
26761 + sbinfo = au_sbi(sb);
26762 + switch (opt->type) {
26764 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26765 + sbinfo->si_mntflags |= opt->udba;
26766 + opts->given_udba |= opt->udba;
26770 + au_opt_set(sbinfo->si_mntflags, PLINK);
26772 + case Opt_noplink:
26773 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26774 + au_plink_put(sb, /*verbose*/1);
26775 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26777 + case Opt_list_plink:
26778 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26779 + au_plink_list(sb);
26783 + au_opt_set(sbinfo->si_mntflags, DIO);
26784 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26787 + au_opt_clr(sbinfo->si_mntflags, DIO);
26788 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26791 + case Opt_fhsm_sec:
26792 + au_fhsm_set(sbinfo, opt->fhsm_second);
26795 + case Opt_diropq_a:
26796 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26798 + case Opt_diropq_w:
26799 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26802 + case Opt_warn_perm:
26803 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26805 + case Opt_nowarn_perm:
26806 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26809 + case Opt_verbose:
26810 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26812 + case Opt_noverbose:
26813 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26817 + au_opt_set(sbinfo->si_mntflags, SUM);
26820 + au_opt_clr(sbinfo->si_mntflags, SUM);
26821 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26823 + au_opt_clr(sbinfo->si_mntflags, SUM);
26824 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26827 + case Opt_wbr_create:
26828 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26830 + case Opt_wbr_copyup:
26831 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26832 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26836 + sbinfo->si_dirwh = opt->dirwh;
26839 + case Opt_rdcache:
26840 + sbinfo->si_rdcache
26841 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26844 + sbinfo->si_rdblk = opt->rdblk;
26846 + case Opt_rdblk_def:
26847 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26850 + sbinfo->si_rdhash = opt->rdhash;
26852 + case Opt_rdhash_def:
26853 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26857 + au_opt_set(sbinfo->si_mntflags, SHWH);
26860 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26863 + case Opt_dirperm1:
26864 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26866 + case Opt_nodirperm1:
26867 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26870 + case Opt_trunc_xino:
26871 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26873 + case Opt_notrunc_xino:
26874 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26877 + case Opt_trunc_xino_path:
26878 + case Opt_itrunc_xino:
26879 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
26884 + case Opt_trunc_xib:
26885 + au_fset_opts(opts->flags, TRUNC_XIB);
26887 + case Opt_notrunc_xib:
26888 + au_fclr_opts(opts->flags, TRUNC_XIB);
26893 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26894 + err = au_dr_opt_set(sb);
26899 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26901 + case Opt_nodirren:
26903 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26904 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26910 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26914 + sb->s_flags |= SB_POSIXACL;
26917 + sb->s_flags &= ~SB_POSIXACL;
26929 + * returns tri-state.
26930 + * plus: processed without an error
26931 + * zero: unprocessed
26934 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
26935 + struct au_opts *opts)
26937 + int err, do_refresh;
26940 + switch (opt->type) {
26942 + opt->add.bindex = au_sbbot(sb) + 1;
26943 + if (opt->add.bindex < 0)
26944 + opt->add.bindex = 0;
26946 + case Opt_prepend:
26947 + opt->add.bindex = 0;
26948 + add: /* indented label */
26950 + err = au_br_add(sb, &opt->add,
26951 + au_ftest_opts(opts->flags, REMOUNT));
26954 + au_fset_opts(opts->flags, REFRESH);
26960 + err = au_br_del(sb, &opt->del,
26961 + au_ftest_opts(opts->flags, REMOUNT));
26964 + au_fset_opts(opts->flags, TRUNC_XIB);
26965 + au_fset_opts(opts->flags, REFRESH);
26971 + err = au_br_mod(sb, &opt->mod,
26972 + au_ftest_opts(opts->flags, REMOUNT),
26977 + au_fset_opts(opts->flags, REFRESH);
26984 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
26985 + struct au_opt_xino **opt_xino,
26986 + struct au_opts *opts)
26989 + aufs_bindex_t bbot, bindex;
26990 + struct dentry *root, *parent, *h_root;
26993 + switch (opt->type) {
26995 + au_xino_brid_set(sb, -1);
26996 + /* safe d_parent access */
26997 + parent = opt->xino.file->f_path.dentry->d_parent;
26998 + root = sb->s_root;
26999 + bbot = au_sbbot(sb);
27000 + for (bindex = 0; bindex <= bbot; bindex++) {
27001 + h_root = au_h_dptr(root, bindex);
27002 + if (h_root == parent) {
27003 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
27008 + err = au_xino_set(sb, &opt->xino,
27009 + !!au_ftest_opts(opts->flags, REMOUNT));
27010 + if (unlikely(err))
27013 + *opt_xino = &opt->xino;
27018 + *opt_xino = (void *)-1;
27025 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27026 + unsigned int pending)
27029 + aufs_bindex_t bindex, bbot;
27030 + unsigned char do_plink, skip, do_free, can_no_dreval;
27031 + struct au_branch *br;
27032 + struct au_wbr *wbr;
27033 + struct dentry *root, *dentry;
27034 + struct inode *dir, *h_dir;
27035 + struct au_sbinfo *sbinfo;
27036 + struct au_hinode *hdir;
27038 + SiMustAnyLock(sb);
27040 + sbinfo = au_sbi(sb);
27041 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27043 + if (!(sb_flags & SB_RDONLY)) {
27044 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27045 + pr_warn("first branch should be rw\n");
27046 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27047 + pr_warn_once("shwh should be used with ro\n");
27050 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27051 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27052 + pr_warn_once("udba=*notify requires xino\n");
27054 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27055 + pr_warn_once("dirperm1 breaks the protection"
27056 + " by the permission bits on the lower branch\n");
27060 + root = sb->s_root;
27061 + dir = d_inode(root);
27062 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27063 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27065 + bbot = au_sbbot(sb);
27066 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27068 + h_dir = au_h_iptr(dir, bindex);
27069 + br = au_sbr(sb, bindex);
27071 + if ((br->br_perm & AuBrAttr_ICEX)
27072 + && !h_dir->i_op->listxattr)
27073 + br->br_perm &= ~AuBrAttr_ICEX;
27075 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27076 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27077 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27081 + wbr = br->br_wbr;
27083 + wbr_wh_read_lock(wbr);
27085 + if (!au_br_writable(br->br_perm)) {
27088 + || (!wbr->wbr_whbase
27089 + && !wbr->wbr_plink
27090 + && !wbr->wbr_orph));
27091 + } else if (!au_br_wh_linkable(br->br_perm)) {
27092 + /* skip = (!br->br_whbase && !br->br_orph); */
27093 + skip = (!wbr || !wbr->wbr_whbase);
27094 + if (skip && wbr) {
27096 + skip = !!wbr->wbr_plink;
27098 + skip = !wbr->wbr_plink;
27101 + /* skip = (br->br_whbase && br->br_ohph); */
27102 + skip = (wbr && wbr->wbr_whbase);
27105 + skip = !!wbr->wbr_plink;
27107 + skip = !wbr->wbr_plink;
27111 + wbr_wh_read_unlock(wbr);
27113 + if (can_no_dreval) {
27114 + dentry = br->br_path.dentry;
27115 + spin_lock(&dentry->d_lock);
27116 + if (dentry->d_flags &
27117 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27118 + can_no_dreval = 0;
27119 + spin_unlock(&dentry->d_lock);
27122 + if (au_br_fhsm(br->br_perm)) {
27124 + AuDebugOn(!br->br_fhsm);
27130 + hdir = au_hi(dir, bindex);
27131 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27133 + wbr_wh_write_lock(wbr);
27134 + err = au_wh_init(br, sb);
27136 + wbr_wh_write_unlock(wbr);
27137 + au_hn_inode_unlock(hdir);
27139 + if (!err && do_free) {
27141 + br->br_wbr = NULL;
27145 + if (can_no_dreval)
27146 + au_fset_si(sbinfo, NO_DREVAL);
27148 + au_fclr_si(sbinfo, NO_DREVAL);
27151 + au_fset_si(sbinfo, FHSM);
27152 + for (bindex = bbot; bindex >= 0; bindex--) {
27153 + br = au_sbr(sb, bindex);
27154 + if (au_br_fhsm(br->br_perm)) {
27155 + au_fhsm_set_bottom(sb, bindex);
27160 + au_fclr_si(sbinfo, FHSM);
27161 + au_fhsm_set_bottom(sb, -1);
27167 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27170 + unsigned int tmp;
27171 + aufs_bindex_t bindex, bbot;
27172 + struct au_opt *opt;
27173 + struct au_opt_xino *opt_xino, xino;
27174 + struct au_sbinfo *sbinfo;
27175 + struct au_branch *br;
27176 + struct inode *dir;
27178 + SiMustWriteLock(sb);
27183 + while (err >= 0 && opt->type != Opt_tail)
27184 + err = au_opt_simple(sb, opt++, opts);
27187 + else if (unlikely(err < 0))
27190 + /* disable xino and udba temporary */
27191 + sbinfo = au_sbi(sb);
27192 + tmp = sbinfo->si_mntflags;
27193 + au_opt_clr(sbinfo->si_mntflags, XINO);
27194 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27197 + while (err >= 0 && opt->type != Opt_tail)
27198 + err = au_opt_br(sb, opt++, opts);
27201 + else if (unlikely(err < 0))
27204 + bbot = au_sbbot(sb);
27205 + if (unlikely(bbot < 0)) {
27207 + pr_err("no branches\n");
27211 + if (au_opt_test(tmp, XINO))
27212 + au_opt_set(sbinfo->si_mntflags, XINO);
27214 + while (!err && opt->type != Opt_tail)
27215 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27216 + if (unlikely(err))
27219 + err = au_opts_verify(sb, sb->s_flags, tmp);
27220 + if (unlikely(err))
27223 + /* restore xino */
27224 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27225 + xino.file = au_xino_def(sb);
27226 + err = PTR_ERR(xino.file);
27227 + if (IS_ERR(xino.file))
27230 + err = au_xino_set(sb, &xino, /*remount*/0);
27232 + if (unlikely(err))
27236 + /* restore udba */
27237 + tmp &= AuOptMask_UDBA;
27238 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27239 + sbinfo->si_mntflags |= tmp;
27240 + bbot = au_sbbot(sb);
27241 + for (bindex = 0; bindex <= bbot; bindex++) {
27242 + br = au_sbr(sb, bindex);
27243 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27244 + if (unlikely(err))
27245 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27247 + /* go on even if err */
27249 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27250 + dir = d_inode(sb->s_root);
27251 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27258 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27261 + unsigned char no_dreval;
27262 + struct inode *dir;
27263 + struct au_opt_xino *opt_xino;
27264 + struct au_opt *opt;
27265 + struct au_sbinfo *sbinfo;
27267 + SiMustWriteLock(sb);
27269 + err = au_dr_opt_flush(sb);
27270 + if (unlikely(err))
27272 + au_fset_opts(opts->flags, DR_FLUSHED);
27274 + dir = d_inode(sb->s_root);
27275 + sbinfo = au_sbi(sb);
27278 + while (err >= 0 && opt->type != Opt_tail) {
27279 + err = au_opt_simple(sb, opt, opts);
27281 + err = au_opt_br(sb, opt, opts);
27283 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27289 + /* go on even err */
27291 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27292 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27293 + if (unlikely(rerr && !err))
27296 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27297 + au_fset_opts(opts->flags, REFRESH_IDOP);
27299 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27300 + rerr = au_xib_trunc(sb);
27301 + if (unlikely(rerr && !err))
27305 + /* will be handled by the caller */
27306 + if (!au_ftest_opts(opts->flags, REFRESH)
27307 + && (opts->given_udba
27308 + || au_opt_test(sbinfo->si_mntflags, XINO)
27309 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27311 + au_fset_opts(opts->flags, REFRESH);
27313 + AuDbg("status 0x%x\n", opts->flags);
27319 +/* ---------------------------------------------------------------------- */
27321 +unsigned int au_opt_udba(struct super_block *sb)
27323 + return au_mntflags(sb) & AuOptMask_UDBA;
27325 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27326 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27327 +++ linux/fs/aufs/opts.h 2018-07-19 09:46:13.063314675 +0200
27329 +/* SPDX-License-Identifier: GPL-2.0 */
27331 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27333 + * This program, aufs is free software; you can redistribute it and/or modify
27334 + * it under the terms of the GNU General Public License as published by
27335 + * the Free Software Foundation; either version 2 of the License, or
27336 + * (at your option) any later version.
27338 + * This program is distributed in the hope that it will be useful,
27339 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27341 + * GNU General Public License for more details.
27343 + * You should have received a copy of the GNU General Public License
27344 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27348 + * mount options/flags
27351 +#ifndef __AUFS_OPTS_H__
27352 +#define __AUFS_OPTS_H__
27356 +#include <linux/path.h>
27360 +/* ---------------------------------------------------------------------- */
27363 +#define AuOpt_XINO 1 /* external inode number bitmap
27364 + and translation table */
27365 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27366 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27367 +#define AuOpt_UDBA_REVAL (1 << 3)
27368 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27369 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27370 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27371 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27373 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27374 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27375 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27376 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27377 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
27378 +#define AuOpt_DIO (1 << 14) /* direct io */
27379 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27381 +#ifndef CONFIG_AUFS_HNOTIFY
27382 +#undef AuOpt_UDBA_HNOTIFY
27383 +#define AuOpt_UDBA_HNOTIFY 0
27385 +#ifndef CONFIG_AUFS_DIRREN
27386 +#undef AuOpt_DIRREN
27387 +#define AuOpt_DIRREN 0
27389 +#ifndef CONFIG_AUFS_SHWH
27391 +#define AuOpt_SHWH 0
27394 +#define AuOpt_Def (AuOpt_XINO \
27395 + | AuOpt_UDBA_REVAL \
27397 + /* | AuOpt_DIRPERM1 */ \
27398 + | AuOpt_WARN_PERM)
27399 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27400 + | AuOpt_UDBA_REVAL \
27401 + | AuOpt_UDBA_HNOTIFY)
27403 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27404 +#define au_opt_set(flags, name) do { \
27405 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27406 + ((flags) |= AuOpt_##name); \
27408 +#define au_opt_set_udba(flags, name) do { \
27409 + (flags) &= ~AuOptMask_UDBA; \
27410 + ((flags) |= AuOpt_##name); \
27412 +#define au_opt_clr(flags, name) do { \
27413 + ((flags) &= ~AuOpt_##name); \
27416 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27418 +#ifdef CONFIG_PROC_FS
27421 + return mntflags & ~AuOpt_PLINK;
27425 +/* ---------------------------------------------------------------------- */
27427 +/* policies to select one among multiple writable branches */
27429 + AuWbrCreate_TDP, /* top down parent */
27430 + AuWbrCreate_RR, /* round robin */
27431 + AuWbrCreate_MFS, /* most free space */
27432 + AuWbrCreate_MFSV, /* mfs with seconds */
27433 + AuWbrCreate_MFSRR, /* mfs then rr */
27434 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27435 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27436 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27437 + AuWbrCreate_PMFS, /* parent and mfs */
27438 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27439 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27440 + AuWbrCreate_PMFSRRV, /* plus seconds */
27442 + AuWbrCreate_Def = AuWbrCreate_TDP
27446 + AuWbrCopyup_TDP, /* top down parent */
27447 + AuWbrCopyup_BUP, /* bottom up parent */
27448 + AuWbrCopyup_BU, /* bottom up */
27450 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27453 +/* ---------------------------------------------------------------------- */
27455 +struct au_opt_add {
27456 + aufs_bindex_t bindex;
27459 + struct path path;
27462 +struct au_opt_del {
27464 + struct path h_path;
27467 +struct au_opt_mod {
27470 + struct dentry *h_root;
27473 +struct au_opt_xino {
27475 + struct file *file;
27478 +struct au_opt_xino_itrunc {
27479 + aufs_bindex_t bindex;
27482 +struct au_opt_wbr_create {
27485 + unsigned long long mfsrr_watermark;
27491 + struct au_opt_xino xino;
27492 + struct au_opt_xino_itrunc xino_itrunc;
27493 + struct au_opt_add add;
27494 + struct au_opt_del del;
27495 + struct au_opt_mod mod;
27498 + unsigned int rdblk;
27499 + unsigned int rdhash;
27501 + struct au_opt_wbr_create wbr_create;
27503 + unsigned int fhsm_second;
27508 +#define AuOpts_REMOUNT 1
27509 +#define AuOpts_REFRESH (1 << 1)
27510 +#define AuOpts_TRUNC_XIB (1 << 2)
27511 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27512 +#define AuOpts_REFRESH_IDOP (1 << 4)
27513 +#define AuOpts_DR_FLUSHED (1 << 5)
27514 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27515 +#define au_fset_opts(flags, name) \
27516 + do { (flags) |= AuOpts_##name; } while (0)
27517 +#define au_fclr_opts(flags, name) \
27518 + do { (flags) &= ~AuOpts_##name; } while (0)
27520 +#ifndef CONFIG_AUFS_DIRREN
27521 +#undef AuOpts_DR_FLUSHED
27522 +#define AuOpts_DR_FLUSHED 0
27526 + struct au_opt *opt;
27529 + unsigned int given_udba;
27530 + unsigned int flags;
27531 + unsigned long sb_flags;
27534 +/* ---------------------------------------------------------------------- */
27537 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27538 +const char *au_optstr_udba(int udba);
27539 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27540 +const char *au_optstr_wbr_create(int wbr_create);
27542 +void au_opts_free(struct au_opts *opts);
27543 +struct super_block;
27544 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27545 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27546 + unsigned int pending);
27547 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27548 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27550 +unsigned int au_opt_udba(struct super_block *sb);
27552 +#endif /* __KERNEL__ */
27553 +#endif /* __AUFS_OPTS_H__ */
27554 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27555 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27556 +++ linux/fs/aufs/plink.c 2018-07-19 09:46:13.063314675 +0200
27558 +/* SPDX-License-Identifier: GPL-2.0 */
27560 + * Copyright (C) 2005-2018 Junjiro R. Okajima
27562 + * This program, aufs is free software; you can redistribute it and/or modify
27563 + * it under the terms of the GNU General Public License as published by
27564 + * the Free Software Foundation; either version 2 of the License, or
27565 + * (at your option) any later version.
27567 + * This program is distributed in the hope that it will be useful,
27568 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27569 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27570 + * GNU General Public License for more details.
27572 + * You should have received a copy of the GNU General Public License
27573 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27583 + * the pseudo-link maintenance mode.
27584 + * during a user process maintains the pseudo-links,
27585 + * prohibit adding a new plink and branch manipulation.
27589 + * For entry functions which will handle plink, and i_mutex is already held
27591 + * They cannot wait and should return an error at once.
27592 + * Callers has to check the error.
27594 + * For entry functions which will handle plink, but i_mutex is not held
27596 + * They can wait the plink maintenance mode to finish.
27598 + * They behave like F_SETLK and F_SETLKW.
27599 + * If the caller never handle plink, then both flags are unnecessary.
27602 +int au_plink_maint(struct super_block *sb, int flags)
27606 + struct task_struct *parent, *prev;
27607 + struct au_sbinfo *sbi;
27609 + SiMustAnyLock(sb);
27612 + if (!au_opt_test(au_mntflags(sb), PLINK))
27615 + sbi = au_sbi(sb);
27616 + pid = sbi->si_plink_maint_pid;
27617 + if (!pid || pid == current->pid)
27620 + /* todo: it highly depends upon /sbin/mount.aufs */
27622 + parent = current;
27626 + parent = rcu_dereference(parent->real_parent);
27627 + if (parent == prev)
27629 + ppid = task_pid_vnr(parent);
27630 + if (pid == ppid) {
27631 + rcu_read_unlock();
27636 + rcu_read_unlock();
27638 + if (au_ftest_lock(flags, NOPLMW)) {
27639 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27640 + /* AuDebugOn(!lockdep_depth(current)); */
27641 + while (sbi->si_plink_maint_pid) {
27642 + si_read_unlock(sb);
27643 + /* gave up wake_up_bit() */
27644 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27646 + if (au_ftest_lock(flags, FLUSH))
27647 + au_nwt_flush(&sbi->si_nowait);
27648 + si_noflush_read_lock(sb);
27650 + } else if (au_ftest_lock(flags, NOPLM)) {
27651 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27659 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27661 + spin_lock(&sbinfo->si_plink_maint_lock);
27662 + sbinfo->si_plink_maint_pid = 0;
27663 + spin_unlock(&sbinfo->si_plink_maint_lock);
27664 + wake_up_all(&sbinfo->si_plink_wq);
27667 +int au_plink_maint_enter(struct super_block *sb)
27670 + struct au_sbinfo *sbinfo;
27673 + sbinfo = au_sbi(sb);
27674 + /* make sure i am the only one in this fs */
27675 + si_write_lock(sb, AuLock_FLUSH);
27676 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27677 + spin_lock(&sbinfo->si_plink_maint_lock);
27678 + if (!sbinfo->si_plink_maint_pid)
27679 + sbinfo->si_plink_maint_pid = current->pid;
27682 + spin_unlock(&sbinfo->si_plink_maint_lock);
27684 + si_write_unlock(sb);
27689 +/* ---------------------------------------------------------------------- */
27691 +#ifdef CONFIG_AUFS_DEBUG
27692 +void au_plink_list(struct super_block *sb)
27695 + struct au_sbinfo *sbinfo;
27696 + struct hlist_bl_head *hbl;
27697 + struct hlist_bl_node *pos;
27698 + struct au_icntnr *icntnr;
27700 + SiMustAnyLock(sb);
27702 + sbinfo = au_sbi(sb);
27703 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27704 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27706 + for (i = 0; i < AuPlink_NHASH; i++) {
27707 + hbl = sbinfo->si_plink + i;
27708 + hlist_bl_lock(hbl);
27709 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27710 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27711 + hlist_bl_unlock(hbl);
27716 +/* is the inode pseudo-linked? */
27717 +int au_plink_test(struct inode *inode)
27720 + struct au_sbinfo *sbinfo;
27721 + struct hlist_bl_head *hbl;
27722 + struct hlist_bl_node *pos;
27723 + struct au_icntnr *icntnr;
27725 + sbinfo = au_sbi(inode->i_sb);
27726 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27727 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27728 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27731 + i = au_plink_hash(inode->i_ino);
27732 + hbl = sbinfo->si_plink + i;
27733 + hlist_bl_lock(hbl);
27734 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27735 + if (&icntnr->vfs_inode == inode) {
27739 + hlist_bl_unlock(hbl);
27743 +/* ---------------------------------------------------------------------- */
27746 + * generate a name for plink.
27747 + * the file will be stored under AUFS_WH_PLINKDIR.
27749 +/* 20 is max digits length of ulong 64 */
27750 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27752 +static int plink_name(char *name, int len, struct inode *inode,
27753 + aufs_bindex_t bindex)
27756 + struct inode *h_inode;
27758 + h_inode = au_h_iptr(inode, bindex);
27759 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27763 +struct au_do_plink_lkup_args {
27764 + struct dentry **errp;
27765 + struct qstr *tgtname;
27766 + struct dentry *h_parent;
27767 + struct au_branch *br;
27770 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27771 + struct dentry *h_parent,
27772 + struct au_branch *br)
27774 + struct dentry *h_dentry;
27775 + struct inode *h_inode;
27777 + h_inode = d_inode(h_parent);
27778 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27779 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27780 + inode_unlock_shared(h_inode);
27784 +static void au_call_do_plink_lkup(void *args)
27786 + struct au_do_plink_lkup_args *a = args;
27787 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27790 +/* lookup the plink-ed @inode under the branch at @bindex */
27791 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27793 + struct dentry *h_dentry, *h_parent;
27794 + struct au_branch *br;
27796 + char a[PLINK_NAME_LEN];
27797 + struct qstr tgtname = QSTR_INIT(a, 0);
27799 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27801 + br = au_sbr(inode->i_sb, bindex);
27802 + h_parent = br->br_wbr->wbr_plink;
27803 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27805 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27806 + struct au_do_plink_lkup_args args = {
27807 + .errp = &h_dentry,
27808 + .tgtname = &tgtname,
27809 + .h_parent = h_parent,
27813 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27814 + if (unlikely(wkq_err))
27815 + h_dentry = ERR_PTR(wkq_err);
27817 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27822 +/* create a pseudo-link */
27823 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27824 + struct dentry *h_dentry, struct au_branch *br)
27827 + struct path h_path = {
27828 + .mnt = au_br_mnt(br)
27830 + struct inode *h_dir, *delegated;
27832 + h_dir = d_inode(h_parent);
27833 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27835 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27836 + err = PTR_ERR(h_path.dentry);
27837 + if (IS_ERR(h_path.dentry))
27841 + /* wh.plink dir is not monitored */
27842 + /* todo: is it really safe? */
27843 + if (d_is_positive(h_path.dentry)
27844 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27845 + delegated = NULL;
27846 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27847 + if (unlikely(err == -EWOULDBLOCK)) {
27848 + pr_warn("cannot retry for NFSv4 delegation"
27849 + " for an internal unlink\n");
27852 + dput(h_path.dentry);
27853 + h_path.dentry = NULL;
27857 + if (!err && d_is_negative(h_path.dentry)) {
27858 + delegated = NULL;
27859 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27860 + if (unlikely(err == -EWOULDBLOCK)) {
27861 + pr_warn("cannot retry for NFSv4 delegation"
27862 + " for an internal link\n");
27866 + dput(h_path.dentry);
27869 + inode_unlock(h_dir);
27873 +struct do_whplink_args {
27875 + struct qstr *tgt;
27876 + struct dentry *h_parent;
27877 + struct dentry *h_dentry;
27878 + struct au_branch *br;
27881 +static void call_do_whplink(void *args)
27883 + struct do_whplink_args *a = args;
27884 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27887 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27888 + aufs_bindex_t bindex, struct au_branch *br)
27890 + int err, wkq_err;
27891 + struct au_wbr *wbr;
27892 + struct dentry *h_parent;
27893 + char a[PLINK_NAME_LEN];
27894 + struct qstr tgtname = QSTR_INIT(a, 0);
27896 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27897 + h_parent = wbr->wbr_plink;
27898 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27900 + /* always superio. */
27901 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27902 + struct do_whplink_args args = {
27905 + .h_parent = h_parent,
27906 + .h_dentry = h_dentry,
27909 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27910 + if (unlikely(wkq_err))
27913 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
27919 + * create a new pseudo-link for @h_dentry on @bindex.
27920 + * the linked inode is held in aufs @inode.
27922 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27923 + struct dentry *h_dentry)
27925 + struct super_block *sb;
27926 + struct au_sbinfo *sbinfo;
27927 + struct hlist_bl_head *hbl;
27928 + struct hlist_bl_node *pos;
27929 + struct au_icntnr *icntnr;
27930 + int found, err, cnt, i;
27932 + sb = inode->i_sb;
27933 + sbinfo = au_sbi(sb);
27934 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27935 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27937 + found = au_plink_test(inode);
27941 + i = au_plink_hash(inode->i_ino);
27942 + hbl = sbinfo->si_plink + i;
27945 + hlist_bl_lock(hbl);
27946 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
27947 + if (&icntnr->vfs_inode == inode) {
27953 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
27954 + hlist_bl_add_head(&icntnr->plink, hbl);
27956 + hlist_bl_unlock(hbl);
27958 + cnt = au_hbl_count(hbl);
27959 +#define msg "unexpectedly unblanced or too many pseudo-links"
27960 + if (cnt > AUFS_PLINK_WARN)
27961 + AuWarn1(msg ", %d\n", cnt);
27963 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
27964 + if (unlikely(err)) {
27965 + pr_warn("err %d, damaged pseudo link.\n", err);
27966 + au_hbl_del(&icntnr->plink, hbl);
27967 + iput(&icntnr->vfs_inode);
27970 + iput(&icntnr->vfs_inode);
27973 +/* free all plinks */
27974 +void au_plink_put(struct super_block *sb, int verbose)
27977 + struct au_sbinfo *sbinfo;
27978 + struct hlist_bl_head *hbl;
27979 + struct hlist_bl_node *pos, *tmp;
27980 + struct au_icntnr *icntnr;
27982 + SiMustWriteLock(sb);
27984 + sbinfo = au_sbi(sb);
27985 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27986 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27988 + /* no spin_lock since sbinfo is write-locked */
27990 + for (i = 0; i < AuPlink_NHASH; i++) {
27991 + hbl = sbinfo->si_plink + i;
27992 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
27993 + pr_warn("pseudo-link is not flushed");
27996 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
27997 + iput(&icntnr->vfs_inode);
27998 + INIT_HLIST_BL_HEAD(hbl);
28002 +void au_plink_clean(struct super_block *sb, int verbose)
28004 + struct dentry *root;
28006 + root = sb->s_root;
28007 + aufs_write_lock(root);
28008 + if (au_opt_test(au_mntflags(sb), PLINK))
28009 + au_plink_put(sb, verbose);
28010 + aufs_write_unlock(root);
28013 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28016 + aufs_bindex_t btop, bbot, bindex;
28019 + btop = au_ibtop(inode);
28020 + bbot = au_ibbot(inode);
28022 + for (bindex = btop; bindex <= bbot; bindex++) {
28023 + if (!au_h_iptr(inode, bindex)
28024 + || au_ii_br_id(inode, bindex) != br_id)
28026 + au_set_h_iptr(inode, bindex, NULL, 0);
28031 + for (bindex = btop; bindex <= bbot; bindex++)
28032 + if (au_h_iptr(inode, bindex)) {
28042 +/* free the plinks on a branch specified by @br_id */
28043 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28045 + struct au_sbinfo *sbinfo;
28046 + struct hlist_bl_head *hbl;
28047 + struct hlist_bl_node *pos, *tmp;
28048 + struct au_icntnr *icntnr;
28049 + struct inode *inode;
28052 + SiMustWriteLock(sb);
28054 + sbinfo = au_sbi(sb);
28055 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28056 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28058 + /* no bit_lock since sbinfo is write-locked */
28059 + for (i = 0; i < AuPlink_NHASH; i++) {
28060 + hbl = sbinfo->si_plink + i;
28061 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28062 + inode = au_igrab(&icntnr->vfs_inode);
28063 + ii_write_lock_child(inode);
28064 + do_put = au_plink_do_half_refresh(inode, br_id);
28066 + hlist_bl_del(&icntnr->plink);
28069 + ii_write_unlock(inode);
28074 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28075 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28076 +++ linux/fs/aufs/poll.c 2018-07-19 09:46:13.063314675 +0200
28078 +/* SPDX-License-Identifier: GPL-2.0 */
28080 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28082 + * This program, aufs is free software; you can redistribute it and/or modify
28083 + * it under the terms of the GNU General Public License as published by
28084 + * the Free Software Foundation; either version 2 of the License, or
28085 + * (at your option) any later version.
28087 + * This program is distributed in the hope that it will be useful,
28088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28090 + * GNU General Public License for more details.
28092 + * You should have received a copy of the GNU General Public License
28093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28098 + * There is only one filesystem which implements ->poll operation, currently.
28103 +__poll_t aufs_poll(struct file *file, poll_table *wait)
28106 + struct file *h_file;
28107 + struct super_block *sb;
28109 + /* We should pretend an error happened. */
28110 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28111 + sb = file->f_path.dentry->d_sb;
28112 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28114 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28115 + if (IS_ERR(h_file)) {
28116 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28120 + /* it is not an error if h_file has no operation */
28121 + mask = DEFAULT_POLLMASK;
28122 + if (h_file->f_op->poll)
28123 + mask = h_file->f_op->poll(h_file, wait);
28124 + fput(h_file); /* instead of au_read_post() */
28127 + si_read_unlock(sb);
28128 + if (mask & EPOLLERR)
28129 + AuDbg("mask 0x%x\n", mask);
28132 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28133 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28134 +++ linux/fs/aufs/posix_acl.c 2018-07-19 09:46:13.063314675 +0200
28136 +/* SPDX-License-Identifier: GPL-2.0 */
28138 + * Copyright (C) 2014-2018 Junjiro R. Okajima
28140 + * This program, aufs is free software; you can redistribute it and/or modify
28141 + * it under the terms of the GNU General Public License as published by
28142 + * the Free Software Foundation; either version 2 of the License, or
28143 + * (at your option) any later version.
28145 + * This program is distributed in the hope that it will be useful,
28146 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28147 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28148 + * GNU General Public License for more details.
28150 + * You should have received a copy of the GNU General Public License
28151 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28155 + * posix acl operations
28158 +#include <linux/fs.h>
28161 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28163 + struct posix_acl *acl;
28165 + aufs_bindex_t bindex;
28166 + struct inode *h_inode;
28167 + struct super_block *sb;
28170 + sb = inode->i_sb;
28171 + si_read_lock(sb, AuLock_FLUSH);
28172 + ii_read_lock_child(inode);
28173 + if (!(sb->s_flags & SB_POSIXACL))
28176 + bindex = au_ibtop(inode);
28177 + h_inode = au_h_iptr(inode, bindex);
28178 + if (unlikely(!h_inode
28179 + || ((h_inode->i_mode & S_IFMT)
28180 + != (inode->i_mode & S_IFMT)))) {
28181 + err = au_busy_or_stale();
28182 + acl = ERR_PTR(err);
28186 + /* always topmost only */
28187 + acl = get_acl(h_inode, type);
28188 + if (!IS_ERR_OR_NULL(acl))
28189 + set_cached_acl(inode, type, acl);
28192 + ii_read_unlock(inode);
28193 + si_read_unlock(sb);
28195 + AuTraceErrPtr(acl);
28199 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28203 + struct dentry *dentry;
28204 + struct au_sxattr arg = {
28205 + .type = AU_ACL_SET,
28212 + IMustLock(inode);
28214 + if (inode->i_ino == AUFS_ROOT_INO)
28215 + dentry = dget(inode->i_sb->s_root);
28217 + dentry = d_find_alias(inode);
28219 + dentry = d_find_any_alias(inode);
28221 + pr_warn("cannot handle this inode, "
28222 + "please report to aufs-users ML\n");
28228 + ssz = au_sxattr(dentry, inode, &arg);
28233 + set_cached_acl(inode, type, acl);
28239 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28240 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28241 +++ linux/fs/aufs/procfs.c 2018-07-19 09:46:13.063314675 +0200
28243 +/* SPDX-License-Identifier: GPL-2.0 */
28245 + * Copyright (C) 2010-2018 Junjiro R. Okajima
28247 + * This program, aufs is free software; you can redistribute it and/or modify
28248 + * it under the terms of the GNU General Public License as published by
28249 + * the Free Software Foundation; either version 2 of the License, or
28250 + * (at your option) any later version.
28252 + * This program is distributed in the hope that it will be useful,
28253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28255 + * GNU General Public License for more details.
28257 + * You should have received a copy of the GNU General Public License
28258 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28262 + * procfs interfaces
28265 +#include <linux/proc_fs.h>
28268 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28270 + struct au_sbinfo *sbinfo;
28272 + sbinfo = file->private_data;
28274 + au_plink_maint_leave(sbinfo);
28275 + kobject_put(&sbinfo->si_kobj);
28281 +static void au_procfs_plm_write_clean(struct file *file)
28283 + struct au_sbinfo *sbinfo;
28285 + sbinfo = file->private_data;
28287 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28290 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28293 + struct super_block *sb;
28294 + struct au_sbinfo *sbinfo;
28295 + struct hlist_bl_node *pos;
28298 + if (unlikely(file->private_data))
28302 + /* don't use au_sbilist_lock() here */
28303 + hlist_bl_lock(&au_sbilist);
28304 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28305 + if (id == sysaufs_si_id(sbinfo)) {
28306 + kobject_get(&sbinfo->si_kobj);
28307 + sb = sbinfo->si_sb;
28310 + hlist_bl_unlock(&au_sbilist);
28313 + if (unlikely(!sb))
28316 + err = au_plink_maint_enter(sb);
28318 + /* keep kobject_get() */
28319 + file->private_data = sbinfo;
28321 + kobject_put(&sbinfo->si_kobj);
28327 + * Accept a valid "si=xxxx" only.
28328 + * Once it is accepted successfully, accept "clean" too.
28330 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28331 + size_t count, loff_t *ppos)
28334 + unsigned long id;
28335 + /* last newline is allowed */
28336 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28339 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28343 + if (unlikely(count > sizeof(buf)))
28346 + err = copy_from_user(buf, ubuf, count);
28347 + if (unlikely(err)) {
28354 + if (!strcmp("clean", buf)) {
28355 + au_procfs_plm_write_clean(file);
28356 + goto out_success;
28357 + } else if (unlikely(strncmp("si=", buf, 3)))
28360 + err = kstrtoul(buf + 3, 16, &id);
28361 + if (unlikely(err))
28364 + err = au_procfs_plm_write_si(file, id);
28365 + if (unlikely(err))
28369 + err = count; /* success */
28374 +static const struct file_operations au_procfs_plm_fop = {
28375 + .write = au_procfs_plm_write,
28376 + .release = au_procfs_plm_release,
28377 + .owner = THIS_MODULE
28380 +/* ---------------------------------------------------------------------- */
28382 +static struct proc_dir_entry *au_procfs_dir;
28384 +void au_procfs_fin(void)
28386 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28387 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28390 +int __init au_procfs_init(void)
28393 + struct proc_dir_entry *entry;
28396 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28397 + if (unlikely(!au_procfs_dir))
28400 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
28401 + au_procfs_dir, &au_procfs_plm_fop);
28402 + if (unlikely(!entry))
28406 + goto out; /* success */
28410 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28414 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28415 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28416 +++ linux/fs/aufs/rdu.c 2018-07-19 09:46:13.063314675 +0200
28418 +/* SPDX-License-Identifier: GPL-2.0 */
28420 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28422 + * This program, aufs is free software; you can redistribute it and/or modify
28423 + * it under the terms of the GNU General Public License as published by
28424 + * the Free Software Foundation; either version 2 of the License, or
28425 + * (at your option) any later version.
28427 + * This program is distributed in the hope that it will be useful,
28428 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28429 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28430 + * GNU General Public License for more details.
28432 + * You should have received a copy of the GNU General Public License
28433 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28437 + * readdir in userspace.
28440 +#include <linux/compat.h>
28441 +#include <linux/fs_stack.h>
28442 +#include <linux/security.h>
28445 +/* bits for struct aufs_rdu.flags */
28446 +#define AuRdu_CALLED 1
28447 +#define AuRdu_CONT (1 << 1)
28448 +#define AuRdu_FULL (1 << 2)
28449 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28450 +#define au_fset_rdu(flags, name) \
28451 + do { (flags) |= AuRdu_##name; } while (0)
28452 +#define au_fclr_rdu(flags, name) \
28453 + do { (flags) &= ~AuRdu_##name; } while (0)
28455 +struct au_rdu_arg {
28456 + struct dir_context ctx;
28457 + struct aufs_rdu *rdu;
28458 + union au_rdu_ent_ul ent;
28459 + unsigned long end;
28461 + struct super_block *sb;
28465 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28466 + loff_t offset, u64 h_ino, unsigned int d_type)
28469 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28470 + struct aufs_rdu *rdu = arg->rdu;
28471 + struct au_rdu_ent ent;
28475 + au_fset_rdu(rdu->cookie.flags, CALLED);
28476 + len = au_rdu_len(nlen);
28477 + if (arg->ent.ul + len < arg->end) {
28479 + ent.bindex = rdu->cookie.bindex;
28480 + ent.type = d_type;
28482 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28483 + ent.type = DT_UNKNOWN;
28485 + /* unnecessary to support mmap_sem since this is a dir */
28487 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28489 + if (copy_to_user(arg->ent.e->name, name, nlen))
28491 + /* the terminating NULL */
28492 + if (__put_user(0, arg->ent.e->name + nlen))
28495 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28496 + arg->ent.ul += len;
28500 + au_fset_rdu(rdu->cookie.flags, FULL);
28502 + rdu->tail = arg->ent;
28506 + /* AuTraceErr(err); */
28510 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28514 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28516 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28517 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28519 + if (unlikely(offset != cookie->h_pos))
28525 + au_fclr_rdu(cookie->flags, CALLED);
28527 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28531 + && au_ftest_rdu(cookie->flags, CALLED)
28532 + && !au_ftest_rdu(cookie->flags, FULL));
28533 + cookie->h_pos = h_file->f_pos;
28540 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28543 + aufs_bindex_t bbot;
28544 + struct au_rdu_arg arg = {
28546 + .actor = au_rdu_fill
28549 + struct dentry *dentry;
28550 + struct inode *inode;
28551 + struct file *h_file;
28552 + struct au_rdu_cookie *cookie = &rdu->cookie;
28554 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28555 + if (unlikely(err)) {
28561 + rdu->tail = rdu->ent;
28564 + arg.ent = rdu->ent;
28565 + arg.end = arg.ent.ul;
28566 + arg.end += rdu->sz;
28569 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28572 + err = security_file_permission(file, MAY_READ);
28574 + if (unlikely(err))
28577 + dentry = file->f_path.dentry;
28578 + inode = d_inode(dentry);
28579 + inode_lock_shared(inode);
28581 + arg.sb = inode->i_sb;
28582 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28583 + if (unlikely(err))
28585 + err = au_alive_dir(dentry);
28586 + if (unlikely(err))
28588 + /* todo: reval? */
28589 + fi_read_lock(file);
28592 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28593 + && cookie->generation != au_figen(file)))
28598 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28600 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28602 + bbot = au_fbtop(file);
28603 + if (cookie->bindex < bbot)
28604 + cookie->bindex = bbot;
28605 + bbot = au_fbbot_dir(file);
28606 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28607 + for (; !err && cookie->bindex <= bbot;
28608 + cookie->bindex++, cookie->h_pos = 0) {
28609 + h_file = au_hf_dir(file, cookie->bindex);
28613 + au_fclr_rdu(cookie->flags, FULL);
28614 + err = au_rdu_do(h_file, &arg);
28616 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28619 + AuDbg("rent %llu\n", rdu->rent);
28621 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28622 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28623 + au_fset_rdu(cookie->flags, CONT);
28624 + cookie->generation = au_figen(file);
28627 + ii_read_lock_child(inode);
28628 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28629 + ii_read_unlock(inode);
28632 + fi_read_unlock(file);
28634 + si_read_unlock(arg.sb);
28636 + inode_unlock_shared(inode);
28642 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28646 + unsigned long long nent;
28647 + union au_rdu_ent_ul *u;
28648 + struct au_rdu_ent ent;
28649 + struct super_block *sb;
28652 + nent = rdu->nent;
28654 + sb = file->f_path.dentry->d_sb;
28655 + si_read_lock(sb, AuLock_FLUSH);
28656 + while (nent-- > 0) {
28657 + /* unnecessary to support mmap_sem since this is a dir */
28658 + err = copy_from_user(&ent, u->e, sizeof(ent));
28660 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28661 + if (unlikely(err)) {
28667 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28669 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28671 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28673 + if (unlikely(err)) {
28678 + err = __put_user(ino, &u->e->ino);
28679 + if (unlikely(err)) {
28684 + u->ul += au_rdu_len(ent.nlen);
28686 + si_read_unlock(sb);
28691 +/* ---------------------------------------------------------------------- */
28693 +static int au_rdu_verify(struct aufs_rdu *rdu)
28695 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28696 + "%llu, b%d, 0x%x, g%u}\n",
28697 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28699 + rdu->rent, rdu->shwh, rdu->full,
28700 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28701 + rdu->cookie.generation);
28703 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28707 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28711 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28714 + struct aufs_rdu rdu;
28715 + void __user *p = (void __user *)arg;
28717 + err = copy_from_user(&rdu, p, sizeof(rdu));
28718 + if (unlikely(err)) {
28723 + err = au_rdu_verify(&rdu);
28724 + if (unlikely(err))
28728 + case AUFS_CTL_RDU:
28729 + err = au_rdu(file, &rdu);
28730 + if (unlikely(err))
28733 + e = copy_to_user(p, &rdu, sizeof(rdu));
28734 + if (unlikely(e)) {
28739 + case AUFS_CTL_RDU_INO:
28740 + err = au_rdu_ino(file, &rdu);
28744 + /* err = -ENOTTY; */
28753 +#ifdef CONFIG_COMPAT
28754 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28757 + struct aufs_rdu rdu;
28758 + void __user *p = compat_ptr(arg);
28760 + /* todo: get_user()? */
28761 + err = copy_from_user(&rdu, p, sizeof(rdu));
28762 + if (unlikely(err)) {
28767 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28768 + err = au_rdu_verify(&rdu);
28769 + if (unlikely(err))
28773 + case AUFS_CTL_RDU:
28774 + err = au_rdu(file, &rdu);
28775 + if (unlikely(err))
28778 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28779 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28780 + e = copy_to_user(p, &rdu, sizeof(rdu));
28781 + if (unlikely(e)) {
28786 + case AUFS_CTL_RDU_INO:
28787 + err = au_rdu_ino(file, &rdu);
28791 + /* err = -ENOTTY; */
28800 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28801 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28802 +++ linux/fs/aufs/rwsem.h 2018-07-19 09:46:13.063314675 +0200
28804 +/* SPDX-License-Identifier: GPL-2.0 */
28806 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28808 + * This program, aufs is free software; you can redistribute it and/or modify
28809 + * it under the terms of the GNU General Public License as published by
28810 + * the Free Software Foundation; either version 2 of the License, or
28811 + * (at your option) any later version.
28813 + * This program is distributed in the hope that it will be useful,
28814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28816 + * GNU General Public License for more details.
28818 + * You should have received a copy of the GNU General Public License
28819 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28823 + * simple read-write semaphore wrappers
28826 +#ifndef __AUFS_RWSEM_H__
28827 +#define __AUFS_RWSEM_H__
28831 +#include "debug.h"
28833 +/* in the futre, the name 'au_rwsem' will be totally gone */
28834 +#define au_rwsem rw_semaphore
28836 +/* to debug easier, do not make them inlined functions */
28837 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28838 +/* rwsem_is_locked() is unusable */
28839 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
28841 + && !lockdep_is_held_type(rw, 1))
28842 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
28844 + && !lockdep_is_held_type(rw, 0))
28845 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
28847 + && !lockdep_is_held(rw))
28848 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
28850 + && lockdep_is_held(rw))
28852 +#define au_rw_init(rw) init_rwsem(rw)
28854 +#define au_rw_init_wlock(rw) do { \
28855 + au_rw_init(rw); \
28856 + down_write(rw); \
28859 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28860 + au_rw_init(rw); \
28861 + down_write_nested(rw, lsc); \
28864 +#define au_rw_read_lock(rw) down_read(rw)
28865 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28866 +#define au_rw_read_unlock(rw) up_read(rw)
28867 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28868 +#define au_rw_write_lock(rw) down_write(rw)
28869 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28870 +#define au_rw_write_unlock(rw) up_write(rw)
28871 +/* why is not _nested version defined? */
28872 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28873 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28875 +#endif /* __KERNEL__ */
28876 +#endif /* __AUFS_RWSEM_H__ */
28877 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28878 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28879 +++ linux/fs/aufs/sbinfo.c 2018-07-19 09:46:13.063314675 +0200
28881 +/* SPDX-License-Identifier: GPL-2.0 */
28883 + * Copyright (C) 2005-2018 Junjiro R. Okajima
28885 + * This program, aufs is free software; you can redistribute it and/or modify
28886 + * it under the terms of the GNU General Public License as published by
28887 + * the Free Software Foundation; either version 2 of the License, or
28888 + * (at your option) any later version.
28890 + * This program is distributed in the hope that it will be useful,
28891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28893 + * GNU General Public License for more details.
28895 + * You should have received a copy of the GNU General Public License
28896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28900 + * superblock private data
28906 + * they are necessary regardless sysfs is disabled.
28908 +void au_si_free(struct kobject *kobj)
28911 + struct au_sbinfo *sbinfo;
28912 + char *locked __maybe_unused; /* debug only */
28914 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28915 + for (i = 0; i < AuPlink_NHASH; i++)
28916 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28917 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28919 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
28920 + percpu_counter_destroy(&sbinfo->si_ninodes);
28921 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
28922 + percpu_counter_destroy(&sbinfo->si_nfiles);
28924 + dbgaufs_si_fin(sbinfo);
28925 + au_rw_write_lock(&sbinfo->si_rwsem);
28926 + au_br_free(sbinfo);
28927 + au_rw_write_unlock(&sbinfo->si_rwsem);
28929 + kfree(sbinfo->si_branch);
28930 + mutex_destroy(&sbinfo->si_xib_mtx);
28931 + AuRwDestroy(&sbinfo->si_rwsem);
28936 +int au_si_alloc(struct super_block *sb)
28939 + struct au_sbinfo *sbinfo;
28942 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
28943 + if (unlikely(!sbinfo))
28946 + /* will be reallocated separately */
28947 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
28948 + if (unlikely(!sbinfo->si_branch))
28951 + err = sysaufs_si_init(sbinfo);
28953 + dbgaufs_si_null(sbinfo);
28954 + err = dbgaufs_si_init(sbinfo);
28955 + if (unlikely(err))
28956 + kobject_put(&sbinfo->si_kobj);
28958 + if (unlikely(err))
28961 + au_nwt_init(&sbinfo->si_nowait);
28962 + au_rw_init_wlock(&sbinfo->si_rwsem);
28964 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
28965 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
28967 + sbinfo->si_bbot = -1;
28968 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
28970 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
28971 + sbinfo->si_wbr_create = AuWbrCreate_Def;
28972 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
28973 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
28975 + au_fhsm_init(sbinfo);
28977 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
28979 + sbinfo->si_xino_jiffy = jiffies;
28980 + sbinfo->si_xino_expire
28981 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
28982 + mutex_init(&sbinfo->si_xib_mtx);
28983 + sbinfo->si_xino_brid = -1;
28984 + /* leave si_xib_last_pindex and si_xib_next_bit */
28986 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
28988 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
28989 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
28990 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
28991 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
28993 + for (i = 0; i < AuPlink_NHASH; i++)
28994 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
28995 + init_waitqueue_head(&sbinfo->si_plink_wq);
28996 + spin_lock_init(&sbinfo->si_plink_maint_lock);
28998 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29000 + /* with getattr by default */
29001 + sbinfo->si_iop_array = aufs_iop;
29003 + /* leave other members for sysaufs and si_mnt. */
29004 + sbinfo->si_sb = sb;
29005 + sb->s_fs_info = sbinfo;
29007 + return 0; /* success */
29010 + kfree(sbinfo->si_branch);
29017 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29020 + struct au_branch **brp;
29022 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29025 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29026 + if (unlikely(!sz))
29027 + sz = sizeof(*brp);
29028 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29031 + sbinfo->si_branch = brp;
29038 +/* ---------------------------------------------------------------------- */
29040 +unsigned int au_sigen_inc(struct super_block *sb)
29042 + unsigned int gen;
29043 + struct inode *inode;
29045 + SiMustWriteLock(sb);
29047 + gen = ++au_sbi(sb)->si_generation;
29048 + au_update_digen(sb->s_root);
29049 + inode = d_inode(sb->s_root);
29050 + au_update_iigen(inode, /*half*/0);
29051 + inode_inc_iversion(inode);
29055 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29057 + aufs_bindex_t br_id;
29059 + struct au_sbinfo *sbinfo;
29061 + SiMustWriteLock(sb);
29063 + sbinfo = au_sbi(sb);
29064 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29065 + br_id = ++sbinfo->si_last_br_id;
29066 + AuDebugOn(br_id < 0);
29067 + if (br_id && au_br_index(sb, br_id) < 0)
29074 +/* ---------------------------------------------------------------------- */
29076 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29077 +int si_read_lock(struct super_block *sb, int flags)
29082 + if (au_ftest_lock(flags, FLUSH))
29083 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29085 + si_noflush_read_lock(sb);
29086 + err = au_plink_maint(sb, flags);
29087 + if (unlikely(err))
29088 + si_read_unlock(sb);
29093 +int si_write_lock(struct super_block *sb, int flags)
29097 + if (au_ftest_lock(flags, FLUSH))
29098 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29100 + si_noflush_write_lock(sb);
29101 + err = au_plink_maint(sb, flags);
29102 + if (unlikely(err))
29103 + si_write_unlock(sb);
29108 +/* dentry and super_block lock. call at entry point */
29109 +int aufs_read_lock(struct dentry *dentry, int flags)
29112 + struct super_block *sb;
29114 + sb = dentry->d_sb;
29115 + err = si_read_lock(sb, flags);
29116 + if (unlikely(err))
29119 + if (au_ftest_lock(flags, DW))
29120 + di_write_lock_child(dentry);
29122 + di_read_lock_child(dentry, flags);
29124 + if (au_ftest_lock(flags, GEN)) {
29125 + err = au_digen_test(dentry, au_sigen(sb));
29126 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29127 + AuDebugOn(!err && au_dbrange_test(dentry));
29129 + err = au_dbrange_test(dentry);
29130 + if (unlikely(err))
29131 + aufs_read_unlock(dentry, flags);
29138 +void aufs_read_unlock(struct dentry *dentry, int flags)
29140 + if (au_ftest_lock(flags, DW))
29141 + di_write_unlock(dentry);
29143 + di_read_unlock(dentry, flags);
29144 + si_read_unlock(dentry->d_sb);
29147 +void aufs_write_lock(struct dentry *dentry)
29149 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29150 + di_write_lock_child(dentry);
29153 +void aufs_write_unlock(struct dentry *dentry)
29155 + di_write_unlock(dentry);
29156 + si_write_unlock(dentry->d_sb);
29159 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29162 + unsigned int sigen;
29163 + struct super_block *sb;
29166 + err = si_read_lock(sb, flags);
29167 + if (unlikely(err))
29170 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29172 + if (au_ftest_lock(flags, GEN)) {
29173 + sigen = au_sigen(sb);
29174 + err = au_digen_test(d1, sigen);
29175 + AuDebugOn(!err && au_dbrange_test(d1));
29177 + err = au_digen_test(d2, sigen);
29178 + AuDebugOn(!err && au_dbrange_test(d2));
29180 + if (unlikely(err))
29181 + aufs_read_and_write_unlock2(d1, d2);
29188 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29190 + di_write_unlock2(d1, d2);
29191 + si_read_unlock(d1->d_sb);
29193 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29194 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29195 +++ linux/fs/aufs/super.c 2018-07-19 09:46:13.063314675 +0200
29197 +/* SPDX-License-Identifier: GPL-2.0 */
29199 + * Copyright (C) 2005-2018 Junjiro R. Okajima
29201 + * This program, aufs is free software; you can redistribute it and/or modify
29202 + * it under the terms of the GNU General Public License as published by
29203 + * the Free Software Foundation; either version 2 of the License, or
29204 + * (at your option) any later version.
29206 + * This program is distributed in the hope that it will be useful,
29207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29209 + * GNU General Public License for more details.
29211 + * You should have received a copy of the GNU General Public License
29212 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29216 + * mount and super_block operations
29219 +#include <linux/mm.h>
29220 +#include <linux/seq_file.h>
29221 +#include <linux/statfs.h>
29222 +#include <linux/vmalloc.h>
29226 + * super_operations
29228 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29230 + struct au_icntnr *c;
29232 + c = au_cache_alloc_icntnr();
29234 + au_icntnr_init(c);
29235 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29236 + c->iinfo.ii_hinode = NULL;
29237 + return &c->vfs_inode;
29242 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29244 + struct inode *inode = container_of(head, struct inode, i_rcu);
29246 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29249 +static void aufs_destroy_inode(struct inode *inode)
29251 + if (!au_is_bad_inode(inode))
29252 + au_iinfo_fin(inode);
29253 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29256 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29258 + struct inode *inode;
29261 + inode = iget_locked(sb, ino);
29262 + if (unlikely(!inode)) {
29263 + inode = ERR_PTR(-ENOMEM);
29266 + if (!(inode->i_state & I_NEW))
29269 + err = au_xigen_new(inode);
29271 + err = au_iinfo_init(inode);
29273 + inode_inc_iversion(inode);
29275 + iget_failed(inode);
29276 + inode = ERR_PTR(err);
29280 + /* never return NULL */
29281 + AuDebugOn(!inode);
29282 + AuTraceErrPtr(inode);
29286 +/* lock free root dinfo */
29287 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29290 + aufs_bindex_t bindex, bbot;
29291 + struct path path;
29292 + struct au_hdentry *hdp;
29293 + struct au_branch *br;
29294 + au_br_perm_str_t perm;
29297 + bbot = au_sbbot(sb);
29299 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29300 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29301 + br = au_sbr(sb, bindex);
29302 + path.mnt = au_br_mnt(br);
29303 + path.dentry = hdp->hd_dentry;
29304 + err = au_seq_path(seq, &path);
29306 + au_optstr_br_perm(&perm, br->br_perm);
29307 + seq_printf(seq, "=%s", perm.a);
29308 + if (bindex != bbot)
29309 + seq_putc(seq, ':');
29312 + if (unlikely(err || seq_has_overflowed(seq)))
29318 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29319 + const char *append)
29324 + while (*pat != ':')
29327 + strcpy(p, append);
29328 + AuDebugOn(strlen(fmt) >= len);
29331 +static void au_show_wbr_create(struct seq_file *m, int v,
29332 + struct au_sbinfo *sbinfo)
29336 + struct au_wbr_mfs *mfs;
29338 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29340 + seq_puts(m, ",create=");
29341 + pat = au_optstr_wbr_create(v);
29342 + mfs = &sbinfo->si_wbr_mfs;
29344 + case AuWbrCreate_TDP:
29345 + case AuWbrCreate_RR:
29346 + case AuWbrCreate_MFS:
29347 + case AuWbrCreate_PMFS:
29348 + seq_puts(m, pat);
29350 + case AuWbrCreate_MFSRR:
29351 + case AuWbrCreate_TDMFS:
29352 + case AuWbrCreate_PMFSRR:
29353 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29354 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29356 + case AuWbrCreate_MFSV:
29357 + case AuWbrCreate_PMFSV:
29358 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29359 + seq_printf(m, fmt,
29360 + jiffies_to_msecs(mfs->mfs_expire)
29363 + case AuWbrCreate_MFSRRV:
29364 + case AuWbrCreate_TDMFSV:
29365 + case AuWbrCreate_PMFSRRV:
29366 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29367 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29368 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29375 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29377 +#ifdef CONFIG_SYSFS
29381 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29382 + aufs_bindex_t bindex, brid;
29383 + struct qstr *name;
29385 + struct dentry *d, *h_root;
29387 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29390 + f = au_sbi(sb)->si_xib;
29394 + /* stop printing the default xino path on the first writable branch */
29396 + brid = au_xino_brid(sb);
29398 + bindex = au_br_index(sb, brid);
29399 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
29401 + d = f->f_path.dentry;
29402 + name = &d->d_name;
29403 + /* safe ->d_parent because the file is unlinked */
29404 + if (d->d_parent == h_root
29405 + && name->len == len
29406 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29409 + seq_puts(seq, ",xino=");
29410 + err = au_xino_path(seq, f);
29417 +/* seq_file will re-call me in case of too long string */
29418 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29421 + unsigned int mnt_flags, v;
29422 + struct super_block *sb;
29423 + struct au_sbinfo *sbinfo;
29425 +#define AuBool(name, str) do { \
29426 + v = au_opt_test(mnt_flags, name); \
29427 + if (v != au_opt_test(AuOpt_Def, name)) \
29428 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29431 +#define AuStr(name, str) do { \
29432 + v = mnt_flags & AuOptMask_##name; \
29433 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29434 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29437 +#define AuUInt(name, str, val) do { \
29438 + if (val != AUFS_##name##_DEF) \
29439 + seq_printf(m, "," #str "=%u", val); \
29442 + sb = dentry->d_sb;
29443 + if (sb->s_flags & SB_POSIXACL)
29444 + seq_puts(m, ",acl");
29446 + if (sb->s_flags & SB_I_VERSION)
29447 + seq_puts(m, ",i_version");
29450 + /* lock free root dinfo */
29451 + si_noflush_read_lock(sb);
29452 + sbinfo = au_sbi(sb);
29453 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29455 + mnt_flags = au_mntflags(sb);
29456 + if (au_opt_test(mnt_flags, XINO)) {
29457 + err = au_show_xino(m, sb);
29458 + if (unlikely(err))
29461 + seq_puts(m, ",noxino");
29463 + AuBool(TRUNC_XINO, trunc_xino);
29464 + AuStr(UDBA, udba);
29465 + AuBool(SHWH, shwh);
29466 + AuBool(PLINK, plink);
29467 + AuBool(DIO, dio);
29468 + AuBool(DIRPERM1, dirperm1);
29470 + v = sbinfo->si_wbr_create;
29471 + if (v != AuWbrCreate_Def)
29472 + au_show_wbr_create(m, v, sbinfo);
29474 + v = sbinfo->si_wbr_copyup;
29475 + if (v != AuWbrCopyup_Def)
29476 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29478 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29479 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29480 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29482 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29484 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29485 + AuUInt(RDCACHE, rdcache, v);
29487 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29488 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29490 + au_fhsm_show(m, sbinfo);
29492 + AuBool(DIRREN, dirren);
29493 + AuBool(SUM, sum);
29494 + /* AuBool(SUM_W, wsum); */
29495 + AuBool(WARN_PERM, warn_perm);
29496 + AuBool(VERBOSE, verbose);
29499 + /* be sure to print "br:" last */
29500 + if (!sysaufs_brs) {
29501 + seq_puts(m, ",br:");
29502 + au_show_brs(m, sb);
29504 + si_read_unlock(sb);
29512 +/* ---------------------------------------------------------------------- */
29514 +/* sum mode which returns the summation for statfs(2) */
29516 +static u64 au_add_till_max(u64 a, u64 b)
29524 + return ULLONG_MAX;
29527 +static u64 au_mul_till_max(u64 a, long mul)
29535 + return ULLONG_MAX;
29538 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29541 + long bsize, factor;
29542 + u64 blocks, bfree, bavail, files, ffree;
29543 + aufs_bindex_t bbot, bindex, i;
29544 + unsigned char shared;
29545 + struct path h_path;
29546 + struct super_block *h_sb;
29549 + bsize = LONG_MAX;
29555 + bbot = au_sbbot(sb);
29556 + for (bindex = 0; bindex <= bbot; bindex++) {
29557 + h_path.mnt = au_sbr_mnt(sb, bindex);
29558 + h_sb = h_path.mnt->mnt_sb;
29560 + for (i = 0; !shared && i < bindex; i++)
29561 + shared = (au_sbr_sb(sb, i) == h_sb);
29565 + /* sb->s_root for NFS is unreliable */
29566 + h_path.dentry = h_path.mnt->mnt_root;
29567 + err = vfs_statfs(&h_path, buf);
29568 + if (unlikely(err))
29571 + if (bsize > buf->f_bsize) {
29573 + * we will reduce bsize, so we have to expand blocks
29574 + * etc. to match them again
29576 + factor = (bsize / buf->f_bsize);
29577 + blocks = au_mul_till_max(blocks, factor);
29578 + bfree = au_mul_till_max(bfree, factor);
29579 + bavail = au_mul_till_max(bavail, factor);
29580 + bsize = buf->f_bsize;
29583 + factor = (buf->f_bsize / bsize);
29584 + blocks = au_add_till_max(blocks,
29585 + au_mul_till_max(buf->f_blocks, factor));
29586 + bfree = au_add_till_max(bfree,
29587 + au_mul_till_max(buf->f_bfree, factor));
29588 + bavail = au_add_till_max(bavail,
29589 + au_mul_till_max(buf->f_bavail, factor));
29590 + files = au_add_till_max(files, buf->f_files);
29591 + ffree = au_add_till_max(ffree, buf->f_ffree);
29594 + buf->f_bsize = bsize;
29595 + buf->f_blocks = blocks;
29596 + buf->f_bfree = bfree;
29597 + buf->f_bavail = bavail;
29598 + buf->f_files = files;
29599 + buf->f_ffree = ffree;
29600 + buf->f_frsize = 0;
29606 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29609 + struct path h_path;
29610 + struct super_block *sb;
29612 + /* lock free root dinfo */
29613 + sb = dentry->d_sb;
29614 + si_noflush_read_lock(sb);
29615 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29616 + /* sb->s_root for NFS is unreliable */
29617 + h_path.mnt = au_sbr_mnt(sb, 0);
29618 + h_path.dentry = h_path.mnt->mnt_root;
29619 + err = vfs_statfs(&h_path, buf);
29621 + err = au_statfs_sum(sb, buf);
29622 + si_read_unlock(sb);
29625 + buf->f_type = AUFS_SUPER_MAGIC;
29626 + buf->f_namelen = AUFS_MAX_NAMELEN;
29627 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29629 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29634 +/* ---------------------------------------------------------------------- */
29636 +static int aufs_sync_fs(struct super_block *sb, int wait)
29639 + aufs_bindex_t bbot, bindex;
29640 + struct au_branch *br;
29641 + struct super_block *h_sb;
29644 + si_noflush_read_lock(sb);
29645 + bbot = au_sbbot(sb);
29646 + for (bindex = 0; bindex <= bbot; bindex++) {
29647 + br = au_sbr(sb, bindex);
29648 + if (!au_br_writable(br->br_perm))
29651 + h_sb = au_sbr_sb(sb, bindex);
29652 + e = vfsub_sync_filesystem(h_sb, wait);
29653 + if (unlikely(e && !err))
29655 + /* go on even if an error happens */
29657 + si_read_unlock(sb);
29662 +/* ---------------------------------------------------------------------- */
29664 +/* final actions when unmounting a file system */
29665 +static void aufs_put_super(struct super_block *sb)
29667 + struct au_sbinfo *sbinfo;
29669 + sbinfo = au_sbi(sb);
29671 + kobject_put(&sbinfo->si_kobj);
29674 +/* ---------------------------------------------------------------------- */
29676 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29677 + struct super_block *sb, void *arg)
29680 + unsigned long long n, sz;
29687 + if (*hint > ULLONG_MAX / sizeof(array)) {
29688 + array = ERR_PTR(-EMFILE);
29689 + pr_err("hint %llu\n", *hint);
29693 + sz = sizeof(array) * *hint;
29694 + array = kzalloc(sz, GFP_NOFS);
29695 + if (unlikely(!array))
29696 + array = vzalloc(sz);
29697 + if (unlikely(!array)) {
29698 + array = ERR_PTR(-ENOMEM);
29702 + n = cb(sb, array, *hint, arg);
29703 + AuDebugOn(n > *hint);
29710 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29711 + unsigned long long max __maybe_unused,
29714 + unsigned long long n;
29715 + struct inode **p, *inode;
29716 + struct list_head *head;
29721 + spin_lock(&sb->s_inode_list_lock);
29722 + list_for_each_entry(inode, head, i_sb_list) {
29723 + if (!au_is_bad_inode(inode)
29724 + && au_ii(inode)->ii_btop >= 0) {
29725 + spin_lock(&inode->i_lock);
29726 + if (atomic_read(&inode->i_count)) {
29730 + AuDebugOn(n > max);
29732 + spin_unlock(&inode->i_lock);
29735 + spin_unlock(&sb->s_inode_list_lock);
29740 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29742 + *max = au_ninodes(sb);
29743 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29746 +void au_iarray_free(struct inode **a, unsigned long long max)
29748 + unsigned long long ull;
29750 + for (ull = 0; ull < max; ull++)
29755 +/* ---------------------------------------------------------------------- */
29758 + * refresh dentry and inode at remount time.
29760 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29761 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29762 + struct dentry *parent)
29766 + di_write_lock_child(dentry);
29767 + di_read_lock_parent(parent, AuLock_IR);
29768 + err = au_refresh_dentry(dentry, parent);
29769 + if (!err && dir_flags)
29770 + au_hn_reset(d_inode(dentry), dir_flags);
29771 + di_read_unlock(parent, AuLock_IR);
29772 + di_write_unlock(dentry);
29777 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29778 + struct au_sbinfo *sbinfo,
29779 + const unsigned int dir_flags, unsigned int do_idop)
29782 + struct dentry *parent;
29785 + parent = dget_parent(dentry);
29786 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29787 + if (d_really_is_positive(dentry)) {
29788 + if (!d_is_dir(dentry))
29789 + err = au_do_refresh(dentry, /*dir_flags*/0,
29792 + err = au_do_refresh(dentry, dir_flags, parent);
29793 + if (unlikely(err))
29794 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29797 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29798 + AuDbgDentry(dentry);
29804 + au_refresh_dop(dentry, /*force_reval*/0);
29806 + au_refresh_dop(dentry, /*force_reval*/1);
29812 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29814 + int err, i, j, ndentry, e;
29815 + unsigned int sigen;
29816 + struct au_dcsub_pages dpages;
29817 + struct au_dpage *dpage;
29818 + struct dentry **dentries, *d;
29819 + struct au_sbinfo *sbinfo;
29820 + struct dentry *root = sb->s_root;
29821 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29824 + au_refresh_dop(root, /*force_reval*/0);
29826 + err = au_dpages_init(&dpages, GFP_NOFS);
29827 + if (unlikely(err))
29829 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29830 + if (unlikely(err))
29833 + sigen = au_sigen(sb);
29834 + sbinfo = au_sbi(sb);
29835 + for (i = 0; i < dpages.ndpage; i++) {
29836 + dpage = dpages.dpages + i;
29837 + dentries = dpage->dentries;
29838 + ndentry = dpage->ndentry;
29839 + for (j = 0; j < ndentry; j++) {
29841 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29843 + if (unlikely(e && !err))
29845 + /* go on even err */
29850 + au_dpages_free(&dpages);
29855 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29858 + unsigned int sigen;
29859 + unsigned long long max, ull;
29860 + struct inode *inode, **array;
29862 + array = au_iarray_alloc(sb, &max);
29863 + err = PTR_ERR(array);
29864 + if (IS_ERR(array))
29868 + sigen = au_sigen(sb);
29869 + for (ull = 0; ull < max; ull++) {
29870 + inode = array[ull];
29871 + if (unlikely(!inode))
29875 + ii_write_lock_child(inode);
29876 + if (au_iigen(inode, NULL) != sigen) {
29877 + e = au_refresh_hinode_self(inode);
29878 + if (unlikely(e)) {
29879 + au_refresh_iop(inode, /*force_getattr*/1);
29880 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29883 + /* go on even if err */
29886 + if (!e && do_idop)
29887 + au_refresh_iop(inode, /*force_getattr*/0);
29888 + ii_write_unlock(inode);
29891 + au_iarray_free(array, max);
29897 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29900 + unsigned int udba;
29901 + aufs_bindex_t bindex, bbot;
29902 + struct dentry *root;
29903 + struct inode *inode;
29904 + struct au_branch *br;
29905 + struct au_sbinfo *sbi;
29907 + au_sigen_inc(sb);
29908 + sbi = au_sbi(sb);
29909 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29911 + root = sb->s_root;
29912 + DiMustNoWaiters(root);
29913 + inode = d_inode(root);
29914 + IiMustNoWaiters(inode);
29916 + udba = au_opt_udba(sb);
29917 + bbot = au_sbbot(sb);
29918 + for (bindex = 0; bindex <= bbot; bindex++) {
29919 + br = au_sbr(sb, bindex);
29920 + err = au_hnotify_reset_br(udba, br, br->br_perm);
29921 + if (unlikely(err))
29922 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
29924 + /* go on even if err */
29926 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
29929 + if (au_ftest_si(sbi, NO_DREVAL)) {
29930 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
29931 + sb->s_d_op = &aufs_dop_noreval;
29932 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
29933 + sbi->si_iop_array = aufs_iop_nogetattr;
29935 + AuDebugOn(sb->s_d_op == &aufs_dop);
29936 + sb->s_d_op = &aufs_dop;
29937 + AuDebugOn(sbi->si_iop_array == aufs_iop);
29938 + sbi->si_iop_array = aufs_iop;
29940 + pr_info("reset to %ps and %ps\n",
29941 + sb->s_d_op, sbi->si_iop_array);
29944 + di_write_unlock(root);
29945 + err = au_refresh_d(sb, do_idop);
29946 + e = au_refresh_i(sb, do_idop);
29947 + if (unlikely(e && !err))
29949 + /* aufs_write_lock() calls ..._child() */
29950 + di_write_lock_child(root);
29952 + au_cpup_attr_all(inode, /*force*/1);
29954 + if (unlikely(err))
29955 + AuIOErr("refresh failed, ignored, %d\n", err);
29958 +/* stop extra interpretation of errno in mount(8), and strange error messages */
29959 +static int cvt_err(int err)
29973 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
29976 + unsigned int mntflags;
29977 + struct au_opts opts = {
29980 + struct dentry *root;
29981 + struct inode *inode;
29982 + struct au_sbinfo *sbinfo;
29985 + root = sb->s_root;
29986 + if (!data || !*data) {
29987 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
29989 + di_write_lock_child(root);
29990 + err = au_opts_verify(sb, *flags, /*pending*/0);
29991 + aufs_write_unlock(root);
29997 + opts.opt = (void *)__get_free_page(GFP_NOFS);
29998 + if (unlikely(!opts.opt))
30000 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30001 + opts.flags = AuOpts_REMOUNT;
30002 + opts.sb_flags = *flags;
30004 + /* parse it before aufs lock */
30005 + err = au_opts_parse(sb, data, &opts);
30006 + if (unlikely(err))
30009 + sbinfo = au_sbi(sb);
30010 + inode = d_inode(root);
30011 + inode_lock(inode);
30012 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30013 + if (unlikely(err))
30015 + di_write_lock_child(root);
30017 + /* au_opts_remount() may return an error */
30018 + err = au_opts_remount(sb, &opts);
30019 + au_opts_free(&opts);
30021 + if (au_ftest_opts(opts.flags, REFRESH))
30022 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30024 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30025 + mntflags = au_mntflags(sb);
30026 + do_dx = !!au_opt_test(mntflags, DIO);
30027 + au_dy_arefresh(do_dx);
30030 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30031 + aufs_write_unlock(root);
30034 + inode_unlock(inode);
30036 + free_page((unsigned long)opts.opt);
30038 + err = cvt_err(err);
30043 +static const struct super_operations aufs_sop = {
30044 + .alloc_inode = aufs_alloc_inode,
30045 + .destroy_inode = aufs_destroy_inode,
30046 + /* always deleting, no clearing */
30047 + .drop_inode = generic_delete_inode,
30048 + .show_options = aufs_show_options,
30049 + .statfs = aufs_statfs,
30050 + .put_super = aufs_put_super,
30051 + .sync_fs = aufs_sync_fs,
30052 + .remount_fs = aufs_remount_fs
30055 +/* ---------------------------------------------------------------------- */
30057 +static int alloc_root(struct super_block *sb)
30060 + struct inode *inode;
30061 + struct dentry *root;
30064 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30065 + err = PTR_ERR(inode);
30066 + if (IS_ERR(inode))
30069 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30070 + inode->i_fop = &aufs_dir_fop;
30071 + inode->i_mode = S_IFDIR;
30072 + set_nlink(inode, 2);
30073 + unlock_new_inode(inode);
30075 + root = d_make_root(inode);
30076 + if (unlikely(!root))
30078 + err = PTR_ERR(root);
30079 + if (IS_ERR(root))
30082 + err = au_di_init(root);
30084 + sb->s_root = root;
30085 + return 0; /* success */
30093 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30094 + int silent __maybe_unused)
30097 + struct au_opts opts = {
30100 + struct au_sbinfo *sbinfo;
30101 + struct dentry *root;
30102 + struct inode *inode;
30103 + char *arg = raw_data;
30105 + if (unlikely(!arg || !*arg)) {
30107 + pr_err("no arg\n");
30112 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30113 + if (unlikely(!opts.opt))
30115 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30116 + opts.sb_flags = sb->s_flags;
30118 + err = au_si_alloc(sb);
30119 + if (unlikely(err))
30121 + sbinfo = au_sbi(sb);
30123 + /* all timestamps always follow the ones on the branch */
30124 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30125 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30126 + sb->s_op = &aufs_sop;
30127 + sb->s_d_op = &aufs_dop;
30128 + sb->s_magic = AUFS_SUPER_MAGIC;
30129 + sb->s_maxbytes = 0;
30130 + sb->s_stack_depth = 1;
30131 + au_export_init(sb);
30132 + au_xattr_init(sb);
30134 + err = alloc_root(sb);
30135 + if (unlikely(err)) {
30136 + si_write_unlock(sb);
30139 + root = sb->s_root;
30140 + inode = d_inode(root);
30143 + * actually we can parse options regardless aufs lock here.
30144 + * but at remount time, parsing must be done before aufs lock.
30145 + * so we follow the same rule.
30147 + ii_write_lock_parent(inode);
30148 + aufs_write_unlock(root);
30149 + err = au_opts_parse(sb, arg, &opts);
30150 + if (unlikely(err))
30153 + /* lock vfs_inode first, then aufs. */
30154 + inode_lock(inode);
30155 + aufs_write_lock(root);
30156 + err = au_opts_mount(sb, &opts);
30157 + au_opts_free(&opts);
30158 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30159 + sb->s_d_op = &aufs_dop_noreval;
30160 + pr_info("%ps\n", sb->s_d_op);
30161 + au_refresh_dop(root, /*force_reval*/0);
30162 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30163 + au_refresh_iop(inode, /*force_getattr*/0);
30165 + aufs_write_unlock(root);
30166 + inode_unlock(inode);
30168 + goto out_opts; /* success */
30172 + sb->s_root = NULL;
30174 + kobject_put(&sbinfo->si_kobj);
30175 + sb->s_fs_info = NULL;
30177 + free_page((unsigned long)opts.opt);
30180 + err = cvt_err(err);
30185 +/* ---------------------------------------------------------------------- */
30187 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30188 + const char *dev_name __maybe_unused,
30191 + struct dentry *root;
30193 + /* all timestamps always follow the ones on the branch */
30194 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30195 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30196 + if (IS_ERR(root))
30199 + au_sbilist_add(root->d_sb);
30205 +static void aufs_kill_sb(struct super_block *sb)
30207 + struct au_sbinfo *sbinfo;
30209 + sbinfo = au_sbi(sb);
30211 + au_sbilist_del(sb);
30212 + aufs_write_lock(sb->s_root);
30214 + if (sbinfo->si_wbr_create_ops->fin)
30215 + sbinfo->si_wbr_create_ops->fin(sb);
30216 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30217 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30218 + au_remount_refresh(sb, /*do_idop*/0);
30220 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30221 + au_plink_put(sb, /*verbose*/1);
30223 + au_dr_opt_flush(sb);
30224 + sbinfo->si_sb = NULL;
30225 + aufs_write_unlock(sb->s_root);
30226 + au_nwt_flush(&sbinfo->si_nowait);
30228 + kill_anon_super(sb);
30231 +struct file_system_type aufs_fs_type = {
30232 + .name = AUFS_FSTYPE,
30233 + /* a race between rename and others */
30234 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30235 + .mount = aufs_mount,
30236 + .kill_sb = aufs_kill_sb,
30237 + /* no need to __module_get() and module_put(). */
30238 + .owner = THIS_MODULE,
30240 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30241 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30242 +++ linux/fs/aufs/super.h 2018-07-19 09:46:13.063314675 +0200
30244 +/* SPDX-License-Identifier: GPL-2.0 */
30246 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30248 + * This program, aufs is free software; you can redistribute it and/or modify
30249 + * it under the terms of the GNU General Public License as published by
30250 + * the Free Software Foundation; either version 2 of the License, or
30251 + * (at your option) any later version.
30253 + * This program is distributed in the hope that it will be useful,
30254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30256 + * GNU General Public License for more details.
30258 + * You should have received a copy of the GNU General Public License
30259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30263 + * super_block operations
30266 +#ifndef __AUFS_SUPER_H__
30267 +#define __AUFS_SUPER_H__
30271 +#include <linux/fs.h>
30272 +#include <linux/kobject.h>
30274 +#include "rwsem.h"
30277 +/* policies to select one among multiple writable branches */
30278 +struct au_wbr_copyup_operations {
30279 + int (*copyup)(struct dentry *dentry);
30282 +#define AuWbr_DIR 1 /* target is a dir */
30283 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30285 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30286 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30287 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30289 +struct au_wbr_create_operations {
30290 + int (*create)(struct dentry *dentry, unsigned int flags);
30291 + int (*init)(struct super_block *sb);
30292 + int (*fin)(struct super_block *sb);
30295 +struct au_wbr_mfs {
30296 + struct mutex mfs_lock; /* protect this structure */
30297 + unsigned long mfs_jiffy;
30298 + unsigned long mfs_expire;
30299 + aufs_bindex_t mfs_bindex;
30301 + unsigned long long mfsrr_bytes;
30302 + unsigned long long mfsrr_watermark;
30305 +#define AuPlink_NHASH 100
30306 +static inline int au_plink_hash(ino_t ino)
30308 + return ino % AuPlink_NHASH;
30311 +/* File-based Hierarchical Storage Management */
30313 +#ifdef CONFIG_AUFS_FHSM
30314 + /* allow only one process who can receive the notification */
30315 + spinlock_t fhsm_spin;
30317 + wait_queue_head_t fhsm_wqh;
30318 + atomic_t fhsm_readable;
30320 + /* these are protected by si_rwsem */
30321 + unsigned long fhsm_expire;
30322 + aufs_bindex_t fhsm_bottom;
30327 +struct au_sbinfo {
30328 + /* nowait tasks in the system-wide workqueue */
30329 + struct au_nowait_tasks si_nowait;
30332 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
30333 + * rwsem for au_sbinfo is necessary.
30335 + struct au_rwsem si_rwsem;
30338 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30341 + struct percpu_counter si_ninodes, si_nfiles;
30343 + /* branch management */
30344 + unsigned int si_generation;
30346 + /* see AuSi_ flags */
30347 + unsigned char au_si_status;
30349 + aufs_bindex_t si_bbot;
30351 + /* dirty trick to keep br_id plus */
30352 + unsigned int si_last_br_id :
30353 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30354 + struct au_branch **si_branch;
30356 + /* policy to select a writable branch */
30357 + unsigned char si_wbr_copyup;
30358 + unsigned char si_wbr_create;
30359 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30360 + struct au_wbr_create_operations *si_wbr_create_ops;
30362 + /* round robin */
30363 + atomic_t si_wbr_rr_next;
30365 + /* most free space */
30366 + struct au_wbr_mfs si_wbr_mfs;
30368 + /* File-based Hierarchical Storage Management */
30369 + struct au_fhsm si_fhsm;
30371 + /* mount flags */
30372 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30373 + unsigned int si_mntflags;
30375 + /* external inode number (bitmap and translation table) */
30376 + vfs_readf_t si_xread;
30377 + vfs_writef_t si_xwrite;
30378 + struct file *si_xib;
30379 + struct mutex si_xib_mtx; /* protect xib members */
30380 + unsigned long *si_xib_buf;
30381 + unsigned long si_xib_last_pindex;
30382 + int si_xib_next_bit;
30383 + aufs_bindex_t si_xino_brid;
30384 + unsigned long si_xino_jiffy;
30385 + unsigned long si_xino_expire;
30386 + /* reserved for future use */
30387 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30389 +#ifdef CONFIG_AUFS_EXPORT
30390 + /* i_generation */
30391 + struct file *si_xigen;
30392 + atomic_t si_xigen_next;
30395 + /* dirty trick to suppoer atomic_open */
30396 + struct hlist_bl_head si_aopen;
30398 + /* vdir parameters */
30399 + unsigned long si_rdcache; /* max cache time in jiffies */
30400 + unsigned int si_rdblk; /* deblk size */
30401 + unsigned int si_rdhash; /* hash size */
30404 + * If the number of whiteouts are larger than si_dirwh, leave all of
30405 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30406 + * future fsck.aufs or kernel thread will remove them later.
30407 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30409 + unsigned int si_dirwh;
30411 + /* pseudo_link list */
30412 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30413 + wait_queue_head_t si_plink_wq;
30414 + spinlock_t si_plink_maint_lock;
30415 + pid_t si_plink_maint_pid;
30418 + struct hlist_bl_head si_files;
30420 + /* with/without getattr, brother of sb->s_d_op */
30421 + struct inode_operations *si_iop_array;
30424 + * sysfs and lifetime management.
30425 + * this is not a small structure and it may be a waste of memory in case
30426 + * of sysfs is disabled, particulary when many aufs-es are mounted.
30427 + * but using sysfs is majority.
30429 + struct kobject si_kobj;
30430 +#ifdef CONFIG_DEBUG_FS
30431 + struct dentry *si_dbgaufs;
30432 + struct dentry *si_dbgaufs_plink;
30433 + struct dentry *si_dbgaufs_xib;
30434 +#ifdef CONFIG_AUFS_EXPORT
30435 + struct dentry *si_dbgaufs_xigen;
30439 +#ifdef CONFIG_AUFS_SBILIST
30440 + struct hlist_bl_node si_list;
30443 + /* dirty, necessary for unmounting, sysfs and sysrq */
30444 + struct super_block *si_sb;
30447 +/* sbinfo status flags */
30449 + * set true when refresh_dirs() failed at remount time.
30450 + * then try refreshing dirs at access time again.
30451 + * if it is false, refreshing dirs at access time is unnecessary
30453 +#define AuSi_FAILED_REFRESH_DIR 1
30454 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30455 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30457 +#ifndef CONFIG_AUFS_FHSM
30459 +#define AuSi_FHSM 0
30462 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30463 + unsigned int flag)
30465 + AuRwMustAnyLock(&sbi->si_rwsem);
30466 + return sbi->au_si_status & flag;
30468 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30469 +#define au_fset_si(sbinfo, name) do { \
30470 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30471 + (sbinfo)->au_si_status |= AuSi_##name; \
30473 +#define au_fclr_si(sbinfo, name) do { \
30474 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30475 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30478 +/* ---------------------------------------------------------------------- */
30480 +/* policy to select one among writable branches */
30481 +#define AuWbrCopyup(sbinfo, ...) \
30482 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30483 +#define AuWbrCreate(sbinfo, ...) \
30484 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30486 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30487 +#define AuLock_DW 1 /* write-lock dentry */
30488 +#define AuLock_IR (1 << 1) /* read-lock inode */
30489 +#define AuLock_IW (1 << 2) /* write-lock inode */
30490 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30491 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30492 + /* except RENAME_EXCHANGE */
30493 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30494 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30495 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30496 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30497 +#define au_fset_lock(flags, name) \
30498 + do { (flags) |= AuLock_##name; } while (0)
30499 +#define au_fclr_lock(flags, name) \
30500 + do { (flags) &= ~AuLock_##name; } while (0)
30502 +/* ---------------------------------------------------------------------- */
30505 +extern struct file_system_type aufs_fs_type;
30506 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30507 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30508 + unsigned long long max, void *arg);
30509 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30510 + struct super_block *sb, void *arg);
30511 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30512 +void au_iarray_free(struct inode **a, unsigned long long max);
30515 +void au_si_free(struct kobject *kobj);
30516 +int au_si_alloc(struct super_block *sb);
30517 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30519 +unsigned int au_sigen_inc(struct super_block *sb);
30520 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30522 +int si_read_lock(struct super_block *sb, int flags);
30523 +int si_write_lock(struct super_block *sb, int flags);
30524 +int aufs_read_lock(struct dentry *dentry, int flags);
30525 +void aufs_read_unlock(struct dentry *dentry, int flags);
30526 +void aufs_write_lock(struct dentry *dentry);
30527 +void aufs_write_unlock(struct dentry *dentry);
30528 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30529 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30531 +/* wbr_policy.c */
30532 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30533 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30534 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30535 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30536 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30539 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30541 +#ifdef CONFIG_AUFS_FHSM
30544 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30548 + spin_lock(&fhsm->fhsm_spin);
30549 + pid = fhsm->fhsm_pid;
30550 + spin_unlock(&fhsm->fhsm_spin);
30555 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30556 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30557 +int au_fhsm_fd(struct super_block *sb, int oflags);
30558 +int au_fhsm_br_alloc(struct au_branch *br);
30559 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30560 +void au_fhsm_fin(struct super_block *sb);
30561 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30562 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30563 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30565 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30567 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30568 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30569 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30570 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30571 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30572 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30573 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30574 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30575 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30578 +/* ---------------------------------------------------------------------- */
30580 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30582 + return sb->s_fs_info;
30585 +/* ---------------------------------------------------------------------- */
30587 +#ifdef CONFIG_AUFS_EXPORT
30588 +int au_test_nfsd(void);
30589 +void au_export_init(struct super_block *sb);
30590 +void au_xigen_inc(struct inode *inode);
30591 +int au_xigen_new(struct inode *inode);
30592 +int au_xigen_set(struct super_block *sb, struct path *path);
30593 +void au_xigen_clr(struct super_block *sb);
30595 +static inline int au_busy_or_stale(void)
30597 + if (!au_test_nfsd())
30602 +AuStubInt0(au_test_nfsd, void)
30603 +AuStubVoid(au_export_init, struct super_block *sb)
30604 +AuStubVoid(au_xigen_inc, struct inode *inode)
30605 +AuStubInt0(au_xigen_new, struct inode *inode)
30606 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30607 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30608 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30609 +#endif /* CONFIG_AUFS_EXPORT */
30611 +/* ---------------------------------------------------------------------- */
30613 +#ifdef CONFIG_AUFS_SBILIST
30615 +extern struct hlist_bl_head au_sbilist;
30617 +static inline void au_sbilist_init(void)
30619 + INIT_HLIST_BL_HEAD(&au_sbilist);
30622 +static inline void au_sbilist_add(struct super_block *sb)
30624 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30627 +static inline void au_sbilist_del(struct super_block *sb)
30629 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30632 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30633 +static inline void au_sbilist_lock(void)
30635 + hlist_bl_lock(&au_sbilist);
30638 +static inline void au_sbilist_unlock(void)
30640 + hlist_bl_unlock(&au_sbilist);
30642 +#define AuGFP_SBILIST GFP_ATOMIC
30644 +AuStubVoid(au_sbilist_lock, void)
30645 +AuStubVoid(au_sbilist_unlock, void)
30646 +#define AuGFP_SBILIST GFP_NOFS
30647 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30649 +AuStubVoid(au_sbilist_init, void)
30650 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30651 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30652 +AuStubVoid(au_sbilist_lock, void)
30653 +AuStubVoid(au_sbilist_unlock, void)
30654 +#define AuGFP_SBILIST GFP_NOFS
30657 +/* ---------------------------------------------------------------------- */
30659 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30662 + * This function is a dynamic '__init' function actually,
30663 + * so the tiny check for si_rwsem is unnecessary.
30665 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30666 +#ifdef CONFIG_DEBUG_FS
30667 + sbinfo->si_dbgaufs = NULL;
30668 + sbinfo->si_dbgaufs_plink = NULL;
30669 + sbinfo->si_dbgaufs_xib = NULL;
30670 +#ifdef CONFIG_AUFS_EXPORT
30671 + sbinfo->si_dbgaufs_xigen = NULL;
30676 +/* ---------------------------------------------------------------------- */
30678 +/* current->atomic_flags */
30679 +/* this value should never corrupt the ones defined in linux/sched.h */
30680 +#define PFA_AUFS 7
30682 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30683 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30684 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30686 +static inline int si_pid_test(struct super_block *sb)
30688 + return !!task_test_aufs(current);
30691 +static inline void si_pid_clr(struct super_block *sb)
30693 + AuDebugOn(!task_test_aufs(current));
30694 + task_clear_aufs(current);
30697 +static inline void si_pid_set(struct super_block *sb)
30699 + AuDebugOn(task_test_aufs(current));
30700 + task_set_aufs(current);
30703 +/* ---------------------------------------------------------------------- */
30705 +/* lock superblock. mainly for entry point functions */
30706 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30707 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30708 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30709 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30711 +#define __si_read_trylock_nested(sb) \
30712 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30713 +#define __si_write_trylock_nested(sb) \
30714 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30717 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30718 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30719 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30721 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30722 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30723 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30725 +static inline void si_noflush_read_lock(struct super_block *sb)
30727 + __si_read_lock(sb);
30731 +static inline int si_noflush_read_trylock(struct super_block *sb)
30735 + locked = __si_read_trylock(sb);
30741 +static inline void si_noflush_write_lock(struct super_block *sb)
30743 + __si_write_lock(sb);
30747 +static inline int si_noflush_write_trylock(struct super_block *sb)
30751 + locked = __si_write_trylock(sb);
30757 +#if 0 /* reserved */
30758 +static inline int si_read_trylock(struct super_block *sb, int flags)
30760 + if (au_ftest_lock(flags, FLUSH))
30761 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30762 + return si_noflush_read_trylock(sb);
30766 +static inline void si_read_unlock(struct super_block *sb)
30769 + __si_read_unlock(sb);
30772 +#if 0 /* reserved */
30773 +static inline int si_write_trylock(struct super_block *sb, int flags)
30775 + if (au_ftest_lock(flags, FLUSH))
30776 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30777 + return si_noflush_write_trylock(sb);
30781 +static inline void si_write_unlock(struct super_block *sb)
30784 + __si_write_unlock(sb);
30787 +#if 0 /* reserved */
30788 +static inline void si_downgrade_lock(struct super_block *sb)
30790 + __si_downgrade_lock(sb);
30794 +/* ---------------------------------------------------------------------- */
30796 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30798 + SiMustAnyLock(sb);
30799 + return au_sbi(sb)->si_bbot;
30802 +static inline unsigned int au_mntflags(struct super_block *sb)
30804 + SiMustAnyLock(sb);
30805 + return au_sbi(sb)->si_mntflags;
30808 +static inline unsigned int au_sigen(struct super_block *sb)
30810 + SiMustAnyLock(sb);
30811 + return au_sbi(sb)->si_generation;
30814 +static inline unsigned long long au_ninodes(struct super_block *sb)
30816 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
30822 +static inline void au_ninodes_inc(struct super_block *sb)
30824 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
30827 +static inline void au_ninodes_dec(struct super_block *sb)
30829 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
30832 +static inline unsigned long long au_nfiles(struct super_block *sb)
30834 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
30840 +static inline void au_nfiles_inc(struct super_block *sb)
30842 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
30845 +static inline void au_nfiles_dec(struct super_block *sb)
30847 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
30850 +static inline struct au_branch *au_sbr(struct super_block *sb,
30851 + aufs_bindex_t bindex)
30853 + SiMustAnyLock(sb);
30854 + return au_sbi(sb)->si_branch[0 + bindex];
30857 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
30859 + SiMustWriteLock(sb);
30860 + au_sbi(sb)->si_xino_brid = brid;
30863 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
30865 + SiMustAnyLock(sb);
30866 + return au_sbi(sb)->si_xino_brid;
30869 +#endif /* __KERNEL__ */
30870 +#endif /* __AUFS_SUPER_H__ */
30871 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30872 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30873 +++ linux/fs/aufs/sysaufs.c 2018-07-19 09:46:13.063314675 +0200
30875 +/* SPDX-License-Identifier: GPL-2.0 */
30877 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30879 + * This program, aufs is free software; you can redistribute it and/or modify
30880 + * it under the terms of the GNU General Public License as published by
30881 + * the Free Software Foundation; either version 2 of the License, or
30882 + * (at your option) any later version.
30884 + * This program is distributed in the hope that it will be useful,
30885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30887 + * GNU General Public License for more details.
30889 + * You should have received a copy of the GNU General Public License
30890 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30894 + * sysfs interface and lifetime management
30895 + * they are necessary regardless sysfs is disabled.
30898 +#include <linux/random.h>
30901 +unsigned long sysaufs_si_mask;
30902 +struct kset *sysaufs_kset;
30904 +#define AuSiAttr(_name) { \
30905 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30906 + .show = sysaufs_si_##_name, \
30909 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30910 +struct attribute *sysaufs_si_attrs[] = {
30911 + &sysaufs_si_attr_xi_path.attr,
30915 +static const struct sysfs_ops au_sbi_ops = {
30916 + .show = sysaufs_si_show
30919 +static struct kobj_type au_sbi_ktype = {
30920 + .release = au_si_free,
30921 + .sysfs_ops = &au_sbi_ops,
30922 + .default_attrs = sysaufs_si_attrs
30925 +/* ---------------------------------------------------------------------- */
30927 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30931 + sbinfo->si_kobj.kset = sysaufs_kset;
30932 + /* cf. sysaufs_name() */
30933 + err = kobject_init_and_add
30934 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30935 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30940 +void sysaufs_fin(void)
30942 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30943 + kset_unregister(sysaufs_kset);
30946 +int __init sysaufs_init(void)
30951 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30952 + } while (!sysaufs_si_mask);
30955 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30956 + if (unlikely(!sysaufs_kset))
30958 + err = PTR_ERR(sysaufs_kset);
30959 + if (IS_ERR(sysaufs_kset))
30961 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30962 + if (unlikely(err))
30963 + kset_unregister(sysaufs_kset);
30968 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
30969 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
30970 +++ linux/fs/aufs/sysaufs.h 2018-07-19 09:46:13.063314675 +0200
30972 +/* SPDX-License-Identifier: GPL-2.0 */
30974 + * Copyright (C) 2005-2018 Junjiro R. Okajima
30976 + * This program, aufs is free software; you can redistribute it and/or modify
30977 + * it under the terms of the GNU General Public License as published by
30978 + * the Free Software Foundation; either version 2 of the License, or
30979 + * (at your option) any later version.
30981 + * This program is distributed in the hope that it will be useful,
30982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30984 + * GNU General Public License for more details.
30986 + * You should have received a copy of the GNU General Public License
30987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30991 + * sysfs interface and mount lifetime management
30994 +#ifndef __SYSAUFS_H__
30995 +#define __SYSAUFS_H__
30999 +#include <linux/sysfs.h>
31000 +#include "module.h"
31002 +struct super_block;
31005 +struct sysaufs_si_attr {
31006 + struct attribute attr;
31007 + int (*show)(struct seq_file *seq, struct super_block *sb);
31010 +/* ---------------------------------------------------------------------- */
31013 +extern unsigned long sysaufs_si_mask;
31014 +extern struct kset *sysaufs_kset;
31015 +extern struct attribute *sysaufs_si_attrs[];
31016 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31017 +int __init sysaufs_init(void);
31018 +void sysaufs_fin(void);
31020 +/* ---------------------------------------------------------------------- */
31022 +/* some people doesn't like to show a pointer in kernel */
31023 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31025 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31028 +#define SysaufsSiNamePrefix "si_"
31029 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31030 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31032 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31033 + sysaufs_si_id(sbinfo));
31037 +#ifdef CONFIG_SYSFS
31039 +extern struct attribute_group *sysaufs_attr_group;
31041 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31042 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31044 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31045 +#ifdef CONFIG_COMPAT
31046 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31049 +void sysaufs_br_init(struct au_branch *br);
31050 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31051 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31053 +#define sysaufs_brs_init() do {} while (0)
31056 +#define sysaufs_attr_group NULL
31058 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31059 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31060 + struct attribute *attr, char *buf)
31061 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31062 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31063 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31065 +static inline void sysaufs_brs_init(void)
31070 +#endif /* CONFIG_SYSFS */
31072 +#endif /* __KERNEL__ */
31073 +#endif /* __SYSAUFS_H__ */
31074 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31075 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31076 +++ linux/fs/aufs/sysfs.c 2018-07-19 09:46:13.063314675 +0200
31078 +/* SPDX-License-Identifier: GPL-2.0 */
31080 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31082 + * This program, aufs is free software; you can redistribute it and/or modify
31083 + * it under the terms of the GNU General Public License as published by
31084 + * the Free Software Foundation; either version 2 of the License, or
31085 + * (at your option) any later version.
31087 + * This program is distributed in the hope that it will be useful,
31088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31090 + * GNU General Public License for more details.
31092 + * You should have received a copy of the GNU General Public License
31093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31097 + * sysfs interface
31100 +#include <linux/compat.h>
31101 +#include <linux/seq_file.h>
31104 +#ifdef CONFIG_AUFS_FS_MODULE
31105 +/* this entry violates the "one line per file" policy of sysfs */
31106 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31110 + static char *conf =
31111 +/* this file is generated at compiling */
31112 +#include "conf.str"
31115 + err = snprintf(buf, PAGE_SIZE, conf);
31116 + if (unlikely(err >= PAGE_SIZE))
31121 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31124 +static struct attribute *au_attr[] = {
31125 +#ifdef CONFIG_AUFS_FS_MODULE
31126 + &au_config_attr.attr,
31128 + NULL, /* need to NULL terminate the list of attributes */
31131 +static struct attribute_group sysaufs_attr_group_body = {
31135 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31137 +/* ---------------------------------------------------------------------- */
31139 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31143 + SiMustAnyLock(sb);
31146 + if (au_opt_test(au_mntflags(sb), XINO)) {
31147 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31148 + seq_putc(seq, '\n');
31154 + * the lifetime of branch is independent from the entry under sysfs.
31155 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31158 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31159 + aufs_bindex_t bindex, int idx)
31162 + struct path path;
31163 + struct dentry *root;
31164 + struct au_branch *br;
31165 + au_br_perm_str_t perm;
31167 + AuDbg("b%d\n", bindex);
31170 + root = sb->s_root;
31171 + di_read_lock_parent(root, !AuLock_IR);
31172 + br = au_sbr(sb, bindex);
31175 + case AuBrSysfs_BR:
31176 + path.mnt = au_br_mnt(br);
31177 + path.dentry = au_h_dptr(root, bindex);
31178 + err = au_seq_path(seq, &path);
31180 + au_optstr_br_perm(&perm, br->br_perm);
31181 + seq_printf(seq, "=%s\n", perm.a);
31184 + case AuBrSysfs_BRID:
31185 + seq_printf(seq, "%d\n", br->br_id);
31188 + di_read_unlock(root, !AuLock_IR);
31189 + if (unlikely(err || seq_has_overflowed(seq)))
31195 +/* ---------------------------------------------------------------------- */
31197 +static struct seq_file *au_seq(char *p, ssize_t len)
31199 + struct seq_file *seq;
31201 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31203 + /* mutex_init(&seq.lock); */
31206 + return seq; /* success */
31209 + seq = ERR_PTR(-ENOMEM);
31213 +#define SysaufsBr_PREFIX "br"
31214 +#define SysaufsBrid_PREFIX "brid"
31216 +/* todo: file size may exceed PAGE_SIZE */
31217 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31223 + aufs_bindex_t bbot;
31224 + struct au_sbinfo *sbinfo;
31225 + struct super_block *sb;
31226 + struct seq_file *seq;
31228 + struct attribute **cattr;
31230 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31231 + sb = sbinfo->si_sb;
31234 + * prevent a race condition between sysfs and aufs.
31235 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31236 + * prohibits maintaining the sysfs entries.
31237 + * hew we acquire read lock after sysfs_get_active_two().
31238 + * on the other hand, the remount process may maintain the sysfs/aufs
31239 + * entries after acquiring write lock.
31240 + * it can cause a deadlock.
31241 + * simply we gave up processing read here.
31244 + if (unlikely(!si_noflush_read_trylock(sb)))
31247 + seq = au_seq(buf, PAGE_SIZE);
31248 + err = PTR_ERR(seq);
31252 + name = (void *)attr->name;
31253 + cattr = sysaufs_si_attrs;
31255 + if (!strcmp(name, (*cattr)->name)) {
31256 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31263 + if (!strncmp(name, SysaufsBrid_PREFIX,
31264 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31265 + idx = AuBrSysfs_BRID;
31266 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31267 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31268 + sizeof(SysaufsBr_PREFIX) - 1)) {
31269 + idx = AuBrSysfs_BR;
31270 + name += sizeof(SysaufsBr_PREFIX) - 1;
31274 + err = kstrtol(name, 10, &l);
31276 + bbot = au_sbbot(sb);
31278 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31285 + err = seq->count;
31286 + /* sysfs limit */
31287 + if (unlikely(err == PAGE_SIZE))
31292 + si_read_unlock(sb);
31297 +/* ---------------------------------------------------------------------- */
31299 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31303 + aufs_bindex_t bindex, bbot;
31306 + struct seq_file *seq;
31307 + struct au_branch *br;
31309 + si_read_lock(sb, AuLock_FLUSH);
31310 + bbot = au_sbbot(sb);
31316 + buf = (void *)__get_free_page(GFP_NOFS);
31317 + if (unlikely(!buf))
31320 + seq = au_seq(buf, PAGE_SIZE);
31321 + err = PTR_ERR(seq);
31325 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31326 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31327 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31328 + if (unlikely(err))
31331 + br = au_sbr(sb, bindex);
31332 + brid = br->br_id;
31333 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31334 + err = __put_user(brid, &arg->id);
31335 + if (unlikely(err))
31338 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31339 + err = __put_user(br->br_perm, &arg->perm);
31340 + if (unlikely(err))
31343 + err = au_seq_path(seq, &br->br_path);
31344 + if (unlikely(err))
31346 + seq_putc(seq, '\0');
31347 + if (!seq_has_overflowed(seq)) {
31348 + err = copy_to_user(arg->path, seq->buf, seq->count);
31350 + if (unlikely(err))
31357 + if (unlikely(err))
31363 + free_page((unsigned long)buf);
31365 + si_read_unlock(sb);
31369 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31371 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31374 +#ifdef CONFIG_COMPAT
31375 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31377 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31381 +/* ---------------------------------------------------------------------- */
31383 +void sysaufs_br_init(struct au_branch *br)
31386 + struct au_brsysfs *br_sysfs;
31387 + struct attribute *attr;
31389 + br_sysfs = br->br_sysfs;
31390 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31391 + attr = &br_sysfs->attr;
31392 + sysfs_attr_init(attr);
31393 + attr->name = br_sysfs->name;
31394 + attr->mode = S_IRUGO;
31399 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31401 + struct au_branch *br;
31402 + struct kobject *kobj;
31403 + struct au_brsysfs *br_sysfs;
31405 + aufs_bindex_t bbot;
31407 + if (!sysaufs_brs)
31410 + kobj = &au_sbi(sb)->si_kobj;
31411 + bbot = au_sbbot(sb);
31412 + for (; bindex <= bbot; bindex++) {
31413 + br = au_sbr(sb, bindex);
31414 + br_sysfs = br->br_sysfs;
31415 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31416 + sysfs_remove_file(kobj, &br_sysfs->attr);
31422 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31425 + aufs_bindex_t bbot;
31426 + struct kobject *kobj;
31427 + struct au_branch *br;
31428 + struct au_brsysfs *br_sysfs;
31430 + if (!sysaufs_brs)
31433 + kobj = &au_sbi(sb)->si_kobj;
31434 + bbot = au_sbbot(sb);
31435 + for (; bindex <= bbot; bindex++) {
31436 + br = au_sbr(sb, bindex);
31437 + br_sysfs = br->br_sysfs;
31438 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31439 + SysaufsBr_PREFIX "%d", bindex);
31440 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31441 + SysaufsBrid_PREFIX "%d", bindex);
31442 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31443 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31444 + if (unlikely(err))
31445 + pr_warn("failed %s under sysfs(%d)\n",
31446 + br_sysfs->name, err);
31451 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31452 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31453 +++ linux/fs/aufs/sysrq.c 2018-07-19 09:46:13.063314675 +0200
31455 +/* SPDX-License-Identifier: GPL-2.0 */
31457 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31459 + * This program, aufs is free software; you can redistribute it and/or modify
31460 + * it under the terms of the GNU General Public License as published by
31461 + * the Free Software Foundation; either version 2 of the License, or
31462 + * (at your option) any later version.
31464 + * This program is distributed in the hope that it will be useful,
31465 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31466 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31467 + * GNU General Public License for more details.
31469 + * You should have received a copy of the GNU General Public License
31470 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31474 + * magic sysrq hanlder
31477 +/* #include <linux/sysrq.h> */
31478 +#include <linux/writeback.h>
31481 +/* ---------------------------------------------------------------------- */
31483 +static void sysrq_sb(struct super_block *sb)
31486 + struct au_sbinfo *sbinfo;
31487 + struct file *file;
31488 + struct hlist_bl_head *files;
31489 + struct hlist_bl_node *pos;
31490 + struct au_finfo *finfo;
31492 + plevel = au_plevel;
31493 + au_plevel = KERN_WARNING;
31495 + /* since we define pr_fmt, call printk directly */
31496 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31498 + sbinfo = au_sbi(sb);
31499 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31500 + pr("superblock\n");
31504 + pr("root dentry\n");
31505 + au_dpri_dentry(sb->s_root);
31506 + pr("root inode\n");
31507 + au_dpri_inode(d_inode(sb->s_root));
31512 + int err, i, j, ndentry;
31513 + struct au_dcsub_pages dpages;
31514 + struct au_dpage *dpage;
31516 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31517 + if (unlikely(err))
31519 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31521 + for (i = 0; i < dpages.ndpage; i++) {
31522 + dpage = dpages.dpages + i;
31523 + ndentry = dpage->ndentry;
31524 + for (j = 0; j < ndentry; j++)
31525 + au_dpri_dentry(dpage->dentries[j]);
31527 + au_dpages_free(&dpages);
31535 + pr("isolated inode\n");
31536 + spin_lock(&sb->s_inode_list_lock);
31537 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31538 + spin_lock(&i->i_lock);
31539 + if (1 || hlist_empty(&i->i_dentry))
31540 + au_dpri_inode(i);
31541 + spin_unlock(&i->i_lock);
31543 + spin_unlock(&sb->s_inode_list_lock);
31547 + files = &au_sbi(sb)->si_files;
31548 + hlist_bl_lock(files);
31549 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31552 + file = finfo->fi_file;
31553 + mode = file_inode(file)->i_mode;
31554 + if (!special_file(mode))
31555 + au_dpri_file(file);
31557 + hlist_bl_unlock(files);
31561 + au_plevel = plevel;
31564 +/* ---------------------------------------------------------------------- */
31566 +/* module parameter */
31567 +static char *aufs_sysrq_key = "a";
31568 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
31569 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31571 +static void au_sysrq(int key __maybe_unused)
31573 + struct au_sbinfo *sbinfo;
31574 + struct hlist_bl_node *pos;
31577 + au_sbilist_lock();
31578 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31579 + sysrq_sb(sbinfo->si_sb);
31580 + au_sbilist_unlock();
31584 +static struct sysrq_key_op au_sysrq_op = {
31585 + .handler = au_sysrq,
31586 + .help_msg = "Aufs",
31587 + .action_msg = "Aufs",
31588 + .enable_mask = SYSRQ_ENABLE_DUMP
31591 +/* ---------------------------------------------------------------------- */
31593 +int __init au_sysrq_init(void)
31599 + key = *aufs_sysrq_key;
31600 + if ('a' <= key && key <= 'z')
31601 + err = register_sysrq_key(key, &au_sysrq_op);
31602 + if (unlikely(err))
31603 + pr_err("err %d, sysrq=%c\n", err, key);
31607 +void au_sysrq_fin(void)
31611 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31612 + if (unlikely(err))
31613 + pr_err("err %d (ignored)\n", err);
31615 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31616 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31617 +++ linux/fs/aufs/vdir.c 2018-07-19 09:46:13.063314675 +0200
31619 +/* SPDX-License-Identifier: GPL-2.0 */
31621 + * Copyright (C) 2005-2018 Junjiro R. Okajima
31623 + * This program, aufs is free software; you can redistribute it and/or modify
31624 + * it under the terms of the GNU General Public License as published by
31625 + * the Free Software Foundation; either version 2 of the License, or
31626 + * (at your option) any later version.
31628 + * This program is distributed in the hope that it will be useful,
31629 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31630 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31631 + * GNU General Public License for more details.
31633 + * You should have received a copy of the GNU General Public License
31634 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31638 + * virtual or vertical directory
31643 +static unsigned int calc_size(int nlen)
31645 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31648 +static int set_deblk_end(union au_vdir_deblk_p *p,
31649 + union au_vdir_deblk_p *deblk_end)
31651 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31652 + p->de->de_str.len = 0;
31656 + return -1; /* error */
31659 +/* returns true or false */
31660 +static int is_deblk_end(union au_vdir_deblk_p *p,
31661 + union au_vdir_deblk_p *deblk_end)
31663 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31664 + return !p->de->de_str.len;
31668 +static unsigned char *last_deblk(struct au_vdir *vdir)
31670 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31673 +/* ---------------------------------------------------------------------- */
31675 +/* estimate the appropriate size for name hash table */
31676 +unsigned int au_rdhash_est(loff_t sz)
31684 + if (sz < AUFS_RDHASH_DEF)
31685 + n = AUFS_RDHASH_DEF;
31686 + /* pr_info("n %u\n", n); */
31691 + * the allocated memory has to be freed by
31692 + * au_nhash_wh_free() or au_nhash_de_free().
31694 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31696 + struct hlist_head *head;
31700 + sz = sizeof(*nhash->nh_head) * num_hash;
31701 + head = kmalloc(sz, gfp);
31703 + nhash->nh_num = num_hash;
31704 + nhash->nh_head = head;
31705 + for (u = 0; u < num_hash; u++)
31706 + INIT_HLIST_HEAD(head++);
31707 + return 0; /* success */
31713 +static void nhash_count(struct hlist_head *head)
31717 + struct hlist_node *pos;
31720 + hlist_for_each(pos, head)
31722 + pr_info("%lu\n", n);
31726 +static void au_nhash_wh_do_free(struct hlist_head *head)
31728 + struct au_vdir_wh *pos;
31729 + struct hlist_node *node;
31731 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31735 +static void au_nhash_de_do_free(struct hlist_head *head)
31737 + struct au_vdir_dehstr *pos;
31738 + struct hlist_node *node;
31740 + hlist_for_each_entry_safe(pos, node, head, hash)
31741 + au_cache_free_vdir_dehstr(pos);
31744 +static void au_nhash_do_free(struct au_nhash *nhash,
31745 + void (*free)(struct hlist_head *head))
31748 + struct hlist_head *head;
31750 + n = nhash->nh_num;
31754 + head = nhash->nh_head;
31755 + while (n-- > 0) {
31756 + nhash_count(head);
31759 + kfree(nhash->nh_head);
31762 +void au_nhash_wh_free(struct au_nhash *whlist)
31764 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31767 +static void au_nhash_de_free(struct au_nhash *delist)
31769 + au_nhash_do_free(delist, au_nhash_de_do_free);
31772 +/* ---------------------------------------------------------------------- */
31774 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31778 + unsigned int u, n;
31779 + struct hlist_head *head;
31780 + struct au_vdir_wh *pos;
31783 + n = whlist->nh_num;
31784 + head = whlist->nh_head;
31785 + for (u = 0; u < n; u++, head++)
31786 + hlist_for_each_entry(pos, head, wh_hash)
31787 + if (pos->wh_bindex == btgt && ++num > limit)
31792 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31793 + unsigned char *name,
31794 + unsigned int len)
31797 + /* const unsigned int magic_bit = 12; */
31799 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31806 + /* v = hash_long(v, magic_bit); */
31807 + v %= nhash->nh_num;
31808 + return nhash->nh_head + v;
31811 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31814 + return str->len == nlen && !memcmp(str->name, name, nlen);
31817 +/* returns found or not */
31818 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31820 + struct hlist_head *head;
31821 + struct au_vdir_wh *pos;
31822 + struct au_vdir_destr *str;
31824 + head = au_name_hash(whlist, name, nlen);
31825 + hlist_for_each_entry(pos, head, wh_hash) {
31826 + str = &pos->wh_str;
31827 + AuDbg("%.*s\n", str->len, str->name);
31828 + if (au_nhash_test_name(str, name, nlen))
31834 +/* returns found(true) or not */
31835 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31837 + struct hlist_head *head;
31838 + struct au_vdir_dehstr *pos;
31839 + struct au_vdir_destr *str;
31841 + head = au_name_hash(delist, name, nlen);
31842 + hlist_for_each_entry(pos, head, hash) {
31844 + AuDbg("%.*s\n", str->len, str->name);
31845 + if (au_nhash_test_name(str, name, nlen))
31851 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31852 + unsigned char d_type)
31854 +#ifdef CONFIG_AUFS_SHWH
31855 + wh->wh_ino = ino;
31856 + wh->wh_type = d_type;
31860 +/* ---------------------------------------------------------------------- */
31862 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31863 + unsigned int d_type, aufs_bindex_t bindex,
31864 + unsigned char shwh)
31867 + struct au_vdir_destr *str;
31868 + struct au_vdir_wh *wh;
31870 + AuDbg("%.*s\n", nlen, name);
31871 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31874 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31875 + if (unlikely(!wh))
31879 + wh->wh_bindex = bindex;
31881 + au_shwh_init_wh(wh, ino, d_type);
31882 + str = &wh->wh_str;
31884 + memcpy(str->name, name, nlen);
31885 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31892 +static int append_deblk(struct au_vdir *vdir)
31895 + unsigned long ul;
31896 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31897 + union au_vdir_deblk_p p, deblk_end;
31898 + unsigned char **o;
31901 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31902 + GFP_NOFS, /*may_shrink*/0);
31903 + if (unlikely(!o))
31906 + vdir->vd_deblk = o;
31907 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31909 + ul = vdir->vd_nblk++;
31910 + vdir->vd_deblk[ul] = p.deblk;
31911 + vdir->vd_last.ul = ul;
31912 + vdir->vd_last.p.deblk = p.deblk;
31913 + deblk_end.deblk = p.deblk + deblk_sz;
31914 + err = set_deblk_end(&p, &deblk_end);
31921 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31922 + unsigned int d_type, struct au_nhash *delist)
31926 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31927 + union au_vdir_deblk_p p, *room, deblk_end;
31928 + struct au_vdir_dehstr *dehstr;
31930 + p.deblk = last_deblk(vdir);
31931 + deblk_end.deblk = p.deblk + deblk_sz;
31932 + room = &vdir->vd_last.p;
31933 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31934 + || !is_deblk_end(room, &deblk_end));
31936 + sz = calc_size(nlen);
31937 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31938 + err = append_deblk(vdir);
31939 + if (unlikely(err))
31942 + p.deblk = last_deblk(vdir);
31943 + deblk_end.deblk = p.deblk + deblk_sz;
31945 + AuDebugOn(room->deblk != p.deblk);
31949 + dehstr = au_cache_alloc_vdir_dehstr();
31950 + if (unlikely(!dehstr))
31953 + dehstr->str = &room->de->de_str;
31954 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31955 + room->de->de_ino = ino;
31956 + room->de->de_type = d_type;
31957 + room->de->de_str.len = nlen;
31958 + memcpy(room->de->de_str.name, name, nlen);
31961 + room->deblk += sz;
31962 + if (unlikely(set_deblk_end(room, &deblk_end)))
31963 + err = append_deblk(vdir);
31970 +/* ---------------------------------------------------------------------- */
31972 +void au_vdir_free(struct au_vdir *vdir)
31974 + unsigned char **deblk;
31976 + deblk = vdir->vd_deblk;
31977 + while (vdir->vd_nblk--)
31979 + kfree(vdir->vd_deblk);
31980 + au_cache_free_vdir(vdir);
31983 +static struct au_vdir *alloc_vdir(struct file *file)
31985 + struct au_vdir *vdir;
31986 + struct super_block *sb;
31989 + sb = file->f_path.dentry->d_sb;
31990 + SiMustAnyLock(sb);
31993 + vdir = au_cache_alloc_vdir();
31994 + if (unlikely(!vdir))
31997 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
31998 + if (unlikely(!vdir->vd_deblk))
32001 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32002 + if (!vdir->vd_deblk_sz) {
32003 + /* estimate the appropriate size for deblk */
32004 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32005 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32007 + vdir->vd_nblk = 0;
32008 + vdir->vd_version = 0;
32009 + vdir->vd_jiffy = 0;
32010 + err = append_deblk(vdir);
32012 + return vdir; /* success */
32014 + kfree(vdir->vd_deblk);
32017 + au_cache_free_vdir(vdir);
32019 + vdir = ERR_PTR(err);
32023 +static int reinit_vdir(struct au_vdir *vdir)
32026 + union au_vdir_deblk_p p, deblk_end;
32028 + while (vdir->vd_nblk > 1) {
32029 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
32030 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32033 + p.deblk = vdir->vd_deblk[0];
32034 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32035 + err = set_deblk_end(&p, &deblk_end);
32036 + /* keep vd_dblk_sz */
32037 + vdir->vd_last.ul = 0;
32038 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32039 + vdir->vd_version = 0;
32040 + vdir->vd_jiffy = 0;
32045 +/* ---------------------------------------------------------------------- */
32047 +#define AuFillVdir_CALLED 1
32048 +#define AuFillVdir_WHABLE (1 << 1)
32049 +#define AuFillVdir_SHWH (1 << 2)
32050 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32051 +#define au_fset_fillvdir(flags, name) \
32052 + do { (flags) |= AuFillVdir_##name; } while (0)
32053 +#define au_fclr_fillvdir(flags, name) \
32054 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32056 +#ifndef CONFIG_AUFS_SHWH
32057 +#undef AuFillVdir_SHWH
32058 +#define AuFillVdir_SHWH 0
32061 +struct fillvdir_arg {
32062 + struct dir_context ctx;
32063 + struct file *file;
32064 + struct au_vdir *vdir;
32065 + struct au_nhash delist;
32066 + struct au_nhash whlist;
32067 + aufs_bindex_t bindex;
32068 + unsigned int flags;
32072 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32073 + loff_t offset __maybe_unused, u64 h_ino,
32074 + unsigned int d_type)
32076 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32077 + char *name = (void *)__name;
32078 + struct super_block *sb;
32080 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32083 + sb = arg->file->f_path.dentry->d_sb;
32084 + au_fset_fillvdir(arg->flags, CALLED);
32086 + if (nlen <= AUFS_WH_PFX_LEN
32087 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32088 + if (test_known(&arg->delist, name, nlen)
32089 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32090 + goto out; /* already exists or whiteouted */
32092 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32094 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32095 + d_type = DT_UNKNOWN;
32096 + arg->err = append_de(arg->vdir, name, nlen, ino,
32097 + d_type, &arg->delist);
32099 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32100 + name += AUFS_WH_PFX_LEN;
32101 + nlen -= AUFS_WH_PFX_LEN;
32102 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32103 + goto out; /* already whiteouted */
32106 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32109 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32110 + d_type = DT_UNKNOWN;
32111 + arg->err = au_nhash_append_wh
32112 + (&arg->whlist, name, nlen, ino, d_type,
32113 + arg->bindex, shwh);
32119 + arg->vdir->vd_jiffy = jiffies;
32121 + AuTraceErr(arg->err);
32125 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32126 + struct au_nhash *whlist, struct au_nhash *delist)
32128 +#ifdef CONFIG_AUFS_SHWH
32130 + unsigned int nh, u;
32131 + struct hlist_head *head;
32132 + struct au_vdir_wh *pos;
32133 + struct hlist_node *n;
32135 + struct au_vdir_destr *destr;
32137 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32140 + o = p = (void *)__get_free_page(GFP_NOFS);
32141 + if (unlikely(!p))
32145 + nh = whlist->nh_num;
32146 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32147 + p += AUFS_WH_PFX_LEN;
32148 + for (u = 0; u < nh; u++) {
32149 + head = whlist->nh_head + u;
32150 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32151 + destr = &pos->wh_str;
32152 + memcpy(p, destr->name, destr->len);
32153 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32154 + pos->wh_ino, pos->wh_type, delist);
32155 + if (unlikely(err))
32160 + free_page((unsigned long)o);
32170 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32173 + unsigned int rdhash;
32175 + aufs_bindex_t bbot, bindex, btop;
32176 + unsigned char shwh;
32177 + struct file *hf, *file;
32178 + struct super_block *sb;
32180 + file = arg->file;
32181 + sb = file->f_path.dentry->d_sb;
32182 + SiMustAnyLock(sb);
32184 + rdhash = au_sbi(sb)->si_rdhash;
32186 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32187 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32188 + if (unlikely(err))
32190 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32191 + if (unlikely(err))
32197 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32199 + au_fset_fillvdir(arg->flags, SHWH);
32201 + btop = au_fbtop(file);
32202 + bbot = au_fbbot_dir(file);
32203 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32204 + hf = au_hf_dir(file, bindex);
32208 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32210 + if (unlikely(offset))
32213 + arg->bindex = bindex;
32214 + au_fclr_fillvdir(arg->flags, WHABLE);
32216 + || (bindex != bbot
32217 + && au_br_whable(au_sbr_perm(sb, bindex))))
32218 + au_fset_fillvdir(arg->flags, WHABLE);
32221 + au_fclr_fillvdir(arg->flags, CALLED);
32223 + err = vfsub_iterate_dir(hf, &arg->ctx);
32226 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32229 + * dir_relax() may be good for concurrency, but aufs should not
32230 + * use it since it will cause a lockdep problem.
32234 + if (!err && shwh)
32235 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32237 + au_nhash_wh_free(&arg->whlist);
32240 + au_nhash_de_free(&arg->delist);
32245 +static int read_vdir(struct file *file, int may_read)
32248 + unsigned long expire;
32249 + unsigned char do_read;
32250 + struct fillvdir_arg arg = {
32252 + .actor = fillvdir
32255 + struct inode *inode;
32256 + struct au_vdir *vdir, *allocated;
32259 + inode = file_inode(file);
32260 + IMustLock(inode);
32261 + IiMustWriteLock(inode);
32262 + SiMustAnyLock(inode->i_sb);
32264 + allocated = NULL;
32266 + expire = au_sbi(inode->i_sb)->si_rdcache;
32267 + vdir = au_ivdir(inode);
32270 + vdir = alloc_vdir(file);
32271 + err = PTR_ERR(vdir);
32272 + if (IS_ERR(vdir))
32275 + allocated = vdir;
32276 + } else if (may_read
32277 + && (!inode_eq_iversion(inode, vdir->vd_version)
32278 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32280 + err = reinit_vdir(vdir);
32281 + if (unlikely(err))
32286 + return 0; /* success */
32290 + err = au_do_read_vdir(&arg);
32292 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32293 + vdir->vd_version = inode_query_iversion(inode);
32294 + vdir->vd_last.ul = 0;
32295 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32297 + au_set_ivdir(inode, allocated);
32298 + } else if (allocated)
32299 + au_vdir_free(allocated);
32305 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32308 + unsigned long ul, n;
32309 + const unsigned int deblk_sz = src->vd_deblk_sz;
32311 + AuDebugOn(tgt->vd_nblk != 1);
32314 + if (tgt->vd_nblk < src->vd_nblk) {
32315 + unsigned char **p;
32317 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32318 + GFP_NOFS, /*may_shrink*/0);
32319 + if (unlikely(!p))
32321 + tgt->vd_deblk = p;
32324 + if (tgt->vd_deblk_sz != deblk_sz) {
32325 + unsigned char *p;
32327 + tgt->vd_deblk_sz = deblk_sz;
32328 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32329 + /*may_shrink*/1);
32330 + if (unlikely(!p))
32332 + tgt->vd_deblk[0] = p;
32334 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32335 + tgt->vd_version = src->vd_version;
32336 + tgt->vd_jiffy = src->vd_jiffy;
32338 + n = src->vd_nblk;
32339 + for (ul = 1; ul < n; ul++) {
32340 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32342 + if (unlikely(!tgt->vd_deblk[ul]))
32346 + tgt->vd_nblk = n;
32347 + tgt->vd_last.ul = tgt->vd_last.ul;
32348 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32349 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32350 + - src->vd_deblk[src->vd_last.ul];
32352 + return 0; /* success */
32355 + rerr = reinit_vdir(tgt);
32360 +int au_vdir_init(struct file *file)
32363 + struct inode *inode;
32364 + struct au_vdir *vdir_cache, *allocated;
32366 + /* test file->f_pos here instead of ctx->pos */
32367 + err = read_vdir(file, !file->f_pos);
32368 + if (unlikely(err))
32371 + allocated = NULL;
32372 + vdir_cache = au_fvdir_cache(file);
32373 + if (!vdir_cache) {
32374 + vdir_cache = alloc_vdir(file);
32375 + err = PTR_ERR(vdir_cache);
32376 + if (IS_ERR(vdir_cache))
32378 + allocated = vdir_cache;
32379 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32380 + /* test file->f_pos here instead of ctx->pos */
32381 + err = reinit_vdir(vdir_cache);
32382 + if (unlikely(err))
32385 + return 0; /* success */
32387 + inode = file_inode(file);
32388 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32390 + file->f_version = inode_query_iversion(inode);
32392 + au_set_fvdir_cache(file, allocated);
32393 + } else if (allocated)
32394 + au_vdir_free(allocated);
32400 +static loff_t calc_offset(struct au_vdir *vdir)
32403 + union au_vdir_deblk_p p;
32405 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32406 + offset = vdir->vd_last.p.deblk - p.deblk;
32407 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32411 +/* returns true or false */
32412 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32415 + unsigned int deblk_sz;
32416 + unsigned long ul, n;
32418 + union au_vdir_deblk_p p, deblk_end;
32419 + struct au_vdir *vdir_cache;
32422 + vdir_cache = au_fvdir_cache(file);
32423 + offset = calc_offset(vdir_cache);
32424 + AuDbg("offset %lld\n", offset);
32425 + if (ctx->pos == offset)
32428 + vdir_cache->vd_last.ul = 0;
32429 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32434 + deblk_sz = vdir_cache->vd_deblk_sz;
32435 + ul = div64_u64(ctx->pos, deblk_sz);
32436 + AuDbg("ul %lu\n", ul);
32437 + if (ul >= vdir_cache->vd_nblk)
32440 + n = vdir_cache->vd_nblk;
32441 + for (; ul < n; ul++) {
32442 + p.deblk = vdir_cache->vd_deblk[ul];
32443 + deblk_end.deblk = p.deblk + deblk_sz;
32445 + offset *= deblk_sz;
32446 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32449 + l = calc_size(p.de->de_str.len);
32453 + if (!is_deblk_end(&p, &deblk_end)) {
32455 + vdir_cache->vd_last.ul = ul;
32456 + vdir_cache->vd_last.p = p;
32464 + AuDbg("valid %d\n", !valid);
32468 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32470 + unsigned int l, deblk_sz;
32471 + union au_vdir_deblk_p deblk_end;
32472 + struct au_vdir *vdir_cache;
32473 + struct au_vdir_de *de;
32475 + vdir_cache = au_fvdir_cache(file);
32476 + if (!seek_vdir(file, ctx))
32479 + deblk_sz = vdir_cache->vd_deblk_sz;
32481 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32482 + deblk_end.deblk += deblk_sz;
32483 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32484 + de = vdir_cache->vd_last.p.de;
32485 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32486 + de->de_str.len, de->de_str.name, ctx->pos,
32487 + (unsigned long)de->de_ino, de->de_type);
32488 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32489 + de->de_str.len, de->de_ino,
32491 + /* todo: ignore the error caused by udba? */
32492 + /* return err; */
32496 + l = calc_size(de->de_str.len);
32497 + vdir_cache->vd_last.p.deblk += l;
32500 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32501 + vdir_cache->vd_last.ul++;
32502 + vdir_cache->vd_last.p.deblk
32503 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32504 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32513 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32514 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32515 +++ linux/fs/aufs/vfsub.c 2018-07-19 09:46:13.063314675 +0200
32517 +/* SPDX-License-Identifier: GPL-2.0 */
32519 + * Copyright (C) 2005-2018 Junjiro R. Okajima
32521 + * This program, aufs is free software; you can redistribute it and/or modify
32522 + * it under the terms of the GNU General Public License as published by
32523 + * the Free Software Foundation; either version 2 of the License, or
32524 + * (at your option) any later version.
32526 + * This program is distributed in the hope that it will be useful,
32527 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32528 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32529 + * GNU General Public License for more details.
32531 + * You should have received a copy of the GNU General Public License
32532 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32536 + * sub-routines for VFS
32539 +#include <linux/mnt_namespace.h>
32540 +#include <linux/namei.h>
32541 +#include <linux/nsproxy.h>
32542 +#include <linux/security.h>
32543 +#include <linux/splice.h>
32546 +#ifdef CONFIG_AUFS_BR_FUSE
32547 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32549 + if (!au_test_fuse(h_sb) || !au_userns)
32552 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32556 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32561 + down_read(&h_sb->s_umount);
32562 + err = __sync_filesystem(h_sb, wait);
32563 + up_read(&h_sb->s_umount);
32569 +/* ---------------------------------------------------------------------- */
32571 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32575 + struct super_block *h_sb;
32577 + /* for remote fs, leave work for its getattr or d_revalidate */
32578 + /* for bad i_attr fs, handle them in aufs_getattr() */
32579 + /* still some fs may acquire i_mutex. we need to skip them */
32583 + h_sb = h_path->dentry->d_sb;
32584 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32586 + err = vfsub_getattr(h_path, &st);
32591 +/* ---------------------------------------------------------------------- */
32593 +struct file *vfsub_dentry_open(struct path *path, int flags)
32595 + struct file *file;
32597 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32599 + if (!IS_ERR_OR_NULL(file)
32600 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32601 + i_readcount_inc(d_inode(path->dentry));
32606 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32608 + struct file *file;
32611 + file = filp_open(path,
32612 + oflags /* | __FMODE_NONOTIFY */,
32615 + if (IS_ERR(file))
32617 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32624 + * Ideally this function should call VFS:do_last() in order to keep all its
32625 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32626 + * structure such as nameidata. This is a second (or third) best approach.
32627 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32629 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32630 + struct vfsub_aopen_args *args, struct au_branch *br)
32633 + struct file *file = args->file;
32634 + /* copied from linux/fs/namei.c:atomic_open() */
32635 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32638 + AuDebugOn(!dir->i_op->atomic_open);
32640 + err = au_br_test_oflag(args->open_flag, br);
32641 + if (unlikely(err))
32644 + args->file->f_path.dentry = DENTRY_NOT_SET;
32645 + args->file->f_path.mnt = au_br_mnt(br);
32646 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32647 + args->create_mode, args->opened);
32649 + /* some filesystems don't set FILE_CREATED while succeeded? */
32650 + if (*args->opened & FILE_CREATED)
32651 + fsnotify_create(dir, dentry);
32657 + /* todo: call VFS:may_open() here */
32658 + err = open_check_o_direct(file);
32659 + /* todo: ima_file_check() too? */
32660 + if (!err && (args->open_flag & __FMODE_EXEC))
32661 + err = deny_write_access(file);
32662 + if (unlikely(err))
32663 + /* note that the file is created and still opened */
32668 + fsnotify_open(file);
32674 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32678 + err = kern_path(name, flags, path);
32679 + if (!err && d_is_positive(path->dentry))
32680 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32684 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32685 + struct dentry *parent, int len)
32687 + struct path path = {
32691 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32692 + if (IS_ERR(path.dentry))
32694 + if (d_is_positive(path.dentry))
32695 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32698 + AuTraceErrPtr(path.dentry);
32699 + return path.dentry;
32702 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32705 + struct path path = {
32709 + /* VFS checks it too, but by WARN_ON_ONCE() */
32710 + IMustLock(d_inode(parent));
32712 + path.dentry = lookup_one_len(name, parent, len);
32713 + if (IS_ERR(path.dentry))
32715 + if (d_is_positive(path.dentry))
32716 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32719 + AuTraceErrPtr(path.dentry);
32720 + return path.dentry;
32723 +void vfsub_call_lkup_one(void *args)
32725 + struct vfsub_lkup_one_args *a = args;
32726 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32729 +/* ---------------------------------------------------------------------- */
32731 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32732 + struct dentry *d2, struct au_hinode *hdir2)
32734 + struct dentry *d;
32737 + d = lock_rename(d1, d2);
32739 + au_hn_suspend(hdir1);
32740 + if (hdir1 != hdir2)
32741 + au_hn_suspend(hdir2);
32746 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32747 + struct dentry *d2, struct au_hinode *hdir2)
32749 + au_hn_resume(hdir1);
32750 + if (hdir1 != hdir2)
32751 + au_hn_resume(hdir2);
32753 + unlock_rename(d1, d2);
32757 +/* ---------------------------------------------------------------------- */
32759 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32762 + struct dentry *d;
32766 + d = path->dentry;
32767 + path->dentry = d->d_parent;
32768 + err = security_path_mknod(path, d, mode, 0);
32769 + path->dentry = d;
32770 + if (unlikely(err))
32774 + err = vfs_create(dir, path->dentry, mode, want_excl);
32777 + struct path tmp = *path;
32780 + vfsub_update_h_iattr(&tmp, &did);
32782 + tmp.dentry = path->dentry->d_parent;
32783 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32792 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32795 + struct dentry *d;
32799 + d = path->dentry;
32800 + path->dentry = d->d_parent;
32801 + err = security_path_symlink(path, d, symname);
32802 + path->dentry = d;
32803 + if (unlikely(err))
32807 + err = vfs_symlink(dir, path->dentry, symname);
32810 + struct path tmp = *path;
32813 + vfsub_update_h_iattr(&tmp, &did);
32815 + tmp.dentry = path->dentry->d_parent;
32816 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32825 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32828 + struct dentry *d;
32832 + d = path->dentry;
32833 + path->dentry = d->d_parent;
32834 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32835 + path->dentry = d;
32836 + if (unlikely(err))
32840 + err = vfs_mknod(dir, path->dentry, mode, dev);
32843 + struct path tmp = *path;
32846 + vfsub_update_h_iattr(&tmp, &did);
32848 + tmp.dentry = path->dentry->d_parent;
32849 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32858 +static int au_test_nlink(struct inode *inode)
32860 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32862 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32863 + || inode->i_nlink < link_max)
32868 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32869 + struct inode **delegated_inode)
32872 + struct dentry *d;
32876 + err = au_test_nlink(d_inode(src_dentry));
32877 + if (unlikely(err))
32880 + /* we don't call may_linkat() */
32881 + d = path->dentry;
32882 + path->dentry = d->d_parent;
32883 + err = security_path_link(src_dentry, path, d);
32884 + path->dentry = d;
32885 + if (unlikely(err))
32889 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32892 + struct path tmp = *path;
32895 + /* fuse has different memory inode for the same inumber */
32896 + vfsub_update_h_iattr(&tmp, &did);
32898 + tmp.dentry = path->dentry->d_parent;
32899 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32900 + tmp.dentry = src_dentry;
32901 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32910 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32911 + struct inode *dir, struct path *path,
32912 + struct inode **delegated_inode, unsigned int flags)
32915 + struct path tmp = {
32918 + struct dentry *d;
32921 + IMustLock(src_dir);
32923 + d = path->dentry;
32924 + path->dentry = d->d_parent;
32925 + tmp.dentry = src_dentry->d_parent;
32926 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32927 + path->dentry = d;
32928 + if (unlikely(err))
32932 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32933 + delegated_inode, flags);
32938 + tmp.dentry = d->d_parent;
32939 + vfsub_update_h_iattr(&tmp, &did);
32941 + tmp.dentry = src_dentry;
32942 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32943 + tmp.dentry = src_dentry->d_parent;
32944 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32953 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32956 + struct dentry *d;
32960 + d = path->dentry;
32961 + path->dentry = d->d_parent;
32962 + err = security_path_mkdir(path, d, mode);
32963 + path->dentry = d;
32964 + if (unlikely(err))
32968 + err = vfs_mkdir(dir, path->dentry, mode);
32971 + struct path tmp = *path;
32974 + vfsub_update_h_iattr(&tmp, &did);
32976 + tmp.dentry = path->dentry->d_parent;
32977 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32986 +int vfsub_rmdir(struct inode *dir, struct path *path)
32989 + struct dentry *d;
32993 + d = path->dentry;
32994 + path->dentry = d->d_parent;
32995 + err = security_path_rmdir(path, d);
32996 + path->dentry = d;
32997 + if (unlikely(err))
33001 + err = vfs_rmdir(dir, path->dentry);
33004 + struct path tmp = {
33005 + .dentry = path->dentry->d_parent,
33009 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33016 +/* ---------------------------------------------------------------------- */
33018 +/* todo: support mmap_sem? */
33019 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33025 + err = vfs_read(file, ubuf, count, ppos);
33028 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33032 +/* todo: kernel_read()? */
33033 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33037 + mm_segment_t oldfs;
33044 + oldfs = get_fs();
33045 + set_fs(KERNEL_DS);
33046 + err = vfsub_read_u(file, buf.u, count, ppos);
33051 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33057 + err = vfs_write(file, ubuf, count, ppos);
33060 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33064 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33067 + mm_segment_t oldfs;
33070 + const char __user *u;
33074 + oldfs = get_fs();
33075 + set_fs(KERNEL_DS);
33076 + err = vfsub_write_u(file, buf.u, count, ppos);
33081 +int vfsub_flush(struct file *file, fl_owner_t id)
33086 + if (file->f_op->flush) {
33087 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33088 + err = file->f_op->flush(file, id);
33091 + err = file->f_op->flush(file, id);
33095 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33101 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33105 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33108 + err = iterate_dir(file, ctx);
33111 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33116 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33117 + struct pipe_inode_info *pipe, size_t len,
33118 + unsigned int flags)
33123 + err = do_splice_to(in, ppos, pipe, len, flags);
33125 + file_accessed(in);
33127 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33131 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33132 + loff_t *ppos, size_t len, unsigned int flags)
33137 + err = do_splice_from(pipe, out, ppos, len, flags);
33140 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33144 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33148 + /* file can be NULL */
33150 + err = vfs_fsync(file, datasync);
33154 + AuDebugOn(!file);
33155 + path = &file->f_path;
33157 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33162 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33163 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33164 + struct file *h_file)
33167 + struct inode *h_inode;
33168 + struct super_block *h_sb;
33171 + err = vfsub_truncate(h_path, length);
33175 + h_inode = d_inode(h_path->dentry);
33176 + h_sb = h_inode->i_sb;
33178 + sb_start_write(h_sb);
33180 + err = locks_verify_truncate(h_inode, h_file, length);
33182 + err = security_path_truncate(h_path);
33185 + err = do_truncate(h_path->dentry, length, attr, h_file);
33189 + sb_end_write(h_sb);
33196 +/* ---------------------------------------------------------------------- */
33198 +struct au_vfsub_mkdir_args {
33200 + struct inode *dir;
33201 + struct path *path;
33205 +static void au_call_vfsub_mkdir(void *args)
33207 + struct au_vfsub_mkdir_args *a = args;
33208 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33211 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33213 + int err, do_sio, wkq_err;
33215 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33218 + err = vfsub_mkdir(dir, path, mode);
33221 + struct au_vfsub_mkdir_args args = {
33227 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33228 + if (unlikely(wkq_err))
33235 +struct au_vfsub_rmdir_args {
33237 + struct inode *dir;
33238 + struct path *path;
33241 +static void au_call_vfsub_rmdir(void *args)
33243 + struct au_vfsub_rmdir_args *a = args;
33244 + *a->errp = vfsub_rmdir(a->dir, a->path);
33247 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33249 + int err, do_sio, wkq_err;
33251 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33254 + err = vfsub_rmdir(dir, path);
33257 + struct au_vfsub_rmdir_args args = {
33262 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33263 + if (unlikely(wkq_err))
33270 +/* ---------------------------------------------------------------------- */
33272 +struct notify_change_args {
33274 + struct path *path;
33275 + struct iattr *ia;
33276 + struct inode **delegated_inode;
33279 +static void call_notify_change(void *args)
33281 + struct notify_change_args *a = args;
33282 + struct inode *h_inode;
33284 + h_inode = d_inode(a->path->dentry);
33285 + IMustLock(h_inode);
33287 + *a->errp = -EPERM;
33288 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33290 + *a->errp = notify_change(a->path->dentry, a->ia,
33291 + a->delegated_inode);
33294 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33296 + AuTraceErr(*a->errp);
33299 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33300 + struct inode **delegated_inode)
33303 + struct notify_change_args args = {
33307 + .delegated_inode = delegated_inode
33310 + call_notify_change(&args);
33315 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33316 + struct inode **delegated_inode)
33318 + int err, wkq_err;
33319 + struct notify_change_args args = {
33323 + .delegated_inode = delegated_inode
33326 + wkq_err = au_wkq_wait(call_notify_change, &args);
33327 + if (unlikely(wkq_err))
33333 +/* ---------------------------------------------------------------------- */
33335 +struct unlink_args {
33337 + struct inode *dir;
33338 + struct path *path;
33339 + struct inode **delegated_inode;
33342 +static void call_unlink(void *args)
33344 + struct unlink_args *a = args;
33345 + struct dentry *d = a->path->dentry;
33346 + struct inode *h_inode;
33347 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33348 + && au_dcount(d) == 1);
33350 + IMustLock(a->dir);
33352 + a->path->dentry = d->d_parent;
33353 + *a->errp = security_path_unlink(a->path, d);
33354 + a->path->dentry = d;
33355 + if (unlikely(*a->errp))
33358 + if (!stop_sillyrename)
33361 + if (d_is_positive(d)) {
33362 + h_inode = d_inode(d);
33367 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33370 + struct path tmp = {
33371 + .dentry = d->d_parent,
33372 + .mnt = a->path->mnt
33374 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33377 + if (!stop_sillyrename)
33382 + AuTraceErr(*a->errp);
33386 + * @dir: must be locked.
33387 + * @dentry: target dentry.
33389 +int vfsub_unlink(struct inode *dir, struct path *path,
33390 + struct inode **delegated_inode, int force)
33393 + struct unlink_args args = {
33397 + .delegated_inode = delegated_inode
33401 + call_unlink(&args);
33405 + wkq_err = au_wkq_wait(call_unlink, &args);
33406 + if (unlikely(wkq_err))
33412 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33413 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33414 +++ linux/fs/aufs/vfsub.h 2018-07-19 09:46:13.063314675 +0200
33416 +/* SPDX-License-Identifier: GPL-2.0 */
33418 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33420 + * This program, aufs is free software; you can redistribute it and/or modify
33421 + * it under the terms of the GNU General Public License as published by
33422 + * the Free Software Foundation; either version 2 of the License, or
33423 + * (at your option) any later version.
33425 + * This program is distributed in the hope that it will be useful,
33426 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33427 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33428 + * GNU General Public License for more details.
33430 + * You should have received a copy of the GNU General Public License
33431 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33435 + * sub-routines for VFS
33438 +#ifndef __AUFS_VFSUB_H__
33439 +#define __AUFS_VFSUB_H__
33443 +#include <linux/fs.h>
33444 +#include <linux/iversion.h>
33445 +#include <linux/mount.h>
33446 +#include <linux/posix_acl.h>
33447 +#include <linux/xattr.h>
33448 +#include "debug.h"
33450 +/* copied from linux/fs/internal.h */
33451 +/* todo: BAD approach!! */
33452 +extern void __mnt_drop_write(struct vfsmount *);
33453 +extern int open_check_o_direct(struct file *f);
33455 +/* ---------------------------------------------------------------------- */
33457 +/* lock subclass for lower inode */
33458 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33459 +/* reduce? gave up. */
33461 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33462 + AuLsc_I_PARENT, /* lower inode, parent first */
33463 + AuLsc_I_PARENT2, /* copyup dirs */
33464 + AuLsc_I_PARENT3, /* copyup wh */
33470 +/* to debug easier, do not make them inlined functions */
33471 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33472 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33474 +/* ---------------------------------------------------------------------- */
33476 +static inline void vfsub_drop_nlink(struct inode *inode)
33478 + AuDebugOn(!inode->i_nlink);
33479 + drop_nlink(inode);
33482 +static inline void vfsub_dead_dir(struct inode *inode)
33484 + AuDebugOn(!S_ISDIR(inode->i_mode));
33485 + inode->i_flags |= S_DEAD;
33486 + clear_nlink(inode);
33489 +static inline int vfsub_native_ro(struct inode *inode)
33491 + return sb_rdonly(inode->i_sb)
33492 + || IS_RDONLY(inode)
33493 + /* || IS_APPEND(inode) */
33494 + || IS_IMMUTABLE(inode);
33497 +#ifdef CONFIG_AUFS_BR_FUSE
33498 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33500 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33503 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33505 +/* ---------------------------------------------------------------------- */
33507 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33508 +struct file *vfsub_dentry_open(struct path *path, int flags);
33509 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33510 +struct vfsub_aopen_args {
33511 + struct file *file;
33512 + unsigned int open_flag;
33513 + umode_t create_mode;
33517 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33518 + struct vfsub_aopen_args *args, struct au_branch *br);
33519 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33521 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33522 + struct dentry *parent, int len);
33523 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33526 +struct vfsub_lkup_one_args {
33527 + struct dentry **errp;
33528 + struct qstr *name;
33529 + struct dentry *parent;
33532 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33533 + struct dentry *parent)
33535 + return vfsub_lookup_one_len(name->name, parent, name->len);
33538 +void vfsub_call_lkup_one(void *args);
33540 +/* ---------------------------------------------------------------------- */
33542 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33547 + err = mnt_want_write(mnt);
33552 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33555 + mnt_drop_write(mnt);
33559 +#if 0 /* reserved */
33560 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33563 + mnt_drop_write_file(file);
33568 +/* ---------------------------------------------------------------------- */
33571 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33572 + struct dentry *d2, struct au_hinode *hdir2);
33573 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33574 + struct dentry *d2, struct au_hinode *hdir2);
33576 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33578 +int vfsub_symlink(struct inode *dir, struct path *path,
33579 + const char *symname);
33580 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33581 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33582 + struct path *path, struct inode **delegated_inode);
33583 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33584 + struct inode *hdir, struct path *path,
33585 + struct inode **delegated_inode, unsigned int flags);
33586 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33587 +int vfsub_rmdir(struct inode *dir, struct path *path);
33589 +/* ---------------------------------------------------------------------- */
33591 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33593 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33595 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33597 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33599 +int vfsub_flush(struct file *file, fl_owner_t id);
33600 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33602 +static inline loff_t vfsub_f_size_read(struct file *file)
33604 + return i_size_read(file_inode(file));
33607 +static inline unsigned int vfsub_file_flags(struct file *file)
33609 + unsigned int flags;
33611 + spin_lock(&file->f_lock);
33612 + flags = file->f_flags;
33613 + spin_unlock(&file->f_lock);
33618 +static inline int vfsub_file_execed(struct file *file)
33620 + /* todo: direct access f_flags */
33621 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33624 +#if 0 /* reserved */
33625 +static inline void vfsub_file_accessed(struct file *h_file)
33627 + file_accessed(h_file);
33628 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33632 +#if 0 /* reserved */
33633 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33634 + struct dentry *h_dentry)
33636 + struct path h_path = {
33637 + .dentry = h_dentry,
33640 + touch_atime(&h_path);
33641 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33645 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
33648 + return update_time(h_inode, ts, flags);
33649 + /* no vfsub_update_h_iattr() since we don't have struct path */
33652 +#ifdef CONFIG_FS_POSIX_ACL
33653 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33657 + err = posix_acl_chmod(h_inode, h_mode);
33658 + if (err == -EOPNOTSUPP)
33663 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33666 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33667 + struct pipe_inode_info *pipe, size_t len,
33668 + unsigned int flags);
33669 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33670 + loff_t *ppos, size_t len, unsigned int flags);
33672 +static inline long vfsub_truncate(struct path *path, loff_t length)
33677 + err = vfs_truncate(path, length);
33682 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33683 + struct file *h_file);
33684 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33687 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33690 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33696 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33702 +/* copy_file_range(2) is a systemcall */
33703 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33704 + struct file *dst, loff_t dst_pos,
33705 + size_t len, unsigned int flags)
33710 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33716 +/* ---------------------------------------------------------------------- */
33718 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33723 + err = vfs_llseek(file, offset, origin);
33728 +/* ---------------------------------------------------------------------- */
33730 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33731 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33732 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33733 + struct inode **delegated_inode);
33734 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33735 + struct inode **delegated_inode);
33736 +int vfsub_unlink(struct inode *dir, struct path *path,
33737 + struct inode **delegated_inode, int force);
33739 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33741 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33744 +/* ---------------------------------------------------------------------- */
33746 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33747 + const void *value, size_t size, int flags)
33752 + err = vfs_setxattr(dentry, name, value, size, flags);
33758 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33763 + err = vfs_removexattr(dentry, name);
33769 +#endif /* __KERNEL__ */
33770 +#endif /* __AUFS_VFSUB_H__ */
33771 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33772 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33773 +++ linux/fs/aufs/wbr_policy.c 2018-07-19 09:46:13.063314675 +0200
33775 +/* SPDX-License-Identifier: GPL-2.0 */
33777 + * Copyright (C) 2005-2018 Junjiro R. Okajima
33779 + * This program, aufs is free software; you can redistribute it and/or modify
33780 + * it under the terms of the GNU General Public License as published by
33781 + * the Free Software Foundation; either version 2 of the License, or
33782 + * (at your option) any later version.
33784 + * This program is distributed in the hope that it will be useful,
33785 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33786 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33787 + * GNU General Public License for more details.
33789 + * You should have received a copy of the GNU General Public License
33790 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33794 + * policies for selecting one among multiple writable branches
33797 +#include <linux/statfs.h>
33800 +/* subset of cpup_attr() */
33801 +static noinline_for_stack
33802 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33806 + struct inode *h_isrc;
33808 + h_isrc = d_inode(h_src);
33809 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33810 + ia.ia_mode = h_isrc->i_mode;
33811 + ia.ia_uid = h_isrc->i_uid;
33812 + ia.ia_gid = h_isrc->i_gid;
33813 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33814 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33815 + /* no delegation since it is just created */
33816 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33818 + /* is this nfs only? */
33819 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33820 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33821 + ia.ia_mode = h_isrc->i_mode;
33822 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33828 +#define AuCpdown_PARENT_OPQ 1
33829 +#define AuCpdown_WHED (1 << 1)
33830 +#define AuCpdown_MADE_DIR (1 << 2)
33831 +#define AuCpdown_DIROPQ (1 << 3)
33832 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33833 +#define au_fset_cpdown(flags, name) \
33834 + do { (flags) |= AuCpdown_##name; } while (0)
33835 +#define au_fclr_cpdown(flags, name) \
33836 + do { (flags) &= ~AuCpdown_##name; } while (0)
33838 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33839 + unsigned int *flags)
33842 + struct dentry *opq_dentry;
33844 + opq_dentry = au_diropq_create(dentry, bdst);
33845 + err = PTR_ERR(opq_dentry);
33846 + if (IS_ERR(opq_dentry))
33848 + dput(opq_dentry);
33849 + au_fset_cpdown(*flags, DIROPQ);
33855 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33856 + struct inode *dir, aufs_bindex_t bdst)
33859 + struct path h_path;
33860 + struct au_branch *br;
33862 + br = au_sbr(dentry->d_sb, bdst);
33863 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33864 + err = PTR_ERR(h_path.dentry);
33865 + if (IS_ERR(h_path.dentry))
33869 + if (d_is_positive(h_path.dentry)) {
33870 + h_path.mnt = au_br_mnt(br);
33871 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33874 + dput(h_path.dentry);
33880 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33881 + struct au_pin *pin,
33882 + struct dentry *h_parent, void *arg)
33885 + aufs_bindex_t bopq, btop;
33886 + struct path h_path;
33887 + struct dentry *parent;
33888 + struct inode *h_dir, *h_inode, *inode, *dir;
33889 + unsigned int *flags = arg;
33891 + btop = au_dbtop(dentry);
33892 + /* dentry is di-locked */
33893 + parent = dget_parent(dentry);
33894 + dir = d_inode(parent);
33895 + h_dir = d_inode(h_parent);
33896 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33897 + IMustLock(h_dir);
33899 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33900 + if (unlikely(err < 0))
33902 + h_path.dentry = au_h_dptr(dentry, bdst);
33903 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33904 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
33905 + S_IRWXU | S_IRUGO | S_IXUGO);
33906 + if (unlikely(err))
33908 + au_fset_cpdown(*flags, MADE_DIR);
33910 + bopq = au_dbdiropq(dentry);
33911 + au_fclr_cpdown(*flags, WHED);
33912 + au_fclr_cpdown(*flags, DIROPQ);
33913 + if (au_dbwh(dentry) == bdst)
33914 + au_fset_cpdown(*flags, WHED);
33915 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33916 + au_fset_cpdown(*flags, PARENT_OPQ);
33917 + h_inode = d_inode(h_path.dentry);
33918 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33919 + if (au_ftest_cpdown(*flags, WHED)) {
33920 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33921 + if (unlikely(err)) {
33922 + inode_unlock(h_inode);
33927 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33928 + inode_unlock(h_inode);
33929 + if (unlikely(err))
33932 + if (au_ftest_cpdown(*flags, WHED)) {
33933 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33934 + if (unlikely(err))
33938 + inode = d_inode(dentry);
33939 + if (au_ibbot(inode) < bdst)
33940 + au_set_ibbot(inode, bdst);
33941 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33942 + au_hi_flags(inode, /*isdir*/1));
33943 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33944 + goto out; /* success */
33948 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33949 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33950 + rerr = au_diropq_remove(dentry, bdst);
33951 + inode_unlock(h_inode);
33952 + if (unlikely(rerr)) {
33953 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33954 + dentry, bdst, rerr);
33960 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33961 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33962 + if (unlikely(rerr)) {
33963 + AuIOErr("failed removing %pd b%d (%d)\n",
33964 + dentry, bdst, rerr);
33969 + au_set_h_dptr(dentry, bdst, NULL);
33970 + if (au_dbbot(dentry) == bdst)
33971 + au_update_dbbot(dentry);
33977 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
33980 + unsigned int flags;
33983 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
33988 +/* ---------------------------------------------------------------------- */
33990 +/* policies for create */
33992 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
33994 + int err, i, j, ndentry;
33995 + aufs_bindex_t bopq;
33996 + struct au_dcsub_pages dpages;
33997 + struct au_dpage *dpage;
33998 + struct dentry **dentries, *parent, *d;
34000 + err = au_dpages_init(&dpages, GFP_NOFS);
34001 + if (unlikely(err))
34003 + parent = dget_parent(dentry);
34004 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34005 + if (unlikely(err))
34009 + for (i = 0; i < dpages.ndpage; i++) {
34010 + dpage = dpages.dpages + i;
34011 + dentries = dpage->dentries;
34012 + ndentry = dpage->ndentry;
34013 + for (j = 0; j < ndentry; j++) {
34015 + di_read_lock_parent2(d, !AuLock_IR);
34016 + bopq = au_dbdiropq(d);
34017 + di_read_unlock(d, !AuLock_IR);
34018 + if (bopq >= 0 && bopq < err)
34025 + au_dpages_free(&dpages);
34030 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34032 + for (; bindex >= 0; bindex--)
34033 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34038 +/* top down parent */
34039 +static int au_wbr_create_tdp(struct dentry *dentry,
34040 + unsigned int flags __maybe_unused)
34043 + aufs_bindex_t btop, bindex;
34044 + struct super_block *sb;
34045 + struct dentry *parent, *h_parent;
34047 + sb = dentry->d_sb;
34048 + btop = au_dbtop(dentry);
34050 + if (!au_br_rdonly(au_sbr(sb, btop)))
34054 + parent = dget_parent(dentry);
34055 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34056 + h_parent = au_h_dptr(parent, bindex);
34057 + if (!h_parent || d_is_negative(h_parent))
34060 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34067 + /* bottom up here */
34068 + if (unlikely(err < 0)) {
34069 + err = au_wbr_bu(sb, btop - 1);
34071 + err = au_wbr_nonopq(dentry, err);
34075 + AuDbg("b%d\n", err);
34079 +/* ---------------------------------------------------------------------- */
34081 +/* an exception for the policy other than tdp */
34082 +static int au_wbr_create_exp(struct dentry *dentry)
34085 + aufs_bindex_t bwh, bdiropq;
34086 + struct dentry *parent;
34089 + bwh = au_dbwh(dentry);
34090 + parent = dget_parent(dentry);
34091 + bdiropq = au_dbdiropq(parent);
34093 + if (bdiropq >= 0)
34094 + err = min(bdiropq, bwh);
34097 + AuDbg("%d\n", err);
34098 + } else if (bdiropq >= 0) {
34100 + AuDbg("%d\n", err);
34105 + err = au_wbr_nonopq(dentry, err);
34107 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34110 + AuDbg("%d\n", err);
34114 +/* ---------------------------------------------------------------------- */
34117 +static int au_wbr_create_init_rr(struct super_block *sb)
34121 + err = au_wbr_bu(sb, au_sbbot(sb));
34122 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34125 + AuDbg("b%d\n", err);
34129 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34133 + aufs_bindex_t bindex, bbot;
34134 + struct super_block *sb;
34137 + err = au_wbr_create_exp(dentry);
34141 + sb = dentry->d_sb;
34142 + next = &au_sbi(sb)->si_wbr_rr_next;
34143 + bbot = au_sbbot(sb);
34145 + for (bindex = 0; bindex <= bbot; bindex++) {
34146 + if (!au_ftest_wbr(flags, DIR)) {
34147 + err = atomic_dec_return(next) + 1;
34148 + /* modulo for 0 is meaningless */
34149 + if (unlikely(!err))
34150 + err = atomic_dec_return(next) + 1;
34152 + err = atomic_read(next);
34153 + AuDbg("%d\n", err);
34156 + AuDbg("%d\n", err);
34157 + if (!au_br_rdonly(au_sbr(sb, err)))
34163 + err = au_wbr_nonopq(dentry, err);
34166 + AuDbg("%d\n", err);
34170 +/* ---------------------------------------------------------------------- */
34172 +/* most free space */
34173 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34175 + struct super_block *sb;
34176 + struct au_branch *br;
34177 + struct au_wbr_mfs *mfs;
34178 + struct dentry *h_parent;
34179 + aufs_bindex_t bindex, bbot;
34181 + unsigned long long b, bavail;
34182 + struct path h_path;
34183 + /* reduce the stack usage */
34184 + struct kstatfs *st;
34186 + st = kmalloc(sizeof(*st), GFP_NOFS);
34187 + if (unlikely(!st)) {
34188 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34193 + sb = dentry->d_sb;
34194 + mfs = &au_sbi(sb)->si_wbr_mfs;
34195 + MtxMustLock(&mfs->mfs_lock);
34196 + mfs->mfs_bindex = -EROFS;
34197 + mfs->mfsrr_bytes = 0;
34200 + bbot = au_sbbot(sb);
34202 + bindex = au_dbtop(parent);
34203 + bbot = au_dbtaildir(parent);
34206 + for (; bindex <= bbot; bindex++) {
34208 + h_parent = au_h_dptr(parent, bindex);
34209 + if (!h_parent || d_is_negative(h_parent))
34212 + br = au_sbr(sb, bindex);
34213 + if (au_br_rdonly(br))
34216 + /* sb->s_root for NFS is unreliable */
34217 + h_path.mnt = au_br_mnt(br);
34218 + h_path.dentry = h_path.mnt->mnt_root;
34219 + err = vfs_statfs(&h_path, st);
34220 + if (unlikely(err)) {
34221 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34225 + /* when the available size is equal, select the lower one */
34226 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34227 + || sizeof(b) < sizeof(st->f_bsize));
34228 + b = st->f_bavail * st->f_bsize;
34229 + br->br_wbr->wbr_bytes = b;
34230 + if (b >= bavail) {
34232 + mfs->mfs_bindex = bindex;
34233 + mfs->mfs_jiffy = jiffies;
34237 + mfs->mfsrr_bytes = bavail;
34238 + AuDbg("b%d\n", mfs->mfs_bindex);
34242 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34245 + struct dentry *parent;
34246 + struct super_block *sb;
34247 + struct au_wbr_mfs *mfs;
34249 + err = au_wbr_create_exp(dentry);
34253 + sb = dentry->d_sb;
34255 + if (au_ftest_wbr(flags, PARENT))
34256 + parent = dget_parent(dentry);
34257 + mfs = &au_sbi(sb)->si_wbr_mfs;
34258 + mutex_lock(&mfs->mfs_lock);
34259 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34260 + || mfs->mfs_bindex < 0
34261 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34262 + au_mfs(dentry, parent);
34263 + mutex_unlock(&mfs->mfs_lock);
34264 + err = mfs->mfs_bindex;
34268 + err = au_wbr_nonopq(dentry, err);
34271 + AuDbg("b%d\n", err);
34275 +static int au_wbr_create_init_mfs(struct super_block *sb)
34277 + struct au_wbr_mfs *mfs;
34279 + mfs = &au_sbi(sb)->si_wbr_mfs;
34280 + mutex_init(&mfs->mfs_lock);
34281 + mfs->mfs_jiffy = 0;
34282 + mfs->mfs_bindex = -EROFS;
34287 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34289 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34293 +/* ---------------------------------------------------------------------- */
34295 +/* top down regardless parent, and then mfs */
34296 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34297 + unsigned int flags __maybe_unused)
34300 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34301 + unsigned long long watermark;
34302 + struct super_block *sb;
34303 + struct au_wbr_mfs *mfs;
34304 + struct au_branch *br;
34305 + struct dentry *parent;
34307 + sb = dentry->d_sb;
34308 + mfs = &au_sbi(sb)->si_wbr_mfs;
34309 + mutex_lock(&mfs->mfs_lock);
34310 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34311 + || mfs->mfs_bindex < 0)
34312 + au_mfs(dentry, /*parent*/NULL);
34313 + watermark = mfs->mfsrr_watermark;
34314 + bmfs = mfs->mfs_bindex;
34315 + mutex_unlock(&mfs->mfs_lock);
34317 + /* another style of au_wbr_create_exp() */
34318 + bwh = au_dbwh(dentry);
34319 + parent = dget_parent(dentry);
34320 + btail = au_dbtaildir(parent);
34321 + if (bwh >= 0 && bwh < btail)
34324 + err = au_wbr_nonopq(dentry, btail);
34325 + if (unlikely(err < 0))
34329 + for (bindex = 0; bindex <= btail; bindex++) {
34330 + br = au_sbr(sb, bindex);
34331 + if (au_br_rdonly(br))
34333 + if (br->br_wbr->wbr_bytes > watermark) {
34344 + AuDbg("b%d\n", err);
34348 +/* ---------------------------------------------------------------------- */
34350 +/* most free space and then round robin */
34351 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34354 + struct au_wbr_mfs *mfs;
34356 + err = au_wbr_create_mfs(dentry, flags);
34358 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34359 + mutex_lock(&mfs->mfs_lock);
34360 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34361 + err = au_wbr_create_rr(dentry, flags);
34362 + mutex_unlock(&mfs->mfs_lock);
34365 + AuDbg("b%d\n", err);
34369 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34373 + au_wbr_create_init_mfs(sb); /* ignore */
34374 + err = au_wbr_create_init_rr(sb);
34379 +/* ---------------------------------------------------------------------- */
34381 +/* top down parent and most free space */
34382 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34385 + unsigned long long b;
34386 + aufs_bindex_t bindex, btop, bbot;
34387 + struct super_block *sb;
34388 + struct dentry *parent, *h_parent;
34389 + struct au_branch *br;
34391 + err = au_wbr_create_tdp(dentry, flags);
34392 + if (unlikely(err < 0))
34394 + parent = dget_parent(dentry);
34395 + btop = au_dbtop(parent);
34396 + bbot = au_dbtaildir(parent);
34397 + if (btop == bbot)
34398 + goto out_parent; /* success */
34400 + e2 = au_wbr_create_mfs(dentry, flags);
34402 + goto out_parent; /* success */
34404 + /* when the available size is equal, select upper one */
34405 + sb = dentry->d_sb;
34406 + br = au_sbr(sb, err);
34407 + b = br->br_wbr->wbr_bytes;
34408 + AuDbg("b%d, %llu\n", err, b);
34410 + for (bindex = btop; bindex <= bbot; bindex++) {
34411 + h_parent = au_h_dptr(parent, bindex);
34412 + if (!h_parent || d_is_negative(h_parent))
34415 + br = au_sbr(sb, bindex);
34416 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34417 + b = br->br_wbr->wbr_bytes;
34419 + AuDbg("b%d, %llu\n", err, b);
34424 + err = au_wbr_nonopq(dentry, err);
34429 + AuDbg("b%d\n", err);
34433 +/* ---------------------------------------------------------------------- */
34436 + * - top down parent
34437 + * - most free space with parent
34438 + * - most free space round-robin regardless parent
34440 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34443 + unsigned long long watermark;
34444 + struct super_block *sb;
34445 + struct au_branch *br;
34446 + struct au_wbr_mfs *mfs;
34448 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34449 + if (unlikely(err < 0))
34452 + sb = dentry->d_sb;
34453 + br = au_sbr(sb, err);
34454 + mfs = &au_sbi(sb)->si_wbr_mfs;
34455 + mutex_lock(&mfs->mfs_lock);
34456 + watermark = mfs->mfsrr_watermark;
34457 + mutex_unlock(&mfs->mfs_lock);
34458 + if (br->br_wbr->wbr_bytes < watermark)
34459 + /* regardless the parent dir */
34460 + err = au_wbr_create_mfsrr(dentry, flags);
34463 + AuDbg("b%d\n", err);
34467 +/* ---------------------------------------------------------------------- */
34469 +/* policies for copyup */
34471 +/* top down parent */
34472 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34474 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34477 +/* bottom up parent */
34478 +static int au_wbr_copyup_bup(struct dentry *dentry)
34481 + aufs_bindex_t bindex, btop;
34482 + struct dentry *parent, *h_parent;
34483 + struct super_block *sb;
34486 + sb = dentry->d_sb;
34487 + parent = dget_parent(dentry);
34488 + btop = au_dbtop(parent);
34489 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34490 + h_parent = au_h_dptr(parent, bindex);
34491 + if (!h_parent || d_is_negative(h_parent))
34494 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34501 + /* bottom up here */
34502 + if (unlikely(err < 0))
34503 + err = au_wbr_bu(sb, btop - 1);
34505 + AuDbg("b%d\n", err);
34510 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34514 + err = au_wbr_bu(dentry->d_sb, btop);
34515 + AuDbg("b%d\n", err);
34517 + err = au_wbr_nonopq(dentry, err);
34519 + AuDbg("b%d\n", err);
34523 +static int au_wbr_copyup_bu(struct dentry *dentry)
34526 + aufs_bindex_t btop;
34528 + btop = au_dbtop(dentry);
34529 + err = au_wbr_do_copyup_bu(dentry, btop);
34533 +/* ---------------------------------------------------------------------- */
34535 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34536 + [AuWbrCopyup_TDP] = {
34537 + .copyup = au_wbr_copyup_tdp
34539 + [AuWbrCopyup_BUP] = {
34540 + .copyup = au_wbr_copyup_bup
34542 + [AuWbrCopyup_BU] = {
34543 + .copyup = au_wbr_copyup_bu
34547 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34548 + [AuWbrCreate_TDP] = {
34549 + .create = au_wbr_create_tdp
34551 + [AuWbrCreate_RR] = {
34552 + .create = au_wbr_create_rr,
34553 + .init = au_wbr_create_init_rr
34555 + [AuWbrCreate_MFS] = {
34556 + .create = au_wbr_create_mfs,
34557 + .init = au_wbr_create_init_mfs,
34558 + .fin = au_wbr_create_fin_mfs
34560 + [AuWbrCreate_MFSV] = {
34561 + .create = au_wbr_create_mfs,
34562 + .init = au_wbr_create_init_mfs,
34563 + .fin = au_wbr_create_fin_mfs
34565 + [AuWbrCreate_MFSRR] = {
34566 + .create = au_wbr_create_mfsrr,
34567 + .init = au_wbr_create_init_mfsrr,
34568 + .fin = au_wbr_create_fin_mfs
34570 + [AuWbrCreate_MFSRRV] = {
34571 + .create = au_wbr_create_mfsrr,
34572 + .init = au_wbr_create_init_mfsrr,
34573 + .fin = au_wbr_create_fin_mfs
34575 + [AuWbrCreate_TDMFS] = {
34576 + .create = au_wbr_create_tdmfs,
34577 + .init = au_wbr_create_init_mfs,
34578 + .fin = au_wbr_create_fin_mfs
34580 + [AuWbrCreate_TDMFSV] = {
34581 + .create = au_wbr_create_tdmfs,
34582 + .init = au_wbr_create_init_mfs,
34583 + .fin = au_wbr_create_fin_mfs
34585 + [AuWbrCreate_PMFS] = {
34586 + .create = au_wbr_create_pmfs,
34587 + .init = au_wbr_create_init_mfs,
34588 + .fin = au_wbr_create_fin_mfs
34590 + [AuWbrCreate_PMFSV] = {
34591 + .create = au_wbr_create_pmfs,
34592 + .init = au_wbr_create_init_mfs,
34593 + .fin = au_wbr_create_fin_mfs
34595 + [AuWbrCreate_PMFSRR] = {
34596 + .create = au_wbr_create_pmfsrr,
34597 + .init = au_wbr_create_init_mfsrr,
34598 + .fin = au_wbr_create_fin_mfs
34600 + [AuWbrCreate_PMFSRRV] = {
34601 + .create = au_wbr_create_pmfsrr,
34602 + .init = au_wbr_create_init_mfsrr,
34603 + .fin = au_wbr_create_fin_mfs
34606 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34607 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34608 +++ linux/fs/aufs/whout.c 2018-07-19 09:46:13.063314675 +0200
34610 +/* SPDX-License-Identifier: GPL-2.0 */
34612 + * Copyright (C) 2005-2018 Junjiro R. Okajima
34614 + * This program, aufs is free software; you can redistribute it and/or modify
34615 + * it under the terms of the GNU General Public License as published by
34616 + * the Free Software Foundation; either version 2 of the License, or
34617 + * (at your option) any later version.
34619 + * This program is distributed in the hope that it will be useful,
34620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34622 + * GNU General Public License for more details.
34624 + * You should have received a copy of the GNU General Public License
34625 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34629 + * whiteout for logical deletion and opaque directory
34634 +#define WH_MASK S_IRUGO
34637 + * If a directory contains this file, then it is opaque. We start with the
34638 + * .wh. flag so that it is blocked by lookup.
34640 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34641 + sizeof(AUFS_WH_DIROPQ) - 1);
34644 + * generate whiteout name, which is NOT terminated by NULL.
34645 + * @name: original d_name.name
34646 + * @len: original d_name.len
34647 + * @wh: whiteout qstr
34648 + * returns zero when succeeds, otherwise error.
34649 + * succeeded value as wh->name should be freed by kfree().
34651 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34655 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34656 + return -ENAMETOOLONG;
34658 + wh->len = name->len + AUFS_WH_PFX_LEN;
34659 + p = kmalloc(wh->len, GFP_NOFS);
34662 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34663 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34670 +/* ---------------------------------------------------------------------- */
34673 + * test if the @wh_name exists under @h_parent.
34674 + * @try_sio specifies the necessary of super-io.
34676 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34679 + struct dentry *wh_dentry;
34682 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34684 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34685 + err = PTR_ERR(wh_dentry);
34686 + if (IS_ERR(wh_dentry)) {
34687 + if (err == -ENAMETOOLONG)
34693 + if (d_is_negative(wh_dentry))
34694 + goto out_wh; /* success */
34697 + if (d_is_reg(wh_dentry))
34698 + goto out_wh; /* success */
34701 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34702 + wh_dentry, d_inode(wh_dentry)->i_mode);
34711 + * test if the @h_dentry sets opaque or not.
34713 +int au_diropq_test(struct dentry *h_dentry)
34716 + struct inode *h_dir;
34718 + h_dir = d_inode(h_dentry);
34719 + err = au_wh_test(h_dentry, &diropq_name,
34720 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34725 + * returns a negative dentry whose name is unique and temporary.
34727 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34728 + struct qstr *prefix)
34730 + struct dentry *dentry;
34732 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34734 + /* strict atomic_t is unnecessary here */
34735 + static unsigned short cnt;
34738 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34741 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34742 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34743 + dentry = ERR_PTR(-ENAMETOOLONG);
34744 + if (unlikely(qs.len > NAME_MAX))
34746 + dentry = ERR_PTR(-ENOMEM);
34747 + name = kmalloc(qs.len + 1, GFP_NOFS);
34748 + if (unlikely(!name))
34752 + /* doubly whiteout-ed */
34753 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34754 + p = name + AUFS_WH_PFX_LEN * 2;
34755 + memcpy(p, prefix->name, prefix->len);
34756 + p += prefix->len;
34758 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34761 + for (i = 0; i < 3; i++) {
34762 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34763 + dentry = au_sio_lkup_one(&qs, h_parent);
34764 + if (IS_ERR(dentry) || d_is_negative(dentry))
34768 + /* pr_warn("could not get random name\n"); */
34769 + dentry = ERR_PTR(-EEXIST);
34770 + AuDbg("%.*s\n", AuLNPair(&qs));
34774 + if (name != defname)
34777 + AuTraceErrPtr(dentry);
34782 + * rename the @h_dentry on @br to the whiteouted temporary name.
34784 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34787 + struct path h_path = {
34788 + .mnt = au_br_mnt(br)
34790 + struct inode *h_dir, *delegated;
34791 + struct dentry *h_parent;
34793 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34794 + h_dir = d_inode(h_parent);
34795 + IMustLock(h_dir);
34797 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34798 + err = PTR_ERR(h_path.dentry);
34799 + if (IS_ERR(h_path.dentry))
34802 + /* under the same dir, no need to lock_rename() */
34803 + delegated = NULL;
34804 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34807 + if (unlikely(err == -EWOULDBLOCK)) {
34808 + pr_warn("cannot retry for NFSv4 delegation"
34809 + " for an internal rename\n");
34812 + dput(h_path.dentry);
34819 +/* ---------------------------------------------------------------------- */
34821 + * functions for removing a whiteout
34824 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34827 + struct inode *delegated;
34830 + * forces superio when the dir has a sticky bit.
34831 + * this may be a violation of unix fs semantics.
34833 + force = (h_dir->i_mode & S_ISVTX)
34834 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34835 + delegated = NULL;
34836 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34837 + if (unlikely(err == -EWOULDBLOCK)) {
34838 + pr_warn("cannot retry for NFSv4 delegation"
34839 + " for an internal unlink\n");
34845 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34846 + struct dentry *dentry)
34850 + err = do_unlink_wh(h_dir, h_path);
34851 + if (!err && dentry)
34852 + au_set_dbwh(dentry, -1);
34857 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34858 + struct au_branch *br)
34861 + struct path h_path = {
34862 + .mnt = au_br_mnt(br)
34866 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34867 + if (IS_ERR(h_path.dentry))
34868 + err = PTR_ERR(h_path.dentry);
34870 + if (d_is_reg(h_path.dentry))
34871 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34872 + dput(h_path.dentry);
34878 +/* ---------------------------------------------------------------------- */
34880 + * initialize/clean whiteout for a branch
34883 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34887 + struct inode *delegated;
34889 + if (d_is_negative(whpath->dentry))
34893 + err = vfsub_rmdir(h_dir, whpath);
34895 + delegated = NULL;
34896 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34897 + if (unlikely(err == -EWOULDBLOCK)) {
34898 + pr_warn("cannot retry for NFSv4 delegation"
34899 + " for an internal unlink\n");
34903 + if (unlikely(err))
34904 + pr_warn("failed removing %pd (%d), ignored.\n",
34905 + whpath->dentry, err);
34908 +static int test_linkable(struct dentry *h_root)
34910 + struct inode *h_dir = d_inode(h_root);
34912 + if (h_dir->i_op->link)
34915 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34916 + h_root, au_sbtype(h_root->d_sb));
34920 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34921 +static int au_whdir(struct inode *h_dir, struct path *path)
34926 + if (d_is_negative(path->dentry)) {
34927 + int mode = S_IRWXU;
34929 + if (au_test_nfs(path->dentry->d_sb))
34931 + err = vfsub_mkdir(h_dir, path, mode);
34932 + } else if (d_is_dir(path->dentry))
34935 + pr_err("unknown %pd exists\n", path->dentry);
34940 +struct au_wh_base {
34941 + const struct qstr *name;
34942 + struct dentry *dentry;
34945 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34946 + struct path *h_path)
34948 + h_path->dentry = base[AuBrWh_BASE].dentry;
34949 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34950 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34951 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34952 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34953 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34957 + * returns tri-state,
34958 + * minus: error, caller should print the message
34960 + * plus: error, caller should NOT print the message
34962 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34963 + int do_plink, struct au_wh_base base[],
34964 + struct path *h_path)
34967 + struct inode *h_dir;
34969 + h_dir = d_inode(h_root);
34970 + h_path->dentry = base[AuBrWh_BASE].dentry;
34971 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34972 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34974 + err = test_linkable(h_root);
34975 + if (unlikely(err)) {
34980 + err = au_whdir(h_dir, h_path);
34981 + if (unlikely(err))
34983 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
34985 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34986 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34987 + err = au_whdir(h_dir, h_path);
34988 + if (unlikely(err))
34990 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
34997 + * for the moment, aufs supports the branch filesystem which does not support
34998 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
34999 + * copyup failed. finally, such filesystem will not be used as the writable
35002 + * returns tri-state, see above.
35004 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35005 + int do_plink, struct au_wh_base base[],
35006 + struct path *h_path)
35009 + struct inode *h_dir;
35011 + WbrWhMustWriteLock(wbr);
35013 + err = test_linkable(h_root);
35014 + if (unlikely(err)) {
35020 + * todo: should this create be done in /sbin/mount.aufs helper?
35023 + h_dir = d_inode(h_root);
35024 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35025 + h_path->dentry = base[AuBrWh_BASE].dentry;
35026 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35027 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35030 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35031 + if (unlikely(err))
35034 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35036 + err = au_whdir(h_dir, h_path);
35037 + if (unlikely(err))
35039 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35041 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35042 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35044 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35045 + err = au_whdir(h_dir, h_path);
35046 + if (unlikely(err))
35048 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35055 + * initialize the whiteout base file/dir for @br.
35057 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35060 + const unsigned char do_plink
35061 + = !!au_opt_test(au_mntflags(sb), PLINK);
35062 + struct inode *h_dir;
35063 + struct path path = br->br_path;
35064 + struct dentry *h_root = path.dentry;
35065 + struct au_wbr *wbr = br->br_wbr;
35066 + static const struct qstr base_name[] = {
35067 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35068 + sizeof(AUFS_BASE_NAME) - 1),
35069 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35070 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35071 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35072 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35074 + struct au_wh_base base[] = {
35075 + [AuBrWh_BASE] = {
35076 + .name = base_name + AuBrWh_BASE,
35079 + [AuBrWh_PLINK] = {
35080 + .name = base_name + AuBrWh_PLINK,
35083 + [AuBrWh_ORPH] = {
35084 + .name = base_name + AuBrWh_ORPH,
35090 + WbrWhMustWriteLock(wbr);
35092 + for (i = 0; i < AuBrWh_Last; i++) {
35093 + /* doubly whiteouted */
35094 + struct dentry *d;
35096 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35097 + err = PTR_ERR(d);
35101 + base[i].dentry = d;
35103 + && wbr->wbr_wh[i]
35104 + && wbr->wbr_wh[i] != base[i].dentry);
35108 + for (i = 0; i < AuBrWh_Last; i++) {
35109 + dput(wbr->wbr_wh[i]);
35110 + wbr->wbr_wh[i] = NULL;
35114 + if (!au_br_writable(br->br_perm)) {
35115 + h_dir = d_inode(h_root);
35116 + au_wh_init_ro(h_dir, base, &path);
35117 + } else if (!au_br_wh_linkable(br->br_perm)) {
35118 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35124 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35130 + goto out; /* success */
35133 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35134 + err, h_root, au_sbtype(h_root->d_sb));
35136 + for (i = 0; i < AuBrWh_Last; i++)
35137 + dput(base[i].dentry);
35141 +/* ---------------------------------------------------------------------- */
35143 + * whiteouts are all hard-linked usually.
35144 + * when its link count reaches a ceiling, we create a new whiteout base
35145 + * asynchronously.
35148 +struct reinit_br_wh {
35149 + struct super_block *sb;
35150 + struct au_branch *br;
35153 +static void reinit_br_wh(void *arg)
35156 + aufs_bindex_t bindex;
35157 + struct path h_path;
35158 + struct reinit_br_wh *a = arg;
35159 + struct au_wbr *wbr;
35160 + struct inode *dir, *delegated;
35161 + struct dentry *h_root;
35162 + struct au_hinode *hdir;
35165 + wbr = a->br->br_wbr;
35166 + /* big aufs lock */
35167 + si_noflush_write_lock(a->sb);
35168 + if (!au_br_writable(a->br->br_perm))
35170 + bindex = au_br_index(a->sb, a->br->br_id);
35171 + if (unlikely(bindex < 0))
35174 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35175 + dir = d_inode(a->sb->s_root);
35176 + hdir = au_hi(dir, bindex);
35177 + h_root = au_h_dptr(a->sb->s_root, bindex);
35178 + AuDebugOn(h_root != au_br_dentry(a->br));
35180 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35181 + wbr_wh_write_lock(wbr);
35182 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35185 + h_path.dentry = wbr->wbr_whbase;
35186 + h_path.mnt = au_br_mnt(a->br);
35187 + delegated = NULL;
35188 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35190 + if (unlikely(err == -EWOULDBLOCK)) {
35191 + pr_warn("cannot retry for NFSv4 delegation"
35192 + " for an internal unlink\n");
35196 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35199 + dput(wbr->wbr_whbase);
35200 + wbr->wbr_whbase = NULL;
35202 + err = au_wh_init(a->br, a->sb);
35203 + wbr_wh_write_unlock(wbr);
35204 + au_hn_inode_unlock(hdir);
35205 + di_read_unlock(a->sb->s_root, AuLock_IR);
35207 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35211 + atomic_dec(&wbr->wbr_wh_running);
35212 + au_br_put(a->br);
35213 + si_write_unlock(a->sb);
35214 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35216 + if (unlikely(err))
35217 + AuIOErr("err %d\n", err);
35220 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35222 + int do_dec, wkq_err;
35223 + struct reinit_br_wh *arg;
35226 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35229 + /* ignore ENOMEM */
35230 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35233 + * dec(wh_running), kfree(arg) and dec(br_count)
35234 + * in reinit function
35239 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35240 + if (unlikely(wkq_err)) {
35241 + atomic_dec(&br->br_wbr->wbr_wh_running);
35250 + atomic_dec(&br->br_wbr->wbr_wh_running);
35253 +/* ---------------------------------------------------------------------- */
35256 + * create the whiteout @wh.
35258 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35259 + struct dentry *wh)
35262 + struct path h_path = {
35265 + struct au_branch *br;
35266 + struct au_wbr *wbr;
35267 + struct dentry *h_parent;
35268 + struct inode *h_dir, *delegated;
35270 + h_parent = wh->d_parent; /* dir inode is locked */
35271 + h_dir = d_inode(h_parent);
35272 + IMustLock(h_dir);
35274 + br = au_sbr(sb, bindex);
35275 + h_path.mnt = au_br_mnt(br);
35276 + wbr = br->br_wbr;
35277 + wbr_wh_read_lock(wbr);
35278 + if (wbr->wbr_whbase) {
35279 + delegated = NULL;
35280 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35281 + if (unlikely(err == -EWOULDBLOCK)) {
35282 + pr_warn("cannot retry for NFSv4 delegation"
35283 + " for an internal link\n");
35286 + if (!err || err != -EMLINK)
35289 + /* link count full. re-initialize br_whbase. */
35290 + kick_reinit_br_wh(sb, br);
35293 + /* return this error in this context */
35294 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35296 + au_fhsm_wrote(sb, bindex, /*force*/0);
35299 + wbr_wh_read_unlock(wbr);
35303 +/* ---------------------------------------------------------------------- */
35306 + * create or remove the diropq.
35308 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35309 + unsigned int flags)
35311 + struct dentry *opq_dentry, *h_dentry;
35312 + struct super_block *sb;
35313 + struct au_branch *br;
35316 + sb = dentry->d_sb;
35317 + br = au_sbr(sb, bindex);
35318 + h_dentry = au_h_dptr(dentry, bindex);
35319 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35320 + if (IS_ERR(opq_dentry))
35323 + if (au_ftest_diropq(flags, CREATE)) {
35324 + err = link_or_create_wh(sb, bindex, opq_dentry);
35326 + au_set_dbdiropq(dentry, bindex);
35327 + goto out; /* success */
35330 + struct path tmp = {
35331 + .dentry = opq_dentry,
35332 + .mnt = au_br_mnt(br)
35334 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35336 + au_set_dbdiropq(dentry, -1);
35338 + dput(opq_dentry);
35339 + opq_dentry = ERR_PTR(err);
35342 + return opq_dentry;
35345 +struct do_diropq_args {
35346 + struct dentry **errp;
35347 + struct dentry *dentry;
35348 + aufs_bindex_t bindex;
35349 + unsigned int flags;
35352 +static void call_do_diropq(void *args)
35354 + struct do_diropq_args *a = args;
35355 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35358 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35359 + unsigned int flags)
35361 + struct dentry *diropq, *h_dentry;
35363 + h_dentry = au_h_dptr(dentry, bindex);
35364 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35365 + diropq = do_diropq(dentry, bindex, flags);
35368 + struct do_diropq_args args = {
35370 + .dentry = dentry,
35371 + .bindex = bindex,
35375 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35376 + if (unlikely(wkq_err))
35377 + diropq = ERR_PTR(wkq_err);
35383 +/* ---------------------------------------------------------------------- */
35386 + * lookup whiteout dentry.
35387 + * @h_parent: lower parent dentry which must exist and be locked
35388 + * @base_name: name of dentry which will be whiteouted
35389 + * returns dentry for whiteout.
35391 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35392 + struct au_branch *br)
35395 + struct qstr wh_name;
35396 + struct dentry *wh_dentry;
35398 + err = au_wh_name_alloc(&wh_name, base_name);
35399 + wh_dentry = ERR_PTR(err);
35401 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35402 + kfree(wh_name.name);
35404 + return wh_dentry;
35408 + * link/create a whiteout for @dentry on @bindex.
35410 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35411 + struct dentry *h_parent)
35413 + struct dentry *wh_dentry;
35414 + struct super_block *sb;
35417 + sb = dentry->d_sb;
35418 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35419 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35420 + err = link_or_create_wh(sb, bindex, wh_dentry);
35422 + au_set_dbwh(dentry, bindex);
35423 + au_fhsm_wrote(sb, bindex, /*force*/0);
35426 + wh_dentry = ERR_PTR(err);
35430 + return wh_dentry;
35433 +/* ---------------------------------------------------------------------- */
35435 +/* Delete all whiteouts in this directory on branch bindex. */
35436 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35437 + aufs_bindex_t bindex, struct au_branch *br)
35440 + unsigned long ul, n;
35441 + struct qstr wh_name;
35443 + struct hlist_head *head;
35444 + struct au_vdir_wh *pos;
35445 + struct au_vdir_destr *str;
35448 + p = (void *)__get_free_page(GFP_NOFS);
35449 + wh_name.name = p;
35450 + if (unlikely(!wh_name.name))
35454 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35455 + p += AUFS_WH_PFX_LEN;
35456 + n = whlist->nh_num;
35457 + head = whlist->nh_head;
35458 + for (ul = 0; !err && ul < n; ul++, head++) {
35459 + hlist_for_each_entry(pos, head, wh_hash) {
35460 + if (pos->wh_bindex != bindex)
35463 + str = &pos->wh_str;
35464 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35465 + memcpy(p, str->name, str->len);
35466 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35467 + err = unlink_wh_name(h_dentry, &wh_name, br);
35472 + AuIOErr("whiteout name too long %.*s\n",
35473 + str->len, str->name);
35478 + free_page((unsigned long)wh_name.name);
35484 +struct del_wh_children_args {
35486 + struct dentry *h_dentry;
35487 + struct au_nhash *whlist;
35488 + aufs_bindex_t bindex;
35489 + struct au_branch *br;
35492 +static void call_del_wh_children(void *args)
35494 + struct del_wh_children_args *a = args;
35495 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35498 +/* ---------------------------------------------------------------------- */
35500 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35502 + struct au_whtmp_rmdir *whtmp;
35504 + unsigned int rdhash;
35506 + SiMustAnyLock(sb);
35508 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35509 + if (unlikely(!whtmp)) {
35510 + whtmp = ERR_PTR(-ENOMEM);
35514 + /* no estimation for dir size */
35515 + rdhash = au_sbi(sb)->si_rdhash;
35517 + rdhash = AUFS_RDHASH_DEF;
35518 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35519 + if (unlikely(err)) {
35521 + whtmp = ERR_PTR(err);
35528 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35531 + au_br_put(whtmp->br);
35532 + dput(whtmp->wh_dentry);
35533 + iput(whtmp->dir);
35534 + au_nhash_wh_free(&whtmp->whlist);
35539 + * rmdir the whiteouted temporary named dir @h_dentry.
35540 + * @whlist: whiteouted children.
35542 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35543 + struct dentry *wh_dentry, struct au_nhash *whlist)
35546 + unsigned int h_nlink;
35547 + struct path h_tmp;
35548 + struct inode *wh_inode, *h_dir;
35549 + struct au_branch *br;
35551 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35552 + IMustLock(h_dir);
35554 + br = au_sbr(dir->i_sb, bindex);
35555 + wh_inode = d_inode(wh_dentry);
35556 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35559 + * someone else might change some whiteouts while we were sleeping.
35560 + * it means this whlist may have an obsoleted entry.
35562 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35563 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35566 + struct del_wh_children_args args = {
35568 + .h_dentry = wh_dentry,
35569 + .whlist = whlist,
35570 + .bindex = bindex,
35574 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35575 + if (unlikely(wkq_err))
35578 + inode_unlock(wh_inode);
35581 + h_tmp.dentry = wh_dentry;
35582 + h_tmp.mnt = au_br_mnt(br);
35583 + h_nlink = h_dir->i_nlink;
35584 + err = vfsub_rmdir(h_dir, &h_tmp);
35585 + /* some fs doesn't change the parent nlink in some cases */
35586 + h_nlink -= h_dir->i_nlink;
35590 + if (au_ibtop(dir) == bindex) {
35591 + /* todo: dir->i_mutex is necessary */
35592 + au_cpup_attr_timesizes(dir);
35594 + vfsub_drop_nlink(dir);
35596 + return 0; /* success */
35599 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35603 +static void call_rmdir_whtmp(void *args)
35606 + aufs_bindex_t bindex;
35607 + struct au_whtmp_rmdir *a = args;
35608 + struct super_block *sb;
35609 + struct dentry *h_parent;
35610 + struct inode *h_dir;
35611 + struct au_hinode *hdir;
35613 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35614 + /* inode_lock(a->dir); */
35616 + sb = a->dir->i_sb;
35617 + si_read_lock(sb, !AuLock_FLUSH);
35618 + if (!au_br_writable(a->br->br_perm))
35620 + bindex = au_br_index(sb, a->br->br_id);
35621 + if (unlikely(bindex < 0))
35625 + ii_write_lock_parent(a->dir);
35626 + h_parent = dget_parent(a->wh_dentry);
35627 + h_dir = d_inode(h_parent);
35628 + hdir = au_hi(a->dir, bindex);
35629 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35630 + if (unlikely(err))
35632 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35633 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35636 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35637 + au_hn_inode_unlock(hdir);
35638 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35642 + ii_write_unlock(a->dir);
35644 + /* inode_unlock(a->dir); */
35645 + au_whtmp_rmdir_free(a);
35646 + si_read_unlock(sb);
35647 + au_nwt_done(&au_sbi(sb)->si_nowait);
35648 + if (unlikely(err))
35649 + AuIOErr("err %d\n", err);
35652 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35653 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35656 + struct super_block *sb;
35660 + /* all post-process will be done in do_rmdir_whtmp(). */
35662 + args->dir = au_igrab(dir);
35663 + args->br = au_sbr(sb, bindex);
35664 + au_br_get(args->br);
35665 + args->wh_dentry = dget(wh_dentry);
35666 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35667 + if (unlikely(wkq_err)) {
35668 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35669 + au_whtmp_rmdir_free(args);
35672 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35673 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35674 +++ linux/fs/aufs/whout.h 2018-07-19 09:46:13.063314675 +0200
35676 +/* SPDX-License-Identifier: GPL-2.0 */
35678 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35680 + * This program, aufs is free software; you can redistribute it and/or modify
35681 + * it under the terms of the GNU General Public License as published by
35682 + * the Free Software Foundation; either version 2 of the License, or
35683 + * (at your option) any later version.
35685 + * This program is distributed in the hope that it will be useful,
35686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35688 + * GNU General Public License for more details.
35690 + * You should have received a copy of the GNU General Public License
35691 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35695 + * whiteout for logical deletion and opaque directory
35698 +#ifndef __AUFS_WHOUT_H__
35699 +#define __AUFS_WHOUT_H__
35706 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35707 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35708 +int au_diropq_test(struct dentry *h_dentry);
35710 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35711 + struct qstr *prefix);
35712 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35713 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35714 + struct dentry *dentry);
35715 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35717 +/* diropq flags */
35718 +#define AuDiropq_CREATE 1
35719 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35720 +#define au_fset_diropq(flags, name) \
35721 + do { (flags) |= AuDiropq_##name; } while (0)
35722 +#define au_fclr_diropq(flags, name) \
35723 + do { (flags) &= ~AuDiropq_##name; } while (0)
35725 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35726 + unsigned int flags);
35727 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35728 + struct au_branch *br);
35729 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35730 + struct dentry *h_parent);
35732 +/* real rmdir for the whiteout-ed dir */
35733 +struct au_whtmp_rmdir {
35734 + struct inode *dir;
35735 + struct au_branch *br;
35736 + struct dentry *wh_dentry;
35737 + struct au_nhash whlist;
35740 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35741 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35742 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35743 + struct dentry *wh_dentry, struct au_nhash *whlist);
35744 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35745 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35747 +/* ---------------------------------------------------------------------- */
35749 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35750 + aufs_bindex_t bindex)
35752 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35755 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35757 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35760 +#endif /* __KERNEL__ */
35761 +#endif /* __AUFS_WHOUT_H__ */
35762 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35763 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35764 +++ linux/fs/aufs/wkq.c 2018-07-19 09:46:13.063314675 +0200
35766 +/* SPDX-License-Identifier: GPL-2.0 */
35768 + * Copyright (C) 2005-2018 Junjiro R. Okajima
35770 + * This program, aufs is free software; you can redistribute it and/or modify
35771 + * it under the terms of the GNU General Public License as published by
35772 + * the Free Software Foundation; either version 2 of the License, or
35773 + * (at your option) any later version.
35775 + * This program is distributed in the hope that it will be useful,
35776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35778 + * GNU General Public License for more details.
35780 + * You should have received a copy of the GNU General Public License
35781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35785 + * workqueue for asynchronous/super-io operations
35786 + * todo: try new dredential scheme
35789 +#include <linux/module.h>
35792 +/* internal workqueue named AUFS_WKQ_NAME */
35794 +static struct workqueue_struct *au_wkq;
35796 +struct au_wkinfo {
35797 + struct work_struct wk;
35798 + struct kobject *kobj;
35800 + unsigned int flags; /* see wkq.h */
35802 + au_wkq_func_t func;
35805 +#ifdef CONFIG_LOCKDEP
35807 + struct held_lock **hlock;
35810 + struct completion *comp;
35813 +/* ---------------------------------------------------------------------- */
35815 + * Aufs passes some operations to the workqueue such as the internal copyup.
35816 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35817 + * job run by workqueue depends upon the locks acquired in the other task.
35818 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35819 + * information too. And the job in the workqueue restores the info in order to
35820 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35821 + * correctly and expectedly.
35824 +#ifndef CONFIG_LOCKDEP
35825 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35826 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35827 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35828 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35829 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35831 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35833 + wkinfo->hlock = NULL;
35834 + wkinfo->dont_check = 0;
35841 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35843 + static DEFINE_SPINLOCK(spin);
35846 + struct lock_class_key *key;
35848 + { .name = "&sbinfo->si_rwsem" },
35849 + { .name = "&finfo->fi_rwsem" },
35850 + { .name = "&dinfo->di_rwsem" },
35851 + { .name = "&iinfo->ii_rwsem" }
35856 + /* lockless read from 'set.' see below */
35857 + if (set == ARRAY_SIZE(a)) {
35858 + for (i = 0; i < ARRAY_SIZE(a); i++)
35859 + if (a[i].key == key)
35864 + spin_lock(&spin);
35866 + for (i = 0; i < ARRAY_SIZE(a); i++)
35867 + if (a[i].key == key) {
35868 + spin_unlock(&spin);
35871 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35873 + if (unlikely(a[i].key == key)) { /* rare but possible */
35874 + spin_unlock(&spin);
35879 + if (strstr(a[i].name, name)) {
35881 + * the order of these three lines is important for the
35882 + * lockless read above.
35885 + spin_unlock(&spin);
35887 + /* AuDbg("%d, %s\n", set, name); */
35891 + spin_unlock(&spin);
35900 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35903 + struct task_struct *curr;
35904 + struct held_lock **hl, *held_locks, *p;
35908 + wkinfo->dont_check = lockdep_recursing(curr);
35909 + if (wkinfo->dont_check)
35911 + n = curr->lockdep_depth;
35916 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35917 + if (unlikely(!wkinfo->hlock))
35922 + if (0 && au_debug_test()) /* left for debugging */
35923 + lockdep_print_held_locks(curr);
35925 + held_locks = curr->held_locks;
35926 + hl = wkinfo->hlock;
35928 + p = held_locks++;
35929 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35938 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35940 + kfree(wkinfo->hlock);
35943 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
35945 + struct held_lock *p, **hl = wkinfo->hlock;
35948 + if (wkinfo->dont_check)
35952 + while ((p = *hl++)) { /* assignment */
35953 + subclass = lockdep_hlock_class(p)->subclass;
35954 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
35956 + rwsem_acquire_read(p->instance, subclass, 0,
35957 + /*p->acquire_ip*/_RET_IP_);
35959 + rwsem_acquire(p->instance, subclass, 0,
35960 + /*p->acquire_ip*/_RET_IP_);
35964 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
35966 + struct held_lock *p, **hl = wkinfo->hlock;
35968 + if (wkinfo->dont_check)
35972 + while ((p = *hl++)) /* assignment */
35973 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
35977 +static void wkq_func(struct work_struct *wk)
35979 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
35981 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
35982 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
35984 + au_wkq_lockdep_pre(wkinfo);
35985 + wkinfo->func(wkinfo->args);
35986 + au_wkq_lockdep_post(wkinfo);
35987 + if (au_ftest_wkq(wkinfo->flags, WAIT))
35988 + complete(wkinfo->comp);
35990 + kobject_put(wkinfo->kobj);
35991 + module_put(THIS_MODULE); /* todo: ?? */
35997 + * Since struct completion is large, try allocating it dynamically.
35999 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36000 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36002 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36004 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36006 + init_completion(*comp);
36007 + wkinfo->comp = *comp;
36013 +static void au_wkq_comp_free(struct completion *comp)
36021 +#define AuWkqCompDeclare(name) \
36022 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36023 + struct completion *comp = &_ ## name
36025 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36027 + wkinfo->comp = *comp;
36031 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36035 +#endif /* 4KSTACKS */
36037 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36039 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36040 + if (au_wkq_test()) {
36041 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36042 + " due to a dead dir by UDBA?\n");
36043 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36046 + au_dbg_verify_kthread();
36048 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36049 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36050 + queue_work(au_wkq, &wkinfo->wk);
36052 + INIT_WORK(&wkinfo->wk, wkq_func);
36053 + schedule_work(&wkinfo->wk);
36058 + * Be careful. It is easy to make deadlock happen.
36059 + * processA: lock, wkq and wait
36060 + * processB: wkq and wait, lock in wkq
36063 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36066 + AuWkqCompDeclare(comp);
36067 + struct au_wkinfo wkinfo = {
36073 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36074 + if (unlikely(err))
36076 + err = au_wkq_lockdep_alloc(&wkinfo);
36077 + if (unlikely(err))
36080 + au_wkq_run(&wkinfo);
36081 + /* no timeout, no interrupt */
36082 + wait_for_completion(wkinfo.comp);
36084 + au_wkq_lockdep_free(&wkinfo);
36087 + au_wkq_comp_free(comp);
36089 + destroy_work_on_stack(&wkinfo.wk);
36094 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36095 + * problem in a concurrent umounting.
36097 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36098 + unsigned int flags)
36101 + struct au_wkinfo *wkinfo;
36103 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36106 + * wkq_func() must free this wkinfo.
36107 + * it highly depends upon the implementation of workqueue.
36110 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36112 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36113 + wkinfo->flags = flags & ~AuWkq_WAIT;
36114 + wkinfo->func = func;
36115 + wkinfo->args = args;
36116 + wkinfo->comp = NULL;
36117 + au_wkq_lockdep_init(wkinfo);
36118 + kobject_get(wkinfo->kobj);
36119 + __module_get(THIS_MODULE); /* todo: ?? */
36121 + au_wkq_run(wkinfo);
36124 + au_nwt_done(&au_sbi(sb)->si_nowait);
36130 +/* ---------------------------------------------------------------------- */
36132 +void au_nwt_init(struct au_nowait_tasks *nwt)
36134 + atomic_set(&nwt->nw_len, 0);
36135 + /* smp_mb(); */ /* atomic_set */
36136 + init_waitqueue_head(&nwt->nw_wq);
36139 +void au_wkq_fin(void)
36141 + destroy_workqueue(au_wkq);
36144 +int __init au_wkq_init(void)
36149 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36150 + if (IS_ERR(au_wkq))
36151 + err = PTR_ERR(au_wkq);
36152 + else if (!au_wkq)
36157 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36158 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36159 +++ linux/fs/aufs/wkq.h 2018-07-19 09:46:13.063314675 +0200
36161 +/* SPDX-License-Identifier: GPL-2.0 */
36163 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36165 + * This program, aufs is free software; you can redistribute it and/or modify
36166 + * it under the terms of the GNU General Public License as published by
36167 + * the Free Software Foundation; either version 2 of the License, or
36168 + * (at your option) any later version.
36170 + * This program is distributed in the hope that it will be useful,
36171 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36172 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36173 + * GNU General Public License for more details.
36175 + * You should have received a copy of the GNU General Public License
36176 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36180 + * workqueue for asynchronous/super-io operations
36181 + * todo: try new credentials management scheme
36184 +#ifndef __AUFS_WKQ_H__
36185 +#define __AUFS_WKQ_H__
36189 +#include <linux/wait.h>
36191 +struct super_block;
36193 +/* ---------------------------------------------------------------------- */
36196 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36198 +struct au_nowait_tasks {
36200 + wait_queue_head_t nw_wq;
36203 +/* ---------------------------------------------------------------------- */
36205 +typedef void (*au_wkq_func_t)(void *args);
36208 +#define AuWkq_WAIT 1
36209 +#define AuWkq_NEST (1 << 1)
36210 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36211 +#define au_fset_wkq(flags, name) \
36212 + do { (flags) |= AuWkq_##name; } while (0)
36213 +#define au_fclr_wkq(flags, name) \
36214 + do { (flags) &= ~AuWkq_##name; } while (0)
36216 +#ifndef CONFIG_AUFS_HNOTIFY
36218 +#define AuWkq_NEST 0
36222 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36223 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36224 + unsigned int flags);
36225 +void au_nwt_init(struct au_nowait_tasks *nwt);
36226 +int __init au_wkq_init(void);
36227 +void au_wkq_fin(void);
36229 +/* ---------------------------------------------------------------------- */
36231 +static inline int au_wkq_test(void)
36233 + return current->flags & PF_WQ_WORKER;
36236 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36238 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36241 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36243 + if (atomic_dec_and_test(&nwt->nw_len))
36244 + wake_up_all(&nwt->nw_wq);
36247 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36249 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36253 +#endif /* __KERNEL__ */
36254 +#endif /* __AUFS_WKQ_H__ */
36255 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36256 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36257 +++ linux/fs/aufs/xattr.c 2018-07-19 09:46:13.066648108 +0200
36259 +/* SPDX-License-Identifier: GPL-2.0 */
36261 + * Copyright (C) 2014-2018 Junjiro R. Okajima
36263 + * This program, aufs is free software; you can redistribute it and/or modify
36264 + * it under the terms of the GNU General Public License as published by
36265 + * the Free Software Foundation; either version 2 of the License, or
36266 + * (at your option) any later version.
36268 + * This program is distributed in the hope that it will be useful,
36269 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36270 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36271 + * GNU General Public License for more details.
36273 + * You should have received a copy of the GNU General Public License
36274 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36278 + * handling xattr functions
36281 +#include <linux/fs.h>
36282 +#include <linux/posix_acl_xattr.h>
36283 +#include <linux/xattr.h>
36286 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36288 + if (!ignore_flags)
36296 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36301 +#define cmp(brattr, prefix) do { \
36302 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36303 + XATTR_##prefix##_PREFIX_LEN)) { \
36304 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36310 + cmp(SEC, SECURITY);
36311 + cmp(SYS, SYSTEM);
36312 + cmp(TR, TRUSTED);
36316 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36323 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36325 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36326 + char *name, char **buf, unsigned int ignore_flags,
36327 + unsigned int verbose)
36331 + struct inode *h_idst;
36333 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36335 + if (unlikely(err <= 0)) {
36336 + if (err == -ENODATA
36337 + || (err == -EOPNOTSUPP
36338 + && ((ignore_flags & au_xattr_out_of_list)
36339 + || (au_test_nfs_noacl(d_inode(h_src))
36340 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36342 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36345 + if (err && (verbose || au_debug_test()))
36346 + pr_err("%s, err %d\n", name, err);
36350 + /* unlock it temporary */
36351 + h_idst = d_inode(h_dst);
36352 + inode_unlock(h_idst);
36353 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36354 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36355 + if (unlikely(err)) {
36356 + if (verbose || au_debug_test())
36357 + pr_err("%s, err %d\n", name, err);
36358 + err = au_xattr_ignore(err, name, ignore_flags);
36365 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36366 + unsigned int verbose)
36368 + int err, unlocked, acl_access, acl_default;
36370 + struct inode *h_isrc, *h_idst;
36371 + char *value, *p, *o, *e;
36373 + /* try stopping to update the source inode while we are referencing */
36374 + /* there should not be the parent-child relationship between them */
36375 + h_isrc = d_inode(h_src);
36376 + h_idst = d_inode(h_dst);
36377 + inode_unlock(h_idst);
36378 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36379 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36382 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36383 + ssz = vfs_listxattr(h_src, NULL, 0);
36385 + if (unlikely(err < 0)) {
36387 + if (err == -ENODATA
36388 + || err == -EOPNOTSUPP)
36389 + err = 0; /* ignore */
36398 + p = kmalloc(ssz, GFP_NOFS);
36400 + if (unlikely(!p))
36402 + err = vfs_listxattr(h_src, p, ssz);
36404 + inode_unlock_shared(h_isrc);
36406 + AuDbg("err %d, ssz %zd\n", err, ssz);
36407 + if (unlikely(err < 0))
36415 + while (!err && p < e) {
36416 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36417 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36418 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36419 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36421 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36423 + p += strlen(p) + 1;
36426 + ignore_flags |= au_xattr_out_of_list;
36427 + if (!err && !acl_access) {
36428 + err = au_do_cpup_xattr(h_dst, h_src,
36429 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36430 + ignore_flags, verbose);
36433 + if (!err && !acl_default) {
36434 + err = au_do_cpup_xattr(h_dst, h_src,
36435 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36436 + ignore_flags, verbose);
36446 + inode_unlock_shared(h_isrc);
36451 +/* ---------------------------------------------------------------------- */
36453 +static int au_smack_reentering(struct super_block *sb)
36455 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36457 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36458 + * i_op->getxattr(). ouch.
36460 + return si_pid_test(sb);
36471 +struct au_lgxattr {
36479 + const char *name;
36486 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36490 + struct path h_path;
36491 + struct super_block *sb;
36493 + sb = dentry->d_sb;
36494 + reenter = au_smack_reentering(sb);
36496 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36497 + if (unlikely(err))
36500 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36501 + if (unlikely(err))
36503 + if (unlikely(!h_path.dentry))
36504 + /* illegally overlapped or something */
36505 + goto out_di; /* pretending success */
36507 + /* always topmost entry only */
36508 + switch (arg->type) {
36509 + case AU_XATTR_LIST:
36510 + err = vfs_listxattr(h_path.dentry,
36511 + arg->u.list.list, arg->u.list.size);
36513 + case AU_XATTR_GET:
36514 + AuDebugOn(d_is_negative(h_path.dentry));
36515 + err = vfs_getxattr(h_path.dentry,
36516 + arg->u.get.name, arg->u.get.value,
36517 + arg->u.get.size);
36523 + di_read_unlock(dentry, AuLock_IR);
36526 + si_read_unlock(sb);
36532 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36534 + struct au_lgxattr arg = {
36535 + .type = AU_XATTR_LIST,
36542 + return au_lgxattr(dentry, &arg);
36545 +static ssize_t au_getxattr(struct dentry *dentry,
36546 + struct inode *inode __maybe_unused,
36547 + const char *name, void *value, size_t size)
36549 + struct au_lgxattr arg = {
36550 + .type = AU_XATTR_GET,
36558 + return au_lgxattr(dentry, &arg);
36561 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36562 + const char *name, const void *value, size_t size,
36565 + struct au_sxattr arg = {
36566 + .type = AU_XATTR_SET,
36575 + return au_sxattr(dentry, inode, &arg);
36578 +/* ---------------------------------------------------------------------- */
36580 +static int au_xattr_get(const struct xattr_handler *handler,
36581 + struct dentry *dentry, struct inode *inode,
36582 + const char *name, void *buffer, size_t size)
36584 + return au_getxattr(dentry, inode, name, buffer, size);
36587 +static int au_xattr_set(const struct xattr_handler *handler,
36588 + struct dentry *dentry, struct inode *inode,
36589 + const char *name, const void *value, size_t size,
36592 + return au_setxattr(dentry, inode, name, value, size, flags);
36595 +static const struct xattr_handler au_xattr_handler = {
36598 + .get = au_xattr_get,
36599 + .set = au_xattr_set
36602 +static const struct xattr_handler *au_xattr_handlers[] = {
36603 +#ifdef CONFIG_FS_POSIX_ACL
36604 + &posix_acl_access_xattr_handler,
36605 + &posix_acl_default_xattr_handler,
36607 + &au_xattr_handler, /* must be last */
36611 +void au_xattr_init(struct super_block *sb)
36613 + sb->s_xattr = au_xattr_handlers;
36615 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36616 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36617 +++ linux/fs/aufs/xino.c 2018-07-19 09:46:13.066648108 +0200
36619 +/* SPDX-License-Identifier: GPL-2.0 */
36621 + * Copyright (C) 2005-2018 Junjiro R. Okajima
36623 + * This program, aufs is free software; you can redistribute it and/or modify
36624 + * it under the terms of the GNU General Public License as published by
36625 + * the Free Software Foundation; either version 2 of the License, or
36626 + * (at your option) any later version.
36628 + * This program is distributed in the hope that it will be useful,
36629 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36630 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36631 + * GNU General Public License for more details.
36633 + * You should have received a copy of the GNU General Public License
36634 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36638 + * external inode number translation table and bitmap
36640 + * things to consider
36642 + * + au_xino object
36643 + * + XINO files (xino, xib, xigen)
36644 + * + dynamic debugfs entries (xiN)
36645 + * + static debugfs entries (xib, xigen)
36646 + * + static sysfs entry (xi_path)
36647 + * - several entry points to handle them.
36648 + * + mount(2) without xino option (default)
36649 + * + mount(2) with xino option
36650 + * + mount(2) with noxino option
36652 + * + remount with add/del branches
36653 + * + remount with xino/noxino options
36656 +#include <linux/seq_file.h>
36657 +#include <linux/statfs.h>
36660 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36661 + aufs_bindex_t bbot,
36662 + struct super_block *h_sb)
36664 + /* todo: try binary-search if the branches are many */
36665 + for (; btop <= bbot; btop++)
36666 + if (h_sb == au_sbr_sb(sb, btop))
36672 + * find another branch who is on the same filesystem of the specified
36673 + * branch{@btgt}. search until @bbot.
36675 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36676 + aufs_bindex_t bbot)
36678 + aufs_bindex_t bindex;
36679 + struct super_block *tgt_sb;
36681 + tgt_sb = au_sbr_sb(sb, btgt);
36682 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36684 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36689 +/* ---------------------------------------------------------------------- */
36692 + * stop unnecessary notify events at creating xino files
36694 +struct au_xino_lock_dir {
36695 + struct au_hinode *hdir;
36696 + struct dentry *parent;
36697 + struct inode *dir;
36700 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36701 + unsigned int lsc)
36703 + struct dentry *parent;
36704 + struct inode *dir;
36706 + parent = dget_parent(dentry);
36707 + dir = d_inode(parent);
36708 + inode_lock_nested(dir, lsc);
36709 +#if 0 /* it should not happen */
36710 + spin_lock(&dentry->d_lock);
36711 + if (unlikely(dentry->d_parent != parent)) {
36712 + spin_unlock(&dentry->d_lock);
36713 + inode_unlock(dir);
36718 + spin_unlock(&dentry->d_lock);
36725 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36726 + struct au_xino_lock_dir *ldir)
36728 + aufs_bindex_t brid, bindex;
36730 + ldir->hdir = NULL;
36732 + brid = au_xino_brid(sb);
36734 + bindex = au_br_index(sb, brid);
36735 + if (bindex >= 0) {
36736 + /* rw branch root */
36737 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36738 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36741 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36743 + ldir->dir = d_inode(ldir->parent);
36747 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36750 + au_hn_inode_unlock(ldir->hdir);
36752 + inode_unlock(ldir->dir);
36753 + dput(ldir->parent);
36757 +/* ---------------------------------------------------------------------- */
36760 + * create and set a new xino file
36762 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent)
36764 + struct file *file;
36765 + struct dentry *h_parent, *d;
36766 + struct inode *h_dir, *inode;
36770 + * at mount-time, and the xino file is the default path,
36771 + * hnotify is disabled so we have no notify events to ignore.
36772 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36774 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36775 + /* | __FMODE_NONOTIFY */,
36776 + S_IRUGO | S_IWUGO);
36777 + if (IS_ERR(file)) {
36779 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36783 + /* keep file count */
36785 + d = file->f_path.dentry;
36786 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36787 + /* mnt_want_write() is unnecessary here */
36788 + h_dir = d_inode(h_parent);
36789 + inode = file_inode(file);
36790 + /* no delegation since it is just created */
36791 + if (inode->i_nlink)
36792 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36794 + inode_unlock(h_dir);
36796 + if (unlikely(err)) {
36798 + pr_err("unlink %s(%d)\n", fpath, err);
36803 + if (unlikely(sb == d->d_sb)) {
36805 + pr_err("%s must be outside\n", fpath);
36808 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36810 + pr_err("xino doesn't support %s(%s)\n",
36811 + fpath, au_sbtype(d->d_sb));
36814 + return file; /* success */
36818 + file = ERR_PTR(err);
36823 + * create a new xinofile at the same place/path as @base.
36825 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36826 + struct file *copy_src)
36828 + struct file *file;
36829 + struct dentry *dentry, *parent;
36830 + struct inode *dir, *delegated;
36831 + struct qstr *name;
36832 + struct path path;
36833 + int err, do_unlock;
36834 + struct au_xino_lock_dir ldir;
36837 + au_xino_lock_dir(sb, base, &ldir);
36838 + dentry = base->dentry;
36839 + parent = dentry->d_parent; /* dir inode is locked */
36840 + dir = d_inode(parent);
36843 + name = &dentry->d_name;
36844 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36845 + if (IS_ERR(path.dentry)) {
36846 + file = (void *)path.dentry;
36847 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36851 + /* no need to mnt_want_write() since we call dentry_open() later */
36852 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
36853 + if (unlikely(err)) {
36854 + file = ERR_PTR(err);
36855 + pr_err("%pd create err %d\n", dentry, err);
36859 + path.mnt = base->mnt;
36860 + file = vfsub_dentry_open(&path,
36861 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36862 + /* | __FMODE_NONOTIFY */);
36863 + if (IS_ERR(file)) {
36864 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36868 + delegated = NULL;
36869 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36870 + au_xino_unlock_dir(&ldir);
36872 + if (unlikely(err == -EWOULDBLOCK)) {
36873 + pr_warn("cannot retry for NFSv4 delegation"
36874 + " for an internal unlink\n");
36877 + if (unlikely(err)) {
36878 + pr_err("%pd unlink err %d\n", dentry, err);
36883 + /* no one can touch copy_src xino */
36884 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36885 + if (unlikely(err)) {
36886 + pr_err("%pd copy err %d\n", dentry, err);
36890 + goto out_dput; /* success */
36894 + file = ERR_PTR(err);
36896 + dput(path.dentry);
36899 + au_xino_unlock_dir(&ldir);
36903 +/* ---------------------------------------------------------------------- */
36906 + * truncate xino files
36908 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
36911 + unsigned long jiffy;
36913 + aufs_bindex_t bbot;
36914 + struct kstatfs *st;
36915 + struct au_branch *br;
36916 + struct file *new_xino, *file;
36917 + struct path *path;
36920 + st = kmalloc(sizeof(*st), GFP_NOFS);
36921 + if (unlikely(!st))
36925 + bbot = au_sbbot(sb);
36926 + if (unlikely(bindex < 0 || bbot < bindex))
36928 + br = au_sbr(sb, bindex);
36929 + file = au_xino_file(br);
36933 + path = &file->f_path;
36934 + err = vfs_statfs(path, st);
36935 + if (unlikely(err))
36936 + AuErr1("statfs err %d, ignored\n", err);
36938 + blocks = file_inode(file)->i_blocks;
36939 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36940 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
36942 + new_xino = au_xino_create2(sb, path, file);
36943 + err = PTR_ERR(new_xino);
36944 + if (IS_ERR(new_xino)) {
36945 + pr_err("err %d, ignored\n", err);
36949 + au_xino_file_set(br, new_xino);
36951 + err = vfs_statfs(&new_xino->f_path, st);
36953 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
36954 + bindex, (u64)file_inode(new_xino)->i_blocks,
36955 + st->f_bfree, st->f_blocks);
36956 + if (file_inode(new_xino)->i_blocks < blocks)
36957 + au_sbi(sb)->si_xino_jiffy = jiffy;
36959 + AuErr1("statfs err %d, ignored\n", err);
36968 +struct xino_do_trunc_args {
36969 + struct super_block *sb;
36970 + struct au_branch *br;
36973 +static void xino_do_trunc(void *_args)
36975 + struct xino_do_trunc_args *args = _args;
36976 + struct super_block *sb;
36977 + struct au_branch *br;
36978 + struct inode *dir;
36980 + aufs_bindex_t bindex;
36984 + dir = d_inode(sb->s_root);
36987 + si_noflush_write_lock(sb);
36988 + ii_read_lock_parent(dir);
36989 + bindex = au_br_index(sb, br->br_id);
36990 + err = au_xino_trunc(sb, bindex);
36991 + ii_read_unlock(dir);
36992 + if (unlikely(err))
36993 + pr_warn("err b%d, (%d)\n", bindex, err);
36994 + atomic_dec(&br->br_xino->xi_truncating);
36996 + si_write_unlock(sb);
36997 + au_nwt_done(&au_sbi(sb)->si_nowait);
37001 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37004 + struct kstatfs st;
37005 + struct au_sbinfo *sbinfo;
37006 + struct file *file;
37008 + /* todo: si_xino_expire and the ratio should be customizable */
37009 + sbinfo = au_sbi(sb);
37010 + if (time_before(jiffies,
37011 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37014 + /* truncation border */
37015 + file = au_xino_file(br);
37016 + AuDebugOn(!file);
37017 + err = vfs_statfs(&file->f_path, &st);
37018 + if (unlikely(err)) {
37019 + AuErr1("statfs err %d, ignored\n", err);
37022 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
37028 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37030 + struct xino_do_trunc_args *args;
37033 + if (!xino_trunc_test(sb, br))
37036 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37039 + /* lock and kfree() will be called in trunc_xino() */
37040 + args = kmalloc(sizeof(*args), GFP_NOFS);
37041 + if (unlikely(!args)) {
37042 + AuErr1("no memory\n");
37049 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37051 + return; /* success */
37053 + pr_err("wkq %d\n", wkq_err);
37058 + atomic_dec(&br->br_xino->xi_truncating);
37061 +/* ---------------------------------------------------------------------- */
37064 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37065 + * at the position of @h_ino.
37067 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37073 + struct au_branch *br;
37074 + struct file *file;
37075 + struct au_sbinfo *sbinfo;
37078 + if (!au_opt_test(au_mntflags(sb), XINO))
37079 + return 0; /* no xino */
37082 + sbinfo = au_sbi(sb);
37084 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
37085 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37088 + pos *= sizeof(*ino);
37090 + br = au_sbr(sb, bindex);
37091 + file = au_xino_file(br);
37092 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
37093 + return 0; /* no ino */
37095 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
37096 + if (sz == sizeof(*ino))
37097 + return 0; /* success */
37100 + if (unlikely(sz >= 0)) {
37102 + AuIOErr("xino read error (%zd)\n", sz);
37108 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37109 + ino_t h_ino, ino_t ino)
37115 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
37116 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
37119 + pos *= sizeof(ino);
37120 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
37121 + if (sz == sizeof(ino))
37122 + return 0; /* success */
37124 + AuIOErr("write failed (%zd)\n", sz);
37129 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37130 + * at the position of @h_ino.
37131 + * even if @ino is zero, it is written to the xinofile and means no entry.
37132 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37133 + * try truncating it.
37135 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37139 + unsigned int mnt_flags;
37140 + struct au_branch *br;
37142 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
37143 + || ((loff_t)-1) > 0);
37144 + SiMustAnyLock(sb);
37146 + mnt_flags = au_mntflags(sb);
37147 + if (!au_opt_test(mnt_flags, XINO))
37150 + br = au_sbr(sb, bindex);
37151 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, au_xino_file(br), h_ino,
37154 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37155 + && au_test_fs_trunc_xino(au_br_sb(br)))
37156 + xino_try_trunc(sb, br);
37157 + return 0; /* success */
37160 + AuIOErr("write failed (%d)\n", err);
37164 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37165 + size_t size, loff_t *pos);
37167 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37168 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37172 + mm_segment_t oldfs;
37178 + const int prevent_endless = 10;
37182 + oldfs = get_fs();
37183 + set_fs(KERNEL_DS);
37185 + err = func(file, buf.u, size, pos);
37186 + if (err == -EINTR
37187 + && !au_wkq_test()
37188 + && fatal_signal_pending(current)) {
37190 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37191 + BUG_ON(err == -EINTR);
37192 + oldfs = get_fs();
37193 + set_fs(KERNEL_DS);
37195 + } while (i++ < prevent_endless
37196 + && (err == -EAGAIN || err == -EINTR));
37199 +#if 0 /* reserved for future use */
37201 + fsnotify_access(file->f_path.dentry);
37207 +struct xino_fread_args {
37209 + vfs_readf_t func;
37210 + struct file *file;
37216 +static void call_xino_fread(void *args)
37218 + struct xino_fread_args *a = args;
37219 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37222 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37223 + size_t size, loff_t *pos)
37227 + struct xino_fread_args args = {
37236 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37237 + if (unlikely(wkq_err))
37243 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37244 + size_t size, loff_t *pos);
37246 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37247 + size_t size, loff_t *pos)
37250 + mm_segment_t oldfs;
37253 + const char __user *u;
37256 + const int prevent_endless = 10;
37260 + oldfs = get_fs();
37261 + set_fs(KERNEL_DS);
37263 + err = func(file, buf.u, size, pos);
37264 + if (err == -EINTR
37265 + && !au_wkq_test()
37266 + && fatal_signal_pending(current)) {
37268 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37269 + BUG_ON(err == -EINTR);
37270 + oldfs = get_fs();
37271 + set_fs(KERNEL_DS);
37273 + } while (i++ < prevent_endless
37274 + && (err == -EAGAIN || err == -EINTR));
37277 +#if 0 /* reserved for future use */
37279 + fsnotify_modify(file->f_path.dentry);
37285 +struct do_xino_fwrite_args {
37287 + vfs_writef_t func;
37288 + struct file *file;
37294 +static void call_do_xino_fwrite(void *args)
37296 + struct do_xino_fwrite_args *a = args;
37297 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37300 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37301 + size_t size, loff_t *pos)
37305 + struct do_xino_fwrite_args args = {
37315 + * it breaks RLIMIT_FSIZE and normal user's limit,
37316 + * users should care about quota and real 'filesystem full.'
37318 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37319 + if (unlikely(wkq_err))
37325 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37326 + size_t size, loff_t *pos)
37330 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37332 + err = do_xino_fwrite(func, file, buf, size, pos);
37336 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37343 +/* ---------------------------------------------------------------------- */
37346 + * inode number bitmap
37348 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37349 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37353 + AuDebugOn(bit < 0 || page_bits <= bit);
37354 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37358 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37360 + AuDebugOn(ino < AUFS_FIRST_INO);
37361 + ino -= AUFS_FIRST_INO;
37362 + *pindex = ino / page_bits;
37363 + *bit = ino % page_bits;
37366 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37371 + struct au_sbinfo *sbinfo;
37372 + struct file *xib;
37373 + unsigned long *p;
37375 + sbinfo = au_sbi(sb);
37376 + MtxMustLock(&sbinfo->si_xib_mtx);
37377 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37378 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37380 + if (pindex == sbinfo->si_xib_last_pindex)
37383 + xib = sbinfo->si_xib;
37384 + p = sbinfo->si_xib_buf;
37385 + pos = sbinfo->si_xib_last_pindex;
37386 + pos *= PAGE_SIZE;
37387 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37388 + if (unlikely(sz != PAGE_SIZE))
37392 + pos *= PAGE_SIZE;
37393 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37394 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37396 + memset(p, 0, PAGE_SIZE);
37397 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37399 + if (sz == PAGE_SIZE) {
37400 + sbinfo->si_xib_last_pindex = pindex;
37401 + return 0; /* success */
37405 + AuIOErr1("write failed (%zd)\n", sz);
37412 +static void au_xib_clear_bit(struct inode *inode)
37415 + unsigned long pindex;
37416 + struct super_block *sb;
37417 + struct au_sbinfo *sbinfo;
37419 + AuDebugOn(inode->i_nlink);
37421 + sb = inode->i_sb;
37422 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37423 + AuDebugOn(page_bits <= bit);
37424 + sbinfo = au_sbi(sb);
37425 + mutex_lock(&sbinfo->si_xib_mtx);
37426 + err = xib_pindex(sb, pindex);
37428 + clear_bit(bit, sbinfo->si_xib_buf);
37429 + sbinfo->si_xib_next_bit = bit;
37431 + mutex_unlock(&sbinfo->si_xib_mtx);
37434 +/* ---------------------------------------------------------------------- */
37437 + * truncate a xino bitmap file
37441 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37445 + unsigned long pindex;
37446 + loff_t pos, pend;
37447 + struct au_sbinfo *sbinfo;
37448 + vfs_readf_t func;
37450 + unsigned long *p;
37453 + sbinfo = au_sbi(sb);
37454 + MtxMustLock(&sbinfo->si_xib_mtx);
37455 + p = sbinfo->si_xib_buf;
37456 + func = sbinfo->si_xread;
37457 + pend = vfsub_f_size_read(file);
37459 + while (pos < pend) {
37460 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37462 + if (unlikely(sz <= 0))
37466 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37467 + if (unlikely(*ino < AUFS_FIRST_INO))
37470 + xib_calc_bit(*ino, &pindex, &bit);
37471 + AuDebugOn(page_bits <= bit);
37472 + err = xib_pindex(sb, pindex);
37484 +static int xib_restore(struct super_block *sb)
37487 + aufs_bindex_t bindex, bbot;
37489 + struct au_branch *br;
37492 + page = (void *)__get_free_page(GFP_NOFS);
37493 + if (unlikely(!page))
37497 + bbot = au_sbbot(sb);
37498 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37499 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37500 + br = au_sbr(sb, bindex);
37501 + err = do_xib_restore(sb, au_xino_file(br), page);
37503 + AuDbg("skip shared b%d\n", bindex);
37504 + free_page((unsigned long)page);
37510 +int au_xib_trunc(struct super_block *sb)
37515 + struct au_sbinfo *sbinfo;
37516 + unsigned long *p;
37517 + struct file *file;
37519 + SiMustWriteLock(sb);
37522 + sbinfo = au_sbi(sb);
37523 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37526 + file = sbinfo->si_xib;
37527 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37530 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37531 + err = PTR_ERR(file);
37532 + if (IS_ERR(file))
37534 + fput(sbinfo->si_xib);
37535 + sbinfo->si_xib = file;
37537 + p = sbinfo->si_xib_buf;
37538 + memset(p, 0, PAGE_SIZE);
37540 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
37541 + if (unlikely(sz != PAGE_SIZE)) {
37543 + AuIOErr("err %d\n", err);
37549 + mutex_lock(&sbinfo->si_xib_mtx);
37550 + /* mnt_want_write() is unnecessary here */
37551 + err = xib_restore(sb);
37552 + mutex_unlock(&sbinfo->si_xib_mtx);
37558 +/* ---------------------------------------------------------------------- */
37560 +struct au_xino *au_xino_alloc(void)
37562 + struct au_xino *xi;
37564 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37565 + if (unlikely(!xi))
37568 + xi->xi_nondir.total = 8; /* initial size */
37569 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37571 + if (unlikely(!xi->xi_nondir.array))
37574 + spin_lock_init(&xi->xi_nondir.spin);
37575 + init_waitqueue_head(&xi->xi_nondir.wqh);
37576 + atomic_set(&xi->xi_truncating, 0);
37577 + kref_init(&xi->xi_kref);
37578 + goto out; /* success */
37587 +static int au_xino_init(struct au_branch *br, struct file *file)
37590 + struct au_xino *xi;
37593 + xi = au_xino_alloc();
37594 + if (unlikely(!xi)) {
37600 + xi->xi_file = file;
37601 + AuDebugOn(br->br_xino);
37602 + br->br_xino = xi;
37608 +static void au_xino_release(struct kref *kref)
37610 + struct au_xino *xi;
37613 + xi = container_of(kref, struct au_xino, xi_kref);
37615 + fput(xi->xi_file);
37616 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37617 + AuDebugOn(xi->xi_nondir.array[i]);
37618 + kfree(xi->xi_nondir.array);
37622 +int au_xino_put(struct au_branch *br)
37625 + struct au_xino *xi;
37628 + xi = br->br_xino;
37630 + br->br_xino = NULL;
37631 + ret = kref_put(&xi->xi_kref, au_xino_release);
37637 +void au_xino_file_set(struct au_branch *br, struct file *file)
37639 + struct au_xino *xi;
37644 + xi = br->br_xino;
37649 + xi->xi_file = file;
37652 +/* ---------------------------------------------------------------------- */
37655 + * xino mount option handlers
37659 +static void xino_clear_xib(struct super_block *sb)
37661 + struct au_sbinfo *sbinfo;
37663 + SiMustWriteLock(sb);
37665 + sbinfo = au_sbi(sb);
37666 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
37667 + if (sbinfo->si_xib)
37668 + fput(sbinfo->si_xib);
37669 + sbinfo->si_xib = NULL;
37670 + if (sbinfo->si_xib_buf)
37671 + free_page((unsigned long)sbinfo->si_xib_buf);
37672 + sbinfo->si_xib_buf = NULL;
37675 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
37679 + struct au_sbinfo *sbinfo;
37680 + struct file *file;
37682 + SiMustWriteLock(sb);
37684 + sbinfo = au_sbi(sb);
37685 + file = au_xino_create2(sb, path, sbinfo->si_xib);
37686 + err = PTR_ERR(file);
37687 + if (IS_ERR(file))
37689 + if (sbinfo->si_xib)
37690 + fput(sbinfo->si_xib);
37691 + sbinfo->si_xib = file;
37692 + sbinfo->si_xread = vfs_readf(file);
37693 + sbinfo->si_xwrite = vfs_writef(file);
37696 + if (!sbinfo->si_xib_buf)
37697 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
37698 + if (unlikely(!sbinfo->si_xib_buf))
37701 + sbinfo->si_xib_last_pindex = 0;
37702 + sbinfo->si_xib_next_bit = 0;
37703 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
37705 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
37706 + PAGE_SIZE, &pos);
37707 + if (unlikely(err != PAGE_SIZE))
37711 + goto out; /* success */
37714 + if (sbinfo->si_xib_buf)
37715 + free_page((unsigned long)sbinfo->si_xib_buf);
37716 + sbinfo->si_xib_buf = NULL;
37720 + fput(sbinfo->si_xib);
37721 + sbinfo->si_xib = NULL;
37727 +/* xino for each branch */
37728 +static void xino_clear_br(struct super_block *sb)
37730 + aufs_bindex_t bindex, bbot;
37731 + struct au_branch *br;
37733 + bbot = au_sbbot(sb);
37734 + for (bindex = 0; bindex <= bbot; bindex++) {
37735 + br = au_sbr(sb, bindex);
37741 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
37742 + aufs_bindex_t bshared)
37744 + struct au_branch *brshared;
37746 + brshared = au_sbr(sb, bshared);
37747 + AuDebugOn(!brshared->br_xino);
37748 + AuDebugOn(!brshared->br_xino->xi_file);
37749 + if (br->br_xino != brshared->br_xino) {
37750 + au_xino_get(brshared);
37752 + br->br_xino = brshared->br_xino;
37756 +struct au_xino_do_set_br {
37757 + vfs_writef_t writef;
37758 + struct au_branch *br;
37760 + aufs_bindex_t bshared;
37763 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
37764 + struct au_xino_do_set_br *args)
37767 + struct file *file;
37769 + if (args->bshared >= 0) {
37770 + /* shared xino */
37771 + au_xino_set_br_shared(sb, args->br, args->bshared);
37772 + file = au_xino_file(args->br);
37773 + goto out_ino; /* success */
37777 + file = au_xino_create2(sb, path, au_xino_file(args->br));
37778 + err = PTR_ERR(file);
37779 + if (IS_ERR(file))
37781 + if (!args->br->br_xino) {
37782 + err = au_xino_init(args->br, file);
37784 + if (unlikely(err))
37787 + au_xino_file_set(args->br, file);
37792 + err = au_xino_do_write(args->writef, file, args->h_ino, AUFS_ROOT_INO);
37798 +static int au_xino_set_br(struct super_block *sb, struct path *path)
37801 + aufs_bindex_t bindex, bbot;
37802 + struct au_xino_do_set_br args;
37803 + struct inode *inode;
37805 + SiMustWriteLock(sb);
37807 + bbot = au_sbbot(sb);
37808 + inode = d_inode(sb->s_root);
37809 + args.writef = au_sbi(sb)->si_xwrite;
37810 + for (bindex = 0; bindex <= bbot; bindex++) {
37811 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
37812 + args.br = au_sbr(sb, bindex);
37813 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
37814 + err = au_xino_do_set_br(sb, path, &args);
37815 + if (unlikely(err))
37823 +void au_xino_clr(struct super_block *sb)
37825 + struct au_sbinfo *sbinfo;
37827 + au_xigen_clr(sb);
37828 + xino_clear_xib(sb);
37829 + xino_clear_br(sb);
37830 + dbgaufs_brs_del(sb, 0);
37831 + au_xino_brid_set(sb, -1);
37832 + sbinfo = au_sbi(sb);
37833 + /* lvalue, do not call au_mntflags() */
37834 + au_opt_clr(sbinfo->si_mntflags, XINO);
37837 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
37840 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
37841 + struct qstr *dname, *cur_name;
37842 + struct file *cur_xino;
37843 + struct au_sbinfo *sbinfo;
37844 + struct path *path, *cur_path;
37846 + SiMustWriteLock(sb);
37849 + sbinfo = au_sbi(sb);
37850 + path = &xiopt->file->f_path;
37851 + dentry = path->dentry;
37852 + parent = dget_parent(dentry);
37855 + cur_xino = sbinfo->si_xib;
37857 + cur_path = &cur_xino->f_path;
37858 + cur_dentry = cur_path->dentry;
37859 + cur_parent = dget_parent(cur_dentry);
37860 + cur_name = &cur_dentry->d_name;
37861 + dname = &dentry->d_name;
37862 + skip = (cur_parent == parent
37863 + && au_qstreq(dname, cur_name));
37864 + dput(cur_parent);
37870 + au_opt_set(sbinfo->si_mntflags, XINO);
37871 + err = au_xino_set_xib(sb, path);
37872 + /* si_x{read,write} are set */
37874 + err = au_xigen_set(sb, path);
37876 + err = au_xino_set_br(sb, path);
37878 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
37879 + goto out; /* success */
37883 + AuIOErr("failed setting xino(%d).\n", err);
37892 + * create a xinofile at the default place/path.
37894 +struct file *au_xino_def(struct super_block *sb)
37896 + struct file *file;
37898 + struct au_branch *br;
37899 + struct super_block *h_sb;
37900 + struct path path;
37901 + aufs_bindex_t bbot, bindex, bwr;
37904 + bbot = au_sbbot(sb);
37906 + for (bindex = 0; bindex <= bbot; bindex++) {
37907 + br = au_sbr(sb, bindex);
37908 + if (au_br_writable(br->br_perm)
37909 + && !au_test_fs_bad_xino(au_br_sb(br))) {
37916 + file = ERR_PTR(-ENOMEM);
37917 + page = (void *)__get_free_page(GFP_NOFS);
37918 + if (unlikely(!page))
37920 + path.mnt = au_br_mnt(br);
37921 + path.dentry = au_h_dptr(sb->s_root, bwr);
37922 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
37923 + file = (void *)p;
37924 + if (!IS_ERR(p)) {
37925 + strcat(p, "/" AUFS_XINO_FNAME);
37926 + AuDbg("%s\n", p);
37927 + file = au_xino_create(sb, p, /*silent*/0);
37928 + if (!IS_ERR(file))
37929 + au_xino_brid_set(sb, br->br_id);
37931 + free_page((unsigned long)page);
37933 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
37934 + if (IS_ERR(file))
37936 + h_sb = file->f_path.dentry->d_sb;
37937 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
37938 + pr_err("xino doesn't support %s(%s)\n",
37939 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
37941 + file = ERR_PTR(-EINVAL);
37943 + if (!IS_ERR(file))
37944 + au_xino_brid_set(sb, -1);
37951 +/* ---------------------------------------------------------------------- */
37954 + * initialize the xinofile for the specified branch @br
37955 + * at the place/path where @base_file indicates.
37956 + * test whether another branch is on the same filesystem or not,
37957 + * if found then share the xinofile with another branch.
37959 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
37960 + struct path *base)
37963 + struct au_xino_do_set_br args = {
37968 + args.writef = au_sbi(sb)->si_xwrite;
37969 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
37971 + err = au_xino_do_set_br(sb, base, &args);
37972 + if (unlikely(err))
37978 +/* ---------------------------------------------------------------------- */
37981 + * get an unused inode number from bitmap
37983 +ino_t au_xino_new_ino(struct super_block *sb)
37986 + unsigned long *p, pindex, ul, pend;
37987 + struct au_sbinfo *sbinfo;
37988 + struct file *file;
37989 + int free_bit, err;
37991 + if (!au_opt_test(au_mntflags(sb), XINO))
37992 + return iunique(sb, AUFS_FIRST_INO);
37994 + sbinfo = au_sbi(sb);
37995 + mutex_lock(&sbinfo->si_xib_mtx);
37996 + p = sbinfo->si_xib_buf;
37997 + free_bit = sbinfo->si_xib_next_bit;
37998 + if (free_bit < page_bits && !test_bit(free_bit, p))
37999 + goto out; /* success */
38000 + free_bit = find_first_zero_bit(p, page_bits);
38001 + if (free_bit < page_bits)
38002 + goto out; /* success */
38004 + pindex = sbinfo->si_xib_last_pindex;
38005 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38006 + err = xib_pindex(sb, ul);
38007 + if (unlikely(err))
38009 + free_bit = find_first_zero_bit(p, page_bits);
38010 + if (free_bit < page_bits)
38011 + goto out; /* success */
38014 + file = sbinfo->si_xib;
38015 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38016 + for (ul = pindex + 1; ul <= pend; ul++) {
38017 + err = xib_pindex(sb, ul);
38018 + if (unlikely(err))
38020 + free_bit = find_first_zero_bit(p, page_bits);
38021 + if (free_bit < page_bits)
38022 + goto out; /* success */
38027 + set_bit(free_bit, p);
38028 + sbinfo->si_xib_next_bit = free_bit + 1;
38029 + pindex = sbinfo->si_xib_last_pindex;
38030 + mutex_unlock(&sbinfo->si_xib_mtx);
38031 + ino = xib_calc_ino(pindex, free_bit);
38032 + AuDbg("i%lu\n", (unsigned long)ino);
38035 + mutex_unlock(&sbinfo->si_xib_mtx);
38040 +/* for s_op->delete_inode() */
38041 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38044 + unsigned int mnt_flags;
38045 + aufs_bindex_t bindex, bbot, bi;
38046 + unsigned char try_trunc;
38047 + struct au_iinfo *iinfo;
38048 + struct super_block *sb;
38049 + struct au_hinode *hi;
38050 + struct inode *h_inode;
38051 + struct au_branch *br;
38052 + vfs_writef_t xwrite;
38054 + AuDebugOn(au_is_bad_inode(inode));
38056 + sb = inode->i_sb;
38057 + mnt_flags = au_mntflags(sb);
38058 + if (!au_opt_test(mnt_flags, XINO)
38059 + || inode->i_ino == AUFS_ROOT_INO)
38063 + au_xigen_inc(inode);
38064 + au_xib_clear_bit(inode);
38067 + iinfo = au_ii(inode);
38068 + bindex = iinfo->ii_btop;
38072 + xwrite = au_sbi(sb)->si_xwrite;
38073 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38074 + hi = au_hinode(iinfo, bindex);
38075 + bbot = iinfo->ii_bbot;
38076 + for (; bindex <= bbot; bindex++, hi++) {
38077 + h_inode = hi->hi_inode;
38079 + || (!unlinked && h_inode->i_nlink))
38082 + /* inode may not be revalidated */
38083 + bi = au_br_index(sb, hi->hi_id);
38087 + br = au_sbr(sb, bi);
38088 + err = au_xino_do_write(xwrite, au_xino_file(br),
38089 + h_inode->i_ino, /*ino*/0);
38090 + if (!err && try_trunc
38091 + && au_test_fs_trunc_xino(au_br_sb(br)))
38092 + xino_try_trunc(sb, br);
38096 +/* ---------------------------------------------------------------------- */
38098 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38100 + int found, total, i;
38103 + total = xi->xi_nondir.total;
38104 + for (i = 0; i < total; i++) {
38105 + if (xi->xi_nondir.array[i] != h_ino)
38114 +static int au_xinondir_expand(struct au_xino *xi)
38119 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38122 + sz = xi->xi_nondir.total * sizeof(ino_t);
38123 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38125 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38126 + /*may_shrink*/0);
38128 + xi->xi_nondir.array = p;
38129 + xi->xi_nondir.total <<= 1;
38130 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38138 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38139 + ino_t h_ino, int idx)
38141 + struct au_xino *xi;
38143 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38144 + xi = au_sbr(sb, bindex)->br_xino;
38145 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38147 + spin_lock(&xi->xi_nondir.spin);
38148 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38149 + xi->xi_nondir.array[idx] = 0;
38150 + spin_unlock(&xi->xi_nondir.spin);
38151 + wake_up_all(&xi->xi_nondir.wqh);
38154 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38157 + int err, found, empty;
38158 + struct au_xino *xi;
38162 + if (!au_opt_test(au_mntflags(sb), XINO))
38163 + goto out; /* no xino */
38165 + xi = au_sbr(sb, bindex)->br_xino;
38168 + spin_lock(&xi->xi_nondir.spin);
38169 + found = au_xinondir_find(xi, h_ino);
38170 + if (found == -1) {
38171 + empty = au_xinondir_find(xi, /*h_ino*/0);
38172 + if (empty == -1) {
38173 + empty = xi->xi_nondir.total;
38174 + err = au_xinondir_expand(xi);
38175 + if (unlikely(err))
38178 + xi->xi_nondir.array[empty] = h_ino;
38181 + spin_unlock(&xi->xi_nondir.spin);
38182 + wait_event(xi->xi_nondir.wqh,
38183 + xi->xi_nondir.array[found] != h_ino);
38188 + spin_unlock(&xi->xi_nondir.spin);
38193 +/* ---------------------------------------------------------------------- */
38195 +int au_xino_path(struct seq_file *seq, struct file *file)
38199 + err = au_seq_path(seq, &file->f_path);
38200 + if (unlikely(err))
38203 +#define Deleted "\\040(deleted)"
38204 + seq->count -= sizeof(Deleted) - 1;
38205 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38206 + sizeof(Deleted) - 1));
38212 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38213 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38214 +++ linux/include/uapi/linux/aufs_type.h 2018-07-19 09:46:13.066648108 +0200
38216 +/* SPDX-License-Identifier: GPL-2.0 */
38218 + * Copyright (C) 2005-2018 Junjiro R. Okajima
38220 + * This program, aufs is free software; you can redistribute it and/or modify
38221 + * it under the terms of the GNU General Public License as published by
38222 + * the Free Software Foundation; either version 2 of the License, or
38223 + * (at your option) any later version.
38225 + * This program is distributed in the hope that it will be useful,
38226 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38227 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38228 + * GNU General Public License for more details.
38230 + * You should have received a copy of the GNU General Public License
38231 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38234 +#ifndef __AUFS_TYPE_H__
38235 +#define __AUFS_TYPE_H__
38237 +#define AUFS_NAME "aufs"
38241 + * define it before including all other headers.
38242 + * sched.h may use pr_* macros before defining "current", so define the
38243 + * no-current version first, and re-define later.
38245 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38246 +#include <linux/sched.h>
38248 +#define pr_fmt(fmt) \
38249 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38250 + (int)sizeof(current->comm), current->comm, current->pid
38252 +#include <stdint.h>
38253 +#include <sys/types.h>
38254 +#endif /* __KERNEL__ */
38256 +#include <linux/limits.h>
38258 +#define AUFS_VERSION "4.17-20180716"
38260 +/* todo? move this to linux-2.6.19/include/magic.h */
38261 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38263 +/* ---------------------------------------------------------------------- */
38265 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38266 +typedef int8_t aufs_bindex_t;
38267 +#define AUFS_BRANCH_MAX 127
38269 +typedef int16_t aufs_bindex_t;
38270 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38271 +#define AUFS_BRANCH_MAX 511
38272 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38273 +#define AUFS_BRANCH_MAX 1023
38274 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38275 +#define AUFS_BRANCH_MAX 32767
38280 +#ifndef AUFS_BRANCH_MAX
38281 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38283 +#endif /* __KERNEL__ */
38285 +/* ---------------------------------------------------------------------- */
38287 +#define AUFS_FSTYPE AUFS_NAME
38289 +#define AUFS_ROOT_INO 2
38290 +#define AUFS_FIRST_INO 11
38292 +#define AUFS_WH_PFX ".wh."
38293 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38294 +#define AUFS_WH_TMP_LEN 4
38295 +/* a limit for rmdir/rename a dir and copyup */
38296 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38297 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38299 + - AUFS_WH_TMP_LEN) /* hex */
38300 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38301 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38302 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38303 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38304 +#define AUFS_DIRWH_DEF 3
38305 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38306 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38307 +#define AUFS_RDBLK_DEF 512 /* bytes */
38308 +#define AUFS_RDHASH_DEF 32
38309 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38310 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38311 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38312 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38313 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38315 +/* pseudo-link maintenace under /proc */
38316 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38317 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38318 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38320 +/* dirren, renamed dir */
38321 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38322 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38323 +/* whiteouted doubly */
38324 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38325 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38327 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38328 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38330 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38331 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38332 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38334 +/* doubly whiteouted */
38335 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38336 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38337 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38339 +/* branch permissions and attributes */
38340 +#define AUFS_BRPERM_RW "rw"
38341 +#define AUFS_BRPERM_RO "ro"
38342 +#define AUFS_BRPERM_RR "rr"
38343 +#define AUFS_BRATTR_COO_REG "coo_reg"
38344 +#define AUFS_BRATTR_COO_ALL "coo_all"
38345 +#define AUFS_BRATTR_FHSM "fhsm"
38346 +#define AUFS_BRATTR_UNPIN "unpin"
38347 +#define AUFS_BRATTR_ICEX "icex"
38348 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38349 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38350 +#define AUFS_BRATTR_ICEX_TR "icextr"
38351 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38352 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38353 +#define AUFS_BRRATTR_WH "wh"
38354 +#define AUFS_BRWATTR_NLWH "nolwh"
38355 +#define AUFS_BRWATTR_MOO "moo"
38357 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38358 +#define AuBrPerm_RO (1 << 1) /* readonly */
38359 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38360 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38362 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38363 +#define AuBrAttr_COO_ALL (1 << 4)
38364 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38366 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38367 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38368 + branch. meaningless since
38369 + linux-3.18-rc1 */
38371 +/* ignore error in copying XATTR */
38372 +#define AuBrAttr_ICEX_SEC (1 << 7)
38373 +#define AuBrAttr_ICEX_SYS (1 << 8)
38374 +#define AuBrAttr_ICEX_TR (1 << 9)
38375 +#define AuBrAttr_ICEX_USR (1 << 10)
38376 +#define AuBrAttr_ICEX_OTH (1 << 11)
38377 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38378 + | AuBrAttr_ICEX_SYS \
38379 + | AuBrAttr_ICEX_TR \
38380 + | AuBrAttr_ICEX_USR \
38381 + | AuBrAttr_ICEX_OTH)
38383 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38384 +#define AuBrRAttr_Mask AuBrRAttr_WH
38386 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38387 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38388 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38390 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38392 +/* #warning test userspace */
38394 +#ifndef CONFIG_AUFS_FHSM
38395 +#undef AuBrAttr_FHSM
38396 +#define AuBrAttr_FHSM 0
38398 +#ifndef CONFIG_AUFS_XATTR
38399 +#undef AuBrAttr_ICEX
38400 +#define AuBrAttr_ICEX 0
38401 +#undef AuBrAttr_ICEX_SEC
38402 +#define AuBrAttr_ICEX_SEC 0
38403 +#undef AuBrAttr_ICEX_SYS
38404 +#define AuBrAttr_ICEX_SYS 0
38405 +#undef AuBrAttr_ICEX_TR
38406 +#define AuBrAttr_ICEX_TR 0
38407 +#undef AuBrAttr_ICEX_USR
38408 +#define AuBrAttr_ICEX_USR 0
38409 +#undef AuBrAttr_ICEX_OTH
38410 +#define AuBrAttr_ICEX_OTH 0
38414 +/* the longest combination */
38415 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38416 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38417 + "+" AUFS_BRATTR_COO_REG \
38418 + "+" AUFS_BRATTR_FHSM \
38419 + "+" AUFS_BRATTR_UNPIN \
38420 + "+" AUFS_BRATTR_ICEX_SEC \
38421 + "+" AUFS_BRATTR_ICEX_SYS \
38422 + "+" AUFS_BRATTR_ICEX_USR \
38423 + "+" AUFS_BRATTR_ICEX_OTH \
38424 + "+" AUFS_BRWATTR_NLWH)
38427 + char a[AuBrPermStrSz];
38428 +} au_br_perm_str_t;
38430 +static inline int au_br_writable(int brperm)
38432 + return brperm & AuBrPerm_RW;
38435 +static inline int au_br_whable(int brperm)
38437 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38440 +static inline int au_br_wh_linkable(int brperm)
38442 + return !(brperm & AuBrWAttr_NoLinkWH);
38445 +static inline int au_br_cmoo(int brperm)
38447 + return brperm & AuBrAttr_CMOO_Mask;
38450 +static inline int au_br_fhsm(int brperm)
38452 + return brperm & AuBrAttr_FHSM;
38455 +/* ---------------------------------------------------------------------- */
38459 + /* readdir in userspace */
38463 + AuCtl_WBR_FD, /* pathconf wrapper */
38464 + AuCtl_IBUSY, /* busy inode */
38465 + AuCtl_MVDOWN, /* move-down */
38466 + AuCtl_BR, /* info about branches */
38467 + AuCtl_FHSM_FD /* connection for fhsm */
38470 +/* borrowed from linux/include/linux/kernel.h */
38472 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38473 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38476 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38478 +#define __aligned(x) __attribute__((aligned(x)))
38483 +#define __packed __attribute__((packed))
38487 +struct au_rdu_cookie {
38492 + uint32_t generation;
38495 +struct au_rdu_ent {
38504 +static inline int au_rdu_len(int nlen)
38506 + /* include the terminating NULL */
38507 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38508 + sizeof(uint64_t));
38511 +union au_rdu_ent_ul {
38512 + struct au_rdu_ent __user *e;
38524 + uint64_t sz; /* AuCtl_RDU */
38525 + uint64_t nent; /* AuCtl_RDU_INO */
38527 + union au_rdu_ent_ul ent;
38528 + uint16_t verify[AufsCtlRduV_End];
38530 + /* input/output */
38534 + union au_rdu_ent_ul tail;
38535 + /* number of entries which were added in a single call */
38540 + struct au_rdu_cookie cookie;
38543 +/* ---------------------------------------------------------------------- */
38545 +/* dirren. the branch is identified by the filename who contains this */
38546 +struct au_drinfo {
38549 + uint8_t oldnamelen;
38550 + uint64_t _padding;
38552 + uint8_t oldname[0];
38555 +struct au_drinfo_fdata {
38557 + struct au_drinfo drinfo;
38560 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38562 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38564 +/* ---------------------------------------------------------------------- */
38566 +struct aufs_wbr_fd {
38571 +/* ---------------------------------------------------------------------- */
38573 +struct aufs_ibusy {
38574 + uint64_t ino, h_ino;
38578 +/* ---------------------------------------------------------------------- */
38580 +/* error code for move-down */
38581 +/* the actual message strings are implemented in aufs-util.git */
38583 + EAU_MVDOWN_OPAQUE = 1,
38584 + EAU_MVDOWN_WHITEOUT,
38585 + EAU_MVDOWN_UPPER,
38586 + EAU_MVDOWN_BOTTOM,
38587 + EAU_MVDOWN_NOUPPER,
38588 + EAU_MVDOWN_NOLOWERBR,
38592 +/* flags for move-down */
38593 +#define AUFS_MVDOWN_DMSG 1
38594 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38595 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38596 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38597 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38598 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38599 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38600 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38601 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38602 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38603 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38604 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38605 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38607 +/* index for move-down */
38609 + AUFS_MVDOWN_UPPER,
38610 + AUFS_MVDOWN_LOWER,
38611 + AUFS_MVDOWN_NARRAY
38615 + * additional info of move-down
38616 + * number of free blocks and inodes.
38617 + * subset of struct kstatfs, but smaller and always 64bit.
38619 +struct aufs_stfs {
38620 + uint64_t f_blocks;
38621 + uint64_t f_bavail;
38622 + uint64_t f_files;
38623 + uint64_t f_ffree;
38626 +struct aufs_stbr {
38627 + int16_t brid; /* optional input */
38628 + int16_t bindex; /* output */
38629 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38632 +struct aufs_mvdown {
38633 + uint32_t flags; /* input/output */
38634 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38635 + int8_t au_errno; /* output */
38638 +/* ---------------------------------------------------------------------- */
38640 +union aufs_brinfo {
38641 + /* PATH_MAX may differ between kernel-space and user-space */
38642 + char _spacer[4096];
38650 +/* ---------------------------------------------------------------------- */
38652 +#define AuCtlType 'A'
38653 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38654 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38655 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38656 + struct aufs_wbr_fd)
38657 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38658 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38659 + struct aufs_mvdown)
38660 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
38661 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
38663 +#endif /* __AUFS_TYPE_H__ */
38664 SPDX-License-Identifier: GPL-2.0
38665 aufs4.17 loopback patch
38667 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38668 index bc965e5..852868a 100644
38669 --- a/drivers/block/loop.c
38670 +++ b/drivers/block/loop.c
38671 @@ -622,6 +622,15 @@ static inline void loop_update_dio(struct loop_device *lo)
38675 +static struct file *loop_real_file(struct file *file)
38677 + struct file *f = NULL;
38679 + if (file->f_path.dentry->d_sb->s_op->real_loop)
38680 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
38684 static void loop_reread_partitions(struct loop_device *lo,
38685 struct block_device *bdev)
38687 @@ -656,6 +665,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38690 struct file *file, *old_file;
38691 + struct file *f, *virt_file = NULL, *old_virt_file;
38692 struct inode *inode;
38695 @@ -672,9 +682,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38696 error = loop_validate_file(file, bdev);
38699 + f = loop_real_file(file);
38701 + virt_file = file;
38706 inode = file->f_mapping->host;
38707 old_file = lo->lo_backing_file;
38708 + old_virt_file = lo->lo_backing_virt_file;
38712 @@ -689,6 +706,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38713 blk_mq_freeze_queue(lo->lo_queue);
38714 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
38715 lo->lo_backing_file = file;
38716 + lo->lo_backing_virt_file = virt_file;
38717 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
38718 mapping_set_gfp_mask(file->f_mapping,
38719 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
38720 @@ -696,12 +714,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
38721 blk_mq_unfreeze_queue(lo->lo_queue);
38724 + if (old_virt_file)
38725 + fput(old_virt_file);
38726 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
38727 loop_reread_partitions(lo, bdev);
38737 @@ -895,7 +917,7 @@ static int loop_prepare_queue(struct loop_device *lo)
38738 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38739 struct block_device *bdev, unsigned int arg)
38741 - struct file *file;
38742 + struct file *file, *f, *virt_file = NULL;
38743 struct inode *inode;
38744 struct address_space *mapping;
38746 @@ -909,6 +931,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38750 + f = loop_real_file(file);
38752 + virt_file = file;
38758 if (lo->lo_state != Lo_unbound)
38759 @@ -957,6 +985,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38760 lo->lo_device = bdev;
38761 lo->lo_flags = lo_flags;
38762 lo->lo_backing_file = file;
38763 + lo->lo_backing_virt_file = virt_file;
38764 lo->transfer = NULL;
38766 lo->lo_sizelimit = 0;
38767 @@ -990,6 +1019,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
38774 /* This is safe: open() is still holding a reference. */
38775 module_put(THIS_MODULE);
38776 @@ -1036,6 +1067,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
38777 static int loop_clr_fd(struct loop_device *lo)
38779 struct file *filp = lo->lo_backing_file;
38780 + struct file *virt_filp = lo->lo_backing_virt_file;
38781 gfp_t gfp = lo->old_gfp_mask;
38782 struct block_device *bdev = lo->lo_device;
38784 @@ -1067,6 +1099,7 @@ static int loop_clr_fd(struct loop_device *lo)
38785 spin_lock_irq(&lo->lo_lock);
38786 lo->lo_state = Lo_rundown;
38787 lo->lo_backing_file = NULL;
38788 + lo->lo_backing_virt_file = NULL;
38789 spin_unlock_irq(&lo->lo_lock);
38791 loop_release_xfer(lo);
38792 @@ -1115,6 +1148,8 @@ static int loop_clr_fd(struct loop_device *lo)
38793 * bd_mutex which is usually taken before lo_ctl_mutex.
38801 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
38802 index b78de98..2bbbd92 100644
38803 --- a/drivers/block/loop.h
38804 +++ b/drivers/block/loop.h
38805 @@ -46,7 +46,7 @@ struct loop_device {
38806 int (*ioctl)(struct loop_device *, int cmd,
38807 unsigned long arg);
38809 - struct file * lo_backing_file;
38810 + struct file * lo_backing_file, *lo_backing_virt_file;
38811 struct block_device *lo_device;
38814 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
38815 index 7ca7f67..3d4e90d 100644
38816 --- a/fs/aufs/f_op.c
38817 +++ b/fs/aufs/f_op.c
38818 @@ -358,7 +358,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
38819 if (IS_ERR(h_file))
38822 - if (au_test_loopback_kthread()) {
38823 + if (0 && au_test_loopback_kthread()) {
38824 au_warn_loopback(h_file->f_path.dentry->d_sb);
38825 if (file->f_mapping != h_file->f_mapping) {
38826 file->f_mapping = h_file->f_mapping;
38827 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
38828 index 2d65b8f..5ed7903 100644
38829 --- a/fs/aufs/loop.c
38830 +++ b/fs/aufs/loop.c
38831 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
38832 symbol_put(loop_backing_file);
38833 kfree(au_warn_loopback_array);
38836 +/* ---------------------------------------------------------------------- */
38838 +/* support the loopback block device insude aufs */
38840 +struct file *aufs_real_loop(struct file *file)
38844 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
38845 + fi_read_lock(file);
38846 + f = au_hf_top(file);
38847 + fi_read_unlock(file);
38851 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
38852 index 05d703d..6bb23c8 100644
38853 --- a/fs/aufs/loop.h
38854 +++ b/fs/aufs/loop.h
38855 @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb);
38857 int au_loopback_init(void);
38858 void au_loopback_fin(void);
38860 +struct file *aufs_real_loop(struct file *file);
38862 +AuStub(struct file *, loop_backing_file, return NULL)
38864 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
38865 struct dentry *h_adding)
38866 AuStubInt0(au_test_loopback_kthread, void)
38867 @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
38869 AuStubInt0(au_loopback_init, void)
38870 AuStubVoid(au_loopback_fin, void)
38872 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
38873 #endif /* BLK_DEV_LOOP */
38875 #endif /* __KERNEL__ */
38876 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
38877 index eed37ba..a3a5cd7 100644
38878 --- a/fs/aufs/super.c
38879 +++ b/fs/aufs/super.c
38880 @@ -840,7 +840,10 @@ static const struct super_operations aufs_sop = {
38881 .statfs = aufs_statfs,
38882 .put_super = aufs_put_super,
38883 .sync_fs = aufs_sync_fs,
38884 - .remount_fs = aufs_remount_fs
38885 + .remount_fs = aufs_remount_fs,
38886 +#ifdef CONFIG_AUFS_BDEV_LOOP
38887 + .real_loop = aufs_real_loop
38891 /* ---------------------------------------------------------------------- */
38892 diff --git a/include/linux/fs.h b/include/linux/fs.h
38893 index 09a2542..11a6346 100644
38894 --- a/include/linux/fs.h
38895 +++ b/include/linux/fs.h
38896 @@ -1852,6 +1852,10 @@ struct super_operations {
38897 struct shrink_control *);
38898 long (*free_cached_objects)(struct super_block *,
38899 struct shrink_control *);
38900 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
38902 + struct file *(*real_loop)(struct file *);